diff options
author | David Vrabel <david.vrabel@csr.com> | 2007-08-08 09:24:21 -0400 |
---|---|---|
committer | Pierre Ossman <drzeus@drzeus.cx> | 2007-09-23 15:21:32 -0400 |
commit | eb6594689226663968ef0a9fd71ec5e1e4e04f9c (patch) | |
tree | d523962b81a2b5f4a55543d4342daaaebc5d5162 /drivers/mmc/core | |
parent | 9a08f82b3cc522f727ace580a2aaee5402435bc8 (diff) |
sdio: extend sdio_readsb() and friends to handle any length of buffer
Extend sdio_readsb(), sdio_writesb(), sdio_memcpy_fromio(), and
sdio_memcpy_toio() to handle any length of buffer by splitting the transfer
into several IO_RW_EXTENDED commands. Typically, a transfer would be split
into a single block mode transfer followed by a byte mode transfer for the
remainder but we also handle lack of block mode support and the block size
being greater than 512 (the maximum byte mode transfer size).
host->max_seg_size <= host->max_req_size so there's no need to check both
when determining the maximum data size for a single command.
Signed-off-by: David Vrabel <david.vrabel@csr.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r-- | drivers/mmc/core/sdio_io.c | 93 | ||||
-rw-r--r-- | drivers/mmc/core/sdio_ops.c | 19 | ||||
-rw-r--r-- | drivers/mmc/core/sdio_ops.h | 2 |
3 files changed, 86 insertions, 28 deletions
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c index c2bad1195e3b..34b085d4024a 100644 --- a/drivers/mmc/core/sdio_io.c +++ b/drivers/mmc/core/sdio_io.c | |||
@@ -189,6 +189,67 @@ int sdio_set_block_size(struct sdio_func *func, unsigned blksz) | |||
189 | 189 | ||
190 | EXPORT_SYMBOL_GPL(sdio_set_block_size); | 190 | EXPORT_SYMBOL_GPL(sdio_set_block_size); |
191 | 191 | ||
192 | /* Split an arbitrarily sized data transfer into several | ||
193 | * IO_RW_EXTENDED commands. */ | ||
194 | static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, | ||
195 | unsigned addr, int incr_addr, u8 *buf, unsigned size) | ||
196 | { | ||
197 | unsigned remainder = size; | ||
198 | unsigned max_blocks; | ||
199 | int ret; | ||
200 | |||
201 | /* Do the bulk of the transfer using block mode (if supported). */ | ||
202 | if (func->card->cccr.multi_block) { | ||
203 | /* Blocks per command is limited by host count, host transfer | ||
204 | * size (we only use a single sg entry) and the maximum for | ||
205 | * IO_RW_EXTENDED of 511 blocks. */ | ||
206 | max_blocks = min(min( | ||
207 | func->card->host->max_blk_count, | ||
208 | func->card->host->max_seg_size / func->cur_blksize), | ||
209 | 511u); | ||
210 | |||
211 | while (remainder > func->cur_blksize) { | ||
212 | unsigned blocks; | ||
213 | |||
214 | blocks = remainder / func->cur_blksize; | ||
215 | if (blocks > max_blocks) | ||
216 | blocks = max_blocks; | ||
217 | size = blocks * func->cur_blksize; | ||
218 | |||
219 | ret = mmc_io_rw_extended(func->card, write, | ||
220 | func->num, addr, incr_addr, buf, | ||
221 | blocks, func->cur_blksize); | ||
222 | if (ret) | ||
223 | return ret; | ||
224 | |||
225 | remainder -= size; | ||
226 | buf += size; | ||
227 | if (incr_addr) | ||
228 | addr += size; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | /* Write the remainder using byte mode. */ | ||
233 | while (remainder > 0) { | ||
234 | size = remainder; | ||
235 | if (size > func->cur_blksize) | ||
236 | size = func->cur_blksize; | ||
237 | if (size > 512) | ||
238 | size = 512; /* maximum size for byte mode */ | ||
239 | |||
240 | ret = mmc_io_rw_extended(func->card, write, func->num, addr, | ||
241 | incr_addr, buf, 1, size); | ||
242 | if (ret) | ||
243 | return ret; | ||
244 | |||
245 | remainder -= size; | ||
246 | buf += size; | ||
247 | if (incr_addr) | ||
248 | addr += size; | ||
249 | } | ||
250 | return 0; | ||
251 | } | ||
252 | |||
192 | /** | 253 | /** |
193 | * sdio_readb - read a single byte from a SDIO function | 254 | * sdio_readb - read a single byte from a SDIO function |
194 | * @func: SDIO function to access | 255 | * @func: SDIO function to access |
@@ -252,15 +313,13 @@ EXPORT_SYMBOL_GPL(sdio_writeb); | |||
252 | * @addr: address to begin reading from | 313 | * @addr: address to begin reading from |
253 | * @count: number of bytes to read | 314 | * @count: number of bytes to read |
254 | * | 315 | * |
255 | * Reads up to 512 bytes from the address space of a given SDIO | 316 | * Reads from the address space of a given SDIO function. Return |
256 | * function. Return value indicates if the transfer succeeded or | 317 | * value indicates if the transfer succeeded or not. |
257 | * not. | ||
258 | */ | 318 | */ |
259 | int sdio_memcpy_fromio(struct sdio_func *func, void *dst, | 319 | int sdio_memcpy_fromio(struct sdio_func *func, void *dst, |
260 | unsigned int addr, int count) | 320 | unsigned int addr, int count) |
261 | { | 321 | { |
262 | return mmc_io_rw_extended(func->card, 0, func->num, addr, 0, dst, | 322 | return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count); |
263 | count); | ||
264 | } | 323 | } |
265 | EXPORT_SYMBOL_GPL(sdio_memcpy_fromio); | 324 | EXPORT_SYMBOL_GPL(sdio_memcpy_fromio); |
266 | 325 | ||
@@ -271,15 +330,13 @@ EXPORT_SYMBOL_GPL(sdio_memcpy_fromio); | |||
271 | * @src: buffer that contains the data to write | 330 | * @src: buffer that contains the data to write |
272 | * @count: number of bytes to write | 331 | * @count: number of bytes to write |
273 | * | 332 | * |
274 | * Writes up to 512 bytes to the address space of a given SDIO | 333 | * Writes to the address space of a given SDIO function. Return |
275 | * function. Return value indicates if the transfer succeeded or | 334 | * value indicates if the transfer succeeded or not. |
276 | * not. | ||
277 | */ | 335 | */ |
278 | int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr, | 336 | int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr, |
279 | void *src, int count) | 337 | void *src, int count) |
280 | { | 338 | { |
281 | return mmc_io_rw_extended(func->card, 1, func->num, addr, 0, src, | 339 | return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count); |
282 | count); | ||
283 | } | 340 | } |
284 | EXPORT_SYMBOL_GPL(sdio_memcpy_toio); | 341 | EXPORT_SYMBOL_GPL(sdio_memcpy_toio); |
285 | 342 | ||
@@ -290,15 +347,13 @@ EXPORT_SYMBOL_GPL(sdio_memcpy_toio); | |||
290 | * @addr: address of (single byte) FIFO | 347 | * @addr: address of (single byte) FIFO |
291 | * @count: number of bytes to read | 348 | * @count: number of bytes to read |
292 | * | 349 | * |
293 | * Reads up to 512 bytes from the specified FIFO of a given SDIO | 350 | * Reads from the specified FIFO of a given SDIO function. Return |
294 | * function. Return value indicates if the transfer succeeded or | 351 | * value indicates if the transfer succeeded or not. |
295 | * not. | ||
296 | */ | 352 | */ |
297 | int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr, | 353 | int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr, |
298 | int count) | 354 | int count) |
299 | { | 355 | { |
300 | return mmc_io_rw_extended(func->card, 0, func->num, addr, 1, dst, | 356 | return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count); |
301 | count); | ||
302 | } | 357 | } |
303 | 358 | ||
304 | EXPORT_SYMBOL_GPL(sdio_readsb); | 359 | EXPORT_SYMBOL_GPL(sdio_readsb); |
@@ -310,15 +365,13 @@ EXPORT_SYMBOL_GPL(sdio_readsb); | |||
310 | * @src: buffer that contains the data to write | 365 | * @src: buffer that contains the data to write |
311 | * @count: number of bytes to write | 366 | * @count: number of bytes to write |
312 | * | 367 | * |
313 | * Writes up to 512 bytes to the specified FIFO of a given SDIO | 368 | * Writes to the specified FIFO of a given SDIO function. Return |
314 | * function. Return value indicates if the transfer succeeded or | 369 | * value indicates if the transfer succeeded or not. |
315 | * not. | ||
316 | */ | 370 | */ |
317 | int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src, | 371 | int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src, |
318 | int count) | 372 | int count) |
319 | { | 373 | { |
320 | return mmc_io_rw_extended(func->card, 1, func->num, addr, 1, src, | 374 | return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count); |
321 | count); | ||
322 | } | 375 | } |
323 | EXPORT_SYMBOL_GPL(sdio_writesb); | 376 | EXPORT_SYMBOL_GPL(sdio_writesb); |
324 | 377 | ||
diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c index 4f2c77139477..98e20532452a 100644 --- a/drivers/mmc/core/sdio_ops.c +++ b/drivers/mmc/core/sdio_ops.c | |||
@@ -88,7 +88,7 @@ int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn, | |||
88 | } | 88 | } |
89 | 89 | ||
90 | int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, | 90 | int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, |
91 | unsigned addr, int bang, u8 *buf, unsigned size) | 91 | unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz) |
92 | { | 92 | { |
93 | struct mmc_request mrq; | 93 | struct mmc_request mrq; |
94 | struct mmc_command cmd; | 94 | struct mmc_command cmd; |
@@ -97,7 +97,9 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, | |||
97 | 97 | ||
98 | BUG_ON(!card); | 98 | BUG_ON(!card); |
99 | BUG_ON(fn > 7); | 99 | BUG_ON(fn > 7); |
100 | BUG_ON(size > 512); | 100 | BUG_ON(blocks == 1 && blksz > 512); |
101 | WARN_ON(blocks == 0); | ||
102 | WARN_ON(blksz == 0); | ||
101 | 103 | ||
102 | memset(&mrq, 0, sizeof(struct mmc_request)); | 104 | memset(&mrq, 0, sizeof(struct mmc_request)); |
103 | memset(&cmd, 0, sizeof(struct mmc_command)); | 105 | memset(&cmd, 0, sizeof(struct mmc_command)); |
@@ -109,18 +111,21 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, | |||
109 | cmd.opcode = SD_IO_RW_EXTENDED; | 111 | cmd.opcode = SD_IO_RW_EXTENDED; |
110 | cmd.arg = write ? 0x80000000 : 0x00000000; | 112 | cmd.arg = write ? 0x80000000 : 0x00000000; |
111 | cmd.arg |= fn << 28; | 113 | cmd.arg |= fn << 28; |
112 | cmd.arg |= bang ? 0x00000000 : 0x04000000; | 114 | cmd.arg |= incr_addr ? 0x04000000 : 0x00000000; |
113 | cmd.arg |= addr << 9; | 115 | cmd.arg |= addr << 9; |
114 | cmd.arg |= (size == 512) ? 0 : size; | 116 | if (blocks == 1 && blksz <= 512) |
117 | cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */ | ||
118 | else | ||
119 | cmd.arg |= 0x08000000 | blocks; /* block mode */ | ||
115 | cmd.flags = MMC_RSP_R5 | MMC_CMD_ADTC; | 120 | cmd.flags = MMC_RSP_R5 | MMC_CMD_ADTC; |
116 | 121 | ||
117 | data.blksz = size; | 122 | data.blksz = blksz; |
118 | data.blocks = 1; | 123 | data.blocks = blocks; |
119 | data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; | 124 | data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; |
120 | data.sg = &sg; | 125 | data.sg = &sg; |
121 | data.sg_len = 1; | 126 | data.sg_len = 1; |
122 | 127 | ||
123 | sg_init_one(&sg, buf, size); | 128 | sg_init_one(&sg, buf, blksz * blocks); |
124 | 129 | ||
125 | mmc_set_data_timeout(&data, card); | 130 | mmc_set_data_timeout(&data, card); |
126 | 131 | ||
diff --git a/drivers/mmc/core/sdio_ops.h b/drivers/mmc/core/sdio_ops.h index 1d42e4f366aa..e2e74b0d17d8 100644 --- a/drivers/mmc/core/sdio_ops.h +++ b/drivers/mmc/core/sdio_ops.h | |||
@@ -16,7 +16,7 @@ int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); | |||
16 | int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn, | 16 | int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn, |
17 | unsigned addr, u8 in, u8* out); | 17 | unsigned addr, u8 in, u8* out); |
18 | int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, | 18 | int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, |
19 | unsigned addr, int bang, u8 *data, unsigned size); | 19 | unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz); |
20 | 20 | ||
21 | #endif | 21 | #endif |
22 | 22 | ||