summaryrefslogtreecommitdiff
path: root/src/mainboard/google
diff options
context:
space:
mode:
authorRex-BC Chen <rex-bc.chen@mediatek.com>2021-05-14 18:18:29 +0800
committerHung-Te Lin <hungte@chromium.org>2021-06-24 03:15:00 +0000
commit506b4c90935c1dd89daf989f59229b3d016e6b51 (patch)
tree0394fab70e5945b6fc85e637af67dcad25ed3164 /src/mainboard/google
parentda63f09b80627da9b41ee869194a4e86c0b3184d (diff)
mb/google/cherry: Implement regulator interface
Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com> Change-Id: Iab58edd019ccf9130e96fae55f147ab20cd0f45b Reviewed-on: https://review.coreboot.org/c/coreboot/+/55751 Reviewed-by: Yu-Ping Wu <yupingso@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/mainboard/google')
-rw-r--r--src/mainboard/google/cherry/Makefile.inc2
-rw-r--r--src/mainboard/google/cherry/regulator.c141
2 files changed, 143 insertions, 0 deletions
diff --git a/src/mainboard/google/cherry/Makefile.inc b/src/mainboard/google/cherry/Makefile.inc
index a0862d3646..e1e363c4ed 100644
--- a/src/mainboard/google/cherry/Makefile.inc
+++ b/src/mainboard/google/cherry/Makefile.inc
@@ -9,6 +9,7 @@ verstage-y += reset.c
romstage-y += memlayout.ld
romstage-y += boardid.c
romstage-y += chromeos.c
+romstage-y += regulator.c
romstage-y += romstage.c
romstage-y += sdram_configs.c
@@ -16,4 +17,5 @@ ramstage-y += memlayout.ld
ramstage-y += boardid.c
ramstage-y += chromeos.c
ramstage-y += mainboard.c
+ramstage-y += regulator.c
ramstage-y += reset.c
diff --git a/src/mainboard/google/cherry/regulator.c b/src/mainboard/google/cherry/regulator.c
new file mode 100644
index 0000000000..e7da942616
--- /dev/null
+++ b/src/mainboard/google/cherry/regulator.c
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <console/console.h>
+#include <ec/google/chromeec/ec.h>
+#include <soc/mt6359p.h>
+#include <soc/mt6360.h>
+#include <soc/mt6691.h>
+#include <soc/regulator.h>
+
+#define MT6691_I2C_NUM 7
+
+static int get_mt6360_regulator_id(enum mtk_regulator regulator)
+{
+ switch (regulator) {
+ case MTK_REGULATOR_VDD2:
+ return MT6360_PMIC_BUCK1;
+ case MTK_REGULATOR_VDDQ:
+ return MT6360_PMIC_BUCK2;
+ default:
+ break;
+ }
+
+ return -1;
+}
+
+static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
+{
+ return regulator == MTK_REGULATOR_VCORE ? MT6359P_GPU11 : -1;
+}
+
+static int get_mt6691_regulator_id(enum mtk_regulator regulator)
+{
+ return regulator == MTK_REGULATOR_VMDDR ? MT6691_I2C_NUM : -1;
+}
+
+static int check_regulator_control(enum mtk_regulator regulator)
+{
+ /*
+ * MT6880 is not controlled by SW.
+ * No need to control it.
+ */
+ if (regulator == MTK_REGULATOR_VDD1) {
+ printk(BIOS_WARNING,
+ "[%d] MT6880 is not controlled by SW.\n", regulator);
+ return -1;
+ }
+ return 0;
+}
+
+void mainboard_set_regulator_vol(enum mtk_regulator regulator,
+ uint32_t voltage_uv)
+{
+ if (check_regulator_control(regulator) < 0)
+ return;
+
+ int id;
+
+ id = get_mt6360_regulator_id(regulator);
+ if (id >= 0) {
+ mt6360_pmic_set_voltage(id, voltage_uv);
+ return;
+ }
+
+ id = get_mt6359p_regulator_id(regulator);
+ if (id >= 0) {
+ mt6359p_buck_set_voltage(id, voltage_uv);
+ return;
+ }
+
+ id = get_mt6691_regulator_id(regulator);
+ if (id >= 0) {
+ mt6691_set_voltage(id, voltage_uv);
+ return;
+ }
+
+ printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
+}
+
+uint32_t mainboard_get_regulator_vol(enum mtk_regulator regulator)
+{
+ if (check_regulator_control(regulator) < 0)
+ return 0;
+
+ int id;
+
+ id = get_mt6360_regulator_id(regulator);
+ if (id >= 0)
+ return mt6360_pmic_get_voltage(id);
+
+ id = get_mt6359p_regulator_id(regulator);
+ if (id >= 0)
+ return mt6359p_buck_get_voltage(id);
+
+ id = get_mt6691_regulator_id(regulator);
+ if (id >= 0)
+ return mt6691_get_voltage(id);
+
+ printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
+
+ return 0;
+}
+
+int mainboard_enable_regulator(enum mtk_regulator regulator, uint8_t enable)
+{
+ if (check_regulator_control(regulator) < 0)
+ return 0;
+
+ /* Return 0 if the regulator is already enabled or disabled. */
+ if (mainboard_regulator_is_enabled(regulator) == enable)
+ return 0;
+
+ int id;
+
+ id = get_mt6360_regulator_id(regulator);
+ if (id >= 0) {
+ mt6360_pmic_enable(id, enable);
+ return 0;
+ }
+
+ printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
+
+ return -1;
+}
+
+uint8_t mainboard_regulator_is_enabled(enum mtk_regulator regulator)
+{
+ if (check_regulator_control(regulator) < 0)
+ return 0;
+
+ int id;
+
+ id = get_mt6360_regulator_id(regulator);
+ if (id >= 0)
+ return mt6360_pmic_is_enabled(id);
+
+ printk(BIOS_ERR,
+ "Failed to query regulator ID: %d\n; assuming disabled",
+ regulator);
+
+ return 0;
+}