2 * linux/drivers/mmc/core/host.c
4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 * Copyright (C) 2007-2008 Pierre Ossman
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * MMC host class device management
14 #include <linux/device.h>
15 #include <linux/err.h>
16 #include <linux/idr.h>
17 #include <linux/pagemap.h>
18 #include <linux/leds.h>
19 #if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
20 #include <linux/suspend.h>
22 #include <linux/mmc/host.h>
27 #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
29 static void mmc_host_classdev_release(struct device *dev)
31 struct mmc_host *host = cls_dev_to_mmc_host(dev);
35 static struct class mmc_host_class = {
37 .dev_release = mmc_host_classdev_release,
40 int mmc_register_host_class(void)
42 return class_register(&mmc_host_class);
45 void mmc_unregister_host_class(void)
47 class_unregister(&mmc_host_class);
50 static DEFINE_IDR(mmc_host_idr);
51 static DEFINE_SPINLOCK(mmc_host_lock);
54 * mmc_alloc_host - initialise the per-host structure.
55 * @extra: sizeof private data structure
56 * @dev: pointer to host device model structure
58 * Initialise the per-host structure.
60 struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
63 struct mmc_host *host;
65 if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
68 host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
72 spin_lock(&mmc_host_lock);
73 err = idr_get_new(&mmc_host_idr, host, &host->index);
74 spin_unlock(&mmc_host_lock);
78 dev_set_name(&host->class_dev, "mmc%d", host->index);
81 host->class_dev.parent = dev;
82 host->class_dev.class = &mmc_host_class;
83 device_initialize(&host->class_dev);
85 spin_lock_init(&host->lock);
86 init_waitqueue_head(&host->wq);
87 INIT_DELAYED_WORK(&host->detect, mmc_rescan);
88 INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable);
89 #if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) // old driver, add pm reform to kernel2.6.38
91 host->pm_notify.notifier_call = mmc_pm_notify;
96 * By default, hosts do not support SGIO or large requests.
97 * They have to set these according to their abilities.
99 host->max_hw_segs = 1;
100 host->max_phys_segs = 1;
101 host->max_seg_size = PAGE_CACHE_SIZE;
103 host->max_req_size = PAGE_CACHE_SIZE;
104 host->max_blk_size = 512;
105 host->max_blk_count = PAGE_CACHE_SIZE / 512;
114 EXPORT_SYMBOL(mmc_alloc_host);
117 * mmc_add_host - initialise host hardware
120 * Register the host with the driver model. The host must be
121 * prepared to start servicing requests before this function
124 int mmc_add_host(struct mmc_host *host)
128 WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
129 !host->ops->enable_sdio_irq);
131 led_trigger_register_simple(dev_name(&host->class_dev), &host->led);
133 err = device_add(&host->class_dev);
137 #ifdef CONFIG_DEBUG_FS
138 mmc_add_host_debugfs(host);
141 mmc_start_host(host);
143 #if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) // old driver, add pm reform to kernel2.6.38
144 if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
145 register_pm_notifier(&host->pm_notify);
151 EXPORT_SYMBOL(mmc_add_host);
154 * mmc_remove_host - remove host hardware
157 * Unregister and remove all cards associated with this host,
158 * and power down the MMC bus. No new requests will be issued
159 * after this function has returned.
161 void mmc_remove_host(struct mmc_host *host)
163 #if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) // old driver, add pm reform to kernel2.6.38
164 if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
165 unregister_pm_notifier(&host->pm_notify);
170 #ifdef CONFIG_DEBUG_FS
171 mmc_remove_host_debugfs(host);
174 device_del(&host->class_dev);
176 led_trigger_unregister_simple(host->led);
179 EXPORT_SYMBOL(mmc_remove_host);
182 * mmc_free_host - free the host structure
185 * Free the host once all references to it have been dropped.
187 void mmc_free_host(struct mmc_host *host)
189 spin_lock(&mmc_host_lock);
190 idr_remove(&mmc_host_idr, host->index);
191 spin_unlock(&mmc_host_lock);
193 put_device(&host->class_dev);
196 EXPORT_SYMBOL(mmc_free_host);