Lines Matching full:host
3 * linux/drivers/mmc/core/host.c
9 * MMC host class device management
22 #include <linux/mmc/host.h>
28 #include "host.h"
40 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_class_prepare() local
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()
58 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_class_complete() local
60 _mmc_detect_change(host, 0, false); in mmc_host_class_complete()
75 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_classdev_release() local
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()
79 kfree(host); in mmc_host_classdev_release()
84 struct mmc_host *host = cls_dev_to_mmc_host(dev); in mmc_host_classdev_shutdown() local
86 __mmc_stop_host(host); in mmc_host_classdev_shutdown()
109 * @host: host which should retune now
111 void mmc_retune_enable(struct mmc_host *host) in mmc_retune_enable() argument
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()
123 void mmc_retune_pause(struct mmc_host *host) in mmc_retune_pause() argument
125 if (!host->retune_paused) { in mmc_retune_pause()
126 host->retune_paused = 1; in mmc_retune_pause()
127 mmc_retune_hold(host); in mmc_retune_pause()
132 void mmc_retune_unpause(struct mmc_host *host) in mmc_retune_unpause() argument
134 if (host->retune_paused) { in mmc_retune_unpause()
135 host->retune_paused = 0; in mmc_retune_unpause()
136 mmc_retune_release(host); in mmc_retune_unpause()
143 * @host: host which should not retune anymore
147 void mmc_retune_disable(struct mmc_host *host) in mmc_retune_disable() argument
149 mmc_retune_unpause(host); in mmc_retune_disable()
150 host->can_retune = 0; in mmc_retune_disable()
151 del_timer_sync(&host->retune_timer); in mmc_retune_disable()
152 mmc_retune_clear(host); in mmc_retune_disable()
155 void mmc_retune_timer_stop(struct mmc_host *host) in mmc_retune_timer_stop() argument
157 del_timer_sync(&host->retune_timer); in mmc_retune_timer_stop()
161 void mmc_retune_hold(struct mmc_host *host) in mmc_retune_hold() argument
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()
168 void mmc_retune_release(struct mmc_host *host) in mmc_retune_release() argument
170 if (host->hold_retune) in mmc_retune_release()
171 host->hold_retune -= 1; in mmc_retune_release()
177 int mmc_retune(struct mmc_host *host) in mmc_retune() argument
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()
216 struct mmc_host *host = from_timer(host, t, retune_timer); in mmc_retune_timer() local
218 mmc_retune_needed(host); in mmc_retune_timer()
264 * mmc_of_parse() - parse host's device properties
265 * @host: host whose properties should be parsed.
268 * used to instantiate and configure this host instance or not, we
269 * parse the properties and set respective generic mmc-host flags and
272 int mmc_of_parse(struct mmc_host *host) in mmc_of_parse() argument
274 struct device *dev = host->parent; in mmc_of_parse()
283 dev_dbg(host->parent, in mmc_of_parse()
290 host->caps |= MMC_CAP_8_BIT_DATA; 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()
304 device_property_read_u32(dev, "max-frequency", &host->f_max); in mmc_of_parse()
321 host->caps |= MMC_CAP_NONREMOVABLE; in mmc_of_parse()
324 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; in mmc_of_parse()
331 host->caps |= MMC_CAP_NEEDS_POLL; in mmc_of_parse()
333 ret = mmc_gpiod_request_cd(host, "cd", 0, false, in mmc_of_parse()
336 dev_info(host->parent, "Got CD GPIO\n"); 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()
353 host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; in mmc_of_parse()
356 host->caps |= MMC_CAP_SD_HIGHSPEED; in mmc_of_parse()
358 host->caps |= MMC_CAP_MMC_HIGHSPEED; in mmc_of_parse()
360 host->caps |= MMC_CAP_UHS_SDR12; in mmc_of_parse()
362 host->caps |= MMC_CAP_UHS_SDR25; in mmc_of_parse()
364 host->caps |= MMC_CAP_UHS_SDR50; in mmc_of_parse()
366 host->caps |= MMC_CAP_UHS_SDR104; in mmc_of_parse()
368 host->caps |= MMC_CAP_UHS_DDR50; in mmc_of_parse()
370 host->caps |= MMC_CAP_POWER_OFF_CARD; in mmc_of_parse()
372 host->caps |= MMC_CAP_HW_RESET; in mmc_of_parse()
374 host->caps |= MMC_CAP_SDIO_IRQ; in mmc_of_parse()
376 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; in mmc_of_parse()
378 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND; in mmc_of_parse()
380 host->pm_caps |= MMC_PM_KEEP_POWER; in mmc_of_parse()
383 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; in mmc_of_parse()
385 host->caps |= MMC_CAP_3_3V_DDR; in mmc_of_parse()
387 host->caps |= MMC_CAP_1_8V_DDR; in mmc_of_parse()
389 host->caps |= MMC_CAP_1_2V_DDR; in mmc_of_parse()
391 host->caps2 |= MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
393 host->caps2 |= MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
395 host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR; in mmc_of_parse()
397 host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR; in mmc_of_parse()
399 host->caps2 |= MMC_CAP2_HS400_ES; in mmc_of_parse()
401 host->caps2 |= MMC_CAP2_NO_SDIO; in mmc_of_parse()
403 host->caps2 |= MMC_CAP2_NO_SD; in mmc_of_parse()
405 host->caps2 |= MMC_CAP2_NO_MMC; in mmc_of_parse()
407 host->caps2 &= ~(MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V | 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()
428 &host->ios.power_delay_ms); in mmc_of_parse()
430 return mmc_pwrseq_alloc(host); in mmc_of_parse()
437 * @host: host whose properties should be parsed.
444 int mmc_of_parse_voltage(struct mmc_host *host, u32 *mask) in mmc_of_parse_voltage() argument
447 struct device *dev = host->parent; in mmc_of_parse_voltage()
512 * mmc_alloc_host - initialise the per-host structure.
514 * @dev: pointer to host device model structure
516 * Initialise the per-host structure.
521 struct mmc_host *host; in mmc_alloc_host() local
524 host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); in mmc_alloc_host()
525 if (!host) in mmc_alloc_host()
529 host->rescan_disable = 1; in mmc_alloc_host()
541 kfree(host); 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()
557 if (mmc_gpio_alloc(host)) { 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()
583 return host; in mmc_alloc_host()
595 struct mmc_host **dr, *host; in devm_mmc_alloc_host() local
601 host = mmc_alloc_host(extra, dev); in devm_mmc_alloc_host()
602 if (!host) { in devm_mmc_alloc_host()
607 *dr = host; in devm_mmc_alloc_host()
610 return host; in devm_mmc_alloc_host()
614 static int mmc_validate_host_caps(struct mmc_host *host) in mmc_validate_host_caps() argument
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()
627 host->caps2 = caps2 & ~MMC_CAP2_HS400_ES & ~MMC_CAP2_HS400; in mmc_validate_host_caps()
634 * mmc_add_host - initialise host hardware
635 * @host: mmc host
637 * Register the host with the driver model. The host must be
641 int mmc_add_host(struct mmc_host *host) in mmc_add_host() argument
645 err = mmc_validate_host_caps(host); in mmc_add_host()
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()
655 mmc_add_host_debugfs(host); in mmc_add_host()
657 mmc_start_host(host); in mmc_add_host()
664 * mmc_remove_host - remove host hardware
665 * @host: mmc host
667 * Unregister and remove all cards associated with this host,
671 void mmc_remove_host(struct mmc_host *host) in mmc_remove_host() argument
673 mmc_stop_host(host); in mmc_remove_host()
675 mmc_remove_host_debugfs(host); in mmc_remove_host()
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
686 * @host: mmc host
688 * Free the host once all references to it have been dropped.
690 void mmc_free_host(struct mmc_host *host) in mmc_free_host() argument
692 cancel_delayed_work_sync(&host->detect); in mmc_free_host()
693 mmc_pwrseq_free(host); in mmc_free_host()
694 put_device(&host->class_dev); in mmc_free_host()