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