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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
Index: linux-2.6.29/drivers/char/Kconfig
===================================================================
--- linux-2.6.29.orig/drivers/char/Kconfig 2009-03-24 00:12:14.000000000 +0100
+++ linux-2.6.29/drivers/char/Kconfig 2009-04-01 17:37:55.000000000 +0200
@@ -1020,6 +1020,24 @@
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
+ select LEDS_CLASS
+ 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: linux-2.6.29/drivers/char/Makefile
===================================================================
--- linux-2.6.29.orig/drivers/char/Makefile 2009-03-24 00:12:14.000000000 +0100
+++ linux-2.6.29/drivers/char/Makefile 2009-04-01 17:37:55.000000000 +0200
@@ -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: linux-2.6.29/drivers/char/mpc8313e_exio.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.29/drivers/char/mpc8313e_exio.c 2009-04-01 17:37:55.000000000 +0200
@@ -0,0 +1,240 @@
+/*
+* CPE Extender io driver
+*
+* Copyright (C) 2007, CenoSYS (www.cenosys.com).
+*
+* Alexandre Coffignal <alexandre.coffignal@cenosys.com>
+* Sylvain Giroudon <sylvain.giroudon@goobie.fr>
+*
+* 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>
+#include <linux/leds.h>
+
+static char module_name[] = "exio";
+
+
+#define NB_EXIO 8
+#define DEFAULT_STATE 0x58
+#define EXIO_BASE 0xfa000000
+#define EXIO_SIZE 0x2
+#define EXIO_LED_MASK 0x01
+
+static int major = 0;
+static u8 exio_state = DEFAULT_STATE;
+static void *exio_io = NULL;
+static struct resource *exio_mem = NULL;
+static struct class * exio_class = NULL;
+
+
+static void
+exio_led_set(struct led_classdev *led_cdev,
+ enum led_brightness value)
+{
+ if ( value )
+ exio_state &= ~EXIO_LED_MASK;
+ else
+ exio_state |= EXIO_LED_MASK;
+
+ iowrite8(exio_state, exio_io);
+}
+
+static struct led_classdev exio_led = {
+ .name = "boc:blue:status",
+ .brightness_set = exio_led_set,
+};
+
+static inline int
+exio_led_init(void)
+{
+ return led_classdev_register(NULL, &exio_led);
+}
+
+
+static inline void
+exio_led_exit(void)
+{
+ led_classdev_unregister(&exio_led);
+}
+
+
+static inline void
+exio_led_suspend(void)
+{
+ led_classdev_suspend(&exio_led);
+}
+
+
+static inline void
+exio_led_resume(void)
+{
+ led_classdev_resume(&exio_led);
+}
+
+
+static ssize_t 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;
+
+ 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 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 exio_open(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+static int exio_close(struct inode *inode, struct file *file)
+{
+ printk(KERN_DEBUG "close()\n");
+ return 0;
+}
+
+struct file_operations exio_fops =
+{
+ .owner = THIS_MODULE,
+ .read = exio_read,
+ .write = exio_write,
+ .open = exio_open,
+ .release = exio_close /* correspond a close */
+};
+
+
+static void exio_cleanup(void)
+{
+ if ( exio_mem )
+ release_mem_region(EXIO_BASE, EXIO_SIZE);
+ exio_mem = NULL;
+ exio_io = NULL;
+
+ if ( exio_class )
+ class_destroy(exio_class);
+ exio_class = NULL;
+
+ unregister_chrdev(major, module_name);
+}
+
+
+static int __init exio_init(void)
+{
+ int rc, i;
+
+ rc = register_chrdev(major, module_name, &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");
+ if ( exio_class == NULL )
+ goto out_cleanup;
+
+ 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 */
+ exio_mem = request_mem_region(EXIO_BASE, EXIO_SIZE, "exio");
+ if ( exio_mem == NULL )
+ goto out_cleanup;
+
+ exio_io = ioremap(EXIO_BASE, EXIO_SIZE);
+ if ( exio_io == NULL )
+ goto out_cleanup;
+
+ /* Output default exio state */
+ iowrite8(exio_state, exio_io);
+
+ /* Register led class entry for driving the Status led */
+ exio_led_init();
+
+ return 0;
+
+out_cleanup:
+ exio_cleanup();
+ return -ENOMEM;
+}
+
+static void __exit exio_exit(void)
+{
+ /* Unregister Status led */
+ exio_led_exit();
+
+ /* Cleanup all other gears */
+ exio_cleanup();
+}
+
+
+module_param(major, int, 0644);
+MODULE_PARM_DESC(major, "Static major number (none = dynamic)");
+MODULE_AUTHOR("Alexandre Coffignal <alexandre.coffignal@cenosys.com>");
+MODULE_DESCRIPTION("boc01 exio management");
+MODULE_LICENSE("GPL");
+
+module_init(exio_init);
+module_exit(exio_exit);
+
+
Index: linux-2.6.29/drivers/char/mpc8313e_gpio.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.29/drivers/char/mpc8313e_gpio.c 2009-04-01 17:37:55.000000000 +0200
@@ -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);
+
+
|