[ALSA] ad1848 - Add PM support
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / char / scx200_gpio.c
blob664a6e97eb1a8012475625af6383825a3d885e20
1 /* linux/drivers/char/scx200_gpio.c
3 National Semiconductor SCx200 GPIO driver. Allows a user space
4 process to play with the GPIO pins.
6 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> */
8 #include <linux/config.h>
9 #include <linux/fs.h>
10 #include <linux/module.h>
11 #include <linux/errno.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <asm/uaccess.h>
15 #include <asm/io.h>
17 #include <linux/scx200_gpio.h>
19 #define NAME "scx200_gpio"
21 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
22 MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver");
23 MODULE_LICENSE("GPL");
25 static int major = 0; /* default to dynamic major */
26 module_param(major, int, 0);
27 MODULE_PARM_DESC(major, "Major device number");
29 static ssize_t scx200_gpio_write(struct file *file, const char __user *data,
30 size_t len, loff_t *ppos)
32 unsigned m = iminor(file->f_dentry->d_inode);
33 size_t i;
35 for (i = 0; i < len; ++i) {
36 char c;
37 if (get_user(c, data+i))
38 return -EFAULT;
39 switch (c)
41 case '0':
42 scx200_gpio_set(m, 0);
43 break;
44 case '1':
45 scx200_gpio_set(m, 1);
46 break;
47 case 'O':
48 printk(KERN_INFO NAME ": GPIO%d output enabled\n", m);
49 scx200_gpio_configure(m, ~1, 1);
50 break;
51 case 'o':
52 printk(KERN_INFO NAME ": GPIO%d output disabled\n", m);
53 scx200_gpio_configure(m, ~1, 0);
54 break;
55 case 'T':
56 printk(KERN_INFO NAME ": GPIO%d output is push pull\n", m);
57 scx200_gpio_configure(m, ~2, 2);
58 break;
59 case 't':
60 printk(KERN_INFO NAME ": GPIO%d output is open drain\n", m);
61 scx200_gpio_configure(m, ~2, 0);
62 break;
63 case 'P':
64 printk(KERN_INFO NAME ": GPIO%d pull up enabled\n", m);
65 scx200_gpio_configure(m, ~4, 4);
66 break;
67 case 'p':
68 printk(KERN_INFO NAME ": GPIO%d pull up disabled\n", m);
69 scx200_gpio_configure(m, ~4, 0);
70 break;
74 return len;
77 static ssize_t scx200_gpio_read(struct file *file, char __user *buf,
78 size_t len, loff_t *ppos)
80 unsigned m = iminor(file->f_dentry->d_inode);
81 int value;
83 value = scx200_gpio_get(m);
84 if (put_user(value ? '1' : '0', buf))
85 return -EFAULT;
87 return 1;
90 static int scx200_gpio_open(struct inode *inode, struct file *file)
92 unsigned m = iminor(inode);
93 if (m > 63)
94 return -EINVAL;
95 return nonseekable_open(inode, file);
98 static int scx200_gpio_release(struct inode *inode, struct file *file)
100 return 0;
104 static struct file_operations scx200_gpio_fops = {
105 .owner = THIS_MODULE,
106 .write = scx200_gpio_write,
107 .read = scx200_gpio_read,
108 .open = scx200_gpio_open,
109 .release = scx200_gpio_release,
112 static int __init scx200_gpio_init(void)
114 int r;
116 printk(KERN_DEBUG NAME ": NatSemi SCx200 GPIO Driver\n");
118 if (!scx200_gpio_present()) {
119 printk(KERN_ERR NAME ": no SCx200 gpio pins available\n");
120 return -ENODEV;
123 r = register_chrdev(major, NAME, &scx200_gpio_fops);
124 if (r < 0) {
125 printk(KERN_ERR NAME ": unable to register character device\n");
126 return r;
128 if (!major) {
129 major = r;
130 printk(KERN_DEBUG NAME ": got dynamic major %d\n", major);
133 return 0;
136 static void __exit scx200_gpio_cleanup(void)
138 unregister_chrdev(major, NAME);
141 module_init(scx200_gpio_init);
142 module_exit(scx200_gpio_cleanup);
145 Local variables:
146 compile-command: "make -k -C ../.. SUBDIRS=drivers/char modules"
147 c-basic-offset: 8
148 End: