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>
27 static sb_t
*gpio_sbh
;
28 static int gpio_major
;
29 static devfs_handle_t gpio_dir
;
32 devfs_handle_t handle
;
41 gpio_open(struct inode
*inode
, struct file
* file
)
43 if (MINOR(inode
->i_rdev
) > ARRAYSIZE(gpio_file
))
51 gpio_release(struct inode
*inode
, struct file
* file
)
58 gpio_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
62 switch (MINOR(file
->f_dentry
->d_inode
->i_rdev
)) {
64 val
= sb_gpioin(gpio_sbh
);
67 val
= sb_gpioout(gpio_sbh
, 0, 0, GPIO_DRV_PRIORITY
);
70 val
= sb_gpioouten(gpio_sbh
, 0, 0, GPIO_DRV_PRIORITY
);
73 val
= sb_gpiocontrol(gpio_sbh
, 0, 0, GPIO_DRV_PRIORITY
);
79 if (put_user(val
, (u32
*) buf
))
86 gpio_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
90 if (get_user(val
, (u32
*) buf
))
93 switch (MINOR(file
->f_dentry
->d_inode
->i_rdev
)) {
97 sb_gpioout(gpio_sbh
, ~0, val
, GPIO_DRV_PRIORITY
);
100 sb_gpioouten(gpio_sbh
, ~0, val
, GPIO_DRV_PRIORITY
);
103 sb_gpiocontrol(gpio_sbh
, ~0, val
, GPIO_DRV_PRIORITY
);
112 static struct file_operations gpio_fops
= {
115 release
: gpio_release
,
125 if (!(gpio_sbh
= sb_kattach()))
128 sb_gpiosetcore(gpio_sbh
);
130 if ((gpio_major
= devfs_register_chrdev(0, "gpio", &gpio_fops
)) < 0)
133 gpio_dir
= devfs_mk_dir(NULL
, "gpio", NULL
);
135 for (i
= 0; i
< ARRAYSIZE(gpio_file
); i
++) {
136 gpio_file
[i
].handle
= devfs_register(gpio_dir
,
138 DEVFS_FL_DEFAULT
, gpio_major
, i
,
139 S_IFCHR
| S_IRUGO
| S_IWUGO
,
151 for (i
= 0; i
< ARRAYSIZE(gpio_file
); i
++)
152 devfs_unregister(gpio_file
[i
].handle
);
153 devfs_unregister(gpio_dir
);
154 devfs_unregister_chrdev(gpio_major
, "gpio");
158 module_init(gpio_init
);
159 module_exit(gpio_exit
);