2 * This file contains code used for lowlevel initialization
3 * of GPIO, on supported Qualcomm/Atheros platforms
5 * Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
7 * SPDX-License-Identifier: GPL-2.0
12 #include <asm/regdef.h>
13 #include <asm/mipsregs.h>
14 #include <asm/addrspace.h>
15 #include <soc/qca_soc_common.h>
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
22 * 4. Setup all configured GPIO inputs/outputs
23 * 5. Set desired init values on configured GPIOs
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_OUT,
29 * CONFIG_QCA_GPIO_MASK_IN
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_OUT_INIT_H,
35 * CONFIG_QCA_GPIO_MASK_OUT_INIT_L
36 * - bitmask for outputs initialized to high and low state at start
37 * 5. CONFIG_QCA_GPIO_MASK_LED_ACT_H,
38 * CONFIG_QCA_GPIO_MASK_LED_ACT_L
39 * - bitmask for GPIO driven LEDs, used only in leds_on/leds_off functions
42 * 1. Allow to select LS, HS, both or none UART type
43 * on platforms which support both
44 * 2. Allow to select clocks observation on chosen pins
45 * 3. Ethernet/WLAN LEDs configuration
46 * 4. Enable JTAG on request (button?)
49 /* Sanity check for GPIO driven LEDs */
50 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_H) &&\
51 defined(CONFIG_QCA_GPIO_MASK_LED_ACT_L)
52 #if ((CONFIG_QCA_GPIO_MASK_LED_ACT_H) &\
53 (CONFIG_QCA_GPIO_MASK_LED_ACT_L))
54 #error "Same GPIO/s included in CONFIG_QCA_GPIO_MASK_LED_ACT_H and CONFIG_QCA_GPIO_MASK_LED_ACT_L"
58 /* Output GPIOs cannot have initial value hi and low at the same time */
59 #if defined(CONFIG_QCA_GPIO_MASK_OUT_INIT_H) &&\
60 defined(CONFIG_QCA_GPIO_MASK_OUT_INIT_L)
61 #if ((CONFIG_QCA_GPIO_MASK_OUT_INIT_H) &\
62 (CONFIG_QCA_GPIO_MASK_OUT_INIT_L))
63 #error "Same GPIO/s included in CONFIG_QCA_GPIO_MASK_OUT_INIT_H and CONFIG_QCA_GPIO_MASK_OUT_INIT_L"
67 /* Include active low/high LEDs in GPIO init low/high masks */
68 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_H)
69 #if defined(CONFIG_QCA_GPIO_MASK_OUT_INIT_L)
70 #define _GPIO_MASK_OUT_INIT_L (CONFIG_QCA_GPIO_MASK_LED_ACT_H |\
71 CONFIG_QCA_GPIO_MASK_OUT_INIT_L)
73 #define _GPIO_MASK_OUT_INIT_L (CONFIG_QCA_GPIO_MASK_LED_ACT_H)
76 #if defined(CONFIG_QCA_GPIO_MASK_OUT_INIT_L)
77 #define _GPIO_MASK_OUT_INIT_L (CONFIG_QCA_GPIO_MASK_OUT_INIT_L)
81 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_L)
82 #if defined(CONFIG_QCA_GPIO_MASK_OUT_INIT_H)
83 #define _GPIO_MASK_OUT_INIT_H (CONFIG_QCA_GPIO_MASK_LED_ACT_L |\
84 CONFIG_QCA_GPIO_MASK_OUT_INIT_H)
86 #define _GPIO_MASK_OUT_INIT_H (CONFIG_QCA_GPIO_MASK_LED_ACT_L)
89 #if defined(CONFIG_QCA_GPIO_MASK_OUT_INIT_H)
90 #define _GPIO_MASK_OUT_INIT_H (CONFIG_QCA_GPIO_MASK_OUT_INIT_H)
94 /* Include GPIO init low/high in GPIO output mask */
95 #if defined(CONFIG_QCA_GPIO_MASK_OUT)
96 #if defined(_GPIO_MASK_OUT_INIT_H) && defined(_GPIO_MASK_OUT_INIT_L)
97 #define _GPIO_MASK_OUT (CONFIG_QCA_GPIO_MASK_OUT |\
98 _GPIO_MASK_OUT_INIT_H |\
99 _GPIO_MASK_OUT_INIT_L)
100 #elif defined(_GPIO_MASK_OUT_INIT_H)
101 #define _GPIO_MASK_OUT (CONFIG_QCA_GPIO_MASK_OUT |\
102 _GPIO_MASK_OUT_INIT_H)
103 #elif defined(_GPIO_MASK_OUT_INIT_L)
104 #define _GPIO_MASK_OUT (CONFIG_QCA_GPIO_MASK_OUT |\
105 _GPIO_MASK_OUT_INIT_L)
107 #define _GPIO_MASK_OUT (CONFIG_QCA_GPIO_MASK_OUT)
110 #if defined(_GPIO_MASK_OUT_INIT_H) && defined(_GPIO_MASK_OUT_INIT_L)
111 #define _GPIO_MASK_OUT (_GPIO_MASK_OUT_INIT_H |\
112 _GPIO_MASK_OUT_INIT_L)
113 #elif defined(_GPIO_MASK_OUT_INIT_H)
114 #define _GPIO_MASK_OUT (_GPIO_MASK_OUT_INIT_H)
115 #elif defined(_GPIO_MASK_OUT_INIT_L)
116 #define _GPIO_MASK_OUT (_GPIO_MASK_OUT_INIT_L)
120 /* Include CONFIG_GPIO_RESET_BTN in GPIO inputs mask */
121 #if defined(CONFIG_GPIO_RESET_BTN)
122 #if defined(CONFIG_QCA_GPIO_MASK_IN)
123 #define _GPIO_MASK_IN ((CONFIG_QCA_GPIO_MASK_IN) |\
124 (1 << CONFIG_GPIO_RESET_BTN))
126 #define _GPIO_MASK_IN (1 << CONFIG_GPIO_RESET_BTN)
129 #if defined(CONFIG_QCA_GPIO_MASK_IN)
130 #define _GPIO_MASK_IN (CONFIG_QCA_GPIO_MASK_IN)
134 .globl lowlevel_gpio_init
135 .type lowlevel_gpio_init, @function
138 .ent lowlevel_gpio_init
142 * =========================
143 * Low level GPIO setup for:
147 * =========================
149 #if (SOC_TYPE & QCA_AR934X_SOC) ||\
150 (SOC_TYPE & QCA_QCA953X_SOC) ||\
151 (SOC_TYPE & QCA_QCA955X_SOC)
153 /* Sanity check for JTAG pins (GPIO 0~3) */
154 #if defined(CONFIG_SKIP_LOWLEVEL_INIT) ||\
155 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
156 #if defined(_GPIO_MASK_IN)
157 #define __GPIO_MASK_IN \
158 (_GPIO_MASK_IN & ~QCA_GPIO_JTAG_MASK)
161 #if defined(_GPIO_MASK_OUT)
162 #define __GPIO_MASK_OUT \
163 (_GPIO_MASK_OUT & ~QCA_GPIO_JTAG_MASK)
166 #if defined(_GPIO_MASK_OUT_INIT_H)
167 #define __GPIO_MASK_OUT_INIT_H \
168 (_GPIO_MASK_OUT_INIT_H & ~QCA_GPIO_JTAG_MASK)
171 #if defined(_GPIO_MASK_OUT_INIT_L)
172 #define __GPIO_MASK_OUT_INIT_L \
173 (_GPIO_MASK_OUT_INIT_L & ~QCA_GPIO_JTAG_MASK)
176 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_H)
177 #define _QCA_GPIO_MASK_LED_ACT_H \
178 (CONFIG_QCA_GPIO_MASK_LED_ACT_H & ~QCA_GPIO_JTAG_MASK)
181 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_L)
182 #define _QCA_GPIO_MASK_LED_ACT_L \
183 (CONFIG_QCA_GPIO_MASK_LED_ACT_L & ~QCA_GPIO_JTAG_MASK)
186 #if defined(CONFIG_QCA_GPIO_LSUART_TX) &&\
187 (CONFIG_QCA_GPIO_LSUART_TX & QCA_GPIO_JTAG_MASK)
188 #error "Cannot use JTAG pin for LSUART TX!"
191 #if defined(CONFIG_QCA_GPIO_LSUART_RX) &&\
192 (CONFIG_QCA_GPIO_LSUART_RX & QCA_GPIO_JTAG_MASK)
193 #error "Cannot use JTAG pin for LSUART RX!"
196 #if defined(_GPIO_MASK_IN)
197 #define __GPIO_MASK_IN _GPIO_MASK_IN
200 #if defined(_GPIO_MASK_OUT)
201 #define __GPIO_MASK_OUT _GPIO_MASK_OUT
204 #if defined(_GPIO_MASK_OUT_INIT_H)
205 #define __GPIO_MASK_OUT_INIT_H _GPIO_MASK_OUT_INIT_H
208 #if defined(_GPIO_MASK_OUT_INIT_L)
209 #define __GPIO_MASK_OUT_INIT_L _GPIO_MASK_OUT_INIT_L
212 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_H)
213 #define _QCA_GPIO_MASK_LED_ACT_H \
214 CONFIG_QCA_GPIO_MASK_LED_ACT_H
217 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_L)
218 #define _QCA_GPIO_MASK_LED_ACT_L \
219 CONFIG_QCA_GPIO_MASK_LED_ACT_L
225 * 1. By default JTAG (bit 1 set)
226 * 2. All clock observation (bits 2~9 reset)
228 li t8, QCA_GPIO_FUNC_REG
229 #if defined(CONFIG_SKIP_LOWLEVEL_INIT) ||\
230 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
233 li t9, QCA_GPIO_FUNC_JTAG_DIS_MASK
237 /* By default use GPIO10 for TX and GPIO9 for RX */
238 #if !defined(CONFIG_QCA_GPIO_LSUART_TX)
239 #define CONFIG_QCA_GPIO_LSUART_TX 10
242 #if !defined(CONFIG_QCA_GPIO_LSUART_RX)
243 #define CONFIG_QCA_GPIO_LSUART_RX 9
246 #define CONFIG_QCA_GPIO_MASK_LSUART_TX \
247 (1 << CONFIG_QCA_GPIO_LSUART_TX)
249 #define CONFIG_QCA_GPIO_MASK_LSUART_RX \
250 (1 << CONFIG_QCA_GPIO_LSUART_RX)
252 #define CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT \
253 (8 * (CONFIG_QCA_GPIO_LSUART_TX -\
254 ((CONFIG_QCA_GPIO_LSUART_TX / 4) * 4)))
256 /* Some sanity checks for LS UART GPIO lines */
257 #if (CONFIG_QCA_GPIO_LSUART_TX >= QCA_GPIO_COUNT) ||\
258 (CONFIG_QCA_GPIO_LSUART_RX >= QCA_GPIO_COUNT)
259 #error "LSUART GPIO numbers are incorrect!"
262 #if (CONFIG_QCA_GPIO_LSUART_TX == CONFIG_QCA_GPIO_LSUART_RX)
263 #error "LSUART TX and RX GPIO numbers cannot be the same!"
267 * Do not allow to use LSUART TX/RX lines
268 * as regular GPIO inputs/outputs at the same time
270 #if defined(__GPIO_MASK_IN)
271 #if (__GPIO_MASK_IN & CONFIG_QCA_GPIO_MASK_LSUART_TX) ||\
272 (__GPIO_MASK_IN & CONFIG_QCA_GPIO_MASK_LSUART_RX)
273 #error "Cannot use LSUART lines as GPIO inputs!"
277 #if defined(__GPIO_MASK_OUT)
278 #if (__GPIO_MASK_OUT & CONFIG_QCA_GPIO_MASK_LSUART_TX) ||\
279 (__GPIO_MASK_OUT & CONFIG_QCA_GPIO_MASK_LSUART_RX)
280 #error "Cannot use LSUART lines as GPIO outputs!"
285 * Target regular GPIO and LSUART TX line configuration
287 * After selecting GPIO as output in GPIO_OE register,
288 * the line will be set to low, which causes signal
289 * toggle on pulled-up lines
291 * To prevent this, we need to first setup desired
292 * init state for all GPIOs configured as outputs
293 * and then setup them as outputs
295 li t8, QCA_GPIO_OUT_REG
297 #if defined(__GPIO_MASK_OUT_INIT_H)
298 or t9, t9, (__GPIO_MASK_OUT_INIT_H | CONFIG_QCA_GPIO_MASK_LSUART_TX)
300 or t9, t9, CONFIG_QCA_GPIO_MASK_LSUART_TX
302 #if defined(__GPIO_MASK_OUT_INIT_L)
303 and t9, t9, ~__GPIO_MASK_OUT_INIT_L
308 * Setup GPIO type (out/in) in GPIO_OE
309 * register for all configured regular
310 * GPIOs and LSUART TX/RX lines
312 li t8, QCA_GPIO_OE_REG
314 #if defined(__GPIO_MASK_OUT)
315 #if (SOC_TYPE & QCA_QCA955X_SOC)
316 or t9, t9, (__GPIO_MASK_OUT | CONFIG_QCA_GPIO_MASK_LSUART_TX)
318 and t9, t9, ~(__GPIO_MASK_OUT | CONFIG_QCA_GPIO_MASK_LSUART_TX)
321 #if (SOC_TYPE & QCA_QCA955X_SOC)
322 or t9, t9, CONFIG_QCA_GPIO_MASK_LSUART_TX
324 and t9, t9, ~CONFIG_QCA_GPIO_MASK_LSUART_TX
327 #if defined(__GPIO_MASK_IN)
328 #if (SOC_TYPE & QCA_QCA955X_SOC)
329 and t9, t9, ~(__GPIO_MASK_IN | CONFIG_QCA_GPIO_MASK_LSUART_RX)
331 or t9, t9, (__GPIO_MASK_IN | CONFIG_QCA_GPIO_MASK_LSUART_RX)
334 #if (SOC_TYPE & QCA_QCA955X_SOC)
335 and t9, t9, ~CONFIG_QCA_GPIO_MASK_LSUART_RX
337 or t9, t9, CONFIG_QCA_GPIO_MASK_LSUART_RX
342 /* Setup GPIO number for LSUART RX in GPIO IN MUX */
343 li t8, QCA_GPIO_IN_EN0_REG
345 and t9, t9, ~(QCA_GPIO_IN_EN0_LSUART_RXD_MASK)
346 or t9, t9, (CONFIG_QCA_GPIO_LSUART_RX <<\
347 QCA_GPIO_IN_EN0_LSUART_RXD_SHIFT)
351 * TODO: what with default LSUART TX line?
353 * Some of QCA WiSoCs have GPIOs for LSUART TX/RX lines
354 * set by default (10 and 9 respectively) on reset and
355 * others do not (ex. QCA953x?).
357 * Because of that we can use more than one line
358 * for TX signal if we setup other than default
359 * GPIO for it, without change default GPIO
362 * Confirmed on AR9344 with LSUART TX set on
363 * GPIO1 and GPIO10 at the same time
367 * Set GPIO mode on desired lines and GPIO number
368 * for LSUART TX using GPIO_OUT_FUNCTIONX registers:
369 * - 0 ~ 3 -> GPIO_OUT_FUNCTION0 (mask: 0x00000F)
370 * - 4 ~ 7 -> GPIO_OUT_FUNCTION1 (mask: 0x0000F0)
371 * - 8 ~ 11 -> GPIO_OUT_FUNCTION2 (mask: 0x000F00)
372 * - 12 ~ 15 -> GPIO_OUT_FUNCTION3 (mask: 0x00F000)
373 * - 16 ~ 19 -> GPIO_OUT_FUNCTION4 (mask: 0x0F0000)
374 * - 20 ~ 23 -> GPIO_OUT_FUNCTION5 (mask: 0xF00000)
376 #if defined(__GPIO_MASK_OUT) || defined(__GPIO_MASK_IN) ||\
377 defined(CONFIG_QCA_GPIO_MASK_LSUART_TX)
379 /* GPIO_OUT_FUNCTION0 (GPIO 0~3) */
380 #if (__GPIO_MASK_OUT & 0x00000F) ||\
381 (__GPIO_MASK_IN & 0x00000F) ||\
382 (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00000F)
383 li t8, QCA_GPIO_OUT_FUNC0_REG
385 #if (__GPIO_MASK_OUT & GPIO0) ||\
386 (__GPIO_MASK_IN & GPIO0)
387 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO0_EN_MASK)
389 #if (__GPIO_MASK_OUT & GPIO1) ||\
390 (__GPIO_MASK_IN & GPIO1)
391 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO1_EN_MASK)
393 #if (__GPIO_MASK_OUT & GPIO2) ||\
394 (__GPIO_MASK_IN & GPIO2)
395 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO2_EN_MASK)
397 #if (__GPIO_MASK_OUT & GPIO3) ||\
398 (__GPIO_MASK_IN & GPIO3)
399 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO3_EN_MASK)
401 #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00000F)
402 and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
403 or t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL <<\
404 CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
409 /* GPIO_OUT_FUNCTION1 (GPIO 4~7) */
410 #if (__GPIO_MASK_OUT & 0x0000F0) ||\
411 (__GPIO_MASK_IN & 0x0000F0) ||\
412 (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0000F0)
413 li t8, QCA_GPIO_OUT_FUNC1_REG
415 #if (__GPIO_MASK_OUT & GPIO4) ||\
416 (__GPIO_MASK_IN & GPIO4)
417 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO4_EN_MASK)
419 #if (__GPIO_MASK_OUT & GPIO5) ||\
420 (__GPIO_MASK_IN & GPIO5)
421 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO5_EN_MASK)
423 #if (__GPIO_MASK_OUT & GPIO6) ||\
424 (__GPIO_MASK_IN & GPIO6)
425 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO6_EN_MASK)
427 #if (__GPIO_MASK_OUT & GPIO7) ||\
428 (__GPIO_MASK_IN & GPIO7)
429 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO7_EN_MASK)
431 #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0000F0)
432 and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
433 or t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL <<\
434 CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
439 /* GPIO_OUT_FUNCTION2 (GPIO 8~11) */
440 #if (__GPIO_MASK_OUT & 0x000F00) ||\
441 (__GPIO_MASK_IN & 0x000F00) ||\
442 (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x000F00)
443 li t8, QCA_GPIO_OUT_FUNC2_REG
445 #if (__GPIO_MASK_OUT & GPIO8) ||\
446 (__GPIO_MASK_IN & GPIO8)
447 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO8_EN_MASK)
449 #if (__GPIO_MASK_OUT & GPIO9) ||\
450 (__GPIO_MASK_IN & GPIO9)
451 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO9_EN_MASK)
453 #if (__GPIO_MASK_OUT & GPIO10) ||\
454 (__GPIO_MASK_IN & GPIO10)
455 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO10_EN_MASK)
457 #if (__GPIO_MASK_OUT & GPIO11) ||\
458 (__GPIO_MASK_IN & GPIO11)
459 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO11_EN_MASK)
461 #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x000F00)
462 and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
463 or t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL <<\
464 CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
469 /* GPIO_OUT_FUNCTION3 (GPIO 12~15) */
470 #if (__GPIO_MASK_OUT & 0x00F000) ||\
471 (__GPIO_MASK_IN & 0x00F000) ||\
472 (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00F000)
473 li t8, QCA_GPIO_OUT_FUNC3_REG
475 #if (__GPIO_MASK_OUT & GPIO12) ||\
476 (__GPIO_MASK_IN & GPIO12)
477 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO12_EN_MASK)
479 #if (__GPIO_MASK_OUT & GPIO13) ||\
480 (__GPIO_MASK_IN & GPIO13)
481 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO13_EN_MASK)
483 #if (__GPIO_MASK_OUT & GPIO14) ||\
484 (__GPIO_MASK_IN & GPIO14)
485 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO14_EN_MASK)
487 #if (__GPIO_MASK_OUT & GPIO15) ||\
488 (__GPIO_MASK_IN & GPIO15)
489 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO15_EN_MASK)
491 #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x00F000)
492 and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
493 or t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL <<\
494 CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
499 /* GPIO_OUT_FUNCTION4 (GPIO 16~19) */
500 #if (__GPIO_MASK_OUT & 0x0F0000) ||\
501 (__GPIO_MASK_IN & 0x0F0000) ||\
502 (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0F0000)
503 li t8, QCA_GPIO_OUT_FUNC4_REG
505 #if (__GPIO_MASK_OUT & GPIO16) ||\
506 (__GPIO_MASK_IN & GPIO16)
507 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO16_EN_MASK)
509 #if (__GPIO_MASK_OUT & GPIO17) ||\
510 (__GPIO_MASK_IN & GPIO17)
511 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO17_EN_MASK)
513 #if (__GPIO_MASK_OUT & GPIO18) ||\
514 (__GPIO_MASK_IN & GPIO18)
515 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO18_EN_MASK)
517 #if (__GPIO_MASK_OUT & GPIO19) ||\
518 (__GPIO_MASK_IN & GPIO19)
519 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO19_EN_MASK)
521 #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0x0F0000)
522 and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
523 or t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL <<\
524 CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
529 /* GPIO_OUT_FUNCTION5 (GPIO 20~23) */
530 #if (__GPIO_MASK_OUT & 0xF00000) ||\
531 (__GPIO_MASK_IN & 0xF00000) ||\
532 (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0xF00000)
533 li t8, QCA_GPIO_OUT_FUNC5_REG
535 #if (__GPIO_MASK_OUT & GPIO20) ||\
536 (__GPIO_MASK_IN & GPIO20)
537 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO20_EN_MASK)
539 #if (__GPIO_MASK_OUT & GPIO21) ||\
540 (__GPIO_MASK_IN & GPIO21)
541 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO21_EN_MASK)
543 #if (__GPIO_MASK_OUT & GPIO22) ||\
544 (__GPIO_MASK_IN & GPIO22)
545 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO22_EN_MASK)
547 #if (__GPIO_MASK_OUT & GPIO23) ||\
548 (__GPIO_MASK_IN & GPIO23)
549 and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO23_EN_MASK)
551 #if (CONFIG_QCA_GPIO_MASK_LSUART_TX & 0xF00000)
552 and t9, t9, ~(0xFF << CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
553 or t9, t9, (QCA_GPIO_OUT_MUX_LSUART_TXD_VAL <<\
554 CONFIG_QCA_GPIO_LSUART_TX_FUNCX_SHIFT)
562 * CONFIG_QCA_GPIO_MASK_LSUART_TX
565 #endif /* QCA_AR934X_SOC || QCA_QCA953X_SOC || QCA_QCA955X_SOC */
568 * ===============================
569 * Low level GPIO setup for AR933x
570 * ===============================
572 #if (SOC_TYPE & QCA_AR933X_SOC)
574 /* Sanity check for JTAG pins (GPIO 6~8, 29) */
575 #if defined(CONFIG_SKIP_LOWLEVEL_INIT) ||\
576 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
577 #if defined(_GPIO_MASK_IN)
578 #define __GPIO_MASK_IN \
579 (_GPIO_MASK_IN & ~QCA_GPIO_JTAG_MASK)
582 #if defined(_GPIO_MASK_OUT)
583 #define __GPIO_MASK_OUT \
584 (_GPIO_MASK_OUT & ~QCA_GPIO_JTAG_MASK)
587 #if defined(_GPIO_MASK_OUT_INIT_H)
588 #define __GPIO_MASK_OUT_INIT_H \
589 (_GPIO_MASK_OUT_INIT_H & ~QCA_GPIO_JTAG_MASK)
592 #if defined(_GPIO_MASK_OUT_INIT_L)
593 #define __GPIO_MASK_OUT_INIT_L \
594 (_GPIO_MASK_OUT_INIT_L & ~QCA_GPIO_JTAG_MASK)
597 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_H)
598 #define _QCA_GPIO_MASK_LED_ACT_H \
599 (CONFIG_QCA_GPIO_MASK_LED_ACT_H & ~QCA_GPIO_JTAG_MASK)
602 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_L)
603 #define _QCA_GPIO_MASK_LED_ACT_L \
604 (CONFIG_QCA_GPIO_MASK_LED_ACT_L & ~QCA_GPIO_JTAG_MASK)
607 #if defined(_GPIO_MASK_IN)
608 #define __GPIO_MASK_IN _GPIO_MASK_IN
611 #if defined(_GPIO_MASK_OUT)
612 #define __GPIO_MASK_OUT _GPIO_MASK_OUT
615 #if defined(_GPIO_MASK_OUT_INIT_H)
616 #define __GPIO_MASK_OUT_INIT_H _GPIO_MASK_OUT_INIT_H
619 #if defined(_GPIO_MASK_OUT_INIT_L)
620 #define __GPIO_MASK_OUT_INIT_L _GPIO_MASK_OUT_INIT_L
623 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_H)
624 #define _QCA_GPIO_MASK_LED_ACT_H \
625 CONFIG_QCA_GPIO_MASK_LED_ACT_H
628 #if defined(CONFIG_QCA_GPIO_MASK_LED_ACT_L)
629 #define _QCA_GPIO_MASK_LED_ACT_L \
630 CONFIG_QCA_GPIO_MASK_LED_ACT_L
635 * On AR933x HSUART TX/RX lines are connected to
636 * GPIO10 and GPIO9 respectively, so do not allow
637 * to use those GPIOs as regular at the same time
639 #if defined(__GPIO_MASK_IN)
640 #if (__GPIO_MASK_IN & (GPIO9 | GPIO10))
641 #error "Cannot use HSUART lines as GPIO inputs!"
645 #if defined(__GPIO_MASK_OUT)
646 #if (__GPIO_MASK_OUT & (GPIO9 | GPIO10))
647 #error "Cannot use HSUART lines as GPIO outputs!"
652 * Workaround for hang issue,
653 * from original Atheros (Q)SDK:
655 * "Hornet 1.1 currently need a reset
656 * once we boot to let the resetb has
657 * enough time to stable, so that
658 * trigger reset at 1st boot".
660 * Read one 4 byte value from SRAM base address and compare it with
661 * known magic number (0x12345678 here), if it's the same, it means
662 * that this is not first boot and we can continue. Otherwise, make
663 * full chip reset (it's not power reset, SRAM data will survive).
665 * We need it here as it's first custom asm code
666 * executed in start{_bootstrap).S
670 #if !defined(CONFIG_SKIP_LOWLEVEL_INIT)
676 bne t9, t7, full_reset
683 li t8, QCA_RST_RESET_REG
685 or t9, t9, (QCA_RST_RESET_FULL_CHIP_RST_MASK |\
686 QCA_RST_RESET_DDR_RST_MASK)
695 * GPIO configuration, using GPIO_FUNCTION_1 register:
696 * 1. Disable JTAG by default
697 * 2. Enable HSUART on GPIO9 and GPIO10 by default
698 * 3. Disable HSUART RTS/CTS on GPIO11/12 if needed
699 * 4. Disable selected Ethernet switch LEDs if needed
702 li t8, QCA_GPIO_FUNC_1_REG
704 #if defined(CONFIG_SKIP_LOWLEVEL_INIT) ||\
705 defined(CONFIG_QCA_KEEP_JTAG_ENABLED)
706 and t9, t9, ~(QCA_GPIO_FUNC_1_JTAG_DIS_MASK)
707 or t9, t9, QCA_GPIO_FUNC_1_UART_EN_MASK
709 or t9, t9, (QCA_GPIO_FUNC_1_JTAG_DIS_MASK |\
710 QCA_GPIO_FUNC_1_UART_EN_MASK)
712 #if (__GPIO_MASK_OUT & (GPIO11 | GPIO12)) ||\
713 (__GPIO_MASK_IN & (GPIO11 | GPIO12))
714 and t9, t9, ~(QCA_GPIO_FUNC_1_UART_RTS_CTS_EN_MASK)
716 #if (__GPIO_MASK_OUT & GPIO13) ||\
717 (__GPIO_MASK_IN & GPIO13)
718 and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED0_EN_MASK)
720 #if (__GPIO_MASK_OUT & GPIO14) ||\
721 (__GPIO_MASK_IN & GPIO14)
722 and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED1_EN_MASK)
724 #if (__GPIO_MASK_OUT & GPIO15) ||\
725 (__GPIO_MASK_IN & GPIO15)
726 and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED2_EN_MASK)
728 #if (__GPIO_MASK_OUT & GPIO16) ||\
729 (__GPIO_MASK_IN & GPIO16)
730 and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED3_EN_MASK)
732 #if (__GPIO_MASK_OUT & GPIO17) ||\
733 (__GPIO_MASK_IN & GPIO17)
734 and t9, t9, ~(QCA_GPIO_FUNC_1_ETH_SW_LED4_EN_MASK)
736 #if (__GPIO_MASK_OUT & GPIO9)
737 and t9, t9, ~(QCA_GPIO_FUNC_1_SPI_CS_EN1_MASK)
739 #if (__GPIO_MASK_OUT & GPIO10)
740 and t9, t9, ~(QCA_GPIO_FUNC_1_SPI_CS_EN2_MASK)
742 /* From datasheet: bit 15 should be written with 1 */
743 or t9, t9, ((1 << 15) | QCA_GPIO_FUNC_1_SPI_EN_MASK)
746 /* Enable regular GPIO function on GPIO26 and/or GPIO27 if needed */
747 #if defined(__GPIO_MASK_OUT) || defined(__GPIO_MASK_IN)
748 #if (__GPIO_MASK_OUT & (GPIO26 | GPIO27)) ||\
749 (__GPIO_MASK_IN & (GPIO26 | GPIO27))
750 li t8, QCA_RST_BOOTSTRAP_REG
752 or t9, t9, QCA_RST_BOOTSTRAP_MDIO_GPIO_EN_MASK
757 /* Enable regular GPIO function on GPIO11 and/or GPIO12 if needed */
758 #if defined(__GPIO_MASK_OUT) || defined(__GPIO_MASK_IN)
759 #if (__GPIO_MASK_OUT & (GPIO11 | GPIO12)) ||\
760 (__GPIO_MASK_IN & (GPIO11 | GPIO12))
761 li t8, QCA_GPIO_FUNC_2_REG
763 #if (__GPIO_MASK_OUT & GPIO11) ||\
764 (__GPIO_MASK_IN & GPIO11)
765 or t9, t9, QCA_GPIO_FUNC_2_JUMPSTART_DIS_MASK
767 #if (__GPIO_MASK_OUT & GPIO12) ||\
768 (__GPIO_MASK_IN & GPIO12)
769 or t9, t9, QCA_GPIO_FUNC_2_WPS_DIS_MASK
775 /* Setup init states on requested GPIO lines */
776 li t8, QCA_GPIO_OUT_REG
778 #if defined(__GPIO_MASK_OUT_INIT_H)
779 or t9, t9, __GPIO_MASK_OUT_INIT_H
781 #if defined(__GPIO_MASK_OUT_INIT_L)
782 and t9, t9, ~__GPIO_MASK_OUT_INIT_L
786 /* Setup GPIOs in OE register */
787 #if defined(__GPIO_MASK_OUT) || defined(__GPIO_MASK_IN)
788 li t8, QCA_GPIO_OE_REG
790 #if defined(__GPIO_MASK_OUT)
791 or t9, t9, __GPIO_MASK_OUT
793 #if defined(__GPIO_MASK_IN)
794 and t9, t9, ~__GPIO_MASK_IN
799 #endif /* (SOC_TYPE & QCA_AR933X_SOC) */
802 * Custom, GPIO related code for boards should go here,
803 * after initial/basic GPIO configuration
807 * Some YunCore have on PCB, on button reset
808 * line (GPIO17) a huge capacitor (~10u)...
809 * which means that before the voltage level
810 * rises to VCC, our O/C recovery mode reads
811 * reset button input as low.
813 * So, delay start for some time here.
817 #if defined(CONFIG_FOR_YUNCORE_AP90Q) ||\
818 defined(CONFIG_FOR_YUNCORE_CPE830) ||\
819 defined(CONFIG_FOR_YUNCORE_T830)
825 bne t8, t9, loop_start
827 #endif /* CONFIG_FOR_YUNCORE_AP90Q */
832 .end lowlevel_gpio_init
835 * Set all predefined GPIO driven LEDs ON
839 .type all_led_on, @function
845 #if defined(_QCA_GPIO_MASK_LED_ACT_H) || defined(_QCA_GPIO_MASK_LED_ACT_L)
846 li t8, QCA_GPIO_OUT_REG
848 #if defined(_QCA_GPIO_MASK_LED_ACT_H)
849 or t9, t9, _QCA_GPIO_MASK_LED_ACT_H
851 #if defined(_QCA_GPIO_MASK_LED_ACT_L)
852 and t9, t9, ~(_QCA_GPIO_MASK_LED_ACT_L)
865 * Set all predefined GPIO driven LEDs OFF
869 .type all_led_off, @function
875 #if defined(_QCA_GPIO_MASK_LED_ACT_H) || defined(_QCA_GPIO_MASK_LED_ACT_L)
876 li t8, QCA_GPIO_OUT_REG
878 #if defined(_QCA_GPIO_MASK_LED_ACT_H)
879 and t9, t9, ~(_QCA_GPIO_MASK_LED_ACT_H)
881 #if defined(_QCA_GPIO_MASK_LED_ACT_L)
882 or t9, t9, _QCA_GPIO_MASK_LED_ACT_L