2 * character device wrapper for generic gpio layer
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
18 * Feedback, Bugs... blogic@openwrt.org
23 #include <linux/module.h>
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <asm/uaccess.h>
29 #include <asm/atomic.h>
30 #include <linux/init.h>
31 #include <linux/genhd.h>
32 #include <linux/device.h>
33 #include <linux/platform_device.h>
34 #include <linux/gpio_dev.h>
36 #define DRVNAME "gpiodev"
37 #define DEVNAME "gpio"
40 static struct class *gpiodev_class
;
43 /* third argument of user space ioctl ('arg' here) contains the <pin> */
45 gpio_ioctl(struct inode
* inode
, struct file
* file
, unsigned int cmd
,
53 retval
= gpio_get_value(arg
);
56 gpio_set_value(arg
, 1);
59 gpio_set_value(arg
, 0);
62 retval
= gpio_direction_input(arg
);
65 retval
= gpio_direction_output(arg
, 0);
68 retval
= gpio_direction_output(arg
, 1);
71 /* should be first ioctl operation on <pin> */
72 retval
= gpio_request(arg
, DRVNAME
);
75 /* should be last ioctl operation on <pin> */
76 /* may be needed first if previous user missed this ioctl */
80 retval
= gpio_cansleep(arg
);
84 /* = -ENOTTY; // correct return but ... */
90 /* Allow co-incident opens */
92 gpio_open(struct inode
*inode
, struct file
*file
)
95 unsigned int dev_minor
= MINOR(inode
->i_rdev
);
99 printk(KERN_ERR DRVNAME
": trying to access unknown minor device -> %d\n", dev_minor
);
108 gpio_close(struct inode
* inode
, struct file
* file
)
110 /* could track all <pin>s requested by this fd and gpio_free()
116 struct file_operations gpio_fops
= {
123 gpio_probe(struct platform_device
*dev
)
127 dev_major
= register_chrdev(0, DEVNAME
, &gpio_fops
);
130 printk(KERN_ERR DRVNAME
": Error whilst opening %s \n", DEVNAME
);
134 gpiodev_class
= class_create(THIS_MODULE
, DRVNAME
);
135 device_create(gpiodev_class
, NULL
, MKDEV(dev_major
, 0), dev
, DEVNAME
);
136 printk(KERN_INFO DRVNAME
": gpio device registered with major %d\n", dev_major
);
142 gpio_remove(struct platform_device
*dev
)
144 unregister_chrdev(dev_major
, DEVNAME
);
149 platform_driver gpio_driver
= {
151 .remove
= gpio_remove
,
154 .owner
= THIS_MODULE
,
161 int ret
= platform_driver_register(&gpio_driver
);
163 printk(KERN_INFO DRVNAME
": Error registering platfom driver!\n");
171 platform_driver_unregister(&gpio_driver
);
174 module_init (gpio_mod_init
);
175 module_exit (gpio_mod_exit
);
177 MODULE_LICENSE("GPL");
178 MODULE_AUTHOR("John Crispin / OpenWrt +");
179 MODULE_DESCRIPTION("Character device for for generic gpio api");