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.
15 #include <linux/module.h>
16 #include <linux/init.h>
18 #include <linux/miscdevice.h>
19 #include <asm/uaccess.h>
26 static sb_t
*gpio_sbh
;
27 static int gpio_major
;
28 static devfs_handle_t gpio_dir
;
31 devfs_handle_t handle
;
40 gpio_open(struct inode
*inode
, struct file
* file
)
42 if (MINOR(inode
->i_rdev
) > ARRAYSIZE(gpio_file
))
50 gpio_release(struct inode
*inode
, struct file
* file
)
57 gpio_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
61 switch (MINOR(file
->f_dentry
->d_inode
->i_rdev
)) {
63 val
= sb_gpioin(gpio_sbh
);
66 val
= sb_gpioout(gpio_sbh
, 0, 0, GPIO_DRV_PRIORITY
);
69 val
= sb_gpioouten(gpio_sbh
, 0, 0, GPIO_DRV_PRIORITY
);
72 val
= sb_gpiocontrol(gpio_sbh
, 0, 0, GPIO_DRV_PRIORITY
);
78 if (put_user(val
, (u32
*) buf
))
85 gpio_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
89 if (get_user(val
, (u32
*) buf
))
92 switch (MINOR(file
->f_dentry
->d_inode
->i_rdev
)) {
96 sb_gpioout(gpio_sbh
, ~0, val
, GPIO_DRV_PRIORITY
);
99 sb_gpioouten(gpio_sbh
, ~0, val
, GPIO_DRV_PRIORITY
);
102 sb_gpiocontrol(gpio_sbh
, ~0, val
, GPIO_DRV_PRIORITY
);
111 static struct file_operations gpio_fops
= {
114 release
: gpio_release
,
124 if (!(gpio_sbh
= sb_kattach(SB_OSH
)))
127 sb_gpiosetcore(gpio_sbh
);
129 if ((gpio_major
= devfs_register_chrdev(0, "gpio", &gpio_fops
)) < 0)
132 gpio_dir
= devfs_mk_dir(NULL
, "gpio", NULL
);
134 for (i
= 0; i
< ARRAYSIZE(gpio_file
); i
++) {
135 gpio_file
[i
].handle
= devfs_register(gpio_dir
,
137 DEVFS_FL_DEFAULT
, gpio_major
, i
,
138 S_IFCHR
| S_IRUGO
| S_IWUGO
,
150 for (i
= 0; i
< ARRAYSIZE(gpio_file
); i
++)
151 devfs_unregister(gpio_file
[i
].handle
);
152 devfs_unregister(gpio_dir
);
153 devfs_unregister_chrdev(gpio_major
, "gpio");
157 module_init(gpio_init
);
158 module_exit(gpio_exit
);