refactor(st): update CPU and VDD voltage get

Use regulator framework to get CPU and VDD power supplies.

Change-Id: Ice745fb21ff10e71ef811e747165499c2e19253e
Signed-off-by: Pascal Paillet <p.paillet@st.com>
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
This commit is contained in:
Yann Gautier 2021-09-17 16:08:12 +02:00 committed by Yann Gautier
parent 67d95409ba
commit c39c658e75
2 changed files with 36 additions and 26 deletions

View File

@ -37,6 +37,8 @@ int dt_get_stdout_uart_info(struct dt_node_info *info);
int dt_match_instance_by_compatible(const char *compatible, uintptr_t address);
uint32_t dt_get_ddr_size(void);
uint32_t dt_get_pwr_vdd_voltage(void);
struct rdev *dt_get_vdd_regulator(void);
struct rdev *dt_get_cpu_regulator(void);
const char *dt_get_board_model(void);
int fdt_get_gpio_bank_pin_count(unsigned int bank);

View File

@ -7,16 +7,15 @@
#include <assert.h>
#include <errno.h>
#include <libfdt.h>
#include <platform_def.h>
#include <common/debug.h>
#include <common/fdt_wrappers.h>
#include <drivers/st/regulator.h>
#include <drivers/st/stm32_gpio.h>
#include <drivers/st/stm32mp1_ddr.h>
#include <drivers/st/stm32mp1_ram.h>
#include <libfdt.h>
#include <platform_def.h>
#include <stm32mp_dt.h>
static void *fdt;
@ -262,37 +261,46 @@ uint32_t dt_get_ddr_size(void)
******************************************************************************/
uint32_t dt_get_pwr_vdd_voltage(void)
{
int node, pwr_regulators_node;
const fdt32_t *cuint;
struct rdev *regul = dt_get_vdd_regulator();
uint16_t min;
if (regul == NULL) {
return 0;
}
regulator_get_range(regul, &min, NULL);
return (uint32_t)min * 1000U;
}
/*******************************************************************************
* This function retrieves VDD supply regulator from DT.
* Returns an rdev taken from supply node, NULL otherwise.
******************************************************************************/
struct rdev *dt_get_vdd_regulator(void)
{
int node = fdt_node_offset_by_compatible(fdt, -1, DT_PWR_COMPAT);
node = fdt_node_offset_by_compatible(fdt, -1, DT_PWR_COMPAT);
if (node < 0) {
INFO("%s: Cannot read PWR node in DT\n", __func__);
return 0;
return NULL;
}
pwr_regulators_node = fdt_subnode_offset(fdt, node, "pwr-regulators");
if (pwr_regulators_node < 0) {
INFO("%s: Cannot read pwr-regulators node in DT\n", __func__);
return 0;
}
return regulator_get_by_supply_name(fdt, node, "vdd");
}
cuint = fdt_getprop(fdt, pwr_regulators_node, "vdd-supply", NULL);
if (cuint == NULL) {
return 0;
}
/*******************************************************************************
* This function retrieves CPU supply regulator from DT.
* Returns an rdev taken from supply node, NULL otherwise.
******************************************************************************/
struct rdev *dt_get_cpu_regulator(void)
{
int node = fdt_path_offset(fdt, "/cpus/cpu@0");
node = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint));
if (node < 0) {
return 0;
return NULL;
}
cuint = fdt_getprop(fdt, node, "regulator-min-microvolt", NULL);
if (cuint == NULL) {
return 0;
}
return fdt32_to_cpu(*cuint);
return regulator_get_by_supply_name(fdt, node, "cpu");
}
/*******************************************************************************