GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / char / scx200_gpio.c
blob99e5272e3c53e1ef1aa32f0733b1bbf0e9f2487e
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/device.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 <linux/platform_device.h>
15 #include <asm/uaccess.h>
16 #include <asm/io.h>
18 #include <linux/types.h>
19 #include <linux/cdev.h>
21 #include <linux/scx200_gpio.h>
22 #include <linux/nsc_gpio.h>
24 #define DRVNAME "scx200_gpio"
26 static struct platform_device *pdev;
28 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
29 MODULE_DESCRIPTION("NatSemi/AMD SCx200 GPIO Pin Driver");
30 MODULE_LICENSE("GPL");
32 static int major = 0; /* default to dynamic major */
33 module_param(major, int, 0);
34 MODULE_PARM_DESC(major, "Major device number");
36 #define MAX_PINS 32 /* 64 later, when known ok */
38 struct nsc_gpio_ops scx200_gpio_ops = {
39 .owner = THIS_MODULE,
40 .gpio_config = scx200_gpio_configure,
41 .gpio_dump = nsc_gpio_dump,
42 .gpio_get = scx200_gpio_get,
43 .gpio_set = scx200_gpio_set,
44 .gpio_change = scx200_gpio_change,
45 .gpio_current = scx200_gpio_current
47 EXPORT_SYMBOL_GPL(scx200_gpio_ops);
49 static int scx200_gpio_open(struct inode *inode, struct file *file)
51 unsigned m = iminor(inode);
52 file->private_data = &scx200_gpio_ops;
54 if (m >= MAX_PINS)
55 return -EINVAL;
56 return nonseekable_open(inode, file);
59 static int scx200_gpio_release(struct inode *inode, struct file *file)
61 return 0;
64 static const struct file_operations scx200_gpio_fileops = {
65 .owner = THIS_MODULE,
66 .write = nsc_gpio_write,
67 .read = nsc_gpio_read,
68 .open = scx200_gpio_open,
69 .release = scx200_gpio_release,
72 static struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
74 static int __init scx200_gpio_init(void)
76 int rc;
77 dev_t devid;
79 if (!scx200_gpio_present()) {
80 printk(KERN_ERR DRVNAME ": no SCx200 gpio present\n");
81 return -ENODEV;
84 /* support dev_dbg() with pdev->dev */
85 pdev = platform_device_alloc(DRVNAME, 0);
86 if (!pdev)
87 return -ENOMEM;
89 rc = platform_device_add(pdev);
90 if (rc)
91 goto undo_malloc;
93 /* nsc_gpio uses dev_dbg(), so needs this */
94 scx200_gpio_ops.dev = &pdev->dev;
96 if (major) {
97 devid = MKDEV(major, 0);
98 rc = register_chrdev_region(devid, MAX_PINS, "scx200_gpio");
99 } else {
100 rc = alloc_chrdev_region(&devid, 0, MAX_PINS, "scx200_gpio");
101 major = MAJOR(devid);
103 if (rc < 0) {
104 dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
105 goto undo_platform_device_add;
108 cdev_init(&scx200_gpio_cdev, &scx200_gpio_fileops);
109 cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
111 return 0; /* succeed */
113 undo_platform_device_add:
114 platform_device_del(pdev);
115 undo_malloc:
116 platform_device_put(pdev);
118 return rc;
121 static void __exit scx200_gpio_cleanup(void)
123 cdev_del(&scx200_gpio_cdev);
124 /* cdev_put(&scx200_gpio_cdev); */
126 unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
127 platform_device_unregister(pdev);
130 module_init(scx200_gpio_init);
131 module_exit(scx200_gpio_cleanup);