Skip to content

Commit

Permalink
boards: mimxrt595evk: Setup the regulator for Run mode
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mmahadevan108 authored and carlescufi committed Dec 5, 2022
1 parent 0b845cd commit b79e744
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
74 changes: 74 additions & 0 deletions boards/arm/mimxrt595_evk/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,75 @@
#include <zephyr/init.h>
#include "fsl_power.h"

#if CONFIG_REGULATOR
#include <zephyr/drivers/regulator.h>

#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. */
Expand All @@ -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);
8 changes: 4 additions & 4 deletions boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,28 @@ arduino_serial: &flexcomm12 {
regulator-initial-mode = <PCA9420_MODECFG0_PIN>;
modesel-reg = <PCA9420_MODECFG_0_0>;
modesel-mask = <PCA9420_MODECFG_0_MODE_CTRL_SEL_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>;
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/mimxrt595_evk/mimxrt595_evk_cm33_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b79e744

Please sign in to comment.