2 * linux/arch/arm/mach-w90x900/gpio.c
4 * Generic nuc900 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/driver.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))
34 #define NUC900_GPIO_CHIP(name, base_gpio, nr_gpio) \
38 .direction_input = nuc900_dir_input, \
39 .direction_output = nuc900_dir_output, \
40 .get = nuc900_gpio_get, \
41 .set = nuc900_gpio_set, \
47 struct nuc900_gpio_chip {
48 struct gpio_chip chip;
49 void __iomem *regbase; /* Base of group register*/
53 static int nuc900_gpio_get(struct gpio_chip *chip, unsigned offset)
55 struct nuc900_gpio_chip *nuc900_gpio = gpiochip_get_data(chip);
56 void __iomem *pio = nuc900_gpio->regbase + GPIO_IN;
59 regval = __raw_readl(pio);
60 regval &= GPIO_GPIO(offset);
65 static void nuc900_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
67 struct nuc900_gpio_chip *nuc900_gpio = gpiochip_get_data(chip);
68 void __iomem *pio = nuc900_gpio->regbase + GPIO_OUT;
72 spin_lock_irqsave(&nuc900_gpio->gpio_lock, flags);
74 regval = __raw_readl(pio);
77 regval |= GPIO_GPIO(offset);
79 regval &= ~GPIO_GPIO(offset);
81 __raw_writel(regval, pio);
83 spin_unlock_irqrestore(&nuc900_gpio->gpio_lock, flags);
86 static int nuc900_dir_input(struct gpio_chip *chip, unsigned offset)
88 struct nuc900_gpio_chip *nuc900_gpio = gpiochip_get_data(chip);
89 void __iomem *pio = nuc900_gpio->regbase + GPIO_DIR;
93 spin_lock_irqsave(&nuc900_gpio->gpio_lock, flags);
95 regval = __raw_readl(pio);
96 regval &= ~GPIO_GPIO(offset);
97 __raw_writel(regval, pio);
99 spin_unlock_irqrestore(&nuc900_gpio->gpio_lock, flags);
104 static int nuc900_dir_output(struct gpio_chip *chip, unsigned offset, int val)
106 struct nuc900_gpio_chip *nuc900_gpio = gpiochip_get_data(chip);
107 void __iomem *outreg = nuc900_gpio->regbase + GPIO_OUT;
108 void __iomem *pio = nuc900_gpio->regbase + GPIO_DIR;
112 spin_lock_irqsave(&nuc900_gpio->gpio_lock, flags);
114 regval = __raw_readl(pio);
115 regval |= GPIO_GPIO(offset);
116 __raw_writel(regval, pio);
118 regval = __raw_readl(outreg);
121 regval |= GPIO_GPIO(offset);
123 regval &= ~GPIO_GPIO(offset);
125 __raw_writel(regval, outreg);
127 spin_unlock_irqrestore(&nuc900_gpio->gpio_lock, flags);
132 static struct nuc900_gpio_chip nuc900_gpio[] = {
133 NUC900_GPIO_CHIP("GROUPC", 0, 16),
134 NUC900_GPIO_CHIP("GROUPD", 16, 10),
135 NUC900_GPIO_CHIP("GROUPE", 26, 14),
136 NUC900_GPIO_CHIP("GROUPF", 40, 10),
137 NUC900_GPIO_CHIP("GROUPG", 50, 17),
138 NUC900_GPIO_CHIP("GROUPH", 67, 8),
139 NUC900_GPIO_CHIP("GROUPI", 75, 17),
142 void __init nuc900_init_gpio(int nr_group)
145 struct nuc900_gpio_chip *gpio_chip;
147 for (i = 0; i < nr_group; i++) {
148 gpio_chip = &nuc900_gpio[i];
149 spin_lock_init(&gpio_chip->gpio_lock);
150 gpio_chip->regbase = GPIO_BASE + i * GROUPINERV;
151 gpiochip_add_data(&gpio_chip->chip, gpio_chip);