aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-davinci/gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-davinci/gpio.c')
-rw-r--r--arch/arm/mach-davinci/gpio.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/arch/arm/mach-davinci/gpio.c b/arch/arm/mach-davinci/gpio.c
index 93f7c686153a..c77683c3c3d2 100644
--- a/arch/arm/mach-davinci/gpio.c
+++ b/arch/arm/mach-davinci/gpio.c
@@ -22,28 +22,22 @@
22 22
23static DEFINE_SPINLOCK(gpio_lock); 23static DEFINE_SPINLOCK(gpio_lock);
24 24
25struct davinci_gpio {
26 struct gpio_chip chip;
27 struct gpio_controller __iomem *regs;
28 int irq_base;
29};
30
31#define chip2controller(chip) \ 25#define chip2controller(chip) \
32 container_of(chip, struct davinci_gpio, chip) 26 container_of(chip, struct davinci_gpio_controller, chip)
33 27
34static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; 28static struct davinci_gpio_controller chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
35 29
36/* create a non-inlined version */ 30/* create a non-inlined version */
37static struct gpio_controller __iomem __init *gpio2controller(unsigned gpio) 31static struct davinci_gpio_regs __iomem __init *gpio2regs(unsigned gpio)
38{ 32{
39 return __gpio_to_controller(gpio); 33 return __gpio_to_controller(gpio);
40} 34}
41 35
42static inline struct gpio_controller __iomem *irq2controller(int irq) 36static inline struct davinci_gpio_regs __iomem *irq2regs(int irq)
43{ 37{
44 struct gpio_controller __iomem *g; 38 struct davinci_gpio_regs __iomem *g;
45 39
46 g = (__force struct gpio_controller __iomem *)get_irq_chip_data(irq); 40 g = (__force struct davinci_gpio_regs __iomem *)get_irq_chip_data(irq);
47 41
48 return g; 42 return g;
49} 43}
@@ -60,8 +54,8 @@ static int __init davinci_gpio_irq_setup(void);
60static inline int __davinci_direction(struct gpio_chip *chip, 54static inline int __davinci_direction(struct gpio_chip *chip,
61 unsigned offset, bool out, int value) 55 unsigned offset, bool out, int value)
62{ 56{
63 struct davinci_gpio *d = chip2controller(chip); 57 struct davinci_gpio_controller *d = chip2controller(chip);
64 struct gpio_controller __iomem *g = d->regs; 58 struct davinci_gpio_regs __iomem *g = d->regs;
65 u32 temp; 59 u32 temp;
66 u32 mask = 1 << offset; 60 u32 mask = 1 << offset;
67 61
@@ -99,8 +93,8 @@ davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
99 */ 93 */
100static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) 94static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
101{ 95{
102 struct davinci_gpio *d = chip2controller(chip); 96 struct davinci_gpio_controller *d = chip2controller(chip);
103 struct gpio_controller __iomem *g = d->regs; 97 struct davinci_gpio_regs __iomem *g = d->regs;
104 98
105 return (1 << offset) & __raw_readl(&g->in_data); 99 return (1 << offset) & __raw_readl(&g->in_data);
106} 100}
@@ -111,8 +105,8 @@ static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
111static void 105static void
112davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 106davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
113{ 107{
114 struct davinci_gpio *d = chip2controller(chip); 108 struct davinci_gpio_controller *d = chip2controller(chip);
115 struct gpio_controller __iomem *g = d->regs; 109 struct davinci_gpio_regs __iomem *g = d->regs;
116 110
117 __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); 111 __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data);
118} 112}
@@ -150,7 +144,7 @@ static int __init davinci_gpio_setup(void)
150 if (chips[i].chip.ngpio > 32) 144 if (chips[i].chip.ngpio > 32)
151 chips[i].chip.ngpio = 32; 145 chips[i].chip.ngpio = 32;
152 146
153 chips[i].regs = gpio2controller(base); 147 chips[i].regs = gpio2regs(base);
154 148
155 gpiochip_add(&chips[i].chip); 149 gpiochip_add(&chips[i].chip);
156 } 150 }
@@ -174,7 +168,7 @@ pure_initcall(davinci_gpio_setup);
174 168
175static void gpio_irq_disable(unsigned irq) 169static void gpio_irq_disable(unsigned irq)
176{ 170{
177 struct gpio_controller __iomem *g = irq2controller(irq); 171 struct davinci_gpio_regs __iomem *g = irq2regs(irq);
178 u32 mask = (u32) get_irq_data(irq); 172 u32 mask = (u32) get_irq_data(irq);
179 173
180 __raw_writel(mask, &g->clr_falling); 174 __raw_writel(mask, &g->clr_falling);
@@ -183,7 +177,7 @@ static void gpio_irq_disable(unsigned irq)
183 177
184static void gpio_irq_enable(unsigned irq) 178static void gpio_irq_enable(unsigned irq)
185{ 179{
186 struct gpio_controller __iomem *g = irq2controller(irq); 180 struct davinci_gpio_regs __iomem *g = irq2regs(irq);
187 u32 mask = (u32) get_irq_data(irq); 181 u32 mask = (u32) get_irq_data(irq);
188 unsigned status = irq_desc[irq].status; 182 unsigned status = irq_desc[irq].status;
189 183
@@ -199,7 +193,7 @@ static void gpio_irq_enable(unsigned irq)
199 193
200static int gpio_irq_type(unsigned irq, unsigned trigger) 194static int gpio_irq_type(unsigned irq, unsigned trigger)
201{ 195{
202 struct gpio_controller __iomem *g = irq2controller(irq); 196 struct davinci_gpio_regs __iomem *g = irq2regs(irq);
203 u32 mask = (u32) get_irq_data(irq); 197 u32 mask = (u32) get_irq_data(irq);
204 198
205 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 199 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
@@ -228,7 +222,7 @@ static struct irq_chip gpio_irqchip = {
228static void 222static void
229gpio_irq_handler(unsigned irq, struct irq_desc *desc) 223gpio_irq_handler(unsigned irq, struct irq_desc *desc)
230{ 224{
231 struct gpio_controller __iomem *g = irq2controller(irq); 225 struct davinci_gpio_regs __iomem *g = irq2regs(irq);
232 u32 mask = 0xffff; 226 u32 mask = 0xffff;
233 227
234 /* we only care about one bank */ 228 /* we only care about one bank */
@@ -266,7 +260,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
266 260
267static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) 261static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
268{ 262{
269 struct davinci_gpio *d = chip2controller(chip); 263 struct davinci_gpio_controller *d = chip2controller(chip);
270 264
271 if (d->irq_base >= 0) 265 if (d->irq_base >= 0)
272 return d->irq_base + offset; 266 return d->irq_base + offset;
@@ -289,7 +283,7 @@ static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
289 283
290static int gpio_irq_type_unbanked(unsigned irq, unsigned trigger) 284static int gpio_irq_type_unbanked(unsigned irq, unsigned trigger)
291{ 285{
292 struct gpio_controller __iomem *g = irq2controller(irq); 286 struct davinci_gpio_regs __iomem *g = irq2regs(irq);
293 u32 mask = (u32) get_irq_data(irq); 287 u32 mask = (u32) get_irq_data(irq);
294 288
295 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 289 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
@@ -318,7 +312,7 @@ static int __init davinci_gpio_irq_setup(void)
318 u32 binten = 0; 312 u32 binten = 0;
319 unsigned ngpio, bank_irq; 313 unsigned ngpio, bank_irq;
320 struct davinci_soc_info *soc_info = &davinci_soc_info; 314 struct davinci_soc_info *soc_info = &davinci_soc_info;
321 struct gpio_controller __iomem *g; 315 struct davinci_gpio_regs __iomem *g;
322 316
323 ngpio = soc_info->gpio_num; 317 ngpio = soc_info->gpio_num;
324 318
@@ -367,7 +361,7 @@ static int __init davinci_gpio_irq_setup(void)
367 gpio_irqchip_unbanked.set_type = gpio_irq_type_unbanked; 361 gpio_irqchip_unbanked.set_type = gpio_irq_type_unbanked;
368 362
369 /* default trigger: both edges */ 363 /* default trigger: both edges */
370 g = gpio2controller(0); 364 g = gpio2regs(0);
371 __raw_writel(~0, &g->set_falling); 365 __raw_writel(~0, &g->set_falling);
372 __raw_writel(~0, &g->set_rising); 366 __raw_writel(~0, &g->set_rising);
373 367
@@ -392,7 +386,7 @@ static int __init davinci_gpio_irq_setup(void)
392 unsigned i; 386 unsigned i;
393 387
394 /* disabled by default, enabled only as needed */ 388 /* disabled by default, enabled only as needed */
395 g = gpio2controller(gpio); 389 g = gpio2regs(gpio);
396 __raw_writel(~0, &g->clr_falling); 390 __raw_writel(~0, &g->clr_falling);
397 __raw_writel(~0, &g->clr_rising); 391 __raw_writel(~0, &g->clr_rising);
398 392