summaryrefslogtreecommitdiff
path: root/src/mainboard/google/corsola/regulator.c
diff options
context:
space:
mode:
authorLiju-Clr Chen <liju-clr.chen@mediatek.com>2023-02-06 16:21:05 +0800
committerFelix Held <felix-coreboot@felixheld.de>2023-02-08 15:38:38 +0000
commit45d51a92ee3a93c0704b4450436d194df376bed1 (patch)
tree2b1da22e15766796ba5323f2a7ac8108726a6457 /src/mainboard/google/corsola/regulator.c
parent6f375320c3fafc5f501cd7bbace82026eae32cd3 (diff)
mb/google/corsola: Use function to get regulator IDs
There might be inconsistence between regulator_id[] and `enum mtk_regulator` when we need to add new regulator IDs for Geralt. Therefore, we implement get_mt6366_regulator_id() to get regulator IDs. BUG=None TEST=build pass. Change-Id: I3d28ebf2affe4e9464b1a7c1fb2bbb9e31d64a5e Signed-off-by: Liju-Clr Chen <liju-clr.chen@mediatek.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/72838 Reviewed-by: Rex-BC Chen <rex-bc.chen@mediatek.com> Reviewed-by: Yidi Lin <yidilin@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Diffstat (limited to 'src/mainboard/google/corsola/regulator.c')
-rw-r--r--src/mainboard/google/corsola/regulator.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/mainboard/google/corsola/regulator.c b/src/mainboard/google/corsola/regulator.c
index 4f03c181e2..76433963c9 100644
--- a/src/mainboard/google/corsola/regulator.c
+++ b/src/mainboard/google/corsola/regulator.c
@@ -5,45 +5,54 @@
#include <soc/mt6366.h>
#include <soc/regulator.h>
-#define REGULATOR_NOT_SUPPORT -1
+#define MTK_REGULATOR_INVALID -1
-static const int regulator_id[] = {
- [MTK_REGULATOR_VDD1] = REGULATOR_NOT_SUPPORT,
- [MTK_REGULATOR_VDD2] = REGULATOR_NOT_SUPPORT,
- [MTK_REGULATOR_VDDQ] = MT6366_VDDQ,
- [MTK_REGULATOR_VMDDR] = REGULATOR_NOT_SUPPORT,
- [MTK_REGULATOR_VCORE] = MT6366_VCORE,
- [MTK_REGULATOR_VCC] = REGULATOR_NOT_SUPPORT,
- [MTK_REGULATOR_VCCQ] = REGULATOR_NOT_SUPPORT,
- [MTK_REGULATOR_VDRAM1] = MT6366_VDRAM1,
- [MTK_REGULATOR_VMCH] = MT6366_VMCH,
- [MTK_REGULATOR_VMC] = MT6366_VMC,
- [MTK_REGULATOR_VPROC12] = MT6366_VPROC12,
- [MTK_REGULATOR_VSRAM_PROC12] = MT6366_VSRAM_PROC12,
- [MTK_REGULATOR_VRF12] = MT6366_VRF12,
- [MTK_REGULATOR_VCN33] = MT6366_VCN33,
-};
-
-_Static_assert(ARRAY_SIZE(regulator_id) == MTK_REGULATOR_NUM, "regulator_id size error");
+static int get_mt6366_regulator_id(enum mtk_regulator regulator)
+{
+ switch (regulator) {
+ case MTK_REGULATOR_VDDQ:
+ return MT6366_VDDQ;
+ case MTK_REGULATOR_VCORE:
+ return MT6366_VCORE;
+ case MTK_REGULATOR_VDRAM1:
+ return MT6366_VDRAM1;
+ case MTK_REGULATOR_VMCH:
+ return MT6366_VMCH;
+ case MTK_REGULATOR_VMC:
+ return MT6366_VMC;
+ case MTK_REGULATOR_VPROC12:
+ return MT6366_VPROC12;
+ case MTK_REGULATOR_VSRAM_PROC12:
+ return MT6366_VSRAM_PROC12;
+ case MTK_REGULATOR_VRF12:
+ return MT6366_VRF12;
+ case MTK_REGULATOR_VCN33:
+ return MT6366_VCN33;
+ default:
+ return MTK_REGULATOR_INVALID;
+ }
+}
void mainboard_set_regulator_voltage(enum mtk_regulator regulator, uint32_t voltage_uv)
{
- assert(regulator < MTK_REGULATOR_NUM);
+ int id;
- if (regulator_id[regulator] < 0) {
+ id = get_mt6366_regulator_id(regulator);
+ if (id < 0) {
printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
return;
}
- mt6366_set_voltage(regulator_id[regulator], voltage_uv);
+ mt6366_set_voltage(id, voltage_uv);
}
uint32_t mainboard_get_regulator_voltage(enum mtk_regulator regulator)
{
- assert(regulator < MTK_REGULATOR_NUM);
+ int id;
- if (regulator_id[regulator] < 0) {
+ id = get_mt6366_regulator_id(regulator);
+ if (id < 0) {
printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
return 0;
}
- return mt6366_get_voltage(regulator_id[regulator]);
+ return mt6366_get_voltage(id);
}