diff options
author | Rex-BC Chen <rex-bc.chen@mediatek.corp-partner.google.com> | 2021-07-16 20:04:26 +0800 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2021-07-21 15:46:53 +0000 |
commit | 86c50e11ced7d7e3ae62b90a4a0dcdae8d740247 (patch) | |
tree | 21cc1222df5db7a4cb8dcc166eef2984b9614e61 | |
parent | cd67657dea6e4c5ca1f068ebf16623924e1b001d (diff) |
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 <rex-bc.chen@mediatek.com>
Change-Id: I7ccc32cb0a9481d5f55349c152267a44fe09d20a
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56435
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
-rw-r--r-- | src/mainboard/google/cherry/mainboard.c | 4 | ||||
-rw-r--r-- | src/mainboard/google/cherry/regulator.c | 8 | ||||
-rw-r--r-- | src/soc/mediatek/mt8195/include/soc/mt6360.h | 14 | ||||
-rw-r--r-- | src/soc/mediatek/mt8195/mt6360.c | 100 |
4 files changed, 78 insertions, 48 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,31 +297,7 @@ u32 mt6360_ldo_get_voltage(enum mt6360_regulator_id id) return voltage_uv; } -void mt6360_init(uint8_t bus) -{ - u8 delay01, delay02, delay03, delay04; - - crc8_populate_msb(crc8_table[MT6360_INDEX_LDO], 0x7); - crc8_populate_msb(crc8_table[MT6360_INDEX_PMIC], 0x7); - - i2c_data[MT6360_INDEX_LDO].bus = bus; - i2c_data[MT6360_INDEX_PMIC].bus = bus; - - mt6360_config_interface(MT6360_INDEX_PMIC, 0x07, 0x04, 0xff, 0); - mt6360_config_interface(MT6360_INDEX_PMIC, 0x08, 0x00, 0xff, 0); - mt6360_config_interface(MT6360_INDEX_PMIC, 0x09, 0x02, 0xff, 0); - mt6360_config_interface(MT6360_INDEX_PMIC, 0x0a, 0x00, 0xff, 0); - - mt6360_read_interface(MT6360_INDEX_PMIC, 0x07, &delay01, 0xff, 0); - mt6360_read_interface(MT6360_INDEX_PMIC, 0x08, &delay02, 0xff, 0); - mt6360_read_interface(MT6360_INDEX_PMIC, 0x09, &delay03, 0xff, 0); - mt6360_read_interface(MT6360_INDEX_PMIC, 0x0a, &delay04, 0xff, 0); - printk(BIOS_DEBUG, - "%s: power off sequence delay: %#x, %#x, %#x, %#x\n", - __func__, delay01, delay02, delay03, delay04); -} - -void mt6360_pmic_enable(enum mt6360_regulator_id id, uint8_t enable) +static void mt6360_pmic_enable(enum mt6360_regulator_id id, uint8_t enable) { u8 val; const struct mt6360_data *data; @@ -342,7 +318,7 @@ void mt6360_pmic_enable(enum mt6360_regulator_id id, uint8_t enable) mt6360_config_interface(MT6360_INDEX_PMIC, data->enable_reg, val, 0xff, 0); } -uint8_t mt6360_pmic_is_enabled(enum mt6360_regulator_id id) +static uint8_t mt6360_pmic_is_enabled(enum mt6360_regulator_id id) { u8 val; const struct mt6360_data *data; @@ -358,7 +334,7 @@ uint8_t mt6360_pmic_is_enabled(enum mt6360_regulator_id id) return (val & data->enable_mask) ? 1 : 0; } -void mt6360_pmic_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) +static void mt6360_pmic_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) { u8 val = 0; @@ -379,7 +355,7 @@ void mt6360_pmic_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) mt6360_config_interface(MT6360_INDEX_PMIC, data->vsel_reg, val, 0xff, 0); } -u32 mt6360_pmic_get_voltage(enum mt6360_regulator_id id) +static u32 mt6360_pmic_get_voltage(enum mt6360_regulator_id id) { u8 val; u32 voltage_uv = 0; @@ -403,3 +379,63 @@ u32 mt6360_pmic_get_voltage(enum mt6360_regulator_id id) return voltage_uv; } + +void mt6360_init(uint8_t bus) +{ + u8 delay01, delay02, delay03, delay04; + + crc8_populate_msb(crc8_table[MT6360_INDEX_LDO], 0x7); + crc8_populate_msb(crc8_table[MT6360_INDEX_PMIC], 0x7); + + i2c_data[MT6360_INDEX_LDO].bus = bus; + i2c_data[MT6360_INDEX_PMIC].bus = bus; + + mt6360_config_interface(MT6360_INDEX_PMIC, 0x07, 0x04, 0xff, 0); + mt6360_config_interface(MT6360_INDEX_PMIC, 0x08, 0x00, 0xff, 0); + mt6360_config_interface(MT6360_INDEX_PMIC, 0x09, 0x02, 0xff, 0); + mt6360_config_interface(MT6360_INDEX_PMIC, 0x0a, 0x00, 0xff, 0); + + mt6360_read_interface(MT6360_INDEX_PMIC, 0x07, &delay01, 0xff, 0); + mt6360_read_interface(MT6360_INDEX_PMIC, 0x08, &delay02, 0xff, 0); + mt6360_read_interface(MT6360_INDEX_PMIC, 0x09, &delay03, 0xff, 0); + mt6360_read_interface(MT6360_INDEX_PMIC, 0x0a, &delay04, 0xff, 0); + printk(BIOS_DEBUG, + "%s: power off sequence delay: %#x, %#x, %#x, %#x\n", + __func__, delay01, delay02, delay03, delay04); +} + +void mt6360_enable(enum mt6360_regulator_id id, uint8_t enable) +{ + if (is_valid_ldo(id)) + mt6360_ldo_enable(id, enable); + else if (is_valid_pmic(id)) + mt6360_pmic_enable(id, enable); +} + +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 + return 0; +} + +void mt6360_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv) +{ + 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); +} + +u32 mt6360_get_voltage(enum mt6360_regulator_id 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; +} |