This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / pcmcia / socket_sysfs.c
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>
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>
20 #include <linux/mm.h>
21 #include <linux/interrupt.h>
22 #include <linux/timer.h>
23 #include <linux/ioport.h>
24 #include <linux/delay.h>
25 #include <linux/pm.h>
26 #include <linux/pci.h>
27 #include <linux/device.h>
28 #include <linux/suspend.h>
29 #include <asm/system.h>
30 #include <asm/irq.h>
31
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"
42
43 #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
44
45 static ssize_t pccard_show_type(struct class_device *dev, char *buf)
46 {
47         int val;
48         struct pcmcia_socket *s = to_socket(dev);
49
50         if (!(s->state & SOCKET_PRESENT))
51                 return -ENODEV;
52         s->ops->get_status(s, &val);
53         if (val & SS_CARDBUS)
54                 return sprintf(buf, "32-bit\n");
55         if (val & SS_DETECT)
56                 return sprintf(buf, "16-bit\n");
57         return sprintf(buf, "invalid\n");
58 }
59 static CLASS_DEVICE_ATTR(card_type, 0400, pccard_show_type, NULL);
60
61 static ssize_t pccard_show_voltage(struct class_device *dev, char *buf)
62 {
63         int val;
64         struct pcmcia_socket *s = to_socket(dev);
65
66         if (!(s->state & SOCKET_PRESENT))
67                 return -ENODEV;
68         s->ops->get_status(s, &val);
69         if (val & SS_3VCARD)
70                 return sprintf(buf, "3.3V\n");
71         if (val & SS_XVCARD)
72                 return sprintf(buf, "X.XV\n");
73         return sprintf(buf, "5.0V\n");
74 }
75 static CLASS_DEVICE_ATTR(card_voltage, 0400, pccard_show_voltage, NULL);
76
77 static ssize_t pccard_show_vpp(struct class_device *dev, char *buf)
78 {
79         struct pcmcia_socket *s = to_socket(dev);
80         if (!(s->state & SOCKET_PRESENT))
81                 return -ENODEV;
82         return sprintf(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10);
83 }
84 static CLASS_DEVICE_ATTR(card_vpp, 0400, pccard_show_vpp, NULL);
85
86 static ssize_t pccard_show_vcc(struct class_device *dev, char *buf)
87 {
88         struct pcmcia_socket *s = to_socket(dev);
89         if (!(s->state & SOCKET_PRESENT))
90                 return -ENODEV;
91         return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10);
92 }
93 static CLASS_DEVICE_ATTR(card_vcc, 0400, pccard_show_vcc, NULL);
94
95
96 static ssize_t pccard_store_insert(struct class_device *dev, const char *buf, size_t count)
97 {
98         ssize_t ret;
99         struct pcmcia_socket *s = to_socket(dev);
100
101         if (!count)
102                 return -EINVAL;
103
104         ret = pcmcia_insert_card(s);
105
106         return ret ? ret : count;
107 }
108 static CLASS_DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert);
109
110 static ssize_t pccard_store_eject(struct class_device *dev, const char *buf, size_t count)
111 {
112         ssize_t ret;
113         struct pcmcia_socket *s = to_socket(dev);
114
115         if (!count)
116                 return -EINVAL;
117
118         ret = pcmcia_eject_card(s);
119
120         return ret ? ret : count;
121 }
122 static CLASS_DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject);
123
124
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,
132         NULL,
133 };
134
135 static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
136 {
137         struct class_device_attribute **attr;
138         int ret = 0;
139
140         for (attr = pccard_socket_attributes; *attr; attr++) {
141                 ret = class_device_create_file(class_dev, *attr);
142                 if (ret)
143                         break;
144         }
145
146         return ret;
147 }
148
149 static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev)
150 {
151         struct class_device_attribute **attr;
152
153         for (attr = pccard_socket_attributes; *attr; attr++)
154                 class_device_remove_file(class_dev, *attr);
155 }
156
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),
161 };