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