Lines Matching +full:transfer +full:- +full:function

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2007-2008 Pierre Ossman
21 * sdio_claim_host - exclusively claim a bus for a certain SDIO function
22 * @func: SDIO function that will be accessed
24 * Claim a bus for a set of operations. The SDIO function given
32 mmc_claim_host(func->card->host); in sdio_claim_host()
37 * sdio_release_host - release a bus for a certain SDIO function
38 * @func: SDIO function that was accessed
48 mmc_release_host(func->card->host); in sdio_release_host()
53 * sdio_enable_func - enables a SDIO function for usage
54 * @func: SDIO function to enable
56 * Powers up and activates a SDIO function so that register
66 return -EINVAL; in sdio_enable_func()
70 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg); in sdio_enable_func()
74 reg |= 1 << func->num; in sdio_enable_func()
76 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); in sdio_enable_func()
80 timeout = jiffies + msecs_to_jiffies(func->enable_timeout); in sdio_enable_func()
83 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg); in sdio_enable_func()
86 if (reg & (1 << func->num)) in sdio_enable_func()
88 ret = -ETIME; in sdio_enable_func()
104 * sdio_disable_func - disable a SDIO function
105 * @func: SDIO function to disable
107 * Powers down and deactivates a SDIO function. Register access
108 * to this function will fail until the function is reenabled.
116 return -EINVAL; in sdio_disable_func()
120 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg); in sdio_disable_func()
124 reg &= ~(1 << func->num); in sdio_disable_func()
126 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); in sdio_disable_func()
141 * sdio_set_block_size - set the block size of an SDIO function
142 * @func: SDIO function to change
145 * The default block size is the largest supported by both the function
147 * data transfer use the optimal (least) number of commands.
154 * Returns 0 on success, -EINVAL if the host does not support the
155 * requested block size, or -EIO (etc.) if one of the resultant FBR block
163 if (blksz > func->card->host->max_blk_size) in sdio_set_block_size()
164 return -EINVAL; in sdio_set_block_size()
167 blksz = min(func->max_blksize, func->card->host->max_blk_size); in sdio_set_block_size()
171 ret = mmc_io_rw_direct(func->card, 1, 0, in sdio_set_block_size()
172 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE, in sdio_set_block_size()
176 ret = mmc_io_rw_direct(func->card, 1, 0, in sdio_set_block_size()
177 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1, in sdio_set_block_size()
181 func->cur_blksize = blksz; in sdio_set_block_size()
187 * Calculate the maximum byte mode transfer size
191 unsigned mval = func->card->host->max_blk_size; in sdio_max_byte_size()
193 if (mmc_blksz_for_byte_mode(func->card)) in sdio_max_byte_size()
194 mval = min(mval, func->cur_blksize); in sdio_max_byte_size()
196 mval = min(mval, func->max_blksize); in sdio_max_byte_size()
198 if (mmc_card_broken_byte_mode_512(func->card)) in sdio_max_byte_size()
205 * This is legacy code, which needs to be re-worked some day. Basically we need
213 * the core about its problems yet, so for now we just 32-bit in _sdio_align_size()
220 * sdio_align_size - pads a transfer size to a more optimal value
221 * @func: SDIO function
222 * @sz: original transfer size
249 * If we can still do this with just a byte transfer, then in sdio_align_size()
255 if (func->card->cccr.multi_block) { in sdio_align_size()
257 * Check if the transfer is already block aligned in sdio_align_size()
259 if ((sz % func->cur_blksize) == 0) in sdio_align_size()
266 blk_sz = ((sz + func->cur_blksize - 1) / in sdio_align_size()
267 func->cur_blksize) * func->cur_blksize; in sdio_align_size()
274 if ((blk_sz % func->cur_blksize) == 0) in sdio_align_size()
281 byte_sz = _sdio_align_size(sz % func->cur_blksize); in sdio_align_size()
283 blk_sz = sz / func->cur_blksize; in sdio_align_size()
284 return blk_sz * func->cur_blksize + byte_sz; in sdio_align_size()
313 /* Split an arbitrarily sized data transfer into several
322 if (!func || (func->num > 7)) in sdio_io_rw_ext_helper()
323 return -EINVAL; in sdio_io_rw_ext_helper()
325 /* Do the bulk of the transfer using block mode (if supported). */ in sdio_io_rw_ext_helper()
326 if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) { in sdio_io_rw_ext_helper()
327 /* Blocks per command is limited by host count, host transfer in sdio_io_rw_ext_helper()
329 max_blocks = min(func->card->host->max_blk_count, 511u); in sdio_io_rw_ext_helper()
331 while (remainder >= func->cur_blksize) { in sdio_io_rw_ext_helper()
334 blocks = remainder / func->cur_blksize; in sdio_io_rw_ext_helper()
337 size = blocks * func->cur_blksize; in sdio_io_rw_ext_helper()
339 ret = mmc_io_rw_extended(func->card, write, in sdio_io_rw_ext_helper()
340 func->num, addr, incr_addr, buf, in sdio_io_rw_ext_helper()
341 blocks, func->cur_blksize); in sdio_io_rw_ext_helper()
345 remainder -= size; in sdio_io_rw_ext_helper()
357 ret = mmc_io_rw_extended(func->card, write, func->num, addr, in sdio_io_rw_ext_helper()
362 remainder -= size; in sdio_io_rw_ext_helper()
371 * sdio_readb - read a single byte from a SDIO function
372 * @func: SDIO function to access
374 * @err_ret: optional status value from transfer
377 * function. If there is a problem reading the address, 0xff
387 *err_ret = -EINVAL; in sdio_readb()
391 ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val); in sdio_readb()
402 * sdio_writeb - write a single byte to a SDIO function
403 * @func: SDIO function to access
406 * @err_ret: optional status value from transfer
409 * function. @err_ret will contain the status of the actual
410 * transfer.
418 *err_ret = -EINVAL; in sdio_writeb()
422 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL); in sdio_writeb()
429 * sdio_writeb_readb - write and read a byte from SDIO function
430 * @func: SDIO function to access
433 * @err_ret: optional status value from transfer
435 * Performs a RAW (Read after Write) operation as defined by SDIO spec -
436 * single byte is written to address space of a given SDIO function and
447 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, in sdio_writeb_readb()
459 * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
460 * @func: SDIO function to access
465 * Reads from the address space of a given SDIO function. Return
466 * value indicates if the transfer succeeded or not.
476 * sdio_memcpy_toio - write a chunk of memory to a SDIO function
477 * @func: SDIO function to access
482 * Writes to the address space of a given SDIO function. Return
483 * value indicates if the transfer succeeded or not.
493 * sdio_readsb - read from a FIFO on a SDIO function
494 * @func: SDIO function to access
499 * Reads from the specified FIFO of a given SDIO function. Return
500 * value indicates if the transfer succeeded or not.
510 * sdio_writesb - write to a FIFO of a SDIO function
511 * @func: SDIO function to access
516 * Writes to the specified FIFO of a given SDIO function. Return
517 * value indicates if the transfer succeeded or not.
527 * sdio_readw - read a 16 bit integer from a SDIO function
528 * @func: SDIO function to access
530 * @err_ret: optional status value from transfer
533 * function. If there is a problem reading the address, 0xffff
540 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2); in sdio_readw()
546 return le16_to_cpup((__le16 *)func->tmpbuf); in sdio_readw()
551 * sdio_writew - write a 16 bit integer to a SDIO function
552 * @func: SDIO function to access
555 * @err_ret: optional status value from transfer
558 * function. @err_ret will contain the status of the actual
559 * transfer.
565 *(__le16 *)func->tmpbuf = cpu_to_le16(b); in sdio_writew()
567 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2); in sdio_writew()
574 * sdio_readl - read a 32 bit integer from a SDIO function
575 * @func: SDIO function to access
577 * @err_ret: optional status value from transfer
580 * function. If there is a problem reading the address,
588 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4); in sdio_readl()
594 return le32_to_cpup((__le32 *)func->tmpbuf); in sdio_readl()
599 * sdio_writel - write a 32 bit integer to a SDIO function
600 * @func: SDIO function to access
603 * @err_ret: optional status value from transfer
606 * function. @err_ret will contain the status of the actual
607 * transfer.
613 *(__le32 *)func->tmpbuf = cpu_to_le32(b); in sdio_writel()
615 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4); in sdio_writel()
622 * sdio_f0_readb - read a single byte from SDIO function 0
623 * @func: an SDIO function of the card
625 * @err_ret: optional status value from transfer
627 * Reads a single byte from the address space of SDIO function 0.
639 *err_ret = -EINVAL; in sdio_f0_readb()
643 ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val); in sdio_f0_readb()
654 * sdio_f0_writeb - write a single byte to SDIO function 0
655 * @func: an SDIO function of the card
658 * @err_ret: optional status value from transfer
660 * Writes a single byte to the address space of SDIO function 0.
661 * @err_ret will contain the status of the actual transfer.
663 * Only writes to the vendor specific CCCR registers (0xF0 -
664 * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
674 *err_ret = -EINVAL; in sdio_f0_writeb()
678 if ((addr < 0xF0 || addr > 0xFF) && (!mmc_card_lenient_fn0(func->card))) { in sdio_f0_writeb()
680 *err_ret = -EINVAL; in sdio_f0_writeb()
684 ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL); in sdio_f0_writeb()
691 * sdio_get_host_pm_caps - get host power management capabilities
692 * @func: SDIO function attached to host
695 * features supported by the host controller that the card function
697 * to be claimed, nor the function active, for this information to be
705 return func->card->host->pm_caps; in sdio_get_host_pm_caps()
710 * sdio_set_host_pm_flags - set wanted host power management capabilities
711 * @func: SDIO function attached to host
717 * the function driver is called, and must contain only bits that
719 * The host doesn't need to be claimed, nor the function active,
727 return -EINVAL; in sdio_set_host_pm_flags()
729 host = func->card->host; in sdio_set_host_pm_flags()
731 if (flags & ~host->pm_caps) in sdio_set_host_pm_flags()
732 return -EINVAL; in sdio_set_host_pm_flags()
734 /* function suspend methods are serialized, hence no lock needed */ in sdio_set_host_pm_flags()
735 host->pm_flags |= flags; in sdio_set_host_pm_flags()
741 * sdio_retune_crc_disable - temporarily disable retuning on CRC errors
742 * @func: SDIO function attached to host
746 * transitioning between power states), an SDIO function driver can
747 * call this function to temporarily disable the SD/MMC core behavior of
750 * This function should be called while the host is claimed and the host
753 * - sdio_claim_host()
754 * - sdio_retune_crc_disable()
755 * - some number of calls like sdio_writeb() and sdio_readb()
756 * - sdio_retune_crc_enable()
757 * - sdio_release_host()
761 func->card->host->retune_crc_disable = true; in sdio_retune_crc_disable()
766 * sdio_retune_crc_enable - re-enable retuning on CRC errors
767 * @func: SDIO function attached to host
773 func->card->host->retune_crc_disable = false; in sdio_retune_crc_enable()
778 * sdio_retune_hold_now - start deferring retuning requests till release
779 * @func: SDIO function attached to host
781 * This function can be called if it's currently a bad time to do
786 * This function could be useful if an SDIO card is in a power state
789 * this function since (presumably) the retuning request we might be
792 * This function should be called while the host is claimed.
796 mmc_retune_hold_now(func->card->host); in sdio_retune_hold_now()
801 * sdio_retune_release - signal that it's OK to retune now
802 * @func: SDIO function attached to host
805 * function won't make a retune happen right away but will allow
808 * This function should be called while the host is claimed.
812 mmc_retune_release(func->card->host); in sdio_retune_release()