summaryrefslogtreecommitdiff
path: root/packages/linux/linux-2.6.27/boc01/011-081218-gpio.patch
blob: 2381140ab2ca74eb842e16700264b32a660c3af2 (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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
Index: Goobie-2.6-27/drivers/char/Kconfig
===================================================================
--- Goobie-2.6-27.orig/drivers/char/Kconfig	2008-12-12 11:39:46.000000000 +0100
+++ Goobie-2.6-27/drivers/char/Kconfig	2008-12-12 11:39:48.000000000 +0100
@@ -1014,6 +1014,23 @@
 	tristate "NEC VR4100 series General-purpose I/O Unit support"
 	depends on CPU_VR41XX
 
+config GPIO_MPC8313
+	tristate "mpc8313e gpio"
+	depends on PPC_MPC831x
+	select INPUT
+	default y
+	help
+	  Give userspace access to the GPIO pins on the MPC8313E devices.
+
+config EXIO_MPC8313
+	tristate "mpc8313e exio"
+	depends on PPC_MPC831x
+	select INPUT
+	default y
+	help
+	  Give userspace access to the Extenrder IO pins on the CPE board.
+
+
 config RAW_DRIVER
 	tristate "RAW driver (/dev/raw/rawN)"
 	depends on BLOCK
Index: Goobie-2.6-27/drivers/char/Makefile
===================================================================
--- Goobie-2.6-27.orig/drivers/char/Makefile	2008-12-12 11:39:46.000000000 +0100
+++ Goobie-2.6-27/drivers/char/Makefile	2008-12-12 11:39:48.000000000 +0100
@@ -109,6 +109,8 @@
 obj-$(CONFIG_PS3_FLASH)		+= ps3flash.o
 
 obj-$(CONFIG_JS_RTC)		+= js-rtc.o
+obj-$(CONFIG_GPIO_MPC8313)			+= mpc8313e_gpio.o
+obj-$(CONFIG_EXIO_MPC8313)			+= mpc8313e_exio.o
 js-rtc-y = rtc.o
 
 # Files generated that shall be removed upon make clean
Index: Goobie-2.6-27/drivers/char/mpc8313e_exio.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ Goobie-2.6-27/drivers/char/mpc8313e_exio.c	2008-12-12 11:41:21.000000000 +0100
@@ -0,0 +1,170 @@
+/*
+* CPE Extender io driver
+*
+*
+* Copyright (C) 2007, CenoSYS (www.cenosys.com).
+* Alexandre Coffignal
+* alexandre.coffignal@cenosys.com
+*
+* This software program is licensed subject to the GNU General Public License
+* (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html
+*
+* Allows a user space process to control the EXIO pins.
+*
+*/
+
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <linux/of_platform.h>
+#include <sysdev/fsl_soc.h>
+#include <linux/cdev.h>
+
+static char module_name[] = "exio";
+
+
+#define NB_EXIO		8
+#define DEFAULT_STATE 0x58
+#define EXIO_BASE 0xfa000000
+#define EXIO_SIZE 0x2
+
+static int major = 0;
+static u8 exio_state = DEFAULT_STATE;
+static void *exio_io = NULL;
+static struct resource *exio_mem = NULL;
+
+static ssize_t mpc8313e_exio_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
+{
+	unsigned m = iminor(file->f_path.dentry->d_inode);
+	size_t i;
+	char mask;
+	int err = 0;
+
+	for (i = 0; i < len; ++i) {
+		char c;
+		if (get_user(c, data + i))
+			return -EFAULT;
+		//TODO write
+
+		mask=(1<<(7-m));
+		switch (c) {
+		case '0':
+			/*Clear exio level */
+			exio_state&=~mask;
+			iowrite8(exio_state, exio_io);
+			break;
+		case '1':
+			/*Set exio level */
+			exio_state|=mask;
+			iowrite8(exio_state, exio_io);
+			break;
+		default:
+			printk(KERN_DEBUG "exio%2d bad setting: chr<0x%2x>\n",
+				m, (int)c);
+			err++;
+		}
+	}
+	if (err)
+		return -EINVAL;
+
+	return len;
+}
+
+
+static ssize_t mpc8313e_exio_read(struct file *file, char __user * buf,
+		size_t len, loff_t * ppos)
+{
+	unsigned m = iminor(file->f_path.dentry->d_inode);
+	int value;
+	char mask;
+	char state=ioread8(exio_io);
+
+	mask=(1<<(7-m));
+	value=state&mask;
+	if (put_user(value ? '1' : '0', buf))
+		return -EFAULT;
+	return 1;
+
+}
+
+static int mpc8313e_exio_open(struct inode *inode, struct file *file)
+{
+    return 0;
+}
+
+static int mpc8313e_exio_close(struct inode *inode, struct file *file)
+{
+    printk(KERN_DEBUG "close()\n");
+    return 0;
+}
+
+struct file_operations mpc8313e_exio_fops =
+{
+	.owner =	THIS_MODULE,
+    .read = mpc8313e_exio_read,
+    .write = mpc8313e_exio_write,
+    .open = mpc8313e_exio_open,
+    .release = mpc8313e_exio_close  /* correspond a close */
+};
+
+static struct class * exio_class;
+
+static int __init mpc8313e_exio_init(void)
+{
+	int rc,i;
+
+	rc = register_chrdev(major, module_name, &mpc8313e_exio_fops);
+	if (rc < 0) {
+		return rc;
+	}
+
+	if (major == 0) {
+		major = rc;  /* accept dynamic major number */
+ 		printk(KERN_INFO "%s: successfully loaded with major %d\n",module_name, major);
+	}
+
+	exio_class = class_create(THIS_MODULE, "exio");
+
+	for (i = 0; i < NB_EXIO; i++)
+	{
+		device_create(exio_class, NULL,	MKDEV(major, i)	,NULL, "exio%i", i);
+
+	}
+
+	/* System I/O Configuration Register Low */
+	if (!(exio_mem = request_mem_region(EXIO_BASE, EXIO_SIZE, "mpc8313-exio")))
+		return -ENOMEM;
+
+	if (!(exio_io = ioremap(EXIO_BASE, EXIO_SIZE)))
+	{
+		release_mem_region(EXIO_BASE, EXIO_SIZE);
+		exio_mem = NULL;
+		return -ENOMEM;
+	}
+	iowrite8(exio_state, exio_io);
+
+	return 0;
+}
+
+static void __exit mpc8313e_exio_cleanup(void)
+{
+	if (exio_mem) release_mem_region(EXIO_BASE, EXIO_SIZE);
+	exio_mem = NULL;
+
+    unregister_chrdev(major, module_name);
+}
+
+module_param(major, int, 0644);
+MODULE_PARM_DESC(major, "Static major number (none = dynamic)");
+MODULE_AUTHOR("Alexandre Coffignal <alexandre.coffignal@cenosys.com>");
+MODULE_DESCRIPTION("mpc8313e exio");
+MODULE_LICENSE("GPL");
+
+module_init(mpc8313e_exio_init);
+module_exit(mpc8313e_exio_cleanup);
+
+
Index: Goobie-2.6-27/drivers/char/mpc8313e_gpio.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ Goobie-2.6-27/drivers/char/mpc8313e_gpio.c	2008-12-12 11:40:52.000000000 +0100
@@ -0,0 +1,148 @@
+/*
+* mpc8313e gpio driver
+*
+*
+* Copyright (C) 2007, CenoSYS (www.cenosys.com).
+* Alexandre Coffignal
+* alexandre.coffignal@cenosys.com
+*
+* This software program is licensed subject to the GNU General Public License
+* (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html
+*
+* Allows a user space process to control the GPIO pins.
+*
+*/
+
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <linux/of_platform.h>
+#include <sysdev/fsl_soc.h>
+
+static char module_name[] = "gpio";
+#define NB_GPIO	8
+static int major = 0;
+struct gpio {
+	__be32 gpdir;
+	__be32 gpodr;
+	__be32 gpdat;
+	__be32 gpier;
+	__be32 gpimr;
+	__be32 gpicr;
+} __attribute__ ((packed));
+static struct gpio *gpio_regs;
+
+static ssize_t mpc8313e_gpio_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
+{
+	unsigned m = iminor(file->f_path.dentry->d_inode);
+	size_t i;
+	int err = 0;
+
+	for (i = 0; i < len; ++i) {
+		char c;
+		if (get_user(c, data + i))
+			return -EFAULT;
+		/* set GPIO as output */
+		setbits32(&gpio_regs->gpdir, 1 << (31 - m));
+		clrbits32(&gpio_regs->gpodr, 1 << (31 - m));
+		switch (c) {
+		case '0':
+			/*Set GPIO level */
+			clrbits32(&gpio_regs->gpdat, 1 << (31 - m));
+			break;
+		case '1':
+			/*Set GPIO level */
+			setbits32(&gpio_regs->gpdat, 1 << (31 - m));
+			break;
+		default:
+			printk(KERN_DEBUG "io%2d bad setting: chr<0x%2x>\n",
+				m, (int)c);
+			err++;
+		}
+	}
+	if (err)
+		return -EINVAL;
+
+	return len;
+}
+
+static ssize_t mpc8313e_gpio_read(struct file *file, char __user * buf, size_t len, loff_t * ppos)
+{
+	unsigned m = iminor(file->f_path.dentry->d_inode);
+	int value;
+	value=in_be32(&gpio_regs->gpdat)&(1 << (31 - m));
+	if (put_user(value ? '1' : '0', buf))
+		return -EFAULT;
+	return 1;
+
+
+}
+
+
+
+static int mpc8313e_gpio_open(struct inode *inode, struct file *file)
+{
+    return 0;
+}
+
+static int mpc8313e_gpio_close(struct inode *inode, struct file *file)
+{
+    return 0;
+}
+
+struct file_operations mpc8313e_gpio_fops =
+{
+	.owner =	THIS_MODULE,
+    .read = mpc8313e_gpio_read,
+    .write = mpc8313e_gpio_write,
+    .open = mpc8313e_gpio_open,
+    .release = mpc8313e_gpio_close
+};
+static struct class * gpio_class;
+static int __init mpc8313e_gpio_init(void)
+{
+	int rc,i;
+
+	rc = register_chrdev(major, module_name, &mpc8313e_gpio_fops);
+	if (rc < 0) {
+		return rc;
+	}
+
+	if (major == 0) {
+		major = rc;  /* accept dynamic major number */
+ 		printk(KERN_INFO "%s: successfully loaded with major %d\n",module_name, major);
+
+	}
+	gpio_class = class_create(THIS_MODULE, "gpio");
+
+	for (i = 0; i < NB_GPIO; i++)
+	{
+		device_create(gpio_class, NULL,	MKDEV(major, i)	,NULL, "gpio%d",i);
+
+	}
+
+	/* System I/O Configuration Register Low */
+	gpio_regs = ioremap(get_immrbase() + 0xc00, 0x20);
+	if (!gpio_regs)
+		return -ENOMEM;
+    return 0;
+}
+
+static void __exit mpc8313e_gpio_cleanup(void)
+{
+    unregister_chrdev(major, module_name);
+}
+module_param(major, int, 0644);
+MODULE_PARM_DESC(major, "Static major number (none = dynamic)");
+MODULE_AUTHOR("Alexandre Coffignal <alexandre.coffignal@cenosys.com>");
+MODULE_DESCRIPTION("mpc8313e GPIO");
+MODULE_LICENSE("GPL");
+
+module_init(mpc8313e_gpio_init);
+module_exit(mpc8313e_gpio_cleanup);
+
+