36 if (mmc_card_nonstd_func_interface(func->
card)) {
75 ret = sdio_read_fbr(func);
101 static int sdio_read_cccr(
struct mmc_card *card,
u32 ocr)
115 cccr_vsn = data & 0x0f;
118 pr_err(
"%s: unrecognised CCCR structure version %d\n",
123 card->
cccr.sdio_vsn = (data & 0xf0) >> 4;
130 card->
cccr.multi_block = 1;
132 card->
cccr.low_speed = 1;
134 card->
cccr.wide_bus = 1;
142 card->
cccr.high_power = 1;
150 card->
scr.sda_spec3 = 0;
151 card->
sw_caps.sd3_bus_mode = 0;
152 card->
sw_caps.sd3_drv_type = 0;
154 card->
scr.sda_spec3 = 1;
160 if (card->
host->caps &
191 if (!card->
sw_caps.sd3_bus_mode) {
193 card->
cccr.high_speed = 1;
194 card->
sw_caps.hs_max_dtr = 50000000;
196 card->
cccr.high_speed = 0;
197 card->
sw_caps.hs_max_dtr = 25000000;
206 static int sdio_enable_wide(
struct mmc_card *card)
214 if (card->
cccr.low_speed && !card->
cccr.wide_bus)
222 pr_warning(
"%s: SDIO_CCCR_IF is invalid: 0x%02x\n",
226 ctrl &= ~SDIO_BUS_WIDTH_MASK;
242 static int sdio_disable_cd(
struct mmc_card *card)
247 if (!mmc_card_disable_cd(card))
263 static int sdio_disable_wide(
struct mmc_card *card)
271 if (card->
cccr.low_speed && !card->
cccr.wide_bus)
281 ctrl &= ~SDIO_BUS_WIDTH_4BIT;
294 static int sdio_enable_4bit_bus(
struct mmc_card *card)
299 return sdio_enable_wide(card);
309 err = sdio_enable_wide(card);
328 if (!card->
cccr.high_speed)
350 static int sdio_enable_hs(
struct mmc_card *card)
354 ret = mmc_sdio_switch_hs(card,
true);
360 mmc_sdio_switch_hs(card,
false);
365 static unsigned mmc_sdio_get_max_clock(
struct mmc_card *card)
378 max_dtr = card->
cis.max_dtr;
387 static unsigned char host_drive_to_sdio_drive(
int host_strength)
389 switch (host_strength) {
403 static void sdio_select_driver_type(
struct mmc_card *card)
408 unsigned char card_strength;
416 if (!(card->
host->caps &
422 if (!card->
host->ops->select_drive_strength)
449 drive_strength = card->
host->ops->select_drive_strength(
451 host_drv_type, card_drv_type);
460 card_strength |= host_drive_to_sdio_drive(drive_strength);
463 card_strength,
NULL);
471 static int sdio_set_bus_speed_mode(
struct mmc_card *card)
473 unsigned int bus_speed,
timing;
539 static int mmc_sdio_init_uhs_card(
struct mmc_card *card)
543 if (!card->
scr.sda_spec3)
550 err = sdio_enable_4bit_bus(card);
558 sdio_select_driver_type(card);
561 err = sdio_set_bus_speed_mode(card);
567 err = card->
host->ops->execute_tuning(card->
host,
582 struct mmc_card *oldcard,
int powered_resume)
593 if (!powered_resume) {
638 if (host->
ops->init_card)
639 host->
ops->init_card(host, card);
648 if ((ocr & R4_18V_PRESENT) &&
656 ocr &= ~R4_18V_PRESENT;
657 host->
ocr &= ~R4_18V_PRESENT;
661 ocr &= ~R4_18V_PRESENT;
662 host->
ocr &= ~R4_18V_PRESENT;
711 if (card->
cccr.high_speed) {
722 err = sdio_read_cccr(card, ocr);
734 int same = (card->
cis.vendor == oldcard->
cis.vendor &&
735 card->
cis.device == oldcard->
cis.device);
760 err = sdio_disable_cd(card);
766 if ((ocr & R4_18V_PRESENT) && card->
sw_caps.sd3_bus_mode) {
767 err = mmc_sdio_init_uhs_card(card);
777 err = sdio_enable_hs(card);
791 err = sdio_enable_4bit_bus(card);
813 static void mmc_sdio_remove(
struct mmc_host *host)
820 for (i = 0;i < host->
card->sdio_funcs;i++) {
821 if (host->
card->sdio_func[i]) {
834 static int mmc_sdio_alive(
struct mmc_host *host)
842 static void mmc_sdio_detect(
struct mmc_host *host)
851 err = pm_runtime_get_sync(&host->
card->dev);
856 mmc_claim_host(host);
877 pm_runtime_put_sync(&host->
card->dev);
881 mmc_sdio_remove(host);
883 mmc_claim_host(host);
895 static int mmc_sdio_suspend(
struct mmc_host *host)
899 for (i = 0; i < host->
card->sdio_funcs; i++) {
912 while (err && --i >= 0) {
920 if (!err && mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
921 mmc_claim_host(host);
922 sdio_disable_wide(host->
card);
929 static int mmc_sdio_resume(
struct mmc_host *host)
937 mmc_claim_host(host);
940 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host))
941 err = mmc_sdio_init_card(host, host->
ocr, host->
card,
942 mmc_card_keep_power(host));
943 else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
945 err = sdio_enable_4bit_bus(host->
card);
966 for (i = 0; !err && i < host->
card->sdio_funcs; i++) {
977 static int mmc_sdio_power_restore(
struct mmc_host *host)
985 mmc_claim_host(host);
1023 ret = mmc_sdio_init_card(host, host->
ocr, host->
card,
1024 mmc_card_keep_power(host));
1026 mmc_signal_sdio_irq(host);
1035 .remove = mmc_sdio_remove,
1036 .detect = mmc_sdio_detect,
1037 .suspend = mmc_sdio_suspend,
1038 .resume = mmc_sdio_resume,
1039 .power_restore = mmc_sdio_power_restore,
1040 .alive = mmc_sdio_alive,
1069 pr_warning(
"%s: card claims to support voltages "
1070 "below the defined range. These will be ignored.\n",
1088 err = mmc_sdio_init_card(host, host->
ocr,
NULL, 0);
1094 host->
ocr &= ~R4_18V_PRESENT;
1095 err = mmc_sdio_init_card(host, host->
ocr,
NULL, 0);
1109 err = pm_runtime_set_active(&card->
dev);
1123 funcs = (ocr & 0x70000000) >> 28;
1129 for (i = 0; i < funcs; i++, card->
sdio_funcs++) {
1130 err = sdio_init_func(host->
card, i + 1);
1152 for (i = 0;i < funcs;i++) {
1158 mmc_claim_host(host);
1164 mmc_sdio_remove(host);
1165 mmc_claim_host(host);
1170 mmc_sdio_remove(host);
1171 mmc_claim_host(host);
1175 pr_err(
"%s: error %d whilst initialising SDIO card\n",