1 From 302f69453721e5ee19f583339a3a646821d4a173 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Fri, 20 Feb 2015 23:58:54 +0100
4 Subject: [PATCH 2/6] MIPS: BCM63XX: switch to new gpio driver
6 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
8 arch/mips/bcm63xx/boards/board_common.c | 2 +
9 arch/mips/bcm63xx/gpio.c | 145 ++++++++++------------------------------------
10 arch/mips/bcm63xx/setup.c | 3 -
11 3 files changed, 32 insertions(+), 118 deletions(-)
13 --- a/arch/mips/bcm63xx/boards/board_common.c
14 +++ b/arch/mips/bcm63xx/boards/board_common.c
15 @@ -188,6 +188,8 @@ int __init board_register_devices(void)
19 + bcm63xx_gpio_init();
22 bcm63xx_uart_register(0);
24 --- a/arch/mips/bcm63xx/gpio.c
25 +++ b/arch/mips/bcm63xx/gpio.c
28 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
29 * Copyright (C) 2008-2011 Florian Fainelli <florian@openwrt.org>
30 + * Copyright (C) Jonas Gorski <jogo@openwrt.org>
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 -#include <linux/spinlock.h>
36 #include <linux/platform_device.h>
37 #include <linux/gpio/driver.h>
39 #include <bcm63xx_cpu.h>
40 #include <bcm63xx_gpio.h>
41 -#include <bcm63xx_io.h>
42 #include <bcm63xx_regs.h>
44 -static u32 gpio_out_low_reg;
46 -static void bcm63xx_gpio_out_low_reg_init(void)
47 +static void __init bcm63xx_gpio_init_one(int id, int dir, int data, int ngpio)
49 - switch (bcm63xx_get_cpu_id()) {
50 - case BCM6345_CPU_ID:
51 - gpio_out_low_reg = GPIO_DATA_LO_REG_6345;
54 - gpio_out_low_reg = GPIO_DATA_LO_REG;
59 -static DEFINE_SPINLOCK(bcm63xx_gpio_lock);
60 -static u32 gpio_out_low, gpio_out_high;
61 + struct resource res[2];
62 + struct bgpio_pdata pdata;
64 -static void bcm63xx_gpio_set(struct gpio_chip *chip,
65 - unsigned gpio, int val)
70 - unsigned long flags;
72 - if (gpio >= chip->ngpio)
76 - reg = gpio_out_low_reg;
80 - reg = GPIO_DATA_HI_REG;
81 - mask = 1 << (gpio - 32);
85 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
90 - bcm_gpio_writel(*v, reg);
91 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
93 + memset(res, 0, sizeof(res));
94 + memset(&pdata, 0, sizeof(pdata));
96 -static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio)
100 + res[0].flags = IORESOURCE_MEM;
101 + res[0].start = bcm63xx_regset_address(RSET_GPIO);
102 + res[0].start += dir;
104 - if (gpio >= chip->ngpio)
106 + res[0].end = res[0].start + 3;
109 - reg = gpio_out_low_reg;
112 - reg = GPIO_DATA_HI_REG;
113 - mask = 1 << (gpio - 32);
115 + res[1].flags = IORESOURCE_MEM;
116 + res[1].start = bcm63xx_regset_address(RSET_GPIO);
117 + res[1].start += data;
119 - return !!(bcm_gpio_readl(reg) & mask);
121 + res[1].end = res[1].start + 3;
123 -static int bcm63xx_gpio_set_direction(struct gpio_chip *chip,
124 - unsigned gpio, int dir)
129 - unsigned long flags;
131 - if (gpio >= chip->ngpio)
135 - reg = GPIO_CTL_LO_REG;
138 - reg = GPIO_CTL_HI_REG;
139 - mask = 1 << (gpio - 32);
142 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
143 - tmp = bcm_gpio_readl(reg);
144 - if (dir == BCM63XX_GPIO_DIR_IN)
148 - bcm_gpio_writel(tmp, reg);
149 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
150 + pdata.base = id * 32;
151 + pdata.ngpio = ngpio;
154 + platform_device_register_resndata(NULL, "bcm63xx-gpio", id, res, 2,
155 + &pdata, sizeof(pdata));
158 -static int bcm63xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
159 +int __init bcm63xx_gpio_init(void)
161 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_IN);
163 + int ngpio = bcm63xx_gpio_count();
166 -static int bcm63xx_gpio_direction_output(struct gpio_chip *chip,
167 - unsigned gpio, int value)
169 - bcm63xx_gpio_set(chip, gpio, value);
170 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_OUT);
172 + if (BCMCPU_IS_6345())
173 + data_low_reg = GPIO_DATA_LO_REG_6345;
175 + data_low_reg = GPIO_DATA_LO_REG;
177 + bcm63xx_gpio_init_one(0, GPIO_CTL_LO_REG, data_low_reg, min(ngpio, 32));
179 -static struct gpio_chip bcm63xx_gpio_chip = {
180 - .label = "bcm63xx-gpio",
181 - .direction_input = bcm63xx_gpio_direction_input,
182 - .direction_output = bcm63xx_gpio_direction_output,
183 - .get = bcm63xx_gpio_get,
184 - .set = bcm63xx_gpio_set,
190 -int __init bcm63xx_gpio_init(void)
192 - bcm63xx_gpio_out_low_reg_init();
193 + bcm63xx_gpio_init_one(1, GPIO_CTL_HI_REG, GPIO_DATA_HI_REG, ngpio - 32);
195 - gpio_out_low = bcm_gpio_readl(gpio_out_low_reg);
196 - if (!BCMCPU_IS_6345())
197 - gpio_out_high = bcm_gpio_readl(GPIO_DATA_HI_REG);
198 - bcm63xx_gpio_chip.ngpio = bcm63xx_gpio_count();
199 - pr_info("registering %d GPIOs\n", bcm63xx_gpio_chip.ngpio);
202 - return gpiochip_add_data(&bcm63xx_gpio_chip, NULL);
204 --- a/arch/mips/bcm63xx/setup.c
205 +++ b/arch/mips/bcm63xx/setup.c
206 @@ -164,9 +164,6 @@ void __init plat_mem_setup(void)
208 int __init bcm63xx_register_devices(void)
210 - /* register gpiochip */
211 - bcm63xx_gpio_init();
213 return board_register_devices();