2 * Linux Broadcom BCM47xx GPIO char driver
4 * Copyright 2007, 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.
15 #include <linux/module.h>
16 #include <linux/init.h>
18 #include <linux/miscdevice.h>
19 #include <asm/uaccess.h>
26 #include <linux_gpio.h>
28 /* handle to the sb */
29 static sb_t
*gpio_sbh
;
31 /* major number assigned to the device and device handles */
32 static int gpio_major
;
33 devfs_handle_t gpiodev_handle
;
36 gpio_open(struct inode
*inode
, struct file
* file
)
43 gpio_release(struct inode
*inode
, struct file
* file
)
50 gpio_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
52 struct gpio_ioctl gpioioc
;
54 if (copy_from_user(&gpioioc
, (struct gpio_ioctl
*)arg
, sizeof(struct gpio_ioctl
)))
58 case GPIO_IOC_RESERVE
:
59 gpioioc
.val
= sb_gpioreserve(gpio_sbh
, gpioioc
.mask
, GPIO_APP_PRIORITY
);
61 case GPIO_IOC_RELEASE
:
63 * releasing the gpio doesn't change the current
64 * value on the GPIO last write value
65 * persists till some one overwrites it
67 gpioioc
.val
= sb_gpiorelease(gpio_sbh
, gpioioc
.mask
, GPIO_APP_PRIORITY
);
70 gpioioc
.val
= sb_gpioout(gpio_sbh
, gpioioc
.mask
, gpioioc
.val
,
74 gpioioc
.val
= sb_gpioouten(gpio_sbh
, gpioioc
.mask
, gpioioc
.val
,
78 gpioioc
.val
= sb_gpioin(gpio_sbh
);
83 if (copy_to_user((struct gpio_ioctl
*)arg
, &gpioioc
, sizeof(struct gpio_ioctl
)))
89 static struct file_operations gpio_fops
= {
92 release
: gpio_release
,
99 if (!(gpio_sbh
= sb_kattach(SB_OSH
)))
102 if ((gpio_major
= devfs_register_chrdev(0, "gpio", &gpio_fops
)) < 0)
105 gpiodev_handle
= devfs_register(NULL
, "gpio", DEVFS_FL_DEFAULT
,
106 gpio_major
, 0, S_IFCHR
| S_IRUGO
| S_IWUGO
,
115 if (gpiodev_handle
!= NULL
)
116 devfs_unregister(gpiodev_handle
);
117 gpiodev_handle
= NULL
;
118 devfs_unregister_chrdev(gpio_major
, "gpio");
122 module_init(gpio_init
);
123 module_exit(gpio_exit
);