1 From cc99dca188bb63ba390008e2f7fa62d0300233e0 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 | 147 +++++++------------------------
10 arch/mips/bcm63xx/setup.c | 3 -
11 3 files changed, 33 insertions(+), 119 deletions(-)
13 --- a/arch/mips/bcm63xx/boards/board_common.c
14 +++ b/arch/mips/bcm63xx/boards/board_common.c
15 @@ -204,6 +204,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/module.h>
35 -#include <linux/spinlock.h>
36 #include <linux/platform_device.h>
37 +#include <linux/basic_mmio_gpio.h>
38 #include <linux/gpio.h>
40 #include <bcm63xx_cpu.h>
41 #include <bcm63xx_gpio.h>
42 -#include <bcm63xx_io.h>
43 #include <bcm63xx_regs.h>
45 -static u32 gpio_out_low_reg;
47 -static void bcm63xx_gpio_out_low_reg_init(void)
48 +static void __init bcm63xx_gpio_init_one(int id, int dir, int data, int ngpio)
50 - switch (bcm63xx_get_cpu_id()) {
51 - case BCM6345_CPU_ID:
52 - gpio_out_low_reg = GPIO_DATA_LO_REG_6345;
55 - gpio_out_low_reg = GPIO_DATA_LO_REG;
60 -static DEFINE_SPINLOCK(bcm63xx_gpio_lock);
61 -static u32 gpio_out_low, gpio_out_high;
62 + struct resource res[2];
63 + struct bgpio_pdata pdata;
65 -static void bcm63xx_gpio_set(struct gpio_chip *chip,
66 - unsigned gpio, int val)
71 - unsigned long flags;
73 - if (gpio >= chip->ngpio)
77 - reg = gpio_out_low_reg;
81 - reg = GPIO_DATA_HI_REG;
82 - mask = 1 << (gpio - 32);
86 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
91 - bcm_gpio_writel(*v, reg);
92 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
94 + memset(res, 0, sizeof(res));
95 + memset(&pdata, 0, sizeof(pdata));
97 -static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio)
101 + res[0].flags = IORESOURCE_MEM;
102 + res[0].start = bcm63xx_regset_address(RSET_GPIO);
103 + res[0].start += dir;
105 - if (gpio >= chip->ngpio)
107 + res[0].end = res[0].start + 3;
110 - reg = gpio_out_low_reg;
113 - reg = GPIO_DATA_HI_REG;
114 - mask = 1 << (gpio - 32);
116 + res[1].flags = IORESOURCE_MEM;
117 + res[1].start = bcm63xx_regset_address(RSET_GPIO);
118 + res[1].start += data;
120 - return !!(bcm_gpio_readl(reg) & mask);
122 + res[1].end = res[1].start + 3;
124 -static int bcm63xx_gpio_set_direction(struct gpio_chip *chip,
125 - unsigned gpio, int dir)
130 - unsigned long flags;
132 - if (gpio >= chip->ngpio)
136 - reg = GPIO_CTL_LO_REG;
139 - reg = GPIO_CTL_HI_REG;
140 - mask = 1 << (gpio - 32);
143 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
144 - tmp = bcm_gpio_readl(reg);
145 - if (dir == BCM63XX_GPIO_DIR_IN)
149 - bcm_gpio_writel(tmp, reg);
150 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
151 + pdata.base = id * 32;
152 + pdata.ngpio = ngpio;
155 + platform_device_register_resndata(NULL, "bcm63xx-gpio", id, res, 2,
156 + &pdata, sizeof(pdata));
159 -static int bcm63xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
160 +int __init bcm63xx_gpio_init(void)
162 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_IN);
164 + int ngpio = bcm63xx_gpio_count();
167 -static int bcm63xx_gpio_direction_output(struct gpio_chip *chip,
168 - unsigned gpio, int value)
170 - bcm63xx_gpio_set(chip, gpio, value);
171 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_OUT);
173 + if (BCMCPU_IS_6345())
174 + data_low_reg = GPIO_DATA_LO_REG_6345;
176 + data_low_reg = GPIO_DATA_LO_REG;
178 + bcm63xx_gpio_init_one(0, GPIO_CTL_LO_REG, data_low_reg, min(ngpio, 32));
180 -static struct gpio_chip bcm63xx_gpio_chip = {
181 - .label = "bcm63xx-gpio",
182 - .direction_input = bcm63xx_gpio_direction_input,
183 - .direction_output = bcm63xx_gpio_direction_output,
184 - .get = bcm63xx_gpio_get,
185 - .set = bcm63xx_gpio_set,
191 -int __init bcm63xx_gpio_init(void)
193 - bcm63xx_gpio_out_low_reg_init();
194 + bcm63xx_gpio_init_one(1, GPIO_CTL_HI_REG, GPIO_DATA_HI_REG, ngpio - 32);
196 - gpio_out_low = bcm_gpio_readl(gpio_out_low_reg);
197 - if (!BCMCPU_IS_6345())
198 - gpio_out_high = bcm_gpio_readl(GPIO_DATA_HI_REG);
199 - bcm63xx_gpio_chip.ngpio = bcm63xx_gpio_count();
200 - pr_info("registering %d GPIOs\n", bcm63xx_gpio_chip.ngpio);
203 - return gpiochip_add(&bcm63xx_gpio_chip);
205 --- a/arch/mips/bcm63xx/setup.c
206 +++ b/arch/mips/bcm63xx/setup.c
207 @@ -164,9 +164,6 @@ void __init plat_mem_setup(void)
209 int __init bcm63xx_register_devices(void)
211 - /* register gpiochip */
212 - bcm63xx_gpio_init();
214 return board_register_devices();