Skip to content

Commit 4e0a5ad

Browse files
jh80chungcjb
authored andcommitted
mmc: dw_mmc: modify DATA register offset
In dw_mmc 2.40a spec, Data register's offset is changed. Before we used Data register offset 0x100. but if somebody uses a 2.40a controller, we must use 0x200 for Data register. This patch adds a version-id checking point and uses SDMMC_DATA(x) instead of SDMMC_DATA. It assumes 2.40a is the latest version. Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent c43fd77 commit 4e0a5ad

3 files changed

Lines changed: 61 additions & 22 deletions

File tree

‎drivers/mmc/host/dw_mmc.c‎

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
10431043
buf += len;
10441044
cnt -= len;
10451045
if (!sg_next(host->sg) || host->part_buf_count == 2) {
1046-
mci_writew(host, DATA, host->part_buf16);
1046+
mci_writew(host, DATA(host->data_offset),
1047+
host->part_buf16);
10471048
host->part_buf_count = 0;
10481049
}
10491050
}
@@ -1060,21 +1061,23 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
10601061
cnt -= len;
10611062
/* push data from aligned buffer into fifo */
10621063
for (i = 0; i < items; ++i)
1063-
mci_writew(host, DATA, aligned_buf[i]);
1064+
mci_writew(host, DATA(host->data_offset),
1065+
aligned_buf[i]);
10641066
}
10651067
} else
10661068
#endif
10671069
{
10681070
u16 *pdata = buf;
10691071
for (; cnt >= 2; cnt -= 2)
1070-
mci_writew(host, DATA, *pdata++);
1072+
mci_writew(host, DATA(host->data_offset), *pdata++);
10711073
buf = pdata;
10721074
}
10731075
/* put anything remaining in the part_buf */
10741076
if (cnt) {
10751077
dw_mci_set_part_bytes(host, buf, cnt);
10761078
if (!sg_next(host->sg))
1077-
mci_writew(host, DATA, host->part_buf16);
1079+
mci_writew(host, DATA(host->data_offset),
1080+
host->part_buf16);
10781081
}
10791082
}
10801083

@@ -1089,7 +1092,8 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
10891092
int items = len >> 1;
10901093
int i;
10911094
for (i = 0; i < items; ++i)
1092-
aligned_buf[i] = mci_readw(host, DATA);
1095+
aligned_buf[i] = mci_readw(host,
1096+
DATA(host->data_offset));
10931097
/* memcpy from aligned buffer into output buffer */
10941098
memcpy(buf, aligned_buf, len);
10951099
buf += len;
@@ -1100,11 +1104,11 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
11001104
{
11011105
u16 *pdata = buf;
11021106
for (; cnt >= 2; cnt -= 2)
1103-
*pdata++ = mci_readw(host, DATA);
1107+
*pdata++ = mci_readw(host, DATA(host->data_offset));
11041108
buf = pdata;
11051109
}
11061110
if (cnt) {
1107-
host->part_buf16 = mci_readw(host, DATA);
1111+
host->part_buf16 = mci_readw(host, DATA(host->data_offset));
11081112
dw_mci_pull_final_bytes(host, buf, cnt);
11091113
}
11101114
}
@@ -1117,7 +1121,8 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
11171121
buf += len;
11181122
cnt -= len;
11191123
if (!sg_next(host->sg) || host->part_buf_count == 4) {
1120-
mci_writel(host, DATA, host->part_buf32);
1124+
mci_writel(host, DATA(host->data_offset),
1125+
host->part_buf32);
11211126
host->part_buf_count = 0;
11221127
}
11231128
}
@@ -1134,21 +1139,23 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
11341139
cnt -= len;
11351140
/* push data from aligned buffer into fifo */
11361141
for (i = 0; i < items; ++i)
1137-
mci_writel(host, DATA, aligned_buf[i]);
1142+
mci_writel(host, DATA(host->data_offset),
1143+
aligned_buf[i]);
11381144
}
11391145
} else
11401146
#endif
11411147
{
11421148
u32 *pdata = buf;
11431149
for (; cnt >= 4; cnt -= 4)
1144-
mci_writel(host, DATA, *pdata++);
1150+
mci_writel(host, DATA(host->data_offset), *pdata++);
11451151
buf = pdata;
11461152
}
11471153
/* put anything remaining in the part_buf */
11481154
if (cnt) {
11491155
dw_mci_set_part_bytes(host, buf, cnt);
11501156
if (!sg_next(host->sg))
1151-
mci_writel(host, DATA, host->part_buf32);
1157+
mci_writel(host, DATA(host->data_offset),
1158+
host->part_buf32);
11521159
}
11531160
}
11541161

