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 <linux/suspend.h>
29 #include <asm/system.h>
32 #define IN_CARD_SERVICES
33 #include <pcmcia/version.h>
34 #include <pcmcia/cs_types.h>
35 #include <pcmcia/ss.h>
36 #include <pcmcia/cs.h>
37 #include <pcmcia/bulkmem.h>
38 #include <pcmcia/cistpl.h>
39 #include <pcmcia/cisreg.h>
40 #include <pcmcia/ds.h>
41 #include "cs_internal.h"
43 #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
45 static ssize_t
pccard_show_type(struct class_device
*dev
, char *buf
)
48 struct pcmcia_socket
*s
= to_socket(dev
);
50 if (!(s
->state
& SOCKET_PRESENT
))
52 s
->ops
->get_status(s
, &val
);
54 return sprintf(buf
, "32-bit\n");
56 return sprintf(buf
, "16-bit\n");
57 return sprintf(buf
, "invalid\n");
59 static CLASS_DEVICE_ATTR(card_type
, 0400, pccard_show_type
, NULL
);
61 static ssize_t
pccard_show_voltage(struct class_device
*dev
, char *buf
)
64 struct pcmcia_socket
*s
= to_socket(dev
);
66 if (!(s
->state
& SOCKET_PRESENT
))
68 s
->ops
->get_status(s
, &val
);
70 return sprintf(buf
, "3.3V\n");
72 return sprintf(buf
, "X.XV\n");
73 return sprintf(buf
, "5.0V\n");
75 static CLASS_DEVICE_ATTR(card_voltage
, 0400, pccard_show_voltage
, NULL
);
77 static ssize_t
pccard_show_vpp(struct class_device
*dev
, char *buf
)
79 struct pcmcia_socket
*s
= to_socket(dev
);
80 if (!(s
->state
& SOCKET_PRESENT
))
82 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vpp
/ 10, s
->socket
.Vpp
% 10);
84 static CLASS_DEVICE_ATTR(card_vpp
, 0400, pccard_show_vpp
, NULL
);
86 static ssize_t
pccard_show_vcc(struct class_device
*dev
, char *buf
)
88 struct pcmcia_socket
*s
= to_socket(dev
);
89 if (!(s
->state
& SOCKET_PRESENT
))
91 return sprintf(buf
, "%d.%dV\n", s
->socket
.Vcc
/ 10, s
->socket
.Vcc
% 10);
93 static CLASS_DEVICE_ATTR(card_vcc
, 0400, pccard_show_vcc
, NULL
);
96 static ssize_t
pccard_store_insert(struct class_device
*dev
, const char *buf
, size_t count
)
99 struct pcmcia_socket
*s
= to_socket(dev
);
104 ret
= pcmcia_insert_card(s
);
106 return ret
? ret
: count
;
108 static CLASS_DEVICE_ATTR(card_insert
, 0200, NULL
, pccard_store_insert
);
110 static ssize_t
pccard_store_eject(struct class_device
*dev
, const char *buf
, size_t count
)
113 struct pcmcia_socket
*s
= to_socket(dev
);
118 ret
= pcmcia_eject_card(s
);
120 return ret
? ret
: count
;
122 static CLASS_DEVICE_ATTR(card_eject
, 0200, NULL
, pccard_store_eject
);
125 static struct class_device_attribute
*pccard_socket_attributes
[] = {
126 &class_device_attr_card_type
,
127 &class_device_attr_card_voltage
,
128 &class_device_attr_card_vpp
,
129 &class_device_attr_card_vcc
,
130 &class_device_attr_card_insert
,
131 &class_device_attr_card_eject
,
135 static int __devinit
pccard_sysfs_add_socket(struct class_device
*class_dev
)
137 struct class_device_attribute
**attr
;
140 for (attr
= pccard_socket_attributes
; *attr
; attr
++) {
141 ret
= class_device_create_file(class_dev
, *attr
);
149 static void __devexit
pccard_sysfs_remove_socket(struct class_device
*class_dev
)
151 struct class_device_attribute
**attr
;
153 for (attr
= pccard_socket_attributes
; *attr
; attr
++)
154 class_device_remove_file(class_dev
, *attr
);
157 struct class_interface pccard_sysfs_interface
= {
158 .class = &pcmcia_socket_class
,
159 .add
= &pccard_sysfs_add_socket
,
160 .remove
= __devexit_p(&pccard_sysfs_remove_socket
),