2 * linux/arch/arm/mach-w90p910/gpio.c
4 * Generic w90p910 GPIO handling
6 * Wan ZongShun <mcuos.com@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/clk.h>
14 #include <linux/errno.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
17 #include <linux/debugfs.h>
18 #include <linux/seq_file.h>
19 #include <linux/kernel.h>
20 #include <linux/list.h>
21 #include <linux/module.h>
23 #include <linux/gpio.h>
25 #include <mach/hardware.h>
27 #define GPIO_BASE (W90X900_VA_GPIO)
28 #define GPIO_DIR (0x04)
29 #define GPIO_OUT (0x08)
30 #define GPIO_IN (0x0C)
31 #define GROUPINERV (0x10)
32 #define GPIO_GPIO(Nb) (0x00000001 << (Nb))
33 #define to_w90p910_gpio_chip(c) container_of(c, struct w90p910_gpio_chip, chip)
35 #define W90P910_GPIO_CHIP(name, base_gpio, nr_gpio) \
39 .direction_input = w90p910_dir_input, \
40 .direction_output = w90p910_dir_output, \
41 .get = w90p910_gpio_get, \
42 .set = w90p910_gpio_set, \
48 struct w90p910_gpio_chip {
49 struct gpio_chip chip;
50 void __iomem *regbase; /* Base of group register*/
54 static int w90p910_gpio_get(struct gpio_chip *chip, unsigned offset)
56 struct w90p910_gpio_chip *w90p910_gpio = to_w90p910_gpio_chip(chip);
57 void __iomem *pio = w90p910_gpio->regbase + GPIO_IN;
60 regval = __raw_readl(pio);
61 regval &= GPIO_GPIO(offset);
66 static void w90p910_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
68 struct w90p910_gpio_chip *w90p910_gpio = to_w90p910_gpio_chip(chip);
69 void __iomem *pio = w90p910_gpio->regbase + GPIO_OUT;
73 spin_lock_irqsave(&w90p910_gpio->gpio_lock, flags);
75 regval = __raw_readl(pio);
78 regval |= GPIO_GPIO(offset);
80 regval &= ~GPIO_GPIO(offset);
82 __raw_writel(regval, pio);
84 spin_unlock_irqrestore(&w90p910_gpio->gpio_lock, flags);
87 static int w90p910_dir_input(struct gpio_chip *chip, unsigned offset)
89 struct w90p910_gpio_chip *w90p910_gpio = to_w90p910_gpio_chip(chip);
90 void __iomem *pio = w90p910_gpio->regbase + GPIO_DIR;
94 spin_lock_irqsave(&w90p910_gpio->gpio_lock, flags);
96 regval = __raw_readl(pio);
97 regval &= ~GPIO_GPIO(offset);
98 __raw_writel(regval, pio);
100 spin_unlock_irqrestore(&w90p910_gpio->gpio_lock, flags);
105 static int w90p910_dir_output(struct gpio_chip *chip, unsigned offset, int val)
107 struct w90p910_gpio_chip *w90p910_gpio = to_w90p910_gpio_chip(chip);
108 void __iomem *outreg = w90p910_gpio->regbase + GPIO_OUT;
109 void __iomem *pio = w90p910_gpio->regbase + GPIO_DIR;
113 spin_lock_irqsave(&w90p910_gpio->gpio_lock, flags);
115 regval = __raw_readl(pio);
116 regval |= GPIO_GPIO(offset);
117 __raw_writel(regval, pio);
119 regval = __raw_readl(outreg);
122 regval |= GPIO_GPIO(offset);
124 regval &= ~GPIO_GPIO(offset);
126 __raw_writel(regval, outreg);
128 spin_unlock_irqrestore(&w90p910_gpio->gpio_lock, flags);
133 static struct w90p910_gpio_chip w90p910_gpio[] = {
134 W90P910_GPIO_CHIP("GROUPC", 0, 16),
135 W90P910_GPIO_CHIP("GROUPD", 16, 10),
136 W90P910_GPIO_CHIP("GROUPE", 26, 14),
137 W90P910_GPIO_CHIP("GROUPF", 40, 10),
138 W90P910_GPIO_CHIP("GROUPG", 50, 17),
139 W90P910_GPIO_CHIP("GROUPH", 67, 8),
140 W90P910_GPIO_CHIP("GROUPI", 75, 17),
143 void __init w90p910_init_gpio(int nr_group)
146 struct w90p910_gpio_chip *gpio_chip;
148 for (i = 0; i < nr_group; i++) {
149 gpio_chip = &w90p910_gpio[i];
150 spin_lock_init(&gpio_chip->gpio_lock);
151 gpio_chip->regbase = GPIO_BASE + i * GROUPINERV;
152 gpiochip_add(&gpio_chip->chip);