aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-davinci/gpio.c
diff options
context:
space:
mode:
authorCyril Chemparathy <cyril@ti.com>2010-05-01 18:37:53 -0400
committerKevin Hilman <khilman@deeprootsystems.com>2010-05-06 18:02:08 -0400
commitc12f415a9144a76dc99df34f56ce3022207ad1d0 (patch)
tree6fa81f4b2494ab8d0bf4f6bd7f71b5c0bdae8ecb /arch/arm/mach-davinci/gpio.c
parent99e9e52de635728d7c89a0fdf79b307f3082cf3a (diff)
Davinci: gpio - register layout invariant inlines
This patch renders the inlined gpio accessors in gpio.h independent of the underlying controller's register layout. This is done by including three new fields in davinci_gpio_controller to hold the addresses of the set, clear, and in data registers. Other changes: 1. davinci_gpio_regs structure definition moved to gpio.c. This structure is no longer common across all davinci socs (davinci_gpio_controller is). 2. controller base address calculation code (gpio2controller()) moved to gpio.c as this was no longer necessary for the inline implementation. 3. modified inline range checks to use davinci_soc_info.gpio_num instead of DAVINCI_N_GPIO. Signed-off-by: Cyril Chemparathy <cyril@ti.com> Tested-by: Sandeep Paulraj <s-paulraj@ti.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.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/arch/arm/mach-davinci/gpio.c b/arch/arm/mach-davinci/gpio.c
index c77683c3c3d2..d241b4f2abe2 100644
--- a/arch/arm/mach-davinci/gpio.c
+++ b/arch/arm/mach-davinci/gpio.c
@@ -20,6 +20,19 @@
20 20
21#include <asm/mach/irq.h> 21#include <asm/mach/irq.h>
22 22
23struct davinci_gpio_regs {
24 u32 dir;
25 u32 out_data;
26 u32 set_data;
27 u32 clr_data;
28 u32 in_data;
29 u32 set_rising;
30 u32 clr_rising;
31 u32 set_falling;
32 u32 clr_falling;
33 u32 intstat;
34};
35
23static DEFINE_SPINLOCK(gpio_lock); 36static DEFINE_SPINLOCK(gpio_lock);
24 37
25#define chip2controller(chip) \ 38#define chip2controller(chip) \
@@ -27,10 +40,24 @@ static DEFINE_SPINLOCK(gpio_lock);
27 40
28static struct davinci_gpio_controller chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; 41static struct davinci_gpio_controller chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
29 42
30/* create a non-inlined version */
31static struct davinci_gpio_regs __iomem __init *gpio2regs(unsigned gpio) 43static struct davinci_gpio_regs __iomem __init *gpio2regs(unsigned gpio)
32{ 44{
33 return __gpio_to_controller(gpio); 45 void __iomem *ptr;
46 void __iomem *base = davinci_soc_info.gpio_base;
47
48 if (gpio < 32 * 1)
49 ptr = base + 0x10;
50 else if (gpio < 32 * 2)
51 ptr = base + 0x38;
52 else if (gpio < 32 * 3)
53 ptr = base + 0x60;
54 else if (gpio < 32 * 4)
55 ptr = base + 0x88;
56 else if (gpio < 32 * 5)
57 ptr = base + 0xb0;
58 else
59 ptr = NULL;
60 return ptr;
34} 61}
35 62
36static inline struct davinci_gpio_regs __iomem *irq2regs(int irq) 63static inline struct davinci_gpio_regs __iomem *irq2regs(int irq)
@@ -116,6 +143,7 @@ static int __init davinci_gpio_setup(void)
116 int i, base; 143 int i, base;
117 unsigned ngpio; 144 unsigned ngpio;
118 struct davinci_soc_info *soc_info = &davinci_soc_info; 145 struct davinci_soc_info *soc_info = &davinci_soc_info;
146 struct davinci_gpio_regs *regs;
119 147
120 /* 148 /*
121 * The gpio banks conceptually expose a segmented bitmap, 149 * The gpio banks conceptually expose a segmented bitmap,
@@ -144,11 +172,18 @@ static int __init davinci_gpio_setup(void)
144 if (chips[i].chip.ngpio > 32) 172 if (chips[i].chip.ngpio > 32)
145 chips[i].chip.ngpio = 32; 173 chips[i].chip.ngpio = 32;
146 174
147 chips[i].regs = gpio2regs(base); 175 regs = gpio2regs(base);
176 chips[i].regs = regs;
177 chips[i].set_data = &regs->set_data;
178 chips[i].clr_data = &regs->clr_data;
179 chips[i].in_data = &regs->in_data;
148 180
149 gpiochip_add(&chips[i].chip); 181 gpiochip_add(&chips[i].chip);
150 } 182 }
151 183
184 soc_info->gpio_ctlrs = chips;
185 soc_info->gpio_ctlrs_num = DIV_ROUND_UP(ngpio, 32);
186
152 davinci_gpio_irq_setup(); 187 davinci_gpio_irq_setup();
153 return 0; 188 return 0;
154} 189}