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