.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/drivers/mmc/sdio.c |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2006-2007 Pierre Ossman |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or (at |
---|
9 | | - * your option) any later version. |
---|
10 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <linux/err.h> |
---|
13 | | -#include <linux/module.h> |
---|
14 | 9 | #include <linux/pm_runtime.h> |
---|
15 | 10 | |
---|
16 | 11 | #include <linux/mmc/host.h> |
---|
.. | .. |
---|
31 | 26 | #include "sd_ops.h" |
---|
32 | 27 | #include "sdio_ops.h" |
---|
33 | 28 | #include "sdio_cis.h" |
---|
| 29 | + |
---|
| 30 | +MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor); |
---|
| 31 | +MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device); |
---|
| 32 | +MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev); |
---|
| 33 | +MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr); |
---|
| 34 | +MMC_DEV_ATTR(rca, "0x%04x\n", card->rca); |
---|
| 35 | + |
---|
| 36 | +#define sdio_info_attr(num) \ |
---|
| 37 | +static ssize_t info##num##_show(struct device *dev, struct device_attribute *attr, char *buf) \ |
---|
| 38 | +{ \ |
---|
| 39 | + struct mmc_card *card = mmc_dev_to_card(dev); \ |
---|
| 40 | + \ |
---|
| 41 | + if (num > card->num_info) \ |
---|
| 42 | + return -ENODATA; \ |
---|
| 43 | + if (!card->info[num-1][0]) \ |
---|
| 44 | + return 0; \ |
---|
| 45 | + return sprintf(buf, "%s\n", card->info[num-1]); \ |
---|
| 46 | +} \ |
---|
| 47 | +static DEVICE_ATTR_RO(info##num) |
---|
| 48 | + |
---|
| 49 | +sdio_info_attr(1); |
---|
| 50 | +sdio_info_attr(2); |
---|
| 51 | +sdio_info_attr(3); |
---|
| 52 | +sdio_info_attr(4); |
---|
| 53 | + |
---|
| 54 | +static struct attribute *sdio_std_attrs[] = { |
---|
| 55 | + &dev_attr_vendor.attr, |
---|
| 56 | + &dev_attr_device.attr, |
---|
| 57 | + &dev_attr_revision.attr, |
---|
| 58 | + &dev_attr_info1.attr, |
---|
| 59 | + &dev_attr_info2.attr, |
---|
| 60 | + &dev_attr_info3.attr, |
---|
| 61 | + &dev_attr_info4.attr, |
---|
| 62 | + &dev_attr_ocr.attr, |
---|
| 63 | + &dev_attr_rca.attr, |
---|
| 64 | + NULL, |
---|
| 65 | +}; |
---|
| 66 | +ATTRIBUTE_GROUPS(sdio_std); |
---|
| 67 | + |
---|
| 68 | +static struct device_type sdio_type = { |
---|
| 69 | + .groups = sdio_std_groups, |
---|
| 70 | +}; |
---|
34 | 71 | |
---|
35 | 72 | static int sdio_read_fbr(struct sdio_func *func) |
---|
36 | 73 | { |
---|
.. | .. |
---|
163 | 200 | if (mmc_host_uhs(card->host)) { |
---|
164 | 201 | if (data & SDIO_UHS_DDR50) |
---|
165 | 202 | card->sw_caps.sd3_bus_mode |
---|
166 | | - |= SD_MODE_UHS_DDR50; |
---|
| 203 | + |= SD_MODE_UHS_DDR50 | SD_MODE_UHS_SDR50 |
---|
| 204 | + | SD_MODE_UHS_SDR25 | SD_MODE_UHS_SDR12; |
---|
167 | 205 | |
---|
168 | 206 | if (data & SDIO_UHS_SDR50) |
---|
169 | 207 | card->sw_caps.sd3_bus_mode |
---|
170 | | - |= SD_MODE_UHS_SDR50; |
---|
| 208 | + |= SD_MODE_UHS_SDR50 | SD_MODE_UHS_SDR25 |
---|
| 209 | + | SD_MODE_UHS_SDR12; |
---|
171 | 210 | |
---|
172 | 211 | if (data & SDIO_UHS_SDR104) |
---|
173 | 212 | card->sw_caps.sd3_bus_mode |
---|
174 | | - |= SD_MODE_UHS_SDR104; |
---|
| 213 | + |= SD_MODE_UHS_SDR104 | SD_MODE_UHS_SDR50 |
---|
| 214 | + | SD_MODE_UHS_SDR25 | SD_MODE_UHS_SDR12; |
---|
175 | 215 | } |
---|
176 | 216 | |
---|
177 | 217 | ret = mmc_io_rw_direct(card, 0, 0, |
---|
.. | .. |
---|
290 | 330 | return 0; |
---|
291 | 331 | } |
---|
292 | 332 | |
---|
| 333 | +static int sdio_disable_4bit_bus(struct mmc_card *card) |
---|
| 334 | +{ |
---|
| 335 | + int err; |
---|
| 336 | + |
---|
| 337 | + if (card->type == MMC_TYPE_SDIO) |
---|
| 338 | + goto out; |
---|
| 339 | + |
---|
| 340 | + if (!(card->host->caps & MMC_CAP_4_BIT_DATA)) |
---|
| 341 | + return 0; |
---|
| 342 | + |
---|
| 343 | + if (!(card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) |
---|
| 344 | + return 0; |
---|
| 345 | + |
---|
| 346 | + err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1); |
---|
| 347 | + if (err) |
---|
| 348 | + return err; |
---|
| 349 | + |
---|
| 350 | +out: |
---|
| 351 | + return sdio_disable_wide(card); |
---|
| 352 | +} |
---|
| 353 | + |
---|
293 | 354 | |
---|
294 | 355 | static int sdio_enable_4bit_bus(struct mmc_card *card) |
---|
295 | 356 | { |
---|
296 | 357 | int err; |
---|
297 | 358 | |
---|
| 359 | + err = sdio_enable_wide(card); |
---|
| 360 | + if (err <= 0) |
---|
| 361 | + return err; |
---|
298 | 362 | if (card->type == MMC_TYPE_SDIO) |
---|
299 | | - err = sdio_enable_wide(card); |
---|
300 | | - else if ((card->host->caps & MMC_CAP_4_BIT_DATA) && |
---|
301 | | - (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { |
---|
| 363 | + goto out; |
---|
| 364 | + |
---|
| 365 | + if (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4) { |
---|
302 | 366 | err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); |
---|
303 | | - if (err) |
---|
| 367 | + if (err) { |
---|
| 368 | + sdio_disable_wide(card); |
---|
304 | 369 | return err; |
---|
305 | | - err = sdio_enable_wide(card); |
---|
306 | | - if (err <= 0) |
---|
307 | | - mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1); |
---|
308 | | - } else |
---|
309 | | - return 0; |
---|
310 | | - |
---|
311 | | - if (err > 0) { |
---|
312 | | - mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); |
---|
313 | | - err = 0; |
---|
| 370 | + } |
---|
314 | 371 | } |
---|
| 372 | +out: |
---|
| 373 | + mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); |
---|
315 | 374 | |
---|
316 | | - return err; |
---|
| 375 | + return 0; |
---|
317 | 376 | } |
---|
318 | 377 | |
---|
319 | 378 | |
---|
.. | .. |
---|
505 | 564 | max_rate = min_not_zero(card->quirk_max_rate, |
---|
506 | 565 | card->sw_caps.uhs_max_dtr); |
---|
507 | 566 | |
---|
508 | | - if (bus_speed) { |
---|
509 | | - mmc_set_timing(card->host, timing); |
---|
510 | | - mmc_set_clock(card->host, max_rate); |
---|
511 | | - } |
---|
| 567 | + mmc_set_timing(card->host, timing); |
---|
| 568 | + mmc_set_clock(card->host, max_rate); |
---|
512 | 569 | |
---|
513 | 570 | return 0; |
---|
514 | 571 | } |
---|
.. | .. |
---|
548 | 605 | return err; |
---|
549 | 606 | } |
---|
550 | 607 | |
---|
551 | | -static void mmc_sdio_resend_if_cond(struct mmc_host *host, |
---|
552 | | - struct mmc_card *card) |
---|
| 608 | +static int mmc_sdio_pre_init(struct mmc_host *host, u32 ocr, |
---|
| 609 | + struct mmc_card *card) |
---|
553 | 610 | { |
---|
| 611 | + if (card) |
---|
| 612 | + mmc_remove_card(card); |
---|
| 613 | + |
---|
| 614 | + /* |
---|
| 615 | + * Reset the card by performing the same steps that are taken by |
---|
| 616 | + * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe. |
---|
| 617 | + * |
---|
| 618 | + * sdio_reset() is technically not needed. Having just powered up the |
---|
| 619 | + * hardware, it should already be in reset state. However, some |
---|
| 620 | + * platforms (such as SD8686 on OLPC) do not instantly cut power, |
---|
| 621 | + * meaning that a reset is required when restoring power soon after |
---|
| 622 | + * powering off. It is harmless in other cases. |
---|
| 623 | + * |
---|
| 624 | + * The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec, |
---|
| 625 | + * is not necessary for non-removable cards. However, it is required |
---|
| 626 | + * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and |
---|
| 627 | + * harmless in other situations. |
---|
| 628 | + * |
---|
| 629 | + */ |
---|
| 630 | + |
---|
554 | 631 | sdio_reset(host); |
---|
555 | 632 | mmc_go_idle(host); |
---|
556 | | - mmc_send_if_cond(host, host->ocr_avail); |
---|
557 | | - mmc_remove_card(card); |
---|
| 633 | + mmc_send_if_cond(host, ocr); |
---|
| 634 | + return mmc_send_io_op_cond(host, 0, NULL); |
---|
558 | 635 | } |
---|
559 | 636 | |
---|
560 | 637 | /* |
---|
.. | .. |
---|
564 | 641 | * we're trying to reinitialise. |
---|
565 | 642 | */ |
---|
566 | 643 | static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, |
---|
567 | | - struct mmc_card *oldcard, int powered_resume) |
---|
| 644 | + struct mmc_card *oldcard) |
---|
568 | 645 | { |
---|
569 | 646 | struct mmc_card *card; |
---|
570 | 647 | int err; |
---|
.. | .. |
---|
587 | 664 | /* |
---|
588 | 665 | * Inform the card of the voltage |
---|
589 | 666 | */ |
---|
590 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
591 | | - if (!(host->chip_alive)) { |
---|
592 | | - if (!powered_resume) { |
---|
593 | | - err = mmc_send_io_op_cond(host, ocr, &rocr); |
---|
594 | | - if (err) { |
---|
595 | | - pr_err("%s: mmc_send_io_op_cond() err=%d\n", __func__, err); |
---|
596 | | - goto err; |
---|
597 | | - } |
---|
598 | | - } |
---|
599 | | - } else { |
---|
600 | | - rocr = 0xa0ffff00; |
---|
601 | | - } |
---|
602 | | -#else |
---|
603 | | - if (!powered_resume) { |
---|
604 | | - err = mmc_send_io_op_cond(host, ocr, &rocr); |
---|
605 | | - if (err) |
---|
606 | | - goto err; |
---|
607 | | - } |
---|
608 | | -#endif |
---|
| 667 | + err = mmc_send_io_op_cond(host, ocr, &rocr); |
---|
| 668 | + if (err) |
---|
| 669 | + return err; |
---|
609 | 670 | |
---|
610 | 671 | /* |
---|
611 | 672 | * For SPI, enable CRC as appropriate. |
---|
.. | .. |
---|
613 | 674 | if (mmc_host_is_spi(host)) { |
---|
614 | 675 | err = mmc_spi_set_crc(host, use_spi_crc); |
---|
615 | 676 | if (err) |
---|
616 | | - goto err; |
---|
| 677 | + return err; |
---|
617 | 678 | } |
---|
618 | 679 | |
---|
619 | 680 | /* |
---|
620 | 681 | * Allocate card structure. |
---|
621 | 682 | */ |
---|
622 | | - card = mmc_alloc_card(host, NULL); |
---|
623 | | - if (IS_ERR(card)) { |
---|
624 | | - err = PTR_ERR(card); |
---|
625 | | - goto err; |
---|
626 | | - } |
---|
| 683 | + card = mmc_alloc_card(host, &sdio_type); |
---|
| 684 | + if (IS_ERR(card)) |
---|
| 685 | + return PTR_ERR(card); |
---|
627 | 686 | |
---|
628 | 687 | if ((rocr & R4_MEMORY_PRESENT) && |
---|
629 | 688 | mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) { |
---|
.. | .. |
---|
631 | 690 | |
---|
632 | 691 | if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || |
---|
633 | 692 | memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) { |
---|
634 | | - mmc_remove_card(card); |
---|
635 | | - return -ENOENT; |
---|
| 693 | + err = -ENOENT; |
---|
| 694 | + goto mismatch; |
---|
636 | 695 | } |
---|
637 | 696 | } else { |
---|
638 | 697 | card->type = MMC_TYPE_SDIO; |
---|
639 | 698 | |
---|
640 | 699 | if (oldcard && oldcard->type != MMC_TYPE_SDIO) { |
---|
641 | | - mmc_remove_card(card); |
---|
642 | | - return -ENOENT; |
---|
| 700 | + err = -ENOENT; |
---|
| 701 | + goto mismatch; |
---|
643 | 702 | } |
---|
644 | 703 | } |
---|
645 | 704 | |
---|
.. | .. |
---|
662 | 721 | * try to init uhs card. sdio_read_cccr will take over this task |
---|
663 | 722 | * to make sure which speed mode should work. |
---|
664 | 723 | */ |
---|
665 | | - if (!powered_resume && (rocr & ocr & R4_18V_PRESENT)) { |
---|
| 724 | + if (rocr & ocr & R4_18V_PRESENT) { |
---|
666 | 725 | err = mmc_set_uhs_voltage(host, ocr_card); |
---|
667 | 726 | if (err == -EAGAIN) { |
---|
668 | | - mmc_sdio_resend_if_cond(host, card); |
---|
| 727 | + mmc_sdio_pre_init(host, ocr_card, card); |
---|
669 | 728 | retries--; |
---|
670 | 729 | goto try_again; |
---|
671 | 730 | } else if (err) { |
---|
.. | .. |
---|
676 | 735 | /* |
---|
677 | 736 | * For native busses: set card RCA and quit open drain mode. |
---|
678 | 737 | */ |
---|
679 | | - if (!powered_resume && !mmc_host_is_spi(host)) { |
---|
680 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
681 | | - if (!(host->chip_alive)) { |
---|
682 | | - err = mmc_send_relative_addr(host, &card->rca); |
---|
683 | | - if (err) |
---|
684 | | - goto remove; |
---|
685 | | - } else { |
---|
686 | | - card->rca = 1; |
---|
687 | | - } |
---|
688 | | -#else |
---|
| 738 | + if (!mmc_host_is_spi(host)) { |
---|
689 | 739 | err = mmc_send_relative_addr(host, &card->rca); |
---|
690 | 740 | if (err) |
---|
691 | 741 | goto remove; |
---|
692 | | -#endif |
---|
693 | 742 | |
---|
694 | 743 | /* |
---|
695 | 744 | * Update oldcard with the new RCA received from the SDIO |
---|
.. | .. |
---|
706 | 755 | if (!oldcard && card->type == MMC_TYPE_SD_COMBO) { |
---|
707 | 756 | err = mmc_sd_get_csd(host, card); |
---|
708 | 757 | if (err) |
---|
709 | | - return err; |
---|
| 758 | + goto remove; |
---|
710 | 759 | |
---|
711 | 760 | mmc_decode_cid(card); |
---|
712 | 761 | } |
---|
.. | .. |
---|
714 | 763 | /* |
---|
715 | 764 | * Select card, as all following commands rely on that. |
---|
716 | 765 | */ |
---|
717 | | - if (!powered_resume && !mmc_host_is_spi(host)) { |
---|
| 766 | + if (!mmc_host_is_spi(host)) { |
---|
718 | 767 | err = mmc_select_card(card); |
---|
719 | 768 | if (err) |
---|
720 | 769 | goto remove; |
---|
.. | .. |
---|
733 | 782 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); |
---|
734 | 783 | } |
---|
735 | 784 | |
---|
736 | | - goto finish; |
---|
| 785 | + if (oldcard) |
---|
| 786 | + mmc_remove_card(card); |
---|
| 787 | + else |
---|
| 788 | + host->card = card; |
---|
| 789 | + |
---|
| 790 | + return 0; |
---|
737 | 791 | } |
---|
738 | 792 | |
---|
739 | 793 | /* |
---|
.. | .. |
---|
742 | 796 | */ |
---|
743 | 797 | err = sdio_read_cccr(card, ocr); |
---|
744 | 798 | if (err) { |
---|
745 | | - mmc_sdio_resend_if_cond(host, card); |
---|
| 799 | + mmc_sdio_pre_init(host, ocr_card, card); |
---|
746 | 800 | if (ocr & R4_18V_PRESENT) { |
---|
747 | 801 | /* Retry init sequence, but without R4_18V_PRESENT. */ |
---|
748 | 802 | retries = 0; |
---|
.. | .. |
---|
759 | 813 | goto remove; |
---|
760 | 814 | |
---|
761 | 815 | if (oldcard) { |
---|
762 | | - int same = (card->cis.vendor == oldcard->cis.vendor && |
---|
763 | | - card->cis.device == oldcard->cis.device); |
---|
764 | | - mmc_remove_card(card); |
---|
765 | | - if (!same) |
---|
766 | | - return -ENOENT; |
---|
767 | | - |
---|
768 | | - card = oldcard; |
---|
| 816 | + if (card->cis.vendor == oldcard->cis.vendor && |
---|
| 817 | + card->cis.device == oldcard->cis.device) { |
---|
| 818 | + mmc_remove_card(card); |
---|
| 819 | + card = oldcard; |
---|
| 820 | + } else { |
---|
| 821 | + err = -ENOENT; |
---|
| 822 | + goto mismatch; |
---|
| 823 | + } |
---|
769 | 824 | } |
---|
770 | 825 | |
---|
771 | 826 | mmc_fixup_device(card, sdio_fixup_methods); |
---|
.. | .. |
---|
826 | 881 | err = -EINVAL; |
---|
827 | 882 | goto remove; |
---|
828 | 883 | } |
---|
829 | | -finish: |
---|
830 | | - if (!oldcard) |
---|
831 | | - host->card = card; |
---|
| 884 | + |
---|
| 885 | + host->card = card; |
---|
832 | 886 | return 0; |
---|
833 | 887 | |
---|
| 888 | +mismatch: |
---|
| 889 | + pr_debug("%s: Perhaps the card was replaced\n", mmc_hostname(host)); |
---|
834 | 890 | remove: |
---|
835 | | - if (!oldcard) |
---|
| 891 | + if (oldcard != card) |
---|
836 | 892 | mmc_remove_card(card); |
---|
837 | | - |
---|
838 | | -err: |
---|
839 | 893 | return err; |
---|
840 | 894 | } |
---|
841 | 895 | |
---|
842 | | -static int mmc_sdio_reinit_card(struct mmc_host *host, bool powered_resume) |
---|
| 896 | +static int mmc_sdio_reinit_card(struct mmc_host *host) |
---|
843 | 897 | { |
---|
844 | 898 | int ret; |
---|
845 | 899 | |
---|
846 | | - sdio_reset(host); |
---|
847 | | - mmc_go_idle(host); |
---|
848 | | - mmc_send_if_cond(host, host->card->ocr); |
---|
849 | | - |
---|
850 | | - ret = mmc_send_io_op_cond(host, 0, NULL); |
---|
| 900 | + ret = mmc_sdio_pre_init(host, host->card->ocr, NULL); |
---|
851 | 901 | if (ret) |
---|
852 | 902 | return ret; |
---|
853 | 903 | |
---|
854 | | - return mmc_sdio_init_card(host, host->card->ocr, host->card, |
---|
855 | | - powered_resume); |
---|
| 904 | + return mmc_sdio_init_card(host, host->card->ocr, host->card); |
---|
856 | 905 | } |
---|
857 | 906 | |
---|
858 | 907 | /* |
---|
.. | .. |
---|
938 | 987 | */ |
---|
939 | 988 | static int mmc_sdio_pre_suspend(struct mmc_host *host) |
---|
940 | 989 | { |
---|
941 | | - int i, err = 0; |
---|
| 990 | + int i; |
---|
942 | 991 | |
---|
943 | 992 | for (i = 0; i < host->card->sdio_funcs; i++) { |
---|
944 | 993 | struct sdio_func *func = host->card->sdio_func[i]; |
---|
945 | 994 | if (func && sdio_func_present(func) && func->dev.driver) { |
---|
946 | 995 | const struct dev_pm_ops *pmops = func->dev.driver->pm; |
---|
947 | | - if (!pmops || !pmops->suspend || !pmops->resume) { |
---|
| 996 | + if (!pmops || !pmops->suspend || !pmops->resume) |
---|
948 | 997 | /* force removal of entire card in that case */ |
---|
949 | | - err = -ENOSYS; |
---|
950 | | - break; |
---|
951 | | - } |
---|
| 998 | + goto remove; |
---|
952 | 999 | } |
---|
953 | 1000 | } |
---|
954 | 1001 | |
---|
955 | | - return err; |
---|
| 1002 | + return 0; |
---|
| 1003 | + |
---|
| 1004 | +remove: |
---|
| 1005 | + if (!mmc_card_is_removable(host)) { |
---|
| 1006 | + dev_warn(mmc_dev(host), |
---|
| 1007 | + "missing suspend/resume ops for non-removable SDIO card\n"); |
---|
| 1008 | + /* Don't remove a non-removable card - we can't re-detect it. */ |
---|
| 1009 | + return 0; |
---|
| 1010 | + } |
---|
| 1011 | + |
---|
| 1012 | + /* Remove the SDIO card and let it be re-detected later on. */ |
---|
| 1013 | + mmc_sdio_remove(host); |
---|
| 1014 | + mmc_claim_host(host); |
---|
| 1015 | + mmc_detach_bus(host); |
---|
| 1016 | + mmc_power_off(host); |
---|
| 1017 | + mmc_release_host(host); |
---|
| 1018 | + host->pm_flags = 0; |
---|
| 1019 | + |
---|
| 1020 | + return 0; |
---|
956 | 1021 | } |
---|
957 | 1022 | |
---|
958 | 1023 | /* |
---|
.. | .. |
---|
960 | 1025 | */ |
---|
961 | 1026 | static int mmc_sdio_suspend(struct mmc_host *host) |
---|
962 | 1027 | { |
---|
| 1028 | + WARN_ON(host->sdio_irqs && !mmc_card_keep_power(host)); |
---|
| 1029 | + |
---|
963 | 1030 | /* Prevent processing of SDIO IRQs in suspended state. */ |
---|
964 | 1031 | mmc_card_set_suspended(host->card); |
---|
965 | 1032 | cancel_delayed_work_sync(&host->sdio_irq_work); |
---|
.. | .. |
---|
967 | 1034 | mmc_claim_host(host); |
---|
968 | 1035 | |
---|
969 | 1036 | if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) |
---|
970 | | - sdio_disable_wide(host->card); |
---|
| 1037 | + sdio_disable_4bit_bus(host->card); |
---|
971 | 1038 | |
---|
972 | 1039 | if (!mmc_card_keep_power(host)) { |
---|
973 | 1040 | mmc_power_off(host); |
---|
.. | .. |
---|
988 | 1055 | /* Basic card reinitialization. */ |
---|
989 | 1056 | mmc_claim_host(host); |
---|
990 | 1057 | |
---|
991 | | - /* Restore power if needed */ |
---|
| 1058 | + /* |
---|
| 1059 | + * Restore power and reinitialize the card when needed. Note that a |
---|
| 1060 | + * removable card is checked from a detect work later on in the resume |
---|
| 1061 | + * process. |
---|
| 1062 | + */ |
---|
992 | 1063 | if (!mmc_card_keep_power(host)) { |
---|
993 | 1064 | mmc_power_up(host, host->card->ocr); |
---|
994 | 1065 | /* |
---|
.. | .. |
---|
1002 | 1073 | pm_runtime_set_active(&host->card->dev); |
---|
1003 | 1074 | pm_runtime_enable(&host->card->dev); |
---|
1004 | 1075 | } |
---|
1005 | | - } |
---|
1006 | | - |
---|
1007 | | - /* No need to reinitialize powered-resumed nonremovable cards */ |
---|
1008 | | - if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { |
---|
1009 | | - err = mmc_sdio_reinit_card(host, mmc_card_keep_power(host)); |
---|
1010 | | - } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { |
---|
| 1076 | + err = mmc_sdio_reinit_card(host); |
---|
| 1077 | + } else if (mmc_card_wake_sdio_irq(host)) { |
---|
1011 | 1078 | /* We may have switched to 1-bit mode during suspend */ |
---|
1012 | 1079 | err = sdio_enable_4bit_bus(host->card); |
---|
1013 | 1080 | } |
---|
.. | .. |
---|
1022 | 1089 | if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) |
---|
1023 | 1090 | wake_up_process(host->sdio_irq_thread); |
---|
1024 | 1091 | else if (host->caps & MMC_CAP_SDIO_IRQ) |
---|
1025 | | - host->ops->enable_sdio_irq(host, 1); |
---|
| 1092 | + queue_delayed_work(system_wq, &host->sdio_irq_work, 0); |
---|
1026 | 1093 | } |
---|
1027 | 1094 | |
---|
1028 | 1095 | out: |
---|
.. | .. |
---|
1030 | 1097 | |
---|
1031 | 1098 | host->pm_flags &= ~MMC_PM_KEEP_POWER; |
---|
1032 | 1099 | return err; |
---|
1033 | | -} |
---|
1034 | | - |
---|
1035 | | -static int mmc_sdio_power_restore(struct mmc_host *host) |
---|
1036 | | -{ |
---|
1037 | | - int ret; |
---|
1038 | | - |
---|
1039 | | - /* |
---|
1040 | | - * Reset the card by performing the same steps that are taken by |
---|
1041 | | - * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe. |
---|
1042 | | - * |
---|
1043 | | - * sdio_reset() is technically not needed. Having just powered up the |
---|
1044 | | - * hardware, it should already be in reset state. However, some |
---|
1045 | | - * platforms (such as SD8686 on OLPC) do not instantly cut power, |
---|
1046 | | - * meaning that a reset is required when restoring power soon after |
---|
1047 | | - * powering off. It is harmless in other cases. |
---|
1048 | | - * |
---|
1049 | | - * The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec, |
---|
1050 | | - * is not necessary for non-removable cards. However, it is required |
---|
1051 | | - * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and |
---|
1052 | | - * harmless in other situations. |
---|
1053 | | - * |
---|
1054 | | - */ |
---|
1055 | | - |
---|
1056 | | - mmc_claim_host(host); |
---|
1057 | | - |
---|
1058 | | - ret = mmc_sdio_reinit_card(host, mmc_card_keep_power(host)); |
---|
1059 | | - if (!ret && host->sdio_irqs) |
---|
1060 | | - mmc_signal_sdio_irq(host); |
---|
1061 | | - |
---|
1062 | | - mmc_release_host(host); |
---|
1063 | | - |
---|
1064 | | - return ret; |
---|
1065 | 1100 | } |
---|
1066 | 1101 | |
---|
1067 | 1102 | static int mmc_sdio_runtime_suspend(struct mmc_host *host) |
---|
.. | .. |
---|
1081 | 1116 | /* Restore power and re-initialize. */ |
---|
1082 | 1117 | mmc_claim_host(host); |
---|
1083 | 1118 | mmc_power_up(host, host->card->ocr); |
---|
1084 | | - ret = mmc_sdio_power_restore(host); |
---|
| 1119 | + ret = mmc_sdio_reinit_card(host); |
---|
1085 | 1120 | mmc_release_host(host); |
---|
1086 | 1121 | |
---|
1087 | 1122 | return ret; |
---|
1088 | 1123 | } |
---|
1089 | 1124 | |
---|
| 1125 | +/* |
---|
| 1126 | + * SDIO HW reset |
---|
| 1127 | + * |
---|
| 1128 | + * Returns 0 if the HW reset was executed synchronously, returns 1 if the HW |
---|
| 1129 | + * reset was asynchronously scheduled, else a negative error code. |
---|
| 1130 | + */ |
---|
1090 | 1131 | static int mmc_sdio_hw_reset(struct mmc_host *host) |
---|
1091 | 1132 | { |
---|
1092 | | - mmc_power_cycle(host, host->card->ocr); |
---|
1093 | | - return mmc_sdio_power_restore(host); |
---|
| 1133 | + struct mmc_card *card = host->card; |
---|
| 1134 | + |
---|
| 1135 | + /* |
---|
| 1136 | + * In case the card is shared among multiple func drivers, reset the |
---|
| 1137 | + * card through a rescan work. In this way it will be removed and |
---|
| 1138 | + * re-detected, thus all func drivers becomes informed about it. |
---|
| 1139 | + */ |
---|
| 1140 | + if (atomic_read(&card->sdio_funcs_probed) > 1) { |
---|
| 1141 | + if (mmc_card_removed(card)) |
---|
| 1142 | + return 1; |
---|
| 1143 | + host->rescan_entered = 0; |
---|
| 1144 | + mmc_card_set_removed(card); |
---|
| 1145 | + _mmc_detect_change(host, 0, false); |
---|
| 1146 | + return 1; |
---|
| 1147 | + } |
---|
| 1148 | + |
---|
| 1149 | + /* |
---|
| 1150 | + * A single func driver has been probed, then let's skip the heavy |
---|
| 1151 | + * hotplug dance above and execute the reset immediately. |
---|
| 1152 | + */ |
---|
| 1153 | + mmc_power_cycle(host, card->ocr); |
---|
| 1154 | + return mmc_sdio_reinit_card(host); |
---|
1094 | 1155 | } |
---|
1095 | 1156 | |
---|
1096 | 1157 | static int mmc_sdio_sw_reset(struct mmc_host *host) |
---|
.. | .. |
---|
1102 | 1163 | mmc_set_initial_state(host); |
---|
1103 | 1164 | mmc_set_initial_signal_voltage(host); |
---|
1104 | 1165 | |
---|
1105 | | - return mmc_sdio_reinit_card(host, 0); |
---|
| 1166 | + return mmc_sdio_reinit_card(host); |
---|
1106 | 1167 | } |
---|
1107 | 1168 | |
---|
1108 | 1169 | static const struct mmc_bus_ops mmc_sdio_ops = { |
---|
.. | .. |
---|
1130 | 1191 | |
---|
1131 | 1192 | WARN_ON(!host->claimed); |
---|
1132 | 1193 | |
---|
1133 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
1134 | | - if (!(host->chip_alive)) { |
---|
1135 | | - err = mmc_send_io_op_cond(host, 0, &ocr); |
---|
1136 | | - if (err) { |
---|
1137 | | - pr_err("%s mmc_send_io_op_cond err: %d\n", mmc_hostname(host), err); |
---|
1138 | | - return err; |
---|
1139 | | - } |
---|
1140 | | - } else { |
---|
1141 | | - ocr = 0x20ffff00; |
---|
1142 | | - } |
---|
1143 | | -#else |
---|
1144 | 1194 | err = mmc_send_io_op_cond(host, 0, &ocr); |
---|
1145 | 1195 | if (err) |
---|
1146 | 1196 | return err; |
---|
1147 | | -#endif |
---|
1148 | 1197 | |
---|
1149 | 1198 | mmc_attach_bus(host, &mmc_sdio_ops); |
---|
1150 | 1199 | if (host->ocr_avail_sdio) |
---|
.. | .. |
---|
1164 | 1213 | /* |
---|
1165 | 1214 | * Detect and init the card. |
---|
1166 | 1215 | */ |
---|
1167 | | - err = mmc_sdio_init_card(host, rocr, NULL, 0); |
---|
| 1216 | + err = mmc_sdio_init_card(host, rocr, NULL); |
---|
1168 | 1217 | if (err) |
---|
1169 | 1218 | goto err; |
---|
1170 | 1219 | |
---|
.. | .. |
---|
1215 | 1264 | pm_runtime_enable(&card->sdio_func[i]->dev); |
---|
1216 | 1265 | } |
---|
1217 | 1266 | |
---|
1218 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
1219 | | - if (host->card->sdio_func[1]) |
---|
1220 | | - host->card->sdio_func[1]->card_alive = host->chip_alive; |
---|
1221 | | -#endif |
---|
1222 | | - |
---|
1223 | 1267 | /* |
---|
1224 | 1268 | * First add the card to the driver model... |
---|
1225 | 1269 | */ |
---|
.. | .. |
---|
1264 | 1308 | return err; |
---|
1265 | 1309 | } |
---|
1266 | 1310 | |
---|
1267 | | -int sdio_reset_comm(struct mmc_card *card) |
---|
1268 | | -{ |
---|
1269 | | - struct mmc_host *host = card->host; |
---|
1270 | | - u32 ocr; |
---|
1271 | | - u32 rocr; |
---|
1272 | | - int err; |
---|
1273 | | - |
---|
1274 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
---|
1275 | | - if (host->chip_alive) |
---|
1276 | | - host->chip_alive = 0; |
---|
1277 | | -#endif |
---|
1278 | | - |
---|
1279 | | - printk("%s():\n", __func__); |
---|
1280 | | - mmc_claim_host(host); |
---|
1281 | | - |
---|
1282 | | - mmc_retune_disable(host); |
---|
1283 | | - |
---|
1284 | | - mmc_power_cycle(host, host->card->ocr); |
---|
1285 | | - mmc_go_idle(host); |
---|
1286 | | - |
---|
1287 | | - mmc_set_clock(host, host->f_min); |
---|
1288 | | - |
---|
1289 | | - err = mmc_send_io_op_cond(host, 0, &ocr); |
---|
1290 | | - if (err) |
---|
1291 | | - goto err; |
---|
1292 | | - |
---|
1293 | | - rocr = mmc_select_voltage(host, ocr); |
---|
1294 | | - if (!rocr) { |
---|
1295 | | - err = -EINVAL; |
---|
1296 | | - goto err; |
---|
1297 | | - } |
---|
1298 | | - |
---|
1299 | | - err = mmc_sdio_init_card(host, rocr, card, 0); |
---|
1300 | | - if (err) |
---|
1301 | | - goto err; |
---|
1302 | | - |
---|
1303 | | - mmc_release_host(host); |
---|
1304 | | - return 0; |
---|
1305 | | -err: |
---|
1306 | | - printk("%s: Error resetting SDIO communications (%d)\n", |
---|
1307 | | - mmc_hostname(host), err); |
---|
1308 | | - mmc_release_host(host); |
---|
1309 | | - return err; |
---|
1310 | | -} |
---|
1311 | | -EXPORT_SYMBOL(sdio_reset_comm); |
---|