base-files: sysupgrade: fix streaming backup archives to stdout
[openwrt/staging/mans0n.git] / target / linux / bcm63xx / patches-5.15 / 375-MIPS-BCM63XX-switch-to-new-gpio-driver.patch
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
5
6 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
7 ---
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(-)
12
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)
16 }
17 #endif
18
19 + bcm63xx_gpio_init();
20 +
21 if (board.has_uart0)
22 bcm63xx_uart_register(0);
23
24 --- a/arch/mips/bcm63xx/gpio.c
25 +++ b/arch/mips/bcm63xx/gpio.c
26 @@ -5,144 +5,62 @@
27 *
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>
31 */
32
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>
38
39 #include <bcm63xx_cpu.h>
40 #include <bcm63xx_gpio.h>
41 -#include <bcm63xx_io.h>
42 #include <bcm63xx_regs.h>
43
44 -static u32 gpio_out_low_reg;
45 -
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)
48 {
49 - switch (bcm63xx_get_cpu_id()) {
50 - case BCM6345_CPU_ID:
51 - gpio_out_low_reg = GPIO_DATA_LO_REG_6345;
52 - break;
53 - default:
54 - gpio_out_low_reg = GPIO_DATA_LO_REG;
55 - break;
56 - }
57 -}
58 -
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;
63
64 -static void bcm63xx_gpio_set(struct gpio_chip *chip,
65 - unsigned gpio, int val)
66 -{
67 - u32 reg;
68 - u32 mask;
69 - u32 *v;
70 - unsigned long flags;
71 -
72 - BUG_ON(gpio >= chip->ngpio);
73 -
74 - if (gpio < 32) {
75 - reg = gpio_out_low_reg;
76 - mask = 1 << gpio;
77 - v = &gpio_out_low;
78 - } else {
79 - reg = GPIO_DATA_HI_REG;
80 - mask = 1 << (gpio - 32);
81 - v = &gpio_out_high;
82 - }
83 -
84 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
85 - if (val)
86 - *v |= mask;
87 - else
88 - *v &= ~mask;
89 - bcm_gpio_writel(*v, reg);
90 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
91 -}
92 + memset(res, 0, sizeof(res));
93 + memset(&pdata, 0, sizeof(pdata));
94
95 -static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio)
96 -{
97 - u32 reg;
98 - u32 mask;
99 + res[0].flags = IORESOURCE_MEM;
100 + res[0].start = bcm63xx_regset_address(RSET_GPIO);
101 + res[0].start += dir;
102
103 - BUG_ON(gpio >= chip->ngpio);
104 + res[0].end = res[0].start + 3;
105
106 - if (gpio < 32) {
107 - reg = gpio_out_low_reg;
108 - mask = 1 << gpio;
109 - } else {
110 - reg = GPIO_DATA_HI_REG;
111 - mask = 1 << (gpio - 32);
112 - }
113 + res[1].flags = IORESOURCE_MEM;
114 + res[1].start = bcm63xx_regset_address(RSET_GPIO);
115 + res[1].start += data;
116
117 - return !!(bcm_gpio_readl(reg) & mask);
118 -}
119 + res[1].end = res[1].start + 3;
120
121 -static int bcm63xx_gpio_set_direction(struct gpio_chip *chip,
122 - unsigned gpio, int dir)
123 -{
124 - u32 reg;
125 - u32 mask;
126 - u32 tmp;
127 - unsigned long flags;
128 -
129 - BUG_ON(gpio >= chip->ngpio);
130 -
131 - if (gpio < 32) {
132 - reg = GPIO_CTL_LO_REG;
133 - mask = 1 << gpio;
134 - } else {
135 - reg = GPIO_CTL_HI_REG;
136 - mask = 1 << (gpio - 32);
137 - }
138 -
139 - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
140 - tmp = bcm_gpio_readl(reg);
141 - if (dir == BCM63XX_GPIO_DIR_IN)
142 - tmp &= ~mask;
143 - else
144 - tmp |= mask;
145 - bcm_gpio_writel(tmp, reg);
146 - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
147 + pdata.base = id * 32;
148 + pdata.ngpio = ngpio;
149
150 - return 0;
151 + platform_device_register_resndata(NULL, "bcm63xx-gpio", id, res, 2,
152 + &pdata, sizeof(pdata));
153 }
154
155 -static int bcm63xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
156 +int __init bcm63xx_gpio_init(void)
157 {
158 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_IN);
159 -}
160 + int ngpio = bcm63xx_gpio_count();
161 + int data_low_reg;
162
163 -static int bcm63xx_gpio_direction_output(struct gpio_chip *chip,
164 - unsigned gpio, int value)
165 -{
166 - bcm63xx_gpio_set(chip, gpio, value);
167 - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_OUT);
168 -}
169 + if (BCMCPU_IS_6345())
170 + data_low_reg = GPIO_DATA_LO_REG_6345;
171 + else
172 + data_low_reg = GPIO_DATA_LO_REG;
173
174 + bcm63xx_gpio_init_one(0, GPIO_CTL_LO_REG, data_low_reg, min(ngpio, 32));
175
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,
182 - .base = 0,
183 -};
184 + if (ngpio <= 32)
185 + return 0;
186
187 -int __init bcm63xx_gpio_init(void)
188 -{
189 - bcm63xx_gpio_out_low_reg_init();
190 + bcm63xx_gpio_init_one(1, GPIO_CTL_HI_REG, GPIO_DATA_HI_REG, ngpio - 32);
191
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);
197 + return 0;
198
199 - return gpiochip_add_data(&bcm63xx_gpio_chip, NULL);
200 }
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)
204
205 int __init bcm63xx_register_devices(void)
206 {
207 - /* register gpiochip */
208 - bcm63xx_gpio_init();
209 -
210 return board_register_devices();
211 }
212