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>
This commit is contained in:
Rex-BC Chen 2021-07-16 20:04:26 +08:00 committed by Felix Held
parent cd67657dea
commit 86c50e11ce
4 changed files with 121 additions and 91 deletions

View File

@ -127,8 +127,8 @@ static void configure_sdcard(void)
mtk_i2c_bus_init(7); mtk_i2c_bus_init(7);
mt6360_init(7); mt6360_init(7);
mt6360_ldo_enable(MT6360_LDO3, 1); mt6360_enable(MT6360_LDO3, 1);
mt6360_ldo_enable(MT6360_LDO5, 1); mt6360_enable(MT6360_LDO5, 1);
} }
/* Set up backlight control pins as output pin and power-off by default */ /* Set up backlight control pins as output pin and power-off by default */

View File

@ -57,7 +57,7 @@ void mainboard_set_regulator_vol(enum mtk_regulator regulator,
id = get_mt6360_regulator_id(regulator); id = get_mt6360_regulator_id(regulator);
if (id >= 0) { if (id >= 0) {
mt6360_pmic_set_voltage(id, voltage_uv); mt6360_set_voltage(id, voltage_uv);
return; return;
} }
@ -85,7 +85,7 @@ uint32_t mainboard_get_regulator_vol(enum mtk_regulator regulator)
id = get_mt6360_regulator_id(regulator); id = get_mt6360_regulator_id(regulator);
if (id >= 0) if (id >= 0)
return mt6360_pmic_get_voltage(id); return mt6360_get_voltage(id);
id = get_mt6359p_regulator_id(regulator); id = get_mt6359p_regulator_id(regulator);
if (id >= 0) if (id >= 0)
@ -113,7 +113,7 @@ int mainboard_enable_regulator(enum mtk_regulator regulator, uint8_t enable)
id = get_mt6360_regulator_id(regulator); id = get_mt6360_regulator_id(regulator);
if (id >= 0) { if (id >= 0) {
mt6360_pmic_enable(id, enable); mt6360_enable(id, enable);
return 0; return 0;
} }
@ -131,7 +131,7 @@ uint8_t mainboard_regulator_is_enabled(enum mtk_regulator regulator)
id = get_mt6360_regulator_id(regulator); id = get_mt6360_regulator_id(regulator);
if (id >= 0) if (id >= 0)
return mt6360_pmic_is_enabled(id); return mt6360_is_enabled(id);
printk(BIOS_ERR, printk(BIOS_ERR,
"Failed to query regulator ID: %d\n; assuming disabled", "Failed to query regulator ID: %d\n; assuming disabled",

View File

@ -55,15 +55,9 @@ struct mt6360_data {
}; };
void mt6360_init(uint8_t bus); void mt6360_init(uint8_t bus);
void mt6360_enable(enum mt6360_regulator_id id, uint8_t enable);
void mt6360_ldo_enable(enum mt6360_regulator_id id, uint8_t enable); uint8_t mt6360_is_enabled(enum mt6360_regulator_id id);
uint8_t mt6360_ldo_is_enabled(enum mt6360_regulator_id id); void mt6360_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv);
void mt6360_ldo_set_voltage(enum mt6360_regulator_id id, u32 voltage_uv); u32 mt6360_get_voltage(enum mt6360_regulator_id id);
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);
#endif #endif

View File

@ -195,7 +195,7 @@ static bool is_valid_pmic(enum mt6360_regulator_id id)
return true; 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; u8 val;
const struct mt6360_data *data; 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); 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; u8 val;
const struct mt6360_data *data; 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; 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; u8 val = 0;
u32 voltage_uv_temp = 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); 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; u8 val;
u32 voltage_uv; u32 voltage_uv;
@ -297,6 +297,89 @@ u32 mt6360_ldo_get_voltage(enum mt6360_regulator_id id)
return voltage_uv; 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 = &regulator_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 = &regulator_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 = &regulator_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 = &regulator_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) void mt6360_init(uint8_t bus)
{ {
u8 delay01, delay02, delay03, delay04; u8 delay01, delay02, delay03, delay04;
@ -321,85 +404,38 @@ void mt6360_init(uint8_t bus)
__func__, delay01, delay02, delay03, delay04); __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; if (is_valid_ldo(id))
const struct mt6360_data *data; mt6360_ldo_enable(id, enable);
else if (is_valid_pmic(id))
mt6360_pmic_enable(id, enable);
}
if (!is_valid_pmic(id)) uint8_t mt6360_is_enabled(enum mt6360_regulator_id id)
return; {
if (is_valid_ldo(id))
data = &regulator_data[id]; return mt6360_ldo_is_enabled(id);
else if (is_valid_pmic(id))
if (mt6360_read_interface(MT6360_INDEX_PMIC, data->enable_reg, &val, 0xff, 0) < 0) return mt6360_pmic_is_enabled(id);
return;
if (enable)
val |= data->enable_mask;
else else
val &= ~(data->enable_mask); return 0;
mt6360_config_interface(MT6360_INDEX_PMIC, data->enable_reg, val, 0xff, 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; if (is_valid_ldo(id))
const struct mt6360_data *data; mt6360_ldo_set_voltage(id, voltage_uv);
else if (is_valid_pmic(id))
if (!is_valid_pmic(id)) mt6360_pmic_set_voltage(id, voltage_uv);
return 0;
data = &regulator_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;
} }
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; if (is_valid_ldo(id))
return mt6360_ldo_get_voltage(id);
const struct mt6360_data *data; else if (is_valid_pmic(id))
return mt6360_pmic_get_voltage(id);
if (!is_valid_pmic(id)) else
return;
data = &regulator_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))
return 0; return 0;
data = &regulator_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;
} }