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 - BUG_ON(gpio >= chip->ngpio);
75 - reg = gpio_out_low_reg;
79 - reg = GPIO_DATA_HI_REG;
80 - mask = 1 << (gpio - 32);
84 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
89 - bcm_gpio_writel(*v, reg);
90 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
92 + memset(res, 0, sizeof(res));
93 + memset(&pdata, 0, sizeof(pdata));
95 -static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio)
99 + res[0].flags = IORESOURCE_MEM;
100 + res[0].start = bcm63xx_regset_address(RSET_GPIO);
101 + res[0].start += dir;
103 - BUG_ON(gpio >= chip->ngpio);
104 + res[0].end = res[0].start + 3;
107 - reg = gpio_out_low_reg;
110 - reg = GPIO_DATA_HI_REG;
111 - mask = 1 << (gpio - 32);
113 + res[1].flags = IORESOURCE_MEM;
114 + res[1].start = bcm63xx_regset_address(RSET_GPIO);
115 + res[1].start += data;
117 - return !!(bcm_gpio_readl(reg) & mask);
119 + res[1].end = res[1].start + 3;
121 -static int bcm63xx_gpio_set_direction(struct gpio_chip *chip,
122 - unsigned gpio, int dir)
127 - unsigned long flags;
129 - BUG_ON(gpio >= chip->ngpio);
132 - reg = GPIO_CTL_LO_REG;
135 - reg = GPIO_CTL_HI_REG;
136 - mask = 1 << (gpio - 32);
139 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
140 - tmp = bcm_gpio_readl(reg);
141 - if (dir == BCM63XX_GPIO_DIR_IN)
145 - bcm_gpio_writel(tmp, reg);
146 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
147 + pdata.base = id * 32;
148 + pdata.ngpio = ngpio;
151 + platform_device_register_resndata(NULL, "bcm63xx-gpio", id, res, 2,
152 + &pdata, sizeof(pdata));
155 -static int bcm63xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
156 +int __init bcm63xx_gpio_init(void)
158 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_IN);
160 + int ngpio = bcm63xx_gpio_count();
163 -static int bcm63xx_gpio_direction_output(struct gpio_chip *chip,
164 - unsigned gpio, int value)
166 - bcm63xx_gpio_set(chip, gpio, value);
167 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_OUT);
169 + if (BCMCPU_IS_6345())
170 + data_low_reg = GPIO_DATA_LO_REG_6345;
172 + data_low_reg = GPIO_DATA_LO_REG;
174 + bcm63xx_gpio_init_one(0, GPIO_CTL_LO_REG, data_low_reg, min(ngpio, 32));
176 -static struct gpio_chip bcm63xx_gpio_chip = {
177 - .label = "bcm63xx-gpio",
178 - .direction_input = bcm63xx_gpio_direction_input,
179 - .direction_output = bcm63xx_gpio_direction_output,
180 - .get = bcm63xx_gpio_get,
181 - .set = bcm63xx_gpio_set,
187 -int __init bcm63xx_gpio_init(void)
189 - bcm63xx_gpio_out_low_reg_init();
190 + bcm63xx_gpio_init_one(1, GPIO_CTL_HI_REG, GPIO_DATA_HI_REG, ngpio - 32);
192 - gpio_out_low = bcm_gpio_readl(gpio_out_low_reg);
193 - if (!BCMCPU_IS_6345())
194 - gpio_out_high = bcm_gpio_readl(GPIO_DATA_HI_REG);
195 - bcm63xx_gpio_chip.ngpio = bcm63xx_gpio_count();
196 - pr_info("registering %d GPIOs\n", bcm63xx_gpio_chip.ngpio);
199 - return gpiochip_add_data(&bcm63xx_gpio_chip, NULL);
201 --- a/arch/mips/bcm63xx/setup.c
202 +++ b/arch/mips/bcm63xx/setup.c
203 @@ -164,9 +164,6 @@ void __init plat_mem_setup(void)
205 int __init bcm63xx_register_devices(void)
207 - /* register gpiochip */
208 - bcm63xx_gpio_init();
210 return board_register_devices();