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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/mm.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/timer.h> |
| 21 | #include <linux/ioport.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/device.h> |
Dominik Brodowski | 7fe908d | 2006-01-10 21:20:36 +0100 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/system.h> |
| 27 | #include <asm/irq.h> |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <pcmcia/ss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <pcmcia/cistpl.h> |
| 31 | #include <pcmcia/cisreg.h> |
| 32 | #include <pcmcia/ds.h> |
| 33 | #include "cs_internal.h" |
| 34 | |
| 35 | #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev) |
| 36 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 37 | static ssize_t pccard_show_type(struct device *dev, struct device_attribute *attr, |
| 38 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct pcmcia_socket *s = to_socket(dev); |
| 41 | |
| 42 | if (!(s->state & SOCKET_PRESENT)) |
| 43 | return -ENODEV; |
Dominik Brodowski | 002dbb2 | 2005-12-08 23:50:36 +0100 | [diff] [blame] | 44 | if (s->state & SOCKET_CARDBUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | return sprintf(buf, "32-bit\n"); |
Dominik Brodowski | 002dbb2 | 2005-12-08 23:50:36 +0100 | [diff] [blame] | 46 | return sprintf(buf, "16-bit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 48 | static DEVICE_ATTR(card_type, 0444, pccard_show_type, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 50 | static ssize_t pccard_show_voltage(struct device *dev, struct device_attribute *attr, |
| 51 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct pcmcia_socket *s = to_socket(dev); |
| 54 | |
| 55 | if (!(s->state & SOCKET_PRESENT)) |
| 56 | return -ENODEV; |
Dominik Brodowski | 002dbb2 | 2005-12-08 23:50:36 +0100 | [diff] [blame] | 57 | if (s->socket.Vcc) |
| 58 | return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, |
| 59 | s->socket.Vcc % 10); |
| 60 | return sprintf(buf, "X.XV\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 62 | static DEVICE_ATTR(card_voltage, 0444, pccard_show_voltage, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 64 | static ssize_t pccard_show_vpp(struct device *dev, struct device_attribute *attr, |
| 65 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | struct pcmcia_socket *s = to_socket(dev); |
| 68 | if (!(s->state & SOCKET_PRESENT)) |
| 69 | return -ENODEV; |
| 70 | return sprintf(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10); |
| 71 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 72 | static DEVICE_ATTR(card_vpp, 0444, pccard_show_vpp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 74 | static ssize_t pccard_show_vcc(struct device *dev, struct device_attribute *attr, |
| 75 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
| 77 | struct pcmcia_socket *s = to_socket(dev); |
| 78 | if (!(s->state & SOCKET_PRESENT)) |
| 79 | return -ENODEV; |
| 80 | return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10); |
| 81 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 82 | static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 85 | static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, |
| 86 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | struct pcmcia_socket *s = to_socket(dev); |
| 89 | |
| 90 | if (!count) |
| 91 | return -EINVAL; |
| 92 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 93 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 95 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 97 | static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 99 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 100 | static ssize_t pccard_show_card_pm_state(struct device *dev, |
| 101 | struct device_attribute *attr, |
| 102 | char *buf) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 103 | { |
| 104 | struct pcmcia_socket *s = to_socket(dev); |
| 105 | return sprintf(buf, "%s\n", s->state & SOCKET_SUSPEND ? "off" : "on"); |
| 106 | } |
| 107 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 108 | static ssize_t pccard_store_card_pm_state(struct device *dev, |
| 109 | struct device_attribute *attr, |
| 110 | const char *buf, size_t count) |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 111 | { |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 112 | struct pcmcia_socket *s = to_socket(dev); |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 113 | ssize_t ret = count; |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 114 | |
| 115 | if (!count) |
| 116 | return -EINVAL; |
| 117 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 118 | if (!strncmp(buf, "off", 3)) |
| 119 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND); |
| 120 | else { |
| 121 | if (!strncmp(buf, "on", 2)) |
| 122 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME); |
| 123 | else |
| 124 | ret = -EINVAL; |
| 125 | } |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 126 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 127 | return ret; |
Dominik Brodowski | db1019c | 2006-01-10 19:19:37 +0100 | [diff] [blame] | 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 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | struct pcmcia_socket *s = to_socket(dev); |
| 136 | |
| 137 | if (!count) |
| 138 | return -EINVAL; |
| 139 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 140 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Dominik Brodowski | f971dbd | 2010-01-17 18:13:31 +0100 | [diff] [blame] | 142 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 144 | static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 147 | static ssize_t pccard_show_irq_mask(struct device *dev, |
| 148 | struct device_attribute *attr, |
| 149 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | struct pcmcia_socket *s = to_socket(dev); |
| 152 | return sprintf(buf, "0x%04x\n", s->irq_mask); |
| 153 | } |
| 154 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 155 | static ssize_t pccard_store_irq_mask(struct device *dev, |
| 156 | struct device_attribute *attr, |
| 157 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
| 159 | ssize_t ret; |
| 160 | struct pcmcia_socket *s = to_socket(dev); |
| 161 | u32 mask; |
| 162 | |
| 163 | if (!count) |
| 164 | return -EINVAL; |
| 165 | |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 166 | ret = sscanf(buf, "0x%x\n", &mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | if (ret == 1) { |
Dominik Brodowski | 64d8d46 | 2010-01-16 01:14:38 +0100 | [diff] [blame] | 169 | mutex_lock(&s->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | s->irq_mask &= mask; |
Dominik Brodowski | 64d8d46 | 2010-01-16 01:14:38 +0100 | [diff] [blame] | 171 | mutex_unlock(&s->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | ret = 0; |
| 173 | } |
| 174 | |
| 175 | return ret ? ret : count; |
| 176 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 177 | 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] | 178 | |
| 179 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 180 | static ssize_t pccard_show_resource(struct device *dev, |
| 181 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
| 183 | struct pcmcia_socket *s = to_socket(dev); |
| 184 | return sprintf(buf, "%s\n", s->resource_setup_done ? "yes" : "no"); |
| 185 | } |
| 186 | |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 187 | static ssize_t pccard_store_resource(struct device *dev, |
| 188 | struct device_attribute *attr, |
| 189 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | struct pcmcia_socket *s = to_socket(dev); |
| 192 | |
| 193 | if (!count) |
| 194 | return -EINVAL; |
| 195 | |
Dominik Brodowski | 00ce99f | 2010-01-16 09:14:11 +0100 | [diff] [blame] | 196 | mutex_lock(&s->ops_mutex); |
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; |
Dominik Brodowski | 00ce99f | 2010-01-16 09:14:11 +0100 | [diff] [blame] | 199 | mutex_unlock(&s->ops_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Dominik Brodowski | af461fc | 2010-01-17 19:30:53 +0100 | [diff] [blame] | 201 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); |
Dominik Brodowski | e2f0b53 | 2005-06-27 16:28:17 -0700 | [diff] [blame] | 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return count; |
| 204 | } |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 205 | 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] | 206 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 207 | static struct attribute *pccard_socket_attributes[] = { |
| 208 | &dev_attr_card_type.attr, |
| 209 | &dev_attr_card_voltage.attr, |
| 210 | &dev_attr_card_vpp.attr, |
| 211 | &dev_attr_card_vcc.attr, |
| 212 | &dev_attr_card_insert.attr, |
| 213 | &dev_attr_card_pm_state.attr, |
| 214 | &dev_attr_card_eject.attr, |
| 215 | &dev_attr_card_irq_mask.attr, |
| 216 | &dev_attr_available_resources_setup_done.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | NULL, |
| 218 | }; |
| 219 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 220 | static const struct attribute_group socket_attrs = { |
| 221 | .attrs = pccard_socket_attributes, |
| 222 | }; |
| 223 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 224 | int pccard_sysfs_add_socket(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
Dominik Brodowski | 6e7b51a | 2010-01-06 13:57:43 +0100 | [diff] [blame] | 226 | return sysfs_create_group(&dev->kobj, &socket_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 229 | void pccard_sysfs_remove_socket(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 231 | sysfs_remove_group(&dev->kobj, &socket_attrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |