Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <platform_def.h> |
| 8 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 9 | #include <arch.h> |
| 10 | #include <asm_macros.S> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <common/bl_common.h> |
| 12 | #include <drivers/st/stm32_gpio.h> |
| 13 | #include <drivers/st/stm32mp1_rcc.h> |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 14 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 15 | #define GPIO_TX_SHIFT (DEBUG_UART_TX_GPIO_PORT << 1) |
| 16 | #define GPIO_TX_ALT_SHIFT ((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2) |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 17 | |
| 18 | .globl platform_mem_init |
| 19 | .globl plat_report_exception |
| 20 | .globl plat_get_my_entrypoint |
| 21 | .globl plat_secondary_cold_boot_setup |
| 22 | .globl plat_reset_handler |
| 23 | .globl plat_is_my_cpu_primary |
| 24 | .globl plat_my_core_pos |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 25 | .globl plat_crash_console_init |
| 26 | .globl plat_crash_console_flush |
| 27 | .globl plat_crash_console_putc |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 28 | .globl plat_panic_handler |
| 29 | |
| 30 | func platform_mem_init |
| 31 | /* Nothing to do, don't need to init SYSRAM */ |
| 32 | bx lr |
| 33 | endfunc platform_mem_init |
| 34 | |
| 35 | func plat_report_exception |
| 36 | bx lr |
| 37 | endfunc plat_report_exception |
| 38 | |
| 39 | func plat_reset_handler |
| 40 | bx lr |
| 41 | endfunc plat_reset_handler |
| 42 | |
| 43 | /* ------------------------------------------------------------------ |
| 44 | * unsigned long plat_get_my_entrypoint (void); |
| 45 | * |
| 46 | * Main job of this routine is to distinguish between a cold and warm |
| 47 | * boot. |
| 48 | * |
| 49 | * Currently supports only cold boot |
| 50 | * ------------------------------------------------------------------ |
| 51 | */ |
| 52 | func plat_get_my_entrypoint |
| 53 | mov r0, #0 |
| 54 | bx lr |
| 55 | endfunc plat_get_my_entrypoint |
| 56 | |
| 57 | /* --------------------------------------------- |
| 58 | * void plat_secondary_cold_boot_setup (void); |
| 59 | * |
| 60 | * Cold-booting secondary CPUs is not supported. |
| 61 | * --------------------------------------------- |
| 62 | */ |
| 63 | func plat_secondary_cold_boot_setup |
| 64 | b . |
| 65 | endfunc plat_secondary_cold_boot_setup |
| 66 | |
| 67 | /* ----------------------------------------------------- |
| 68 | * unsigned int plat_is_my_cpu_primary (void); |
| 69 | * |
| 70 | * Find out whether the current cpu is the primary cpu. |
| 71 | * ----------------------------------------------------- |
| 72 | */ |
| 73 | func plat_is_my_cpu_primary |
| 74 | ldcopr r0, MPIDR |
| 75 | ldr r1, =(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK) |
| 76 | and r0, r1 |
| 77 | cmp r0, #STM32MP1_PRIMARY_CPU |
| 78 | moveq r0, #1 |
| 79 | movne r0, #0 |
| 80 | bx lr |
| 81 | endfunc plat_is_my_cpu_primary |
| 82 | |
| 83 | /* ------------------------------------------- |
| 84 | * int plat_stm32mp1_get_core_pos(int mpidr); |
| 85 | * |
| 86 | * Return CorePos = (ClusterId * 4) + CoreId |
| 87 | * ------------------------------------------- |
| 88 | */ |
| 89 | func plat_stm32mp1_get_core_pos |
| 90 | and r1, r0, #MPIDR_CPU_MASK |
| 91 | and r0, r0, #MPIDR_CLUSTER_MASK |
| 92 | add r0, r1, r0, LSR #6 |
| 93 | bx lr |
| 94 | endfunc plat_stm32mp1_get_core_pos |
| 95 | |
| 96 | /* ------------------------------------ |
| 97 | * unsigned int plat_my_core_pos(void) |
| 98 | * ------------------------------------ |
| 99 | */ |
| 100 | func plat_my_core_pos |
| 101 | ldcopr r0, MPIDR |
| 102 | b plat_stm32mp1_get_core_pos |
| 103 | endfunc plat_my_core_pos |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 104 | |
| 105 | /* --------------------------------------------- |
| 106 | * int plat_crash_console_init(void) |
| 107 | * |
| 108 | * Initialize the crash console without a C Runtime stack. |
| 109 | * --------------------------------------------- |
| 110 | */ |
| 111 | func plat_crash_console_init |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 112 | /* Enable GPIOs for UART TX */ |
| 113 | ldr r1, =(RCC_BASE + DEBUG_UART_TX_GPIO_BANK_CLK_REG) |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 114 | ldr r2, [r1] |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 115 | /* Configure GPIO */ |
| 116 | orr r2, r2, #DEBUG_UART_TX_GPIO_BANK_CLK_EN |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 117 | str r2, [r1] |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 118 | ldr r1, =DEBUG_UART_TX_GPIO_BANK_ADDRESS |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 119 | /* Set GPIO mode alternate */ |
| 120 | ldr r2, [r1, #GPIO_MODE_OFFSET] |
| 121 | bic r2, r2, #(GPIO_MODE_MASK << GPIO_TX_SHIFT) |
| 122 | orr r2, r2, #(GPIO_MODE_ALTERNATE << GPIO_TX_SHIFT) |
| 123 | str r2, [r1, #GPIO_MODE_OFFSET] |
| 124 | /* Set GPIO speed low */ |
| 125 | ldr r2, [r1, #GPIO_SPEED_OFFSET] |
| 126 | bic r2, r2, #(GPIO_SPEED_MASK << GPIO_TX_SHIFT) |
| 127 | str r2, [r1, #GPIO_SPEED_OFFSET] |
| 128 | /* Set no-pull */ |
| 129 | ldr r2, [r1, #GPIO_PUPD_OFFSET] |
| 130 | bic r2, r2, #(GPIO_PULL_MASK << GPIO_TX_SHIFT) |
| 131 | str r2, [r1, #GPIO_PUPD_OFFSET] |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 132 | /* Set alternate */ |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 133 | ldr r2, [r1, #GPIO_AFRH_OFFSET] |
| 134 | bic r2, r2, #(GPIO_ALTERNATE_MASK << GPIO_TX_ALT_SHIFT) |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 135 | orr r2, r2, #(DEBUG_UART_TX_GPIO_ALTERNATE << GPIO_TX_ALT_SHIFT) |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 136 | str r2, [r1, #GPIO_AFRH_OFFSET] |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 137 | /* Enable UART clock, with its source */ |
| 138 | ldr r1, =(RCC_BASE + DEBUG_UART_TX_CLKSRC_REG) |
| 139 | mov r2, #DEBUG_UART_TX_CLKSRC |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 140 | str r2, [r1] |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 141 | ldr r1, =(RCC_BASE + DEBUG_UART_TX_EN_REG) |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 142 | ldr r2, [r1] |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 143 | orr r2, r2, #DEBUG_UART_TX_EN |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 144 | str r2, [r1] |
| 145 | |
| 146 | ldr r0, =STM32MP1_DEBUG_USART_BASE |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 147 | ldr r1, =STM32MP1_DEBUG_USART_CLK_FRQ |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 148 | ldr r2, =STM32MP1_UART_BAUDRATE |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 149 | b console_stm32_core_init |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 150 | endfunc plat_crash_console_init |
| 151 | |
| 152 | /* --------------------------------------------- |
| 153 | * int plat_crash_console_flush(void) |
| 154 | * |
| 155 | * Flush the crash console without a C Runtime stack. |
| 156 | * --------------------------------------------- |
| 157 | */ |
| 158 | func plat_crash_console_flush |
| 159 | ldr r1, =STM32MP1_DEBUG_USART_BASE |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 160 | b console_stm32_core_flush |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 161 | endfunc plat_crash_console_flush |
| 162 | |
| 163 | /* --------------------------------------------- |
| 164 | * int plat_crash_console_putc(int c) |
| 165 | * |
| 166 | * Print a character on the crash console without a C Runtime stack. |
| 167 | * Clobber list : r1 - r3 |
| 168 | * |
| 169 | * In case of bootloading through uart, we keep console crash as this. |
| 170 | * Characters could be sent to the programmer, but will be ignored. |
| 171 | * No specific code in that case. |
| 172 | * --------------------------------------------- |
| 173 | */ |
| 174 | func plat_crash_console_putc |
| 175 | ldr r1, =STM32MP1_DEBUG_USART_BASE |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 176 | b console_stm32_core_putc |
Yann Gautier | 69035a8 | 2018-07-05 16:48:16 +0200 | [diff] [blame] | 177 | endfunc plat_crash_console_putc |