Lines Matching +full:no +full:- +full:sdio

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2007-2008 Pierre Ossman
12 #include <linux/mmc/sdio.h>
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()
68 pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func)); 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()
93 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func)); in sdio_enable_func()
98 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func)); 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
116 return -EINVAL; in sdio_disable_func()
118 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func)); 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()
130 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func)); in sdio_disable_func()
135 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func)); in sdio_disable_func()
141 * sdio_set_block_size - set the block size of an SDIO function
142 * @func: SDIO function to change
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()
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
206 * to take into account the properties of the host, as to enable the SDIO func
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
255 if (func->card->cccr.multi_block) { 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()
322 if (!func || (func->num > 7)) in sdio_io_rw_ext_helper()
323 return -EINVAL; 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()
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
376 * Reads a single byte from the address space of a given SDIO
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
408 * Writes a single byte to the address space of a given SDIO
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
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
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
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
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
527 * sdio_readw - read a 16 bit integer from a SDIO function
528 * @func: SDIO function to access
532 * Reads a 16 bit integer from the address space of a given SDIO
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
557 * Writes a 16 bit integer to the address space of a given SDIO
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
579 * Reads a 32 bit integer from the address space of a given SDIO
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
605 * Writes a 32 bit integer to the address space of a given SDIO
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
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
660 * Writes a single byte to the address space of SDIO function 0.
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
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
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
744 * If the SDIO card is known to be in a state where it might produce
746 * transitioning between power states), an SDIO function driver can
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
782 * a retune of the SDIO card. Retune requests made during this time
786 * This function could be useful if an SDIO card is in a power state
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
812 mmc_retune_release(func->card->host); in sdio_retune_release()