Lines Matching refs:host

2  *  linux/drivers/mmc/core/host.c
12 * MMC host class device management
26 #include <linux/mmc/host.h>
31 #include "host.h"
37 struct mmc_host *host = cls_dev_to_mmc_host(dev);
38 mutex_destroy(&host->slot.lock);
39 kfree(host);
64 struct mmc_host *host = cls_dev_to_mmc_host(dev);
65 return snprintf(buf, PAGE_SIZE, "%lu\n", host->clkgate_delay);
71 struct mmc_host *host = cls_dev_to_mmc_host(dev);
77 spin_lock_irqsave(&host->clk_lock, flags);
78 host->clkgate_delay = value;
79 spin_unlock_irqrestore(&host->clk_lock, flags);
84 * Enabling clock gating will make the core call out to the host
90 static void mmc_host_clk_gate_delayed(struct mmc_host *host)
93 unsigned long freq = host->ios.clock;
99 mmc_hostname(host));
107 spin_lock_irqsave(&host->clk_lock, flags);
114 if (!host->clk_requests) {
115 spin_unlock_irqrestore(&host->clk_lock, flags);
117 ndelay(host->clk_delay * tick_ns);
120 spin_unlock_irqrestore(&host->clk_lock, flags);
123 mutex_lock(&host->clk_gate_mutex);
124 spin_lock_irqsave(&host->clk_lock, flags);
125 if (!host->clk_requests) {
126 spin_unlock_irqrestore(&host->clk_lock, flags);
127 /* This will set host->ios.clock to 0 */
128 mmc_gate_clock(host);
129 spin_lock_irqsave(&host->clk_lock, flags);
130 pr_debug("%s: gated MCI clock\n", mmc_hostname(host));
132 spin_unlock_irqrestore(&host->clk_lock, flags);
133 mutex_unlock(&host->clk_gate_mutex);
141 struct mmc_host *host = container_of(work, struct mmc_host,
144 mmc_host_clk_gate_delayed(host);
149 * @host: host to ungate.
151 * Makes sure the host ios.clock is restored to a non-zero value
155 void mmc_host_clk_hold(struct mmc_host *host)
160 cancel_delayed_work_sync(&host->clk_gate_work);
161 mutex_lock(&host->clk_gate_mutex);
162 spin_lock_irqsave(&host->clk_lock, flags);
163 if (host->clk_gated) {
164 spin_unlock_irqrestore(&host->clk_lock, flags);
165 mmc_ungate_clock(host);
166 spin_lock_irqsave(&host->clk_lock, flags);
167 pr_debug("%s: ungated MCI clock\n", mmc_hostname(host));
169 host->clk_requests++;
170 spin_unlock_irqrestore(&host->clk_lock, flags);
171 mutex_unlock(&host->clk_gate_mutex);
196 * @host: host to gate.
198 * Calls the host driver with ios.clock set to zero as often as possible
202 void mmc_host_clk_release(struct mmc_host *host)
206 spin_lock_irqsave(&host->clk_lock, flags);
207 host->clk_requests--;
208 if (mmc_host_may_gate_card(host->card) &&
209 !host->clk_requests)
210 schedule_delayed_work(&host->clk_gate_work,
211 msecs_to_jiffies(host->clkgate_delay));
212 spin_unlock_irqrestore(&host->clk_lock, flags);
217 * @host: host to get the clock frequency for.
221 unsigned int mmc_host_clk_rate(struct mmc_host *host)
226 spin_lock_irqsave(&host->clk_lock, flags);
227 if (host->clk_gated)
228 freq = host->clk_old;
230 freq = host->ios.clock;
231 spin_unlock_irqrestore(&host->clk_lock, flags);
237 * @host: host with potential clock to control
239 static inline void mmc_host_clk_init(struct mmc_host *host)
241 host->clk_requests = 0;
243 host->clk_delay = 8;
248 host->clkgate_delay = 0;
249 host->clk_gated = false;
250 INIT_DELAYED_WORK(&host->clk_gate_work, mmc_host_clk_gate_work);
251 spin_lock_init(&host->clk_lock);
252 mutex_init(&host->clk_gate_mutex);
257 * @host: host with potential clock to control
259 static inline void mmc_host_clk_exit(struct mmc_host *host)
265 if (cancel_delayed_work_sync(&host->clk_gate_work))
266 mmc_host_clk_gate_delayed(host);
267 if (host->clk_gated)
268 mmc_host_clk_hold(host);
270 WARN_ON(host->clk_requests > 1);
273 static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
275 host->clkgate_delay_attr.show = clkgate_delay_show;
276 host->clkgate_delay_attr.store = clkgate_delay_store;
277 sysfs_attr_init(&host->clkgate_delay_attr.attr);
278 host->clkgate_delay_attr.attr.name = "clkgate_delay";
279 host->clkgate_delay_attr.attr.mode = S_IRUGO | S_IWUSR;
280 if (device_create_file(&host->class_dev, &host->clkgate_delay_attr))
282 mmc_hostname(host));
286 static inline void mmc_host_clk_init(struct mmc_host *host)
290 static inline void mmc_host_clk_exit(struct mmc_host *host)
294 static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
301 * mmc_of_parse() - parse host's device-tree node
302 * @host: host whose node should be parsed.
305 * used to to instantiate and configure this host instance or not, we
306 * parse the properties and set respective generic mmc-host flags and
309 int mmc_of_parse(struct mmc_host *host)
317 if (!host->parent || !host->parent->of_node)
320 np = host->parent->of_node;
324 dev_dbg(host->parent,
331 host->caps |= MMC_CAP_8_BIT_DATA;
334 host->caps |= MMC_CAP_4_BIT_DATA;
339 dev_err(host->parent,
345 of_property_read_u32(np, "max-frequency", &host->f_max);
361 host->caps |= MMC_CAP_NONREMOVABLE;
366 host->caps |= MMC_CAP_NEEDS_POLL;
368 ret = mmc_gpiod_request_cd(host, "cd", 0, true,
374 dev_err(host->parent,
379 dev_info(host->parent, "Got CD GPIO\n");
388 * If the capability on the host AND the GPIO line are
393 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
399 ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert);
404 dev_err(host->parent,
409 dev_info(host->parent, "Got WP GPIO\n");
413 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
416 host->caps |= MMC_CAP_SD_HIGHSPEED;
418 host->caps |= MMC_CAP_MMC_HIGHSPEED;
420 host->caps |= MMC_CAP_UHS_SDR12;
422 host->caps |= MMC_CAP_UHS_SDR25;
424 host->caps |= MMC_CAP_UHS_SDR50;
426 host->caps |= MMC_CAP_UHS_SDR104;
428 host->caps |= MMC_CAP_UHS_DDR50;
430 host->caps |= MMC_CAP_POWER_OFF_CARD;
432 host->caps |= MMC_CAP_SDIO_IRQ;
434 host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE;
436 host->pm_caps |= MMC_PM_KEEP_POWER;
438 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
440 host->caps |= MMC_CAP_1_8V_DDR;
442 host->caps |= MMC_CAP_1_2V_DDR;
444 host->caps2 |= MMC_CAP2_HS200_1_8V_SDR;
446 host->caps2 |= MMC_CAP2_HS200_1_2V_SDR;
448 host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR;
450 host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR;
452 host->dsr_req = !of_property_read_u32(np, "dsr", &host->dsr);
453 if (host->dsr_req && (host->dsr & ~0xffff)) {
454 dev_err(host->parent,
456 host->dsr);
457 host->dsr_req = 0;
463 mmc_gpio_free_cd(host);
470 * mmc_alloc_host - initialise the per-host structure.
472 * @dev: pointer to host device model structure
474 * Initialise the per-host structure.
479 struct mmc_host *host;
481 host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
482 if (!host)
486 host->rescan_disable = 1;
489 err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT);
491 host->index = err;
497 dev_set_name(&host->class_dev, "mmc%d", host->index);
499 host->parent = dev;
500 host->class_dev.parent = dev;
501 host->class_dev.class = &mmc_host_class;
502 device_initialize(&host->class_dev);
504 mmc_host_clk_init(host);
506 mutex_init(&host->slot.lock);
507 host->slot.cd_irq = -EINVAL;
509 spin_lock_init(&host->lock);
510 init_waitqueue_head(&host->wq);
511 INIT_DELAYED_WORK(&host->detect, mmc_rescan);
513 host->pm_notify.notifier_call = mmc_pm_notify;
520 host->max_segs = 1;
521 host->max_seg_size = PAGE_CACHE_SIZE;
523 host->max_req_size = PAGE_CACHE_SIZE;
524 host->max_blk_size = 512;
525 host->max_blk_count = PAGE_CACHE_SIZE / 512;
527 return host;
530 kfree(host);
537 * mmc_add_host - initialise host hardware
538 * @host: mmc host
540 * Register the host with the driver model. The host must be
544 int mmc_add_host(struct mmc_host *host)
548 WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
549 !host->ops->enable_sdio_irq);
551 err = device_add(&host->class_dev);
555 led_trigger_register_simple(dev_name(&host->class_dev), &host->led);
558 mmc_add_host_debugfs(host);
560 mmc_host_clk_sysfs_init(host);
562 mmc_start_host(host);
563 if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
564 register_pm_notifier(&host->pm_notify);
572 * mmc_remove_host - remove host hardware
573 * @host: mmc host
575 * Unregister and remove all cards associated with this host,
579 void mmc_remove_host(struct mmc_host *host)
581 if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
582 unregister_pm_notifier(&host->pm_notify);
584 mmc_stop_host(host);
587 mmc_remove_host_debugfs(host);
590 device_del(&host->class_dev);
592 led_trigger_unregister_simple(host->led);
594 mmc_host_clk_exit(host);
600 * mmc_free_host - free the host structure
601 * @host: mmc host
603 * Free the host once all references to it have been dropped.
605 void mmc_free_host(struct mmc_host *host)
608 idr_remove(&mmc_host_idr, host->index);
611 put_device(&host->class_dev);