scsi: dc395x: fix dma API usage in srb_done
[linux/fpc-iii.git] / drivers / pcmcia / socket_sysfs.c
blobd6881514d38e701c8913e8d57cbd47ab2a5a1d27
1 /*
2 * socket_sysfs.c -- most of socket-related sysfs output
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.
8 * (C) 2003 - 2004 Dominik Brodowski
9 */
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/string.h>
16 #include <linux/major.h>
17 #include <linux/errno.h>
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>
24 #include <linux/device.h>
25 #include <linux/mutex.h>
26 #include <asm/irq.h>
28 #include <pcmcia/ss.h>
29 #include <pcmcia/cistpl.h>
30 #include <pcmcia/cisreg.h>
31 #include <pcmcia/ds.h>
32 #include "cs_internal.h"
34 #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
36 static ssize_t pccard_show_type(struct device *dev, struct device_attribute *attr,
37 char *buf)
39 struct pcmcia_socket *s = to_socket(dev);
41 if (!(s->state & SOCKET_PRESENT))
42 return -ENODEV;
43 if (s->state & SOCKET_CARDBUS)
44 return sprintf(buf, "32-bit\n");
45 return sprintf(buf, "16-bit\n");
47 static DEVICE_ATTR(card_type, 0444, pccard_show_type, NULL);
49 static ssize_t pccard_show_voltage(struct device *dev, struct device_attribute *attr,
50 char *buf)
52 struct pcmcia_socket *s = to_socket(dev);
54 if (!(s->state & SOCKET_PRESENT))
55 return -ENODEV;
56 if (s->socket.Vcc)
57 return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10,
58 s->socket.Vcc % 10);
59 return sprintf(buf, "X.XV\n");
61 static DEVICE_ATTR(card_voltage, 0444, pccard_show_voltage, NULL);
63 static ssize_t pccard_show_vpp(struct device *dev, struct device_attribute *attr,
64 char *buf)
66 struct pcmcia_socket *s = to_socket(dev);
67 if (!(s->state & SOCKET_PRESENT))
68 return -ENODEV;
69 return sprintf(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10);
71 static DEVICE_ATTR(card_vpp, 0444, pccard_show_vpp, NULL);
73 static ssize_t pccard_show_vcc(struct device *dev, struct device_attribute *attr,
74 char *buf)
76 struct pcmcia_socket *s = to_socket(dev);
77 if (!(s->state & SOCKET_PRESENT))
78 return -ENODEV;
79 return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10);
81 static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL);
84 static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr,
85 const char *buf, size_t count)
87 struct pcmcia_socket *s = to_socket(dev);
89 if (!count)
90 return -EINVAL;
92 pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT);
94 return count;
96 static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert);
99 static ssize_t pccard_show_card_pm_state(struct device *dev,
100 struct device_attribute *attr,
101 char *buf)
103 struct pcmcia_socket *s = to_socket(dev);
104 return sprintf(buf, "%s\n", s->state & SOCKET_SUSPEND ? "off" : "on");
107 static ssize_t pccard_store_card_pm_state(struct device *dev,
108 struct device_attribute *attr,
109 const char *buf, size_t count)
111 struct pcmcia_socket *s = to_socket(dev);
112 ssize_t ret = count;
114 if (!count)
115 return -EINVAL;
117 if (!strncmp(buf, "off", 3))
118 pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND);
119 else {
120 if (!strncmp(buf, "on", 2))
121 pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME);
122 else
123 ret = -EINVAL;
126 return ret;
128 static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state);
130 static ssize_t pccard_store_eject(struct device *dev,
131 struct device_attribute *attr,
132 const char *buf, size_t count)
134 struct pcmcia_socket *s = to_socket(dev);
136 if (!count)
137 return -EINVAL;
139 pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT);
141 return count;
143 static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject);
146 static ssize_t pccard_show_irq_mask(struct device *dev,
147 struct device_attribute *attr,
148 char *buf)
150 struct pcmcia_socket *s = to_socket(dev);
151 return sprintf(buf, "0x%04x\n", s->irq_mask);
154 static ssize_t pccard_store_irq_mask(struct device *dev,
155 struct device_attribute *attr,
156 const char *buf, size_t count)
158 ssize_t ret;
159 struct pcmcia_socket *s = to_socket(dev);
160 u32 mask;
162 if (!count)
163 return -EINVAL;
165 ret = sscanf(buf, "0x%x\n", &mask);
167 if (ret == 1) {
168 mutex_lock(&s->ops_mutex);
169 s->irq_mask &= mask;
170 mutex_unlock(&s->ops_mutex);
171 ret = 0;
174 return ret ? ret : count;
176 static DEVICE_ATTR(card_irq_mask, 0600, pccard_show_irq_mask, pccard_store_irq_mask);
179 static ssize_t pccard_show_resource(struct device *dev,
180 struct device_attribute *attr, char *buf)
182 struct pcmcia_socket *s = to_socket(dev);
183 return sprintf(buf, "%s\n", s->resource_setup_done ? "yes" : "no");
186 static ssize_t pccard_store_resource(struct device *dev,
187 struct device_attribute *attr,
188 const char *buf, size_t count)
190 struct pcmcia_socket *s = to_socket(dev);
192 if (!count)
193 return -EINVAL;
195 mutex_lock(&s->ops_mutex);
196 if (!s->resource_setup_done)
197 s->resource_setup_done = 1;
198 mutex_unlock(&s->ops_mutex);
200 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
202 return count;
204 static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
206 static struct attribute *pccard_socket_attributes[] = {
207 &dev_attr_card_type.attr,
208 &dev_attr_card_voltage.attr,
209 &dev_attr_card_vpp.attr,
210 &dev_attr_card_vcc.attr,
211 &dev_attr_card_insert.attr,
212 &dev_attr_card_pm_state.attr,
213 &dev_attr_card_eject.attr,
214 &dev_attr_card_irq_mask.attr,
215 &dev_attr_available_resources_setup_done.attr,
216 NULL,
219 static const struct attribute_group socket_attrs = {
220 .attrs = pccard_socket_attributes,
223 int pccard_sysfs_add_socket(struct device *dev)
225 return sysfs_create_group(&dev->kobj, &socket_attrs);
228 void pccard_sysfs_remove_socket(struct device *dev)
230 sysfs_remove_group(&dev->kobj, &socket_attrs);