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 #include <linux/suspend.h>
21 #include <linux/mmc/host.h>
26 #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
28 static void mmc_host_classdev_release(struct device
*dev
)
30 struct mmc_host
*host
= cls_dev_to_mmc_host(dev
);
34 static struct class mmc_host_class
= {
36 .dev_release
= mmc_host_classdev_release
,
39 int mmc_register_host_class(void)
41 return class_register(&mmc_host_class
);
44 void mmc_unregister_host_class(void)
46 class_unregister(&mmc_host_class
);
49 static DEFINE_IDR(mmc_host_idr
);
50 static DEFINE_SPINLOCK(mmc_host_lock
);
53 * mmc_alloc_host - initialise the per-host structure.
54 * @extra: sizeof private data structure
55 * @dev: pointer to host device model structure
57 * Initialise the per-host structure.
59 struct mmc_host
*mmc_alloc_host(int extra
, struct device
*dev
)
62 struct mmc_host
*host
;
64 if (!idr_pre_get(&mmc_host_idr
, GFP_KERNEL
))
67 host
= kzalloc(sizeof(struct mmc_host
) + extra
, GFP_KERNEL
);
71 spin_lock(&mmc_host_lock
);
72 err
= idr_get_new(&mmc_host_idr
, host
, &host
->index
);
73 spin_unlock(&mmc_host_lock
);
77 dev_set_name(&host
->class_dev
, "mmc%d", host
->index
);
80 host
->class_dev
.parent
= dev
;
81 host
->class_dev
.class = &mmc_host_class
;
82 device_initialize(&host
->class_dev
);
84 spin_lock_init(&host
->lock
);
85 init_waitqueue_head(&host
->wq
);
86 INIT_DELAYED_WORK(&host
->detect
, mmc_rescan
);
87 INIT_DELAYED_WORK_DEFERRABLE(&host
->disable
, mmc_host_deeper_disable
);
89 host
->pm_notify
.notifier_call
= mmc_pm_notify
;
93 * By default, hosts do not support SGIO or large requests.
94 * They have to set these according to their abilities.
96 host
->max_hw_segs
= 1;
97 host
->max_phys_segs
= 1;
98 host
->max_seg_size
= PAGE_CACHE_SIZE
;
100 host
->max_req_size
= PAGE_CACHE_SIZE
;
101 host
->max_blk_size
= 512;
102 host
->max_blk_count
= PAGE_CACHE_SIZE
/ 512;
111 EXPORT_SYMBOL(mmc_alloc_host
);
114 * mmc_add_host - initialise host hardware
117 * Register the host with the driver model. The host must be
118 * prepared to start servicing requests before this function
121 int mmc_add_host(struct mmc_host
*host
)
125 WARN_ON((host
->caps
& MMC_CAP_SDIO_IRQ
) &&
126 !host
->ops
->enable_sdio_irq
);
128 led_trigger_register_simple(dev_name(&host
->class_dev
), &host
->led
);
130 err
= device_add(&host
->class_dev
);
134 #ifdef CONFIG_DEBUG_FS
135 mmc_add_host_debugfs(host
);
138 mmc_start_host(host
);
139 register_pm_notifier(&host
->pm_notify
);
144 EXPORT_SYMBOL(mmc_add_host
);
147 * mmc_remove_host - remove host hardware
150 * Unregister and remove all cards associated with this host,
151 * and power down the MMC bus. No new requests will be issued
152 * after this function has returned.
154 void mmc_remove_host(struct mmc_host
*host
)
156 unregister_pm_notifier(&host
->pm_notify
);
159 #ifdef CONFIG_DEBUG_FS
160 mmc_remove_host_debugfs(host
);
163 device_del(&host
->class_dev
);
165 led_trigger_unregister_simple(host
->led
);
168 EXPORT_SYMBOL(mmc_remove_host
);
171 * mmc_free_host - free the host structure
174 * Free the host once all references to it have been dropped.
176 void mmc_free_host(struct mmc_host
*host
)
178 spin_lock(&mmc_host_lock
);
179 idr_remove(&mmc_host_idr
, host
->index
);
180 spin_unlock(&mmc_host_lock
);
182 put_device(&host
->class_dev
);
185 EXPORT_SYMBOL(mmc_free_host
);