Add GPIO_FUNCTION_2 register defines, setup GPIO11/12 if needed in low level init...
[oweals/u-boot_mod.git] / u-boot / cpu / mips / ar7240 / qca_gpio_init.S
1 /*
2  * This file contains code used for lowlevel initialization
3  * of GPIO, on supported Qualcomm/Atheros platforms
4  *
5  * Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
6  *
7  * SPDX-License-Identifier: GPL-2.0
8  */
9
10 #include <config.h>
11 #include <version.h>
12 #include <asm/regdef.h>
13 #include <asm/mipsregs.h>
14 #include <asm/addrspace.h>
15 #include <soc/qca_soc_common.h>
16
17 /*
18  * Low level GPIO initialization:
19  * 1. Setup JTAG (disable by default, but allow to keep it up)
20  * 2. Disable all clock observation on platforms which support this
21  * 3. Setup UART lines
22  * 4. Setup all configured GPIO inputs/outputs
23  * 5. Set desired init values on configured GPIOs
24  *
25  * The user may use several config definitions here:
26  * 1. CONFIG_QCA_KEEP_JTAG_ENABLED
27  *    - if defined, JTAG will not be disabled
28  * 2. CONFIG_QCA_GPIO_MASK_OUTPUTS,
29  *    CONFIG_QCA_GPIO_MASK_INPUTS
30  *    - bitmask for GPIOs to be set as outputs and inputs
31  * 3. CONFIG_QCA_GPIO_LSUART_TX,
32  *    CONFIG_QCA_GPIO_LSUART_RX
33  *    - GPIO number for LSUART TX (10 if empty) and RX line (9 if empty)
34  * 4. CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_HI,
35  *    CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_LO
36  *    - bitmask for outputs initialized to high and low state at start
37  * 5. CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI,
38  *    CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO
39  *    - bitmask for GPIO driven LEDs, used only in leds_on/leds_off functions,
40  *      GPIO numbers for LEDs MUST be defined also in CONFIG_QCA_GPIO_MASK_OUTPUTS!
41  *
42  * TODO:
43  * 1. Allow to select LS, HS, both or none UART type
44  *    on platforms which support both
45  * 2. Allow to select clocks observation on chosen pins
46  * 3. Ethernet/WLAN LEDs configuration
47  * 4. Enable JTAG on request (button?)
48  */
49
50 /* Sanity check for GPIO driven LEDs */
51 #if (defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI)  || \
52          defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO)) && \
53         !defined(CONFIG_QCA_GPIO_MASK_OUTPUTS)
54         #error "GPIO numbers for LEDs must be included in CONFIG_QCA_GPIO_MASK_OUTPUTS!"
55 #endif
56
57 #if (defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI) && \
58          !(CONFIG_QCA_GPIO_MASK_OUTPUTS & CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI)) || \
59         (defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO) && \
60          !(CONFIG_QCA_GPIO_MASK_OUTPUTS & CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO))
61         #error "GPIO numbers for LEDs must be included in CONFIG_QCA_GPIO_MASK_OUTPUTS!"
62 #endif
63
64 .globl lowlevel_gpio_init
65 .type  lowlevel_gpio_init, @function
66 .align 4
67 .text
68 .ent lowlevel_gpio_init
69
70 lowlevel_gpio_init:
71 /*
72  * =========================
73  * Low level GPIO setup for:
74  * 1. AR934x
75  * 2. QCA953x
76  * 3. QCA955x
77  * =========================
78  */
79 #if (SOC_TYPE & QCA_AR934X_SOC)  || \
80         (SOC_TYPE & QCA_QCA953X_SOC) || \
81         (SOC_TYPE & QCA_QCA955X_SOC)
82
83         /* Sanity check for JTAG pins (GPIO 0~3) */
84         #if defined(CONFIG_SKIP_LOWLEVEL_INIT) || \
85                 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
86                 #if (defined(CONFIG_QCA_GPIO_MASK_INPUTS)  && (CONFIG_QCA_GPIO_MASK_INPUTS  & 0xF)) || \
87                         (defined(CONFIG_QCA_GPIO_MASK_OUTPUTS) && (CONFIG_QCA_GPIO_MASK_OUTPUTS & 0xF))
88                                 #error "Cannot use JTAG and GPIO0~3 at the same time!"
89                 #endif
90         #endif
91
92         /*
93          * Disable:
94          * 1. By default JTAG (bit 1 set)
95          * 2. All clock observation (bits 2~9 reset)
96          */
97         li t8, QCA_GPIO_FUNC_REG
98         #if defined(CONFIG_SKIP_LOWLEVEL_INIT) || \
99                 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
100         li t9, QCA_GPIO_FUNC_JTAG_DIS_MASK
101         #else
102         li t9, 0x0
103         #endif
104         sw t9, 0(t8)
105
106         /* By default use GPIO10 for TX and GPIO9 for RX */
107         #ifndef CONFIG_QCA_GPIO_LSUART_TX
108                 #define CONFIG_QCA_GPIO_LSUART_TX       10
109         #endif
110
111         #ifndef CONFIG_QCA_GPIO_LSUART_RX
112                 #define CONFIG_QCA_GPIO_LSUART_RX       9
113         #endif
114
115         #define CONFIG_QCA_GPIO_MASK_LSUART_TX  (1 << CONFIG_QCA_GPIO_LSUART_TX)
116         #define CONFIG_QCA_GPIO_MASK_LSUART_RX  (1 << CONFIG_QCA_GPIO_LSUART_RX)
117
118         #define CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT   \
119                                                                         (8 * (CONFIG_QCA_GPIO_LSUART_TX - \
120                                                                         ((CONFIG_QCA_GPIO_LSUART_TX / 4) * 4)))
121
122         /* Some sanity checks for LS UART GPIO lines */
123         #if (CONFIG_QCA_GPIO_LSUART_TX >= QCA_GPIO_COUNT) || \
124                 (CONFIG_QCA_GPIO_LSUART_RX >= QCA_GPIO_COUNT)
125                 #error "LSUART GPIO numbers for TX and/or RX lines are not correct!"
126         #endif
127
128         #if (CONFIG_QCA_GPIO_LSUART_TX == CONFIG_QCA_GPIO_LSUART_RX)
129                 #error "LSUART TX and RX GPIO numbers cannot be the same!"
130         #endif
131
132         /*
133          * Do not allow to use LSUART TX/RX lines
134          * as regular GPIO inputs/outputs at the same time
135          */
136         #if defined(CONFIG_QCA_GPIO_MASK_INPUTS) || defined(CONFIG_QCA_GPIO_MASK_OUTPUTS)
137                 #if (CONFIG_QCA_GPIO_MASK_INPUTS  & CONFIG_QCA_GPIO_MASK_LSUART_TX) || \
138                         (CONFIG_QCA_GPIO_MASK_INPUTS  & CONFIG_QCA_GPIO_MASK_LSUART_RX) || \
139                         (CONFIG_QCA_GPIO_MASK_OUTPUTS & CONFIG_QCA_GPIO_MASK_LSUART_TX) || \
140                         (CONFIG_QCA_GPIO_MASK_OUTPUTS & CONFIG_QCA_GPIO_MASK_LSUART_RX)
141                         #error "Cannot use LSUART lines as regular GPIOs at the same time!"
142                 #endif
143         #endif
144
145         /* Setup GPIO number for LSUART RX in GPIO IN MUX */
146         li  t8, QCA_GPIO_IN_EN0_REG
147         lw  t9, 0(t8)
148         and t9, t9, ~(QCA_GPIO_IN_EN0_LSUART_RXD_MASK)
149         or  t9, t9, (CONFIG_QCA_GPIO_LSUART_RX << QCA_GPIO_IN_EN0_LSUART_RXD_SHIFT)
150         sw  t9, 0(t8)
151
152         /*
153          * Target regular GPIO and LSUART TX line configuration
154          *
155          * After selecting GPIO as output in GPIO_OE register,
156          * the line will be set to low, which causes signal
157          * toggle on pulled-up lines
158          *
159          * To prevent this, we need to first setup desired
160          * init state for all GPIOs configured as outputs
161          * and then setup them as outputs
162          */
163         li  t8, QCA_GPIO_OUT_REG
164         lw  t9, 0(t8)
165         #ifdef CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_HI
166         or  t9, t9, (CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_HI | \
167                                  CONFIG_QCA_GPIO_MASK_LSUART_TX)
168         #else
169         or  t9, t9, CONFIG_QCA_GPIO_MASK_LSUART_TX
170         #endif
171         #ifdef CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_LO
172         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_LO)
173         #endif
174         sw  t9, 0(t8)
175
176         /*
177          * TODO: what with default LSUART TX line?
178          *
179          * Some of QCA WiSoCs have GPIOs for LSUART TX/RX lines
180          * set by default (10 and 9 respectively) on reset and
181          * others do not (ex. QCA953x?).
182          *
183          * Because of that we can use more than one line
184          * for TX signal if we setup other than default
185          * GPIO for it, without change default GPIO
186          * function.
187          *
188          * Confirmed on AR9344 with LSUART TX set on
189          * GPIO1 and GPIO10 at the same time
190          */
191
192         /*
193          * Set GPIO mode on desired lines and GPIO number
194          * for LSUART TX using GPIO_OUT_FUNCTIONX registers:
195          * -  0 ~  3 -> GPIO_OUT_FUNCTION0 (mask: 0x00000F)
196          * -  4 ~  7 -> GPIO_OUT_FUNCTION1 (mask: 0x0000F0)
197          * -  8 ~ 11 -> GPIO_OUT_FUNCTION2 (mask: 0x000F00)
198          * - 12 ~ 15 -> GPIO_OUT_FUNCTION3 (mask: 0x00F000)
199          * - 16 ~ 19 -> GPIO_OUT_FUNCTION4 (mask: 0x0F0000)
200          * - 20 ~ 23 -> GPIO_OUT_FUNCTION5 (mask: 0xF00000)
201          */
202         #if defined(CONFIG_QCA_GPIO_MASK_OUTPUTS) || \
203                 defined(CONFIG_QCA_GPIO_MASK_INPUTS)
204
205                 /* GPIO_OUT_FUNCTION0 (GPIO 0~3) */
206                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS   & 0x00000F) || \
207                         (CONFIG_QCA_GPIO_MASK_INPUTS    & 0x00000F) || \
208                         (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00000F)
209         li  t8, QCA_GPIO_OUT_FUNC0_REG
210         lw  t9, 0(t8)
211                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO0) || \
212                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO0)
213         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO0_EN_MASK)
214                         #endif
215                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO1) || \
216                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO1)
217         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO1_EN_MASK)
218                         #endif
219                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO2) || \
220                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO2)
221         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO2_EN_MASK)
222                         #endif
223                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO3) || \
224                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO3)
225         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO3_EN_MASK)
226                         #endif
227                         #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00000F)
228         and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
229         or  t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL << \
230                                  CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
231                         #endif
232         sw  t9, 0(t8)
233                 #endif
234
235                 /* GPIO_OUT_FUNCTION1 (GPIO 4~7) */
236                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS   & 0x0000F0) || \
237                         (CONFIG_QCA_GPIO_MASK_INPUTS    & 0x0000F0) || \
238                         (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0000F0)
239         li  t8, QCA_GPIO_OUT_FUNC1_REG
240         lw  t9, 0(t8)
241                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO4) || \
242                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO4)
243         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO4_EN_MASK)
244                         #endif
245                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO5) || \
246                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO5)
247         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO5_EN_MASK)
248                         #endif
249                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO6) || \
250                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO6)
251         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO6_EN_MASK)
252                         #endif
253                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO7) || \
254                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO7)
255         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO7_EN_MASK)
256                         #endif
257                         #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0000F0)
258         and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
259         or  t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL << \
260                                  CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
261                         #endif
262         sw  t9, 0(t8)
263                 #endif
264
265                 /* GPIO_OUT_FUNCTION2 (GPIO 8~11) */
266                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS   & 0x000F00) || \
267                         (CONFIG_QCA_GPIO_MASK_INPUTS    & 0x000F00) || \
268                         (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x000F00)
269         li  t8, QCA_GPIO_OUT_FUNC2_REG
270         lw  t9, 0(t8)
271                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO8) || \
272                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO8)
273         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO8_EN_MASK)
274                         #endif
275                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO9) || \
276                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO9)
277         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO9_EN_MASK)
278                         #endif
279                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO10) || \
280                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO10)
281         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO10_EN_MASK)
282                         #endif
283                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO11) || \
284                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO11)
285         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO11_EN_MASK)
286                         #endif
287                         #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x000F00)
288         and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
289         or  t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL << \
290                                  CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
291                         #endif
292         sw  t9, 0(t8)
293                 #endif
294
295                 /* GPIO_OUT_FUNCTION3 (GPIO 12~15) */
296                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS   & 0x00F000) || \
297                         (CONFIG_QCA_GPIO_MASK_INPUTS    & 0x00F000) || \
298                         (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00F000)
299         li  t8, QCA_GPIO_OUT_FUNC3_REG
300         lw  t9, 0(t8)
301                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO12) || \
302                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO12)
303         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO12_EN_MASK)
304                         #endif
305                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO13) || \
306                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO13)
307         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO13_EN_MASK)
308                         #endif
309                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO14) || \
310                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO14)
311         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO14_EN_MASK)
312                         #endif
313                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO15) || \
314                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO15)
315         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO15_EN_MASK)
316                         #endif
317                         #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00F000)
318         and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
319         or  t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL << \
320                                  CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
321                         #endif
322         sw  t9, 0(t8)
323                 #endif
324
325                 /* GPIO_OUT_FUNCTION4 (GPIO 16~19) */
326                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS   & 0x0F0000) || \
327                         (CONFIG_QCA_GPIO_MASK_INPUTS    & 0x0F0000) || \
328                         (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0F0000)
329         li  t8, QCA_GPIO_OUT_FUNC4_REG
330         lw  t9, 0(t8)
331                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO16) || \
332                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO16)
333         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO16_EN_MASK)
334                         #endif
335                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO17) || \
336                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO17)
337         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO17_EN_MASK)
338                         #endif
339                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO18) || \
340                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO18)
341         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO18_EN_MASK)
342                         #endif
343                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO19) || \
344                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO19)
345         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO19_EN_MASK)
346                         #endif
347                         #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0F0000)
348         and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
349         or  t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL << \
350                                  CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
351                         #endif
352         sw  t9, 0(t8)
353                 #endif
354
355                 /* GPIO_OUT_FUNCTION5 (GPIO 20~23) */
356                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS   & 0xF00000) || \
357                         (CONFIG_QCA_GPIO_MASK_INPUTS    & 0xF00000) || \
358                         (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0xF00000)
359         li  t8, QCA_GPIO_OUT_FUNC5_REG
360         lw  t9, 0(t8)
361                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO20) || \
362                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO20)
363         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO20_EN_MASK)
364                         #endif
365                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO21) || \
366                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO21)
367         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO21_EN_MASK)
368                         #endif
369                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO22) || \
370                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO22)
371         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO22_EN_MASK)
372                         #endif
373                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO23) || \
374                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO23)
375         and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO23_EN_MASK)
376                         #endif
377                         #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0xF00000)
378         and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
379         or  t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL << \
380                                  CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
381                         #endif
382         sw  t9, 0(t8)
383                 #endif
384
385         /*
386          * And finally, setup GPIO type (out/in)
387          * in GPIO_OE register for all configured
388          * regular GPIOs and LSUART TX/RX lines
389          */
390         li  t8, QCA_GPIO_OE_REG
391         lw  t9, 0(t8)
392                 #ifdef CONFIG_QCA_GPIO_MASK_OUTPUTS
393         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_OUTPUTS | \
394                                   CONFIG_QCA_GPIO_MASK_LSUART_TX)
395                 #else
396         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_LSUART_TX)
397                 #endif
398                 #ifdef CONFIG_QCA_GPIO_MASK_INPUTS
399         or  t9, t9, (CONFIG_QCA_GPIO_MASK_INPUTS | CONFIG_QCA_GPIO_MASK_LSUART_RX)
400                 #else
401         or  t9, t9, CONFIG_QCA_GPIO_MASK_LSUART_RX
402                 #endif
403         sw  t9, 0(t8)
404
405         #endif /* CONFIG_QCA_GPIO_MASK_OUTPUTS || CONFIG_QCA_GPIO_MASK_INPUTS */
406
407 #endif /* (SOC_TYPE & QCA_AR934X_SOC) || (SOC_TYPE & QCA_QCA953X_SOC) || (SOC_TYPE & QCA_QCA955X_SOC) */
408
409 /*
410  * ===============================
411  * Low level GPIO setup for AR933x
412  * ===============================
413  */
414 #if (SOC_TYPE & QCA_AR933X_SOC)
415
416         /* Sanity check for JTAG pins (GPIO 6~8) */
417         #if defined(CONFIG_SKIP_LOWLEVEL_INIT) || \
418                 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
419                 #if (defined(CONFIG_QCA_GPIO_MASK_INPUTS)  && (CONFIG_QCA_GPIO_MASK_INPUTS  & 0x1C0)) || \
420                         (defined(CONFIG_QCA_GPIO_MASK_OUTPUTS) && (CONFIG_QCA_GPIO_MASK_OUTPUTS & 0x1C0))
421                                 #error "Cannot use JTAG and GPIO6~8 at the same time!"
422                 #endif
423         #endif
424
425         /*
426          * On AR933x HSUART TX/RX lines are connected to
427          * GPIO10 and GPIO9 respectively, so do not allow
428          * to use those GPIOs as regular at the same time
429          */
430         #if defined(CONFIG_QCA_GPIO_MASK_INPUTS) || defined(CONFIG_QCA_GPIO_MASK_OUTPUTS)
431                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & (GPIO9 | GPIO10)) || \
432                         (CONFIG_QCA_GPIO_MASK_INPUTS  & (GPIO9 | GPIO10))
433                         #error "Cannot use HSUART lines as regular GPIOs at the same time!"
434                 #endif
435         #endif
436
437         /*
438          * GPIO configuration, using GPIO_FUNCTION_1 register:
439          * 1. Disable JTAG by default
440          * 2. Enable HSUART on GPIO9 and GPIO10 by default
441          * 3. Disable HSUART RTS/CTS on GPIO11/12 if needed
442          * 4. Disable selected Ethernet switch LEDs if needed
443          */
444         li  t8, QCA_GPIO_FUNC_1_REG
445         lw  t9, 0(t8)
446         #if defined(CONFIG_SKIP_LOWLEVEL_INIT) || \
447                 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
448         and t9, t9, ~(QCA_GPIO_FUNC_1_JTAG_DIS_MASK)
449         or  t9, t9, QCA_GPIO_FUNC_1_UART_EN_MASK
450         #else
451         or  t9, t9, (QCA_GPIO_FUNC_1_JTAG_DIS_MASK | \
452                                  QCA_GPIO_FUNC_1_UART_EN_MASK)
453         #endif
454         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & (GPIO11 | GPIO12)) || \
455                 (CONFIG_QCA_GPIO_MASK_INPUTS  & (GPIO11 | GPIO12))
456         and t9, t9, ~(QCA_GPIO_FUNC_1_UART_RTS_CTS_EN_MASK)
457         #endif
458         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO13) || \
459                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO13)
460         and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED0_EN_MASK)
461         #endif
462         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO14) || \
463                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO14)
464         and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED1_EN_MASK)
465         #endif
466         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO15) || \
467                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO15)
468         and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED2_EN_MASK)
469         #endif
470         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO16) || \
471                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO16)
472         and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED3_EN_MASK)
473         #endif
474         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO17) || \
475                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO17)
476         and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED4_EN_MASK)
477         #endif
478         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO9)
479         and t9, t9, ~(QCA_GPIO_FUNC_1_SPI_CS_EN1_MASK)
480         #endif
481         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO10)
482         and t9, t9, ~(QCA_GPIO_FUNC_1_SPI_CS_EN2_MASK)
483         #endif
484         /* From datasheet: bit 15 should be written with 1 */
485         or  t9, t9, ((1 << 15) | \
486                                  QCA_GPIO_FUNC_1_SPI_EN_MASK)
487         sw  t9, 0(t8)
488
489         /* Enable regular GPIO function on GPIO26 and/or GPIO27 if needed */
490         #if defined(CONFIG_QCA_GPIO_MASK_OUTPUTS) || \
491                 defined(CONFIG_QCA_GPIO_MASK_INPUTS)
492                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & (GPIO26 | GPIO27)) || \
493                         (CONFIG_QCA_GPIO_MASK_INPUTS  & (GPIO26 | GPIO27))
494         li t8, QCA_RST_BOOTSTRAP_REG
495         lw t9, 0(t8)
496         or t9, t9, QCA_RST_BOOTSTRAP_MDIO_GPIO_EN_MASK
497         sw t9, 0(t8)
498                 #endif
499         #endif
500
501         /* Enable regular GPIO function on GPIO11 and/or GPIO12 if needed */
502         #if defined(CONFIG_QCA_GPIO_MASK_OUTPUTS) || \
503                 defined(CONFIG_QCA_GPIO_MASK_INPUTS)
504                 #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & (GPIO11 | GPIO12)) || \
505                         (CONFIG_QCA_GPIO_MASK_INPUTS  & (GPIO11 | GPIO12))
506         li t8, QCA_GPIO_FUNC_2_REG
507         lw t9, 0(t8)
508                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO11) || \
509                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO11)
510         or t9, t9, QCA_GPIO_FUNC_2_JUMPSTART_DIS_MASK
511                         #endif
512                         #if (CONFIG_QCA_GPIO_MASK_OUTPUTS & GPIO12) || \
513                                 (CONFIG_QCA_GPIO_MASK_INPUTS  & GPIO12)
514         or t9, t9, QCA_GPIO_FUNC_2_WPS_DIS_MASK
515                         #endif
516         sw t9, 0(t8)
517                 #endif
518         #endif
519
520         /* Setup init states on requested GPIO lines */
521         li  t8, QCA_GPIO_OUT_REG
522         lw  t9, 0(t8)
523         #ifdef CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_HI
524         or  t9, t9, CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_HI
525         #endif
526         #ifdef CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_LO
527         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_OUTPUTS_INIT_LO)
528         #endif
529         sw  t9, 0(t8)
530
531         /* Setup GPIOs in OE register */
532         #if defined(CONFIG_QCA_GPIO_MASK_OUTPUTS) || \
533                 defined(CONFIG_QCA_GPIO_MASK_INPUTS)
534         li  t8, QCA_GPIO_OE_REG
535         lw  t9, 0(t8)
536                 #ifdef CONFIG_QCA_GPIO_MASK_OUTPUTS
537         or  t9, t9, CONFIG_QCA_GPIO_MASK_OUTPUTS
538                 #endif
539                 #ifdef CONFIG_QCA_GPIO_MASK_INPUTS
540         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_INPUTS)
541                 #endif
542         sw  t9, 0(t8)
543         #endif
544
545 #endif /* (SOC_TYPE & QCA_AR933X_SOC) */
546
547 /*
548  * Custom, GPIO related code for boards should go here,
549  * after initial/basic GPIO configuration
550  */
551
552         jr ra
553         nop
554
555 .end lowlevel_gpio_init
556
557 /*
558  * Set all predefined GPIO driven LEDs ON
559  */
560
561 .globl all_led_on
562 .type  all_led_on, @function
563 .align 4
564 .text
565 .ent all_led_on
566
567 all_led_on:
568 #if defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI) || \
569         defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO)
570         li  t8, QCA_GPIO_OUT_REG
571         lw  t9, 0(t8)
572         #ifdef CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI
573         or  t9, t9, CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI
574         #endif
575         #ifdef CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO
576         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO)
577         #endif
578         sw  t9, 0(t8)
579 #else
580         nop
581 #endif
582
583         jr      ra
584         nop
585
586 .end all_led_on
587
588 /*
589  * Set all predefined GPIO driven LEDs OFF
590  */
591
592 .globl all_led_off
593 .type  all_led_off, @function
594 .align 4
595 .text
596 .ent all_led_off
597
598 all_led_off:
599 #if defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI) || \
600         defined(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO)
601         li  t8, QCA_GPIO_OUT_REG
602         lw  t9, 0(t8)
603         #ifdef CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI
604         and t9, t9, ~(CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_HI)
605         #endif
606         #ifdef CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO
607         or t9, t9, CONFIG_QCA_GPIO_MASK_LEDS_ACTIVE_LO
608         #endif
609         sw  t9, 0(t8)
610 #else
611         nop
612 #endif
613
614         jr      ra
615         nop
616
617 .end all_led_off