aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-davinci/gpio.c
diff options
context:
space:
mode:
authorMark A. Greer <mgreer@mvista.com>2009-04-15 15:40:35 -0400
committerKevin Hilman <khilman@deeprootsystems.com>2009-05-28 18:16:30 -0400
commita994955cc091a8a51b7d7412174d9cf6de04d26b (patch)
tree14c62610ee3ec0aa59fa5df49d4bf5ac88c8eb4c /arch/arm/mach-davinci/gpio.c
parent951d6f6d703110790256abfce03ced117d2dcc6b (diff)
davinci: Make GPIO code more generic
The current gpio code needs to know the number of gpio irqs there are and what the bank irq number is. To determine those values, it checks the SoC type. It also assumes that the base address and the number of irqs the interrupt controller uses is fixed. To clean up the SoC checks and make it support different base addresses and interrupt controllers, have the SoC-specific code set those values in the soc_info structure and have the gpio code reference them there. Signed-off-by: Mark A. Greer <mgreer@mvista.com> Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
Diffstat (limited to 'arch/arm/mach-davinci/gpio.c')
-rw-r--r--arch/arm/mach-davinci/gpio.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/arch/arm/mach-davinci/gpio.c b/arch/arm/mach-davinci/gpio.c
index 40327b557d79..1b6532159c58 100644
--- a/arch/arm/mach-davinci/gpio.c
+++ b/arch/arm/mach-davinci/gpio.c
@@ -23,6 +23,7 @@
23#include <mach/cputype.h> 23#include <mach/cputype.h>
24#include <mach/irqs.h> 24#include <mach/irqs.h>
25#include <mach/hardware.h> 25#include <mach/hardware.h>
26#include <mach/common.h>
26#include <mach/gpio.h> 27#include <mach/gpio.h>
27 28
28#include <asm/mach/irq.h> 29#include <asm/mach/irq.h>
@@ -37,8 +38,6 @@ struct davinci_gpio {
37 38
38static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; 39static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
39 40
40static unsigned __initdata ngpio;
41
42/* create a non-inlined version */ 41/* create a non-inlined version */
43static struct gpio_controller __iomem * __init gpio2controller(unsigned gpio) 42static struct gpio_controller __iomem * __init gpio2controller(unsigned gpio)
44{ 43{
@@ -116,23 +115,16 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
116static int __init davinci_gpio_setup(void) 115static int __init davinci_gpio_setup(void)
117{ 116{
118 int i, base; 117 int i, base;
118 unsigned ngpio;
119 struct davinci_soc_info *soc_info = &davinci_soc_info;
119 120
120 /* The gpio banks conceptually expose a segmented bitmap, 121 /*
122 * The gpio banks conceptually expose a segmented bitmap,
121 * and "ngpio" is one more than the largest zero-based 123 * and "ngpio" is one more than the largest zero-based
122 * bit index that's valid. 124 * bit index that's valid.
123 */ 125 */
124 if (cpu_is_davinci_dm355()) { /* or dm335() */ 126 ngpio = soc_info->gpio_num;
125 ngpio = 104; 127 if (ngpio == 0) {
126 } else if (cpu_is_davinci_dm644x()) { /* or dm337() */
127 ngpio = 71;
128 } else if (cpu_is_davinci_dm646x()) {
129 /* NOTE: each bank has several "reserved" bits,
130 * unusable as GPIOs. Only 33 of the GPIO numbers
131 * are usable, and we're not rejecting the others.
132 */
133 ngpio = 43;
134 } else {
135 /* if cpu_is_davinci_dm643x() ngpio = 111 */
136 pr_err("GPIO setup: how many GPIOs?\n"); 128 pr_err("GPIO setup: how many GPIOs?\n");
137 return -EINVAL; 129 return -EINVAL;
138 } 130 }
@@ -279,17 +271,15 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
279static int __init davinci_gpio_irq_setup(void) 271static int __init davinci_gpio_irq_setup(void)
280{ 272{
281 unsigned gpio, irq, bank; 273 unsigned gpio, irq, bank;
282 unsigned bank_irq;
283 struct clk *clk; 274 struct clk *clk;
284 u32 binten = 0; 275 u32 binten = 0;
276 unsigned ngpio, bank_irq;
277 struct davinci_soc_info *soc_info = &davinci_soc_info;
278
279 ngpio = soc_info->gpio_num;
285 280
286 if (cpu_is_davinci_dm355()) { /* or dm335() */ 281 bank_irq = soc_info->gpio_irq;
287 bank_irq = IRQ_DM355_GPIOBNK0; 282 if (bank_irq == 0) {
288 } else if (cpu_is_davinci_dm644x()) {
289 bank_irq = IRQ_GPIOBNK0;
290 } else if (cpu_is_davinci_dm646x()) {
291 bank_irq = IRQ_DM646X_GPIOBNK0;
292 } else {
293 printk(KERN_ERR "Don't know first GPIO bank IRQ.\n"); 283 printk(KERN_ERR "Don't know first GPIO bank IRQ.\n");
294 return -EINVAL; 284 return -EINVAL;
295 } 285 }
@@ -329,8 +319,7 @@ static int __init davinci_gpio_irq_setup(void)
329 /* BINTEN -- per-bank interrupt enable. genirq would also let these 319 /* BINTEN -- per-bank interrupt enable. genirq would also let these
330 * bits be set/cleared dynamically. 320 * bits be set/cleared dynamically.
331 */ 321 */
332 __raw_writel(binten, (void *__iomem) 322 __raw_writel(binten, soc_info->gpio_base + 0x08);
333 IO_ADDRESS(DAVINCI_GPIO_BASE + 0x08));
334 323
335 printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0)); 324 printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
336 325