mb/google/nissa/var/rull: add ssd timing and modify ssd GPIO pins of rtd3
[coreboot2.git] / src / mainboard / google / asurada / regulator.c
blobdff71230865c54a10d4d4b6d08d66dfa64801157
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)
11 switch (regulator) {
12 case MTK_REGULATOR_VDD2:
13 return MT6360_BUCK1;
14 case MTK_REGULATOR_VDDQ:
15 return MT6360_LDO7;
16 case MTK_REGULATOR_VMDDR:
17 return MT6360_LDO6;
18 case MTK_REGULATOR_VCC:
19 return MT6360_LDO5;
20 case MTK_REGULATOR_VCCQ:
21 return MT6360_LDO3;
22 default:
23 break;
26 return -1;
29 static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
31 switch (regulator) {
32 case MTK_REGULATOR_VCORE:
33 return MT6359P_GPU11;
34 default:
35 break;
38 return -1;
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);
49 return;
52 int id;
54 id = get_mt6360_regulator_id(regulator);
55 if (id >= 0) {
56 uint32_t voltage_mv = voltage_uv / 1000;
57 google_chromeec_regulator_set_voltage(id, voltage_mv, voltage_mv);
58 return;
61 id = get_mt6359p_regulator_id(regulator);
62 if (id >= 0) {
63 mt6359p_buck_set_voltage(id, voltage_uv);
64 return;
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();
79 int id;
81 id = get_mt6360_regulator_id(regulator);
82 if (id >= 0) {
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);
89 if (id >= 0)
90 return mt6359p_buck_get_voltage(id);
92 printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);
94 return 0;
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)
101 return 0;
103 int id;
105 id = get_mt6360_regulator_id(regulator);
106 if (id < 0) {
107 printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);
108 return -1;
111 return google_chromeec_regulator_enable(id, enable);
114 bool mainboard_regulator_is_enabled(enum mtk_regulator regulator)
116 int id;
118 id = get_mt6360_regulator_id(regulator);
119 if (id < 0) {
120 printk(BIOS_WARNING, "Invalid regulator ID: %d\n; assuming disabled",
121 regulator);
122 return false;
125 uint8_t enabled;
126 if (google_chromeec_regulator_is_enabled(id, &enabled) < 0) {
127 printk(BIOS_WARNING,
128 "Failed to query regulator ID: %d\n; assuming disabled",
129 regulator);
130 return false;
133 return !!enabled;