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