1 --- a/arch/arm/mach-cns3xxx/cns3420vb.c
2 +++ b/arch/arm/mach-cns3xxx/cns3420vb.c
3 @@ -216,7 +216,7 @@ static struct map_desc cns3420_io_desc[]
5 static void __init cns3420_map_io(void)
8 + cns3xxx_common_init();
9 iotable_init(cns3420_io_desc, ARRAY_SIZE(cns3420_io_desc));
11 cns3420_early_serial_setup();
12 --- a/arch/arm/mach-cns3xxx/core.c
13 +++ b/arch/arm/mach-cns3xxx/core.c
15 #include <asm/hardware/gic.h>
16 #include <asm/smp_twd.h>
17 #include <asm/hardware/cache-l2x0.h>
18 +#include <asm/gpio.h>
19 #include <mach/cns3xxx.h>
22 @@ -72,12 +73,73 @@ static struct map_desc cns3xxx_io_desc[]
26 -void __init cns3xxx_map_io(void)
27 +static inline void gpio_line_config(u8 line, u32 direction)
32 + reg = __raw_readl(CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_DIR);
34 + __raw_writel(reg, CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_DIR);
36 + reg = __raw_readl(CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_DIR);
37 + reg |= (1 << (line - 32));
38 + __raw_writel(reg, CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_DIR);
42 + reg = __raw_readl(CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_DIR);
43 + reg &= ~(1 << line);
44 + __raw_writel(reg, CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_DIR);
46 + reg = __raw_readl(CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_DIR);
47 + reg &= ~(1 << (line - 32));
48 + __raw_writel(reg, CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_DIR);
53 +static int cns3xxx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
55 + gpio_line_config(gpio, CNS3XXX_GPIO_IN);
59 +static int cns3xxx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
61 + gpio_line_set(gpio, level);
62 + gpio_line_config(gpio, CNS3XXX_GPIO_OUT);
66 +static int cns3xxx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
68 + return gpio_get_value(gpio);
71 +static void cns3xxx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
73 + gpio_set_value(gpio, value);
76 +static struct gpio_chip cns3xxx_gpio_chip = {
77 + .label = "CNS3XXX_GPIO_CHIP",
78 + .direction_input = cns3xxx_gpio_direction_input,
79 + .direction_output = cns3xxx_gpio_direction_output,
80 + .get = cns3xxx_gpio_get_value,
81 + .set = cns3xxx_gpio_set_value,
86 +void __init cns3xxx_common_init(void)
88 #ifdef CONFIG_LOCAL_TIMERS
89 twd_base = (void __iomem *) CNS3XXX_TC11MP_TWD_BASE_VIRT;
91 iotable_init(cns3xxx_io_desc, ARRAY_SIZE(cns3xxx_io_desc));
93 + gpiochip_add(&cns3xxx_gpio_chip);
96 /* used by entry-macro.S */
97 --- a/arch/arm/mach-cns3xxx/core.h
98 +++ b/arch/arm/mach-cns3xxx/core.h
99 @@ -21,7 +21,7 @@ void __init cns3xxx_l2x0_init(void);
100 static inline void cns3xxx_l2x0_init(void) {}
101 #endif /* CONFIG_CACHE_L2X0 */
103 -void __init cns3xxx_map_io(void);
104 +void __init cns3xxx_common_init(void);
105 void __init cns3xxx_init_irq(void);
106 void cns3xxx_power_off(void);
107 void cns3xxx_restart(char, const char *);
108 --- a/arch/arm/Kconfig
109 +++ b/arch/arm/Kconfig
110 @@ -366,6 +366,7 @@ config ARCH_CLPS711X
112 bool "Cavium Networks CNS3XXX family"
114 + select ARCH_WANT_OPTIONAL_GPIOLIB
115 select GENERIC_CLOCKEVENTS
119 +++ b/arch/arm/mach-cns3xxx/include/mach/gpio.h
122 + * arch/arm/mach-cns3xxx/include/mach/gpio.h
124 + * CNS3xxx GPIO wrappers for arch-neutral GPIO calls
126 + * Copyright 2011 Gateworks Corporation
127 + * Chris Lang <clang@gateworks.com>
129 + * Based on IXP implementation by Milan Svoboda <msvoboda@ra.rockwell.com>
130 + * Based on PXA implementation by Philipp Zabel <philipp.zabel@gmail.com>
132 + * This program is free software; you can redistribute it and/or modify
133 + * it under the terms of the GNU General Public License as published by
134 + * the Free Software Foundation; either version 2 of the License, or
135 + * (at your option) any later version.
137 + * This program is distributed in the hope that it will be useful,
138 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140 + * GNU General Public License for more details.
142 + * You should have received a copy of the GNU General Public License
143 + * along with this program; if not, write to the Free Software
144 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
148 +#ifndef __ASM_ARCH_CNS3XXX_GPIO_H
149 +#define __ASM_ARCH_CNS3XXX_GPIO_H
151 +#include <linux/kernel.h>
152 +#include <linux/io.h>
153 +#include <mach/platform.h>
154 +#include <asm-generic/gpio.h> /* cansleep wrappers */
156 +#define NR_BUILTIN_GPIO 64
158 +#define CNS3XXX_GPIO_IN 0x0
159 +#define CNS3XXX_GPIO_OUT 0x1
161 +#define CNS3XXX_GPIO_LO 0
162 +#define CNS3XXX_GPIO_HI 1
164 +#define CNS3XXX_GPIO_OUTPUT 0x00
165 +#define CNS3XXX_GPIO_INPUT 0x04
166 +#define CNS3XXX_GPIO_DIR 0x08
167 +#define CNS3XXX_GPIO_SET 0x10
168 +#define CNS3XXX_GPIO_CLEAR 0x14
170 +static inline void gpio_line_get(u8 line, int *value)
173 + *value = ((__raw_readl(CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_INPUT) >> line) & 0x1);
175 + *value = ((__raw_readl(CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_INPUT) >> (line - 32)) & 0x1);
178 +static inline void gpio_line_set(u8 line, int value)
182 + __raw_writel((1 << line), CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_SET);
184 + __raw_writel((1 << line), CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_CLEAR);
187 + __raw_writel((1 << line), CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_SET);
189 + __raw_writel((1 << line), CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_CLEAR);
193 +static inline int gpio_get_value(unsigned gpio)
195 + if (gpio < NR_BUILTIN_GPIO)
198 + gpio_line_get(gpio, &value);
202 + return __gpio_get_value(gpio);
205 +static inline void gpio_set_value(unsigned gpio, int value)
207 + if (gpio < NR_BUILTIN_GPIO)
208 + gpio_line_set(gpio, value);
210 + __gpio_set_value(gpio, value);
213 +#define gpio_cansleep __gpio_cansleep
215 +extern int gpio_to_irq(int gpio);
216 +extern int irq_to_gpio(int gpio);