4 * Copyright (C) 2012, Broadcom Corporation. All Rights Reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $Id: gpio.c,v 1.5 2008-04-03 03:49:45 $
21 #include <linux/module.h>
22 #include <linux/init.h>
24 #include <linux/miscdevice.h>
25 #include <asm/uaccess.h>
32 static si_t
*gpio_sih
;
33 static int gpio_major
;
34 static devfs_handle_t gpio_dir
;
37 devfs_handle_t handle
;
46 gpio_open(struct inode
*inode
, struct file
* file
)
48 if (MINOR(inode
->i_rdev
) > ARRAYSIZE(gpio_file
))
56 gpio_release(struct inode
*inode
, struct file
* file
)
63 gpio_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
67 switch (MINOR(file
->f_dentry
->d_inode
->i_rdev
)) {
69 val
= si_gpioin(gpio_sih
);
72 val
= si_gpioout(gpio_sih
, 0, 0);
75 val
= si_gpioouten(gpio_sih
, 0, 0);
78 val
= si_gpiocontrol(gpio_sih
, 0, 0);
84 if (put_user(val
, (u32
*) buf
))
91 gpio_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
95 if (get_user(val
, (u32
*) buf
))
98 switch (MINOR(file
->f_dentry
->d_inode
->i_rdev
)) {
102 si_gpioout(gpio_sih
, ~0, val
);
105 si_gpioouten(gpio_sih
, ~0, val
);
108 si_gpiocontrol(gpio_sih
, ~0, val
);
117 static struct file_operations gpio_fops
= {
120 release
: gpio_release
,
130 if (!(gpio_sih
= si_kattach(SI_OSH
)))
133 si_gpiosetcore(gpio_sih
);
135 if ((gpio_major
= devfs_register_chrdev(0, "gpio", &gpio_fops
)) < 0)
138 gpio_dir
= devfs_mk_dir(NULL
, "gpio", NULL
);
140 for (i
= 0; i
< ARRAYSIZE(gpio_file
); i
++) {
141 gpio_file
[i
].handle
= devfs_register(gpio_dir
,
143 DEVFS_FL_DEFAULT
, gpio_major
, i
,
144 S_IFCHR
| S_IRUGO
| S_IWUGO
,
156 for (i
= 0; i
< ARRAYSIZE(gpio_file
); i
++)
157 devfs_unregister(gpio_file
[i
].handle
);
158 devfs_unregister(gpio_dir
);
159 devfs_unregister_chrdev(gpio_major
, "gpio");
163 module_init(gpio_init
);
164 module_exit(gpio_exit
);