1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * linux/drivers/mmc/core/sdio_io.c 4 * 5 * Copyright 2007-2008 Pierre Ossman 6 */ 7 8 #include <linux/export.h> 9 #include <linux/kernel.h> 10 #include <linux/mmc/host.h> 11 #include <linux/mmc/card.h> 12 #include <linux/mmc/sdio.h> 13 #include <linux/mmc/sdio_func.h> 14 15 #include "sdio_ops.h" 16 #include "core.h" 17 #include "card.h" 18 #include "host.h" 19 20 /** 21 * sdio_claim_host - exclusively claim a bus for a certain SDIO function 22 * @func: SDIO function that will be accessed 23 * 24 * Claim a bus for a set of operations. The SDIO function given 25 * is used to figure out which bus is relevant. 26 */ 27 void sdio_claim_host(struct sdio_func *func) 28 { 29 if (WARN_ON(!func)) 30 return; 31 32 mmc_claim_host(func->card->host); 33 } 34 EXPORT_SYMBOL_GPL(sdio_claim_host); 35 36 /** 37 * sdio_release_host - release a bus for a certain SDIO function 38 * @func: SDIO function that was accessed 39 * 40 * Release a bus, allowing others to claim the bus for their 41 * operations. 42 */ 43 void sdio_release_host(struct sdio_func *func) 44 { 45 if (WARN_ON(!func)) 46 return; 47 48 mmc_release_host(func->card->host); 49 } 50 EXPORT_SYMBOL_GPL(sdio_release_host); 51 52 /** 53 * sdio_enable_func - enables a SDIO function for usage 54 * @func: SDIO function to enable 55 * 56 * Powers up and activates a SDIO function so that register 57 * access is possible. 58 */ 59 int sdio_enable_func(struct sdio_func *func) 60 { 61 int ret; 62 unsigned char reg; 63 unsigned long timeout; 64 65 if (!func) 66 return -EINVAL; 67 68 pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func)); 69 70 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®); 71 if (ret) 72 goto err; 73 74 reg |= 1 << func->num; 75 76 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); 77 if (ret) 78 goto err; 79 80 timeout = jiffies + msecs_to_jiffies(func->enable_timeout); 81 82 while (1) { 83 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, ®); 84 if (ret) 85 goto err; 86 if (reg & (1 << func->num)) 87 break; 88 ret = -ETIME; 89 if (time_after(jiffies, timeout)) 90 goto err; 91 } 92 93 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func)); 94 95 return 0; 96 97 err: 98 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func)); 99 return ret; 100 } 101 EXPORT_SYMBOL_GPL(sdio_enable_func); 102 103 /** 104 * sdio_disable_func - disable a SDIO function 105 * @func: SDIO function to disable 106 * 107 * Powers down and deactivates a SDIO function. Register access 108 * to this function will fail until the function is reenabled. 109 */ 110 int sdio_disable_func(struct sdio_func *func) 111 { 112 int ret; 113 unsigned char reg; 114 115 if (!func) 116 return -EINVAL; 117 118 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func)); 119 120 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®); 121 if (ret) 122 goto err; 123 124 reg &= ~(1 << func->num); 125 126 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); 127 if (ret) 128 goto err; 129 130 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func)); 131 132 return 0; 133 134 err: 135 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func)); 136 return ret; 137 } 138 EXPORT_SYMBOL_GPL(sdio_disable_func); 139 140 /** 141 * sdio_set_block_size - set the block size of an SDIO function 142 * @func: SDIO function to change 143 * @blksz: new block size or 0 to use the default. 144 * 145 * The default block size is the largest supported by both the function 146 * and the host, with a maximum of 512 to ensure that arbitrarily sized 147 * data transfer use the optimal (least) number of commands. 148 * 149 * A driver may call this to override the default block size set by the 150 * core. This can be used to set a block size greater than the maximum 151 * that reported by the card; it is the driver's responsibility to ensure 152 * it uses a value that the card supports. 153 * 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 156 * size register writes failed. 157 * 158 */ 159 int sdio_set_block_size(struct sdio_func *func, unsigned blksz) 160 { 161 int ret; 162 163 if (blksz > func->card->host->max_blk_size) 164 return -EINVAL; 165 166 if (blksz == 0) 167 blksz = min3(func->max_blksize, func->card->host->max_blk_size, 512u); 168 169 ret = mmc_io_rw_direct(func->card, 1, 0, 170 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE, 171 blksz & 0xff, NULL); 172 if (ret) 173 return ret; 174 ret = mmc_io_rw_direct(func->card, 1, 0, 175 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1, 176 (blksz >> 8) & 0xff, NULL); 177 if (ret) 178 return ret; 179 func->cur_blksize = blksz; 180 return 0; 181 } 182 EXPORT_SYMBOL_GPL(sdio_set_block_size); 183 184 /* 185 * Calculate the maximum byte mode transfer size 186 */ 187 static inline unsigned int sdio_max_byte_size(struct sdio_func *func) 188 { 189 unsigned mval = func->card->host->max_blk_size; 190 191 if (mmc_blksz_for_byte_mode(func->card)) 192 mval = min(mval, func->cur_blksize); 193 else 194 mval = min(mval, func->max_blksize); 195 196 if (mmc_card_broken_byte_mode_512(func->card)) 197 return min(mval, 511u); 198 199 return min(mval, 512u); /* maximum size for byte mode */ 200 } 201 202 /* 203 * This is legacy code, which needs to be re-worked some day. Basically we need 204 * to take into account the properties of the host, as to enable the SDIO func 205 * driver layer to allocate optimal buffers. 206 */ 207 static inline unsigned int _sdio_align_size(unsigned int sz) 208 { 209 /* 210 * FIXME: We don't have a system for the controller to tell 211 * the core about its problems yet, so for now we just 32-bit 212 * align the size. 213 */ 214 return ALIGN(sz, 4); 215 } 216 217 /** 218 * sdio_align_size - pads a transfer size to a more optimal value 219 * @func: SDIO function 220 * @sz: original transfer size 221 * 222 * Pads the original data size with a number of extra bytes in 223 * order to avoid controller bugs and/or performance hits 224 * (e.g. some controllers revert to PIO for certain sizes). 225 * 226 * If possible, it will also adjust the size so that it can be 227 * handled in just a single request. 228 * 229 * Returns the improved size, which might be unmodified. 230 */ 231 unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) 232 { 233 unsigned int orig_sz; 234 unsigned int blk_sz, byte_sz; 235 unsigned chunk_sz; 236 237 orig_sz = sz; 238 239 /* 240 * Do a first check with the controller, in case it 241 * wants to increase the size up to a point where it 242 * might need more than one block. 243 */ 244 sz = _sdio_align_size(sz); 245 246 /* 247 * If we can still do this with just a byte transfer, then 248 * we're done. 249 */ 250 if (sz <= sdio_max_byte_size(func)) 251 return sz; 252 253 if (func->card->cccr.multi_block) { 254 /* 255 * Check if the transfer is already block aligned 256 */ 257 if ((sz % func->cur_blksize) == 0) 258 return sz; 259 260 /* 261 * Realign it so that it can be done with one request, 262 * and recheck if the controller still likes it. 263 */ 264 blk_sz = ((sz + func->cur_blksize - 1) / 265 func->cur_blksize) * func->cur_blksize; 266 blk_sz = _sdio_align_size(blk_sz); 267 268 /* 269 * This value is only good if it is still just 270 * one request. 271 */ 272 if ((blk_sz % func->cur_blksize) == 0) 273 return blk_sz; 274 275 /* 276 * We failed to do one request, but at least try to 277 * pad the remainder properly. 278 */ 279 byte_sz = _sdio_align_size(sz % func->cur_blksize); 280 if (byte_sz <= sdio_max_byte_size(func)) { 281 blk_sz = sz / func->cur_blksize; 282 return blk_sz * func->cur_blksize + byte_sz; 283 } 284 } else { 285 /* 286 * We need multiple requests, so first check that the 287 * controller can handle the chunk size; 288 */ 289 chunk_sz = _sdio_align_size(sdio_max_byte_size(func)); 290 if (chunk_sz == sdio_max_byte_size(func)) { 291 /* 292 * Fix up the size of the remainder (if any) 293 */ 294 byte_sz = orig_sz % chunk_sz; 295 if (byte_sz) { 296 byte_sz = _sdio_align_size(byte_sz); 297 } 298 299 return (orig_sz / chunk_sz) * chunk_sz + byte_sz; 300 } 301 } 302 303 /* 304 * The controller is simply incapable of transferring the size 305 * we want in decent manner, so just return the original size. 306 */ 307 return orig_sz; 308 } 309 EXPORT_SYMBOL_GPL(sdio_align_size); 310 311 /* Split an arbitrarily sized data transfer into several 312 * IO_RW_EXTENDED commands. */ 313 static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, 314 unsigned addr, int incr_addr, u8 *buf, unsigned size) 315 { 316 unsigned remainder = size; 317 unsigned max_blocks; 318 int ret; 319 320 if (!func || (func->num > 7)) 321 return -EINVAL; 322 323 /* Do the bulk of the transfer using block mode (if supported). */ 324 if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) { 325 /* Blocks per command is limited by host count, host transfer 326 * size and the maximum for IO_RW_EXTENDED of 511 blocks. */ 327 max_blocks = min(func->card->host->max_blk_count, 511u); 328 329 while (remainder >= func->cur_blksize) { 330 unsigned blocks; 331 332 blocks = remainder / func->cur_blksize; 333 if (blocks > max_blocks) 334 blocks = max_blocks; 335 size = blocks * func->cur_blksize; 336 337 ret = mmc_io_rw_extended(func->card, write, 338 func->num, addr, incr_addr, buf, 339 blocks, func->cur_blksize); 340 if (ret) 341 return ret; 342 343 remainder -= size; 344 buf += size; 345 if (incr_addr) 346 addr += size; 347 } 348 } 349 350 /* Write the remainder using byte mode. */ 351 while (remainder > 0) { 352 size = min(remainder, sdio_max_byte_size(func)); 353 354 /* Indicate byte mode by setting "blocks" = 0 */ 355 ret = mmc_io_rw_extended(func->card, write, func->num, addr, 356 incr_addr, buf, 0, size); 357 if (ret) 358 return ret; 359 360 remainder -= size; 361 buf += size; 362 if (incr_addr) 363 addr += size; 364 } 365 return 0; 366 } 367 368 /** 369 * sdio_readb - read a single byte from a SDIO function 370 * @func: SDIO function to access 371 * @addr: address to read 372 * @err_ret: optional status value from transfer 373 * 374 * Reads a single byte from the address space of a given SDIO 375 * function. If there is a problem reading the address, 0xff 376 * is returned and @err_ret will contain the error code. 377 */ 378 u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret) 379 { 380 int ret; 381 u8 val; 382 383 if (!func) { 384 if (err_ret) 385 *err_ret = -EINVAL; 386 return 0xFF; 387 } 388 389 ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val); 390 if (err_ret) 391 *err_ret = ret; 392 if (ret) 393 return 0xFF; 394 395 return val; 396 } 397 EXPORT_SYMBOL_GPL(sdio_readb); 398 399 /** 400 * sdio_writeb - write a single byte to a SDIO function 401 * @func: SDIO function to access 402 * @b: byte to write 403 * @addr: address to write to 404 * @err_ret: optional status value from transfer 405 * 406 * Writes a single byte to the address space of a given SDIO 407 * function. @err_ret will contain the status of the actual 408 * transfer. 409 */ 410 void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret) 411 { 412 int ret; 413 414 if (!func) { 415 if (err_ret) 416 *err_ret = -EINVAL; 417 return; 418 } 419 420 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL); 421 if (err_ret) 422 *err_ret = ret; 423 } 424 EXPORT_SYMBOL_GPL(sdio_writeb); 425 426 /** 427 * sdio_writeb_readb - write and read a byte from SDIO function 428 * @func: SDIO function to access 429 * @write_byte: byte to write 430 * @addr: address to write to 431 * @err_ret: optional status value from transfer 432 * 433 * Performs a RAW (Read after Write) operation as defined by SDIO spec - 434 * single byte is written to address space of a given SDIO function and 435 * response is read back from the same address, both using single request. 436 * If there is a problem with the operation, 0xff is returned and 437 * @err_ret will contain the error code. 438 */ 439 u8 sdio_writeb_readb(struct sdio_func *func, u8 write_byte, 440 unsigned int addr, int *err_ret) 441 { 442 int ret; 443 u8 val; 444 445 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, 446 write_byte, &val); 447 if (err_ret) 448 *err_ret = ret; 449 if (ret) 450 return 0xff; 451 452 return val; 453 } 454 EXPORT_SYMBOL_GPL(sdio_writeb_readb); 455 456 /** 457 * sdio_memcpy_fromio - read a chunk of memory from a SDIO function 458 * @func: SDIO function to access 459 * @dst: buffer to store the data 460 * @addr: address to begin reading from 461 * @count: number of bytes to read 462 * 463 * Reads from the address space of a given SDIO function. Return 464 * value indicates if the transfer succeeded or not. 465 */ 466 int sdio_memcpy_fromio(struct sdio_func *func, void *dst, 467 unsigned int addr, int count) 468 { 469 return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count); 470 } 471 EXPORT_SYMBOL_GPL(sdio_memcpy_fromio); 472 473 /** 474 * sdio_memcpy_toio - write a chunk of memory to a SDIO function 475 * @func: SDIO function to access 476 * @addr: address to start writing to 477 * @src: buffer that contains the data to write 478 * @count: number of bytes to write 479 * 480 * Writes to the address space of a given SDIO function. Return 481 * value indicates if the transfer succeeded or not. 482 */ 483 int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr, 484 void *src, int count) 485 { 486 return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count); 487 } 488 EXPORT_SYMBOL_GPL(sdio_memcpy_toio); 489 490 /** 491 * sdio_readsb - read from a FIFO on a SDIO function 492 * @func: SDIO function to access 493 * @dst: buffer to store the data 494 * @addr: address of (single byte) FIFO 495 * @count: number of bytes to read 496 * 497 * Reads from the specified FIFO of a given SDIO function. Return 498 * value indicates if the transfer succeeded or not. 499 */ 500 int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr, 501 int count) 502 { 503 return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count); 504 } 505 EXPORT_SYMBOL_GPL(sdio_readsb); 506 507 /** 508 * sdio_writesb - write to a FIFO of a SDIO function 509 * @func: SDIO function to access 510 * @addr: address of (single byte) FIFO 511 * @src: buffer that contains the data to write 512 * @count: number of bytes to write 513 * 514 * Writes to the specified FIFO of a given SDIO function. Return 515 * value indicates if the transfer succeeded or not. 516 */ 517 int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src, 518 int count) 519 { 520 return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count); 521 } 522 EXPORT_SYMBOL_GPL(sdio_writesb); 523 524 /** 525 * sdio_readw - read a 16 bit integer from a SDIO function 526 * @func: SDIO function to access 527 * @addr: address to read 528 * @err_ret: optional status value from transfer 529 * 530 * Reads a 16 bit integer from the address space of a given SDIO 531 * function. If there is a problem reading the address, 0xffff 532 * is returned and @err_ret will contain the error code. 533 */ 534 u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret) 535 { 536 int ret; 537 538 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2); 539 if (err_ret) 540 *err_ret = ret; 541 if (ret) 542 return 0xFFFF; 543 544 return le16_to_cpup((__le16 *)func->tmpbuf); 545 } 546 EXPORT_SYMBOL_GPL(sdio_readw); 547 548 /** 549 * sdio_writew - write a 16 bit integer to a SDIO function 550 * @func: SDIO function to access 551 * @b: integer to write 552 * @addr: address to write to 553 * @err_ret: optional status value from transfer 554 * 555 * Writes a 16 bit integer to the address space of a given SDIO 556 * function. @err_ret will contain the status of the actual 557 * transfer. 558 */ 559 void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret) 560 { 561 int ret; 562 563 *(__le16 *)func->tmpbuf = cpu_to_le16(b); 564 565 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2); 566 if (err_ret) 567 *err_ret = ret; 568 } 569 EXPORT_SYMBOL_GPL(sdio_writew); 570 571 /** 572 * sdio_readl - read a 32 bit integer from a SDIO function 573 * @func: SDIO function to access 574 * @addr: address to read 575 * @err_ret: optional status value from transfer 576 * 577 * Reads a 32 bit integer from the address space of a given SDIO 578 * function. If there is a problem reading the address, 579 * 0xffffffff is returned and @err_ret will contain the error 580 * code. 581 */ 582 u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret) 583 { 584 int ret; 585 586 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4); 587 if (err_ret) 588 *err_ret = ret; 589 if (ret) 590 return 0xFFFFFFFF; 591 592 return le32_to_cpup((__le32 *)func->tmpbuf); 593 } 594 EXPORT_SYMBOL_GPL(sdio_readl); 595 596 /** 597 * sdio_writel - write a 32 bit integer to a SDIO function 598 * @func: SDIO function to access 599 * @b: integer to write 600 * @addr: address to write to 601 * @err_ret: optional status value from transfer 602 * 603 * Writes a 32 bit integer to the address space of a given SDIO 604 * function. @err_ret will contain the status of the actual 605 * transfer. 606 */ 607 void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret) 608 { 609 int ret; 610 611 *(__le32 *)func->tmpbuf = cpu_to_le32(b); 612 613 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4); 614 if (err_ret) 615 *err_ret = ret; 616 } 617 EXPORT_SYMBOL_GPL(sdio_writel); 618 619 /** 620 * sdio_f0_readb - read a single byte from SDIO function 0 621 * @func: an SDIO function of the card 622 * @addr: address to read 623 * @err_ret: optional status value from transfer 624 * 625 * Reads a single byte from the address space of SDIO function 0. 626 * If there is a problem reading the address, 0xff is returned 627 * and @err_ret will contain the error code. 628 */ 629 unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr, 630 int *err_ret) 631 { 632 int ret; 633 unsigned char val; 634 635 if (!func) { 636 if (err_ret) 637 *err_ret = -EINVAL; 638 return 0xFF; 639 } 640 641 ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val); 642 if (err_ret) 643 *err_ret = ret; 644 if (ret) 645 return 0xFF; 646 647 return val; 648 } 649 EXPORT_SYMBOL_GPL(sdio_f0_readb); 650 651 /** 652 * sdio_f0_writeb - write a single byte to SDIO function 0 653 * @func: an SDIO function of the card 654 * @b: byte to write 655 * @addr: address to write to 656 * @err_ret: optional status value from transfer 657 * 658 * Writes a single byte to the address space of SDIO function 0. 659 * @err_ret will contain the status of the actual transfer. 660 * 661 * Only writes to the vendor specific CCCR registers (0xF0 - 662 * 0xFF) are permiited; @err_ret will be set to -EINVAL for * 663 * writes outside this range. 664 */ 665 void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr, 666 int *err_ret) 667 { 668 int ret; 669 670 if (!func) { 671 if (err_ret) 672 *err_ret = -EINVAL; 673 return; 674 } 675 676 if ((addr < 0xF0 || addr > 0xFF) && (!mmc_card_lenient_fn0(func->card))) { 677 if (err_ret) 678 *err_ret = -EINVAL; 679 return; 680 } 681 682 ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL); 683 if (err_ret) 684 *err_ret = ret; 685 } 686 EXPORT_SYMBOL_GPL(sdio_f0_writeb); 687 688 /** 689 * sdio_get_host_pm_caps - get host power management capabilities 690 * @func: SDIO function attached to host 691 * 692 * Returns a capability bitmask corresponding to power management 693 * features supported by the host controller that the card function 694 * might rely upon during a system suspend. The host doesn't need 695 * to be claimed, nor the function active, for this information to be 696 * obtained. 697 */ 698 mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func) 699 { 700 if (!func) 701 return 0; 702 703 return func->card->host->pm_caps; 704 } 705 EXPORT_SYMBOL_GPL(sdio_get_host_pm_caps); 706 707 /** 708 * sdio_set_host_pm_flags - set wanted host power management capabilities 709 * @func: SDIO function attached to host 710 * @flags: Power Management flags to set 711 * 712 * Set a capability bitmask corresponding to wanted host controller 713 * power management features for the upcoming suspend state. 714 * This must be called, if needed, each time the suspend method of 715 * the function driver is called, and must contain only bits that 716 * were returned by sdio_get_host_pm_caps(). 717 * The host doesn't need to be claimed, nor the function active, 718 * for this information to be set. 719 */ 720 int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags) 721 { 722 struct mmc_host *host; 723 724 if (!func) 725 return -EINVAL; 726 727 host = func->card->host; 728 729 if (flags & ~host->pm_caps) 730 return -EINVAL; 731 732 /* function suspend methods are serialized, hence no lock needed */ 733 host->pm_flags |= flags; 734 return 0; 735 } 736 EXPORT_SYMBOL_GPL(sdio_set_host_pm_flags); 737 738 /** 739 * sdio_retune_crc_disable - temporarily disable retuning on CRC errors 740 * @func: SDIO function attached to host 741 * 742 * If the SDIO card is known to be in a state where it might produce 743 * CRC errors on the bus in response to commands (like if we know it is 744 * transitioning between power states), an SDIO function driver can 745 * call this function to temporarily disable the SD/MMC core behavior of 746 * triggering an automatic retuning. 747 * 748 * This function should be called while the host is claimed and the host 749 * should remain claimed until sdio_retune_crc_enable() is called. 750 * Specifically, the expected sequence of calls is: 751 * - sdio_claim_host() 752 * - sdio_retune_crc_disable() 753 * - some number of calls like sdio_writeb() and sdio_readb() 754 * - sdio_retune_crc_enable() 755 * - sdio_release_host() 756 */ 757 void sdio_retune_crc_disable(struct sdio_func *func) 758 { 759 func->card->host->retune_crc_disable = true; 760 } 761 EXPORT_SYMBOL_GPL(sdio_retune_crc_disable); 762 763 /** 764 * sdio_retune_crc_enable - re-enable retuning on CRC errors 765 * @func: SDIO function attached to host 766 * 767 * This is the complement to sdio_retune_crc_disable(). 768 */ 769 void sdio_retune_crc_enable(struct sdio_func *func) 770 { 771 func->card->host->retune_crc_disable = false; 772 } 773 EXPORT_SYMBOL_GPL(sdio_retune_crc_enable); 774 775 /** 776 * sdio_retune_hold_now - start deferring retuning requests till release 777 * @func: SDIO function attached to host 778 * 779 * This function can be called if it's currently a bad time to do 780 * a retune of the SDIO card. Retune requests made during this time 781 * will be held and we'll actually do the retune sometime after the 782 * release. 783 * 784 * This function could be useful if an SDIO card is in a power state 785 * where it can respond to a small subset of commands that doesn't 786 * include the retuning command. Care should be taken when using 787 * this function since (presumably) the retuning request we might be 788 * deferring was made for a good reason. 789 * 790 * This function should be called while the host is claimed. 791 */ 792 void sdio_retune_hold_now(struct sdio_func *func) 793 { 794 mmc_retune_hold_now(func->card->host); 795 } 796 EXPORT_SYMBOL_GPL(sdio_retune_hold_now); 797 798 /** 799 * sdio_retune_release - signal that it's OK to retune now 800 * @func: SDIO function attached to host 801 * 802 * This is the complement to sdio_retune_hold_now(). Calling this 803 * function won't make a retune happen right away but will allow 804 * them to be scheduled normally. 805 * 806 * This function should be called while the host is claimed. 807 */ 808 void sdio_retune_release(struct sdio_func *func) 809 { 810 mmc_retune_release(func->card->host); 811 } 812 EXPORT_SYMBOL_GPL(sdio_retune_release); 813