aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/scx200_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/scx200_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/scx200_gpio.c')
-rw-r--r--drivers/char/scx200_gpio.c88
1 files changed, 8 insertions, 80 deletions
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};