aboutsummaryrefslogtreecommitdiffstats
path: root/packages/linux/linux/acern30/gpio-sysfs.patch
blob: b3fde0f9d66e10ef5759f67b3b120ff79ac83d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
This patch adds a lot of sysfs entries for the different GPIO lines.
It allows me to poke at different parts of the hardware to see what
happens.  This allowed me to discover the Bluetooth cutoff switch for
example.

Index: linux-2.6.14/arch/arm/mach-s3c2410/Makefile
===================================================================
--- linux-2.6.14.orig/arch/arm/mach-s3c2410/Makefile
+++ linux-2.6.14/arch/arm/mach-s3c2410/Makefile
@@ -42,3 +42,5 @@ obj-$(CONFIG_MACH_VR1000)	+= mach-vr1000
 obj-$(CONFIG_MACH_RX3715)	+= mach-rx3715.o
 obj-$(CONFIG_MACH_OTOM)		+= mach-otom.o
 obj-$(CONFIG_MACH_NEXCODER_2440) += mach-nexcoder.o
+
+obj-y += gpio-sysfs.o
Index: linux-2.6.14/arch/arm/mach-s3c2410/gpio-sysfs.c
===================================================================
--- /dev/null
+++ linux-2.6.14/arch/arm/mach-s3c2410/gpio-sysfs.c
@@ -0,0 +1,232 @@
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/backlight.h>
+#include <linux/notifier.h>
+#include <linux/ctype.h>
+#include <linux/err.h>
+#include <linux/fb.h>
+#include <asm/bug.h>
+
+#include <asm/arch/regs-gpio.h>
+
+#include <asm/arch/regs-clock.h>
+
+static ssize_t s3c2410_gpio_name_show(struct device *dev, 
+				      struct device_attribute *attr, char *buf)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	return snprintf(buf, PAGE_SIZE, "%d\n", pdev->id);
+}
+
+static ssize_t s3c2410_gpio_val_show(struct device *dev, 
+				     struct device_attribute *attr, char *buf)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	return snprintf(buf, PAGE_SIZE, "%d\n", 
+			s3c2410_gpio_getpin(pdev->id) ? 1 : 0);
+}
+
+static ssize_t s3c2410_gpio_val_store(struct device *dev, 
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	int val;
+	char *endp;
+
+	val = simple_strtoul(buf, &endp, 0);
+	if (*endp && !isspace(*endp))
+		return -EINVAL;
+
+	s3c2410_gpio_setpin(pdev->id, val ? 1 : 0);
+
+	return count;
+}
+
+static DEVICE_ATTR(name, 0444,
+		   s3c2410_gpio_name_show,
+		   NULL);
+
+static DEVICE_ATTR(val, 0666,
+		   s3c2410_gpio_val_show,
+		   s3c2410_gpio_val_store);
+
+
+static int __init s3c2410_gpio_probe(struct device *dev)
+{
+	device_create_file(dev, &dev_attr_name);
+	device_create_file(dev, &dev_attr_val);
+	return 0;
+}
+
+static int s3c2410_gpio_remove(struct device *dev)
+{
+	return 0;
+}
+
+static struct device_driver s3c2410_gpio_driver = {
+	.name		= "s3c2410-gpio",
+	.bus		= &platform_bus_type,
+	.probe		= s3c2410_gpio_probe,
+	.remove		= s3c2410_gpio_remove,
+};
+
+static struct platform_device s3c_device_gpio[32 * 8];
+
+static ssize_t s3c2410_clkslow_show(struct device *dev, 
+				     struct device_attribute *attr, char *buf)
+{
+	unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW);
+	
+	return snprintf(buf, PAGE_SIZE, "0x%08lx\n", clkslow);
+}
+
+static ssize_t s3c2410_clkslow_store(struct device *dev, 
+					struct device_attribute *attr,
+					const char *buf, size_t count)
+{
+	unsigned long val;
+	char *endp;
+
+	val = simple_strtoul(buf, &endp, 0);
+	if (*endp && !isspace(*endp))
+		return -EINVAL;
+
+	printk("CLKSLOW <= 0x%lx\n", val);
+
+	__raw_writel(val, S3C2410_CLKSLOW);
+
+	return count;
+}
+
+static DEVICE_ATTR(clkslow, 0666,
+		   s3c2410_clkslow_show,
+		   s3c2410_clkslow_store);
+
+static ssize_t s3c2410_clkcon_show(struct device *dev, 
+				     struct device_attribute *attr, char *buf)
+{
+	unsigned long clkclkcon = __raw_readl(S3C2410_CLKCON);
+	
+	return snprintf(buf, PAGE_SIZE, "0x%08lx\n", clkclkcon);
+}
+
+static ssize_t s3c2410_clkcon_store(struct device *dev, 
+					struct device_attribute *attr,
+					const char *buf, size_t count)
+{
+	unsigned long val;
+	char *endp;
+
+	val = simple_strtoul(buf, &endp, 0);
+	if (*endp && !isspace(*endp))
+		return -EINVAL;
+
+	printk("CLKCON <= 0x%lx\n", val);
+
+	__raw_writel(val, S3C2410_CLKCON);
+
+	return count;
+}
+
+static DEVICE_ATTR(clkcon, 0666,
+		   s3c2410_clkcon_show,
+		   s3c2410_clkcon_store);
+
+static ssize_t s3c2410_misccr_show(struct device *dev, 
+				   struct device_attribute *attr, char *buf)
+{
+	unsigned long misccr = __raw_readl(S3C2410_MISCCR);
+	
+	return snprintf(buf, PAGE_SIZE, "0x%08lx\n", misccr);
+}
+
+static ssize_t s3c2410_misccr_store(struct device *dev, 
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	unsigned long val;
+	char *endp;
+
+	val = simple_strtoul(buf, &endp, 0);
+	if (*endp && !isspace(*endp))
+		return -EINVAL;
+
+	printk("MISCCR <= 0x%lx\n", val);
+
+	__raw_writel(val, S3C2410_MISCCR);
+
+	return count;
+}
+
+static DEVICE_ATTR(misccr, 0666,
+		   s3c2410_misccr_show,
+		   s3c2410_misccr_store);
+
+static int __init s3c2410_regs_probe(struct device *dev)
+{
+	device_create_file(dev, &dev_attr_clkslow);
+	device_create_file(dev, &dev_attr_clkcon);
+	device_create_file(dev, &dev_attr_misccr);
+	return 0;
+}
+
+static int s3c2410_regs_remove(struct device *dev)
+{
+	return 0;
+}
+
+
+static struct device_driver s3c2410_regs_driver = {
+	.name		= "s3c2410-regs",
+	.bus		= &platform_bus_type,
+	.probe		= s3c2410_regs_probe,
+	.remove		= s3c2410_regs_remove,
+};
+
+static struct platform_device s3c_device_regs = {
+	.name = "s3c2410-regs",
+	.id = -1,
+};
+
+static int __init s3c2410_gpio_init(void)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(s3c_device_gpio); i++) {
+		s3c_device_gpio[i].name = "s3c2410-gpio";
+		s3c_device_gpio[i].id = i;
+		platform_device_register(&s3c_device_gpio[i]);
+	}
+
+	driver_register(&s3c2410_gpio_driver);
+	driver_register(&s3c2410_regs_driver);
+
+	platform_device_register(&s3c_device_regs);
+
+	return 0;
+}
+
+static void __exit s3c2410_gpio_cleanup(void)
+{
+	driver_unregister(&s3c2410_regs_driver);
+	driver_unregister(&s3c2410_gpio_driver);
+}
+
+module_init(s3c2410_gpio_init);
+module_exit(s3c2410_gpio_cleanup);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Christer Weinigel <christer@weinigel.se>");
+MODULE_DESCRIPTION("S3C2410 GPIO Driver");
+ 
+/*
+  Local variables:
+  compile-command: "make -k -C ../../../.. linux "
+  c-basic-offset: 8
+  End:
+*/