blob: 9838b55f64020911e661563f3106382d22083bd1 [file] [log] [blame]
Yann Gautier35527fb2023-06-14 10:40:59 +02001/*
Yann Gautier3007c722023-09-19 18:26:16 +02002 * Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
Yann Gautier35527fb2023-06-14 10:40:59 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef STM32MP2_DEF_H
8#define STM32MP2_DEF_H
9
10#include <common/tbbr/tbbr_img_def.h>
11#ifndef __ASSEMBLER__
12#include <drivers/st/bsec.h>
13#endif
Yann Gautier87a940e2023-06-14 18:05:47 +020014#include <drivers/st/stm32mp25_rcc.h>
Yann Gautierdb77f8b2024-05-21 11:46:59 +020015#ifndef __ASSEMBLER__
16#include <drivers/st/stm32mp2_clk.h>
17#endif
18#include <drivers/st/stm32mp2_pwr.h>
Yann Gautier35527fb2023-06-14 10:40:59 +020019#include <dt-bindings/clock/stm32mp25-clks.h>
20#include <dt-bindings/clock/stm32mp25-clksrc.h>
Pascal Paillete04a9ef2022-03-16 17:25:57 +010021#include <dt-bindings/gpio/stm32-gpio.h>
Yann Gautier35527fb2023-06-14 10:40:59 +020022#include <dt-bindings/reset/stm32mp25-resets.h>
23
24#ifndef __ASSEMBLER__
25#include <boot_api.h>
Yann Gautier3007c722023-09-19 18:26:16 +020026#include <stm32mp2_private.h>
Yann Gautier35527fb2023-06-14 10:40:59 +020027#include <stm32mp_common.h>
28#include <stm32mp_dt.h>
29#include <stm32mp_shared_resources.h>
30#endif
31
32/*******************************************************************************
Yann Gautier381b2a62024-06-21 14:49:47 +020033 * CHIP ID
34 ******************************************************************************/
35#define STM32MP2_CHIP_ID U(0x505)
36
37#define STM32MP251A_PART_NB U(0x400B3E6D)
38#define STM32MP251C_PART_NB U(0x000B306D)
39#define STM32MP251D_PART_NB U(0xC00B3E6D)
40#define STM32MP251F_PART_NB U(0x800B306D)
41#define STM32MP253A_PART_NB U(0x400B3E0C)
42#define STM32MP253C_PART_NB U(0x000B300C)
43#define STM32MP253D_PART_NB U(0xC00B3E0C)
44#define STM32MP253F_PART_NB U(0x800B300C)
45#define STM32MP255A_PART_NB U(0x40082E00)
46#define STM32MP255C_PART_NB U(0x00082000)
47#define STM32MP255D_PART_NB U(0xC0082E00)
48#define STM32MP255F_PART_NB U(0x80082000)
49#define STM32MP257A_PART_NB U(0x40002E00)
50#define STM32MP257C_PART_NB U(0x00002000)
51#define STM32MP257D_PART_NB U(0xC0002E00)
52#define STM32MP257F_PART_NB U(0x80002000)
53
54#define STM32MP2_REV_A U(0x08)
55#define STM32MP2_REV_B U(0x10)
56#define STM32MP2_REV_X U(0x12)
57#define STM32MP2_REV_Y U(0x11)
58#define STM32MP2_REV_Z U(0x09)
59
60/*******************************************************************************
61 * PACKAGE ID
62 ******************************************************************************/
63#define STM32MP25_PKG_CUSTOM U(0)
64#define STM32MP25_PKG_AL_VFBGA361 U(1)
65#define STM32MP25_PKG_AK_VFBGA424 U(3)
66#define STM32MP25_PKG_AI_TFBGA436 U(5)
67#define STM32MP25_PKG_UNKNOWN U(7)
68
69/*******************************************************************************
Yann Gautier35527fb2023-06-14 10:40:59 +020070 * STM32MP2 memory map related constants
71 ******************************************************************************/
72#define STM32MP_SYSRAM_BASE U(0x0E000000)
73#define STM32MP_SYSRAM_SIZE U(0x00040000)
Maxime Méréae845252024-09-13 17:57:58 +020074#define SRAM1_BASE U(0x0E040000)
75#define SRAM1_SIZE_FOR_TFA U(0x00010000)
Maxime Méré52f530d2024-09-19 09:54:28 +020076#define RETRAM_BASE U(0x0E080000)
77#define RETRAM_SIZE U(0x00020000)
78
Yann Gautier03020b62023-06-13 18:45:03 +020079#define STM32MP_SEC_SYSRAM_SIZE STM32MP_SYSRAM_SIZE
Yann Gautier35527fb2023-06-14 10:40:59 +020080
Yann Gautier35527fb2023-06-14 10:40:59 +020081/* DDR configuration */
82#define STM32MP_DDR_BASE U(0x80000000)
83#define STM32MP_DDR_MAX_SIZE UL(0x100000000) /* Max 4GB */
84
85/* DDR power initializations */
86#ifndef __ASSEMBLER__
87enum ddr_type {
88 STM32MP_DDR3,
89 STM32MP_DDR4,
90 STM32MP_LPDDR4
91};
92#endif
93
Yann Gautiere5839ed2023-06-14 18:44:41 +020094/* Section used inside TF binaries */
95#define STM32MP_PARAM_LOAD_SIZE U(0x00002400) /* 9 KB for param */
Yann Gautierdb77f8b2024-05-21 11:46:59 +020096/* 512 Bytes reserved for header */
Yann Gautiere5839ed2023-06-14 18:44:41 +020097#define STM32MP_HEADER_SIZE U(0x00000200)
Yann Gautierdb77f8b2024-05-21 11:46:59 +020098#define STM32MP_HEADER_BASE (STM32MP_SYSRAM_BASE + \
Yann Gautiere5839ed2023-06-14 18:44:41 +020099 STM32MP_PARAM_LOAD_SIZE)
100
101/* round_up(STM32MP_PARAM_LOAD_SIZE + STM32MP_HEADER_SIZE, PAGE_SIZE) */
102#define STM32MP_HEADER_RESERVED_SIZE U(0x3000)
103
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200104#define STM32MP_BINARY_BASE (STM32MP_SYSRAM_BASE + \
Yann Gautiere5839ed2023-06-14 18:44:41 +0200105 STM32MP_PARAM_LOAD_SIZE + \
106 STM32MP_HEADER_SIZE)
107
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200108#define STM32MP_BINARY_SIZE (STM32MP_SYSRAM_SIZE - \
Yann Gautiere5839ed2023-06-14 18:44:41 +0200109 (STM32MP_PARAM_LOAD_SIZE + \
110 STM32MP_HEADER_SIZE))
111
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200112#define STM32MP_BL2_RO_SIZE U(0x00020000) /* 128 KB */
113#define STM32MP_BL2_SIZE U(0x00029000) /* 164 KB for BL2 */
Yann Gautier35527fb2023-06-14 10:40:59 +0200114
Maxime Méré64e5a6d2024-09-20 17:16:20 +0200115/* Allocate remaining sysram to BL31 Binary only */
Yann Gautier03020b62023-06-13 18:45:03 +0200116#define STM32MP_BL31_SIZE (STM32MP_SEC_SYSRAM_SIZE - \
117 STM32MP_BL2_SIZE)
118
Maxime Méré64e5a6d2024-09-20 17:16:20 +0200119#define BL31_PROGBITS_LIMIT STM32MP_BL31_SIZE
120
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200121#define STM32MP_BL2_BASE (STM32MP_SYSRAM_BASE + \
122 STM32MP_SYSRAM_SIZE - \
Yann Gautier35527fb2023-06-14 10:40:59 +0200123 STM32MP_BL2_SIZE)
124
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200125#define STM32MP_BL2_RO_BASE STM32MP_BL2_BASE
126
127#define STM32MP_BL2_RW_BASE (STM32MP_BL2_RO_BASE + \
128 STM32MP_BL2_RO_SIZE)
129
130#define STM32MP_BL2_RW_SIZE (STM32MP_SYSRAM_BASE + \
131 STM32MP_SYSRAM_SIZE - \
132 STM32MP_BL2_RW_BASE)
133
Yann Gautier35527fb2023-06-14 10:40:59 +0200134/* BL2 and BL32/sp_min require 4 tables */
135#define MAX_XLAT_TABLES U(4) /* 16 KB for mapping */
136
137/*
138 * MAX_MMAP_REGIONS is usually:
139 * BL stm32mp2_mmap size + mmap regions in *_plat_arch_setup
140 */
141#define MAX_MMAP_REGIONS 6
142
Yann Gautiere5839ed2023-06-14 18:44:41 +0200143/* DTB initialization value */
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200144#define STM32MP_BL2_DTB_SIZE U(0x00006000) /* 24 KB for DTB */
Yann Gautiere5839ed2023-06-14 18:44:41 +0200145
146#define STM32MP_BL2_DTB_BASE (STM32MP_BL2_BASE - \
147 STM32MP_BL2_DTB_SIZE)
148
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200149#if defined(IMAGE_BL2)
150#define STM32MP_DTB_SIZE STM32MP_BL2_DTB_SIZE
151#define STM32MP_DTB_BASE STM32MP_BL2_DTB_BASE
152#endif
153
Maxime Méréae845252024-09-13 17:57:58 +0200154#if STM32MP_DDR_FIP_IO_STORAGE
155#define STM32MP_DDR_FW_BASE SRAM1_BASE
156#define STM32MP_DDR_FW_MAX_SIZE U(0x8800)
157#endif
158
Yann Gautier5af93692024-05-22 16:16:59 +0200159#define STM32MP_FW_CONFIG_MAX_SIZE PAGE_SIZE
160#define STM32MP_FW_CONFIG_BASE STM32MP_SYSRAM_BASE
161
Yann Gautier35527fb2023-06-14 10:40:59 +0200162#define STM32MP_BL33_BASE (STM32MP_DDR_BASE + U(0x04000000))
163#define STM32MP_BL33_MAX_SIZE U(0x400000)
Yann Gautier5af93692024-05-22 16:16:59 +0200164#define STM32MP_HW_CONFIG_BASE (STM32MP_BL33_BASE + \
165 STM32MP_BL33_MAX_SIZE)
166#define STM32MP_HW_CONFIG_MAX_SIZE U(0x40000)
Yann Gautier35527fb2023-06-14 10:40:59 +0200167
168/*******************************************************************************
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200169 * STM32MP2 device/io map related constants (used for MMU)
170 ******************************************************************************/
171#define STM32MP_DEVICE_BASE U(0x40000000)
172#define STM32MP_DEVICE_SIZE U(0x40000000)
173
174/*******************************************************************************
Yann Gautier35527fb2023-06-14 10:40:59 +0200175 * STM32MP2 RCC
176 ******************************************************************************/
177#define RCC_BASE U(0x44200000)
178
179/*******************************************************************************
180 * STM32MP2 PWR
181 ******************************************************************************/
182#define PWR_BASE U(0x44210000)
183
184/*******************************************************************************
Yann Gautier87a940e2023-06-14 18:05:47 +0200185 * STM32MP2 GPIO
186 ******************************************************************************/
187#define GPIOA_BASE U(0x44240000)
188#define GPIOB_BASE U(0x44250000)
189#define GPIOC_BASE U(0x44260000)
190#define GPIOD_BASE U(0x44270000)
191#define GPIOE_BASE U(0x44280000)
192#define GPIOF_BASE U(0x44290000)
193#define GPIOG_BASE U(0x442A0000)
194#define GPIOH_BASE U(0x442B0000)
195#define GPIOI_BASE U(0x442C0000)
196#define GPIOJ_BASE U(0x442D0000)
197#define GPIOK_BASE U(0x442E0000)
198#define GPIOZ_BASE U(0x46200000)
199#define GPIO_BANK_OFFSET U(0x10000)
200
201#define STM32MP_GPIOS_PIN_MAX_COUNT 16
202#define STM32MP_GPIOZ_PIN_MAX_COUNT 8
203
204/*******************************************************************************
205 * STM32MP2 UART
206 ******************************************************************************/
207#define USART1_BASE U(0x40330000)
208#define USART2_BASE U(0x400E0000)
209#define USART3_BASE U(0x400F0000)
210#define UART4_BASE U(0x40100000)
211#define UART5_BASE U(0x40110000)
212#define USART6_BASE U(0x40220000)
213#define UART7_BASE U(0x40370000)
214#define UART8_BASE U(0x40380000)
215#define UART9_BASE U(0x402C0000)
216#define STM32MP_NB_OF_UART U(9)
217
218/* For UART crash console */
219#define STM32MP_DEBUG_USART_CLK_FRQ 64000000
220/* USART2 on HSI@64MHz, TX on GPIOA4 Alternate 6 */
221#define STM32MP_DEBUG_USART_BASE USART2_BASE
222#define DEBUG_UART_TX_GPIO_BANK_ADDRESS GPIOA_BASE
223#define DEBUG_UART_TX_GPIO_BANK_CLK_REG RCC_GPIOACFGR
224#define DEBUG_UART_TX_GPIO_BANK_CLK_EN RCC_GPIOxCFGR_GPIOxEN
225#define DEBUG_UART_TX_GPIO_PORT 4
226#define DEBUG_UART_TX_GPIO_ALTERNATE 6
227#define DEBUG_UART_TX_CLKSRC_REG RCC_XBAR8CFGR
228#define DEBUG_UART_TX_CLKSRC XBAR_SRC_HSI
229#define DEBUG_UART_TX_EN_REG RCC_USART2CFGR
230#define DEBUG_UART_TX_EN RCC_UARTxCFGR_UARTxEN
231#define DEBUG_UART_RST_REG RCC_USART2CFGR
232#define DEBUG_UART_RST_BIT RCC_UARTxCFGR_UARTxRST
233#define DEBUG_UART_PREDIV_CFGR RCC_PREDIV8CFGR
234#define DEBUG_UART_FINDIV_CFGR RCC_FINDIV8CFGR
235
236/*******************************************************************************
Yann Gautier35527fb2023-06-14 10:40:59 +0200237 * STM32MP2 SDMMC
238 ******************************************************************************/
239#define STM32MP_SDMMC1_BASE U(0x48220000)
240#define STM32MP_SDMMC2_BASE U(0x48230000)
241#define STM32MP_SDMMC3_BASE U(0x48240000)
242
243/*******************************************************************************
Yann Gautier197ac782024-01-03 14:28:23 +0100244 * STM32MP2 BSEC / OTP
245 ******************************************************************************/
246/*
247 * 367 available OTPs, the other are masked
248 * - ECIES key: 368 to 375 (only readable by bootrom)
249 * - HWKEY: 376 to 383 (never reloadable or readable)
250 */
251#define STM32MP2_OTP_MAX_ID U(0x16F)
252#define STM32MP2_MID_OTP_START U(0x80)
253#define STM32MP2_UPPER_OTP_START U(0x100)
254
255/* OTP labels */
256#define PART_NUMBER_OTP "part-number-otp"
Yann Gautier381b2a62024-06-21 14:49:47 +0200257#define REVISION_OTP "rev_otp"
Yann Gautier197ac782024-01-03 14:28:23 +0100258#define PACKAGE_OTP "package-otp"
259#define HCONF1_OTP "otp124"
260#define NAND_OTP "otp16"
261#define NAND2_OTP "otp20"
262#define BOARD_ID_OTP "board-id"
263#define UID_OTP "uid-otp"
264#define LIFECYCLE2_OTP "otp18"
265#define PKH_OTP "otp144"
266#define ENCKEY_OTP "otp260"
267
268/* OTP mask */
269/* PACKAGE */
270#define PACKAGE_OTP_PKG_MASK GENMASK_32(2, 0)
271#define PACKAGE_OTP_PKG_SHIFT U(0)
272
273/* IWDG OTP */
274#define HCONF1_OTP_IWDG_HW_POS U(0)
275#define HCONF1_OTP_IWDG_FZ_STOP_POS U(1)
276#define HCONF1_OTP_IWDG_FZ_STANDBY_POS U(2)
277
278/* NAND OTP */
279/* NAND parameter storage flag */
280#define NAND_PARAM_STORED_IN_OTP BIT_32(31)
281
282/* NAND page size in bytes */
283#define NAND_PAGE_SIZE_MASK GENMASK_32(30, 29)
284#define NAND_PAGE_SIZE_SHIFT U(29)
285#define NAND_PAGE_SIZE_2K U(0)
286#define NAND_PAGE_SIZE_4K U(1)
287#define NAND_PAGE_SIZE_8K U(2)
288
289/* NAND block size in pages */
290#define NAND_BLOCK_SIZE_MASK GENMASK_32(28, 27)
291#define NAND_BLOCK_SIZE_SHIFT U(27)
292#define NAND_BLOCK_SIZE_64_PAGES U(0)
293#define NAND_BLOCK_SIZE_128_PAGES U(1)
294#define NAND_BLOCK_SIZE_256_PAGES U(2)
295
296/* NAND number of block (in unit of 256 blocks) */
297#define NAND_BLOCK_NB_MASK GENMASK_32(26, 19)
298#define NAND_BLOCK_NB_SHIFT U(19)
299#define NAND_BLOCK_NB_UNIT U(256)
300
301/* NAND bus width in bits */
302#define NAND_WIDTH_MASK BIT_32(18)
303#define NAND_WIDTH_SHIFT U(18)
304
305/* NAND number of ECC bits per 512 bytes */
306#define NAND_ECC_BIT_NB_MASK GENMASK_32(17, 15)
307#define NAND_ECC_BIT_NB_SHIFT U(15)
308#define NAND_ECC_BIT_NB_UNSET U(0)
309#define NAND_ECC_BIT_NB_1_BITS U(1)
310#define NAND_ECC_BIT_NB_4_BITS U(2)
311#define NAND_ECC_BIT_NB_8_BITS U(3)
312#define NAND_ECC_ON_DIE U(4)
313
314/* NAND number of planes */
315#define NAND_PLANE_BIT_NB_MASK BIT_32(14)
316
317/* NAND2 OTP */
318#define NAND2_PAGE_SIZE_SHIFT U(16)
319
320/* NAND2 config distribution */
321#define NAND2_CONFIG_DISTRIB BIT_32(0)
322#define NAND2_PNAND_NAND2_SNAND_NAND1 U(0)
323#define NAND2_PNAND_NAND1_SNAND_NAND2 U(1)
324
325/* MONOTONIC OTP */
326#define MAX_MONOTONIC_VALUE U(32)
327
328/* UID OTP */
329#define UID_WORD_NB U(3)
330
331/* Lifecycle OTP */
332#define SECURE_BOOT_CLOSED_SECURE GENMASK_32(3, 0)
333
334/*******************************************************************************
Yann Gautier35527fb2023-06-14 10:40:59 +0200335 * STM32MP2 TAMP
336 ******************************************************************************/
337#define PLAT_MAX_TAMP_INT U(5)
338#define PLAT_MAX_TAMP_EXT U(3)
339#define TAMP_BASE U(0x46010000)
340#define TAMP_SMCR (TAMP_BASE + U(0x20))
341#define TAMP_BKP_REGISTER_BASE (TAMP_BASE + U(0x100))
342#define TAMP_BKP_REG_CLK CK_BUS_RTC
343#define TAMP_BKP_SEC_NUMBER U(10)
344#define TAMP_COUNTR U(0x40)
345
346#if !(defined(__LINKER__) || defined(__ASSEMBLER__))
347static inline uintptr_t tamp_bkpr(uint32_t idx)
348{
349 return TAMP_BKP_REGISTER_BASE + (idx << 2);
350}
351#endif
352
353/*******************************************************************************
354 * STM32MP2 DDRCTRL
355 ******************************************************************************/
356#define DDRCTRL_BASE U(0x48040000)
357
358/*******************************************************************************
359 * STM32MP2 DDRDBG
360 ******************************************************************************/
361#define DDRDBG_BASE U(0x48050000)
362
363/*******************************************************************************
364 * STM32MP2 DDRPHYC
365 ******************************************************************************/
366#define DDRPHYC_BASE U(0x48C00000)
367
368/*******************************************************************************
369 * Miscellaneous STM32MP1 peripherals base address
370 ******************************************************************************/
371#define BSEC_BASE U(0x44000000)
372#define DBGMCU_BASE U(0x4A010000)
373#define HASH_BASE U(0x42010000)
374#define RTC_BASE U(0x46000000)
375#define STGEN_BASE U(0x48080000)
376#define SYSCFG_BASE U(0x44230000)
377
378/*******************************************************************************
Maxime Méréae845252024-09-13 17:57:58 +0200379 * STM32MP RIF
380 ******************************************************************************/
381#define RISAB3_BASE U(0x42110000)
Maxime Méré52f530d2024-09-19 09:54:28 +0200382#define RISAB5_BASE U(0x42130000)
Maxime Méréae845252024-09-13 17:57:58 +0200383
384/*******************************************************************************
Gabriel Fernandez615f31f2022-04-20 10:08:49 +0200385 * STM32MP CA35SSC
386 ******************************************************************************/
387#define A35SSC_BASE U(0x48800000)
388
389/*******************************************************************************
Yann Gautier35527fb2023-06-14 10:40:59 +0200390 * REGULATORS
391 ******************************************************************************/
392/* 3 PWR + 1 VREFBUF + 14 PMIC regulators + 1 FIXED */
393#define PLAT_NB_RDEVS U(19)
394/* 2 FIXED */
395#define PLAT_NB_FIXED_REGUS U(2)
396/* No GPIO regu */
397#define PLAT_NB_GPIO_REGUS U(0)
398
399/*******************************************************************************
400 * Device Tree defines
401 ******************************************************************************/
402#define DT_BSEC_COMPAT "st,stm32mp25-bsec"
403#define DT_DDR_COMPAT "st,stm32mp2-ddr"
404#define DT_PWR_COMPAT "st,stm32mp25-pwr"
405#define DT_RCC_CLK_COMPAT "st,stm32mp25-rcc"
Yann Gautierdb77f8b2024-05-21 11:46:59 +0200406#define DT_SDMMC2_COMPAT "st,stm32mp25-sdmmc2"
Yann Gautier35527fb2023-06-14 10:40:59 +0200407#define DT_UART_COMPAT "st,stm32h7-uart"
408
409#endif /* STM32MP2_DEF_H */