Lines Matching +full:wp +full:- +full:inverted

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (C) 2007-2008 Pierre Ossman
24 #include <linux/mmc/slot-gpio.h>
29 #include "slot-gpio.h"
46 if (!host->bus_ops) in mmc_host_class_prepare()
50 if (host->bus_ops->pre_suspend) in mmc_host_class_prepare()
51 return host->bus_ops->pre_suspend(host); in mmc_host_class_prepare()
76 wakeup_source_unregister(host->ws); in mmc_host_classdev_release()
77 if (of_alias_get_id(host->parent->of_node, "mmc") < 0) in mmc_host_classdev_release()
78 ida_free(&mmc_host_ida, host->index); in mmc_host_classdev_release()
108 * mmc_retune_enable() - enter a transfer mode that requires retuning
113 host->can_retune = 1; in mmc_retune_enable()
114 if (host->retune_period) in mmc_retune_enable()
115 mod_timer(&host->retune_timer, in mmc_retune_enable()
116 jiffies + host->retune_period * HZ); in mmc_retune_enable()
120 * Pause re-tuning for a small set of operations. The pause begins after the
125 if (!host->retune_paused) { in mmc_retune_pause()
126 host->retune_paused = 1; in mmc_retune_pause()
134 if (host->retune_paused) { in mmc_retune_unpause()
135 host->retune_paused = 0; in mmc_retune_unpause()
142 * mmc_retune_disable() - exit a transfer mode that requires retuning
150 host->can_retune = 0; in mmc_retune_disable()
151 del_timer_sync(&host->retune_timer); in mmc_retune_disable()
157 del_timer_sync(&host->retune_timer); in mmc_retune_timer_stop()
163 if (!host->hold_retune) in mmc_retune_hold()
164 host->retune_now = 1; in mmc_retune_hold()
165 host->hold_retune += 1; in mmc_retune_hold()
170 if (host->hold_retune) in mmc_retune_release()
171 host->hold_retune -= 1; in mmc_retune_release()
182 if (host->retune_now) in mmc_retune()
183 host->retune_now = 0; in mmc_retune()
187 if (!host->need_retune || host->doing_retune || !host->card) in mmc_retune()
190 host->need_retune = 0; in mmc_retune()
192 host->doing_retune = 1; in mmc_retune()
194 if (host->ios.timing == MMC_TIMING_MMC_HS400) { in mmc_retune()
195 err = mmc_hs400_to_hs200(host->card); in mmc_retune()
202 err = mmc_execute_tuning(host->card); in mmc_retune()
207 err = mmc_hs200_to_hs400(host->card); in mmc_retune()
209 host->doing_retune = 0; in mmc_retune()
228 phase->valid = !rc; in mmc_of_parse_timing_phase()
229 if (phase->valid) { in mmc_of_parse_timing_phase()
230 phase->in_deg = degrees[0]; in mmc_of_parse_timing_phase()
231 phase->out_deg = degrees[1]; in mmc_of_parse_timing_phase()
238 mmc_of_parse_timing_phase(dev, "clk-phase-legacy", in mmc_of_parse_clk_phase()
239 &map->phase[MMC_TIMING_LEGACY]); in mmc_of_parse_clk_phase()
240 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs", in mmc_of_parse_clk_phase()
241 &map->phase[MMC_TIMING_MMC_HS]); in mmc_of_parse_clk_phase()
242 mmc_of_parse_timing_phase(dev, "clk-phase-sd-hs", in mmc_of_parse_clk_phase()
243 &map->phase[MMC_TIMING_SD_HS]); in mmc_of_parse_clk_phase()
244 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr12", in mmc_of_parse_clk_phase()
245 &map->phase[MMC_TIMING_UHS_SDR12]); in mmc_of_parse_clk_phase()
246 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr25", in mmc_of_parse_clk_phase()
247 &map->phase[MMC_TIMING_UHS_SDR25]); in mmc_of_parse_clk_phase()
248 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr50", in mmc_of_parse_clk_phase()
249 &map->phase[MMC_TIMING_UHS_SDR50]); in mmc_of_parse_clk_phase()
250 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr104", in mmc_of_parse_clk_phase()
251 &map->phase[MMC_TIMING_UHS_SDR104]); in mmc_of_parse_clk_phase()
252 mmc_of_parse_timing_phase(dev, "clk-phase-uhs-ddr50", in mmc_of_parse_clk_phase()
253 &map->phase[MMC_TIMING_UHS_DDR50]); in mmc_of_parse_clk_phase()
254 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-ddr52", in mmc_of_parse_clk_phase()
255 &map->phase[MMC_TIMING_MMC_DDR52]); in mmc_of_parse_clk_phase()
256 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs200", in mmc_of_parse_clk_phase()
257 &map->phase[MMC_TIMING_MMC_HS200]); in mmc_of_parse_clk_phase()
258 mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs400", in mmc_of_parse_clk_phase()
259 &map->phase[MMC_TIMING_MMC_HS400]); in mmc_of_parse_clk_phase()
264 * mmc_of_parse() - parse host's device properties
269 * parse the properties and set respective generic mmc-host flags and
274 struct device *dev = host->parent; in mmc_of_parse()
281 /* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */ in mmc_of_parse()
282 if (device_property_read_u32(dev, "bus-width", &bus_width) < 0) { in mmc_of_parse()
283 dev_dbg(host->parent, in mmc_of_parse()
284 "\"bus-width\" property is missing, assuming 1 bit.\n"); in mmc_of_parse()
290 host->caps |= MMC_CAP_8_BIT_DATA; in mmc_of_parse()
291 fallthrough; /* Hosts capable of 8-bit can also do 4 bits */ in mmc_of_parse()
293 host->caps |= MMC_CAP_4_BIT_DATA; in mmc_of_parse()
298 dev_err(host->parent, in mmc_of_parse()
299 "Invalid \"bus-width\" value %u!\n", bus_width); in mmc_of_parse()
300 return -EINVAL; in mmc_of_parse()
303 /* f_max is obtained from the optional "max-frequency" property */ in mmc_of_parse()
304 device_property_read_u32(dev, "max-frequency", &host->f_max); in mmc_of_parse()
307 * Configure CD and WP pins. They are both by default active low to in mmc_of_parse()
308 * match the SDHCI spec. If GPIOs are provided for CD and / or WP, the in mmc_of_parse()
309 * mmc-gpio helpers are used to attach, configure and use them. If in mmc_of_parse()
311 * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the in mmc_of_parse()
312 * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability in mmc_of_parse()
313 * is set. If the "non-removable" property is found, the in mmc_of_parse()
314 * MMC_CAP_NONREMOVABLE capability is set and no card-detection in mmc_of_parse()
320 if (device_property_read_bool(dev, "non-removable")) { in mmc_of_parse()
321 host->caps |= MMC_CAP_NONREMOVABLE; in mmc_of_parse()
323 if (device_property_read_bool(dev, "cd-inverted")) in mmc_of_parse()
324 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; in mmc_of_parse()
326 if (device_property_read_u32(dev, "cd-debounce-delay-ms", in mmc_of_parse()
330 if (device_property_read_bool(dev, "broken-cd")) in mmc_of_parse()
331 host->caps |= MMC_CAP_NEEDS_POLL; in mmc_of_parse()
336 dev_info(host->parent, "Got CD GPIO\n"); in mmc_of_parse()
337 else if (ret != -ENOENT && ret != -ENOSYS) in mmc_of_parse()
343 if (device_property_read_bool(dev, "wp-inverted")) in mmc_of_parse()
344 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; in mmc_of_parse()
346 ret = mmc_gpiod_request_ro(host, "wp", 0, 0); in mmc_of_parse()
348 dev_info(host->parent, "Got WP GPIO\n"); in mmc_of_parse()
349 else if (ret != -ENOENT && ret != -ENOSYS) in mmc_of_parse()
352 if (device_property_read_bool(dev, "disable-wp")) in mmc_of_parse()
353 host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; in mmc_of_parse()
355 if (device_property_read_bool(dev, "cap-sd-highspeed")) in mmc_of_parse()
356 host->caps |= MMC_CAP_SD_HIGHSPEED; in mmc_of_parse()
357 if (device_property_read_bool(dev, "cap-mmc-highspeed")) in mmc_of_parse()
358 host->caps |= MMC_CAP_MMC_HIGHSPEED; in mmc_of_parse()
359 if (device_property_read_bool(dev, "sd-uhs-sdr12")) in mmc_of_parse()
360 host->caps |= MMC_CAP_UHS_SDR12; in mmc_of_parse()
361 if (device_property_read_bool(dev, "sd-uhs-sdr25")) in mmc_of_parse()
362 host->caps |= MMC_CAP_UHS_SDR25; in mmc_of_parse()
363 if (device_property_read_bool(dev, "sd-uhs-sdr50")) in mmc_of_parse()
364 host->caps |= MMC_CAP_UHS_SDR50; in mmc_of_parse()
365 if (device_property_read_bool(dev, "sd-uhs-sdr104")) in mmc_of_parse()
366 host->caps |= MMC_CAP_UHS_SDR104; in mmc_of_parse()
367 if (device_property_read_bool(dev, "sd-uhs-ddr50")) in mmc_of_parse()
368 host->caps |= MMC_CAP_UHS_DDR50; in mmc_of_parse()
369 if (device_property_read_bool(dev, "cap-power-off-card")) in mmc_of_parse()
370 host->caps |= MMC_CAP_POWER_OFF_CARD; in mmc_of_parse()
371 if (device_property_read_bool(dev, "cap-mmc-hw-reset")) in mmc_of_parse()
372 host->caps |= MMC_CAP_HW_RESET; in mmc_of_parse()
373 if (device_property_read_bool(dev, "cap-sdio-irq")) in mmc_of_parse()
374 host->caps |= MMC_CAP_SDIO_IRQ; in mmc_of_parse()
375 if (device_property_read_bool(dev, "full-pwr-cycle")) in mmc_of_parse()
376 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; in mmc_of_parse()
377 if (device_property_read_bool(dev, "full-pwr-cycle-in-suspend")) in mmc_of_parse()
378 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND; in mmc_of_parse()
379 if (device_property_read_bool(dev, "keep-power-in-suspend")) in mmc_of_parse()
380 host->pm_caps |= MMC_PM_KEEP_POWER; in mmc_of_parse()
381 if (device_property_read_bool(dev, "wakeup-source") || in mmc_of_parse()
382 device_property_read_bool(dev, "enable-sdio-wakeup")) /* legacy */ in mmc_of_parse()
383 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; in mmc_of_parse()
384 if (device_property_read_bool(dev, "mmc-ddr-3_3v")) in mmc_of_parse()
385 host->caps |= MMC_CAP_3_3V_DDR; in mmc_of_parse()
386 if (device_property_read_bool(dev, "mmc-ddr-1_8v")) in mmc_of_parse()
387 host->caps |= MMC_CAP_1_8V_DDR; in mmc_of_parse()
388 if (device_property_read_bool(dev, "mmc-ddr-1_2v")) in mmc_of_parse()
389 host->caps |= MMC_CAP_1_2V_DDR; in mmc_of_parse()
390 if (device_property_read_bool(dev, "mmc-hs200-1_8v")) in mmc_of_parse()
391 host->caps2 |= MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
392 if (device_property_read_bool(dev, "mmc-hs200-1_2v")) in mmc_of_parse()
393 host->caps2 |= MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
394 if (device_property_read_bool(dev, "mmc-hs400-1_8v")) in mmc_of_parse()
395 host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
396 if (device_property_read_bool(dev, "mmc-hs400-1_2v")) in mmc_of_parse()
397 host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
398 if (device_property_read_bool(dev, "mmc-hs400-enhanced-strobe")) in mmc_of_parse()
399 host->caps2 |= MMC_CAP2_HS400_ES; in mmc_of_parse()
400 if (device_property_read_bool(dev, "no-sdio")) in mmc_of_parse()
401 host->caps2 |= MMC_CAP2_NO_SDIO; in mmc_of_parse()
402 if (device_property_read_bool(dev, "no-sd")) in mmc_of_parse()
403 host->caps2 |= MMC_CAP2_NO_SD; in mmc_of_parse()
404 if (device_property_read_bool(dev, "no-mmc")) in mmc_of_parse()
405 host->caps2 |= MMC_CAP2_NO_MMC; in mmc_of_parse()
406 if (device_property_read_bool(dev, "no-mmc-hs400")) in mmc_of_parse()
407 host->caps2 &= ~(MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V | in mmc_of_parse()
410 /* Must be after "non-removable" check */ in mmc_of_parse()
411 if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) { in mmc_of_parse()
412 if (host->caps & MMC_CAP_NONREMOVABLE) in mmc_of_parse()
413 host->fixed_drv_type = drv_type; in mmc_of_parse()
415 dev_err(host->parent, in mmc_of_parse()
419 host->dsr_req = !device_property_read_u32(dev, "dsr", &host->dsr); in mmc_of_parse()
420 if (host->dsr_req && (host->dsr & ~0xffff)) { in mmc_of_parse()
421 dev_err(host->parent, in mmc_of_parse()
423 host->dsr); in mmc_of_parse()
424 host->dsr_req = 0; in mmc_of_parse()
427 device_property_read_u32(dev, "post-power-on-delay-ms", in mmc_of_parse()
428 &host->ios.power_delay_ms); in mmc_of_parse()
436 * mmc_of_parse_voltage - return mask of supported voltages
440 * Parse the "voltage-ranges" property, returning zero if it is not
441 * found, negative errno if the voltage-range specification is invalid,
442 * or one if the voltage-range is specified and successfully parsed.
446 const char *prop = "voltage-ranges"; in mmc_of_parse_voltage()
447 struct device *dev = host->parent; in mmc_of_parse_voltage()
464 return -EINVAL; in mmc_of_parse_voltage()
469 return -ENOMEM; in mmc_of_parse_voltage()
486 return -EINVAL; in mmc_of_parse_voltage()
498 * mmc_first_nonreserved_index() - get the first index that is not reserved
512 * mmc_alloc_host - initialise the per-host structure.
516 * Initialise the per-host structure.
529 host->rescan_disable = 1; in mmc_alloc_host()
531 alias_id = of_alias_get_id(dev->of_node, "mmc"); in mmc_alloc_host()
538 index = ida_alloc_range(&mmc_host_ida, min_idx, max_idx - 1, in mmc_alloc_host()
546 host->index = index; in mmc_alloc_host()
548 dev_set_name(&host->class_dev, "mmc%d", host->index); in mmc_alloc_host()
549 host->ws = wakeup_source_register(NULL, dev_name(&host->class_dev)); in mmc_alloc_host()
551 host->parent = dev; in mmc_alloc_host()
552 host->class_dev.parent = dev; in mmc_alloc_host()
553 host->class_dev.class = &mmc_host_class; in mmc_alloc_host()
554 device_initialize(&host->class_dev); in mmc_alloc_host()
555 device_enable_async_suspend(&host->class_dev); in mmc_alloc_host()
558 put_device(&host->class_dev); in mmc_alloc_host()
562 spin_lock_init(&host->lock); in mmc_alloc_host()
563 init_waitqueue_head(&host->wq); in mmc_alloc_host()
564 INIT_DELAYED_WORK(&host->detect, mmc_rescan); in mmc_alloc_host()
565 INIT_WORK(&host->sdio_irq_work, sdio_irq_work); in mmc_alloc_host()
566 timer_setup(&host->retune_timer, mmc_retune_timer, 0); in mmc_alloc_host()
572 host->max_segs = 1; in mmc_alloc_host()
573 host->max_seg_size = PAGE_SIZE; in mmc_alloc_host()
575 host->max_req_size = PAGE_SIZE; in mmc_alloc_host()
576 host->max_blk_size = 512; in mmc_alloc_host()
577 host->max_blk_count = PAGE_SIZE / 512; in mmc_alloc_host()
579 host->fixed_drv_type = -EINVAL; in mmc_alloc_host()
580 host->ios.power_delay_ms = 10; in mmc_alloc_host()
581 host->ios.power_mode = MMC_POWER_UNDEFINED; in mmc_alloc_host()
616 struct device *dev = host->parent; in mmc_validate_host_caps()
617 u32 caps = host->caps, caps2 = host->caps2; in mmc_validate_host_caps()
619 if (caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) { in mmc_validate_host_caps()
620 dev_warn(dev, "missing ->enable_sdio_irq() ops\n"); in mmc_validate_host_caps()
621 return -EINVAL; in mmc_validate_host_caps()
626 dev_warn(dev, "drop HS400 support since no 8-bit bus\n"); in mmc_validate_host_caps()
627 host->caps2 = caps2 & ~MMC_CAP2_HS400_ES & ~MMC_CAP2_HS400; in mmc_validate_host_caps()
634 * mmc_add_host - initialise host hardware
649 err = device_add(&host->class_dev); in mmc_add_host()
653 led_trigger_register_simple(dev_name(&host->class_dev), &host->led); in mmc_add_host()
664 * mmc_remove_host - remove host hardware
677 device_del(&host->class_dev); in mmc_remove_host()
679 led_trigger_unregister_simple(host->led); in mmc_remove_host()
685 * mmc_free_host - free the host structure
692 cancel_delayed_work_sync(&host->detect); in mmc_free_host()
694 put_device(&host->class_dev); in mmc_free_host()