| 1 |
|
| 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_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; |
| 22 |
case MTK_REGULATOR_VDD18: |
| 23 |
return MT6359P_VM18; |
| 24 |
default: |
| 25 |
return MTK_REGULATOR_INVALID; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
void 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); |
| 41 |
else if (id == MT6359P_VM18) |
| 42 |
mt6359p_set_vm18_voltage(voltage_uv); |
| 43 |
else |
| 44 |
mt6359p_buck_set_voltage(id, voltage_uv); |
| 45 |
} |
| 46 |
|
| 47 |
uint32_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 |
|
| 63 |
int 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); |
| 77 |
else if (id == MT6359P_VM18) |
| 78 |
mt6359p_enable_vm18(enable); |
| 79 |
else |
| 80 |
printk(BIOS_INFO, "No need to enable regulator ID: %d\n", regulator); |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |