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