aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/nsc_gpio.c
diff options
context:
space:
mode:
authorJim Cromie <jim.cromie@gmail.com>2006-06-27 05:54:20 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-27 20:32:43 -0400
commit1a66fdf083bf2b60c4d12feb970bc7373b59e33a (patch)
treef1e9d67e5c2fb3f9e7e575a6a9c44db3af6f6c22 /drivers/char/nsc_gpio.c
parent1ca5df0a4cbd17a9536e63c5f69d4717c6538eb0 (diff)
[PATCH] chardev: GPIO for SCx200 & PC-8736x: migrate file-ops to common module
Now that the read(), write() file-ops are dispatching gpio-ops via the vtable, they are generic, and can be moved 'verbatim' to the nsc_gpio common-support module. After the move, various symbols are renamed to update 'scx200_' to 'nsc_', and headers are adjusted accordingly. Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char/nsc_gpio.c')
-rw-r--r--drivers/char/nsc_gpio.c97
1 files changed, 87 insertions, 10 deletions
diff --git a/drivers/char/nsc_gpio.c b/drivers/char/nsc_gpio.c
index 42d95904967c..3842c2727118 100644
--- a/drivers/char/nsc_gpio.c
+++ b/drivers/char/nsc_gpio.c
@@ -19,9 +19,89 @@
19 19
20#define NAME "nsc_gpio" 20#define NAME "nsc_gpio"
21 21
22MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); 22ssize_t nsc_gpio_write(struct file *file, const char __user *data,
23MODULE_DESCRIPTION("NatSemi GPIO Common Methods"); 23 size_t len, loff_t *ppos)
24MODULE_LICENSE("GPL"); 24{
25 unsigned m = iminor(file->f_dentry->d_inode);
26 struct nsc_gpio_ops *amp = file->private_data;
27 size_t i;
28 int err = 0;
29
30 for (i = 0; i < len; ++i) {
31 char c;
32 if (get_user(c, data + i))
33 return -EFAULT;
34 switch (c) {
35 case '0':
36 amp->gpio_set(m, 0);
37 break;
38 case '1':
39 amp->gpio_set(m, 1);
40 break;
41 case 'O':
42 printk(KERN_INFO NAME ": GPIO%d output enabled\n", m);
43 amp->gpio_config(m, ~1, 1);
44 break;
45 case 'o':
46 printk(KERN_INFO NAME ": GPIO%d output disabled\n", m);
47 amp->gpio_config(m, ~1, 0);
48 break;
49 case 'T':
50 printk(KERN_INFO NAME ": GPIO%d output is push pull\n",
51 m);
52 amp->gpio_config(m, ~2, 2);
53 break;
54 case 't':
55 printk(KERN_INFO NAME ": GPIO%d output is open drain\n",
56 m);
57 amp->gpio_config(m, ~2, 0);
58 break;
59 case 'P':
60 printk(KERN_INFO NAME ": GPIO%d pull up enabled\n", m);
61 amp->gpio_config(m, ~4, 4);
62 break;
63 case 'p':
64 printk(KERN_INFO NAME ": GPIO%d pull up disabled\n", m);
65 amp->gpio_config(m, ~4, 0);
66 break;
67
68 case 'v':
69 /* View Current pin settings */
70 amp->gpio_dump(m);
71 break;
72 case '\n':
73 /* end of settings string, do nothing */
74 break;
75 default:
76 printk(KERN_ERR NAME
77 ": GPIO-%2d bad setting: chr<0x%2x>\n", m,
78 (int)c);
79 err++;
80 }
81 }
82 if (err)
83 return -EINVAL; /* full string handled, report error */
84
85 return len;
86}
87
88ssize_t nsc_gpio_read(struct file *file, char __user * buf,
89 size_t len, loff_t * ppos)
90{
91 unsigned m = iminor(file->f_dentry->d_inode);
92 int value;
93 struct nsc_gpio_ops *amp = file->private_data;
94
95 value = amp->gpio_get(m);
96 if (put_user(value ? '1' : '0', buf))
97 return -EFAULT;
98
99 return 1;
100}
101
102/* common routines for both scx200_gpio and pc87360_gpio */
103EXPORT_SYMBOL(nsc_gpio_write);
104EXPORT_SYMBOL(nsc_gpio_read);
25 105
26static int __init nsc_gpio_init(void) 106static int __init nsc_gpio_init(void)
27{ 107{
@@ -34,12 +114,9 @@ static void __exit nsc_gpio_cleanup(void)
34 printk(KERN_DEBUG NAME " cleanup\n"); 114 printk(KERN_DEBUG NAME " cleanup\n");
35} 115}
36 116
37/* prepare for
38 common routines for both scx200_gpio and pc87360_gpio
39EXPORT_SYMBOL(scx200_gpio_write);
40EXPORT_SYMBOL(scx200_gpio_read);
41EXPORT_SYMBOL(scx200_gpio_release);
42*/
43
44module_init(nsc_gpio_init); 117module_init(nsc_gpio_init);
45module_exit(nsc_gpio_cleanup); 118module_exit(nsc_gpio_cleanup);
119
120MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
121MODULE_DESCRIPTION("NatSemi GPIO Common Methods");
122MODULE_LICENSE("GPL");