xref: /rk3399_ARM-atf/plat/st/common/include/stm32mp_common.h (revision e463d3f43e0115fbafd7a17f7ba550fc8e9a2ae0)
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 
136f4572bdSYann Gautier #include <arch_helpers.h>
146f4572bdSYann Gautier 
15c9d75b3cSYann Gautier /* Functions to save and get boot context address given by ROM code */
163f9c9784SYann Gautier void stm32mp_save_boot_ctx_address(uintptr_t address);
173f9c9784SYann Gautier uintptr_t stm32mp_get_boot_ctx_address(void);
18c9d75b3cSYann Gautier 
19b2182cdeSYann Gautier bool stm32mp_is_single_core(void);
20b2182cdeSYann Gautier 
217ae58c6bSYann Gautier /* Return the base address of the DDR controller */
227ae58c6bSYann Gautier uintptr_t stm32mp_ddrctrl_base(void);
237ae58c6bSYann Gautier 
247ae58c6bSYann Gautier /* Return the base address of the DDR PHY */
257ae58c6bSYann Gautier uintptr_t stm32mp_ddrphyc_base(void);
267ae58c6bSYann Gautier 
277ae58c6bSYann Gautier /* Return the base address of the PWR peripheral */
287ae58c6bSYann Gautier uintptr_t stm32mp_pwr_base(void);
297ae58c6bSYann Gautier 
307ae58c6bSYann Gautier /* Return the base address of the RCC peripheral */
317ae58c6bSYann Gautier uintptr_t stm32mp_rcc_base(void);
327ae58c6bSYann Gautier 
33*e463d3f4SYann Gautier /* Check MMU status to allow spinlock use */
34*e463d3f4SYann Gautier bool stm32mp_lock_available(void);
35*e463d3f4SYann Gautier 
3673680c23SYann Gautier /* Get IWDG platform instance ID from peripheral IO memory base address */
3773680c23SYann Gautier uint32_t stm32_iwdg_get_instance(uintptr_t base);
3873680c23SYann Gautier 
3973680c23SYann Gautier /* Return bitflag mask for expected IWDG configuration from OTP content */
4073680c23SYann Gautier uint32_t stm32_iwdg_get_otp_config(uint32_t iwdg_inst);
4173680c23SYann Gautier 
4273680c23SYann Gautier #if defined(IMAGE_BL2)
4373680c23SYann Gautier /* Update OTP shadow registers with IWDG configuration from device tree */
4473680c23SYann Gautier uint32_t stm32_iwdg_shadow_update(uint32_t iwdg_inst, uint32_t flags);
4573680c23SYann Gautier #endif
4673680c23SYann Gautier 
47c9d75b3cSYann Gautier /*
48c9d75b3cSYann Gautier  * Platform util functions for the GPIO driver
49c9d75b3cSYann Gautier  * @bank: Target GPIO bank ID as per DT bindings
50c9d75b3cSYann Gautier  *
51c9d75b3cSYann Gautier  * Platform shall implement these functions to provide to stm32_gpio
52c9d75b3cSYann Gautier  * driver the resource reference for a target GPIO bank. That are
53c9d75b3cSYann Gautier  * memory mapped interface base address, interface offset (see below)
54c9d75b3cSYann Gautier  * and clock identifier.
55c9d75b3cSYann Gautier  *
56c9d75b3cSYann Gautier  * stm32_get_gpio_bank_offset() returns a bank offset that is used to
57c9d75b3cSYann Gautier  * check DT configuration matches platform implementation of the banks
58c9d75b3cSYann Gautier  * description.
59c9d75b3cSYann Gautier  */
60c9d75b3cSYann Gautier uintptr_t stm32_get_gpio_bank_base(unsigned int bank);
61c9d75b3cSYann Gautier unsigned long stm32_get_gpio_bank_clock(unsigned int bank);
62c9d75b3cSYann Gautier uint32_t stm32_get_gpio_bank_offset(unsigned int bank);
63c9d75b3cSYann Gautier 
64dec286ddSYann Gautier /* Print CPU information */
65dec286ddSYann Gautier void stm32mp_print_cpuinfo(void);
66dec286ddSYann Gautier 
6710e7a9e9SYann Gautier /* Print board information */
6810e7a9e9SYann Gautier void stm32mp_print_boardinfo(void);
6910e7a9e9SYann Gautier 
703f9c9784SYann Gautier /*
713f9c9784SYann Gautier  * Util for clock gating and to get clock rate for stm32 and platform drivers
723f9c9784SYann Gautier  * @id: Target clock ID, ID used in clock DT bindings
733f9c9784SYann Gautier  */
743f9c9784SYann Gautier bool stm32mp_clk_is_enabled(unsigned long id);
750d21680cSYann Gautier void stm32mp_clk_enable(unsigned long id);
760d21680cSYann Gautier void stm32mp_clk_disable(unsigned long id);
773f9c9784SYann Gautier unsigned long stm32mp_clk_get_rate(unsigned long id);
783f9c9784SYann Gautier 
79c9d75b3cSYann Gautier /* Initialise the IO layer and register platform IO devices */
803f9c9784SYann Gautier void stm32mp_io_setup(void);
81c9d75b3cSYann Gautier 
826f4572bdSYann Gautier static inline uint64_t arm_cnt_us2cnt(uint32_t us)
836f4572bdSYann Gautier {
846f4572bdSYann Gautier 	return ((uint64_t)us * (uint64_t)read_cntfrq()) / 1000000ULL;
856f4572bdSYann Gautier }
866f4572bdSYann Gautier 
876f4572bdSYann Gautier static inline uint64_t timeout_init_us(uint32_t us)
886f4572bdSYann Gautier {
896f4572bdSYann Gautier 	return read_cntpct_el0() + arm_cnt_us2cnt(us);
906f4572bdSYann Gautier }
916f4572bdSYann Gautier 
926f4572bdSYann Gautier static inline bool timeout_elapsed(uint64_t expire)
936f4572bdSYann Gautier {
946f4572bdSYann Gautier 	return read_cntpct_el0() > expire;
956f4572bdSYann Gautier }
966f4572bdSYann Gautier 
97c9d75b3cSYann Gautier #endif /* STM32MP_COMMON_H */
98