add IXP4xx GPIOLIB support based on Chris' patch
[openwrt/svn-archive/archive.git] / target / linux / ixp4xx / patches-2.6.28 / 402-ixp4xx_gpiolib.patch
1 diff -ruN a/arch/arm/mach-ixp4xx/common.c b/arch/arm/mach-ixp4xx/common.c
2 --- a/arch/arm/mach-ixp4xx/common.c 2008-10-08 20:24:05.000000000 -0700
3 +++ b/arch/arm/mach-ixp4xx/common.c 2009-01-16 20:55:10.000000000 -0800
4 @@ -36,6 +36,7 @@
5 #include <asm/pgtable.h>
6 #include <asm/page.h>
7 #include <asm/irq.h>
8 +#include <asm/gpio.h>
9
10 #include <asm/mach/map.h>
11 #include <asm/mach/irq.h>
12 @@ -374,12 +375,39 @@
13 unsigned long ixp4xx_exp_bus_size;
14 EXPORT_SYMBOL(ixp4xx_exp_bus_size);
15
16 +static int ixp4xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
17 +{
18 + gpio_line_config(gpio, IXP4XX_GPIO_IN);
19 + return 0;
20 +}
21 +EXPORT_SYMBOL(ixp4xx_gpio_direction_input);
22 +
23 +static int ixp4xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
24 +{
25 + gpio_line_set(gpio, level);
26 + gpio_line_config(gpio, IXP4XX_GPIO_OUT);
27 + return 0;
28 +}
29 +EXPORT_SYMBOL(ixp4xx_gpio_direction_output);
30 +
31 +static struct gpio_chip ixp4xx_gpio_chip = {
32 + .label = "IXP4XX_GPIO_CHIP",
33 + .direction_input = ixp4xx_gpio_direction_input,
34 + .direction_output = ixp4xx_gpio_direction_output,
35 + .get = gpio_get_value,
36 + .set = gpio_set_value,
37 + .base = 0,
38 + .ngpio = 16,
39 +};
40 +
41 void __init ixp4xx_sys_init(void)
42 {
43 ixp4xx_exp_bus_size = SZ_16M;
44
45 platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
46
47 + gpiochip_add(&ixp4xx_gpio_chip);
48 +
49 if (cpu_is_ixp46x()) {
50 int region;
51
52 diff -ruN a/arch/arm/Kconfig b/arch/arm/Kconfig
53 --- a/arch/arm/Kconfig 2009-01-18 19:45:37.000000000 +0100
54 +++ b/arch/arm/Kconfig 2009-01-28 15:30:22.000000000 +0100
55 @@ -355,6 +355,7 @@
56 select GENERIC_GPIO
57 select GENERIC_TIME
58 select GENERIC_CLOCKEVENTS
59 + select ARCH_WANT_OPTIONAL_GPIOLIB
60 select DMABOUNCE if PCI
61 help
62 Support for Intel's IXP4XX (XScale) family of processors.
63 diff -ruN a/arch/arm/mach-ixp4xx/Kconfig b/arch/arm/mach-ixp4xx/Kconfig
64 --- a/arch/arm/mach-ixp4xx/Kconfig 2008-12-31 10:29:21.000000000 -0800
65 +++ b/arch/arm/mach-ixp4xx/Kconfig 2009-01-16 15:17:54.000000000 -0800
66 @@ -28,6 +28,7 @@
67 config MACH_CAMBRIA
68 bool "Cambria"
69 select PCI
70 + select GPIOLIB
71 help
72 Say 'Y' here if you want your kernel to support the Gateworks
73 Cambria series. For more information on this platform,
74
75 diff -ruN a/include/asm-arm/arch-ixp4xx/gpio.h b/include/asm-arm/arch-ixp4xx/gpio.h
76 --- a/arch/arm/mach-ixp4xx/include/mach/gpio.h 2008-10-08 20:24:05.000000000 -0700
77 +++ b/arch/arm/mach-ixp4xx/include/mach/gpio.h 2009-01-16 20:55:25.000000000 -0800
78 @@ -27,47 +27,31 @@
79
80 #include <linux/kernel.h>
81 #include <mach/hardware.h>
82 +#include <asm-generic/gpio.h> /* cansleep wrappers */
83
84 -static inline int gpio_request(unsigned gpio, const char *label)
85 -{
86 - return 0;
87 -}
88 -
89 -static inline void gpio_free(unsigned gpio)
90 -{
91 - might_sleep();
92 -
93 - return;
94 -}
95 -
96 -static inline int gpio_direction_input(unsigned gpio)
97 -{
98 - gpio_line_config(gpio, IXP4XX_GPIO_IN);
99 - return 0;
100 -}
101 -
102 -static inline int gpio_direction_output(unsigned gpio, int level)
103 -{
104 - gpio_line_set(gpio, level);
105 - gpio_line_config(gpio, IXP4XX_GPIO_OUT);
106 - return 0;
107 -}
108 +#define NR_BUILTIN_GPIO 16
109
110 static inline int gpio_get_value(unsigned gpio)
111 {
112 - int value;
113 -
114 - gpio_line_get(gpio, &value);
115 -
116 - return value;
117 + if (gpio < NR_BUILTIN_GPIO)
118 + {
119 + int value;
120 + gpio_line_get(gpio, &value);
121 + return value;
122 + }
123 + else
124 + return __gpio_get_value(gpio);
125 }
126
127 static inline void gpio_set_value(unsigned gpio, int value)
128 {
129 - gpio_line_set(gpio, value);
130 + if (gpio < NR_BUILTIN_GPIO)
131 + gpio_line_set(gpio, value);
132 + else
133 + __gpio_set_value(gpio, value);
134 }
135
136 -#include <asm-generic/gpio.h> /* cansleep wrappers */
137 +#define gpio_cansleep __gpio_cansleep
138
139 extern int gpio_to_irq(int gpio);
140 extern int irq_to_gpio(int gpio);