1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <ec/google/chromeec/ec.h>
5 #include <soc/mt6359p.h>
6 #include <soc/mt6360.h>
7 #include <soc/regulator.h>
9 static int get_mt6360_regulator_id(enum mtk_regulator regulator
)
12 case MTK_REGULATOR_VDD2
:
14 case MTK_REGULATOR_VDDQ
:
16 case MTK_REGULATOR_VMDDR
:
18 case MTK_REGULATOR_VCC
:
20 case MTK_REGULATOR_VCCQ
:
29 static int get_mt6359p_regulator_id(enum mtk_regulator regulator
)
32 case MTK_REGULATOR_VCORE
:
41 void mainboard_set_regulator_voltage(enum mtk_regulator regulator
, uint32_t voltage_uv
)
44 * Handle the regulator that does not have a regulator ID
45 * in its underlying implementation.
47 if (regulator
== MTK_REGULATOR_VDD1
) {
48 mt6359p_set_vm18_voltage(voltage_uv
);
54 id
= get_mt6360_regulator_id(regulator
);
56 uint32_t voltage_mv
= voltage_uv
/ 1000;
57 google_chromeec_regulator_set_voltage(id
, voltage_mv
, voltage_mv
);
61 id
= get_mt6359p_regulator_id(regulator
);
63 mt6359p_buck_set_voltage(id
, voltage_uv
);
67 printk(BIOS_WARNING
, "Invalid regulator ID: %d\n", regulator
);
70 uint32_t mainboard_get_regulator_voltage(enum mtk_regulator regulator
)
73 * Handle the regulator that does not have a regulator ID
74 * in its underlying implementation.
76 if (regulator
== MTK_REGULATOR_VDD1
)
77 return mt6359p_get_vm18_voltage();
81 id
= get_mt6360_regulator_id(regulator
);
83 uint32_t voltage_mv
= 0;
84 google_chromeec_regulator_get_voltage(id
, &voltage_mv
);
85 return voltage_mv
* 1000;
88 id
= get_mt6359p_regulator_id(regulator
);
90 return mt6359p_buck_get_voltage(id
);
92 printk(BIOS_WARNING
, "Invalid regulator ID: %d\n", regulator
);
97 int mainboard_enable_regulator(enum mtk_regulator regulator
, bool enable
)
99 /* Return 0 if the regulator is already enabled or disabled. */
100 if (mainboard_regulator_is_enabled(regulator
) == enable
)
105 id
= get_mt6360_regulator_id(regulator
);
107 printk(BIOS_WARNING
, "Invalid regulator ID: %d\n", regulator
);
111 return google_chromeec_regulator_enable(id
, enable
);
114 bool mainboard_regulator_is_enabled(enum mtk_regulator regulator
)
118 id
= get_mt6360_regulator_id(regulator
);
120 printk(BIOS_WARNING
, "Invalid regulator ID: %d\n; assuming disabled",
126 if (google_chromeec_regulator_is_enabled(id
, &enabled
) < 0) {
128 "Failed to query regulator ID: %d\n; assuming disabled",