Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * cs.c -- Kernel Card Services - core services |
| 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 |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/string.h> |
| 20 | #include <linux/major.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/timer.h> |
| 26 | #include <linux/ioport.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/device.h> |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 30 | #include <linux/kthread.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 31 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/system.h> |
| 33 | #include <asm/irq.h> |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <pcmcia/cs_types.h> |
| 36 | #include <pcmcia/ss.h> |
| 37 | #include <pcmcia/cs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <pcmcia/cistpl.h> |
| 39 | #include <pcmcia/cisreg.h> |
| 40 | #include <pcmcia/ds.h> |
| 41 | #include "cs_internal.h" |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* Module parameters */ |
| 45 | |
| 46 | MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 47 | MODULE_DESCRIPTION("Linux Kernel Card Services"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | MODULE_LICENSE("GPL"); |
| 49 | |
| 50 | #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444) |
| 51 | |
| 52 | INT_MODULE_PARM(setup_delay, 10); /* centiseconds */ |
| 53 | INT_MODULE_PARM(resume_delay, 20); /* centiseconds */ |
| 54 | INT_MODULE_PARM(shutdown_delay, 3); /* centiseconds */ |
| 55 | INT_MODULE_PARM(vcc_settle, 40); /* centiseconds */ |
| 56 | INT_MODULE_PARM(reset_time, 10); /* usecs */ |
| 57 | INT_MODULE_PARM(unreset_delay, 10); /* centiseconds */ |
| 58 | INT_MODULE_PARM(unreset_check, 10); /* centiseconds */ |
| 59 | INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */ |
| 60 | |
| 61 | /* Access speed for attribute memory windows */ |
| 62 | INT_MODULE_PARM(cis_speed, 300); /* ns */ |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | socket_state_t dead_socket = { |
| 66 | .csc_mask = SS_DETECT, |
| 67 | }; |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 68 | EXPORT_SYMBOL(dead_socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | |
| 71 | /* List of all sockets, protected by a rwsem */ |
| 72 | LIST_HEAD(pcmcia_socket_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | EXPORT_SYMBOL(pcmcia_socket_list); |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 74 | |
| 75 | DECLARE_RWSEM(pcmcia_socket_list_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | EXPORT_SYMBOL(pcmcia_socket_list_rwsem); |
| 77 | |
| 78 | |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 79 | /* |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 80 | * Low-level PCMCIA socket drivers need to register with the PCCard |
| 81 | * core using pcmcia_register_socket. |
| 82 | * |
| 83 | * socket drivers are expected to use the following callbacks in their |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * .drv struct: |
| 85 | * - pcmcia_socket_dev_suspend |
| 86 | * - pcmcia_socket_dev_resume |
| 87 | * These functions check for the appropriate struct pcmcia_soket arrays, |
| 88 | * and pass them to the low-level functions pcmcia_{suspend,resume}_socket |
| 89 | */ |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 90 | static int socket_early_resume(struct pcmcia_socket *skt); |
| 91 | static int socket_late_resume(struct pcmcia_socket *skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | static int socket_resume(struct pcmcia_socket *skt); |
| 93 | static int socket_suspend(struct pcmcia_socket *skt); |
| 94 | |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 95 | static void pcmcia_socket_dev_run(struct device *dev, |
| 96 | int (*cb)(struct pcmcia_socket *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 98 | struct pcmcia_socket *socket; |
| 99 | |
| 100 | down_read(&pcmcia_socket_list_rwsem); |
| 101 | list_for_each_entry(socket, &pcmcia_socket_list, socket_list) { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 102 | if (socket->dev.parent != dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | continue; |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 104 | mutex_lock(&socket->skt_mutex); |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 105 | cb(socket); |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 106 | mutex_unlock(&socket->skt_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | up_read(&pcmcia_socket_list_rwsem); |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 111 | int pcmcia_socket_dev_suspend(struct device *dev) |
| 112 | { |
| 113 | pcmcia_socket_dev_run(dev, socket_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | EXPORT_SYMBOL(pcmcia_socket_dev_suspend); |
| 117 | |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 118 | void pcmcia_socket_dev_early_resume(struct device *dev) |
| 119 | { |
| 120 | pcmcia_socket_dev_run(dev, socket_early_resume); |
| 121 | } |
| 122 | EXPORT_SYMBOL(pcmcia_socket_dev_early_resume); |
| 123 | |
| 124 | void pcmcia_socket_dev_late_resume(struct device *dev) |
| 125 | { |
| 126 | pcmcia_socket_dev_run(dev, socket_late_resume); |
| 127 | } |
| 128 | EXPORT_SYMBOL(pcmcia_socket_dev_late_resume); |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | int pcmcia_socket_dev_resume(struct device *dev) |
| 131 | { |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 132 | pcmcia_socket_dev_run(dev, socket_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | EXPORT_SYMBOL(pcmcia_socket_dev_resume); |
| 136 | |
| 137 | |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 138 | struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 140 | struct device *dev = get_device(&skt->dev); |
| 141 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return NULL; |
Dominik Brodowski | 593f010b | 2010-01-02 22:59:15 +0100 | [diff] [blame] | 143 | return dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | EXPORT_SYMBOL(pcmcia_get_socket); |
| 146 | |
| 147 | |
| 148 | void pcmcia_put_socket(struct pcmcia_socket *skt) |
| 149 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 150 | put_device(&skt->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | EXPORT_SYMBOL(pcmcia_put_socket); |
| 153 | |
| 154 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 155 | static void pcmcia_release_socket(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 157 | struct pcmcia_socket *socket = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | complete(&socket->socket_released); |
| 160 | } |
| 161 | |
| 162 | static int pccardd(void *__skt); |
| 163 | |
| 164 | /** |
| 165 | * pcmcia_register_socket - add a new pcmcia socket device |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 166 | * @socket: the &socket to register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
| 168 | int pcmcia_register_socket(struct pcmcia_socket *socket) |
| 169 | { |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 170 | struct task_struct *tsk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | int ret; |
| 172 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 173 | if (!socket || !socket->ops || !socket->dev.parent || !socket->resource_ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return -EINVAL; |
| 175 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 176 | dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* try to obtain a socket number [yes, it gets ugly if we |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 179 | * register more than 2^sizeof(unsigned int) pcmcia |
| 180 | * sockets... but the socket number is deprecated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | * anyways, so I don't care] */ |
| 182 | down_write(&pcmcia_socket_list_rwsem); |
| 183 | if (list_empty(&pcmcia_socket_list)) |
| 184 | socket->sock = 0; |
| 185 | else { |
| 186 | unsigned int found, i = 1; |
| 187 | struct pcmcia_socket *tmp; |
| 188 | do { |
| 189 | found = 1; |
| 190 | list_for_each_entry(tmp, &pcmcia_socket_list, socket_list) { |
| 191 | if (tmp->sock == i) |
| 192 | found = 0; |
| 193 | } |
| 194 | i++; |
| 195 | } while (!found); |
| 196 | socket->sock = i - 1; |
| 197 | } |
| 198 | list_add_tail(&socket->socket_list, &pcmcia_socket_list); |
| 199 | up_write(&pcmcia_socket_list_rwsem); |
| 200 | |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 201 | #ifndef CONFIG_CARDBUS |
| 202 | /* |
| 203 | * If we do not support Cardbus, ensure that |
| 204 | * the Cardbus socket capability is disabled. |
| 205 | */ |
| 206 | socket->features &= ~SS_CAP_CARDBUS; |
| 207 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* set proper values in socket->dev */ |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 210 | dev_set_drvdata(&socket->dev, socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | socket->dev.class = &pcmcia_socket_class; |
Kay Sievers | 2509698 | 2008-11-01 11:46:06 +0100 | [diff] [blame] | 212 | dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | /* base address = 0, map = 0 */ |
| 215 | socket->cis_mem.flags = 0; |
| 216 | socket->cis_mem.speed = cis_speed; |
| 217 | |
| 218 | INIT_LIST_HEAD(&socket->cis_cache); |
| 219 | |
| 220 | init_completion(&socket->socket_released); |
| 221 | init_completion(&socket->thread_done); |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 222 | mutex_init(&socket->skt_mutex); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 223 | mutex_init(&socket->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | spin_lock_init(&socket->thread_lock); |
| 225 | |
Dominik Brodowski | b176945 | 2008-11-09 21:47:47 +0100 | [diff] [blame] | 226 | if (socket->resource_ops->init) { |
Dominik Brodowski | cfe5d80 | 2010-01-17 19:31:45 +0100 | [diff] [blame] | 227 | mutex_lock(&socket->ops_mutex); |
Dominik Brodowski | b176945 | 2008-11-09 21:47:47 +0100 | [diff] [blame] | 228 | ret = socket->resource_ops->init(socket); |
Dominik Brodowski | cfe5d80 | 2010-01-17 19:31:45 +0100 | [diff] [blame] | 229 | mutex_unlock(&socket->ops_mutex); |
Dominik Brodowski | b176945 | 2008-11-09 21:47:47 +0100 | [diff] [blame] | 230 | if (ret) |
| 231 | goto err; |
| 232 | } |
| 233 | |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 234 | tsk = kthread_run(pccardd, socket, "pccardd"); |
| 235 | if (IS_ERR(tsk)) { |
| 236 | ret = PTR_ERR(tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | goto err; |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | wait_for_completion(&socket->thread_done); |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 241 | if (!socket->thread) { |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 242 | dev_printk(KERN_WARNING, &socket->dev, |
| 243 | "PCMCIA: warning: socket thread did not start\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return -EIO; |
| 245 | } |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | pcmcia_parse_events(socket, SS_DETECT); |
| 248 | |
Dominik Brodowski | 638bba5 | 2009-11-07 12:26:17 +0100 | [diff] [blame] | 249 | /* |
| 250 | * Let's try to get the PCMCIA module for 16-bit PCMCIA support. |
| 251 | * If it fails, it doesn't matter -- we still have 32-bit CardBus |
| 252 | * support to offer, so this is not a failure mode. |
| 253 | */ |
| 254 | request_module_nowait("pcmcia"); |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return 0; |
| 257 | |
| 258 | err: |
| 259 | down_write(&pcmcia_socket_list_rwsem); |
| 260 | list_del(&socket->socket_list); |
| 261 | up_write(&pcmcia_socket_list_rwsem); |
| 262 | return ret; |
| 263 | } /* pcmcia_register_socket */ |
| 264 | EXPORT_SYMBOL(pcmcia_register_socket); |
| 265 | |
| 266 | |
| 267 | /** |
| 268 | * pcmcia_unregister_socket - remove a pcmcia socket device |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 269 | * @socket: the &socket to unregister |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | */ |
| 271 | void pcmcia_unregister_socket(struct pcmcia_socket *socket) |
| 272 | { |
| 273 | if (!socket) |
| 274 | return; |
| 275 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 276 | dev_dbg(&socket->dev, "pcmcia_unregister_socket(0x%p)\n", socket->ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Christoph Hellwig | 0b40209 | 2007-04-22 13:55:36 +0100 | [diff] [blame] | 278 | if (socket->thread) |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 279 | kthread_stop(socket->thread); |
Christoph Hellwig | 0b40209 | 2007-04-22 13:55:36 +0100 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* remove from our own list */ |
| 282 | down_write(&pcmcia_socket_list_rwsem); |
| 283 | list_del(&socket->socket_list); |
| 284 | up_write(&pcmcia_socket_list_rwsem); |
| 285 | |
| 286 | /* wait for sysfs to drop all references */ |
Dominik Brodowski | cfe5d80 | 2010-01-17 19:31:45 +0100 | [diff] [blame] | 287 | if (socket->resource_ops->exit) { |
| 288 | mutex_lock(&socket->ops_mutex); |
Dominik Brodowski | 385ee87 | 2010-01-06 11:23:58 +0100 | [diff] [blame] | 289 | socket->resource_ops->exit(socket); |
Dominik Brodowski | cfe5d80 | 2010-01-17 19:31:45 +0100 | [diff] [blame] | 290 | mutex_unlock(&socket->ops_mutex); |
| 291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | wait_for_completion(&socket->socket_released); |
| 293 | } /* pcmcia_unregister_socket */ |
| 294 | EXPORT_SYMBOL(pcmcia_unregister_socket); |
| 295 | |
| 296 | |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 297 | struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
| 299 | struct pcmcia_socket *s; |
| 300 | |
| 301 | down_read(&pcmcia_socket_list_rwsem); |
| 302 | list_for_each_entry(s, &pcmcia_socket_list, socket_list) |
| 303 | if (s->sock == nr) { |
| 304 | up_read(&pcmcia_socket_list_rwsem); |
| 305 | return s; |
| 306 | } |
| 307 | up_read(&pcmcia_socket_list_rwsem); |
| 308 | |
| 309 | return NULL; |
| 310 | |
| 311 | } |
| 312 | EXPORT_SYMBOL(pcmcia_get_socket_by_nr); |
| 313 | |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 314 | /* |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 315 | * The central event handler. Send_event() sends an event to the |
| 316 | * 16-bit subsystem, which then calls the relevant device drivers. |
| 317 | * Parse_events() interprets the event bits from |
| 318 | * a card status change report. Do_shutdown() handles the high |
| 319 | * priority stuff associated with a card removal. |
| 320 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | /* NOTE: send_event needs to be called with skt->sem held. */ |
| 323 | |
| 324 | static int send_event(struct pcmcia_socket *s, event_t event, int priority) |
| 325 | { |
| 326 | int ret; |
| 327 | |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 328 | if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return 0; |
| 330 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 331 | dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | event, priority, s->callback); |
| 333 | |
| 334 | if (!s->callback) |
| 335 | return 0; |
| 336 | if (!try_module_get(s->callback->owner)) |
| 337 | return 0; |
| 338 | |
| 339 | ret = s->callback->event(s, event, priority); |
| 340 | |
| 341 | module_put(s->callback->owner); |
| 342 | |
| 343 | return ret; |
| 344 | } |
| 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | static int socket_reset(struct pcmcia_socket *skt) |
| 347 | { |
| 348 | int status, i; |
| 349 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 350 | dev_dbg(&skt->dev, "reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | skt->socket.flags |= SS_OUTPUT_ENA | SS_RESET; |
| 353 | skt->ops->set_socket(skt, &skt->socket); |
| 354 | udelay((long)reset_time); |
| 355 | |
| 356 | skt->socket.flags &= ~SS_RESET; |
| 357 | skt->ops->set_socket(skt, &skt->socket); |
| 358 | |
| 359 | msleep(unreset_delay * 10); |
| 360 | for (i = 0; i < unreset_limit; i++) { |
| 361 | skt->ops->get_status(skt, &status); |
| 362 | |
| 363 | if (!(status & SS_DETECT)) |
Dominik Brodowski | 3939c1ef | 2008-08-03 11:10:56 +0200 | [diff] [blame] | 364 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | if (status & SS_READY) |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 367 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | msleep(unreset_check * 10); |
| 370 | } |
| 371 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 372 | dev_printk(KERN_ERR, &skt->dev, "time out after reset.\n"); |
Dominik Brodowski | 8567142 | 2008-08-03 11:15:45 +0200 | [diff] [blame] | 373 | return -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Randy Dunlap | 7818786 | 2007-12-10 15:49:22 -0800 | [diff] [blame] | 376 | /* |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 377 | * socket_setup() and socket_shutdown() are called by the main event handler |
| 378 | * when card insertion and removal events are received. |
| 379 | * socket_setup() turns on socket power and resets the socket, in two stages. |
| 380 | * socket_shutdown() unconfigures a socket and turns off socket power. |
| 381 | */ |
| 382 | static void socket_shutdown(struct pcmcia_socket *s) |
| 383 | { |
| 384 | int status; |
| 385 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 386 | dev_dbg(&s->dev, "shutdown\n"); |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 387 | |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 388 | send_event(s, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 389 | |
| 390 | mutex_lock(&s->ops_mutex); |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 391 | s->state &= SOCKET_INUSE | SOCKET_PRESENT; |
| 392 | msleep(shutdown_delay * 10); |
| 393 | s->state &= SOCKET_INUSE; |
| 394 | |
| 395 | /* Blank out the socket state */ |
| 396 | s->socket = dead_socket; |
| 397 | s->ops->init(s); |
| 398 | s->ops->set_socket(s, &s->socket); |
| 399 | s->irq.AssignedIRQ = s->irq.Config = 0; |
| 400 | s->lock_count = 0; |
Dominik Brodowski | 904e377 | 2010-01-02 12:28:04 +0100 | [diff] [blame] | 401 | kfree(s->fake_cis); |
| 402 | s->fake_cis = NULL; |
Dominik Brodowski | c3bfc96 | 2010-01-18 08:43:39 +0100 | [diff] [blame] | 403 | s->functions = 0; |
| 404 | |
| 405 | /* From here on we can be sure that only we (that is, the |
| 406 | * pccardd thread) accesses this socket, and all (16-bit) |
| 407 | * PCMCIA interactions are gone. Therefore, release |
| 408 | * ops_mutex so that we don't get a sysfs-related lockdep |
| 409 | * warning. |
| 410 | */ |
| 411 | mutex_unlock(&s->ops_mutex); |
| 412 | |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 413 | #ifdef CONFIG_CARDBUS |
| 414 | cb_free(s); |
| 415 | #endif |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 416 | |
Daniel Ritz | afb2c16 | 2007-07-31 00:38:08 -0700 | [diff] [blame] | 417 | /* give socket some time to power down */ |
| 418 | msleep(100); |
| 419 | |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 420 | s->ops->get_status(s, &status); |
| 421 | if (status & SS_POWERON) { |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 422 | dev_printk(KERN_ERR, &s->dev, |
| 423 | "*** DANGER *** unable to remove socket power\n"); |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Dominik Brodowski | 3970dd8 | 2010-01-02 23:19:45 +0100 | [diff] [blame] | 426 | s->state &= ~SOCKET_INUSE; |
Daniel Ritz | 6e49388 | 2005-12-30 15:12:35 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | static int socket_setup(struct pcmcia_socket *skt, int initial_delay) |
| 430 | { |
| 431 | int status, i; |
| 432 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 433 | dev_dbg(&skt->dev, "setup\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | skt->ops->get_status(skt, &status); |
| 436 | if (!(status & SS_DETECT)) |
Dominik Brodowski | 3939c1ef | 2008-08-03 11:10:56 +0200 | [diff] [blame] | 437 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | msleep(initial_delay * 10); |
| 440 | |
| 441 | for (i = 0; i < 100; i++) { |
| 442 | skt->ops->get_status(skt, &status); |
| 443 | if (!(status & SS_DETECT)) |
Dominik Brodowski | 3939c1ef | 2008-08-03 11:10:56 +0200 | [diff] [blame] | 444 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
| 446 | if (!(status & SS_PENDING)) |
| 447 | break; |
| 448 | |
| 449 | msleep(100); |
| 450 | } |
| 451 | |
| 452 | if (status & SS_PENDING) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 453 | dev_printk(KERN_ERR, &skt->dev, |
| 454 | "voltage interrogation timed out.\n"); |
Dominik Brodowski | 8567142 | 2008-08-03 11:15:45 +0200 | [diff] [blame] | 455 | return -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | if (status & SS_CARDBUS) { |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 459 | if (!(skt->features & SS_CAP_CARDBUS)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 460 | dev_printk(KERN_ERR, &skt->dev, |
| 461 | "cardbus cards are not supported.\n"); |
Dominik Brodowski | 610e237 | 2008-08-03 11:58:53 +0200 | [diff] [blame] | 462 | return -EINVAL; |
Russell King | 5bc6b68 | 2005-07-07 17:59:07 -0700 | [diff] [blame] | 463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | skt->state |= SOCKET_CARDBUS; |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 465 | } else |
| 466 | skt->state &= ~SOCKET_CARDBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | /* |
| 469 | * Decode the card voltage requirements, and apply power to the card. |
| 470 | */ |
| 471 | if (status & SS_3VCARD) |
| 472 | skt->socket.Vcc = skt->socket.Vpp = 33; |
| 473 | else if (!(status & SS_XVCARD)) |
| 474 | skt->socket.Vcc = skt->socket.Vpp = 50; |
| 475 | else { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 476 | dev_printk(KERN_ERR, &skt->dev, "unsupported voltage key.\n"); |
Dominik Brodowski | 610e237 | 2008-08-03 11:58:53 +0200 | [diff] [blame] | 477 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 479 | |
| 480 | if (skt->power_hook) |
| 481 | skt->power_hook(skt, HOOK_POWER_PRE); |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | skt->socket.flags = 0; |
| 484 | skt->ops->set_socket(skt, &skt->socket); |
| 485 | |
| 486 | /* |
| 487 | * Wait "vcc_settle" for the supply to stabilise. |
| 488 | */ |
| 489 | msleep(vcc_settle * 10); |
| 490 | |
| 491 | skt->ops->get_status(skt, &status); |
| 492 | if (!(status & SS_POWERON)) { |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 493 | dev_printk(KERN_ERR, &skt->dev, "unable to apply power.\n"); |
Dominik Brodowski | 610e237 | 2008-08-03 11:58:53 +0200 | [diff] [blame] | 494 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Daniel Ritz | fa912bc | 2005-06-23 00:10:12 -0700 | [diff] [blame] | 497 | status = socket_reset(skt); |
| 498 | |
| 499 | if (skt->power_hook) |
| 500 | skt->power_hook(skt, HOOK_POWER_POST); |
| 501 | |
| 502 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Handle card insertion. Setup the socket, reset the card, |
| 507 | * and then tell the rest of PCMCIA that a card is present. |
| 508 | */ |
| 509 | static int socket_insert(struct pcmcia_socket *skt) |
| 510 | { |
| 511 | int ret; |
| 512 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 513 | dev_dbg(&skt->dev, "insert\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 515 | mutex_lock(&skt->ops_mutex); |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 516 | if (skt->state & SOCKET_INUSE) { |
| 517 | mutex_unlock(&skt->ops_mutex); |
| 518 | return -EINVAL; |
| 519 | } |
Dominik Brodowski | 3970dd8 | 2010-01-02 23:19:45 +0100 | [diff] [blame] | 520 | skt->state |= SOCKET_INUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | ret = socket_setup(skt, setup_delay); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 523 | if (ret == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | skt->state |= SOCKET_PRESENT; |
Dominik Brodowski | 807277c | 2005-11-12 23:34:06 +0100 | [diff] [blame] | 525 | |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 526 | dev_printk(KERN_NOTICE, &skt->dev, |
| 527 | "pccard: %s card inserted into slot %d\n", |
| 528 | (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA", |
| 529 | skt->sock); |
Dominik Brodowski | 807277c | 2005-11-12 23:34:06 +0100 | [diff] [blame] | 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #ifdef CONFIG_CARDBUS |
| 532 | if (skt->state & SOCKET_CARDBUS) { |
| 533 | cb_alloc(skt); |
| 534 | skt->state |= SOCKET_CARDBUS_CONFIG; |
| 535 | } |
| 536 | #endif |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 537 | dev_dbg(&skt->dev, "insert done\n"); |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 538 | mutex_unlock(&skt->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); |
| 541 | } else { |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 542 | mutex_unlock(&skt->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | socket_shutdown(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | return ret; |
| 547 | } |
| 548 | |
| 549 | static int socket_suspend(struct pcmcia_socket *skt) |
| 550 | { |
| 551 | if (skt->state & SOCKET_SUSPEND) |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 552 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 554 | mutex_lock(&skt->ops_mutex); |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 555 | skt->suspended_state = skt->state; |
| 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); |
| 558 | skt->socket = dead_socket; |
| 559 | skt->ops->set_socket(skt, &skt->socket); |
| 560 | if (skt->ops->suspend) |
| 561 | skt->ops->suspend(skt); |
| 562 | skt->state |= SOCKET_SUSPEND; |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 563 | mutex_unlock(&skt->ops_mutex); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 564 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 567 | static int socket_early_resume(struct pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 569 | mutex_lock(&skt->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | skt->socket = dead_socket; |
| 571 | skt->ops->init(skt); |
| 572 | skt->ops->set_socket(skt, &skt->socket); |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 573 | if (skt->state & SOCKET_PRESENT) |
| 574 | skt->resume_status = socket_setup(skt, resume_delay); |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 575 | mutex_unlock(&skt->ops_mutex); |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 576 | return 0; |
| 577 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 579 | static int socket_late_resume(struct pcmcia_socket *skt) |
| 580 | { |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 581 | mutex_lock(&skt->ops_mutex); |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 582 | skt->state &= ~SOCKET_SUSPEND; |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 583 | mutex_unlock(&skt->ops_mutex); |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 584 | |
| 585 | if (!(skt->state & SOCKET_PRESENT)) |
| 586 | return socket_insert(skt); |
| 587 | |
| 588 | if (skt->resume_status) { |
| 589 | socket_shutdown(skt); |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | if (skt->suspended_state != skt->state) { |
| 594 | dev_dbg(&skt->dev, |
| 595 | "suspend state 0x%x != resume state 0x%x\n", |
| 596 | skt->suspended_state, skt->state); |
| 597 | |
| 598 | socket_shutdown(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | return socket_insert(skt); |
| 600 | } |
| 601 | |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 602 | #ifdef CONFIG_CARDBUS |
| 603 | if (skt->state & SOCKET_CARDBUS) { |
| 604 | /* We can't be sure the CardBus card is the same |
| 605 | * as the one previously inserted. Therefore, remove |
| 606 | * and re-add... */ |
| 607 | cb_free(skt); |
| 608 | cb_alloc(skt); |
| 609 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 611 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Dominik Brodowski | 88b060d | 2010-01-02 14:14:23 +0100 | [diff] [blame] | 613 | send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 614 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Rafael J. Wysocki | 9905d1b | 2009-11-03 10:54:58 +0100 | [diff] [blame] | 617 | /* |
| 618 | * Resume a socket. If a card is present, verify its CIS against |
| 619 | * our cached copy. If they are different, the card has been |
| 620 | * replaced, and we need to tell the drivers. |
| 621 | */ |
| 622 | static int socket_resume(struct pcmcia_socket *skt) |
| 623 | { |
| 624 | if (!(skt->state & SOCKET_SUSPEND)) |
| 625 | return -EBUSY; |
| 626 | |
| 627 | socket_early_resume(skt); |
| 628 | return socket_late_resume(skt); |
| 629 | } |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | static void socket_remove(struct pcmcia_socket *skt) |
| 632 | { |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 633 | dev_printk(KERN_NOTICE, &skt->dev, |
| 634 | "pccard: card ejected from slot %d\n", skt->sock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | socket_shutdown(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /* |
| 639 | * Process a socket card detect status change. |
| 640 | * |
| 641 | * If we don't have a card already present, delay the detect event for |
| 642 | * about 20ms (to be on the safe side) before reading the socket status. |
| 643 | * |
| 644 | * Some i82365-based systems send multiple SS_DETECT events during card |
| 645 | * insertion, and the "card present" status bit seems to bounce. This |
| 646 | * will probably be true with GPIO-based card detection systems after |
| 647 | * the product has aged. |
| 648 | */ |
| 649 | static void socket_detect_change(struct pcmcia_socket *skt) |
| 650 | { |
| 651 | if (!(skt->state & SOCKET_SUSPEND)) { |
| 652 | int status; |
| 653 | |
| 654 | if (!(skt->state & SOCKET_PRESENT)) |
| 655 | msleep(20); |
| 656 | |
| 657 | skt->ops->get_status(skt, &status); |
| 658 | if ((skt->state & SOCKET_PRESENT) && |
| 659 | !(status & SS_DETECT)) |
| 660 | socket_remove(skt); |
| 661 | if (!(skt->state & SOCKET_PRESENT) && |
| 662 | (status & SS_DETECT)) |
| 663 | socket_insert(skt); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | static int pccardd(void *__skt) |
| 668 | { |
| 669 | struct pcmcia_socket *skt = __skt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | int ret; |
| 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | skt->thread = current; |
| 673 | skt->socket = dead_socket; |
| 674 | skt->ops->init(skt); |
| 675 | skt->ops->set_socket(skt, &skt->socket); |
| 676 | |
| 677 | /* register with the device core */ |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 678 | ret = device_register(&skt->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (ret) { |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 680 | dev_printk(KERN_WARNING, &skt->dev, |
| 681 | "PCMCIA: unable to register socket\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | skt->thread = NULL; |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 683 | complete(&skt->thread_done); |
| 684 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 686 | ret = pccard_sysfs_add_socket(&skt->dev); |
| 687 | if (ret) |
| 688 | dev_warn(&skt->dev, "err %d adding socket attributes\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Daniel Ritz | bf4de6f | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 690 | complete(&skt->thread_done); |
| 691 | |
Dominik Brodowski | d801c140 | 2010-02-17 11:02:22 +0100 | [diff] [blame] | 692 | /* wait for userspace to catch up */ |
| 693 | msleep(250); |
| 694 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 695 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | for (;;) { |
| 697 | unsigned long flags; |
| 698 | unsigned int events; |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 699 | unsigned int sysfs_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | set_current_state(TASK_INTERRUPTIBLE); |
| 702 | |
| 703 | spin_lock_irqsave(&skt->thread_lock, flags); |
| 704 | events = skt->thread_events; |
| 705 | skt->thread_events = 0; |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 706 | sysfs_events = skt->sysfs_events; |
| 707 | skt->sysfs_events = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | spin_unlock_irqrestore(&skt->thread_lock, flags); |
| 709 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 710 | mutex_lock(&skt->skt_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if (events) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | if (events & SS_DETECT) |
| 713 | socket_detect_change(skt); |
| 714 | if (events & SS_BATDEAD) |
| 715 | send_event(skt, CS_EVENT_BATTERY_DEAD, CS_EVENT_PRI_LOW); |
| 716 | if (events & SS_BATWARN) |
| 717 | send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); |
| 718 | if (events & SS_READY) |
| 719 | send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 722 | if (sysfs_events) { |
| 723 | if (sysfs_events & PCMCIA_UEVENT_EJECT) |
| 724 | socket_remove(skt); |
| 725 | if (sysfs_events & PCMCIA_UEVENT_INSERT) |
| 726 | socket_insert(skt); |
| 727 | if ((sysfs_events & PCMCIA_UEVENT_RESUME) && |
| 728 | !(skt->state & SOCKET_CARDBUS)) { |
| 729 | ret = socket_resume(skt); |
| 730 | if (!ret && skt->callback) |
| 731 | skt->callback->resume(skt); |
| 732 | } |
| 733 | if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) && |
| 734 | !(skt->state & SOCKET_CARDBUS)) { |
| 735 | if (skt->callback) |
| 736 | ret = skt->callback->suspend(skt); |
| 737 | else |
| 738 | ret = 0; |
| 739 | if (!ret) |
| 740 | socket_suspend(skt); |
| 741 | } |
Dominik Brodowski | af461fc | 2010-01-17 19:30:53 +0100 | [diff] [blame] | 742 | if ((sysfs_events & PCMCIA_UEVENT_REQUERY) && |
| 743 | !(skt->state & SOCKET_CARDBUS)) { |
| 744 | if (!ret && skt->callback) |
| 745 | skt->callback->requery(skt); |
| 746 | } |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 747 | } |
| 748 | mutex_unlock(&skt->skt_mutex); |
| 749 | |
| 750 | if (events || sysfs_events) |
| 751 | continue; |
| 752 | |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 753 | if (kthread_should_stop()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | break; |
Daniel Ritz | bf4de6f | 2005-09-09 13:03:23 -0700 | [diff] [blame] | 755 | |
| 756 | schedule(); |
| 757 | try_to_freeze(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
Steven Rostedt | 220ec02 | 2005-10-10 11:13:17 -0400 | [diff] [blame] | 759 | /* make sure we are running before we exit */ |
| 760 | set_current_state(TASK_RUNNING); |
| 761 | |
Dominik Brodowski | 3970dd8 | 2010-01-02 23:19:45 +0100 | [diff] [blame] | 762 | /* shut down socket, if a device is still present */ |
| 763 | if (skt->state & SOCKET_PRESENT) { |
| 764 | mutex_lock(&skt->skt_mutex); |
| 765 | socket_remove(skt); |
| 766 | mutex_unlock(&skt->skt_mutex); |
| 767 | } |
| 768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | /* remove from the device core */ |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 770 | pccard_sysfs_remove_socket(&skt->dev); |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 771 | device_unregister(&skt->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Serge E. Hallyn | 1da9ab7 | 2006-06-14 08:01:26 -0500 | [diff] [blame] | 773 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Yenta (at least) probes interrupts before registering the socket and |
| 778 | * starting the handler thread. |
| 779 | */ |
| 780 | void pcmcia_parse_events(struct pcmcia_socket *s, u_int events) |
| 781 | { |
Arjan van de Ven | 4b7a89a | 2006-06-30 10:31:13 +0200 | [diff] [blame] | 782 | unsigned long flags; |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 783 | dev_dbg(&s->dev, "parse_events: events %08x\n", events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | if (s->thread) { |
Arjan van de Ven | 4b7a89a | 2006-06-30 10:31:13 +0200 | [diff] [blame] | 785 | spin_lock_irqsave(&s->thread_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | s->thread_events |= events; |
Arjan van de Ven | 4b7a89a | 2006-06-30 10:31:13 +0200 | [diff] [blame] | 787 | spin_unlock_irqrestore(&s->thread_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Christoph Hellwig | 0b40209 | 2007-04-22 13:55:36 +0100 | [diff] [blame] | 789 | wake_up_process(s->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | } /* pcmcia_parse_events */ |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 792 | EXPORT_SYMBOL(pcmcia_parse_events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 794 | /** |
| 795 | * pcmcia_parse_uevents() - tell pccardd to issue manual commands |
| 796 | * @s: the PCMCIA socket we wan't to command |
| 797 | * @events: events to pass to pccardd |
| 798 | * |
| 799 | * userspace-issued insert, eject, suspend and resume commands must be |
| 800 | * handled by pccardd to avoid any sysfs-related deadlocks. Valid events |
| 801 | * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert), |
Dominik Brodowski | af461fc | 2010-01-17 19:30:53 +0100 | [diff] [blame] | 802 | * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend) |
| 803 | * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card). |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 804 | */ |
| 805 | void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events) |
| 806 | { |
| 807 | unsigned long flags; |
| 808 | dev_dbg(&s->dev, "parse_uevents: events %08x\n", events); |
| 809 | if (s->thread) { |
| 810 | spin_lock_irqsave(&s->thread_lock, flags); |
| 811 | s->sysfs_events |= events; |
| 812 | spin_unlock_irqrestore(&s->thread_lock, flags); |
| 813 | |
| 814 | wake_up_process(s->thread); |
| 815 | } |
| 816 | } |
| 817 | EXPORT_SYMBOL(pcmcia_parse_uevents); |
| 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
| 820 | /* register pcmcia_callback */ |
| 821 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) |
| 822 | { |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 823 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 825 | /* s->skt_mutex also protects s->callback */ |
| 826 | mutex_lock(&s->skt_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
| 828 | if (c) { |
| 829 | /* registration */ |
| 830 | if (s->callback) { |
| 831 | ret = -EBUSY; |
| 832 | goto err; |
| 833 | } |
| 834 | |
| 835 | s->callback = c; |
| 836 | |
| 837 | if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) |
| 838 | send_event(s, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); |
| 839 | } else |
| 840 | s->callback = NULL; |
| 841 | err: |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 842 | mutex_unlock(&s->skt_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | return ret; |
| 845 | } |
| 846 | EXPORT_SYMBOL(pccard_register_pcmcia); |
| 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 849 | /* I'm not sure which "reset" function this is supposed to use, |
| 850 | * but for now, it uses the low-level interface's reset, not the |
| 851 | * CIS register. |
| 852 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Dominik Brodowski | 994917f | 2008-08-31 15:20:26 +0200 | [diff] [blame] | 854 | int pcmcia_reset_card(struct pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
| 856 | int ret; |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 857 | |
Dominik Brodowski | d50dbec | 2009-10-23 12:51:28 +0200 | [diff] [blame] | 858 | dev_dbg(&skt->dev, "resetting socket\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 860 | mutex_lock(&skt->skt_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | do { |
| 862 | if (!(skt->state & SOCKET_PRESENT)) { |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 863 | dev_dbg(&skt->dev, "can't reset, not present\n"); |
Dominik Brodowski | 3939c1ef | 2008-08-03 11:10:56 +0200 | [diff] [blame] | 864 | ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | break; |
| 866 | } |
| 867 | if (skt->state & SOCKET_SUSPEND) { |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 868 | dev_dbg(&skt->dev, "can't reset, suspended\n"); |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 869 | ret = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | break; |
| 871 | } |
| 872 | if (skt->state & SOCKET_CARDBUS) { |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 873 | dev_dbg(&skt->dev, "can't reset, is cardbus\n"); |
Dominik Brodowski | de6405e | 2008-08-03 10:47:59 +0200 | [diff] [blame] | 874 | ret = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | break; |
| 876 | } |
| 877 | |
| 878 | ret = send_event(skt, CS_EVENT_RESET_REQUEST, CS_EVENT_PRI_LOW); |
| 879 | if (ret == 0) { |
| 880 | send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 881 | if (skt->callback) |
| 882 | skt->callback->suspend(skt); |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 883 | mutex_lock(&skt->ops_mutex); |
| 884 | ret = socket_reset(skt); |
| 885 | mutex_unlock(&skt->ops_mutex); |
| 886 | if (ret == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 888 | if (skt->callback) |
| 889 | skt->callback->resume(skt); |
| 890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 893 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } while (0); |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 895 | mutex_unlock(&skt->skt_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | return ret; |
| 898 | } /* reset_card */ |
Dominik Brodowski | 994917f | 2008-08-31 15:20:26 +0200 | [diff] [blame] | 899 | EXPORT_SYMBOL(pcmcia_reset_card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 902 | static int pcmcia_socket_uevent(struct device *dev, |
| 903 | struct kobj_uevent_env *env) |
Dominik Brodowski | 3ee1393 | 2005-06-27 16:28:05 -0700 | [diff] [blame] | 904 | { |
| 905 | struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev); |
Dominik Brodowski | 3ee1393 | 2005-06-27 16:28:05 -0700 | [diff] [blame] | 906 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 907 | if (add_uevent_var(env, "SOCKET_NO=%u", s->sock)) |
Dominik Brodowski | 3ee1393 | 2005-06-27 16:28:05 -0700 | [diff] [blame] | 908 | return -ENOMEM; |
| 909 | |
Dominik Brodowski | 3ee1393 | 2005-06-27 16:28:05 -0700 | [diff] [blame] | 910 | return 0; |
| 911 | } |
| 912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Dominik Brodowski | 378a33a | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 914 | static struct completion pcmcia_unload; |
| 915 | |
| 916 | static void pcmcia_release_socket_class(struct class *data) |
| 917 | { |
| 918 | complete(&pcmcia_unload); |
| 919 | } |
| 920 | |
| 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | struct class pcmcia_socket_class = { |
| 923 | .name = "pcmcia_socket", |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 924 | .dev_uevent = pcmcia_socket_uevent, |
| 925 | .dev_release = pcmcia_release_socket, |
Dominik Brodowski | 378a33a | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 926 | .class_release = pcmcia_release_socket_class, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | }; |
| 928 | EXPORT_SYMBOL(pcmcia_socket_class); |
| 929 | |
| 930 | |
| 931 | static int __init init_pcmcia_cs(void) |
| 932 | { |
Dominik Brodowski | 378a33a | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 933 | init_completion(&pcmcia_unload); |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 934 | return class_register(&pcmcia_socket_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static void __exit exit_pcmcia_cs(void) |
| 938 | { |
Dominik Brodowski | 33519dd | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 939 | class_unregister(&pcmcia_socket_class); |
Dominik Brodowski | 378a33a | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 940 | wait_for_completion(&pcmcia_unload); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | subsys_initcall(init_pcmcia_cs); |
| 944 | module_exit(exit_pcmcia_cs); |
| 945 | |