Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ds.c -- 16-bit PCMCIA core support |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * The initial developer of the original code is David A. Hinds |
| 9 | * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds |
| 10 | * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. |
| 11 | * |
| 12 | * (C) 1999 David A. Hinds |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 13 | * (C) 2003 - 2006 Dominik Brodowski |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Dominik Brodowski | 3b659fb | 2005-06-27 16:28:51 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/list.h> |
| 21 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/workqueue.h> |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 23 | #include <linux/crc32.h> |
Dominik Brodowski | daa9517 | 2005-06-27 16:28:14 -0700 | [diff] [blame] | 24 | #include <linux/firmware.h> |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 25 | #include <linux/kref.h> |
James Bottomley | 43d9f7f | 2007-10-16 01:23:58 -0700 | [diff] [blame] | 26 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <pcmcia/cs_types.h> |
| 29 | #include <pcmcia/cs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <pcmcia/cistpl.h> |
| 31 | #include <pcmcia/ds.h> |
| 32 | #include <pcmcia/ss.h> |
| 33 | |
| 34 | #include "cs_internal.h" |
| 35 | |
| 36 | /*====================================================================*/ |
| 37 | |
| 38 | /* Module parameters */ |
| 39 | |
| 40 | MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); |
| 41 | MODULE_DESCRIPTION("PCMCIA Driver Services"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 45 | spinlock_t pcmcia_dev_list_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /*====================================================================*/ |
| 48 | |
| 49 | /* code which was in cs.c before */ |
| 50 | |
| 51 | /* String tables for error messages */ |
| 52 | |
| 53 | typedef struct lookup_t { |
Dominik Brodowski | 79ba675 | 2008-08-03 14:03:07 +0200 | [diff] [blame] | 54 | const int key; |
| 55 | const char *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } lookup_t; |
| 57 | |
| 58 | static const lookup_t error_table[] = { |
Dominik Brodowski | 610e237 | 2008-08-03 11:58:53 +0200 | [diff] [blame] | 59 | { 0, "Operation succeeded" }, |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 60 | { -EIO, "Input/Output error" }, |
Dominik Brodowski | 3939c1ef | 2008-08-03 11:10:56 +0200 | [diff] [blame] | 61 | { -ENODEV, "No card present" }, |
Dominik Brodowski | de6405e | 2008-08-03 10:47:59 +0200 | [diff] [blame] | 62 | { -EINVAL, "Bad parameter" }, |
Dominik Brodowski | 943f70f | 2008-08-03 11:23:42 +0200 | [diff] [blame] | 63 | { -EACCES, "Configuration locked" }, |
Dominik Brodowski | 610e237 | 2008-08-03 11:58:53 +0200 | [diff] [blame] | 64 | { -EBUSY, "Resource in use" }, |
Dominik Brodowski | 635d19b | 2008-08-03 11:47:29 +0200 | [diff] [blame] | 65 | { -ENOSPC, "No more items" }, |
Dominik Brodowski | 610e237 | 2008-08-03 11:58:53 +0200 | [diff] [blame] | 66 | { -ENOMEM, "Out of resource" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | |
| 70 | static const lookup_t service_table[] = { |
| 71 | { AccessConfigurationRegister, "AccessConfigurationRegister" }, |
| 72 | { AddSocketServices, "AddSocketServices" }, |
| 73 | { AdjustResourceInfo, "AdjustResourceInfo" }, |
| 74 | { CheckEraseQueue, "CheckEraseQueue" }, |
| 75 | { CloseMemory, "CloseMemory" }, |
| 76 | { DeregisterClient, "DeregisterClient" }, |
| 77 | { DeregisterEraseQueue, "DeregisterEraseQueue" }, |
| 78 | { GetCardServicesInfo, "GetCardServicesInfo" }, |
| 79 | { GetClientInfo, "GetClientInfo" }, |
| 80 | { GetConfigurationInfo, "GetConfigurationInfo" }, |
| 81 | { GetEventMask, "GetEventMask" }, |
| 82 | { GetFirstClient, "GetFirstClient" }, |
| 83 | { GetFirstRegion, "GetFirstRegion" }, |
| 84 | { GetFirstTuple, "GetFirstTuple" }, |
| 85 | { GetNextClient, "GetNextClient" }, |
| 86 | { GetNextRegion, "GetNextRegion" }, |
| 87 | { GetNextTuple, "GetNextTuple" }, |
| 88 | { GetStatus, "GetStatus" }, |
| 89 | { GetTupleData, "GetTupleData" }, |
| 90 | { MapMemPage, "MapMemPage" }, |
| 91 | { ModifyConfiguration, "ModifyConfiguration" }, |
| 92 | { ModifyWindow, "ModifyWindow" }, |
| 93 | { OpenMemory, "OpenMemory" }, |
| 94 | { ParseTuple, "ParseTuple" }, |
| 95 | { ReadMemory, "ReadMemory" }, |
| 96 | { RegisterClient, "RegisterClient" }, |
| 97 | { RegisterEraseQueue, "RegisterEraseQueue" }, |
| 98 | { RegisterMTD, "RegisterMTD" }, |
| 99 | { ReleaseConfiguration, "ReleaseConfiguration" }, |
| 100 | { ReleaseIO, "ReleaseIO" }, |
| 101 | { ReleaseIRQ, "ReleaseIRQ" }, |
| 102 | { ReleaseWindow, "ReleaseWindow" }, |
| 103 | { RequestConfiguration, "RequestConfiguration" }, |
| 104 | { RequestIO, "RequestIO" }, |
| 105 | { RequestIRQ, "RequestIRQ" }, |
| 106 | { RequestSocketMask, "RequestSocketMask" }, |
| 107 | { RequestWindow, "RequestWindow" }, |
| 108 | { ResetCard, "ResetCard" }, |
| 109 | { SetEventMask, "SetEventMask" }, |
| 110 | { ValidateCIS, "ValidateCIS" }, |
| 111 | { WriteMemory, "WriteMemory" }, |
| 112 | { BindDevice, "BindDevice" }, |
| 113 | { BindMTD, "BindMTD" }, |
| 114 | { ReportError, "ReportError" }, |
| 115 | { SuspendCard, "SuspendCard" }, |
| 116 | { ResumeCard, "ResumeCard" }, |
| 117 | { EjectCard, "EjectCard" }, |
| 118 | { InsertCard, "InsertCard" }, |
| 119 | { ReplaceCIS, "ReplaceCIS" } |
| 120 | }; |
| 121 | |
Dominik Brodowski | 79ba675 | 2008-08-03 14:03:07 +0200 | [diff] [blame] | 122 | const char *pcmcia_error_func(int func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | for (i = 0; i < ARRAY_SIZE(service_table); i++) |
Dominik Brodowski | 79ba675 | 2008-08-03 14:03:07 +0200 | [diff] [blame] | 127 | if (service_table[i].key == func) |
| 128 | return service_table[i].msg; |
| 129 | |
| 130 | return "Unknown service number"; |
| 131 | } |
| 132 | EXPORT_SYMBOL(pcmcia_error_func); |
| 133 | |
| 134 | const char *pcmcia_error_ret(int ret) |
| 135 | { |
| 136 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | for (i = 0; i < ARRAY_SIZE(error_table); i++) |
Dominik Brodowski | 79ba675 | 2008-08-03 14:03:07 +0200 | [diff] [blame] | 139 | if (error_table[i].key == ret) |
| 140 | return error_table[i].msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Dominik Brodowski | 79ba675 | 2008-08-03 14:03:07 +0200 | [diff] [blame] | 142 | return "unknown"; |
| 143 | } |
| 144 | EXPORT_SYMBOL(pcmcia_error_ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /*======================================================================*/ |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Dominik Brodowski | 23a83bf | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 149 | |
| 150 | static void pcmcia_check_driver(struct pcmcia_driver *p_drv) |
| 151 | { |
| 152 | struct pcmcia_device_id *did = p_drv->id_table; |
| 153 | unsigned int i; |
| 154 | u32 hash; |
| 155 | |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 156 | if (!p_drv->probe || !p_drv->remove) |
Pavel Roskin | ba5bb6b | 2005-07-28 01:07:20 -0700 | [diff] [blame] | 157 | printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback " |
| 158 | "function\n", p_drv->drv.name); |
Dominik Brodowski | 1e212f3 | 2005-07-07 17:59:00 -0700 | [diff] [blame] | 159 | |
Dominik Brodowski | 23a83bf | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 160 | while (did && did->match_flags) { |
| 161 | for (i=0; i<4; i++) { |
| 162 | if (!did->prod_id[i]) |
| 163 | continue; |
| 164 | |
| 165 | hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i])); |
| 166 | if (hash == did->prod_id_hash[i]) |
| 167 | continue; |
| 168 | |
| 169 | printk(KERN_DEBUG "pcmcia: %s: invalid hash for " |
| 170 | "product string \"%s\": is 0x%x, should " |
| 171 | "be 0x%x\n", p_drv->drv.name, did->prod_id[i], |
| 172 | did->prod_id_hash[i], hash); |
Dominik Brodowski | 5085cb2 | 2005-06-27 16:28:45 -0700 | [diff] [blame] | 173 | printk(KERN_DEBUG "pcmcia: see " |
| 174 | "Documentation/pcmcia/devicetable.txt for " |
| 175 | "details\n"); |
Dominik Brodowski | 23a83bf | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 176 | } |
| 177 | did++; |
| 178 | } |
| 179 | |
| 180 | return; |
| 181 | } |
| 182 | |
Dominik Brodowski | daa9517 | 2005-06-27 16:28:14 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /*======================================================================*/ |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 187 | struct pcmcia_dynid { |
| 188 | struct list_head node; |
| 189 | struct pcmcia_device_id id; |
| 190 | }; |
| 191 | |
| 192 | /** |
| 193 | * pcmcia_store_new_id - add a new PCMCIA device ID to this driver and re-probe devices |
| 194 | * @driver: target device driver |
| 195 | * @buf: buffer for scanning device ID data |
| 196 | * @count: input size |
| 197 | * |
| 198 | * Adds a new dynamic PCMCIA device ID to this driver, |
| 199 | * and causes the driver to probe for all devices again. |
| 200 | */ |
| 201 | static ssize_t |
| 202 | pcmcia_store_new_id(struct device_driver *driver, const char *buf, size_t count) |
| 203 | { |
| 204 | struct pcmcia_dynid *dynid; |
| 205 | struct pcmcia_driver *pdrv = to_pcmcia_drv(driver); |
| 206 | __u16 match_flags, manf_id, card_id; |
| 207 | __u8 func_id, function, device_no; |
| 208 | __u32 prod_id_hash[4] = {0, 0, 0, 0}; |
| 209 | int fields=0; |
| 210 | int retval = 0; |
| 211 | |
| 212 | fields = sscanf(buf, "%hx %hx %hx %hhx %hhx %hhx %x %x %x %x", |
| 213 | &match_flags, &manf_id, &card_id, &func_id, &function, &device_no, |
| 214 | &prod_id_hash[0], &prod_id_hash[1], &prod_id_hash[2], &prod_id_hash[3]); |
| 215 | if (fields < 6) |
| 216 | return -EINVAL; |
| 217 | |
| 218 | dynid = kzalloc(sizeof(struct pcmcia_dynid), GFP_KERNEL); |
| 219 | if (!dynid) |
| 220 | return -ENOMEM; |
| 221 | |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 222 | dynid->id.match_flags = match_flags; |
| 223 | dynid->id.manf_id = manf_id; |
| 224 | dynid->id.card_id = card_id; |
| 225 | dynid->id.func_id = func_id; |
| 226 | dynid->id.function = function; |
| 227 | dynid->id.device_no = device_no; |
| 228 | memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4); |
| 229 | |
| 230 | spin_lock(&pdrv->dynids.lock); |
Wolfram Sang | b4b3d7b | 2009-07-20 10:58:59 +0200 | [diff] [blame] | 231 | list_add_tail(&dynid->node, &pdrv->dynids.list); |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 232 | spin_unlock(&pdrv->dynids.lock); |
| 233 | |
| 234 | if (get_driver(&pdrv->drv)) { |
| 235 | retval = driver_attach(&pdrv->drv); |
| 236 | put_driver(&pdrv->drv); |
| 237 | } |
| 238 | |
| 239 | if (retval) |
| 240 | return retval; |
| 241 | return count; |
| 242 | } |
| 243 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, pcmcia_store_new_id); |
| 244 | |
| 245 | static void |
| 246 | pcmcia_free_dynids(struct pcmcia_driver *drv) |
| 247 | { |
| 248 | struct pcmcia_dynid *dynid, *n; |
| 249 | |
| 250 | spin_lock(&drv->dynids.lock); |
| 251 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 252 | list_del(&dynid->node); |
| 253 | kfree(dynid); |
| 254 | } |
| 255 | spin_unlock(&drv->dynids.lock); |
| 256 | } |
| 257 | |
| 258 | static int |
| 259 | pcmcia_create_newid_file(struct pcmcia_driver *drv) |
| 260 | { |
| 261 | int error = 0; |
| 262 | if (drv->probe != NULL) |
Greg Kroah-Hartman | 2344c6d | 2007-11-28 12:23:18 -0800 | [diff] [blame] | 263 | error = driver_create_file(&drv->drv, &driver_attr_new_id); |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 264 | return error; |
| 265 | } |
| 266 | |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /** |
| 269 | * pcmcia_register_driver - register a PCMCIA driver with the bus core |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 270 | * @driver: the &driver being registered |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | * |
| 272 | * Registers a PCMCIA driver with the PCMCIA bus core. |
| 273 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | int pcmcia_register_driver(struct pcmcia_driver *driver) |
| 275 | { |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 276 | int error; |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (!driver) |
| 279 | return -EINVAL; |
| 280 | |
Dominik Brodowski | 23a83bf | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 281 | pcmcia_check_driver(driver); |
| 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | /* initialize common fields */ |
| 284 | driver->drv.bus = &pcmcia_bus_type; |
| 285 | driver->drv.owner = driver->owner; |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 286 | spin_lock_init(&driver->dynids.lock); |
| 287 | INIT_LIST_HEAD(&driver->dynids.list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 289 | pr_debug("registering driver %s\n", driver->drv.name); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 290 | |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 291 | error = driver_register(&driver->drv); |
| 292 | if (error < 0) |
| 293 | return error; |
| 294 | |
| 295 | error = pcmcia_create_newid_file(driver); |
| 296 | if (error) |
| 297 | driver_unregister(&driver->drv); |
| 298 | |
| 299 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | EXPORT_SYMBOL(pcmcia_register_driver); |
| 302 | |
| 303 | /** |
| 304 | * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 305 | * @driver: the &driver being unregistered |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | */ |
| 307 | void pcmcia_unregister_driver(struct pcmcia_driver *driver) |
| 308 | { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 309 | pr_debug("unregistering driver %s\n", driver->drv.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | driver_unregister(&driver->drv); |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 311 | pcmcia_free_dynids(driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | EXPORT_SYMBOL(pcmcia_unregister_driver); |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | /* pcmcia_device handling */ |
| 317 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 318 | struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 320 | struct device *tmp_dev; |
| 321 | tmp_dev = get_device(&p_dev->dev); |
| 322 | if (!tmp_dev) |
| 323 | return NULL; |
| 324 | return to_pcmcia_dev(tmp_dev); |
| 325 | } |
| 326 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 327 | void pcmcia_put_dev(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
| 329 | if (p_dev) |
| 330 | put_device(&p_dev->dev); |
| 331 | } |
| 332 | |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 333 | static void pcmcia_release_function(struct kref *ref) |
| 334 | { |
| 335 | struct config_t *c = container_of(ref, struct config_t, ref); |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 336 | pr_debug("releasing config_t\n"); |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 337 | kfree(c); |
| 338 | } |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | static void pcmcia_release_dev(struct device *dev) |
| 341 | { |
| 342 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 343 | dev_dbg(dev, "releasing device\n"); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 344 | pcmcia_put_socket(p_dev->socket); |
Brice Goglin | bd65a68 | 2005-09-09 13:03:29 -0700 | [diff] [blame] | 345 | kfree(p_dev->devname); |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 346 | kref_put(&p_dev->function_config->ref, pcmcia_release_function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | kfree(p_dev); |
| 348 | } |
| 349 | |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 350 | static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc) |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 351 | { |
| 352 | if (!s->pcmcia_state.device_add_pending) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 353 | dev_dbg(&s->dev, "scheduling to add %s secondary" |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 354 | " device to %d\n", mfc ? "mfc" : "pfc", s->sock); |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 355 | s->pcmcia_state.device_add_pending = 1; |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 356 | s->pcmcia_state.mfc_pfc = mfc; |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 357 | schedule_work(&s->device_add); |
| 358 | } |
| 359 | return; |
| 360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | static int pcmcia_device_probe(struct device * dev) |
| 363 | { |
| 364 | struct pcmcia_device *p_dev; |
| 365 | struct pcmcia_driver *p_drv; |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 366 | struct pcmcia_device_id *did; |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 367 | struct pcmcia_socket *s; |
Dominik Brodowski | af2b3b5 | 2006-10-25 21:49:27 -0400 | [diff] [blame] | 368 | cistpl_config_t cis_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | int ret = 0; |
| 370 | |
| 371 | dev = get_device(dev); |
| 372 | if (!dev) |
| 373 | return -ENODEV; |
| 374 | |
| 375 | p_dev = to_pcmcia_dev(dev); |
| 376 | p_drv = to_pcmcia_drv(dev->driver); |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 377 | s = p_dev->socket; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Greg Kroah-Hartman | f3e7a7b | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 379 | /* The PCMCIA code passes the match data in via dev_set_drvdata(dev) |
Alan Cox | cec5eb7 | 2008-09-22 15:58:14 +0100 | [diff] [blame] | 380 | * which is an ugly hack. Once the driver probe is called it may |
| 381 | * and often will overwrite the match data so we must save it first |
| 382 | * |
| 383 | * handle pseudo multifunction devices: |
| 384 | * there are at most two pseudo multifunction devices. |
| 385 | * if we're matching against the first, schedule a |
| 386 | * call which will then check whether there are two |
| 387 | * pseudo devices, and if not, add the second one. |
| 388 | */ |
Greg Kroah-Hartman | f3e7a7b | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 389 | did = dev_get_drvdata(&p_dev->dev); |
Alan Cox | cec5eb7 | 2008-09-22 15:58:14 +0100 | [diff] [blame] | 390 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 391 | dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 392 | |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 393 | if ((!p_drv->probe) || (!p_dev->function_config) || |
| 394 | (!try_module_get(p_drv->owner))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | ret = -EINVAL; |
| 396 | goto put_dev; |
| 397 | } |
| 398 | |
Dominik Brodowski | af2b3b5 | 2006-10-25 21:49:27 -0400 | [diff] [blame] | 399 | /* set up some more device information */ |
| 400 | ret = pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_CONFIG, |
| 401 | &cis_config); |
| 402 | if (!ret) { |
| 403 | p_dev->conf.ConfigBase = cis_config.base; |
| 404 | p_dev->conf.Present = cis_config.rmask[0]; |
| 405 | } else { |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 406 | dev_printk(KERN_INFO, dev, |
| 407 | "pcmcia: could not parse base and rmask0 of CIS\n"); |
Dominik Brodowski | af2b3b5 | 2006-10-25 21:49:27 -0400 | [diff] [blame] | 408 | p_dev->conf.ConfigBase = 0; |
| 409 | p_dev->conf.Present = 0; |
| 410 | } |
| 411 | |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 412 | ret = p_drv->probe(p_dev); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 413 | if (ret) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 414 | dev_dbg(dev, "binding to %s failed with %d\n", |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 415 | p_drv->drv.name, ret); |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 416 | goto put_module; |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 417 | } |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 418 | |
Hugh Dickins | 4ceadbf | 2006-03-10 21:13:44 +0000 | [diff] [blame] | 419 | if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && |
Dominik Brodowski | 82d56e6 | 2006-01-27 19:15:02 +0100 | [diff] [blame] | 420 | (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 421 | pcmcia_add_device_later(p_dev->socket, 0); |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 422 | |
Alan Cox | cec5eb7 | 2008-09-22 15:58:14 +0100 | [diff] [blame] | 423 | put_module: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | if (ret) |
| 425 | module_put(p_drv->owner); |
Alan Cox | cec5eb7 | 2008-09-22 15:58:14 +0100 | [diff] [blame] | 426 | put_dev: |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 427 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | put_device(dev); |
| 429 | return (ret); |
| 430 | } |
| 431 | |
| 432 | |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 433 | /* |
| 434 | * Removes a PCMCIA card from the device tree and socket list. |
| 435 | */ |
| 436 | static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *leftover) |
| 437 | { |
| 438 | struct pcmcia_device *p_dev; |
| 439 | struct pcmcia_device *tmp; |
| 440 | unsigned long flags; |
| 441 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 442 | dev_dbg(leftover ? &leftover->dev : &s->dev, |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 443 | "pcmcia_card_remove(%d) %s\n", s->sock, |
| 444 | leftover ? leftover->devname : ""); |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 445 | |
| 446 | if (!leftover) |
| 447 | s->device_count = 0; |
| 448 | else |
| 449 | s->device_count = 1; |
| 450 | |
| 451 | /* unregister all pcmcia_devices registered with this socket, except leftover */ |
| 452 | list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { |
| 453 | if (p_dev == leftover) |
| 454 | continue; |
| 455 | |
| 456 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); |
| 457 | list_del(&p_dev->socket_device_list); |
| 458 | p_dev->_removed=1; |
| 459 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
| 460 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 461 | dev_dbg(&p_dev->dev, "unregistering device\n"); |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 462 | device_unregister(&p_dev->dev); |
| 463 | } |
| 464 | |
| 465 | return; |
| 466 | } |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | static int pcmcia_device_remove(struct device * dev) |
| 469 | { |
| 470 | struct pcmcia_device *p_dev; |
| 471 | struct pcmcia_driver *p_drv; |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 472 | struct pcmcia_device_id *did; |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 473 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | p_dev = to_pcmcia_dev(dev); |
| 476 | p_drv = to_pcmcia_drv(dev->driver); |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 477 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 478 | dev_dbg(dev, "removing device\n"); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 479 | |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 480 | /* If we're removing the primary module driving a |
| 481 | * pseudo multi-function card, we need to unbind |
| 482 | * all devices |
| 483 | */ |
Greg Kroah-Hartman | f3e7a7b | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 484 | did = dev_get_drvdata(&p_dev->dev); |
Hugh Dickins | b2f51a1 | 2006-03-10 21:15:19 +0000 | [diff] [blame] | 485 | if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 486 | (p_dev->socket->device_count != 0) && |
| 487 | (p_dev->device_no == 0)) |
| 488 | pcmcia_card_remove(p_dev->socket, p_dev); |
| 489 | |
| 490 | /* detach the "instance" */ |
Dominik Brodowski | f399071 | 2005-11-14 21:25:23 +0100 | [diff] [blame] | 491 | if (!p_drv) |
| 492 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Dominik Brodowski | f399071 | 2005-11-14 21:25:23 +0100 | [diff] [blame] | 494 | if (p_drv->remove) |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 495 | p_drv->remove(p_dev); |
| 496 | |
Dominik Brodowski | a0aab14 | 2006-04-04 11:09:26 +0200 | [diff] [blame] | 497 | p_dev->dev_node = NULL; |
| 498 | |
Dominik Brodowski | f399071 | 2005-11-14 21:25:23 +0100 | [diff] [blame] | 499 | /* check for proper unloading */ |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 500 | if (p_dev->_irq || p_dev->_io || p_dev->_locked) |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 501 | dev_printk(KERN_INFO, dev, |
| 502 | "pcmcia: driver %s did not release config properly\n", |
| 503 | p_drv->drv.name); |
Dominik Brodowski | f399071 | 2005-11-14 21:25:23 +0100 | [diff] [blame] | 504 | |
| 505 | for (i = 0; i < MAX_WIN; i++) |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 506 | if (p_dev->_win & CLIENT_WIN_REQ(i)) |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 507 | dev_printk(KERN_INFO, dev, |
| 508 | "pcmcia: driver %s did not release window properly\n", |
| 509 | p_drv->drv.name); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 510 | |
Dominik Brodowski | f399071 | 2005-11-14 21:25:23 +0100 | [diff] [blame] | 511 | /* references from pcmcia_probe_device */ |
| 512 | pcmcia_put_dev(p_dev); |
| 513 | module_put(p_drv->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 519 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | * pcmcia_device_query -- determine information about a pcmcia device |
| 521 | */ |
| 522 | static int pcmcia_device_query(struct pcmcia_device *p_dev) |
| 523 | { |
| 524 | cistpl_manfid_t manf_id; |
| 525 | cistpl_funcid_t func_id; |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 526 | cistpl_vers_1_t *vers1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | unsigned int i; |
| 528 | |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 529 | vers1 = kmalloc(sizeof(*vers1), GFP_KERNEL); |
| 530 | if (!vers1) |
| 531 | return -ENOMEM; |
| 532 | |
Dominik Brodowski | 84897fc | 2009-10-18 23:51:09 +0200 | [diff] [blame] | 533 | if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | CISTPL_MANFID, &manf_id)) { |
| 535 | p_dev->manf_id = manf_id.manf; |
| 536 | p_dev->card_id = manf_id.card; |
| 537 | p_dev->has_manf_id = 1; |
| 538 | p_dev->has_card_id = 1; |
| 539 | } |
| 540 | |
| 541 | if (!pccard_read_tuple(p_dev->socket, p_dev->func, |
| 542 | CISTPL_FUNCID, &func_id)) { |
| 543 | p_dev->func_id = func_id.func; |
| 544 | p_dev->has_func_id = 1; |
| 545 | } else { |
| 546 | /* rule of thumb: cards with no FUNCID, but with |
| 547 | * common memory device geometry information, are |
| 548 | * probably memory cards (from pcmcia-cs) */ |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 549 | cistpl_device_geo_t *devgeo; |
| 550 | |
| 551 | devgeo = kmalloc(sizeof(*devgeo), GFP_KERNEL); |
| 552 | if (!devgeo) { |
| 553 | kfree(vers1); |
| 554 | return -ENOMEM; |
| 555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | if (!pccard_read_tuple(p_dev->socket, p_dev->func, |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 557 | CISTPL_DEVICE_GEO, devgeo)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 558 | dev_dbg(&p_dev->dev, |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 559 | "mem device geometry probably means " |
| 560 | "FUNCID_MEMORY\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | p_dev->func_id = CISTPL_FUNCID_MEMORY; |
| 562 | p_dev->has_func_id = 1; |
| 563 | } |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 564 | kfree(devgeo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Dominik Brodowski | 84897fc | 2009-10-18 23:51:09 +0200 | [diff] [blame] | 567 | if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1, |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 568 | vers1)) { |
Dominik Brodowski | c5e0952 | 2009-10-19 00:04:25 +0200 | [diff] [blame] | 569 | for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | char *tmp; |
| 571 | unsigned int length; |
| 572 | |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 573 | tmp = vers1->str + vers1->ofs[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | length = strlen(tmp) + 1; |
Janos Farkas | 6e3d4f2 | 2006-03-31 01:04:57 +0200 | [diff] [blame] | 576 | if ((length < 2) || (length > 255)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | continue; |
| 578 | |
| 579 | p_dev->prod_id[i] = kmalloc(sizeof(char) * length, |
| 580 | GFP_KERNEL); |
| 581 | if (!p_dev->prod_id[i]) |
| 582 | continue; |
| 583 | |
| 584 | p_dev->prod_id[i] = strncpy(p_dev->prod_id[i], |
| 585 | tmp, length); |
| 586 | } |
| 587 | } |
| 588 | |
Ingo Molnar | 76fa82f | 2005-09-09 13:03:21 -0700 | [diff] [blame] | 589 | kfree(vers1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | |
| 594 | /* device_add_lock is needed to avoid double registration by cardmgr and kernel. |
| 595 | * Serializes pcmcia_device_add; will most likely be removed in future. |
| 596 | * |
| 597 | * While it has the caveat that adding new PCMCIA devices inside(!) device_register() |
| 598 | * won't work, this doesn't matter much at the moment: the driver core doesn't |
| 599 | * support it either. |
| 600 | */ |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 601 | static DEFINE_MUTEX(device_add_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 603 | struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 605 | struct pcmcia_device *p_dev, *tmp_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | unsigned long flags; |
| 607 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 608 | s = pcmcia_get_socket(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (!s) |
| 610 | return NULL; |
| 611 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 612 | mutex_lock(&device_add_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 614 | pr_debug("adding device to %d, function %d\n", s->sock, function); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 615 | |
Dominik Brodowski | 6cf5be5 | 2006-11-27 21:03:48 -0500 | [diff] [blame] | 616 | /* max of 4 devices per card */ |
| 617 | if (s->device_count == 4) |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 618 | goto err_put; |
| 619 | |
Dominik Brodowski | 8084b37 | 2005-12-11 21:18:26 +0100 | [diff] [blame] | 620 | p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | if (!p_dev) |
| 622 | goto err_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 624 | p_dev->socket = s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | p_dev->device_no = (s->device_count++); |
| 626 | p_dev->func = function; |
| 627 | |
| 628 | p_dev->dev.bus = &pcmcia_bus_type; |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 629 | p_dev->dev.parent = s->dev.parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | p_dev->dev.release = pcmcia_release_dev; |
James Bottomley | 43d9f7f | 2007-10-16 01:23:58 -0700 | [diff] [blame] | 631 | /* by default don't allow DMA */ |
| 632 | p_dev->dma_mask = DMA_MASK_NONE; |
| 633 | p_dev->dev.dma_mask = &p_dev->dma_mask; |
Kay Sievers | 2509698 | 2008-11-01 11:46:06 +0100 | [diff] [blame] | 634 | dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no); |
| 635 | if (!dev_name(&p_dev->dev)) |
| 636 | goto err_free; |
| 637 | p_dev->devname = kasprintf(GFP_KERNEL, "pcmcia%s", dev_name(&p_dev->dev)); |
Brice Goglin | bd65a68 | 2005-09-09 13:03:29 -0700 | [diff] [blame] | 638 | if (!p_dev->devname) |
| 639 | goto err_free; |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 640 | dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 643 | |
| 644 | /* |
| 645 | * p_dev->function_config must be the same for all card functions. |
| 646 | * Note that this is serialized by the device_add_lock, so that |
| 647 | * only one such struct will be created. |
| 648 | */ |
| 649 | list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list) |
| 650 | if (p_dev->func == tmp_dev->func) { |
| 651 | p_dev->function_config = tmp_dev->function_config; |
Komuro | 3e879f6 | 2008-11-02 19:33:24 +0900 | [diff] [blame] | 652 | p_dev->io = tmp_dev->io; |
| 653 | p_dev->irq = tmp_dev->irq; |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 654 | kref_get(&p_dev->function_config->ref); |
| 655 | } |
| 656 | |
| 657 | /* Add to the list in pcmcia_bus_socket */ |
Komuro | 6171b88 | 2006-04-02 17:39:27 +0900 | [diff] [blame] | 658 | list_add(&p_dev->socket_device_list, &s->devices_list); |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
| 661 | |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 662 | if (!p_dev->function_config) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 663 | dev_dbg(&p_dev->dev, "creating config_t\n"); |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 664 | p_dev->function_config = kzalloc(sizeof(struct config_t), |
| 665 | GFP_KERNEL); |
| 666 | if (!p_dev->function_config) |
| 667 | goto err_unreg; |
| 668 | kref_init(&p_dev->function_config->ref); |
| 669 | } |
| 670 | |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 671 | dev_printk(KERN_NOTICE, &p_dev->dev, |
| 672 | "pcmcia: registering new device %s\n", |
| 673 | p_dev->devname); |
Dominik Brodowski | 807277c | 2005-11-12 23:34:06 +0100 | [diff] [blame] | 674 | |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 675 | pcmcia_device_query(p_dev); |
| 676 | |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 677 | if (device_register(&p_dev->dev)) |
| 678 | goto err_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 680 | mutex_unlock(&device_add_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | return p_dev; |
| 683 | |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 684 | err_unreg: |
| 685 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); |
| 686 | list_del(&p_dev->socket_device_list); |
| 687 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
| 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | err_free: |
Brice Goglin | bd65a68 | 2005-09-09 13:03:29 -0700 | [diff] [blame] | 690 | kfree(p_dev->devname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | kfree(p_dev); |
| 692 | s->device_count--; |
| 693 | err_put: |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 694 | mutex_unlock(&device_add_lock); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 695 | pcmcia_put_socket(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
| 697 | return NULL; |
| 698 | } |
| 699 | |
| 700 | |
| 701 | static int pcmcia_card_add(struct pcmcia_socket *s) |
| 702 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | cistpl_longlink_mfc_t mfc; |
Dominik Brodowski | c5081d5 | 2008-06-19 20:12:34 +0200 | [diff] [blame] | 704 | unsigned int no_funcs, i, no_chains; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | int ret = 0; |
| 706 | |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 707 | if (!(s->resource_setup_done)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 708 | dev_dbg(&s->dev, |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 709 | "no resources available, delaying card_add\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | return -EAGAIN; /* try again, but later... */ |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 713 | if (pcmcia_validate_mem(s)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 714 | dev_dbg(&s->dev, "validating mem resources failed, " |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 715 | "delaying card_add\n"); |
Dominik Brodowski | de75914 | 2005-09-28 19:41:56 +0200 | [diff] [blame] | 716 | return -EAGAIN; /* try again, but later... */ |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 717 | } |
Dominik Brodowski | de75914 | 2005-09-28 19:41:56 +0200 | [diff] [blame] | 718 | |
Dominik Brodowski | 84897fc | 2009-10-18 23:51:09 +0200 | [diff] [blame] | 719 | ret = pccard_validate_cis(s, &no_chains); |
Dominik Brodowski | c5081d5 | 2008-06-19 20:12:34 +0200 | [diff] [blame] | 720 | if (ret || !no_chains) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 721 | dev_dbg(&s->dev, "invalid CIS or invalid resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | return -ENODEV; |
| 723 | } |
| 724 | |
| 725 | if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc)) |
| 726 | no_funcs = mfc.nfn; |
| 727 | else |
| 728 | no_funcs = 1; |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 729 | s->functions = no_funcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | for (i=0; i < no_funcs; i++) |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 732 | pcmcia_device_add(s, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | return (ret); |
| 735 | } |
| 736 | |
| 737 | |
David Howells | 4796b71 | 2006-12-06 15:01:18 +0000 | [diff] [blame] | 738 | static void pcmcia_delayed_add_device(struct work_struct *work) |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 739 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 740 | struct pcmcia_socket *s = |
| 741 | container_of(work, struct pcmcia_socket, device_add); |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 742 | dev_dbg(&s->dev, "adding additional device to %d\n", s->sock); |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 743 | pcmcia_device_add(s, s->pcmcia_state.mfc_pfc); |
Dominik Brodowski | b5e4391 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 744 | s->pcmcia_state.device_add_pending = 0; |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 745 | s->pcmcia_state.mfc_pfc = 0; |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 748 | static int pcmcia_requery(struct device *dev, void * _data) |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 749 | { |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 750 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 751 | if (!p_dev->dev.driver) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 752 | dev_dbg(dev, "update device information\n"); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 753 | pcmcia_device_query(p_dev); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 754 | } |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 759 | static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis) |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 760 | { |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 761 | int no_devices = 0; |
Dominik Brodowski | f901b8c | 2006-10-25 19:56:55 -0400 | [diff] [blame] | 762 | int ret = 0; |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 763 | unsigned long flags; |
| 764 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 765 | /* must be called with skt_mutex held */ |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 766 | dev_dbg(&skt->dev, "re-scanning socket %d\n", skt->sock); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 767 | |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 768 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 769 | if (list_empty(&skt->devices_list)) |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 770 | no_devices = 1; |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 771 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
| 772 | |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 773 | /* If this is because of a CIS override, start over */ |
| 774 | if (new_cis && !no_devices) |
| 775 | pcmcia_card_remove(skt, NULL); |
| 776 | |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 777 | /* if no devices were added for this socket yet because of |
| 778 | * missing resource information or other trouble, we need to |
| 779 | * do this now. */ |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 780 | if (no_devices || new_cis) { |
Dominik Brodowski | f901b8c | 2006-10-25 19:56:55 -0400 | [diff] [blame] | 781 | ret = pcmcia_card_add(skt); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 782 | if (ret) |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | /* some device information might have changed because of a CIS |
| 787 | * update or because we can finally read it correctly... so |
| 788 | * determine it again, overwriting old values if necessary. */ |
| 789 | bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery); |
| 790 | |
| 791 | /* we re-scan all devices, not just the ones connected to this |
| 792 | * socket. This does not matter, though. */ |
Dominik Brodowski | f901b8c | 2006-10-25 19:56:55 -0400 | [diff] [blame] | 793 | ret = bus_rescan_devices(&pcmcia_bus_type); |
| 794 | if (ret) |
| 795 | printk(KERN_INFO "pcmcia: bus_rescan_devices failed\n"); |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 796 | } |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 797 | |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 798 | #ifdef CONFIG_PCMCIA_LOAD_CIS |
| 799 | |
| 800 | /** |
| 801 | * pcmcia_load_firmware - load CIS from userspace if device-provided is broken |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 802 | * @dev: the pcmcia device which needs a CIS override |
| 803 | * @filename: requested filename in /lib/firmware/ |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 804 | * |
| 805 | * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if |
| 806 | * the one provided by the card is broken. The firmware files reside in |
| 807 | * /lib/firmware/ in userspace. |
| 808 | */ |
| 809 | static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) |
| 810 | { |
| 811 | struct pcmcia_socket *s = dev->socket; |
| 812 | const struct firmware *fw; |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 813 | int ret = -ENOMEM; |
| 814 | int no_funcs; |
| 815 | int old_funcs; |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 816 | cistpl_longlink_mfc_t mfc; |
| 817 | |
| 818 | if (!filename) |
| 819 | return -EINVAL; |
| 820 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 821 | dev_dbg(&dev->dev, "trying to load CIS file %s\n", filename); |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 822 | |
Samuel Ortiz | ed62ace | 2009-05-27 00:49:35 +0200 | [diff] [blame] | 823 | if (request_firmware(&fw, filename, &dev->dev) == 0) { |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 824 | if (fw->size >= CISTPL_MAX_CIS_SIZE) { |
| 825 | ret = -EINVAL; |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 826 | dev_printk(KERN_ERR, &dev->dev, |
| 827 | "pcmcia: CIS override is too big\n"); |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 828 | goto release; |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 829 | } |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 830 | |
Dominik Brodowski | 53efec9 | 2008-07-28 19:44:05 +0200 | [diff] [blame] | 831 | if (!pcmcia_replace_cis(s, fw->data, fw->size)) |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 832 | ret = 0; |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 833 | else { |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 834 | dev_printk(KERN_ERR, &dev->dev, |
| 835 | "pcmcia: CIS override failed\n"); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 836 | goto release; |
| 837 | } |
| 838 | |
Dominik Brodowski | 1d2c904 | 2006-11-06 21:52:16 -0500 | [diff] [blame] | 839 | |
| 840 | /* update information */ |
| 841 | pcmcia_device_query(dev); |
| 842 | |
| 843 | /* does this cis override add or remove functions? */ |
| 844 | old_funcs = s->functions; |
| 845 | |
| 846 | if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc)) |
| 847 | no_funcs = mfc.nfn; |
| 848 | else |
| 849 | no_funcs = 1; |
| 850 | s->functions = no_funcs; |
| 851 | |
| 852 | if (old_funcs > no_funcs) |
| 853 | pcmcia_card_remove(s, dev); |
| 854 | else if (no_funcs > old_funcs) |
| 855 | pcmcia_add_device_later(s, 1); |
| 856 | } |
| 857 | release: |
| 858 | release_firmware(fw); |
| 859 | |
| 860 | return (ret); |
| 861 | } |
| 862 | |
| 863 | #else /* !CONFIG_PCMCIA_LOAD_CIS */ |
| 864 | |
| 865 | static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) |
| 866 | { |
| 867 | return -ENODEV; |
| 868 | } |
| 869 | |
| 870 | #endif |
| 871 | |
| 872 | |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 873 | static inline int pcmcia_devmatch(struct pcmcia_device *dev, |
| 874 | struct pcmcia_device_id *did) |
| 875 | { |
| 876 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) { |
| 877 | if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id)) |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) { |
| 882 | if ((!dev->has_card_id) || (dev->card_id != did->card_id)) |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) { |
| 887 | if (dev->func != did->function) |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) { |
| 892 | if (!dev->prod_id[0]) |
| 893 | return 0; |
| 894 | if (strcmp(did->prod_id[0], dev->prod_id[0])) |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) { |
| 899 | if (!dev->prod_id[1]) |
| 900 | return 0; |
| 901 | if (strcmp(did->prod_id[1], dev->prod_id[1])) |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) { |
| 906 | if (!dev->prod_id[2]) |
| 907 | return 0; |
| 908 | if (strcmp(did->prod_id[2], dev->prod_id[2])) |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) { |
| 913 | if (!dev->prod_id[3]) |
| 914 | return 0; |
| 915 | if (strcmp(did->prod_id[3], dev->prod_id[3])) |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 920 | if (dev->device_no != did->device_no) |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { |
| 925 | if ((!dev->has_func_id) || (dev->func_id != did->func_id)) |
| 926 | return 0; |
| 927 | |
| 928 | /* if this is a pseudo-multi-function device, |
| 929 | * we need explicit matches */ |
| 930 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) |
| 931 | return 0; |
| 932 | if (dev->device_no) |
| 933 | return 0; |
| 934 | |
| 935 | /* also, FUNC_ID matching needs to be activated by userspace |
| 936 | * after it has re-checked that there is no possible module |
| 937 | * with a prod_id/manf_id/card_id match. |
| 938 | */ |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 939 | dev_dbg(&dev->dev, |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 940 | "skipping FUNC_ID match until userspace interaction\n"); |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 941 | if (!dev->allow_func_id_match) |
| 942 | return 0; |
| 943 | } |
| 944 | |
Dominik Brodowski | ea7b388 | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 945 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 946 | dev_dbg(&dev->dev, "device needs a fake CIS\n"); |
Dominik Brodowski | daa9517 | 2005-06-27 16:28:14 -0700 | [diff] [blame] | 947 | if (!dev->socket->fake_cis) |
| 948 | pcmcia_load_firmware(dev, did->cisfile); |
| 949 | |
| 950 | if (!dev->socket->fake_cis) |
Dominik Brodowski | ea7b388 | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 951 | return 0; |
Dominik Brodowski | ea7b388 | 2005-06-27 16:28:07 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Dominik Brodowski | f602ff7 | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 954 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) { |
| 955 | int i; |
| 956 | for (i=0; i<4; i++) |
| 957 | if (dev->prod_id[i]) |
| 958 | return 0; |
| 959 | if (dev->has_manf_id || dev->has_card_id || dev->has_func_id) |
| 960 | return 0; |
| 961 | } |
| 962 | |
Greg Kroah-Hartman | f3e7a7b | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 963 | dev_set_drvdata(&dev->dev, did); |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 964 | |
| 965 | return 1; |
| 966 | } |
| 967 | |
| 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) { |
| 970 | struct pcmcia_device * p_dev = to_pcmcia_dev(dev); |
| 971 | struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 972 | struct pcmcia_device_id *did = p_drv->id_table; |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 973 | struct pcmcia_dynid *dynid; |
| 974 | |
| 975 | /* match dynamic devices first */ |
| 976 | spin_lock(&p_drv->dynids.lock); |
| 977 | list_for_each_entry(dynid, &p_drv->dynids.list, node) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 978 | dev_dbg(dev, "trying to match to %s\n", drv->name); |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 979 | if (pcmcia_devmatch(p_dev, &dynid->id)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 980 | dev_dbg(dev, "matched to %s\n", drv->name); |
Bernhard Walle | 6179b55 | 2007-05-06 14:48:44 -0700 | [diff] [blame] | 981 | spin_unlock(&p_drv->dynids.lock); |
| 982 | return 1; |
| 983 | } |
| 984 | } |
| 985 | spin_unlock(&p_drv->dynids.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
Dominik Brodowski | 0e0fad8 | 2006-01-15 01:14:31 +0100 | [diff] [blame] | 987 | #ifdef CONFIG_PCMCIA_IOCTL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | /* matching by cardmgr */ |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 989 | if (p_dev->cardmgr == p_drv) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 990 | dev_dbg(dev, "cardmgr matched to %s\n", drv->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | return 1; |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 992 | } |
Dominik Brodowski | 0e0fad8 | 2006-01-15 01:14:31 +0100 | [diff] [blame] | 993 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 995 | while (did && did->match_flags) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 996 | dev_dbg(dev, "trying to match to %s\n", drv->name); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 997 | if (pcmcia_devmatch(p_dev, did)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 998 | dev_dbg(dev, "matched to %s\n", drv->name); |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 999 | return 1; |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1000 | } |
Dominik Brodowski | 1ad275e | 2005-06-27 16:28:06 -0700 | [diff] [blame] | 1001 | did++; |
| 1002 | } |
| 1003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | return 0; |
| 1005 | } |
| 1006 | |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1007 | #ifdef CONFIG_HOTPLUG |
| 1008 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1009 | static int pcmcia_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1010 | { |
| 1011 | struct pcmcia_device *p_dev; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1012 | int i; |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1013 | u32 hash[4] = { 0, 0, 0, 0}; |
| 1014 | |
| 1015 | if (!dev) |
| 1016 | return -ENODEV; |
| 1017 | |
| 1018 | p_dev = to_pcmcia_dev(dev); |
| 1019 | |
| 1020 | /* calculate hashes */ |
| 1021 | for (i=0; i<4; i++) { |
| 1022 | if (!p_dev->prod_id[i]) |
| 1023 | continue; |
| 1024 | hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i])); |
| 1025 | } |
| 1026 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1027 | if (add_uevent_var(env, "SOCKET_NO=%u", p_dev->socket->sock)) |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1028 | return -ENOMEM; |
| 1029 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1030 | if (add_uevent_var(env, "DEVICE_NO=%02X", p_dev->device_no)) |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1031 | return -ENOMEM; |
| 1032 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1033 | if (add_uevent_var(env, "MODALIAS=pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X" |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1034 | "pa%08Xpb%08Xpc%08Xpd%08X", |
| 1035 | p_dev->has_manf_id ? p_dev->manf_id : 0, |
| 1036 | p_dev->has_card_id ? p_dev->card_id : 0, |
| 1037 | p_dev->has_func_id ? p_dev->func_id : 0, |
| 1038 | p_dev->func, |
| 1039 | p_dev->device_no, |
| 1040 | hash[0], |
| 1041 | hash[1], |
| 1042 | hash[2], |
| 1043 | hash[3])) |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1044 | return -ENOMEM; |
| 1045 | |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1046 | return 0; |
| 1047 | } |
| 1048 | |
| 1049 | #else |
| 1050 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1051 | static int pcmcia_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
Dominik Brodowski | 840c2ac | 2005-06-27 16:28:04 -0700 | [diff] [blame] | 1052 | { |
| 1053 | return -ENODEV; |
| 1054 | } |
| 1055 | |
| 1056 | #endif |
| 1057 | |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1058 | /************************ runtime PM support ***************************/ |
| 1059 | |
| 1060 | static int pcmcia_dev_suspend(struct device *dev, pm_message_t state); |
| 1061 | static int pcmcia_dev_resume(struct device *dev); |
| 1062 | |
| 1063 | static int runtime_suspend(struct device *dev) |
| 1064 | { |
| 1065 | int rc; |
| 1066 | |
| 1067 | down(&dev->sem); |
| 1068 | rc = pcmcia_dev_suspend(dev, PMSG_SUSPEND); |
| 1069 | up(&dev->sem); |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1070 | return rc; |
| 1071 | } |
| 1072 | |
| 1073 | static void runtime_resume(struct device *dev) |
| 1074 | { |
| 1075 | int rc; |
| 1076 | |
| 1077 | down(&dev->sem); |
| 1078 | rc = pcmcia_dev_resume(dev); |
| 1079 | up(&dev->sem); |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | /************************ per-device sysfs output ***************************/ |
| 1083 | |
| 1084 | #define pcmcia_device_attr(field, test, format) \ |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 1085 | static ssize_t field##_show (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | { \ |
| 1087 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \ |
| 1088 | return p_dev->test ? sprintf (buf, format, p_dev->field) : -ENODEV; \ |
| 1089 | } |
| 1090 | |
| 1091 | #define pcmcia_device_stringattr(name, field) \ |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 1092 | static ssize_t name##_show (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | { \ |
| 1094 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \ |
| 1095 | return p_dev->field ? sprintf (buf, "%s\n", p_dev->field) : -ENODEV; \ |
| 1096 | } |
| 1097 | |
| 1098 | pcmcia_device_attr(func, socket, "0x%02x\n"); |
| 1099 | pcmcia_device_attr(func_id, has_func_id, "0x%02x\n"); |
| 1100 | pcmcia_device_attr(manf_id, has_manf_id, "0x%04x\n"); |
| 1101 | pcmcia_device_attr(card_id, has_card_id, "0x%04x\n"); |
| 1102 | pcmcia_device_stringattr(prod_id1, prod_id[0]); |
| 1103 | pcmcia_device_stringattr(prod_id2, prod_id[1]); |
| 1104 | pcmcia_device_stringattr(prod_id3, prod_id[2]); |
| 1105 | pcmcia_device_stringattr(prod_id4, prod_id[3]); |
| 1106 | |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 1107 | |
| 1108 | static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute *attr, char *buf) |
| 1109 | { |
| 1110 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1111 | |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1112 | if (p_dev->suspended) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 1113 | return sprintf(buf, "off\n"); |
| 1114 | else |
| 1115 | return sprintf(buf, "on\n"); |
| 1116 | } |
| 1117 | |
| 1118 | static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute *attr, |
| 1119 | const char *buf, size_t count) |
| 1120 | { |
| 1121 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1122 | int ret = 0; |
| 1123 | |
| 1124 | if (!count) |
| 1125 | return -EINVAL; |
| 1126 | |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1127 | if ((!p_dev->suspended) && !strncmp(buf, "off", 3)) |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1128 | ret = runtime_suspend(dev); |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1129 | else if (p_dev->suspended && !strncmp(buf, "on", 2)) |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1130 | runtime_resume(dev); |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 1131 | |
| 1132 | return ret ? ret : count; |
| 1133 | } |
| 1134 | |
| 1135 | |
Dominik Brodowski | 3704511 | 2005-06-30 02:58:47 -0700 | [diff] [blame] | 1136 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) |
Dominik Brodowski | 3248ff4 | 2005-06-27 16:29:01 -0700 | [diff] [blame] | 1137 | { |
| 1138 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1139 | int i; |
| 1140 | u32 hash[4] = { 0, 0, 0, 0}; |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1141 | |
Dominik Brodowski | 3248ff4 | 2005-06-27 16:29:01 -0700 | [diff] [blame] | 1142 | /* calculate hashes */ |
| 1143 | for (i=0; i<4; i++) { |
| 1144 | if (!p_dev->prod_id[i]) |
| 1145 | continue; |
| 1146 | hash[i] = crc32(0,p_dev->prod_id[i],strlen(p_dev->prod_id[i])); |
| 1147 | } |
| 1148 | return sprintf(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X" |
| 1149 | "pa%08Xpb%08Xpc%08Xpd%08X\n", |
| 1150 | p_dev->has_manf_id ? p_dev->manf_id : 0, |
| 1151 | p_dev->has_card_id ? p_dev->card_id : 0, |
| 1152 | p_dev->has_func_id ? p_dev->func_id : 0, |
| 1153 | p_dev->func, p_dev->device_no, |
| 1154 | hash[0], hash[1], hash[2], hash[3]); |
| 1155 | } |
| 1156 | |
| 1157 | static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, |
| 1158 | struct device_attribute *attr, const char *buf, size_t count) |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1159 | { |
| 1160 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
Dominik Brodowski | f901b8c | 2006-10-25 19:56:55 -0400 | [diff] [blame] | 1161 | int ret; |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 1162 | |
| 1163 | if (!count) |
| 1164 | return -EINVAL; |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1165 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 1166 | mutex_lock(&p_dev->socket->skt_mutex); |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1167 | p_dev->allow_func_id_match = 1; |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 1168 | mutex_unlock(&p_dev->socket->skt_mutex); |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1169 | |
Dominik Brodowski | f901b8c | 2006-10-25 19:56:55 -0400 | [diff] [blame] | 1170 | ret = bus_rescan_devices(&pcmcia_bus_type); |
| 1171 | if (ret) |
| 1172 | printk(KERN_INFO "pcmcia: bus_rescan_devices failed after " |
| 1173 | "allowing func_id matches\n"); |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1174 | |
| 1175 | return count; |
| 1176 | } |
| 1177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | static struct device_attribute pcmcia_dev_attrs[] = { |
| 1179 | __ATTR(function, 0444, func_show, NULL), |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 1180 | __ATTR(pm_state, 0644, pcmcia_show_pm_state, pcmcia_store_pm_state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | __ATTR_RO(func_id), |
| 1182 | __ATTR_RO(manf_id), |
| 1183 | __ATTR_RO(card_id), |
| 1184 | __ATTR_RO(prod_id1), |
| 1185 | __ATTR_RO(prod_id2), |
| 1186 | __ATTR_RO(prod_id3), |
| 1187 | __ATTR_RO(prod_id4), |
Dominik Brodowski | 3248ff4 | 2005-06-27 16:29:01 -0700 | [diff] [blame] | 1188 | __ATTR_RO(modalias), |
Dominik Brodowski | a5b5577 | 2005-06-27 16:28:10 -0700 | [diff] [blame] | 1189 | __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | __ATTR_NULL, |
| 1191 | }; |
| 1192 | |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1193 | /* PM support, also needed for reset */ |
| 1194 | |
| 1195 | static int pcmcia_dev_suspend(struct device * dev, pm_message_t state) |
| 1196 | { |
| 1197 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1198 | struct pcmcia_driver *p_drv = NULL; |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1199 | int ret = 0; |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1200 | |
David Brownell | d6b4fa6 | 2008-02-04 22:27:37 -0800 | [diff] [blame] | 1201 | if (p_dev->suspended) |
| 1202 | return 0; |
| 1203 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1204 | dev_dbg(dev, "suspending\n"); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1205 | |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1206 | if (dev->driver) |
| 1207 | p_drv = to_pcmcia_drv(dev->driver); |
| 1208 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1209 | if (!p_drv) |
| 1210 | goto out; |
| 1211 | |
| 1212 | if (p_drv->suspend) { |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 1213 | ret = p_drv->suspend(p_dev); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1214 | if (ret) { |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 1215 | dev_printk(KERN_ERR, dev, |
| 1216 | "pcmcia: device %s (driver %s) did " |
| 1217 | "not want to go to sleep (%d)\n", |
| 1218 | p_dev->devname, p_drv->drv.name, ret); |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1219 | goto out; |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1220 | } |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 1221 | } |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1222 | |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1223 | if (p_dev->device_no == p_dev->func) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1224 | dev_dbg(dev, "releasing configuration\n"); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1225 | pcmcia_release_configuration(p_dev); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1226 | } |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1227 | |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1228 | out: |
| 1229 | if (!ret) |
| 1230 | p_dev->suspended = 1; |
| 1231 | return ret; |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | static int pcmcia_dev_resume(struct device * dev) |
| 1236 | { |
| 1237 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1238 | struct pcmcia_driver *p_drv = NULL; |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1239 | int ret = 0; |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1240 | |
David Brownell | d6b4fa6 | 2008-02-04 22:27:37 -0800 | [diff] [blame] | 1241 | if (!p_dev->suspended) |
| 1242 | return 0; |
| 1243 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1244 | dev_dbg(dev, "resuming\n"); |
Dominik Brodowski | d9d9ea0 | 2006-12-02 22:11:44 +0200 | [diff] [blame] | 1245 | |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1246 | if (dev->driver) |
| 1247 | p_drv = to_pcmcia_drv(dev->driver); |
| 1248 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1249 | if (!p_drv) |
| 1250 | goto out; |
| 1251 | |
| 1252 | if (p_dev->device_no == p_dev->func) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1253 | dev_dbg(dev, "requesting configuration\n"); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1254 | ret = pcmcia_request_configuration(p_dev, &p_dev->conf); |
| 1255 | if (ret) |
| 1256 | goto out; |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 1257 | } |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1258 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1259 | if (p_drv->resume) |
| 1260 | ret = p_drv->resume(p_dev); |
| 1261 | |
Dominik Brodowski | f6fbe01 | 2006-01-20 15:10:23 +0100 | [diff] [blame] | 1262 | out: |
| 1263 | if (!ret) |
| 1264 | p_dev->suspended = 0; |
| 1265 | return ret; |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | static int pcmcia_bus_suspend_callback(struct device *dev, void * _data) |
| 1270 | { |
| 1271 | struct pcmcia_socket *skt = _data; |
| 1272 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1273 | |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1274 | if (p_dev->socket != skt || p_dev->suspended) |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1275 | return 0; |
| 1276 | |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1277 | return runtime_suspend(dev); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | static int pcmcia_bus_resume_callback(struct device *dev, void * _data) |
| 1281 | { |
| 1282 | struct pcmcia_socket *skt = _data; |
| 1283 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
| 1284 | |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1285 | if (p_dev->socket != skt || !p_dev->suspended) |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1286 | return 0; |
| 1287 | |
Alan Stern | 3f8df78 | 2007-07-12 16:57:22 -0400 | [diff] [blame] | 1288 | runtime_resume(dev); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1289 | |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | static int pcmcia_bus_resume(struct pcmcia_socket *skt) |
| 1294 | { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1295 | dev_dbg(&skt->dev, "resuming socket %d\n", skt->sock); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1296 | bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback); |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | static int pcmcia_bus_suspend(struct pcmcia_socket *skt) |
| 1301 | { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1302 | dev_dbg(&skt->dev, "suspending socket %d\n", skt->sock); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1303 | if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt, |
| 1304 | pcmcia_bus_suspend_callback)) { |
| 1305 | pcmcia_bus_resume(skt); |
| 1306 | return -EIO; |
| 1307 | } |
| 1308 | return 0; |
| 1309 | } |
| 1310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 1312 | /*====================================================================== |
| 1313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | The card status event handler. |
| 1315 | |
| 1316 | ======================================================================*/ |
| 1317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | /* Normally, the event is passed to individual drivers after |
| 1319 | * informing userspace. Only for CS_EVENT_CARD_REMOVAL this |
| 1320 | * is inversed to maintain historic compatibility. |
| 1321 | */ |
| 1322 | |
| 1323 | static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) |
| 1324 | { |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1325 | struct pcmcia_socket *s = pcmcia_get_socket(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
Florin Malita | 1617406 | 2006-05-24 21:21:31 -0400 | [diff] [blame] | 1327 | if (!s) { |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 1328 | dev_printk(KERN_ERR, &skt->dev, |
| 1329 | "PCMCIA obtaining reference to socket " \ |
| 1330 | "failed, event 0x%x lost!\n", event); |
Florin Malita | 1617406 | 2006-05-24 21:21:31 -0400 | [diff] [blame] | 1331 | return -ENODEV; |
| 1332 | } |
| 1333 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame^] | 1334 | dev_dbg(&skt->dev, "ds_event(0x%06x, %d, 0x%p)\n", |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 1335 | event, priority, skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 1337 | switch (event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | case CS_EVENT_CARD_REMOVAL: |
Dominik Brodowski | b5e4391 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1339 | s->pcmcia_state.present = 0; |
Dominik Brodowski | d6ff5a8 | 2006-02-05 09:51:34 +0100 | [diff] [blame] | 1340 | pcmcia_card_remove(skt, NULL); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1341 | handle_event(skt, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | break; |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 1343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | case CS_EVENT_CARD_INSERTION: |
Dominik Brodowski | b5e4391 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1345 | s->pcmcia_state.present = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | pcmcia_card_add(skt); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1347 | handle_event(skt, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | break; |
| 1349 | |
| 1350 | case CS_EVENT_EJECTION_REQUEST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | break; |
| 1352 | |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1353 | case CS_EVENT_PM_SUSPEND: |
| 1354 | case CS_EVENT_PM_RESUME: |
| 1355 | case CS_EVENT_RESET_PHYSICAL: |
| 1356 | case CS_EVENT_CARD_RESET: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | default: |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1358 | handle_event(skt, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1362 | pcmcia_put_socket(s); |
| 1363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | return 0; |
| 1365 | } /* ds_event */ |
| 1366 | |
| 1367 | |
Dominik Brodowski | 9940ec3 | 2006-03-05 11:04:33 +0100 | [diff] [blame] | 1368 | struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *_p_dev) |
| 1369 | { |
| 1370 | struct pcmcia_device *p_dev; |
| 1371 | struct pcmcia_device *ret = NULL; |
| 1372 | |
| 1373 | p_dev = pcmcia_get_dev(_p_dev); |
| 1374 | if (!p_dev) |
| 1375 | return NULL; |
| 1376 | |
| 1377 | if (!p_dev->socket->pcmcia_state.present) |
| 1378 | goto out; |
| 1379 | |
| 1380 | if (p_dev->_removed) |
| 1381 | goto out; |
| 1382 | |
| 1383 | if (p_dev->suspended) |
| 1384 | goto out; |
| 1385 | |
| 1386 | ret = p_dev; |
| 1387 | out: |
| 1388 | pcmcia_put_dev(p_dev); |
| 1389 | return ret; |
| 1390 | } |
| 1391 | EXPORT_SYMBOL(pcmcia_dev_present); |
| 1392 | |
| 1393 | |
Dominik Brodowski | 90c6cdd | 2005-06-27 16:28:49 -0700 | [diff] [blame] | 1394 | static struct pcmcia_callback pcmcia_bus_callback = { |
| 1395 | .owner = THIS_MODULE, |
| 1396 | .event = ds_event, |
| 1397 | .requery = pcmcia_bus_rescan, |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1398 | .suspend = pcmcia_bus_suspend, |
| 1399 | .resume = pcmcia_bus_resume, |
Dominik Brodowski | 90c6cdd | 2005-06-27 16:28:49 -0700 | [diff] [blame] | 1400 | }; |
| 1401 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1402 | static int __devinit pcmcia_bus_add_socket(struct device *dev, |
Dmitry Torokhov | d8539d8 | 2005-09-15 02:01:36 -0500 | [diff] [blame] | 1403 | struct class_interface *class_intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1405 | struct pcmcia_socket *socket = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | int ret; |
| 1407 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1408 | socket = pcmcia_get_socket(socket); |
| 1409 | if (!socket) { |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 1410 | dev_printk(KERN_ERR, dev, |
| 1411 | "PCMCIA obtaining reference to socket failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | return -ENODEV; |
| 1413 | } |
| 1414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | /* |
| 1416 | * Ugly. But we want to wait for the socket threads to have started up. |
| 1417 | * We really should let the drivers themselves drive some of this.. |
| 1418 | */ |
| 1419 | msleep(250); |
| 1420 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 1421 | #ifdef CONFIG_PCMCIA_IOCTL |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1422 | init_waitqueue_head(&socket->queue); |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 1423 | #endif |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1424 | INIT_LIST_HEAD(&socket->devices_list); |
David Howells | 4796b71 | 2006-12-06 15:01:18 +0000 | [diff] [blame] | 1425 | INIT_WORK(&socket->device_add, pcmcia_delayed_add_device); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1426 | memset(&socket->pcmcia_state, 0, sizeof(u8)); |
| 1427 | socket->device_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
Dominik Brodowski | 90c6cdd | 2005-06-27 16:28:49 -0700 | [diff] [blame] | 1429 | ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | if (ret) { |
Dominik Brodowski | ac449d6 | 2008-08-02 18:33:56 +0200 | [diff] [blame] | 1431 | dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n"); |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1432 | pcmcia_put_socket(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | return (ret); |
| 1434 | } |
| 1435 | |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1439 | static void pcmcia_bus_remove_socket(struct device *dev, |
Dmitry Torokhov | d8539d8 | 2005-09-15 02:01:36 -0500 | [diff] [blame] | 1440 | struct class_interface *class_intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1442 | struct pcmcia_socket *socket = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1444 | if (!socket) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | return; |
| 1446 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1447 | socket->pcmcia_state.dead = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | pccard_register_pcmcia(socket, NULL); |
| 1449 | |
Daniel Ritz | dfbc9e9 | 2006-11-18 22:19:34 -0800 | [diff] [blame] | 1450 | /* unregister any unbound devices */ |
Daniel Ritz | 8e4d9dc | 2006-11-25 11:09:17 -0800 | [diff] [blame] | 1451 | mutex_lock(&socket->skt_mutex); |
Daniel Ritz | dfbc9e9 | 2006-11-18 22:19:34 -0800 | [diff] [blame] | 1452 | pcmcia_card_remove(socket, NULL); |
Daniel Ritz | 8e4d9dc | 2006-11-25 11:09:17 -0800 | [diff] [blame] | 1453 | mutex_unlock(&socket->skt_mutex); |
Daniel Ritz | dfbc9e9 | 2006-11-18 22:19:34 -0800 | [diff] [blame] | 1454 | |
Dominik Brodowski | dc10949 | 2005-06-27 16:28:50 -0700 | [diff] [blame] | 1455 | pcmcia_put_socket(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
| 1457 | return; |
| 1458 | } |
| 1459 | |
| 1460 | |
| 1461 | /* the pcmcia_bus_interface is used to handle pcmcia socket devices */ |
Sam Ravnborg | ed49f5d | 2008-05-01 04:34:50 -0700 | [diff] [blame] | 1462 | static struct class_interface pcmcia_bus_interface __refdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | .class = &pcmcia_socket_class, |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 1464 | .add_dev = &pcmcia_bus_add_socket, |
| 1465 | .remove_dev = &pcmcia_bus_remove_socket, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | }; |
| 1467 | |
| 1468 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 1469 | struct bus_type pcmcia_bus_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | .name = "pcmcia", |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1471 | .uevent = pcmcia_bus_uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | .match = pcmcia_bus_match, |
| 1473 | .dev_attrs = pcmcia_dev_attrs, |
Russell King | 1d0baa3 | 2006-01-05 14:40:58 +0000 | [diff] [blame] | 1474 | .probe = pcmcia_device_probe, |
| 1475 | .remove = pcmcia_device_remove, |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 1476 | .suspend = pcmcia_dev_suspend, |
| 1477 | .resume = pcmcia_dev_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
| 1480 | |
| 1481 | static int __init init_pcmcia_bus(void) |
| 1482 | { |
Randy Dunlap | ace7d47 | 2006-10-20 14:44:12 -0700 | [diff] [blame] | 1483 | int ret; |
| 1484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | spin_lock_init(&pcmcia_dev_list_lock); |
| 1486 | |
Randy Dunlap | ace7d47 | 2006-10-20 14:44:12 -0700 | [diff] [blame] | 1487 | ret = bus_register(&pcmcia_bus_type); |
| 1488 | if (ret < 0) { |
| 1489 | printk(KERN_WARNING "pcmcia: bus_register error: %d\n", ret); |
| 1490 | return ret; |
| 1491 | } |
| 1492 | ret = class_interface_register(&pcmcia_bus_interface); |
| 1493 | if (ret < 0) { |
| 1494 | printk(KERN_WARNING |
| 1495 | "pcmcia: class_interface_register error: %d\n", ret); |
| 1496 | bus_unregister(&pcmcia_bus_type); |
| 1497 | return ret; |
| 1498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 1500 | pcmcia_setup_ioctl(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
| 1502 | return 0; |
| 1503 | } |
| 1504 | fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that |
| 1505 | * pcmcia_socket_class is already registered */ |
| 1506 | |
| 1507 | |
| 1508 | static void __exit exit_pcmcia_bus(void) |
| 1509 | { |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 1510 | pcmcia_cleanup_ioctl(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
Dominik Brodowski | e7a480d | 2005-06-27 16:28:47 -0700 | [diff] [blame] | 1512 | class_interface_unregister(&pcmcia_bus_interface); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
| 1514 | bus_unregister(&pcmcia_bus_type); |
| 1515 | } |
| 1516 | module_exit(exit_pcmcia_bus); |
| 1517 | |
| 1518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | MODULE_ALIAS("ds"); |