1 --- a/arch/arm/mach-cns3xxx/cns3420vb.c
2 +++ b/arch/arm/mach-cns3xxx/cns3420vb.c
3 @@ -213,7 +213,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 @@ -19,7 +19,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