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
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>
19 #include <linux/interrupt.h>
20 #include <linux/timer.h>
21 #include <linux/ioport.h>
22 #include <linux/delay.h>
24 #include <linux/device.h>
25 #include <linux/mutex.h>
26 #include <asm/system.h>
29 #include <pcmcia/ss.h>
30 #include <pcmcia/cs.h>
31 #include <pcmcia/cistpl.h>
32 #include <pcmcia/cisreg.h>
33 #include <pcmcia/ds.h>
34 #include "cs_internal.h"
36 #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
38 static ssize_t
pccard_show_type(struct device
*dev
, struct device_attribute
*attr
,
41 struct pcmcia_socket
*s
= to_socket(dev
);
43 if (!(s
->state
& SOCKET_PRESENT
))
45 if (s
->state
& SOCKET_CARDBUS
)
46 return sprintf(buf
, "32-bit\n");
47 return sprintf(buf
, "16-bit\n");
49 static DEVICE_ATTR(card_type
, 0444, pccard_show_type
, NULL
);
51 static ssize_t
pccard_show_voltage(struct device
*dev
, struct device_attribute
*attr
,
54 struct pcmcia_socket
*s
= to_socket(dev
);
56 if (!(s
->state
& SOCKET_PRESENT
))
59 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vcc
/ 10,
61 return sprintf(buf
, "X.XV\n");
63 static DEVICE_ATTR(card_voltage
, 0444, pccard_show_voltage
, NULL
);
65 static ssize_t
pccard_show_vpp(struct device
*dev
, struct device_attribute
*attr
,
68 struct pcmcia_socket
*s
= to_socket(dev
);
69 if (!(s
->state
& SOCKET_PRESENT
))
71 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vpp
/ 10, s
->socket
.Vpp
% 10);
73 static DEVICE_ATTR(card_vpp
, 0444, pccard_show_vpp
, NULL
);
75 static ssize_t
pccard_show_vcc(struct device
*dev
, struct device_attribute
*attr
,
78 struct pcmcia_socket
*s
= to_socket(dev
);
79 if (!(s
->state
& SOCKET_PRESENT
))
81 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vcc
/ 10, s
->socket
.Vcc
% 10);
83 static DEVICE_ATTR(card_vcc
, 0444, pccard_show_vcc
, NULL
);
86 static ssize_t
pccard_store_insert(struct device
*dev
, struct device_attribute
*attr
,
87 const char *buf
, size_t count
)
89 struct pcmcia_socket
*s
= to_socket(dev
);
94 pcmcia_parse_uevents(s
, PCMCIA_UEVENT_INSERT
);
98 static DEVICE_ATTR(card_insert
, 0200, NULL
, pccard_store_insert
);
101 static ssize_t
pccard_show_card_pm_state(struct device
*dev
,
102 struct device_attribute
*attr
,
105 struct pcmcia_socket
*s
= to_socket(dev
);
106 return sprintf(buf
, "%s\n", s
->state
& SOCKET_SUSPEND
? "off" : "on");
109 static ssize_t
pccard_store_card_pm_state(struct device
*dev
,
110 struct device_attribute
*attr
,
111 const char *buf
, size_t count
)
113 struct pcmcia_socket
*s
= to_socket(dev
);
119 if (!strncmp(buf
, "off", 3))
120 pcmcia_parse_uevents(s
, PCMCIA_UEVENT_SUSPEND
);
122 if (!strncmp(buf
, "on", 2))
123 pcmcia_parse_uevents(s
, PCMCIA_UEVENT_RESUME
);
130 static DEVICE_ATTR(card_pm_state
, 0644, pccard_show_card_pm_state
, pccard_store_card_pm_state
);
132 static ssize_t
pccard_store_eject(struct device
*dev
,
133 struct device_attribute
*attr
,
134 const char *buf
, size_t count
)
136 struct pcmcia_socket
*s
= to_socket(dev
);
141 pcmcia_parse_uevents(s
, PCMCIA_UEVENT_EJECT
);
145 static DEVICE_ATTR(card_eject
, 0200, NULL
, pccard_store_eject
);
148 static ssize_t
pccard_show_irq_mask(struct device
*dev
,
149 struct device_attribute
*attr
,
152 struct pcmcia_socket
*s
= to_socket(dev
);
153 return sprintf(buf
, "0x%04x\n", s
->irq_mask
);
156 static ssize_t
pccard_store_irq_mask(struct device
*dev
,
157 struct device_attribute
*attr
,
158 const char *buf
, size_t count
)
161 struct pcmcia_socket
*s
= to_socket(dev
);
167 ret
= sscanf(buf
, "0x%x\n", &mask
);
170 mutex_lock(&s
->ops_mutex
);
172 mutex_unlock(&s
->ops_mutex
);
176 return ret
? ret
: count
;
178 static DEVICE_ATTR(card_irq_mask
, 0600, pccard_show_irq_mask
, pccard_store_irq_mask
);
181 static ssize_t
pccard_show_resource(struct device
*dev
,
182 struct device_attribute
*attr
, char *buf
)
184 struct pcmcia_socket
*s
= to_socket(dev
);
185 return sprintf(buf
, "%s\n", s
->resource_setup_done
? "yes" : "no");
188 static ssize_t
pccard_store_resource(struct device
*dev
,
189 struct device_attribute
*attr
,
190 const char *buf
, size_t count
)
192 struct pcmcia_socket
*s
= to_socket(dev
);
197 mutex_lock(&s
->ops_mutex
);
198 if (!s
->resource_setup_done
)
199 s
->resource_setup_done
= 1;
200 mutex_unlock(&s
->ops_mutex
);
202 pcmcia_parse_uevents(s
, PCMCIA_UEVENT_REQUERY
);
206 static DEVICE_ATTR(available_resources_setup_done
, 0600, pccard_show_resource
, pccard_store_resource
);
208 static struct attribute
*pccard_socket_attributes
[] = {
209 &dev_attr_card_type
.attr
,
210 &dev_attr_card_voltage
.attr
,
211 &dev_attr_card_vpp
.attr
,
212 &dev_attr_card_vcc
.attr
,
213 &dev_attr_card_insert
.attr
,
214 &dev_attr_card_pm_state
.attr
,
215 &dev_attr_card_eject
.attr
,
216 &dev_attr_card_irq_mask
.attr
,
217 &dev_attr_available_resources_setup_done
.attr
,
221 static const struct attribute_group socket_attrs
= {
222 .attrs
= pccard_socket_attributes
,
225 int pccard_sysfs_add_socket(struct device
*dev
)
227 return sysfs_create_group(&dev
->kobj
, &socket_attrs
);
230 void pccard_sysfs_remove_socket(struct device
*dev
)
232 sysfs_remove_group(&dev
->kobj
, &socket_attrs
);