1001
/* push final bytes to part_buf, only use during push */
1002
static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
1004
memcpy((void *)&host->part_buf, buf, cnt);
1005
host->part_buf_count = cnt;
1008
/* append bytes to part_buf, only use during push */
1009
static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
1011
cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
1012
memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
1013
host->part_buf_count += cnt;
1017
/* pull first bytes from part_buf, only use during pull */
1018
static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
1020
cnt = min(cnt, (int)host->part_buf_count);
1022
memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
1024
host->part_buf_count -= cnt;
1025
host->part_buf_start += cnt;
1030
/* pull final bytes from the part_buf, assuming it's just been filled */
1031
static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
1033
memcpy(buf, &host->part_buf, cnt);
1034
host->part_buf_start = cnt;
1035
host->part_buf_count = (1 << host->data_shift) - cnt;
949
1038
static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
951
u16 *pdata = (u16 *)buf;
953
WARN_ON(cnt % 2 != 0);
957
mci_writew(host, DATA, *pdata++);
1040
/* try and push anything in the part_buf */
1041
if (unlikely(host->part_buf_count)) {
1042
int len = dw_mci_push_part_bytes(host, buf, cnt);
1045
if (!sg_next(host->sg) || host->part_buf_count == 2) {
1046
mci_writew(host, DATA(host->data_offset),
1048
host->part_buf_count = 0;
1051
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1052
if (unlikely((unsigned long)buf & 0x1)) {
1054
u16 aligned_buf[64];
1055
int len = min(cnt & -2, (int)sizeof(aligned_buf));
1056
int items = len >> 1;
1058
/* memcpy from input buffer into aligned buffer */
1059
memcpy(aligned_buf, buf, len);
1062
/* push data from aligned buffer into fifo */
1063
for (i = 0; i < items; ++i)
1064
mci_writew(host, DATA(host->data_offset),
1071
for (; cnt >= 2; cnt -= 2)
1072
mci_writew(host, DATA(host->data_offset), *pdata++);
1075
/* put anything remaining in the part_buf */
1077
dw_mci_set_part_bytes(host, buf, cnt);
1078
if (!sg_next(host->sg))
1079
mci_writew(host, DATA(host->data_offset),
962
1084
static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
964
u16 *pdata = (u16 *)buf;
966
WARN_ON(cnt % 2 != 0);
970
*pdata++ = mci_readw(host, DATA);
1086
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1087
if (unlikely((unsigned long)buf & 0x1)) {
1089
/* pull data from fifo into aligned buffer */
1090
u16 aligned_buf[64];
1091
int len = min(cnt & -2, (int)sizeof(aligned_buf));
1092
int items = len >> 1;
1094
for (i = 0; i < items; ++i)
1095
aligned_buf[i] = mci_readw(host,
1096
DATA(host->data_offset));
1097
/* memcpy from aligned buffer into output buffer */
1098
memcpy(buf, aligned_buf, len);
1106
for (; cnt >= 2; cnt -= 2)
1107
*pdata++ = mci_readw(host, DATA(host->data_offset));
1111
host->part_buf16 = mci_readw(host, DATA(host->data_offset));
1112
dw_mci_pull_final_bytes(host, buf, cnt);
975
1116
static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
977
u32 *pdata = (u32 *)buf;
979
WARN_ON(cnt % 4 != 0);
980
WARN_ON((unsigned long)pdata & 0x3);
984
mci_writel(host, DATA, *pdata++);
1118
/* try and push anything in the part_buf */
1119
if (unlikely(host->part_buf_count)) {
1120
int len = dw_mci_push_part_bytes(host, buf, cnt);
1123
if (!sg_next(host->sg) || host->part_buf_count == 4) {
1124
mci_writel(host, DATA(host->data_offset),
1126
host->part_buf_count = 0;
1129
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1130
if (unlikely((unsigned long)buf & 0x3)) {
1132
u32 aligned_buf[32];
1133
int len = min(cnt & -4, (int)sizeof(aligned_buf));
1134
int items = len >> 2;
1136
/* memcpy from input buffer into aligned buffer */
1137
memcpy(aligned_buf, buf, len);
1140
/* push data from aligned buffer into fifo */
1141
for (i = 0; i < items; ++i)
1142
mci_writel(host, DATA(host->data_offset),
1149
for (; cnt >= 4; cnt -= 4)
1150
mci_writel(host, DATA(host->data_offset), *pdata++);
1153
/* put anything remaining in the part_buf */
1155
dw_mci_set_part_bytes(host, buf, cnt);
1156
if (!sg_next(host->sg))
1157
mci_writel(host, DATA(host->data_offset),
989
1162
static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
991
u32 *pdata = (u32 *)buf;
993
WARN_ON(cnt % 4 != 0);
994
WARN_ON((unsigned long)pdata & 0x3);
998
*pdata++ = mci_readl(host, DATA);
1164
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1165
if (unlikely((unsigned long)buf & 0x3)) {
1167
/* pull data from fifo into aligned buffer */
1168
u32 aligned_buf[32];
1169
int len = min(cnt & -4, (int)sizeof(aligned_buf));
1170
int items = len >> 2;
1172
for (i = 0; i < items; ++i)
1173
aligned_buf[i] = mci_readl(host,
1174
DATA(host->data_offset));
1175
/* memcpy from aligned buffer into output buffer */
1176
memcpy(buf, aligned_buf, len);
1184
for (; cnt >= 4; cnt -= 4)
1185
*pdata++ = mci_readl(host, DATA(host->data_offset));
1189
host->part_buf32 = mci_readl(host, DATA(host->data_offset));
1190
dw_mci_pull_final_bytes(host, buf, cnt);
1003
1194
static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1005
u64 *pdata = (u64 *)buf;
1007
WARN_ON(cnt % 8 != 0);
1011
mci_writeq(host, DATA, *pdata++);
1196
/* try and push anything in the part_buf */
1197
if (unlikely(host->part_buf_count)) {
1198
int len = dw_mci_push_part_bytes(host, buf, cnt);
1201
if (!sg_next(host->sg) || host->part_buf_count == 8) {
1202
mci_writew(host, DATA(host->data_offset),
1204
host->part_buf_count = 0;
1207
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1208
if (unlikely((unsigned long)buf & 0x7)) {
1210
u64 aligned_buf[16];
1211
int len = min(cnt & -8, (int)sizeof(aligned_buf));
1212
int items = len >> 3;
1214
/* memcpy from input buffer into aligned buffer */
1215
memcpy(aligned_buf, buf, len);
1218
/* push data from aligned buffer into fifo */
1219
for (i = 0; i < items; ++i)
1220
mci_writeq(host, DATA(host->data_offset),
1227
for (; cnt >= 8; cnt -= 8)
1228
mci_writeq(host, DATA(host->data_offset), *pdata++);
1231
/* put anything remaining in the part_buf */
1233
dw_mci_set_part_bytes(host, buf, cnt);
1234
if (!sg_next(host->sg))
1235
mci_writeq(host, DATA(host->data_offset),
1016
1240
static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1018
u64 *pdata = (u64 *)buf;
1020
WARN_ON(cnt % 8 != 0);
1024
*pdata++ = mci_readq(host, DATA);
1242
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1243
if (unlikely((unsigned long)buf & 0x7)) {
1245
/* pull data from fifo into aligned buffer */
1246
u64 aligned_buf[16];
1247
int len = min(cnt & -8, (int)sizeof(aligned_buf));
1248
int items = len >> 3;
1250
for (i = 0; i < items; ++i)
1251
aligned_buf[i] = mci_readq(host,
1252
DATA(host->data_offset));
1253
/* memcpy from aligned buffer into output buffer */
1254
memcpy(buf, aligned_buf, len);
1262
for (; cnt >= 8; cnt -= 8)
1263
*pdata++ = mci_readq(host, DATA(host->data_offset));
1267
host->part_buf = mci_readq(host, DATA(host->data_offset));
1268
dw_mci_pull_final_bytes(host, buf, cnt);
1272
static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
1276
/* get remaining partial bytes */
1277
len = dw_mci_pull_part_bytes(host, buf, cnt);
1278
if (unlikely(len == cnt))
1283
/* get the rest of the data */
1284
host->pull_data(host, buf, cnt);
1029
1287
static void dw_mci_read_data_pio(struct dw_mci *host)