xref: /rk3399_ARM-atf/plat/st/common/include/stm32mp_common.h (revision 1e91952942f5063d57e21bd1e9a2e968003b935f)
1c9d75b3cSYann Gautier /*
2c9d75b3cSYann Gautier  * Copyright (C) 2018-2019, STMicroelectronics - All Rights Reserved
36f4572bdSYann Gautier  * Copyright (c) 2018-2019, Linaro Limited
4c9d75b3cSYann Gautier  *
5c9d75b3cSYann Gautier  * SPDX-License-Identifier: BSD-3-Clause
6c9d75b3cSYann Gautier  */
7c9d75b3cSYann Gautier 
8c9d75b3cSYann Gautier #ifndef STM32MP_COMMON_H
9c9d75b3cSYann Gautier #define STM32MP_COMMON_H
10c9d75b3cSYann Gautier 
113f9c9784SYann Gautier #include <stdbool.h>
123f9c9784SYann Gautier 
13*1e919529SYann Gautier #include <platform_def.h>
14*1e919529SYann Gautier 
156f4572bdSYann Gautier #include <arch_helpers.h>
166f4572bdSYann Gautier 
17c9d75b3cSYann Gautier /* Functions to save and get boot context address given by ROM code */
183f9c9784SYann Gautier void stm32mp_save_boot_ctx_address(uintptr_t address);
193f9c9784SYann Gautier uintptr_t stm32mp_get_boot_ctx_address(void);
20c9d75b3cSYann Gautier 
21b2182cdeSYann Gautier bool stm32mp_is_single_core(void);
22b2182cdeSYann Gautier 
237ae58c6bSYann Gautier /* Return the base address of the DDR controller */
247ae58c6bSYann Gautier uintptr_t stm32mp_ddrctrl_base(void);
257ae58c6bSYann Gautier 
267ae58c6bSYann Gautier /* Return the base address of the DDR PHY */
277ae58c6bSYann Gautier uintptr_t stm32mp_ddrphyc_base(void);
287ae58c6bSYann Gautier 
297ae58c6bSYann Gautier /* Return the base address of the PWR peripheral */
307ae58c6bSYann Gautier uintptr_t stm32mp_pwr_base(void);
317ae58c6bSYann Gautier 
327ae58c6bSYann Gautier /* Return the base address of the RCC peripheral */
337ae58c6bSYann Gautier uintptr_t stm32mp_rcc_base(void);
347ae58c6bSYann Gautier 
35e463d3f4SYann Gautier /* Check MMU status to allow spinlock use */
36e463d3f4SYann Gautier bool stm32mp_lock_available(void);
37e463d3f4SYann Gautier 
3873680c23SYann Gautier /* Get IWDG platform instance ID from peripheral IO memory base address */
3973680c23SYann Gautier uint32_t stm32_iwdg_get_instance(uintptr_t base);
4073680c23SYann Gautier 
4173680c23SYann Gautier /* Return bitflag mask for expected IWDG configuration from OTP content */
4273680c23SYann Gautier uint32_t stm32_iwdg_get_otp_config(uint32_t iwdg_inst);
4373680c23SYann Gautier 
4473680c23SYann Gautier #if defined(IMAGE_BL2)
4573680c23SYann Gautier /* Update OTP shadow registers with IWDG configuration from device tree */
4673680c23SYann Gautier uint32_t stm32_iwdg_shadow_update(uint32_t iwdg_inst, uint32_t flags);
4773680c23SYann Gautier #endif
4873680c23SYann Gautier 
49c9d75b3cSYann Gautier /*
50c9d75b3cSYann Gautier  * Platform util functions for the GPIO driver
51c9d75b3cSYann Gautier  * @bank: Target GPIO bank ID as per DT bindings
52c9d75b3cSYann Gautier  *
53c9d75b3cSYann Gautier  * Platform shall implement these functions to provide to stm32_gpio
54c9d75b3cSYann Gautier  * driver the resource reference for a target GPIO bank. That are
55c9d75b3cSYann Gautier  * memory mapped interface base address, interface offset (see below)
56c9d75b3cSYann Gautier  * and clock identifier.
57c9d75b3cSYann Gautier  *
58c9d75b3cSYann Gautier  * stm32_get_gpio_bank_offset() returns a bank offset that is used to
59c9d75b3cSYann Gautier  * check DT configuration matches platform implementation of the banks
60c9d75b3cSYann Gautier  * description.
61c9d75b3cSYann Gautier  */
62c9d75b3cSYann Gautier uintptr_t stm32_get_gpio_bank_base(unsigned int bank);
63c9d75b3cSYann Gautier unsigned long stm32_get_gpio_bank_clock(unsigned int bank);
64c9d75b3cSYann Gautier uint32_t stm32_get_gpio_bank_offset(unsigned int bank);
65c9d75b3cSYann Gautier 
66dec286ddSYann Gautier /* Print CPU information */
67dec286ddSYann Gautier void stm32mp_print_cpuinfo(void);
68dec286ddSYann Gautier 
6910e7a9e9SYann Gautier /* Print board information */
7010e7a9e9SYann Gautier void stm32mp_print_boardinfo(void);
7110e7a9e9SYann Gautier 
723f9c9784SYann Gautier /*
733f9c9784SYann Gautier  * Util for clock gating and to get clock rate for stm32 and platform drivers
743f9c9784SYann Gautier  * @id: Target clock ID, ID used in clock DT bindings
753f9c9784SYann Gautier  */
763f9c9784SYann Gautier bool stm32mp_clk_is_enabled(unsigned long id);
770d21680cSYann Gautier void stm32mp_clk_enable(unsigned long id);
780d21680cSYann Gautier void stm32mp_clk_disable(unsigned long id);
793f9c9784SYann Gautier unsigned long stm32mp_clk_get_rate(unsigned long id);
803f9c9784SYann Gautier 
81c9d75b3cSYann Gautier /* Initialise the IO layer and register platform IO devices */
823f9c9784SYann Gautier void stm32mp_io_setup(void);
83c9d75b3cSYann Gautier 
846f4572bdSYann Gautier static inline uint64_t arm_cnt_us2cnt(uint32_t us)
856f4572bdSYann Gautier {
866f4572bdSYann Gautier 	return ((uint64_t)us * (uint64_t)read_cntfrq()) / 1000000ULL;
876f4572bdSYann Gautier }
886f4572bdSYann Gautier 
896f4572bdSYann Gautier static inline uint64_t timeout_init_us(uint32_t us)
906f4572bdSYann Gautier {
916f4572bdSYann Gautier 	return read_cntpct_el0() + arm_cnt_us2cnt(us);
926f4572bdSYann Gautier }
936f4572bdSYann Gautier 
946f4572bdSYann Gautier static inline bool timeout_elapsed(uint64_t expire)
956f4572bdSYann Gautier {
966f4572bdSYann Gautier 	return read_cntpct_el0() > expire;
976f4572bdSYann Gautier }
986f4572bdSYann Gautier 
99*1e919529SYann Gautier /*
100*1e919529SYann Gautier  * Check that the STM32 header of a .stm32 binary image is valid
101*1e919529SYann Gautier  * @param header: pointer to the stm32 image header
102*1e919529SYann Gautier  * @param buffer: address of the binary image (payload)
103*1e919529SYann Gautier  * @return: 0 on success, negative value in case of error
104*1e919529SYann Gautier  */
105*1e919529SYann Gautier int stm32mp_check_header(boot_api_image_header_t *header, uintptr_t buffer);
106*1e919529SYann Gautier 
107c9d75b3cSYann Gautier #endif /* STM32MP_COMMON_H */
108