Attention is currently required from: Hope Wang.
Hello Hope Wang,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/85563?usp=email
to review the following change.
Change subject: mb/google/rauru: Implement regulator interface ......................................................................
mb/google/rauru: Implement regulator interface
Control regulator more easily with regulator interface.
TEST=build pass BUG=b:317009620
Change-Id: I3cad68dbb2c5873c4e00066da18b1593b88ff499 Signed-off-by: Hope Wang hope.wang@mediatek.corp-partner.google.com --- M src/mainboard/google/rauru/Makefile.mk A src/mainboard/google/rauru/regulator.c 2 files changed, 78 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/63/85563/1
diff --git a/src/mainboard/google/rauru/Makefile.mk b/src/mainboard/google/rauru/Makefile.mk index d5eb8af..d383629 100644 --- a/src/mainboard/google/rauru/Makefile.mk +++ b/src/mainboard/google/rauru/Makefile.mk @@ -9,3 +9,4 @@ romstage-y += romstage.c
ramstage-y += mainboard.c +ramstage-y += regulator.c diff --git a/src/mainboard/google/rauru/regulator.c b/src/mainboard/google/rauru/regulator.c new file mode 100644 index 0000000..6e190f7 --- /dev/null +++ b/src/mainboard/google/rauru/regulator.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#include <console/console.h> +#include <soc/mt6373.h> +#include <soc/regulator.h> + +#define MTK_REGULATOR_INVALID -1 + +static int get_mt6373_regulator_id(enum mtk_regulator regulator) +{ + switch (regulator) { + case MTK_REGULATOR_VMCH: + return MT6373_VMCH; + case MTK_REGULATOR_VMC: + return MT6373_VMC; + default: + return MTK_REGULATOR_INVALID; + } +} + +void mainboard_set_regulator_voltage(enum mtk_regulator regulator, uint32_t voltage_uv) +{ + int id; + + id = get_mt6373_regulator_id(regulator); + if (id < 0) { + printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator); + return; + } + + if (id == MT6373_VMCH) + mt6373_set_vmch_voltage(voltage_uv); + else if (id == MT6373_VMC) + mt6373_set_vmc_voltage(voltage_uv); + else + printk(BIOS_WARNING, "Regulator ID %d: not supported\n", regulator); +} + +uint32_t mainboard_get_regulator_voltage(enum mtk_regulator regulator) +{ + int id; + + id = get_mt6373_regulator_id(regulator); + if (id < 0) { + printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator); + return 0; + } + + if (id == MT6373_VMCH) + return mt6373_get_vmch_voltage(); + else if (id == MT6373_VMC) + return mt6373_get_vmc_voltage(); + else + printk(BIOS_WARNING, "Regulator ID %d: not supported\n", regulator); + + return 0; +} + +int mainboard_enable_regulator(enum mtk_regulator regulator, bool enable) +{ + int id; + + id = get_mt6373_regulator_id(regulator); + if (id < 0) { + printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator); + return -1; + } + + if (id == MT6373_VMCH) + mt6373_enable_vmch(enable); + else if (id == MT6373_VMC) + mt6373_enable_vmc(enable); + else + printk(BIOS_WARNING, "Regulator ID %d: not supported\n", regulator); + + return 0; +}