| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <soc/mt6373.h> |
| 5 |
#include <soc/regulator.h> |
| 6 |
|
| 7 |
#define MTK_REGULATOR_INVALID -1 |
| 8 |
|
| 9 |
static int get_mt6373_regulator_id(enum mtk_regulator regulator) |
| 10 |
{ |
| 11 |
switch (regulator) { |
| 12 |
case MTK_REGULATOR_VMCH: |
| 13 |
return MT6373_VMCH; |
| 14 |
case MTK_REGULATOR_VMC: |
| 15 |
return MT6373_VMC; |
| 16 |
default: |
| 17 |
return MTK_REGULATOR_INVALID; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
void mainboard_set_regulator_voltage(enum mtk_regulator regulator, uint32_t voltage_uv) |
| 22 |
{ |
| 23 |
int id; |
| 24 |
|
| 25 |
id = get_mt6373_regulator_id(regulator); |
| 26 |
if (id < 0) { |
| 27 |
printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
switch (id) { |
| 32 |
case MT6373_VMCH: |
| 33 |
mt6373_set_vmch_voltage(voltage_uv); |
| 34 |
break; |
| 35 |
case MT6373_VMC: |
| 36 |
mt6373_set_vmc_voltage(voltage_uv); |
| 37 |
break; |
| 38 |
default: |
| 39 |
printk(BIOS_ERR, "Regulator ID %d: not supported\n", regulator); |
| 40 |
break; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
uint32_t mainboard_get_regulator_voltage(enum mtk_regulator regulator) |
| 45 |
{ |
| 46 |
int id; |
| 47 |
|
| 48 |
id = get_mt6373_regulator_id(regulator); |
| 49 |
if (id < 0) { |
| 50 |
printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator); |
| 51 |
return 0; |
| 52 |
} |
| 53 |
|
| 54 |
switch (id) { |
| 55 |
case MT6373_VMCH: |
| 56 |
return mt6373_get_vmch_voltage(); |
| 57 |
case MT6373_VMC: |
| 58 |
return mt6373_get_vmc_voltage(); |
| 59 |
default: |
| 60 |
printk(BIOS_ERR, "Regulator ID %d: not supported\n", regulator); |
| 61 |
return 0; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
int mainboard_enable_regulator(enum mtk_regulator regulator, bool enable) |
| 66 |
{ |
| 67 |
int id; |
| 68 |
|
| 69 |
id = get_mt6373_regulator_id(regulator); |
| 70 |
if (id < 0) { |
| 71 |
printk(BIOS_ERR, "Invalid regulator ID: %d\n", regulator); |
| 72 |
return -1; |
| 73 |
} |
| 74 |
|
| 75 |
switch (id) { |
| 76 |
case MT6373_VMCH: |
| 77 |
mt6373_enable_vmch(enable); |
| 78 |
break; |
| 79 |
case MT6373_VMC: |
| 80 |
mt6373_enable_vmc(enable); |
| 81 |
break; |
| 82 |
default: |
| 83 |
printk(BIOS_ERR, "Regulator ID %d: not supported\n", regulator); |
| 84 |
break; |
| 85 |
} |
| 86 |
|
| 87 |
return 0; |
| 88 |
} |