coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
regulator.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
5 #include <soc/mt6359p.h>
6 #include <soc/mt6360.h>
7 #include <soc/regulator.h>
8 
9 static int get_mt6360_regulator_id(enum mtk_regulator regulator)
10 {
11  switch (regulator) {
12  case MTK_REGULATOR_VDD2:
13  return MT6360_BUCK1;
14  case MTK_REGULATOR_VDDQ:
15  return MT6360_LDO7;
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;
24  }
25 
26  return -1;
27 }
28 
29 static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
30 {
31  switch (regulator) {
33  return MT6359P_GPU11;
34  default:
35  break;
36  }
37 
38  return -1;
39 }
40 
42  uint32_t voltage_uv)
43 {
44  /*
45  * Handle the regulator that does not have a regulator ID
46  * in its underlying implementation.
47  */
48  if (regulator == MTK_REGULATOR_VDD1) {
49  mt6359p_set_vm18_voltage(voltage_uv);
50  return;
51  }
52 
53  int id;
54 
55  id = get_mt6360_regulator_id(regulator);
56  if (id >= 0) {
57  uint32_t voltage_mv = voltage_uv / 1000;
58  google_chromeec_regulator_set_voltage(id, voltage_mv, voltage_mv);
59  return;
60  }
61 
62  id = get_mt6359p_regulator_id(regulator);
63  if (id >= 0) {
64  mt6359p_buck_set_voltage(id, voltage_uv);
65  return;
66  }
67 
68  printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);
69 }
70 
72 {
73  /*
74  * Handle the regulator that does not have a regulator ID
75  * in its underlying implementation.
76  */
77  if (regulator == MTK_REGULATOR_VDD1)
78  return mt6359p_get_vm18_voltage();
79 
80  int id;
81 
82  id = get_mt6360_regulator_id(regulator);
83  if (id >= 0) {
84  uint32_t voltage_mv = 0;
86  return voltage_mv * 1000;
87  }
88 
89  id = get_mt6359p_regulator_id(regulator);
90  if (id >= 0)
91  return mt6359p_buck_get_voltage(id);
92 
93  printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);
94 
95  return 0;
96 }
97 
99 {
100  /* Return 0 if the regulator is already enabled or disabled. */
101  if (mainboard_regulator_is_enabled(regulator) == enable)
102  return 0;
103 
104  int id;
105 
106  id = get_mt6360_regulator_id(regulator);
107  if (id < 0) {
108  printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);
109  return -1;
110  }
111 
112  return google_chromeec_regulator_enable(id, enable);
113 }
114 
116 {
117  int id;
118 
119  id = get_mt6360_regulator_id(regulator);
120  if (id < 0) {
121  printk(BIOS_WARNING, "Invalid regulator ID: %d\n; assuming disabled",
122  regulator);
123  return 0;
124  }
125 
126  uint8_t enabled;
127  if (google_chromeec_regulator_is_enabled(id, &enabled) < 0) {
129  "Failed to query regulator ID: %d\n; assuming disabled",
130  regulator);
131  return 0;
132  }
133 
134  return enabled;
135 }
void mainboard_set_regulator_vol(enum mtk_regulator regulator, uint32_t voltage_uv)
Definition: regulator.c:41
uint32_t mainboard_get_regulator_vol(enum mtk_regulator regulator)
Definition: regulator.c:71
int mainboard_enable_regulator(enum mtk_regulator regulator, uint8_t enable)
Definition: regulator.c:98
static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
Definition: regulator.c:29
static int get_mt6360_regulator_id(enum mtk_regulator regulator)
Definition: regulator.c:9
uint8_t mainboard_regulator_is_enabled(enum mtk_regulator regulator)
Definition: regulator.c:115
#define printk(level,...)
Definition: stdlib.h:16
int google_chromeec_regulator_is_enabled(uint32_t index, uint8_t *enabled)
Query if the regulator is enabled.
Definition: ec.c:1776
int google_chromeec_regulator_set_voltage(uint32_t index, uint32_t min_mv, uint32_t max_mv)
Set voltage for the voltage regulator within the range specified.
Definition: ec.c:1800
int google_chromeec_regulator_enable(uint32_t index, uint8_t enable)
Configure the regulator as enabled / disabled.
Definition: ec.c:1754
int google_chromeec_regulator_get_voltage(uint32_t index, uint32_t *voltage_mv)
Get the currently configured voltage for the voltage regulator.
Definition: ec.c:1824
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
void mt6359p_set_vm18_voltage(u32 vm18_uv)
Definition: mt6359p.c:230
@ MT6359P_GPU11
Definition: mt6359p.h:52
u32 mt6359p_buck_get_voltage(u32 buck_id)
Definition: mt6359p.c:193
void mt6359p_buck_set_voltage(u32 buck_id, u32 buck_uv)
Definition: mt6359p.c:160
u32 mt6359p_get_vm18_voltage(void)
Definition: mt6359p.c:245
@ MT6360_BUCK1
Definition: mt6360.h:11
@ MT6360_LDO5
Definition: mt6360.h:8
@ MT6360_LDO3
Definition: mt6360.h:7
@ MT6360_LDO6
Definition: mt6360.h:9
@ MT6360_LDO7
Definition: mt6360.h:10
mtk_regulator
Definition: regulator.h:8
@ MTK_REGULATOR_VDDQ
Definition: regulator.h:11
@ MTK_REGULATOR_VCCQ
Definition: regulator.h:15
@ MTK_REGULATOR_VCC
Definition: regulator.h:14
@ MTK_REGULATOR_VDD1
Definition: regulator.h:9
@ MTK_REGULATOR_VCORE
Definition: regulator.h:13
@ MTK_REGULATOR_VDD2
Definition: regulator.h:10
@ MTK_REGULATOR_VMDDR
Definition: regulator.h:12
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8