blob: bfcd991a3dd3453aea8c752e0e5ef95bfeb8c818 [file] [log] [blame]
Yann Gautier4b0c72a2018-07-16 10:54:09 +02001/*
Yann Gautier038bff22019-01-17 19:17:47 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Yann Gautier4b0c72a2018-07-16 10:54:09 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <platform_def.h>
8
Yann Gautier4b0c72a2018-07-16 10:54:09 +02009#include <arch.h>
10#include <asm_macros.S>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <common/bl_common.h>
12#include <drivers/st/stm32_gpio.h>
Yann Gautier69035a82018-07-05 16:48:16 +020013
Yann Gautier038bff22019-01-17 19:17:47 +010014#define GPIO_TX_SHIFT (DEBUG_UART_TX_GPIO_PORT << 1)
15#define GPIO_TX_ALT_SHIFT ((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2)
Yann Gautier4b0c72a2018-07-16 10:54:09 +020016
17 .globl platform_mem_init
18 .globl plat_report_exception
19 .globl plat_get_my_entrypoint
20 .globl plat_secondary_cold_boot_setup
21 .globl plat_reset_handler
22 .globl plat_is_my_cpu_primary
23 .globl plat_my_core_pos
Yann Gautier69035a82018-07-05 16:48:16 +020024 .globl plat_crash_console_init
25 .globl plat_crash_console_flush
26 .globl plat_crash_console_putc
Yann Gautier4b0c72a2018-07-16 10:54:09 +020027 .globl plat_panic_handler
28
29func platform_mem_init
30 /* Nothing to do, don't need to init SYSRAM */
31 bx lr
32endfunc platform_mem_init
33
34func plat_report_exception
35 bx lr
36endfunc plat_report_exception
37
38func plat_reset_handler
39 bx lr
40endfunc plat_reset_handler
41
42 /* ------------------------------------------------------------------
43 * unsigned long plat_get_my_entrypoint (void);
44 *
45 * Main job of this routine is to distinguish between a cold and warm
46 * boot.
47 *
48 * Currently supports only cold boot
49 * ------------------------------------------------------------------
50 */
51func plat_get_my_entrypoint
52 mov r0, #0
53 bx lr
54endfunc plat_get_my_entrypoint
55
56 /* ---------------------------------------------
57 * void plat_secondary_cold_boot_setup (void);
58 *
59 * Cold-booting secondary CPUs is not supported.
60 * ---------------------------------------------
61 */
62func plat_secondary_cold_boot_setup
63 b .
64endfunc plat_secondary_cold_boot_setup
65
66 /* -----------------------------------------------------
67 * unsigned int plat_is_my_cpu_primary (void);
68 *
69 * Find out whether the current cpu is the primary cpu.
70 * -----------------------------------------------------
71 */
72func plat_is_my_cpu_primary
73 ldcopr r0, MPIDR
74 ldr r1, =(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
75 and r0, r1
Yann Gautiera2e2a302019-02-14 11:13:39 +010076 cmp r0, #STM32MP_PRIMARY_CPU
Yann Gautier4b0c72a2018-07-16 10:54:09 +020077 moveq r0, #1
78 movne r0, #0
79 bx lr
80endfunc plat_is_my_cpu_primary
81
82 /* -------------------------------------------
83 * int plat_stm32mp1_get_core_pos(int mpidr);
84 *
85 * Return CorePos = (ClusterId * 4) + CoreId
86 * -------------------------------------------
87 */
88func plat_stm32mp1_get_core_pos
89 and r1, r0, #MPIDR_CPU_MASK
90 and r0, r0, #MPIDR_CLUSTER_MASK
91 add r0, r1, r0, LSR #6
92 bx lr
93endfunc plat_stm32mp1_get_core_pos
94
95 /* ------------------------------------
96 * unsigned int plat_my_core_pos(void)
97 * ------------------------------------
98 */
99func plat_my_core_pos
100 ldcopr r0, MPIDR
101 b plat_stm32mp1_get_core_pos
102endfunc plat_my_core_pos
Yann Gautier69035a82018-07-05 16:48:16 +0200103
104 /* ---------------------------------------------
105 * int plat_crash_console_init(void)
106 *
107 * Initialize the crash console without a C Runtime stack.
108 * ---------------------------------------------
109 */
110func plat_crash_console_init
Yann Gautier038bff22019-01-17 19:17:47 +0100111 /* Enable GPIOs for UART TX */
112 ldr r1, =(RCC_BASE + DEBUG_UART_TX_GPIO_BANK_CLK_REG)
Yann Gautier69035a82018-07-05 16:48:16 +0200113 ldr r2, [r1]
Yann Gautier038bff22019-01-17 19:17:47 +0100114 /* Configure GPIO */
115 orr r2, r2, #DEBUG_UART_TX_GPIO_BANK_CLK_EN
Yann Gautier69035a82018-07-05 16:48:16 +0200116 str r2, [r1]
Yann Gautier038bff22019-01-17 19:17:47 +0100117 ldr r1, =DEBUG_UART_TX_GPIO_BANK_ADDRESS
Yann Gautier69035a82018-07-05 16:48:16 +0200118 /* Set GPIO mode alternate */
119 ldr r2, [r1, #GPIO_MODE_OFFSET]
120 bic r2, r2, #(GPIO_MODE_MASK << GPIO_TX_SHIFT)
121 orr r2, r2, #(GPIO_MODE_ALTERNATE << GPIO_TX_SHIFT)
122 str r2, [r1, #GPIO_MODE_OFFSET]
123 /* Set GPIO speed low */
124 ldr r2, [r1, #GPIO_SPEED_OFFSET]
125 bic r2, r2, #(GPIO_SPEED_MASK << GPIO_TX_SHIFT)
126 str r2, [r1, #GPIO_SPEED_OFFSET]
127 /* Set no-pull */
128 ldr r2, [r1, #GPIO_PUPD_OFFSET]
129 bic r2, r2, #(GPIO_PULL_MASK << GPIO_TX_SHIFT)
130 str r2, [r1, #GPIO_PUPD_OFFSET]
Yann Gautier038bff22019-01-17 19:17:47 +0100131 /* Set alternate */
Yann Gautier69035a82018-07-05 16:48:16 +0200132 ldr r2, [r1, #GPIO_AFRH_OFFSET]
133 bic r2, r2, #(GPIO_ALTERNATE_MASK << GPIO_TX_ALT_SHIFT)
Yann Gautier038bff22019-01-17 19:17:47 +0100134 orr r2, r2, #(DEBUG_UART_TX_GPIO_ALTERNATE << GPIO_TX_ALT_SHIFT)
Yann Gautier69035a82018-07-05 16:48:16 +0200135 str r2, [r1, #GPIO_AFRH_OFFSET]
Yann Gautier038bff22019-01-17 19:17:47 +0100136 /* Enable UART clock, with its source */
137 ldr r1, =(RCC_BASE + DEBUG_UART_TX_CLKSRC_REG)
138 mov r2, #DEBUG_UART_TX_CLKSRC
Yann Gautier69035a82018-07-05 16:48:16 +0200139 str r2, [r1]
Yann Gautier038bff22019-01-17 19:17:47 +0100140 ldr r1, =(RCC_BASE + DEBUG_UART_TX_EN_REG)
Yann Gautier69035a82018-07-05 16:48:16 +0200141 ldr r2, [r1]
Yann Gautier038bff22019-01-17 19:17:47 +0100142 orr r2, r2, #DEBUG_UART_TX_EN
Yann Gautier69035a82018-07-05 16:48:16 +0200143 str r2, [r1]
144
Yann Gautiera2e2a302019-02-14 11:13:39 +0100145 ldr r0, =STM32MP_DEBUG_USART_BASE
146 ldr r1, =STM32MP_DEBUG_USART_CLK_FRQ
147 ldr r2, =STM32MP_UART_BAUDRATE
Yann Gautier8593e442018-11-14 18:46:15 +0100148 b console_stm32_core_init
Yann Gautier69035a82018-07-05 16:48:16 +0200149endfunc plat_crash_console_init
150
151 /* ---------------------------------------------
152 * int plat_crash_console_flush(void)
153 *
154 * Flush the crash console without a C Runtime stack.
155 * ---------------------------------------------
156 */
157func plat_crash_console_flush
Yann Gautiera2e2a302019-02-14 11:13:39 +0100158 ldr r1, =STM32MP_DEBUG_USART_BASE
Yann Gautier8593e442018-11-14 18:46:15 +0100159 b console_stm32_core_flush
Yann Gautier69035a82018-07-05 16:48:16 +0200160endfunc plat_crash_console_flush
161
162 /* ---------------------------------------------
163 * int plat_crash_console_putc(int c)
164 *
165 * Print a character on the crash console without a C Runtime stack.
166 * Clobber list : r1 - r3
167 *
168 * In case of bootloading through uart, we keep console crash as this.
169 * Characters could be sent to the programmer, but will be ignored.
170 * No specific code in that case.
171 * ---------------------------------------------
172 */
173func plat_crash_console_putc
Yann Gautiera2e2a302019-02-14 11:13:39 +0100174 ldr r1, =STM32MP_DEBUG_USART_BASE
Yann Gautier8593e442018-11-14 18:46:15 +0100175 b console_stm32_core_putc
Yann Gautier69035a82018-07-05 16:48:16 +0200176endfunc plat_crash_console_putc