Hui Liu | ba16e05 | 2022-07-15 14:02:34 +0800 | [diff] [blame] | 1 | /* 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 | |
| 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; |
Sen Chu | e40cbcf | 2023-02-03 16:20:32 +0800 | [diff] [blame] | 22 | case MTK_REGULATOR_VDD18: |
| 23 | return MT6359P_VM18; |
Hui Liu | ba16e05 | 2022-07-15 14:02:34 +0800 | [diff] [blame] | 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); |
Cong Yang | 0ab3918 | 2024-01-29 14:29:55 +0800 | [diff] [blame^] | 41 | else if (id == MT6359P_VM18) |
| 42 | mt6359p_set_vm18_voltage(voltage_uv); |
Hui Liu | ba16e05 | 2022-07-15 14:02:34 +0800 | [diff] [blame] | 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); |
Sen Chu | e40cbcf | 2023-02-03 16:20:32 +0800 | [diff] [blame] | 77 | else if (id == MT6359P_VM18) |
| 78 | mt6359p_enable_vm18(enable); |
Hui Liu | ba16e05 | 2022-07-15 14:02:34 +0800 | [diff] [blame] | 79 | else |
| 80 | printk(BIOS_INFO, "No need to enable regulator ID: %d\n", regulator); |
| 81 | |
| 82 | return 0; |
| 83 | } |