aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-davinci/include/mach/gpio.h
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-09-08 02:41:04 -0400
committerKevin Hilman <khilman@deeprootsystems.com>2008-09-17 03:31:41 -0400
commitdce1115bc32d66237102a4c925e1e0a5e82b9945 (patch)
treead89ff75c84a433c6a3ca0d8829315edbdf52d0b /arch/arm/mach-davinci/include/mach/gpio.h
parentac7643e4d36c63b190709777d9e03392a7d20477 (diff)
ARM: DaVinci: SOC GPIOs use gpiolib
Switch DaVinci SOC gpios over to using the new GPIO library, so it can access GPIO expanders and other non-SOC GPIOs using the same calls. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
Diffstat (limited to 'arch/arm/mach-davinci/include/mach/gpio.h')
-rw-r--r--arch/arm/mach-davinci/include/mach/gpio.h73
1 files changed, 34 insertions, 39 deletions
diff --git a/arch/arm/mach-davinci/include/mach/gpio.h b/arch/arm/mach-davinci/include/mach/gpio.h
index ec151ccf1e8f..b3a2961f0f46 100644
--- a/arch/arm/mach-davinci/include/mach/gpio.h
+++ b/arch/arm/mach-davinci/include/mach/gpio.h
@@ -14,6 +14,7 @@
14#define __DAVINCI_GPIO_H 14#define __DAVINCI_GPIO_H
15 15
16#include <linux/io.h> 16#include <linux/io.h>
17#include <asm-generic/gpio.h>
17#include <mach/hardware.h> 18#include <mach/hardware.h>
18 19
19/* 20/*
@@ -27,13 +28,16 @@
27 * need to pay attention to PINMUX0 and PINMUX1 to be sure those pins are 28 * need to pay attention to PINMUX0 and PINMUX1 to be sure those pins are
28 * used as gpios, not with other peripherals. 29 * used as gpios, not with other peripherals.
29 * 30 *
30 * GPIOs are numbered 0..(DAVINCI_N_GPIO-1). For documentation, and maybe 31 * On-chip GPIOs are numbered 0..(DAVINCI_N_GPIO-1). For documentation,
31 * for later updates, code should write GPIO(N) or: 32 * and maybe for later updates, code should write GPIO(N) or:
32 * - GPIOV18(N) for 1.8V pins, N in 0..53; same as GPIO(0)..GPIO(53) 33 * - GPIOV18(N) for 1.8V pins, N in 0..53; same as GPIO(0)..GPIO(53)
33 * - GPIOV33(N) for 3.3V pins, N in 0..17; same as GPIO(54)..GPIO(70) 34 * - GPIOV33(N) for 3.3V pins, N in 0..17; same as GPIO(54)..GPIO(70)
34 * 35 *
35 * For GPIO IRQs use gpio_to_irq(GPIO(N)) or gpio_to_irq(GPIOV33(N)) etc 36 * For GPIO IRQs use gpio_to_irq(GPIO(N)) or gpio_to_irq(GPIOV33(N)) etc
36 * for now, that's != GPIO(N) 37 * for now, that's != GPIO(N)
38 *
39 * GPIOs can also be on external chips, numbered after the ones built-in
40 * to the DaVinci chip. For now, they won't be usable as IRQ sources.
37 */ 41 */
38#define GPIO(X) (X) /* 0 <= X <= 70 */ 42#define GPIO(X) (X) /* 0 <= X <= 70 */
39#define GPIOV18(X) (X) /* 1.8V i/o; 0 <= X <= 53 */ 43#define GPIOV18(X) (X) /* 1.8V i/o; 0 <= X <= 53 */
@@ -67,11 +71,11 @@ __gpio_to_controller(unsigned gpio)
67 void *__iomem ptr; 71 void *__iomem ptr;
68 72
69 if (gpio < 32) 73 if (gpio < 32)
70 ptr = (void *__iomem)IO_ADDRESS(DAVINCI_GPIO_BASE + 0x10); 74 ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x10);
71 else if (gpio < 64) 75 else if (gpio < 64)
72 ptr = (void *__iomem)IO_ADDRESS(DAVINCI_GPIO_BASE + 0x38); 76 ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x38);
73 else if (gpio < DAVINCI_N_GPIO) 77 else if (gpio < DAVINCI_N_GPIO)
74 ptr = (void *__iomem)IO_ADDRESS(DAVINCI_GPIO_BASE + 0x60); 78 ptr = IO_ADDRESS(DAVINCI_GPIO_BASE + 0x60);
75 else 79 else
76 ptr = NULL; 80 ptr = NULL;
77 return ptr; 81 return ptr;
@@ -83,25 +87,17 @@ static inline u32 __gpio_mask(unsigned gpio)
83} 87}
84 88
85/* The get/set/clear functions will inline when called with constant 89/* The get/set/clear functions will inline when called with constant
86 * parameters, for low-overhead bitbanging. Illegal constant parameters 90 * parameters referencing built-in GPIOs, for low-overhead bitbanging.
87 * cause link-time errors.
88 * 91 *
89 * Otherwise, calls with variable parameters use outlined functions. 92 * Otherwise, calls with variable parameters or referencing external
93 * GPIOs (e.g. on GPIO expander chips) use outlined functions.
90 */ 94 */
91extern int __error_inval_gpio(void);
92
93extern void __gpio_set(unsigned gpio, int value);
94extern int __gpio_get(unsigned gpio);
95
96static inline void gpio_set_value(unsigned gpio, int value) 95static inline void gpio_set_value(unsigned gpio, int value)
97{ 96{
98 if (__builtin_constant_p(value)) { 97 if (__builtin_constant_p(value) && gpio < DAVINCI_N_GPIO) {
99 struct gpio_controller *__iomem g; 98 struct gpio_controller *__iomem g;
100 u32 mask; 99 u32 mask;
101 100
102 if (gpio >= DAVINCI_N_GPIO)
103 __error_inval_gpio();
104
105 g = __gpio_to_controller(gpio); 101 g = __gpio_to_controller(gpio);
106 mask = __gpio_mask(gpio); 102 mask = __gpio_mask(gpio);
107 if (value) 103 if (value)
@@ -111,48 +107,47 @@ static inline void gpio_set_value(unsigned gpio, int value)
111 return; 107 return;
112 } 108 }
113 109
114 __gpio_set(gpio, value); 110 __gpio_set_value(gpio, value);
115} 111}
116 112
117/* Returns zero or nonzero; works for gpios configured as inputs OR 113/* Returns zero or nonzero; works for gpios configured as inputs OR
118 * as outputs. 114 * as outputs, at least for built-in GPIOs.
119 * 115 *
120 * NOTE: changes in reported values are synchronized to the GPIO clock. 116 * NOTE: for built-in GPIOs, changes in reported values are synchronized
121 * This is most easily seen after calling gpio_set_value() and then immediatly 117 * to the GPIO clock. This is easily seen after calling gpio_set_value()
122 * gpio_get_value(), where the gpio_get_value() would return the old value 118 * and then immediately gpio_get_value(), where the gpio_get_value() will
123 * until the GPIO clock ticks and the new value gets latched. 119 * return the old value until the GPIO clock ticks and the new value gets
120 * latched.
124 */ 121 */
125
126static inline int gpio_get_value(unsigned gpio) 122static inline int gpio_get_value(unsigned gpio)
127{ 123{
128 struct gpio_controller *__iomem g; 124 struct gpio_controller *__iomem g;
129
130 if (!__builtin_constant_p(gpio))
131 return __gpio_get(gpio);
132 125
133 if (gpio >= DAVINCI_N_GPIO) 126 if (!__builtin_constant_p(gpio) || gpio >= DAVINCI_N_GPIO)
134 return __error_inval_gpio(); 127 return __gpio_get_value(gpio);
135 128
136 g = __gpio_to_controller(gpio); 129 g = __gpio_to_controller(gpio);
137 return !!(__gpio_mask(gpio) & __raw_readl(&g->in_data)); 130 return __gpio_mask(gpio) & __raw_readl(&g->in_data);
138} 131}
139 132
140/* powerup default direction is IN */ 133static inline int gpio_cansleep(unsigned gpio)
141extern int gpio_direction_input(unsigned gpio); 134{
142extern int gpio_direction_output(unsigned gpio, int value); 135 if (__builtin_constant_p(gpio) && gpio < DAVINCI_N_GPIO)
143 136 return 0;
144#include <asm-generic/gpio.h> /* cansleep wrappers */ 137 else
145 138 return __gpio_cansleep(gpio);
146extern int gpio_request(unsigned gpio, const char *tag); 139}
147extern void gpio_free(unsigned gpio);
148 140
149static inline int gpio_to_irq(unsigned gpio) 141static inline int gpio_to_irq(unsigned gpio)
150{ 142{
143 if (gpio >= DAVINCI_N_GPIO)
144 return -EINVAL;
151 return DAVINCI_N_AINTC_IRQ + gpio; 145 return DAVINCI_N_AINTC_IRQ + gpio;
152} 146}
153 147
154static inline int irq_to_gpio(unsigned irq) 148static inline int irq_to_gpio(unsigned irq)
155{ 149{
150 /* caller guarantees gpio_to_irq() succeeded */
156 return irq - DAVINCI_N_AINTC_IRQ; 151 return irq - DAVINCI_N_AINTC_IRQ;
157} 152}
158 153