diff options
-rw-r--r-- | drivers/char/nsc_gpio.c | 97 | ||||
-rw-r--r-- | drivers/char/scx200_gpio.c | 88 | ||||
-rw-r--r-- | include/linux/nsc_gpio.h | 5 |
3 files changed, 100 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 | ||
22 | MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); | 22 | ssize_t nsc_gpio_write(struct file *file, const char __user *data, |
23 | MODULE_DESCRIPTION("NatSemi GPIO Common Methods"); | 23 | size_t len, loff_t *ppos) |
24 | MODULE_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 | |||
88 | ssize_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 */ | ||
103 | EXPORT_SYMBOL(nsc_gpio_write); | ||
104 | EXPORT_SYMBOL(nsc_gpio_read); | ||
25 | 105 | ||
26 | static int __init nsc_gpio_init(void) | 106 | static 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 | ||
39 | EXPORT_SYMBOL(scx200_gpio_write); | ||
40 | EXPORT_SYMBOL(scx200_gpio_read); | ||
41 | EXPORT_SYMBOL(scx200_gpio_release); | ||
42 | */ | ||
43 | |||
44 | module_init(nsc_gpio_init); | 117 | module_init(nsc_gpio_init); |
45 | module_exit(nsc_gpio_cleanup); | 118 | module_exit(nsc_gpio_cleanup); |
119 | |||
120 | MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); | ||
121 | MODULE_DESCRIPTION("NatSemi GPIO Common Methods"); | ||
122 | MODULE_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 | ||
38 | extern void scx200_gpio_dump(unsigned index); | 38 | extern void scx200_gpio_dump(unsigned index); |
39 | 39 | ||
40 | extern ssize_t nsc_gpio_write(struct file *file, const char __user *data, | ||
41 | size_t len, loff_t *ppos); | ||
42 | |||
43 | extern ssize_t nsc_gpio_read(struct file *file, char __user *buf, | ||
44 | size_t len, loff_t *ppos); | ||
45 | |||
40 | struct nsc_gpio_ops scx200_access = { | 46 | struct 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 | ||
52 | static 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 | |||
116 | static 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 | |||
130 | static int scx200_gpio_open(struct inode *inode, struct file *file) | 58 | static 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 | ||
146 | static struct file_operations scx200_gpio_fops = { | 74 | static 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 | }; |
diff --git a/include/linux/nsc_gpio.h b/include/linux/nsc_gpio.h index 3ad8ae9dcb5a..27bf66f73868 100644 --- a/include/linux/nsc_gpio.h +++ b/include/linux/nsc_gpio.h | |||
@@ -31,3 +31,8 @@ struct nsc_gpio_ops { | |||
31 | int (*gpio_current) (unsigned iminor); | 31 | int (*gpio_current) (unsigned iminor); |
32 | }; | 32 | }; |
33 | 33 | ||
34 | extern ssize_t nsc_gpio_write(struct file *file, const char __user *data, | ||
35 | size_t len, loff_t *ppos); | ||
36 | |||
37 | extern ssize_t nsc_gpio_read(struct file *file, char __user *buf, | ||
38 | size_t len, loff_t *ppos); | ||