4 * Copyright 2005, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
14 #include <linux/module.h>
15 #include <linux/init.h>
17 #include <linux/miscdevice.h>
18 #include <asm/uaccess.h>
25 static sb_t *gpio_sbh;
26 static int gpio_major;
27 static devfs_handle_t gpio_dir;
30 devfs_handle_t handle;
39 gpio_open(struct inode *inode, struct file * file)
41 if (MINOR(inode->i_rdev) > ARRAYSIZE(gpio_file))
49 gpio_release(struct inode *inode, struct file * file)
56 gpio_read(struct file *file, char *buf, size_t count, loff_t *ppos)
60 switch (MINOR(file->f_dentry->d_inode->i_rdev)) {
62 val = sb_gpioin(gpio_sbh);
65 val = sb_gpioout(gpio_sbh, 0, 0, GPIO_DRV_PRIORITY);
68 val = sb_gpioouten(gpio_sbh, 0, 0, GPIO_DRV_PRIORITY);
71 val = sb_gpiocontrol(gpio_sbh, 0, 0, GPIO_DRV_PRIORITY);
77 if (put_user(val, (u32 *) buf))
84 gpio_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
88 if (get_user(val, (u32 *) buf))
91 switch (MINOR(file->f_dentry->d_inode->i_rdev)) {
95 sb_gpioout(gpio_sbh, ~0, val, GPIO_DRV_PRIORITY);
98 sb_gpioouten(gpio_sbh, ~0, val, GPIO_DRV_PRIORITY);
101 sb_gpiocontrol(gpio_sbh, ~0, val, GPIO_DRV_PRIORITY);
110 static struct file_operations gpio_fops = {
113 release: gpio_release,
123 if (!(gpio_sbh = sb_kattach(SB_OSH)))
126 sb_gpiosetcore(gpio_sbh);
128 if ((gpio_major = devfs_register_chrdev(0, "gpio", &gpio_fops)) < 0)
131 gpio_dir = devfs_mk_dir(NULL, "gpio", NULL);
133 for (i = 0; i < ARRAYSIZE(gpio_file); i++) {
134 gpio_file[i].handle = devfs_register(gpio_dir,
136 DEVFS_FL_DEFAULT, gpio_major, i,
137 S_IFCHR | S_IRUGO | S_IWUGO,
149 for (i = 0; i < ARRAYSIZE(gpio_file); i++)
150 devfs_unregister(gpio_file[i].handle);
151 devfs_unregister(gpio_dir);
152 devfs_unregister_chrdev(gpio_major, "gpio");
156 module_init(gpio_init);
157 module_exit(gpio_exit);