Debian Codegraph @

src/mainboard/google/skywalker/regulator.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2
3 #include <console/console.h>
4 #include <soc/mt6359p.h>
5 #include <soc/regulator.h>
6
7 #define MTK_REGULATOR_INVALID -1
8
9 static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
10 {
11 switch (regulator) {
12 case MTK_REGULATOR_VPROC12:
13 return MT6359P_VMODEM;
14 case MTK_REGULATOR_VSRAM_PROC12:
15 return MT6359P_VSRAM_MD;
16 case MTK_REGULATOR_VMCH:
17 return MT6359P_PA;
18 case MTK_REGULATOR_VMC:
19 return MT6359P_SIM1;
20 case MTK_REGULATOR_VCN18:
21 return MT6359P_VCN18;
22 default:
23 return MTK_REGULATOR_INVALID;
24 }
25 }
26
27 void mainboard_set_regulator_voltage(enum mtk_regulator regulator, uint32_t voltage_uv)
28 {
29 int id;
30
31 id = get_mt6359p_regulator_id(regulator);
32 if (id < 0) {
33 printk(BIOS_ERR, "%s: Invalid regulator ID: %d\n", __func__, regulator);
34 return;
35 }
36
37 switch (id) {
38 case MT6359P_VMODEM:
39 mt6359p_buck_set_voltage(MT6359P_VMODEM, voltage_uv);
40 break;
41 case MT6359P_VSRAM_MD:
42 mt6359p_buck_set_voltage(MT6359P_VSRAM_MD, voltage_uv);
43 break;
44 case MT6359P_PA:
45 mt6359p_buck_set_voltage(MT6359P_PA, voltage_uv);
46 break;
47 case MT6359P_SIM1:
48 mt6359p_set_vsim1_voltage(voltage_uv);
49 break;
50 case MT6359P_VCN18:
51 mt6359p_set_vcn18_voltage(voltage_uv);
52 break;
53 default:
54 printk(BIOS_ERR, "%s: Regulator ID %d: not supported\n", __func__, regulator);
55 break;
56 }
57 }
58
59 uint32_t mainboard_get_regulator_voltage(enum mtk_regulator regulator)
60 {
61 int id;
62
63 id = get_mt6359p_regulator_id(regulator);
64 if (id < 0) {
65 printk(BIOS_ERR, "%s: Invalid regulator ID: %d\n", __func__, regulator);
66 return 0;
67 }
68
69 switch (id) {
70 case MT6359P_VMODEM:
71 return mt6359p_buck_get_voltage(MT6359P_VMODEM);
72 case MT6359P_VSRAM_MD:
73 return mt6359p_buck_get_voltage(MT6359P_VSRAM_MD);
74 case MT6359P_PA:
75 return mt6359p_buck_get_voltage(MT6359P_PA);
76 case MT6359P_SIM1:
77 return mt6359p_get_vsim1_voltage();
78 case MT6359P_VCN18:
79 return mt6359p_get_vcn18_voltage();
80 default:
81 printk(BIOS_ERR, "%s: Regulator ID %d: not supported\n", __func__, regulator);
82 return 0;
83 }
84 }
85
86 int mainboard_enable_regulator(enum mtk_regulator regulator, bool enable)
87 {
88 int id;
89
90 id = get_mt6359p_regulator_id(regulator);
91 if (id < 0) {
92 printk(BIOS_ERR, "%s: Invalid regulator ID: %d\n", __func__, regulator);
93 return -1;
94 }
95
96 switch (id) {
97 case MT6359P_PA:
98 mt6359p_enable_vpa(enable);
99 break;
100 case MT6359P_SIM1:
101 mt6359p_enable_vsim1(enable);
102 break;
103 case MT6359P_VCN18:
104 mt6359p_enable_vcn18(enable);
105 break;
106 default:
107 printk(BIOS_ERR, "%s: Regulator ID %d: not supported\n", __func__, regulator);
108 break;
109 }
110
111 return 0;
112 }