2 * linux/drivers/mmc/core/host.c
4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 * Copyright (C) 2007 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>
19 #if 1 // add by Victor Yu. 12-02-2008
20 #include <linux/mmc/card.h>
22 #include <linux/mmc/host.h>
27 #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
29 #if 0 // mask by Victor Yu.12-02-2008
30 static void mmc_host_classdev_release(struct device
*dev
)
32 static void mmc_host_classdev_release(struct class_device
*dev
)
35 #if 0 // mask by Victor Yu. 12-03-2008
36 struct mmc_host
*host
= cls_dev_to_mmc_host(dev
);
38 struct mmc_host
*host
;
40 host
= cls_dev_to_mmc_host(dev
);
45 static struct class mmc_host_class
= {
47 #if 0 // mask by Victor Yu. 12-02-2008
48 .dev_release
= mmc_host_classdev_release
,
50 .release
= mmc_host_classdev_release
,
54 int mmc_register_host_class(void)
56 return class_register(&mmc_host_class
);
59 void mmc_unregister_host_class(void)
61 class_unregister(&mmc_host_class
);
64 static DEFINE_IDR(mmc_host_idr
);
65 #if 0 // mask by Victor Yu. 12-02-2008
66 static DEFINE_SPINLOCK(mmc_host_lock
);
68 static spinlock_t mmc_host_lock
=SPIN_LOCK_UNLOCKED
;
72 * mmc_alloc_host - initialise the per-host structure.
73 * @extra: sizeof private data structure
74 * @dev: pointer to host device model structure
76 * Initialise the per-host structure.
78 struct mmc_host
*mmc_alloc_host(int extra
, struct device
*dev
)
80 struct mmc_host
*host
;
82 #if 0 // mask by Victor Yu. 12-02-2008
83 host
= kzalloc(sizeof(struct mmc_host
) + extra
, GFP_KERNEL
);
85 host
= kmalloc(sizeof(struct mmc_host
) + extra
, GFP_KERNEL
);
89 #if 1 // add by Victor Yu. 12-02-2008
90 memset(host
, 0, sizeof(struct mmc_host
) + extra
);
93 #if 0 // mask by Victor Yu. 12-02-2008
95 host
->class_dev
.parent
= dev
;
98 host
->class_dev
.dev
= dev
;
100 host
->class_dev
.class = &mmc_host_class
;
101 #if 0 // mask by Victor Yu. 12-02-2008
102 device_initialize(&host
->class_dev
);
104 class_device_initialize(&host
->class_dev
);
107 spin_lock_init(&host
->lock
);
108 init_waitqueue_head(&host
->wq
);
109 #if 0 // mask by Victor Yu. 12-02-2008
110 INIT_DELAYED_WORK(&host
->detect
, mmc_rescan
);
112 INIT_WORK(&host
->detect
, mmc_rescan
, host
);
116 * By default, hosts do not support SGIO or large requests.
117 * They have to set these according to their abilities.
119 host
->max_hw_segs
= 1;
120 host
->max_phys_segs
= 1;
121 host
->max_seg_size
= PAGE_CACHE_SIZE
;
123 host
->max_req_size
= PAGE_CACHE_SIZE
;
124 host
->max_blk_size
= 512;
125 host
->max_blk_count
= PAGE_CACHE_SIZE
/ 512;
130 EXPORT_SYMBOL(mmc_alloc_host
);
133 * mmc_add_host - initialise host hardware
136 * Register the host with the driver model. The host must be
137 * prepared to start servicing requests before this function
140 int mmc_add_host(struct mmc_host
*host
)
144 if (!idr_pre_get(&mmc_host_idr
, GFP_KERNEL
))
147 spin_lock(&mmc_host_lock
);
148 err
= idr_get_new(&mmc_host_idr
, host
, &host
->index
);
149 spin_unlock(&mmc_host_lock
);
153 #if 0 // mask by VIctor Yu. 12-02-2008
154 snprintf(host
->class_dev
.bus_id
, BUS_ID_SIZE
,
155 "mmc%d", host
->index
);
156 err
= device_add(&host
->class_dev
);
158 snprintf(host
->class_dev
.class_id
, BUS_ID_SIZE
,
159 "mmc%d", host
->index
);
160 err
= class_device_add(&host
->class_dev
);
166 mmc_start_host(host
);
171 EXPORT_SYMBOL(mmc_add_host
);
174 * mmc_remove_host - remove host hardware
177 * Unregister and remove all cards associated with this host,
178 * and power down the MMC bus. No new requests will be issued
179 * after this function has returned.
181 void mmc_remove_host(struct mmc_host
*host
)
185 #if 0 // mask by Victor Yu. 12-02-2008
186 device_del(&host
->class_dev
);
188 class_device_del(&host
->class_dev
);
191 spin_lock(&mmc_host_lock
);
192 idr_remove(&mmc_host_idr
, host
->index
);
193 spin_unlock(&mmc_host_lock
);
196 EXPORT_SYMBOL(mmc_remove_host
);
199 * mmc_free_host - free the host structure
202 * Free the host once all references to it have been dropped.
204 void mmc_free_host(struct mmc_host
*host
)
206 #if 0 // mask by Victor Yu. 12-02-2008
207 put_device(&host
->class_dev
);
209 class_device_put(&host
->class_dev
);
213 EXPORT_SYMBOL(mmc_free_host
);