From abe9b81e838bcf85e60671989815dfab669002ee Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Thu, 9 Jan 2014 20:17:18 -0600 Subject: xpowers/axp209: Add helper to set voltages from devicetree config Change-Id: I3ffe225b78f88c3c2d3a15292c43009e69413afb Signed-off-by: Alexandru Gagniuc Reviewed-on: http://review.coreboot.org/4638 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich --- src/drivers/xpowers/axp209/axp209.c | 74 ++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'src/drivers/xpowers/axp209/axp209.c') diff --git a/src/drivers/xpowers/axp209/axp209.c b/src/drivers/xpowers/axp209/axp209.c index 9f77cf6867..4f984e6b51 100644 --- a/src/drivers/xpowers/axp209/axp209.c +++ b/src/drivers/xpowers/axp209/axp209.c @@ -11,6 +11,7 @@ #include "axp209.h" #include "chip.h" +#include #include #include @@ -226,7 +227,78 @@ enum cb_err axp209_set_ldo4_voltage(u8 bus, u16 millivolts) reg8 |= REG_LDO24_VOLTAGE_LDO4_VAL(val); if (axp209_write(bus, REG_LDO24_VOLTAGE, reg8) != 1) - return CB_ERR; + return CB_ERR; + + return CB_SUCCESS; +} + +static const struct { + enum cb_err (*set_voltage) (u8 bus, u16 mv); + const char *name; +} vtable[] = { { + .set_voltage = axp209_set_dcdc2_voltage, + .name = "DCDC2", + }, { + .set_voltage = axp209_set_dcdc3_voltage, + .name = "DCDC3", + }, { + .set_voltage = axp209_set_ldo2_voltage, + .name = "LDO2", + }, { + .set_voltage = axp209_set_ldo3_voltage, + .name = "LDO3", + }, { + .set_voltage = axp209_set_ldo4_voltage, + .name = "LDO4", + } +}; + +static enum cb_err set_rail(u8 bus, int idx, u16 mv) +{ + enum cb_err err; + const char *name = vtable[idx].name; + + /* If voltage isn't specified, don't touch the rail */ + if (mv == 0) { + printk(BIOS_DEBUG, "[axp209] Skipping %s configuration\n", + name); + return CB_SUCCESS; + } + + if ((err = vtable[idx].set_voltage(bus, mv) != CB_SUCCESS)) { + printk(BIOS_ERR, "[axp209] Failed to set %s to %u mv\n", + name, mv); + return err; + } + + return CB_SUCCESS; +} + +/** + * \brief Configure all voltage rails + * + * Configure all converters and regulators from devicetree config. If any of the + * voltages are not declared (i.e. are zero), the respective rail will not be + * reconfigured, and retain its powerup voltage. + * + * @param[in] cfg pointer to @ref drivers_xpowers_axp209_config structure + * @param[in] bus I²C bus to which the AXP209 is connected + * @return CB_SUCCES on success, or an error code otherwise. + */ +enum cb_err axp209_set_voltages(u8 bus, const struct + drivers_xpowers_axp209_config *cfg) +{ + enum cb_err err; + + /* Don't worry about what the error is. Console prints that */ + err = set_rail(bus, 0, cfg->dcdc2_voltage_mv); + err |= set_rail(bus, 1, cfg->dcdc3_voltage_mv); + err |= set_rail(bus, 2, cfg->ldo2_voltage_mv); + err |= set_rail(bus, 3, cfg->ldo3_voltage_mv); + err |= set_rail(bus, 4, cfg->ldo4_voltage_mv); + + if (err != CB_SUCCESS) + return CB_ERR; return CB_SUCCESS; } -- cgit v1.2.3