2 +++ b/drivers/char/gemini_gpio_dev.c
5 + * GPIO driver for Gemini board
9 +#include <linux/version.h>
10 +#include <linux/kernel.h>
11 +#include <linux/module.h>
12 +#include <linux/init.h>
13 +#include <linux/proc_fs.h>
14 +#include <linux/fcntl.h>
15 +#include <linux/miscdevice.h>
16 +#include <asm/uaccess.h> /* copy_to_user, copy_from_user */
18 +#include <asm/hardware.h>
20 +#include <asm/arch/sl2312.h>
21 +#include <asm/arch/irqs.h>
22 +#include <asm/arch/gemini_gpio.h>
24 +#define GEMINI_GPIO_BASE1 IO_ADDRESS(SL2312_GPIO_BASE)
25 +#define GEMINI_GPIO_BASE2 IO_ADDRESS(SL2312_GPIO_BASE1)
28 +#define MAX_GPIO_LINE 32*GPIO_SET
30 +wait_queue_head_t gemini_gpio_wait[MAX_GPIO_LINE];
34 + GPIO_DATA_OUT = 0x00,
35 + GPIO_DATA_IN = 0x04,
36 + GPIO_PIN_DIR = 0x08,
37 + GPIO_BY_PASS = 0x0C,
38 + GPIO_DATA_SET = 0x10,
39 + GPIO_DATA_CLEAR = 0x14,
40 + GPIO_PULL_ENABLE = 0x18,
41 + GPIO_PULL_TYPE = 0x1C,
42 + GPIO_INT_ENABLE = 0x20,
43 + GPIO_INT_RAW_STATUS = 0x24,
44 + GPIO_INT_MASK_STATUS = 0x28,
45 + GPIO_INT_MASK = 0x2C,
46 + GPIO_INT_CLEAR = 0x30,
47 + GPIO_INT_TRIG = 0x34,
48 + GPIO_INT_BOTH = 0x38,
49 + GPIO_INT_POLAR = 0x3C
52 +unsigned int regist_gpio_int0=0,regist_gpio_int1=0;
54 +/* defines a specific GPIO bit number and state */
57 + unsigned char state;
60 +#define GPIO_MAJOR 10
61 +#define GPIO_MINOR 127
64 + * ioctl calls that are permitted to the /dev/gpio interface
66 +#define GPIO_GET_BIT 0x0000001
67 +#define GPIO_SET_BIT 0x0000002
68 +#define GPIO_GET_CONFIG 0x0000003
69 +#define GPIO_SET_CONFIG 0x0000004
71 +//#define GPIO_CONFIG_OUT 1
72 +//#define GPIO_CONFIG_IN 2
76 +#define DEVICE_NAME "gpio"
85 +static int gpio_ioctl(struct inode *inode, struct file *file,
86 + unsigned int cmd, unsigned long arg);
88 +/* /proc/driver/gpio */
89 +static int gpio_read_proc(char *page, char **start, off_t off,
90 + int count, int *eof, void *data);
92 +static unsigned char gpio_status; /* bitmapped status byte. */
94 +/* functions for set/get gpio lines on storlink cpu */
96 +void gpio_line_get(unsigned char pin, u32 * data)
98 + unsigned int set = pin >>5; // each GPIO set has 32 pins
99 + unsigned int status,addr;
101 + addr = (set ? GEMINI_GPIO_BASE2:GEMINI_GPIO_BASE1) + GPIO_DATA_IN;
102 + status = readl(addr);
104 + printk("status = %08X, pin = %d, set = %d\n", status, pin, set);
107 + *data = (status&(1<<(pin-32)))?1:0;
109 + *data = (status&(1<<pin))?1:0;
112 +void gpio_line_set(unsigned char pin, u32 high)
114 + unsigned char set = pin >>5; // each GPIO set has 32 pins
115 + unsigned int status=0,addr;
117 + addr = (set ? GEMINI_GPIO_BASE2:GEMINI_GPIO_BASE1)+(high?GPIO_DATA_SET:GPIO_DATA_CLEAR);
119 + status &= ~(1 << (pin %32));
120 + status |= (1 << (pin % 32));
121 + writel(status,addr);
130 +void gpio_line_config(unsigned char pin, unsigned char mode)
132 + unsigned char set = pin >>5; // each GPIO set has 32 pins
133 + unsigned int status,addr;
135 + addr = (set ? GEMINI_GPIO_BASE2:GEMINI_GPIO_BASE1)+GPIO_PIN_DIR;
136 + status = readl(addr);
138 + status &= ~(1 << (pin %32));
140 + status |= (1 << (pin % 32)); /* PinDir: 0 - input, 1 - output */
142 + writel(status,addr);
144 + /* enable pullup-high if mode is input */
146 + addr = (set ? GEMINI_GPIO_BASE2:GEMINI_GPIO_BASE1)+GPIO_PULL_ENABLE;
147 + status = readl(addr);
149 + status &= ~(1 << (pin %32));
150 + if (mode == 2) /* input */
151 + status |= (1 << (pin % 32)); /* PullEnable: 0 - disable, 1 - enable */
153 + writel(status,addr);
155 + addr = (set ? GEMINI_GPIO_BASE2:GEMINI_GPIO_BASE1)+GPIO_PULL_TYPE;
156 + status = readl(addr);
158 + status &= ~(1 << (pin %32));
159 + if (mode == 2) /* input */
160 + status |= (1 << (pin % 32)); /* PullType: 0 - low, 1 - high */
162 + writel(status,addr);
166 +#define GPIO_IS_OPEN 0x01 /* means /dev/gpio is in use */
169 + * Now all the various file operations that we export.
171 +static int gpio_ioctl(struct inode *inode, struct file *file,
172 + unsigned int cmd, unsigned long arg)
174 + struct gpio_bit bit;
177 + if (copy_from_user(&bit, (struct gpio_bit *)arg,
184 + gpio_line_get(bit.bit, &val);
186 + return copy_to_user((void *)arg, &bit, sizeof(bit)) ? -EFAULT : 0;
189 + gpio_line_set(bit.bit, val);
191 + case GPIO_GET_CONFIG:
192 + // gpio_line_config(bit.bit, bit.state);
193 + return copy_to_user((void *)arg, &bit, sizeof(bit)) ? -EFAULT : 0;
194 + case GPIO_SET_CONFIG:
196 + gpio_line_config(bit.bit, bit.state);
203 +static int gpio_open(struct inode *inode, struct file *file)
205 + if (gpio_status & GPIO_IS_OPEN)
208 + gpio_status |= GPIO_IS_OPEN;
213 +static int gpio_release(struct inode *inode, struct file *file)
216 + * Turn off all interrupts once the device is no longer
217 + * in use and clear the data.
220 + gpio_status &= ~GPIO_IS_OPEN;
226 + * The various file operations we support.
229 +static struct file_operations gpio_fops = {
230 + .owner = THIS_MODULE,
231 + .ioctl = gpio_ioctl,
233 + .release = gpio_release,
236 +static struct miscdevice gpio_dev =
238 + .minor = GPIO_MINOR,
240 + .fops = &gpio_fops,
246 +#ifdef CONFIG_PROC_FS
247 +static struct proc_dir_entry *dir;
250 + * Info exported via "/proc/driver/gpio".
252 +static int gpio_get_status(char *buf)
261 + for (i = 0; i < 0x20; i+=4 ) {
262 + addr = IO_ADDRESS(SL2312_GPIO_BASE) + i;
264 + p+=sprintf(p, "GPIO0: 0x%02X: %08X\n", i, val );
266 + for (i = 0; i < 0x20; i+=4 ) {
267 + addr = IO_ADDRESS(SL2312_GPIO_BASE1) + i;
269 + p+=sprintf(p, "GPIO1: 0x%02X: %08X\n", i, val );
273 + for (i = 0; i < 32; i++) {
274 + gpio_line_get(i, &bit);
278 + p += sprintf(p, "gpio0\t: 0x%08x\n", val);
281 + for (i = 32; i < 64; i++) {
282 + gpio_line_get(i, &bit);
286 + p += sprintf(p, "gpio1\t: 0x%08x\n", val);
292 +/* /proc/driver/gpio read op
294 +static int gpio_read_proc(char *page, char **start, off_t off,
295 + int count, int *eof, void *data)
297 + int len = gpio_get_status (page);
299 + if (len <= off+count)
301 + *start = page + off;
309 +#endif /* CONFIG_PROC_FS */
312 +static int __init gpio_init_module(void)
315 +#ifdef CONFIG_PROC_FS
316 + struct proc_dir_entry *res;
319 + /* register /dev/gpio file ops */
320 + //retval = register_chrdev(GPIO_MAJOR, DEVICE_NAME, &gpio_fops);
321 + retval = misc_register(&gpio_dev);
325 +#ifdef CONFIG_PROC_FS
326 + dir = proc_mkdir("driver/gpio", NULL);
328 + misc_deregister(&gpio_dev);
331 + /* register /proc/driver/gpio */
332 + res = create_proc_entry("info", 0644, dir);
334 + res->read_proc= gpio_read_proc;
336 + misc_deregister(&gpio_dev);
341 + printk("%s: GPIO driver loaded\n", __FILE__);
346 +static void __exit gpio_cleanup_module(void)
348 + remove_proc_entry ("info", dir);
349 + misc_deregister(&gpio_dev);
351 + printk("%s: GPIO driver unloaded\n", __FILE__);
354 +module_init(gpio_init_module);
355 +module_exit(gpio_cleanup_module);
357 +MODULE_AUTHOR("Jonas Majauskas");
358 +MODULE_LICENSE("GPL");
360 --- a/drivers/char/Kconfig
361 +++ b/drivers/char/Kconfig
362 @@ -1071,5 +1071,12 @@ config DEVPORT
364 source "drivers/s390/char/Kconfig"
366 +config GEMINI_GPIO_DEV
367 + tristate "GPIO driver for Gemini board (provides /dev/gpio)"
368 + depends on ARCH_SL2312
371 + GPIO driver for Gemini boards - SL3512, SL3516.
375 --- a/drivers/char/Makefile
376 +++ b/drivers/char/Makefile
377 @@ -116,6 +116,7 @@ obj-$(CONFIG_IPMI_HANDLER) += ipmi/
379 obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
380 obj-$(CONFIG_TCG_TPM) += tpm/
381 +obj-$(CONFIG_GEMINI_GPIO_DEV) += gemini_gpio_dev.o
383 obj-$(CONFIG_PS3_FLASH) += ps3flash.o