Lines Matching +full:debounce +full:- +full:exit

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