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/config.h>
16 #include <linux/string.h>
17 #include <linux/major.h>
18 #include <linux/errno.h>
19 #include <linux/slab.h>
21 #include <linux/interrupt.h>
22 #include <linux/timer.h>
23 #include <linux/ioport.h>
24 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/device.h>
28 #include <asm/system.h>
31 #define IN_CARD_SERVICES
32 #include <pcmcia/version.h>
33 #include <pcmcia/cs_types.h>
34 #include <pcmcia/ss.h>
35 #include <pcmcia/cs.h>
36 #include <pcmcia/bulkmem.h>
37 #include <pcmcia/cistpl.h>
38 #include <pcmcia/cisreg.h>
39 #include <pcmcia/ds.h>
40 #include "cs_internal.h"
42 #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
44 static ssize_t
pccard_show_type(struct class_device
*dev
, char *buf
)
47 struct pcmcia_socket
*s
= to_socket(dev
);
49 if (!(s
->state
& SOCKET_PRESENT
))
51 s
->ops
->get_status(s
, &val
);
53 return sprintf(buf
, "32-bit\n");
55 return sprintf(buf
, "16-bit\n");
56 return sprintf(buf
, "invalid\n");
58 static CLASS_DEVICE_ATTR(card_type
, 0400, pccard_show_type
, NULL
);
60 static ssize_t
pccard_show_voltage(struct class_device
*dev
, char *buf
)
63 struct pcmcia_socket
*s
= to_socket(dev
);
65 if (!(s
->state
& SOCKET_PRESENT
))
67 s
->ops
->get_status(s
, &val
);
69 return sprintf(buf
, "3.3V\n");
71 return sprintf(buf
, "X.XV\n");
72 return sprintf(buf
, "5.0V\n");
74 static CLASS_DEVICE_ATTR(card_voltage
, 0400, pccard_show_voltage
, NULL
);
76 static ssize_t
pccard_show_vpp(struct class_device
*dev
, char *buf
)
78 struct pcmcia_socket
*s
= to_socket(dev
);
79 if (!(s
->state
& SOCKET_PRESENT
))
81 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vpp
/ 10, s
->socket
.Vpp
% 10);
83 static CLASS_DEVICE_ATTR(card_vpp
, 0400, pccard_show_vpp
, NULL
);
85 static ssize_t
pccard_show_vcc(struct class_device
*dev
, char *buf
)
87 struct pcmcia_socket
*s
= to_socket(dev
);
88 if (!(s
->state
& SOCKET_PRESENT
))
90 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vcc
/ 10, s
->socket
.Vcc
% 10);
92 static CLASS_DEVICE_ATTR(card_vcc
, 0400, pccard_show_vcc
, NULL
);
95 static ssize_t
pccard_store_insert(struct class_device
*dev
, const char *buf
, size_t count
)
98 struct pcmcia_socket
*s
= to_socket(dev
);
103 ret
= pcmcia_insert_card(s
);
105 return ret
? ret
: count
;
107 static CLASS_DEVICE_ATTR(card_insert
, 0200, NULL
, pccard_store_insert
);
109 static ssize_t
pccard_store_eject(struct class_device
*dev
, const char *buf
, size_t count
)
112 struct pcmcia_socket
*s
= to_socket(dev
);
117 ret
= pcmcia_eject_card(s
);
119 return ret
? ret
: count
;
121 static CLASS_DEVICE_ATTR(card_eject
, 0200, NULL
, pccard_store_eject
);
124 static ssize_t
pccard_show_irq_mask(struct class_device
*dev
, char *buf
)
126 struct pcmcia_socket
*s
= to_socket(dev
);
127 return sprintf(buf
, "0x%04x\n", s
->irq_mask
);
130 static ssize_t
pccard_store_irq_mask(struct class_device
*dev
, const char *buf
, size_t count
)
133 struct pcmcia_socket
*s
= to_socket(dev
);
139 ret
= sscanf (buf
, "0x%x\n", &mask
);
146 return ret
? ret
: count
;
148 static CLASS_DEVICE_ATTR(card_irq_mask
, 0600, pccard_show_irq_mask
, pccard_store_irq_mask
);
151 static ssize_t
pccard_show_resource(struct class_device
*dev
, char *buf
)
153 struct pcmcia_socket
*s
= to_socket(dev
);
154 return sprintf(buf
, "%s\n", s
->resource_setup_done
? "yes" : "no");
157 static ssize_t
pccard_store_resource(struct class_device
*dev
, const char *buf
, size_t count
)
160 struct pcmcia_socket
*s
= to_socket(dev
);
165 spin_lock_irqsave(&s
->lock
, flags
);
166 if (!s
->resource_setup_done
) {
167 s
->resource_setup_done
= 1;
168 spin_unlock_irqrestore(&s
->lock
, flags
);
172 (s
->state
& SOCKET_PRESENT
) &&
173 !(s
->state
& SOCKET_CARDBUS
)) {
174 if (try_module_get(s
->callback
->owner
)) {
175 s
->callback
->resources_done(s
);
176 module_put(s
->callback
->owner
);
183 spin_unlock_irqrestore(&s
->lock
, flags
);
187 static CLASS_DEVICE_ATTR(available_resources_setup_done
, 0600, pccard_show_resource
, pccard_store_resource
);
190 static struct class_device_attribute
*pccard_socket_attributes
[] = {
191 &class_device_attr_card_type
,
192 &class_device_attr_card_voltage
,
193 &class_device_attr_card_vpp
,
194 &class_device_attr_card_vcc
,
195 &class_device_attr_card_insert
,
196 &class_device_attr_card_eject
,
197 &class_device_attr_card_irq_mask
,
198 &class_device_attr_available_resources_setup_done
,
202 static int __devinit
pccard_sysfs_add_socket(struct class_device
*class_dev
)
204 struct class_device_attribute
**attr
;
207 for (attr
= pccard_socket_attributes
; *attr
; attr
++) {
208 ret
= class_device_create_file(class_dev
, *attr
);
216 static void __devexit
pccard_sysfs_remove_socket(struct class_device
*class_dev
)
218 struct class_device_attribute
**attr
;
220 for (attr
= pccard_socket_attributes
; *attr
; attr
++)
221 class_device_remove_file(class_dev
, *attr
);
224 struct class_interface pccard_sysfs_interface
= {
225 .class = &pcmcia_socket_class
,
226 .add
= &pccard_sysfs_add_socket
,
227 .remove
= __devexit_p(&pccard_sysfs_remove_socket
),