aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pnp/driver.c')
-rw-r--r--drivers/pnp/driver.c70
1 files changed, 34 insertions, 36 deletions
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index 1432806451cd..30b8f6f3258a 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -2,7 +2,6 @@
2 * driver.c - device id matching, driver model, etc. 2 * driver.c - device id matching, driver model, etc.
3 * 3 *
4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
5 *
6 */ 5 */
7 6
8#include <linux/string.h> 7#include <linux/string.h>
@@ -16,12 +15,11 @@
16static int compare_func(const char *ida, const char *idb) 15static int compare_func(const char *ida, const char *idb)
17{ 16{
18 int i; 17 int i;
18
19 /* we only need to compare the last 4 chars */ 19 /* we only need to compare the last 4 chars */
20 for (i=3; i<7; i++) 20 for (i = 3; i < 7; i++) {
21 {
22 if (ida[i] != 'X' && 21 if (ida[i] != 'X' &&
23 idb[i] != 'X' && 22 idb[i] != 'X' && toupper(ida[i]) != toupper(idb[i]))
24 toupper(ida[i]) != toupper(idb[i]))
25 return 0; 23 return 0;
26 } 24 }
27 return 1; 25 return 1;
@@ -31,20 +29,22 @@ int compare_pnp_id(struct pnp_id *pos, const char *id)
31{ 29{
32 if (!pos || !id || (strlen(id) != 7)) 30 if (!pos || !id || (strlen(id) != 7))
33 return 0; 31 return 0;
34 if (memcmp(id,"ANYDEVS",7)==0) 32 if (memcmp(id, "ANYDEVS", 7) == 0)
35 return 1; 33 return 1;
36 while (pos){ 34 while (pos) {
37 if (memcmp(pos->id,id,3)==0) 35 if (memcmp(pos->id, id, 3) == 0)
38 if (compare_func(pos->id,id)==1) 36 if (compare_func(pos->id, id) == 1)
39 return 1; 37 return 1;
40 pos = pos->next; 38 pos = pos->next;
41 } 39 }
42 return 0; 40 return 0;
43} 41}
44 42
45static const struct pnp_device_id * match_device(struct pnp_driver *drv, struct pnp_dev *dev) 43static const struct pnp_device_id *match_device(struct pnp_driver *drv,
44 struct pnp_dev *dev)
46{ 45{
47 const struct pnp_device_id *drv_id = drv->id_table; 46 const struct pnp_device_id *drv_id = drv->id_table;
47
48 if (!drv_id) 48 if (!drv_id)
49 return NULL; 49 return NULL;
50 50
@@ -59,7 +59,7 @@ static const struct pnp_device_id * match_device(struct pnp_driver *drv, struct
59int pnp_device_attach(struct pnp_dev *pnp_dev) 59int pnp_device_attach(struct pnp_dev *pnp_dev)
60{ 60{
61 spin_lock(&pnp_lock); 61 spin_lock(&pnp_lock);
62 if(pnp_dev->status != PNP_READY){ 62 if (pnp_dev->status != PNP_READY) {
63 spin_unlock(&pnp_lock); 63 spin_unlock(&pnp_lock);
64 return -EBUSY; 64 return -EBUSY;
65 } 65 }
@@ -86,7 +86,8 @@ static int pnp_device_probe(struct device *dev)
86 pnp_dev = to_pnp_dev(dev); 86 pnp_dev = to_pnp_dev(dev);
87 pnp_drv = to_pnp_driver(dev->driver); 87 pnp_drv = to_pnp_driver(dev->driver);
88 88
89 pnp_dbg("match found with the PnP device '%s' and the driver '%s'", dev->bus_id,pnp_drv->name); 89 pnp_dbg("match found with the PnP device '%s' and the driver '%s'",
90 dev->bus_id, pnp_drv->name);
90 91
91 error = pnp_device_attach(pnp_dev); 92 error = pnp_device_attach(pnp_dev);
92 if (error < 0) 93 if (error < 0)
@@ -99,7 +100,7 @@ static int pnp_device_probe(struct device *dev)
99 return error; 100 return error;
100 } 101 }
101 } else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE) 102 } else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE)
102 == PNP_DRIVER_RES_DISABLE) { 103 == PNP_DRIVER_RES_DISABLE) {
103 error = pnp_disable_dev(pnp_dev); 104 error = pnp_disable_dev(pnp_dev);
104 if (error < 0) 105 if (error < 0)
105 return error; 106 return error;
@@ -110,22 +111,22 @@ static int pnp_device_probe(struct device *dev)
110 if (dev_id != NULL) 111 if (dev_id != NULL)
111 error = pnp_drv->probe(pnp_dev, dev_id); 112 error = pnp_drv->probe(pnp_dev, dev_id);
112 } 113 }
113 if (error >= 0){ 114 if (error >= 0) {
114 pnp_dev->driver = pnp_drv; 115 pnp_dev->driver = pnp_drv;
115 error = 0; 116 error = 0;
116 } else 117 } else
117 goto fail; 118 goto fail;
118 return error; 119 return error;
119 120
120fail: 121 fail:
121 pnp_device_detach(pnp_dev); 122 pnp_device_detach(pnp_dev);
122 return error; 123 return error;
123} 124}
124 125
125static int pnp_device_remove(struct device *dev) 126static int pnp_device_remove(struct device *dev)
126{ 127{
127 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 128 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
128 struct pnp_driver * drv = pnp_dev->driver; 129 struct pnp_driver *drv = pnp_dev->driver;
129 130
130 if (drv) { 131 if (drv) {
131 if (drv->remove) 132 if (drv->remove)
@@ -138,8 +139,9 @@ static int pnp_device_remove(struct device *dev)
138 139
139static int pnp_bus_match(struct device *dev, struct device_driver *drv) 140static int pnp_bus_match(struct device *dev, struct device_driver *drv)
140{ 141{
141 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 142 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
142 struct pnp_driver * pnp_drv = to_pnp_driver(drv); 143 struct pnp_driver *pnp_drv = to_pnp_driver(drv);
144
143 if (match_device(pnp_drv, pnp_dev) == NULL) 145 if (match_device(pnp_drv, pnp_dev) == NULL)
144 return 0; 146 return 0;
145 return 1; 147 return 1;
@@ -147,8 +149,8 @@ static int pnp_bus_match(struct device *dev, struct device_driver *drv)
147 149
148static int pnp_bus_suspend(struct device *dev, pm_message_t state) 150static int pnp_bus_suspend(struct device *dev, pm_message_t state)
149{ 151{
150 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 152 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
151 struct pnp_driver * pnp_drv = pnp_dev->driver; 153 struct pnp_driver *pnp_drv = pnp_dev->driver;
152 int error; 154 int error;
153 155
154 if (!pnp_drv) 156 if (!pnp_drv)
@@ -162,9 +164,9 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)
162 164
163 if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) && 165 if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) &&
164 pnp_can_disable(pnp_dev)) { 166 pnp_can_disable(pnp_dev)) {
165 error = pnp_stop_dev(pnp_dev); 167 error = pnp_stop_dev(pnp_dev);
166 if (error) 168 if (error)
167 return error; 169 return error;
168 } 170 }
169 171
170 if (pnp_dev->protocol && pnp_dev->protocol->suspend) 172 if (pnp_dev->protocol && pnp_dev->protocol->suspend)
@@ -174,8 +176,8 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)
174 176
175static int pnp_bus_resume(struct device *dev) 177static int pnp_bus_resume(struct device *dev)
176{ 178{
177 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 179 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
178 struct pnp_driver * pnp_drv = pnp_dev->driver; 180 struct pnp_driver *pnp_drv = pnp_dev->driver;
179 int error; 181 int error;
180 182
181 if (!pnp_drv) 183 if (!pnp_drv)
@@ -197,12 +199,12 @@ static int pnp_bus_resume(struct device *dev)
197} 199}
198 200
199struct bus_type pnp_bus_type = { 201struct bus_type pnp_bus_type = {
200 .name = "pnp", 202 .name = "pnp",
201 .match = pnp_bus_match, 203 .match = pnp_bus_match,
202 .probe = pnp_device_probe, 204 .probe = pnp_device_probe,
203 .remove = pnp_device_remove, 205 .remove = pnp_device_remove,
204 .suspend = pnp_bus_suspend, 206 .suspend = pnp_bus_suspend,
205 .resume = pnp_bus_resume, 207 .resume = pnp_bus_resume,
206}; 208};
207 209
208int pnp_register_driver(struct pnp_driver *drv) 210int pnp_register_driver(struct pnp_driver *drv)
@@ -225,12 +227,11 @@ void pnp_unregister_driver(struct pnp_driver *drv)
225 * pnp_add_id - adds an EISA id to the specified device 227 * pnp_add_id - adds an EISA id to the specified device
226 * @id: pointer to a pnp_id structure 228 * @id: pointer to a pnp_id structure
227 * @dev: pointer to the desired device 229 * @dev: pointer to the desired device
228 *
229 */ 230 */
230
231int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) 231int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
232{ 232{
233 struct pnp_id *ptr; 233 struct pnp_id *ptr;
234
234 if (!id) 235 if (!id)
235 return -EINVAL; 236 return -EINVAL;
236 if (!dev) 237 if (!dev)
@@ -248,8 +249,5 @@ int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
248 249
249EXPORT_SYMBOL(pnp_register_driver); 250EXPORT_SYMBOL(pnp_register_driver);
250EXPORT_SYMBOL(pnp_unregister_driver); 251EXPORT_SYMBOL(pnp_unregister_driver);
251#if 0
252EXPORT_SYMBOL(pnp_add_id);
253#endif
254EXPORT_SYMBOL(pnp_device_attach); 252EXPORT_SYMBOL(pnp_device_attach);
255EXPORT_SYMBOL(pnp_device_detach); 253EXPORT_SYMBOL(pnp_device_detach);