Lines Matching +full:no +full:- +full:mmc

1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/mmc/core/host.c
6 * Copyright (C) 2007-2008 Pierre Ossman
9 * MMC host class device management
21 #include <linux/mmc/host.h>
22 #include <linux/mmc/card.h>
23 #include <linux/mmc/slot-gpio.h>
28 #include "slot-gpio.h"
45 if (!host->bus_ops) in mmc_host_class_prepare()
49 if (host->bus_ops->pre_suspend) in mmc_host_class_prepare()
50 return host->bus_ops->pre_suspend(host); in mmc_host_class_prepare()
75 wakeup_source_unregister(host->ws); in mmc_host_classdev_release()
76 if (of_alias_get_id(host->parent->of_node, "mmc") < 0) in mmc_host_classdev_release()
77 ida_free(&mmc_host_ida, host->index); in mmc_host_classdev_release()
107 * mmc_retune_enable() - enter a transfer mode that requires retuning
112 host->can_retune = 1; in mmc_retune_enable()
113 if (host->retune_period) in mmc_retune_enable()
114 mod_timer(&host->retune_timer, in mmc_retune_enable()
115 jiffies + host->retune_period * HZ); in mmc_retune_enable()
119 * Pause re-tuning for a small set of operations. The pause begins after the
124 if (!host->retune_paused) { in mmc_retune_pause()
125 host->retune_paused = 1; in mmc_retune_pause()
133 if (host->retune_paused) { in mmc_retune_unpause()
134 host->retune_paused = 0; in mmc_retune_unpause()
141 * mmc_retune_disable() - exit a transfer mode that requires retuning
149 host->can_retune = 0; in mmc_retune_disable()
150 del_timer_sync(&host->retune_timer); in mmc_retune_disable()
156 del_timer_sync(&host->retune_timer); in mmc_retune_timer_stop()
162 if (!host->hold_retune) in mmc_retune_hold()
163 host->retune_now = 1; in mmc_retune_hold()
164 host->hold_retune += 1; in mmc_retune_hold()
169 if (host->hold_retune) in mmc_retune_release()
170 host->hold_retune -= 1; in mmc_retune_release()
181 if (host->retune_now) in mmc_retune()
182 host->retune_now = 0; in mmc_retune()
186 if (!host->need_retune || host->doing_retune || !host->card) in mmc_retune()
189 host->need_retune = 0; in mmc_retune()
191 host->doing_retune = 1; in mmc_retune()
193 if (host->ios.timing == MMC_TIMING_MMC_HS400) { in mmc_retune()
194 err = mmc_hs400_to_hs200(host->card); in mmc_retune()
201 err = mmc_execute_tuning(host->card); in mmc_retune()
206 err = mmc_hs200_to_hs400(host->card); in mmc_retune()
208 host->doing_retune = 0; in mmc_retune()
227 phase->valid = !rc; in mmc_of_parse_timing_phase()
228 if (phase->valid) { in mmc_of_parse_timing_phase()
229 phase->in_deg = degrees[0]; in mmc_of_parse_timing_phase()
230 phase->out_deg = degrees[1]; in mmc_of_parse_timing_phase()
237 mmc_of_parse_timing_phase(dev, "clk-phase-legacy", in mmc_of_parse_clk_phase()
238 &map->phase[MMC_TIMING_LEGACY]); in mmc_of_parse_clk_phase()
239 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs", in mmc_of_parse_clk_phase()
240 &map->phase[MMC_TIMING_MMC_HS]); in mmc_of_parse_clk_phase()
241 mmc_of_parse_timing_phase(dev, "clk-phase-sd-hs", in mmc_of_parse_clk_phase()
242 &map->phase[MMC_TIMING_SD_HS]); in mmc_of_parse_clk_phase()
243 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr12", in mmc_of_parse_clk_phase()
244 &map->phase[MMC_TIMING_UHS_SDR12]); in mmc_of_parse_clk_phase()
245 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr25", in mmc_of_parse_clk_phase()
246 &map->phase[MMC_TIMING_UHS_SDR25]); in mmc_of_parse_clk_phase()
247 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr50", in mmc_of_parse_clk_phase()
248 &map->phase[MMC_TIMING_UHS_SDR50]); in mmc_of_parse_clk_phase()
249 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr104", in mmc_of_parse_clk_phase()
250 &map->phase[MMC_TIMING_UHS_SDR104]); in mmc_of_parse_clk_phase()
251 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-ddr50", in mmc_of_parse_clk_phase()
252 &map->phase[MMC_TIMING_UHS_DDR50]); in mmc_of_parse_clk_phase()
253 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-ddr52", in mmc_of_parse_clk_phase()
254 &map->phase[MMC_TIMING_MMC_DDR52]); in mmc_of_parse_clk_phase()
255 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs200", in mmc_of_parse_clk_phase()
256 &map->phase[MMC_TIMING_MMC_HS200]); in mmc_of_parse_clk_phase()
257 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs400", in mmc_of_parse_clk_phase()
258 &map->phase[MMC_TIMING_MMC_HS400]); in mmc_of_parse_clk_phase()
263 * mmc_of_parse() - parse host's device properties
266 * To keep the rest of the MMC subsystem unaware of whether DT has been
268 * parse the properties and set respective generic mmc-host flags and
273 struct device *dev = host->parent; in mmc_of_parse()
280 /* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */ in mmc_of_parse()
281 if (device_property_read_u32(dev, "bus-width", &bus_width) < 0) { in mmc_of_parse()
282 dev_dbg(host->parent, in mmc_of_parse()
283 "\"bus-width\" property is missing, assuming 1 bit.\n"); in mmc_of_parse()
289 host->caps |= MMC_CAP_8_BIT_DATA; in mmc_of_parse()
290 fallthrough; /* Hosts capable of 8-bit can also do 4 bits */ in mmc_of_parse()
292 host->caps |= MMC_CAP_4_BIT_DATA; in mmc_of_parse()
297 dev_err(host->parent, in mmc_of_parse()
298 "Invalid \"bus-width\" value %u!\n", bus_width); in mmc_of_parse()
299 return -EINVAL; in mmc_of_parse()
302 /* f_max is obtained from the optional "max-frequency" property */ in mmc_of_parse()
303 device_property_read_u32(dev, "max-frequency", &host->f_max); in mmc_of_parse()
308 * mmc-gpio helpers are used to attach, configure and use them. If in mmc_of_parse()
310 * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the in mmc_of_parse()
311 * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability in mmc_of_parse()
312 * is set. If the "non-removable" property is found, the in mmc_of_parse()
313 * MMC_CAP_NONREMOVABLE capability is set and no card-detection in mmc_of_parse()
319 if (device_property_read_bool(dev, "non-removable")) { in mmc_of_parse()
320 host->caps |= MMC_CAP_NONREMOVABLE; in mmc_of_parse()
322 if (device_property_read_bool(dev, "cd-inverted")) in mmc_of_parse()
323 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; in mmc_of_parse()
325 if (device_property_read_u32(dev, "cd-debounce-delay-ms", in mmc_of_parse()
329 if (device_property_read_bool(dev, "broken-cd")) in mmc_of_parse()
330 host->caps |= MMC_CAP_NEEDS_POLL; in mmc_of_parse()
335 dev_info(host->parent, "Got CD GPIO\n"); in mmc_of_parse()
336 else if (ret != -ENOENT && ret != -ENOSYS) in mmc_of_parse()
342 if (device_property_read_bool(dev, "wp-inverted")) in mmc_of_parse()
343 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; in mmc_of_parse()
347 dev_info(host->parent, "Got WP GPIO\n"); in mmc_of_parse()
348 else if (ret != -ENOENT && ret != -ENOSYS) in mmc_of_parse()
351 if (device_property_read_bool(dev, "disable-wp")) in mmc_of_parse()
352 host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; in mmc_of_parse()
354 if (device_property_read_bool(dev, "cap-sd-highspeed")) in mmc_of_parse()
355 host->caps |= MMC_CAP_SD_HIGHSPEED; in mmc_of_parse()
356 if (device_property_read_bool(dev, "cap-mmc-highspeed")) in mmc_of_parse()
357 host->caps |= MMC_CAP_MMC_HIGHSPEED; in mmc_of_parse()
358 if (device_property_read_bool(dev, "sd-uhs-sdr12")) in mmc_of_parse()
359 host->caps |= MMC_CAP_UHS_SDR12; in mmc_of_parse()
360 if (device_property_read_bool(dev, "sd-uhs-sdr25")) in mmc_of_parse()
361 host->caps |= MMC_CAP_UHS_SDR25; in mmc_of_parse()
362 if (device_property_read_bool(dev, "sd-uhs-sdr50")) in mmc_of_parse()
363 host->caps |= MMC_CAP_UHS_SDR50; in mmc_of_parse()
364 if (device_property_read_bool(dev, "sd-uhs-sdr104")) in mmc_of_parse()
365 host->caps |= MMC_CAP_UHS_SDR104; in mmc_of_parse()
366 if (device_property_read_bool(dev, "sd-uhs-ddr50")) in mmc_of_parse()
367 host->caps |= MMC_CAP_UHS_DDR50; in mmc_of_parse()
368 if (device_property_read_bool(dev, "cap-power-off-card")) in mmc_of_parse()
369 host->caps |= MMC_CAP_POWER_OFF_CARD; in mmc_of_parse()
370 if (device_property_read_bool(dev, "cap-mmc-hw-reset")) in mmc_of_parse()
371 host->caps |= MMC_CAP_HW_RESET; in mmc_of_parse()
372 if (device_property_read_bool(dev, "cap-sdio-irq")) in mmc_of_parse()
373 host->caps |= MMC_CAP_SDIO_IRQ; in mmc_of_parse()
374 if (device_property_read_bool(dev, "full-pwr-cycle")) in mmc_of_parse()
375 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; in mmc_of_parse()
376 if (device_property_read_bool(dev, "full-pwr-cycle-in-suspend")) in mmc_of_parse()
377 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND; in mmc_of_parse()
378 if (device_property_read_bool(dev, "keep-power-in-suspend")) in mmc_of_parse()
379 host->pm_caps |= MMC_PM_KEEP_POWER; in mmc_of_parse()
380 if (device_property_read_bool(dev, "wakeup-source") || in mmc_of_parse()
381 device_property_read_bool(dev, "enable-sdio-wakeup")) /* legacy */ in mmc_of_parse()
382 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; in mmc_of_parse()
383 if (device_property_read_bool(dev, "mmc-ddr-3_3v")) in mmc_of_parse()
384 host->caps |= MMC_CAP_3_3V_DDR; in mmc_of_parse()
385 if (device_property_read_bool(dev, "mmc-ddr-1_8v")) in mmc_of_parse()
386 host->caps |= MMC_CAP_1_8V_DDR; in mmc_of_parse()
387 if (device_property_read_bool(dev, "mmc-ddr-1_2v")) in mmc_of_parse()
388 host->caps |= MMC_CAP_1_2V_DDR; in mmc_of_parse()
389 if (device_property_read_bool(dev, "mmc-hs200-1_8v")) in mmc_of_parse()
390 host->caps2 |= MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
391 if (device_property_read_bool(dev, "mmc-hs200-1_2v")) in mmc_of_parse()
392 host->caps2 |= MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
393 if (device_property_read_bool(dev, "mmc-hs400-1_8v")) in mmc_of_parse()
394 host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
395 if (device_property_read_bool(dev, "mmc-hs400-1_2v")) in mmc_of_parse()
396 host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
397 if (device_property_read_bool(dev, "mmc-hs400-enhanced-strobe")) in mmc_of_parse()
398 host->caps2 |= MMC_CAP2_HS400_ES; in mmc_of_parse()
399 if (device_property_read_bool(dev, "no-sdio")) in mmc_of_parse()
400 host->caps2 |= MMC_CAP2_NO_SDIO; in mmc_of_parse()
401 if (device_property_read_bool(dev, "no-sd")) in mmc_of_parse()
402 host->caps2 |= MMC_CAP2_NO_SD; in mmc_of_parse()
403 if (device_property_read_bool(dev, "no-mmc")) in mmc_of_parse()
404 host->caps2 |= MMC_CAP2_NO_MMC; in mmc_of_parse()
405 if (device_property_read_bool(dev, "no-mmc-hs400")) in mmc_of_parse()
406 host->caps2 &= ~(MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V | in mmc_of_parse()
409 /* Must be after "non-removable" check */ in mmc_of_parse()
410 if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) { in mmc_of_parse()
411 if (host->caps & MMC_CAP_NONREMOVABLE) in mmc_of_parse()
412 host->fixed_drv_type = drv_type; in mmc_of_parse()
414 dev_err(host->parent, in mmc_of_parse()
418 host->dsr_req = !device_property_read_u32(dev, "dsr", &host->dsr); in mmc_of_parse()
419 if (host->dsr_req && (host->dsr & ~0xffff)) { in mmc_of_parse()
420 dev_err(host->parent, in mmc_of_parse()
422 host->dsr); in mmc_of_parse()
423 host->dsr_req = 0; in mmc_of_parse()
426 device_property_read_u32(dev, "post-power-on-delay-ms", in mmc_of_parse()
427 &host->ios.power_delay_ms); in mmc_of_parse()
435 * mmc_of_parse_voltage - return mask of supported voltages
437 * @mask: mask of voltages available for MMC/SD/SDIO
439 * Parse the "voltage-ranges" property, returning zero if it is not
440 * found, negative errno if the voltage-range specification is invalid,
441 * or one if the voltage-range is specified and successfully parsed.
445 const char *prop = "voltage-ranges"; in mmc_of_parse_voltage()
446 struct device *dev = host->parent; in mmc_of_parse_voltage()
463 return -EINVAL; in mmc_of_parse_voltage()
468 return -ENOMEM; in mmc_of_parse_voltage()
485 return -EINVAL; in mmc_of_parse_voltage()
497 * mmc_first_nonreserved_index() - get the first index that is not reserved
503 max = of_alias_get_highest_id("mmc"); in mmc_first_nonreserved_index()
511 * mmc_alloc_host - initialise the per-host structure.
515 * Initialise the per-host structure.
528 host->rescan_disable = 1; in mmc_alloc_host()
530 alias_id = of_alias_get_id(dev->of_node, "mmc"); in mmc_alloc_host()
537 index = ida_alloc_range(&mmc_host_ida, min_idx, max_idx - 1, in mmc_alloc_host()
545 host->index = index; in mmc_alloc_host()
547 dev_set_name(&host->class_dev, "mmc%d", host->index); in mmc_alloc_host()
548 host->ws = wakeup_source_register(NULL, dev_name(&host->class_dev)); in mmc_alloc_host()
550 host->parent = dev; in mmc_alloc_host()
551 host->class_dev.parent = dev; in mmc_alloc_host()
552 host->class_dev.class = &mmc_host_class; in mmc_alloc_host()
553 device_initialize(&host->class_dev); in mmc_alloc_host()
554 device_enable_async_suspend(&host->class_dev); in mmc_alloc_host()
557 put_device(&host->class_dev); in mmc_alloc_host()
561 spin_lock_init(&host->lock); in mmc_alloc_host()
562 init_waitqueue_head(&host->wq); in mmc_alloc_host()
563 INIT_DELAYED_WORK(&host->detect, mmc_rescan); in mmc_alloc_host()
564 INIT_WORK(&host->sdio_irq_work, sdio_irq_work); in mmc_alloc_host()
565 timer_setup(&host->retune_timer, mmc_retune_timer, 0); in mmc_alloc_host()
571 host->max_segs = 1; in mmc_alloc_host()
572 host->max_seg_size = PAGE_SIZE; in mmc_alloc_host()
574 host->max_req_size = PAGE_SIZE; in mmc_alloc_host()
575 host->max_blk_size = 512; in mmc_alloc_host()
576 host->max_blk_count = PAGE_SIZE / 512; in mmc_alloc_host()
578 host->fixed_drv_type = -EINVAL; in mmc_alloc_host()
579 host->ios.power_delay_ms = 10; in mmc_alloc_host()
580 host->ios.power_mode = MMC_POWER_UNDEFINED; in mmc_alloc_host()
615 struct device *dev = host->parent; in mmc_validate_host_caps()
616 u32 caps = host->caps, caps2 = host->caps2; in mmc_validate_host_caps()
618 if (caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) { in mmc_validate_host_caps()
619 dev_warn(dev, "missing ->enable_sdio_irq() ops\n"); in mmc_validate_host_caps()
620 return -EINVAL; in mmc_validate_host_caps()
625 dev_warn(dev, "drop HS400 support since no 8-bit bus\n"); in mmc_validate_host_caps()
626 host->caps2 = caps2 & ~MMC_CAP2_HS400_ES & ~MMC_CAP2_HS400; in mmc_validate_host_caps()
633 * mmc_add_host - initialise host hardware
634 * @host: mmc host
648 err = device_add(&host->class_dev); in mmc_add_host()
652 led_trigger_register_simple(dev_name(&host->class_dev), &host->led); in mmc_add_host()
663 * mmc_remove_host - remove host hardware
664 * @host: mmc host
667 * and power down the MMC bus. No new requests will be issued
676 device_del(&host->class_dev); in mmc_remove_host()
678 led_trigger_unregister_simple(host->led); in mmc_remove_host()
684 * mmc_free_host - free the host structure
685 * @host: mmc host
691 cancel_delayed_work_sync(&host->detect); in mmc_free_host()
693 put_device(&host->class_dev); in mmc_free_host()