From 86c50e11ced7d7e3ae62b90a4a0dcdae8d740247 Mon Sep 17 00:00:00 2001 From: Rex-BC Chen Date: Fri, 16 Jul 2021 20:04:26 +0800 Subject: [PATCH] soc/mediatek/mt8195: modify mt6360 interface With the new definition of mt6360_regulator_id, merge the MT6360 LDO and PMIC interfaces into one. Signed-off-by: Rex-BC Chen Change-Id: I7ccc32cb0a9481d5f55349c152267a44fe09d20a Reviewed-on: https://review.coreboot.org/c/coreboot/+/56435 Tested-by: build bot (Jenkins) Reviewed-by: Hung-Te Lin Reviewed-by: Yu-Ping Wu --- src/mainboard/google/cherry/mainboard.c | 4 +- src/mainboard/google/cherry/regulator.c | 8 +- src/soc/mediatek/mt8195/include/soc/mt6360.h | 14 +- src/soc/mediatek/mt8195/mt6360.c | 186 +++++++++++-------- 4 files changed, 121 insertions(+), 91 deletions(-) diff --git a/src/mainboard/google/cherry/mainboard.c b/src/mainboard/google/cherry/mainboard.c index 21ab24c58a..76aa59b5bb 100644 --- a/src/mainboard/google/cherry/mainboard.c +++ b/src/mainboard/google/cherry/mainboard.c @@ -127,8 +127,8 @@ static void configure_sdcard(void) mtk_i2c_bus_init(7); mt6360_init(7); - mt6360_ldo_enable(MT6360_LDO3, 1); - mt6360_ldo_enable(MT6360_LDO5, 1); + mt6360_enable(MT6360_LDO3, 1); + mt6360_enable(MT6360_LDO5, 1); } /* Set up backlight control pins as output pin and power-off by default */ diff --git a/src/mainboard/google/cherry/regulator.c b/src/mainboard/google/cherry/regulator.c index b59a643069..0c1f7feb05 100644 --- a/src/mainboard/google/cherry/regulator.c +++ b/src/mainboard/google/cherry/regulator.c @@ -57,7 +57,7 @@ void mainboard_set_regulator_vol(enum mtk_regulator regulator, id = get_mt6360_regulator_id(regulator); if (id >= 0) { - mt6360_pmic_set_voltage(id, voltage_uv); + mt6360_set_voltage(id, voltage_uv); return; } @@ -85,7 +85,7 @@ uint32_t mainboard_get_regulator_vol(enum mtk_regulator regulator) id = get_mt6360_regulator_id(regulator); if (id >= 0) - return mt6360_pmic_get_voltage(id); + return mt6360_get_voltage(id); id = get_mt6359p_regulator_id(regulator); if (id >= 0) @@ -113,7 +113,7 @@ int mainboard_enable_regulator(enum mtk_regulator regulator, uint8_t enable) id = get_mt6360_regulator_id(regulator); if (id >= 0) { - mt6360_pmic_enable(id, enable); + mt6360_enable(id, enable); return 0; } @@ -131,7 +131,7 @@ uint8_t mainboard_regulator_is_enabled(enum mtk_regulator regulator) id = get_mt6360_regulator_id(regulator); if (id >= 0) - return mt6360_pmic_is_enabled(id); + return mt6360_is_enabled(id); printk(BIOS_ERR, "Failed to query regulator ID: %d\n; assuming disabled", diff --git a/src/soc/mediatek/mt8195/include/soc/mt6360.h b/src/soc/mediatek/mt8195/include/soc/mt6360.h index e7cc9feaa1..0c5edff46e 100644 --- a/src/soc/mediatek/mt8195/include/soc/mt6360.h +++ b/src/soc/mediatek/mt8195/include/soc/mt6360.h @@ -55,15 +55,9 @@ struct mt6360_data { }; void mt6360_init(uint8_t bus); - -void mt6360_ldo_enable(enum mt6360_regulator_id id, uint8_t enable); -uint8_t mt6360_ldo_is_enabled(enum mt6360_regulator_id id); -void mt6360_ldo_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv); -u32 mt6360_ldo_get_voltage(enum mt6360_regulator_id id); - -void mt6360_pmic_enable(enum mt6360_regulator_id id, uint8_t enable); -uint8_t mt6360_pmic_is_enabled(enum mt6360_regulator_id id); -void mt6360_pmic_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv); -u32 mt6360_pmic_get_voltage(enum mt6360_regulator_id id); +void mt6360_enable(enum mt6360_regulator_id id, uint8_t enable); +uint8_t mt6360_is_enabled(enum mt6360_regulator_id id); +void mt6360_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv); +u32 mt6360_get_voltage(enum mt6360_regulator_id id); #endif diff --git a/src/soc/mediatek/mt8195/mt6360.c b/src/soc/mediatek/mt8195/mt6360.c index 437f995c3d..142e244e74 100644 --- a/src/soc/mediatek/mt8195/mt6360.c +++ b/src/soc/mediatek/mt8195/mt6360.c @@ -195,7 +195,7 @@ static bool is_valid_pmic(enum mt6360_regulator_id id) return true; } -void mt6360_ldo_enable(enum mt6360_regulator_id id, uint8_t enable) +static void mt6360_ldo_enable(enum mt6360_regulator_id id, uint8_t enable) { u8 val; const struct mt6360_data *data; @@ -216,7 +216,7 @@ void mt6360_ldo_enable(enum mt6360_regulator_id id, uint8_t enable) mt6360_config_interface(MT6360_INDEX_LDO, data->enable_reg, val, 0xff, 0); } -uint8_t mt6360_ldo_is_enabled(enum mt6360_regulator_id id) +static uint8_t mt6360_ldo_is_enabled(enum mt6360_regulator_id id) { u8 val; const struct mt6360_data *data; @@ -232,7 +232,7 @@ uint8_t mt6360_ldo_is_enabled(enum mt6360_regulator_id id) return (val & data->enable_mask) ? 1 : 0; } -void mt6360_ldo_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) +static void mt6360_ldo_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) { u8 val = 0; u32 voltage_uv_temp = 0; @@ -270,7 +270,7 @@ void mt6360_ldo_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) mt6360_config_interface(MT6360_INDEX_LDO, data->vsel_reg, val, 0xff, 0); } -u32 mt6360_ldo_get_voltage(enum mt6360_regulator_id id) +static u32 mt6360_ldo_get_voltage(enum mt6360_regulator_id id) { u8 val; u32 voltage_uv; @@ -297,6 +297,89 @@ u32 mt6360_ldo_get_voltage(enum mt6360_regulator_id id) return voltage_uv; } +static void mt6360_pmic_enable(enum mt6360_regulator_id id, uint8_t enable) +{ + u8 val; + const struct mt6360_data *data; + + if (!is_valid_pmic(id)) + return; + + data = ®ulator_data[id]; + + if (mt6360_read_interface(MT6360_INDEX_PMIC, data->enable_reg, &val, 0xff, 0) < 0) + return; + + if (enable) + val |= data->enable_mask; + else + val &= ~(data->enable_mask); + + mt6360_config_interface(MT6360_INDEX_PMIC, data->enable_reg, val, 0xff, 0); +} + +static uint8_t mt6360_pmic_is_enabled(enum mt6360_regulator_id id) +{ + u8 val; + const struct mt6360_data *data; + + if (!is_valid_pmic(id)) + return 0; + + data = ®ulator_data[id]; + + if (mt6360_read_interface(MT6360_INDEX_PMIC, data->enable_reg, &val, 0xff, 0) < 0) + return 0; + + return (val & data->enable_mask) ? 1 : 0; +} + +static void mt6360_pmic_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) +{ + u8 val = 0; + + const struct mt6360_data *data; + + if (!is_valid_pmic(id)) + return; + + data = ®ulator_data[id]; + + if (id == MT6360_BUCK1 || id == MT6360_BUCK2) { + val = (voltage_uv - 300000) / 5000; + } else if (id == MT6360_LDO6 || id == MT6360_LDO7) { + val = (((voltage_uv - 500000) / 100000) << 4); + val += (((voltage_uv - 500000) % 100000) / 10000); + } + + mt6360_config_interface(MT6360_INDEX_PMIC, data->vsel_reg, val, 0xff, 0); +} + +static u32 mt6360_pmic_get_voltage(enum mt6360_regulator_id id) +{ + u8 val; + u32 voltage_uv = 0; + + const struct mt6360_data *data; + + if (!is_valid_pmic(id)) + return 0; + + data = ®ulator_data[id]; + + if (mt6360_read_interface(MT6360_INDEX_PMIC, data->vsel_reg, &val, 0xff, 0) < 0) + return 0; + + if (id == MT6360_BUCK1 || id == MT6360_BUCK2) { + voltage_uv = 300000 + val * 5000; + } else if (id == MT6360_LDO6 || id == MT6360_LDO7) { + voltage_uv = 500000 + 100000 * (val >> 4); + voltage_uv += MIN(val & 0xf, 0xa) * 10000; + } + + return voltage_uv; +} + void mt6360_init(uint8_t bus) { u8 delay01, delay02, delay03, delay04; @@ -321,85 +404,38 @@ void mt6360_init(uint8_t bus) __func__, delay01, delay02, delay03, delay04); } -void mt6360_pmic_enable(enum mt6360_regulator_id id, uint8_t enable) +void mt6360_enable(enum mt6360_regulator_id id, uint8_t enable) { - u8 val; - const struct mt6360_data *data; + if (is_valid_ldo(id)) + mt6360_ldo_enable(id, enable); + else if (is_valid_pmic(id)) + mt6360_pmic_enable(id, enable); +} - if (!is_valid_pmic(id)) - return; - - data = ®ulator_data[id]; - - if (mt6360_read_interface(MT6360_INDEX_PMIC, data->enable_reg, &val, 0xff, 0) < 0) - return; - - if (enable) - val |= data->enable_mask; +uint8_t mt6360_is_enabled(enum mt6360_regulator_id id) +{ + if (is_valid_ldo(id)) + return mt6360_ldo_is_enabled(id); + else if (is_valid_pmic(id)) + return mt6360_pmic_is_enabled(id); else - val &= ~(data->enable_mask); - - mt6360_config_interface(MT6360_INDEX_PMIC, data->enable_reg, val, 0xff, 0); + return 0; } -uint8_t mt6360_pmic_is_enabled(enum mt6360_regulator_id id) +void mt6360_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) { - u8 val; - const struct mt6360_data *data; - - if (!is_valid_pmic(id)) - return 0; - - data = ®ulator_data[id]; - - if (mt6360_read_interface(MT6360_INDEX_PMIC, data->enable_reg, &val, 0xff, 0) < 0) - return 0; - - return (val & data->enable_mask) ? 1 : 0; + if (is_valid_ldo(id)) + mt6360_ldo_set_voltage(id, voltage_uv); + else if (is_valid_pmic(id)) + mt6360_pmic_set_voltage(id, voltage_uv); } -void mt6360_pmic_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) +u32 mt6360_get_voltage(enum mt6360_regulator_id id) { - u8 val = 0; - - const struct mt6360_data *data; - - if (!is_valid_pmic(id)) - return; - - data = ®ulator_data[id]; - - if (id == MT6360_BUCK1 || id == MT6360_BUCK2) { - val = (voltage_uv - 300000) / 5000; - } else if (id == MT6360_LDO6 || id == MT6360_LDO7) { - val = (((voltage_uv - 500000) / 100000) << 4); - val += (((voltage_uv - 500000) % 100000) / 10000); - } - - mt6360_config_interface(MT6360_INDEX_PMIC, data->vsel_reg, val, 0xff, 0); -} - -u32 mt6360_pmic_get_voltage(enum mt6360_regulator_id id) -{ - u8 val; - u32 voltage_uv = 0; - - const struct mt6360_data *data; - - if (!is_valid_pmic(id)) + if (is_valid_ldo(id)) + return mt6360_ldo_get_voltage(id); + else if (is_valid_pmic(id)) + return mt6360_pmic_get_voltage(id); + else return 0; - - data = ®ulator_data[id]; - - if (mt6360_read_interface(MT6360_INDEX_PMIC, data->vsel_reg, &val, 0xff, 0) < 0) - return 0; - - if (id == MT6360_BUCK1 || id == MT6360_BUCK2) { - voltage_uv = 300000 + val * 5000; - } else if (id == MT6360_LDO6 || id == MT6360_LDO7) { - voltage_uv = 500000 + 100000 * (val >> 4); - voltage_uv += MIN(val & 0xf, 0xa) * 10000; - } - - return voltage_uv; }