blob: 8f0d7cb37acc377ee706a708c215d4e68f203d26 [file] [log] [blame]
Hui Liuba16e052022-07-15 14:02:34 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <console/console.h>
4#include <soc/mt6359p.h>
5#include <soc/regulator.h>
6
7#define MTK_REGULATOR_INVALID -1
8
9static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
10{
11 switch (regulator) {
12 case MTK_REGULATOR_VCORE:
13 return MT6359P_GPU11;
14 case MTK_REGULATOR_VPROC11:
15 return MT6359P_CORE;
16 case MTK_REGULATOR_VSRAM_PROC11:
17 return MT6359P_SRAM_PROC1;
18 case MTK_REGULATOR_VMCH:
19 return MT6359P_PA;
20 case MTK_REGULATOR_VMC:
21 return MT6359P_SIM1;
Sen Chue40cbcf2023-02-03 16:20:32 +080022 case MTK_REGULATOR_VDD18:
23 return MT6359P_VM18;
Hui Liuba16e052022-07-15 14:02:34 +080024 default:
25 return MTK_REGULATOR_INVALID;
26 }
27}
28
29void mainboard_set_regulator_voltage(enum mtk_regulator regulator, uint32_t voltage_uv)
30{
31 int id;
32
33 id = get_mt6359p_regulator_id(regulator);
34 if (id < 0) {
35 printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
36 return;
37 }
38
39 if (id == MT6359P_SIM1)
40 mt6359p_set_vsim1_voltage(voltage_uv);
Cong Yang0ab39182024-01-29 14:29:55 +080041 else if (id == MT6359P_VM18)
42 mt6359p_set_vm18_voltage(voltage_uv);
Hui Liuba16e052022-07-15 14:02:34 +080043 else
44 mt6359p_buck_set_voltage(id, voltage_uv);
45}
46
47uint32_t mainboard_get_regulator_voltage(enum mtk_regulator regulator)
48{
49 int id;
50
51 id = get_mt6359p_regulator_id(regulator);
52 if (id < 0) {
53 printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
54 return 0;
55 }
56
57 if (id == MT6359P_SIM1)
58 return mt6359p_get_vsim1_voltage();
59
60 return mt6359p_buck_get_voltage(id);
61}
62
63int mainboard_enable_regulator(enum mtk_regulator regulator, bool enable)
64{
65 int id;
66
67 id = get_mt6359p_regulator_id(regulator);
68 if (id < 0) {
69 printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator);
70 return -1;
71 }
72
73 if (id == MT6359P_SIM1)
74 mt6359p_enable_vsim1(enable);
75 else if (id == MT6359P_PA)
76 mt6359p_enable_vpa(enable);
Sen Chue40cbcf2023-02-03 16:20:32 +080077 else if (id == MT6359P_VM18)
78 mt6359p_enable_vm18(enable);
Hui Liuba16e052022-07-15 14:02:34 +080079 else
80 printk(BIOS_INFO, "No need to enable regulator ID: %d\n", regulator);
81
82 return 0;
83}