Lines Matching +full:no +full:- +full:sdio
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * linux/drivers/mmc/sdio.c
5 * Copyright 2006-2007 Pierre Ossman
15 #include <linux/mmc/sdio.h>
31 MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
32 MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
33 MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev);
34 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
35 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
42 if (num > card->num_info) \
43 return -ENODATA; \
44 if (!card->info[num - 1][0]) \
46 return sysfs_emit(buf, "%s\n", card->info[num - 1]); \
78 if (mmc_card_nonstd_func_interface(func->card)) { in sdio_read_fbr()
79 func->class = SDIO_CLASS_NONE; in sdio_read_fbr()
83 ret = mmc_io_rw_direct(func->card, 0, 0, in sdio_read_fbr()
84 SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data); in sdio_read_fbr()
91 ret = mmc_io_rw_direct(func->card, 0, 0, in sdio_read_fbr()
92 SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data); in sdio_read_fbr()
97 func->class = data; in sdio_read_fbr()
109 return -EINVAL; in sdio_init_func()
115 func->num = fn; in sdio_init_func()
117 if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) { in sdio_init_func()
126 func->vendor = func->card->cis.vendor; in sdio_init_func()
127 func->device = func->card->cis.device; in sdio_init_func()
128 func->max_blksize = func->card->cis.blksize; in sdio_init_func()
131 card->sdio_func[fn - 1] = func; in sdio_init_func()
160 mmc_hostname(card->host), cccr_vsn); in sdio_read_cccr()
161 return -EINVAL; in sdio_read_cccr()
164 card->cccr.sdio_vsn = (data & 0xf0) >> 4; in sdio_read_cccr()
171 card->cccr.multi_block = 1; in sdio_read_cccr()
173 card->cccr.low_speed = 1; in sdio_read_cccr()
175 card->cccr.wide_bus = 1; in sdio_read_cccr()
183 card->cccr.high_power = 1; in sdio_read_cccr()
191 card->scr.sda_spec3 = 0; in sdio_read_cccr()
192 card->sw_caps.sd3_bus_mode = 0; in sdio_read_cccr()
193 card->sw_caps.sd3_drv_type = 0; in sdio_read_cccr()
195 card->scr.sda_spec3 = 1; in sdio_read_cccr()
201 if (mmc_host_uhs(card->host)) { in sdio_read_cccr()
203 card->sw_caps.sd3_bus_mode in sdio_read_cccr()
208 card->sw_caps.sd3_bus_mode in sdio_read_cccr()
213 card->sw_caps.sd3_bus_mode in sdio_read_cccr()
224 card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_A; in sdio_read_cccr()
226 card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_C; in sdio_read_cccr()
228 card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_D; in sdio_read_cccr()
241 card->cccr.enable_async_irq = 1; in sdio_read_cccr()
245 /* if no uhs mode ensure we check for high speed */ in sdio_read_cccr()
246 if (!card->sw_caps.sd3_bus_mode) { in sdio_read_cccr()
248 card->cccr.high_speed = 1; in sdio_read_cccr()
249 card->sw_caps.hs_max_dtr = 50000000; in sdio_read_cccr()
251 card->cccr.high_speed = 0; in sdio_read_cccr()
252 card->sw_caps.hs_max_dtr = 25000000; in sdio_read_cccr()
266 if (!(card->host->caps & MMC_CAP_4_BIT_DATA)) in sdio_enable_wide()
269 if (card->cccr.low_speed && !card->cccr.wide_bus) in sdio_enable_wide()
278 mmc_hostname(card->host), ctrl); in sdio_enable_wide()
280 /* set as 4-bit bus width */ in sdio_enable_wide()
292 * If desired, disconnect the pull-up resistor on CD/DAT[3] (pin 1)
294 * controllers and embedded sdio device which do not need the card's
295 * pull-up. As a result, card detection is disabled and power is saved.
316 * put back into 1-bit mode.
323 if (!(card->host->caps & MMC_CAP_4_BIT_DATA)) in sdio_disable_wide()
326 if (card->cccr.low_speed && !card->cccr.wide_bus) in sdio_disable_wide()
343 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_1); in sdio_disable_wide()
355 if (!(card->host->caps & MMC_CAP_4_BIT_DATA)) in sdio_disable_4bit_bus()
358 if (!(card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) in sdio_disable_4bit_bus()
380 if (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4) { in sdio_enable_4bit_bus()
388 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); in sdio_enable_4bit_bus()
395 * Test if the card supports high-speed mode and, if so, switch to it.
402 if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED)) in mmc_sdio_switch_hs()
405 if (!card->cccr.high_speed) in mmc_sdio_switch_hs()
425 * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported.
448 * The SDIO specification doesn't mention how in mmc_sdio_get_max_clock()
450 * high-speed, but it seems that 50 MHz is in mmc_sdio_get_max_clock()
455 max_dtr = card->cis.max_dtr; in mmc_sdio_get_max_clock()
486 card->drive_strength = 0; in sdio_select_driver_type()
488 card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B; in sdio_select_driver_type()
491 card->sw_caps.uhs_max_dtr, in sdio_select_driver_type()
509 card->drive_strength = drive_strength; in sdio_select_driver_type()
513 mmc_set_driver_type(card->host, drv_type); in sdio_select_driver_type()
525 * If the host doesn't support any of the UHS-I modes, fallback on in sdio_set_bus_speed_mode()
528 if (!mmc_host_uhs(card->host)) in sdio_set_bus_speed_mode()
533 if ((card->host->caps & MMC_CAP_UHS_SDR104) && in sdio_set_bus_speed_mode()
534 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) { in sdio_set_bus_speed_mode()
537 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; in sdio_set_bus_speed_mode()
538 card->sd_bus_speed = UHS_SDR104_BUS_SPEED; in sdio_set_bus_speed_mode()
539 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) && in sdio_set_bus_speed_mode()
540 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) { in sdio_set_bus_speed_mode()
543 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; in sdio_set_bus_speed_mode()
544 card->sd_bus_speed = UHS_DDR50_BUS_SPEED; in sdio_set_bus_speed_mode()
545 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sdio_set_bus_speed_mode()
546 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode & in sdio_set_bus_speed_mode()
550 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; in sdio_set_bus_speed_mode()
551 card->sd_bus_speed = UHS_SDR50_BUS_SPEED; in sdio_set_bus_speed_mode()
552 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sdio_set_bus_speed_mode()
554 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) { in sdio_set_bus_speed_mode()
557 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR; in sdio_set_bus_speed_mode()
558 card->sd_bus_speed = UHS_SDR25_BUS_SPEED; in sdio_set_bus_speed_mode()
559 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sdio_set_bus_speed_mode()
561 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode & in sdio_set_bus_speed_mode()
565 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR; in sdio_set_bus_speed_mode()
566 card->sd_bus_speed = UHS_SDR12_BUS_SPEED; in sdio_set_bus_speed_mode()
579 max_rate = min_not_zero(card->quirk_max_rate, in sdio_set_bus_speed_mode()
580 card->sw_caps.uhs_max_dtr); in sdio_set_bus_speed_mode()
582 mmc_set_timing(card->host, timing); in sdio_set_bus_speed_mode()
583 mmc_set_clock(card->host, max_rate); in sdio_set_bus_speed_mode()
589 * UHS-I specific initialization procedure
595 if (!card->scr.sda_spec3) in mmc_sdio_init_uhs_card()
613 * SDR104 mode SD-cards. Note that tuning is mandatory for SDR104. in mmc_sdio_init_uhs_card()
615 if (!mmc_host_is_spi(card->host) && in mmc_sdio_init_uhs_card()
616 ((card->host->ios.timing == MMC_TIMING_UHS_SDR50) || in mmc_sdio_init_uhs_card()
617 (card->host->ios.timing == MMC_TIMING_UHS_SDR104))) in mmc_sdio_init_uhs_card()
639 * The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec, in mmc_sdio_pre_init()
640 * is not necessary for non-removable cards. However, it is required in mmc_sdio_pre_init()
667 WARN_ON(!host->claimed); in mmc_sdio_init_card()
703 mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) { in mmc_sdio_init_card()
704 card->type = MMC_TYPE_SD_COMBO; in mmc_sdio_init_card()
707 memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) { in mmc_sdio_init_card()
708 err = -ENOENT; in mmc_sdio_init_card()
712 card->type = MMC_TYPE_SDIO; in mmc_sdio_init_card()
715 err = -ENOENT; in mmc_sdio_init_card()
723 if (host->ops->init_card) in mmc_sdio_init_card()
724 host->ops->init_card(host, card); in mmc_sdio_init_card()
727 card->ocr = ocr_card; in mmc_sdio_init_card()
730 * If the host and card support UHS-I mode request the card in mmc_sdio_init_card()
731 * to switch to 1.8V signaling level. No 1.8v signalling if in mmc_sdio_init_card()
734 * it. Per SDIO spec v3, section 3.1.2, if the voltage is already in mmc_sdio_init_card()
742 if (err == -EAGAIN) { in mmc_sdio_init_card()
744 retries--; in mmc_sdio_init_card()
755 err = mmc_send_relative_addr(host, &card->rca); in mmc_sdio_init_card()
760 * Update oldcard with the new RCA received from the SDIO in mmc_sdio_init_card()
761 * device -- we're doing this so that it's updated in the in mmc_sdio_init_card()
765 oldcard->rca = card->rca; in mmc_sdio_init_card()
788 if (card->quirks & MMC_QUIRK_NONSTD_SDIO) { in mmc_sdio_init_card()
790 * This is non-standard SDIO device, meaning it doesn't in mmc_sdio_init_card()
795 mmc_set_clock(host, card->cis.max_dtr); in mmc_sdio_init_card()
797 if (card->cccr.high_speed) { in mmc_sdio_init_card()
798 mmc_set_timing(card->host, MMC_TIMING_SD_HS); in mmc_sdio_init_card()
804 host->card = card; in mmc_sdio_init_card()
832 if (card->cis.vendor == oldcard->cis.vendor && in mmc_sdio_init_card()
833 card->cis.device == oldcard->cis.device) { in mmc_sdio_init_card()
837 err = -ENOENT; in mmc_sdio_init_card()
846 /* handle as SDIO-only card if memory init failed */ in mmc_sdio_init_card()
852 card->type = MMC_TYPE_SDIO; in mmc_sdio_init_card()
854 card->dev.type = &sd_type; in mmc_sdio_init_card()
858 * If needed, disconnect card detection pull-up resistor. in mmc_sdio_init_card()
864 /* Initialization sequence for UHS-I cards */ in mmc_sdio_init_card()
866 if ((ocr & R4_18V_PRESENT) && card->sw_caps.sd3_bus_mode) { in mmc_sdio_init_card()
872 * Switch to high-speed (if supported). in mmc_sdio_init_card()
876 mmc_set_timing(card->host, MMC_TIMING_SD_HS); in mmc_sdio_init_card()
893 if (host->caps2 & MMC_CAP2_AVOID_3_3V && in mmc_sdio_init_card()
894 host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in mmc_sdio_init_card()
897 err = -EINVAL; in mmc_sdio_init_card()
901 host->card = card; in mmc_sdio_init_card()
916 ret = mmc_sdio_pre_init(host, host->card->ocr, NULL); in mmc_sdio_reinit_card()
920 return mmc_sdio_init_card(host, host->card->ocr, host->card); in mmc_sdio_reinit_card()
930 for (i = 0;i < host->card->sdio_funcs;i++) { in mmc_sdio_remove()
931 if (host->card->sdio_func[i]) { in mmc_sdio_remove()
932 sdio_remove_func(host->card->sdio_func[i]); in mmc_sdio_remove()
933 host->card->sdio_func[i] = NULL; in mmc_sdio_remove()
937 mmc_remove_card(host->card); in mmc_sdio_remove()
938 host->card = NULL; in mmc_sdio_remove()
942 * Card detection - card is alive.
946 return mmc_select_card(host->card); in mmc_sdio_alive()
957 if (host->caps & MMC_CAP_POWER_OFF_CARD) { in mmc_sdio_detect()
958 err = pm_runtime_resume_and_get(&host->card->dev); in mmc_sdio_detect()
979 * Since there is no specific reason to believe a new user in mmc_sdio_detect()
983 if (host->caps & MMC_CAP_POWER_OFF_CARD) in mmc_sdio_detect()
984 pm_runtime_put_sync(&host->card->dev); in mmc_sdio_detect()
998 * SDIO pre_suspend. We need to suspend all functions separately.
1006 for (i = 0; i < host->card->sdio_funcs; i++) { in mmc_sdio_pre_suspend()
1007 struct sdio_func *func = host->card->sdio_func[i]; in mmc_sdio_pre_suspend()
1008 if (func && sdio_func_present(func) && func->dev.driver) { in mmc_sdio_pre_suspend()
1009 const struct dev_pm_ops *pmops = func->dev.driver->pm; in mmc_sdio_pre_suspend()
1010 if (!pmops || !pmops->suspend || !pmops->resume) in mmc_sdio_pre_suspend()
1021 "missing suspend/resume ops for non-removable SDIO card\n"); in mmc_sdio_pre_suspend()
1022 /* Don't remove a non-removable card - we can't re-detect it. */ in mmc_sdio_pre_suspend()
1026 /* Remove the SDIO card and let it be re-detected later on. */ in mmc_sdio_pre_suspend()
1032 host->pm_flags = 0; in mmc_sdio_pre_suspend()
1038 * SDIO suspend. Suspend all functions separately.
1042 WARN_ON(host->sdio_irqs && !mmc_card_keep_power(host)); in mmc_sdio_suspend()
1044 /* Prevent processing of SDIO IRQs in suspended state. */ in mmc_sdio_suspend()
1045 mmc_card_set_suspended(host->card); in mmc_sdio_suspend()
1046 cancel_work_sync(&host->sdio_irq_work); in mmc_sdio_suspend()
1051 sdio_disable_4bit_bus(host->card); in mmc_sdio_suspend()
1055 } else if (host->retune_period) { in mmc_sdio_suspend()
1078 mmc_power_up(host, host->card->ocr); in mmc_sdio_resume()
1083 * for SDIO cards that are MMC_CAP_POWER_OFF_CARD in mmc_sdio_resume()
1085 if (host->caps & MMC_CAP_POWER_OFF_CARD) { in mmc_sdio_resume()
1086 pm_runtime_disable(&host->card->dev); in mmc_sdio_resume()
1087 pm_runtime_set_active(&host->card->dev); in mmc_sdio_resume()
1088 pm_runtime_enable(&host->card->dev); in mmc_sdio_resume()
1093 * We may have switched to 1-bit mode during suspend, in mmc_sdio_resume()
1095 * 4-bit mode or 8 bit mode. in mmc_sdio_resume()
1098 err = sdio_enable_4bit_bus(host->card); in mmc_sdio_resume()
1105 /* Allow SDIO IRQs to be processed again. */ in mmc_sdio_resume()
1106 mmc_card_clr_suspended(host->card); in mmc_sdio_resume()
1108 if (host->sdio_irqs) { in mmc_sdio_resume()
1109 if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) in mmc_sdio_resume()
1110 wake_up_process(host->sdio_irq_thread); in mmc_sdio_resume()
1111 else if (host->caps & MMC_CAP_SDIO_IRQ) in mmc_sdio_resume()
1112 schedule_work(&host->sdio_irq_work); in mmc_sdio_resume()
1118 host->pm_flags &= ~MMC_PM_KEEP_POWER; in mmc_sdio_resume()
1124 /* No references to the card, cut the power to it. */ in mmc_sdio_runtime_suspend()
1136 /* Restore power and re-initialize. */ in mmc_sdio_runtime_resume()
1138 mmc_power_up(host, host->card->ocr); in mmc_sdio_runtime_resume()
1146 * SDIO HW reset
1153 struct mmc_card *card = host->card; in mmc_sdio_hw_reset()
1158 * re-detected, thus all func drivers becomes informed about it. in mmc_sdio_hw_reset()
1160 if (atomic_read(&card->sdio_funcs_probed) > 1) { in mmc_sdio_hw_reset()
1163 host->rescan_entered = 0; in mmc_sdio_hw_reset()
1173 mmc_power_cycle(host, card->ocr); in mmc_sdio_hw_reset()
1179 mmc_set_clock(host, host->f_init); in mmc_sdio_sw_reset()
1204 * Starting point for SDIO card init.
1212 WARN_ON(!host->claimed); in mmc_attach_sdio()
1219 if (host->ocr_avail_sdio) in mmc_attach_sdio()
1220 host->ocr_avail = host->ocr_avail_sdio; in mmc_attach_sdio()
1229 err = -EINVAL; in mmc_attach_sdio()
1240 card = host->card; in mmc_attach_sdio()
1245 if (host->caps & MMC_CAP_POWER_OFF_CARD) { in mmc_attach_sdio()
1247 * Do not allow runtime suspend until after SDIO function in mmc_attach_sdio()
1250 pm_runtime_get_noresume(&card->dev); in mmc_attach_sdio()
1255 err = pm_runtime_set_active(&card->dev); in mmc_attach_sdio()
1262 pm_runtime_enable(&card->dev); in mmc_attach_sdio()
1270 card->sdio_funcs = 0; in mmc_attach_sdio()
1275 for (i = 0; i < funcs; i++, card->sdio_funcs++) { in mmc_attach_sdio()
1276 err = sdio_init_func(host->card, i + 1); in mmc_attach_sdio()
1283 if (host->caps & MMC_CAP_POWER_OFF_CARD) in mmc_attach_sdio()
1284 pm_runtime_enable(&card->sdio_func[i]->dev); in mmc_attach_sdio()
1291 err = mmc_add_card(host->card); in mmc_attach_sdio()
1296 * ...then the SDIO functions. in mmc_attach_sdio()
1299 err = sdio_add_func(host->card->sdio_func[i]); in mmc_attach_sdio()
1304 if (host->caps & MMC_CAP_POWER_OFF_CARD) in mmc_attach_sdio()
1305 pm_runtime_put(&card->dev); in mmc_attach_sdio()
1316 * runtime PM. Similarly we also don't pm_runtime_put() the SDIO card in mmc_attach_sdio()
1325 pr_err("%s: error %d whilst initialising SDIO card\n", in mmc_attach_sdio()