@@ -1163,7 +1170,8 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
11631170
int items = len >> 2;
11641171
int i;
11651172
for (i = 0; i < items; ++i)
1166-
aligned_buf[i] = mci_readl(host, DATA);
1173+
aligned_buf[i] = mci_readl(host,
1174+
DATA(host->data_offset));
11671175
/* memcpy from aligned buffer into output buffer */
11681176
memcpy(buf, aligned_buf, len);
11691177
buf += len;
@@ -1174,11 +1182,11 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
11741182
{
11751183
u32 *pdata = buf;
11761184
for (; cnt >= 4; cnt -= 4)
1177-
*pdata++ = mci_readl(host, DATA);
1185+
*pdata++ = mci_readl(host, DATA(host->data_offset));
11781186
buf = pdata;
11791187
}
11801188
if (cnt) {
1181-
host->part_buf32 = mci_readl(host, DATA);
1189+
host->part_buf32 = mci_readl(host, DATA(host->data_offset));
11821190
dw_mci_pull_final_bytes(host, buf, cnt);
11831191
}
11841192
}
@@ -1191,7 +1199,8 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
11911199
buf += len;
11921200
cnt -= len;
11931201
if (!sg_next(host->sg) || host->part_buf_count == 8) {
1194-
mci_writew(host, DATA, host->part_buf);
1202+
mci_writew(host, DATA(host->data_offset),
1203+
host->part_buf);
11951204
host->part_buf_count = 0;
11961205
}
11971206
}
@@ -1208,21 +1217,23 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
12081217
cnt -= len;
12091218
/* push data from aligned buffer into fifo */
12101219
for (i = 0; i < items; ++i)
1211-
mci_writeq(host, DATA, aligned_buf[i]);
1220+
mci_writeq(host, DATA(host->data_offset),
1221+
aligned_buf[i]);
12121222
}
12131223
} else
12141224
#endif
12151225
{
12161226
u64 *pdata = buf;
12171227
for (; cnt >= 8; cnt -= 8)
1218-
mci_writeq(host, DATA, *pdata++);
1228+
mci_writeq(host, DATA(host->data_offset), *pdata++);
12191229
buf = pdata;
12201230
}
12211231
/* put anything remaining in the part_buf */
12221232
if (cnt) {
12231233
dw_mci_set_part_bytes(host, buf, cnt);
12241234
if (!sg_next(host->sg))
1225-
mci_writeq(host, DATA, host->part_buf);
1235+
mci_writeq(host, DATA(host->data_offset),
1236+
host->part_buf);
12261237
}
12271238
}
12281239

@@ -1237,7 +1248,8 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
12371248
int items = len >> 3;
12381249
int i;
12391250
for (i = 0; i < items; ++i)
1240-
aligned_buf[i] = mci_readq(host, DATA);
1251+
aligned_buf[i] = mci_readq(host,
1252+
DATA(host->data_offset));
12411253
/* memcpy from aligned buffer into output buffer */
12421254
memcpy(buf, aligned_buf, len);
12431255
buf += len;
@@ -1248,11 +1260,11 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
12481260
{
12491261
u64 *pdata = buf;
12501262
for (; cnt >= 8; cnt -= 8)
1251-
*pdata++ = mci_readq(host, DATA);
1263+
*pdata++ = mci_readq(host, DATA(host->data_offset));
12521264
buf = pdata;
12531265
}
12541266
if (cnt) {
1255-
host->part_buf = mci_readq(host, DATA);
1267+
host->part_buf = mci_readq(host, DATA(host->data_offset));
12561268
dw_mci_pull_final_bytes(host, buf, cnt);
12571269
}
12581270
}
@@ -1951,6 +1963,18 @@ static int dw_mci_probe(struct platform_device *pdev)
19511963
}
19521964
}
19531965

1966+
/*
1967+
* In 2.40a spec, Data offset is changed.
1968+
* Need to check the version-id and set data-offset for DATA register.
1969+
*/
1970+
host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
1971+
dev_info(&pdev->dev, "Version ID is %04x\n", host->verid);
1972+
1973+
if (host->verid < DW_MMC_240A)
1974+
host->data_offset = DATA_OFFSET;
1975+
else
1976+
host->data_offset = DATA_240A_OFFSET;
1977+
19541978
/*
19551979
* Enable interrupts for command done, data over, data empty, card det,
19561980
* receive ready and error such as transmit, receive timeout, crc error

‎drivers/mmc/host/dw_mmc.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#ifndef _DW_MMC_H_
1515
#define _DW_MMC_H_
1616

17+
#define DW_MMC_240A 0x240a
18+
1719
#define SDMMC_CTRL 0x000
1820
#define SDMMC_PWREN 0x004
1921
#define SDMMC_CLKDIV 0x008
@@ -51,7 +53,14 @@
5153
#define SDMMC_IDINTEN 0x090
5254
#define SDMMC_DSCADDR 0x094
5355
#define SDMMC_BUFADDR 0x098
54-
#define SDMMC_DATA 0x100
56+
#define SDMMC_DATA(x) (x)
57+
58+
/*
59+
* Data offset is difference according to Version
60+
* Lower than 2.40a : data register offest is 0x100
61+
*/
62+
#define DATA_OFFSET 0x100
63+
#define DATA_240A_OFFSET 0x200
5564

5665
/* shift bit field */
5766
#define _SBF(f, v) ((v) << (f))
@@ -130,6 +139,8 @@
130139
#define SDMMC_IDMAC_ENABLE BIT(7)
131140
#define SDMMC_IDMAC_FB BIT(1)
132141
#define SDMMC_IDMAC_SWRESET BIT(0)
142+
/* Version ID register define */
143+
#define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
133144

134145
/* Register access macros */
135146
#define mci_readl(dev, reg) \

‎include/linux/mmc/dw_mmc.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct mmc_data;
7272
* rate and timeout calculations.
7373
* @current_speed: Configured rate of the controller.
7474
* @num_slots: Number of slots available.
75+
* @verid: Denote Version ID.
76+
* @data_offset: Set the offset of DATA register according to VERID.
7577
* @pdev: Platform device associated with the MMC controller.
7678
* @pdata: Platform data associated with the MMC controller.
7779
* @slot: Slots sharing this MMC controller.
@@ -147,6 +149,8 @@ struct dw_mci {
147149
u32 current_speed;
148150
u32 num_slots;
149151
u32 fifoth_val;
152+
u16 verid;
153+
u16 data_offset;
150154
struct platform_device *pdev;
151155
struct dw_mci_board *pdata;
152156
struct dw_mci_slot *slot[MAX_MCI_SLOTS];

0 commit comments

Comments
 (0)