Lines Matching full:host

3  *  linux/drivers/mmc/core/host.c
9 * MMC host class device management
21 #include <linux/mmc/host.h>
27 #include "host.h"
39 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_class_prepare() local
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()
57 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_class_complete() local
59 _mmc_detect_change(host, 0, false); in mmc_host_class_complete()
74 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_classdev_release() local
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()
78 kfree(host); in mmc_host_classdev_release()
83 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_classdev_shutdown() local
85 __mmc_stop_host(host); in mmc_host_classdev_shutdown()
108 * @host: host which should retune now
110 void mmc_retune_enable(struct mmc_host *host) in mmc_retune_enable() argument
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()
122 void mmc_retune_pause(struct mmc_host *host) in mmc_retune_pause() argument
124 if (!host->retune_paused) { in mmc_retune_pause()
125 host->retune_paused = 1; in mmc_retune_pause()
126 mmc_retune_hold(host); in mmc_retune_pause()
131 void mmc_retune_unpause(struct mmc_host *host) in mmc_retune_unpause() argument
133 if (host->retune_paused) { in mmc_retune_unpause()
134 host->retune_paused = 0; in mmc_retune_unpause()
135 mmc_retune_release(host); in mmc_retune_unpause()
142 * @host: host which should not retune anymore
146 void mmc_retune_disable(struct mmc_host *host) in mmc_retune_disable() argument
148 mmc_retune_unpause(host); in mmc_retune_disable()
149 host->can_retune = 0; in mmc_retune_disable()
150 del_timer_sync(&host->retune_timer); in mmc_retune_disable()
151 mmc_retune_clear(host); in mmc_retune_disable()
154 void mmc_retune_timer_stop(struct mmc_host *host) in mmc_retune_timer_stop() argument
156 del_timer_sync(&host->retune_timer); in mmc_retune_timer_stop()
160 void mmc_retune_hold(struct mmc_host *host) in mmc_retune_hold() argument
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()
167 void mmc_retune_release(struct mmc_host *host) in mmc_retune_release() argument
169 if (host->hold_retune) in mmc_retune_release()
170 host->hold_retune -= 1; in mmc_retune_release()
176 int mmc_retune(struct mmc_host *host) in mmc_retune() argument
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()
215 struct mmc_host *host = from_timer(host, t, retune_timer); in mmc_retune_timer() local
217 mmc_retune_needed(host); in mmc_retune_timer()
263 * mmc_of_parse() - parse host's device properties
264 * @host: host whose properties should be parsed.
267 * used to instantiate and configure this host instance or not, we
268 * parse the properties and set respective generic mmc-host flags and
271 int mmc_of_parse(struct mmc_host *host) in mmc_of_parse() argument
273 struct device *dev = host->parent; in mmc_of_parse()
282 dev_dbg(host->parent, in mmc_of_parse()
289 host->caps |= MMC_CAP_8_BIT_DATA; 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()
303 device_property_read_u32(dev, "max-frequency", &host->f_max); in mmc_of_parse()
320 host->caps |= MMC_CAP_NONREMOVABLE; in mmc_of_parse()
323 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; in mmc_of_parse()
330 host->caps |= MMC_CAP_NEEDS_POLL; in mmc_of_parse()
332 ret = mmc_gpiod_request_cd(host, "cd", 0, false, in mmc_of_parse()
335 dev_info(host->parent, "Got CD GPIO\n"); in mmc_of_parse()
343 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; in mmc_of_parse()
345 ret = mmc_gpiod_request_ro(host, "wp", 0, 0); in mmc_of_parse()
347 dev_info(host->parent, "Got WP GPIO\n"); in mmc_of_parse()
352 host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; in mmc_of_parse()
355 host->caps |= MMC_CAP_SD_HIGHSPEED; in mmc_of_parse()
357 host->caps |= MMC_CAP_MMC_HIGHSPEED; in mmc_of_parse()
359 host->caps |= MMC_CAP_UHS_SDR12; in mmc_of_parse()
361 host->caps |= MMC_CAP_UHS_SDR25; in mmc_of_parse()
363 host->caps |= MMC_CAP_UHS_SDR50; in mmc_of_parse()
365 host->caps |= MMC_CAP_UHS_SDR104; in mmc_of_parse()
367 host->caps |= MMC_CAP_UHS_DDR50; in mmc_of_parse()
369 host->caps |= MMC_CAP_POWER_OFF_CARD; in mmc_of_parse()
371 host->caps |= MMC_CAP_HW_RESET; in mmc_of_parse()
373 host->caps |= MMC_CAP_SDIO_IRQ; in mmc_of_parse()
375 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; in mmc_of_parse()
377 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND; in mmc_of_parse()
379 host->pm_caps |= MMC_PM_KEEP_POWER; in mmc_of_parse()
382 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; in mmc_of_parse()
384 host->caps |= MMC_CAP_3_3V_DDR; in mmc_of_parse()
386 host->caps |= MMC_CAP_1_8V_DDR; in mmc_of_parse()
388 host->caps |= MMC_CAP_1_2V_DDR; in mmc_of_parse()
390 host->caps2 |= MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
392 host->caps2 |= MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
394 host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
396 host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
398 host->caps2 |= MMC_CAP2_HS400_ES; in mmc_of_parse()
400 host->caps2 |= MMC_CAP2_NO_SDIO; in mmc_of_parse()
402 host->caps2 |= MMC_CAP2_NO_SD; in mmc_of_parse()
404 host->caps2 |= MMC_CAP2_NO_MMC; in mmc_of_parse()
406 host->caps2 &= ~(MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V | 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()
427 &host->ios.power_delay_ms); in mmc_of_parse()
429 return mmc_pwrseq_alloc(host); in mmc_of_parse()
436 * @host: host whose properties should be parsed.
443 int mmc_of_parse_voltage(struct mmc_host *host, u32 *mask) in mmc_of_parse_voltage() argument
446 struct device *dev = host->parent; in mmc_of_parse_voltage()
511 * mmc_alloc_host - initialise the per-host structure.
513 * @dev: pointer to host device model structure
515 * Initialise the per-host structure.
520 struct mmc_host *host; in mmc_alloc_host() local
523 host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); in mmc_alloc_host()
524 if (!host) in mmc_alloc_host()
528 host->rescan_disable = 1; in mmc_alloc_host()
540 kfree(host); 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()
556 if (mmc_gpio_alloc(host)) { 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()
582 return host; in mmc_alloc_host()
594 struct mmc_host **dr, *host; in devm_mmc_alloc_host() local
600 host = mmc_alloc_host(extra, dev); in devm_mmc_alloc_host()
601 if (!host) { in devm_mmc_alloc_host()
606 *dr = host; in devm_mmc_alloc_host()
609 return host; in devm_mmc_alloc_host()
613 static int mmc_validate_host_caps(struct mmc_host *host) in mmc_validate_host_caps() argument
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()
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
636 * Register the host with the driver model. The host must be
640 int mmc_add_host(struct mmc_host *host) in mmc_add_host() argument
644 err = mmc_validate_host_caps(host); in mmc_add_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()
654 mmc_add_host_debugfs(host); in mmc_add_host()
656 mmc_start_host(host); in mmc_add_host()
663 * mmc_remove_host - remove host hardware
664 * @host: mmc host
666 * Unregister and remove all cards associated with this host,
670 void mmc_remove_host(struct mmc_host *host) in mmc_remove_host() argument
672 mmc_stop_host(host); in mmc_remove_host()
674 mmc_remove_host_debugfs(host); in mmc_remove_host()
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
687 * Free the host once all references to it have been dropped.
689 void mmc_free_host(struct mmc_host *host) in mmc_free_host() argument
691 cancel_delayed_work_sync(&host->detect); in mmc_free_host()
692 mmc_pwrseq_free(host); in mmc_free_host()
693 put_device(&host->class_dev); in mmc_free_host()