Alexandru Gagniuc (mr.nuke.me@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4638
-gerrit
commit 521bb928961d13017f7ca7e7ab4c9f6f16b0945e Author: Alexandru Gagniuc mr.nuke.me@gmail.com Date: Thu Jan 9 20:17:18 2014 -0600
xpowers/axp209: Add helper to set voltages from devicetree config
Change-Id: I3ffe225b78f88c3c2d3a15292c43009e69413afb Signed-off-by: Alexandru Gagniuc mr.nuke.me@gmail.com --- src/drivers/xpowers/axp209/axp209.c | 75 ++++++++++++++++++++++++++++++++++++- src/drivers/xpowers/axp209/axp209.h | 3 ++ 2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/src/drivers/xpowers/axp209/axp209.c b/src/drivers/xpowers/axp209/axp209.c index 9f77cf6..cde4546 100644 --- a/src/drivers/xpowers/axp209/axp209.c +++ b/src/drivers/xpowers/axp209/axp209.c @@ -11,9 +11,13 @@ #include "axp209.h" #include "chip.h"
+#include <console/console.h> #include <device/device.h> #include <device/i2c.h>
+#define ERROR(x...) printk(BIOS_ERR, "[axp209] " x) +#define DEBUG(x...) printk(BIOS_DEBUG, "[axp209] " x) + /* Hide these definitions from the rest of the source, so keep them here */ enum registers { REG_POWER_STATUS = 0x00, @@ -226,7 +230,76 @@ 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) { + DEBUG("Skipping %s configuration\n", name); + return CB_SUCCESS; + } + + if ((err = vtable[idx].set_voltage(bus, mv) != CB_SUCCESS)) { + ERROR("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; } diff --git a/src/drivers/xpowers/axp209/axp209.h b/src/drivers/xpowers/axp209/axp209.h index 1d369f5..c9cdd7e 100644 --- a/src/drivers/xpowers/axp209/axp209.h +++ b/src/drivers/xpowers/axp209/axp209.h @@ -6,6 +6,7 @@ */
#include <types.h> +#include "chip.h"
#define AXP209_I2C_ADDR (0x68 >> 1)
@@ -15,3 +16,5 @@ enum cb_err axp209_set_dcdc3_voltage(u8 bus, u16 millivolts); enum cb_err axp209_set_ldo2_voltage(u8 bus, u16 millivolts); enum cb_err axp209_set_ldo3_voltage(u8 bus, u16 millivolts); enum cb_err axp209_set_ldo4_voltage(u8 bus, u16 millivolts); +enum cb_err axp209_set_voltages(u8 bus, const struct + drivers_xpowers_axp209_config *cfg);