MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / mmc / core / host.c
blob40640584213c53dcfa141f55afa36133e3abcb51
1 /*
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>
21 #endif
22 #include <linux/mmc/host.h>
24 #include "core.h"
25 #include "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)
31 #else
32 static void mmc_host_classdev_release(struct class_device *dev)
33 #endif
35 #if 0 // mask by Victor Yu. 12-03-2008
36 struct mmc_host *host = cls_dev_to_mmc_host(dev);
37 #else
38 struct mmc_host *host;
40 host = cls_dev_to_mmc_host(dev);
41 #endif
42 kfree(host);
45 static struct class mmc_host_class = {
46 .name = "mmc_host",
47 #if 0 // mask by Victor Yu. 12-02-2008
48 .dev_release = mmc_host_classdev_release,
49 #else
50 .release = mmc_host_classdev_release,
51 #endif
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);
67 #else
68 static spinlock_t mmc_host_lock=SPIN_LOCK_UNLOCKED;
69 #endif
71 /**
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);
84 #else
85 host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
86 #endif
87 if (!host)
88 return NULL;
89 #if 1 // add by Victor Yu. 12-02-2008
90 memset(host, 0, sizeof(struct mmc_host) + extra);
91 #endif
93 #if 0 // mask by Victor Yu. 12-02-2008
94 host->parent = dev;
95 host->class_dev.parent = dev;
96 #else
97 host->dev = dev;
98 host->class_dev.dev = dev;
99 #endif
100 host->class_dev.class = &mmc_host_class;
101 #if 0 // mask by Victor Yu. 12-02-2008
102 device_initialize(&host->class_dev);
103 #else
104 class_device_initialize(&host->class_dev);
105 #endif
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);
111 #else
112 INIT_WORK(&host->detect, mmc_rescan, host);
113 #endif
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;
127 return host;
130 EXPORT_SYMBOL(mmc_alloc_host);
133 * mmc_add_host - initialise host hardware
134 * @host: mmc host
136 * Register the host with the driver model. The host must be
137 * prepared to start servicing requests before this function
138 * completes.
140 int mmc_add_host(struct mmc_host *host)
142 int err;
144 if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
145 return -ENOMEM;
147 spin_lock(&mmc_host_lock);
148 err = idr_get_new(&mmc_host_idr, host, &host->index);
149 spin_unlock(&mmc_host_lock);
150 if (err)
151 return err;
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);
157 #else
158 snprintf(host->class_dev.class_id, BUS_ID_SIZE,
159 "mmc%d", host->index);
160 err = class_device_add(&host->class_dev);
161 #endif
163 if (err)
164 return err;
166 mmc_start_host(host);
168 return 0;
171 EXPORT_SYMBOL(mmc_add_host);
174 * mmc_remove_host - remove host hardware
175 * @host: mmc host
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)
183 mmc_stop_host(host);
185 #if 0 // mask by Victor Yu. 12-02-2008
186 device_del(&host->class_dev);
187 #else
188 class_device_del(&host->class_dev);
189 #endif
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
200 * @host: mmc host
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);
208 #else
209 class_device_put(&host->class_dev);
210 #endif
213 EXPORT_SYMBOL(mmc_free_host);