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