From b79e74404373827619425912fec5e4ab59bd692e Mon Sep 17 00:00:00 2001 From: Mahesh Mahadevan Date: Tue, 29 Nov 2022 16:13:21 -0600 Subject: [PATCH] boards: mimxrt595evk: Setup the regulator for Run mode Setup the appropriate voltage in the PMIC based on the core frequency. Add labels to the regulators for easy access to the nodes. Add CONFIG_REGULATOR to the defconfig so we can setup the PMIC voltages during platform startup. Signed-off-by: Mahesh Mahadevan --- boards/arm/mimxrt595_evk/board.c | 74 +++++++++++++++++++ .../arm/mimxrt595_evk/mimxrt595_evk_cm33.dts | 8 +- .../mimxrt595_evk_cm33_defconfig | 2 +- 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/boards/arm/mimxrt595_evk/board.c b/boards/arm/mimxrt595_evk/board.c index adffed0119c026..3322f75d48bb9d 100644 --- a/boards/arm/mimxrt595_evk/board.c +++ b/boards/arm/mimxrt595_evk/board.c @@ -6,6 +6,75 @@ #include #include "fsl_power.h" +#if CONFIG_REGULATOR +#include + +#define NODE_SW1 DT_NODELABEL(pca9420_sw1) +#define NODE_SW2 DT_NODELABEL(pca9420_sw2) +#define NODE_LDO1 DT_NODELABEL(pca9420_ldo1) +#define NODE_LDO2 DT_NODELABEL(pca9420_ldo2) +static const struct device *sw1 = DEVICE_DT_GET(NODE_SW1); +static const struct device *sw2 = DEVICE_DT_GET(NODE_SW2); +static const struct device *ldo1 = DEVICE_DT_GET(NODE_LDO1); +static const struct device *ldo2 = DEVICE_DT_GET(NODE_LDO2); + +/* System clock frequency. */ +extern uint32_t SystemCoreClock; + +static const int32_t sw1_volt[] = {1100000, 1000000, 900000, 800000, 700000}; + +static int32_t board_calc_volt_level(void) +{ + uint32_t i; + uint32_t volt; + + for (i = 0U; i < POWER_FREQ_LEVELS_NUM; i++) { + if (SystemCoreClock > powerFreqLevel[i]) { + break; + } + } + + /* Frequency exceed max supported */ + if (i == 0U) { + volt = POWER_INVALID_VOLT_LEVEL; + } else { + volt = sw1_volt[i - 1U]; + } + + return volt; +} + +static int board_config_pmic(const struct device *dev) +{ + uint32_t volt; + int ret = 0; + + volt = board_calc_volt_level(); + + ret = regulator_set_voltage(sw1, volt, volt); + if (ret != 0) { + return ret; + } + + ret = regulator_set_voltage(sw2, 1800000, 1800000); + if (ret != 0) { + return ret; + } + + ret = regulator_set_voltage(ldo1, 1800000, 1800000); + if (ret != 0) { + return ret; + } + + ret = regulator_set_voltage(ldo2, 3300000, 3300000); + if (ret != 0) { + return ret; + } + + return ret; +} +#endif + static int mimxrt595_evk_init(const struct device *dev) { /* Set the correct voltage range according to the board. */ @@ -22,4 +91,9 @@ static int mimxrt595_evk_init(const struct device *dev) return 0; } +#if CONFIG_REGULATOR +/* PMIC setup is dependent on the regulator API */ +SYS_INIT(board_config_pmic, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); +#endif + SYS_INIT(mimxrt595_evk_init, PRE_KERNEL_1, CONFIG_BOARD_INIT_PRIORITY); diff --git a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts index c0ae8755caa873..58c96d3aca6ab5 100644 --- a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts +++ b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts @@ -181,28 +181,28 @@ arduino_serial: &flexcomm12 { regulator-initial-mode = ; modesel-reg = ; modesel-mask = ; - BUCK1 { + pca9420_sw1: BUCK1 { regulator-min-microvolt = <500000>; regulator-max-microvolt = <1800000>; regulator-max-microamp = <250000>; regulator-boot-on; }; - BUCK2 { + pca9420_sw2: BUCK2 { regulator-min-microvolt = <1500000>; regulator-max-microvolt = <3300000>; regulator-max-microamp = <500000>; regulator-boot-on; }; - LDO1 { + pca9420_ldo1: LDO1 { regulator-min-microvolt = <1700000>; regulator-max-microvolt = <1900000>; regulator-max-microamp = <1000>; regulator-boot-on; }; - LDO2 { + pca9420_ldo2: LDO2 { regulator-min-microvolt = <1500000>; regulator-max-microvolt = <3300000>; regulator-max-microamp = <250000>; diff --git a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33_defconfig b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33_defconfig index 4439402d524ca6..5166be5787c2e0 100644 --- a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33_defconfig +++ b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33_defconfig @@ -15,6 +15,6 @@ CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_GPIO=y # Enable TrustZone-M CONFIG_TRUSTED_EXECUTION_SECURE=y - +CONFIG_REGULATOR=y CONFIG_ARM_MPU=y CONFIG_HW_STACK_PROTECTION=y