aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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
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')
-rw-r--r--drivers/char/nsc_gpio.c97
-rw-r--r--drivers/char/scx200_gpio.c88
2 files changed, 95 insertions, 90 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");
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index 15dfb95ebc7e..eb9a84777598 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -37,6 +37,12 @@ MODULE_PARM_DESC(major, "Major device number");
37 37
38extern void scx200_gpio_dump(unsigned index); 38extern void scx200_gpio_dump(unsigned index);
39 39
40extern ssize_t nsc_gpio_write(struct file *file, const char __user *data,
41 size_t len, loff_t *ppos);
42
43extern ssize_t nsc_gpio_read(struct file *file, char __user *buf,
44 size_t len, loff_t *ppos);
45
40struct nsc_gpio_ops scx200_access = { 46struct nsc_gpio_ops scx200_access = {
41 .owner = THIS_MODULE, 47 .owner = THIS_MODULE,
42 .gpio_config = scx200_gpio_configure, 48 .gpio_config = scx200_gpio_configure,
@@ -49,84 +55,6 @@ struct nsc_gpio_ops scx200_access = {
49 .gpio_current = scx200_gpio_current 55 .gpio_current = scx200_gpio_current
50}; 56};
51 57
52static ssize_t scx200_gpio_write(struct file *file, const char __user *data,
53 size_t len, loff_t *ppos)
54{
55 unsigned m = iminor(file->f_dentry->d_inode);
56 struct nsc_gpio_ops *amp = file->private_data;
57 size_t i;
58 int err = 0;
59
60 for (i = 0; i < len; ++i) {
61 char c;
62 if (get_user(c, data + i))
63 return -EFAULT;
64 switch (c) {
65 case '0':
66 amp->gpio_set(m, 0);
67 break;
68 case '1':
69 amp->gpio_set(m, 1);
70 break;
71 case 'O':
72 printk(KERN_INFO NAME ": GPIO%d output enabled\n", m);
73 amp->gpio_config(m, ~1, 1);
74 break;
75 case 'o':
76 printk(KERN_INFO NAME ": GPIO%d output disabled\n", m);
77 amp->gpio_config(m, ~1, 0);
78 break;
79 case 'T':
80 printk(KERN_INFO NAME ": GPIO%d output is push pull\n", m);
81 amp->gpio_config(m, ~2, 2);
82 break;
83 case 't':
84 printk(KERN_INFO NAME ": GPIO%d output is open drain\n", m);
85 amp->gpio_config(m, ~2, 0);
86 break;
87 case 'P':
88 printk(KERN_INFO NAME ": GPIO%d pull up enabled\n", m);
89 amp->gpio_config(m, ~4, 4);
90 break;
91 case 'p':
92 printk(KERN_INFO NAME ": GPIO%d pull up disabled\n", m);
93 amp->gpio_config(m, ~4, 0);
94 break;
95
96 case 'v':
97 /* View Current pin settings */
98 amp->gpio_dump(m);
99 break;
100 case '\n':
101 /* end of settings string, do nothing */
102 break;
103 default:
104 printk(KERN_ERR NAME
105 ": GPIO-%2d bad setting: chr<0x%2x>\n", m,
106 (int)c);
107 err++;
108 }
109 }
110 if (err)
111 return -EINVAL; /* full string handled, report error */
112
113 return len;
114}
115
116static ssize_t scx200_gpio_read(struct file *file, char __user *buf,
117 size_t len, loff_t *ppos)
118{
119 unsigned m = iminor(file->f_dentry->d_inode);
120 int value;
121 struct nsc_gpio_ops *amp = file->private_data;
122
123 value = amp->gpio_get(m);
124 if (put_user(value ? '1' : '0', buf))
125 return -EFAULT;
126
127 return 1;
128}
129
130static int scx200_gpio_open(struct inode *inode, struct file *file) 58static int scx200_gpio_open(struct inode *inode, struct file *file)
131{ 59{
132 unsigned m = iminor(inode); 60 unsigned m = iminor(inode);
@@ -145,8 +73,8 @@ static int scx200_gpio_release(struct inode *inode, struct file *file)
145 73
146static struct file_operations scx200_gpio_fops = { 74static struct file_operations scx200_gpio_fops = {
147 .owner = THIS_MODULE, 75 .owner = THIS_MODULE,
148 .write = scx200_gpio_write, 76 .write = nsc_gpio_write,
149 .read = scx200_gpio_read, 77 .read = nsc_gpio_read,
150 .open = scx200_gpio_open, 78 .open = scx200_gpio_open,
151 .release = scx200_gpio_release, 79 .release = scx200_gpio_release,
152}; 80};