aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core/sdio_io.c
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@csr.com>2007-08-08 09:24:21 -0400
committerPierre Ossman <drzeus@drzeus.cx>2007-09-23 15:21:32 -0400
commiteb6594689226663968ef0a9fd71ec5e1e4e04f9c (patch)
treed523962b81a2b5f4a55543d4342daaaebc5d5162 /drivers/mmc/core/sdio_io.c
parent9a08f82b3cc522f727ace580a2aaee5402435bc8 (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/sdio_io.c')
-rw-r--r--drivers/mmc/core/sdio_io.c93
1 files changed, 73 insertions, 20 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
190EXPORT_SYMBOL_GPL(sdio_set_block_size); 190EXPORT_SYMBOL_GPL(sdio_set_block_size);
191 191
192/* Split an arbitrarily sized data transfer into several
193 * IO_RW_EXTENDED commands. */
194static 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 */
259int sdio_memcpy_fromio(struct sdio_func *func, void *dst, 319int 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}
265EXPORT_SYMBOL_GPL(sdio_memcpy_fromio); 324EXPORT_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 */
278int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr, 336int 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}
284EXPORT_SYMBOL_GPL(sdio_memcpy_toio); 341EXPORT_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 */
297int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr, 353int 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
304EXPORT_SYMBOL_GPL(sdio_readsb); 359EXPORT_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 */
317int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src, 371int 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}
323EXPORT_SYMBOL_GPL(sdio_writesb); 376EXPORT_SYMBOL_GPL(sdio_writesb);
324 377