Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * socket_sysfs.c -- most of socket-related sysfs output |
| 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 | * (C) 2003 - 2004 Dominik Brodowski |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/string.h> |
| 16 | #include <linux/major.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/mm.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/timer.h> |
| 22 | #include <linux/ioport.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/pm.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/device.h> |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/system.h> |
| 29 | #include <asm/irq.h> |
| 30 | |
| 31 | #define IN_CARD_SERVICES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <pcmcia/cs_types.h> |
| 33 | #include <pcmcia/ss.h> |
| 34 | #include <pcmcia/cs.h> |
| 35 | #include <pcmcia/bulkmem.h> |
| 36 | #include <pcmcia/cistpl.h> |
| 37 | #include <pcmcia/cisreg.h> |
| 38 | #include <pcmcia/ds.h> |
| 39 | #include "cs_internal.h" |
| 40 | |
| 41 | #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev) |
| 42 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 43 | static ssize_t pccard_show_type(struct device *dev, struct device_attribute *attr, |
| 44 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | struct pcmcia_socket *s = to_socket(dev); |
| 47 | |
| 48 | if (!(s->state & SOCKET_PRESENT)) |
| 49 | return -ENODEV; |
Dominik Brodowski | 002dbb2 | 2005-12-08 23:50:36 +0100 | [diff] [blame] | 50 | if (s->state & SOCKET_CARDBUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | return sprintf(buf, "32-bit\n"); |
Dominik Brodowski | 002dbb2 | 2005-12-08 23:50:36 +0100 | [diff] [blame] | 52 | return sprintf(buf, "16-bit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 54 | static DEVICE_ATTR(card_type, 0444, pccard_show_type, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 56 | static ssize_t pccard_show_voltage(struct device *dev, struct device_attribute *attr, |
| 57 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | struct pcmcia_socket *s = to_socket(dev); |
| 60 | |
| 61 | if (!(s->state & SOCKET_PRESENT)) |
| 62 | return -ENODEV; |
Dominik Brodowski | 002dbb2 | 2005-12-08 23:50:36 +0100 | [diff] [blame] | 63 | if (s->socket.Vcc) |
| 64 | return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, |
| 65 | s->socket.Vcc % 10); |
| 66 | return sprintf(buf, "X.XV\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 68 | static DEVICE_ATTR(card_voltage, 0444, pccard_show_voltage, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 70 | static ssize_t pccard_show_vpp(struct device *dev, struct device_attribute *attr, |
| 71 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
| 73 | struct pcmcia_socket *s = to_socket(dev); |
| 74 | if (!(s->state & SOCKET_PRESENT)) |
| 75 | return -ENODEV; |
| 76 | return sprintf(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10); |
| 77 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 78 | static DEVICE_ATTR(card_vpp, 0444, pccard_show_vpp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 80 | static ssize_t pccard_show_vcc(struct device *dev, struct device_attribute *attr, |
| 81 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | struct pcmcia_socket *s = to_socket(dev); |
| 84 | if (!(s->state & SOCKET_PRESENT)) |
| 85 | return -ENODEV; |
| 86 | return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10); |
| 87 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 88 | static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 91 | static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, |
| 92 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | ssize_t ret; |
| 95 | struct pcmcia_socket *s = to_socket(dev); |
| 96 | |
| 97 | if (!count) |
| 98 | return -EINVAL; |
| 99 | |
| 100 | ret = pcmcia_insert_card(s); |
| 101 | |
| 102 | return ret ? ret : count; |
| 103 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 104 | static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 106 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 107 | static ssize_t pccard_show_card_pm_state(struct device *dev, |
| 108 | struct device_attribute *attr, |
| 109 | char *buf) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 110 | { |
| 111 | struct pcmcia_socket *s = to_socket(dev); |
| 112 | return sprintf(buf, "%s\n", s->state & SOCKET_SUSPEND ? "off" : "on"); |
| 113 | } |
| 114 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 115 | static ssize_t pccard_store_card_pm_state(struct device *dev, |
| 116 | struct device_attribute *attr, |
| 117 | const char *buf, size_t count) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 118 | { |
| 119 | ssize_t ret = -EINVAL; |
| 120 | struct pcmcia_socket *s = to_socket(dev); |
| 121 | |
| 122 | if (!count) |
| 123 | return -EINVAL; |
| 124 | |
| 125 | if (!(s->state & SOCKET_SUSPEND) && !strncmp(buf, "off", 3)) |
| 126 | ret = pcmcia_suspend_card(s); |
| 127 | else if ((s->state & SOCKET_SUSPEND) && !strncmp(buf, "on", 2)) |
| 128 | ret = pcmcia_resume_card(s); |
| 129 | |
| 130 | return ret ? -ENODEV : count; |
| 131 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 132 | static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state); |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 133 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 134 | static ssize_t pccard_store_eject(struct device *dev, |
| 135 | struct device_attribute *attr, |
| 136 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | ssize_t ret; |
| 139 | struct pcmcia_socket *s = to_socket(dev); |
| 140 | |
| 141 | if (!count) |
| 142 | return -EINVAL; |
| 143 | |
| 144 | ret = pcmcia_eject_card(s); |
| 145 | |
| 146 | return ret ? ret : count; |
| 147 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 148 | static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 151 | static ssize_t pccard_show_irq_mask(struct device *dev, |
| 152 | struct device_attribute *attr, |
| 153 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | struct pcmcia_socket *s = to_socket(dev); |
| 156 | return sprintf(buf, "0x%04x\n", s->irq_mask); |
| 157 | } |
| 158 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 159 | static ssize_t pccard_store_irq_mask(struct device *dev, |
| 160 | struct device_attribute *attr, |
| 161 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
| 163 | ssize_t ret; |
| 164 | struct pcmcia_socket *s = to_socket(dev); |
| 165 | u32 mask; |
| 166 | |
| 167 | if (!count) |
| 168 | return -EINVAL; |
| 169 | |
| 170 | ret = sscanf (buf, "0x%x\n", &mask); |
| 171 | |
| 172 | if (ret == 1) { |
| 173 | s->irq_mask &= mask; |
| 174 | ret = 0; |
| 175 | } |
| 176 | |
| 177 | return ret ? ret : count; |
| 178 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 179 | static DEVICE_ATTR(card_irq_mask, 0600, pccard_show_irq_mask, pccard_store_irq_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 182 | static ssize_t pccard_show_resource(struct device *dev, |
| 183 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | struct pcmcia_socket *s = to_socket(dev); |
| 186 | return sprintf(buf, "%s\n", s->resource_setup_done ? "yes" : "no"); |
| 187 | } |
| 188 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 189 | static ssize_t pccard_store_resource(struct device *dev, |
| 190 | struct device_attribute *attr, |
| 191 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | unsigned long flags; |
| 194 | struct pcmcia_socket *s = to_socket(dev); |
| 195 | |
| 196 | if (!count) |
| 197 | return -EINVAL; |
| 198 | |
| 199 | spin_lock_irqsave(&s->lock, flags); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 200 | if (!s->resource_setup_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | s->resource_setup_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | spin_unlock_irqrestore(&s->lock, flags); |
| 203 | |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 204 | mutex_lock(&s->skt_mutex); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 205 | if ((s->callback) && |
| 206 | (s->state & SOCKET_PRESENT) && |
| 207 | !(s->state & SOCKET_CARDBUS)) { |
| 208 | if (try_module_get(s->callback->owner)) { |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 209 | s->callback->requery(s, 0); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 210 | module_put(s->callback->owner); |
| 211 | } |
| 212 | } |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 213 | mutex_unlock(&s->skt_mutex); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return count; |
| 216 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 217 | static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 220 | static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count) |
| 221 | { |
| 222 | tuple_t tuple; |
| 223 | int status, i; |
| 224 | loff_t pointer = 0; |
| 225 | ssize_t ret = 0; |
| 226 | u_char *tuplebuffer; |
| 227 | u_char *tempbuffer; |
| 228 | |
| 229 | tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); |
| 230 | if (!tuplebuffer) |
| 231 | return -ENOMEM; |
| 232 | |
| 233 | tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); |
| 234 | if (!tempbuffer) { |
| 235 | ret = -ENOMEM; |
| 236 | goto free_tuple; |
| 237 | } |
| 238 | |
| 239 | memset(&tuple, 0, sizeof(tuple_t)); |
| 240 | |
| 241 | tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; |
| 242 | tuple.DesiredTuple = RETURN_FIRST_TUPLE; |
| 243 | tuple.TupleOffset = 0; |
| 244 | |
| 245 | status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); |
| 246 | while (!status) { |
| 247 | tuple.TupleData = tuplebuffer; |
| 248 | tuple.TupleDataMax = 255; |
| 249 | memset(tuplebuffer, 0, sizeof(u_char) * 255); |
| 250 | |
| 251 | status = pccard_get_tuple_data(s, &tuple); |
| 252 | if (status) |
| 253 | break; |
| 254 | |
| 255 | if (off < (pointer + 2 + tuple.TupleDataLen)) { |
| 256 | tempbuffer[0] = tuple.TupleCode & 0xff; |
| 257 | tempbuffer[1] = tuple.TupleLink & 0xff; |
| 258 | for (i = 0; i < tuple.TupleDataLen; i++) |
| 259 | tempbuffer[i + 2] = tuplebuffer[i] & 0xff; |
| 260 | |
| 261 | for (i = 0; i < (2 + tuple.TupleDataLen); i++) { |
| 262 | if (((i + pointer) >= off) && |
| 263 | (i + pointer) < (off + count)) { |
| 264 | buf[ret] = tempbuffer[i]; |
| 265 | ret++; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | pointer += 2 + tuple.TupleDataLen; |
| 271 | |
| 272 | if (pointer >= (off + count)) |
| 273 | break; |
| 274 | |
| 275 | if (tuple.TupleCode == CISTPL_END) |
| 276 | break; |
| 277 | status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); |
| 278 | } |
| 279 | |
| 280 | kfree(tempbuffer); |
| 281 | free_tuple: |
| 282 | kfree(tuplebuffer); |
| 283 | |
| 284 | return (ret); |
| 285 | } |
| 286 | |
| 287 | static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size_t count) |
| 288 | { |
| 289 | unsigned int size = 0x200; |
| 290 | |
| 291 | if (off >= size) |
| 292 | count = 0; |
| 293 | else { |
| 294 | struct pcmcia_socket *s; |
| 295 | cisinfo_t cisinfo; |
| 296 | |
| 297 | if (off + count > size) |
| 298 | count = size - off; |
| 299 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 300 | s = to_socket(container_of(kobj, struct device, kobj)); |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 301 | |
| 302 | if (!(s->state & SOCKET_PRESENT)) |
| 303 | return -ENODEV; |
| 304 | if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo)) |
| 305 | return -EIO; |
| 306 | if (!cisinfo.Chains) |
| 307 | return -ENODATA; |
| 308 | |
| 309 | count = pccard_extract_cis(s, buf, off, count); |
| 310 | } |
| 311 | |
| 312 | return (count); |
| 313 | } |
| 314 | |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 315 | static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, size_t count) |
| 316 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 317 | struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj)); |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 318 | cisdump_t *cis; |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 319 | int error; |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 320 | |
| 321 | if (off) |
| 322 | return -EINVAL; |
| 323 | |
| 324 | if (count >= 0x200) |
| 325 | return -EINVAL; |
| 326 | |
| 327 | if (!(s->state & SOCKET_PRESENT)) |
| 328 | return -ENODEV; |
| 329 | |
Dominik Brodowski | 8084b37 | 2005-12-11 21:18:26 +0100 | [diff] [blame] | 330 | cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL); |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 331 | if (!cis) |
| 332 | return -ENOMEM; |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 333 | |
| 334 | cis->Length = count + 1; |
| 335 | memcpy(cis->Data, buf, count); |
| 336 | |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 337 | error = pcmcia_replace_cis(s, cis); |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 338 | kfree(cis); |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 339 | if (error) |
| 340 | return -EIO; |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 341 | |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 342 | mutex_lock(&s->skt_mutex); |
| 343 | if ((s->callback) && (s->state & SOCKET_PRESENT) && |
| 344 | !(s->state & SOCKET_CARDBUS)) { |
| 345 | if (try_module_get(s->callback->owner)) { |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 346 | s->callback->requery(s, 1); |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 347 | module_put(s->callback->owner); |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 348 | } |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 349 | } |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 350 | mutex_unlock(&s->skt_mutex); |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 351 | |
Linus Torvalds | d834c16 | 2006-10-01 13:17:44 -0700 | [diff] [blame] | 352 | return count; |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 355 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 356 | static struct device_attribute *pccard_socket_attributes[] = { |
| 357 | &dev_attr_card_type, |
| 358 | &dev_attr_card_voltage, |
| 359 | &dev_attr_card_vpp, |
| 360 | &dev_attr_card_vcc, |
| 361 | &dev_attr_card_insert, |
| 362 | &dev_attr_card_pm_state, |
| 363 | &dev_attr_card_eject, |
| 364 | &dev_attr_card_irq_mask, |
| 365 | &dev_attr_available_resources_setup_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | NULL, |
| 367 | }; |
| 368 | |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 369 | static struct bin_attribute pccard_cis_attr = { |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 370 | .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR, .owner = THIS_MODULE}, |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 371 | .size = 0x200, |
| 372 | .read = pccard_show_cis, |
Dominik Brodowski | ff1fa9e | 2005-06-27 16:28:09 -0700 | [diff] [blame] | 373 | .write = pccard_store_cis, |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 376 | static int __devinit pccard_sysfs_add_socket(struct device *dev, |
Dmitry Torokhov | d8539d8 | 2005-09-15 02:01:36 -0500 | [diff] [blame] | 377 | struct class_interface *class_intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 379 | struct device_attribute **attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | int ret = 0; |
| 381 | |
| 382 | for (attr = pccard_socket_attributes; *attr; attr++) { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 383 | ret = device_create_file(dev, *attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (ret) |
| 385 | break; |
| 386 | } |
Dominik Brodowski | 7f299bc | 2005-06-27 16:28:08 -0700 | [diff] [blame] | 387 | if (!ret) |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 388 | ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 393 | static void __devexit pccard_sysfs_remove_socket(struct device *dev, |
Dmitry Torokhov | d8539d8 | 2005-09-15 02:01:36 -0500 | [diff] [blame] | 394 | struct class_interface *class_intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 396 | struct device_attribute **attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 398 | sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | for (attr = pccard_socket_attributes; *attr; attr++) |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 400 | device_remove_file(dev, *attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | struct class_interface pccard_sysfs_interface = { |
| 404 | .class = &pcmcia_socket_class, |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 405 | .add_dev = &pccard_sysfs_add_socket, |
| 406 | .remove_dev = __devexit_p(&pccard_sysfs_remove_socket), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | }; |