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 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | struct pcmcia_socket *s = to_socket(dev); |
| 92 | |
| 93 | if (!count) |
| 94 | return -EINVAL; |
| 95 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 96 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 98 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 100 | static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 102 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 103 | static ssize_t pccard_show_card_pm_state(struct device *dev, |
| 104 | struct device_attribute *attr, |
| 105 | char *buf) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 106 | { |
| 107 | struct pcmcia_socket *s = to_socket(dev); |
| 108 | return sprintf(buf, "%s\n", s->state & SOCKET_SUSPEND ? "off" : "on"); |
| 109 | } |
| 110 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 111 | static ssize_t pccard_store_card_pm_state(struct device *dev, |
| 112 | struct device_attribute *attr, |
| 113 | const char *buf, size_t count) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 114 | { |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 115 | struct pcmcia_socket *s = to_socket(dev); |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 116 | ssize_t ret = count; |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 117 | |
| 118 | if (!count) |
| 119 | return -EINVAL; |
| 120 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 121 | if (!strncmp(buf, "off", 3)) |
| 122 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND); |
| 123 | else { |
| 124 | if (!strncmp(buf, "on", 2)) |
| 125 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME); |
| 126 | else |
| 127 | ret = -EINVAL; |
| 128 | } |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 129 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 130 | return ret; |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 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 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | struct pcmcia_socket *s = to_socket(dev); |
| 139 | |
| 140 | if (!count) |
| 141 | return -EINVAL; |
| 142 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 143 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 145 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 169 | ret = sscanf(buf, "0x%x\n", &mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | if (ret == 1) { |
Dominik Brodowski | 64d8d46 | 2010-01-16 01:14:38 +0100 | [diff] [blame] | 172 | mutex_lock(&s->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | s->irq_mask &= mask; |
Dominik Brodowski | 64d8d46 | 2010-01-16 01:14:38 +0100 | [diff] [blame] | 174 | mutex_unlock(&s->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | ret = 0; |
| 176 | } |
| 177 | |
| 178 | return ret ? ret : count; |
| 179 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 180 | 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] | 181 | |
| 182 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 183 | static ssize_t pccard_show_resource(struct device *dev, |
| 184 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | struct pcmcia_socket *s = to_socket(dev); |
| 187 | return sprintf(buf, "%s\n", s->resource_setup_done ? "yes" : "no"); |
| 188 | } |
| 189 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 190 | static ssize_t pccard_store_resource(struct device *dev, |
| 191 | struct device_attribute *attr, |
| 192 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | struct pcmcia_socket *s = to_socket(dev); |
| 195 | |
| 196 | if (!count) |
| 197 | return -EINVAL; |
| 198 | |
Dominik Brodowski | 00ce99f | 2010-01-16 09:14:11 +0100 | [diff] [blame] | 199 | mutex_lock(&s->ops_mutex); |
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; |
Dominik Brodowski | 00ce99f | 2010-01-16 09:14:11 +0100 | [diff] [blame] | 202 | mutex_unlock(&s->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Dominik Brodowski | af461fc | 2010-01-17 19:30:53 +0100 | [diff] [blame] | 204 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return count; |
| 207 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 208 | 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] | 209 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 210 | static struct attribute *pccard_socket_attributes[] = { |
| 211 | &dev_attr_card_type.attr, |
| 212 | &dev_attr_card_voltage.attr, |
| 213 | &dev_attr_card_vpp.attr, |
| 214 | &dev_attr_card_vcc.attr, |
| 215 | &dev_attr_card_insert.attr, |
| 216 | &dev_attr_card_pm_state.attr, |
| 217 | &dev_attr_card_eject.attr, |
| 218 | &dev_attr_card_irq_mask.attr, |
| 219 | &dev_attr_available_resources_setup_done.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | NULL, |
| 221 | }; |
| 222 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 223 | static const struct attribute_group socket_attrs = { |
| 224 | .attrs = pccard_socket_attributes, |
| 225 | }; |
| 226 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 227 | int pccard_sysfs_add_socket(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Dominik Brodowski | 6e7b51a | 2010-01-06 13:57:43 +0100 | [diff] [blame] | 229 | return sysfs_create_group(&dev->kobj, &socket_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 232 | void pccard_sysfs_remove_socket(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 234 | sysfs_remove_group(&dev->kobj, &socket_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |