xpowers/axp209: Add helper to set voltages from devicetree config

Change-Id: I3ffe225b78f88c3c2d3a15292c43009e69413afb
Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-on: http://review.coreboot.org/4638
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Alexandru Gagniuc 2014-01-09 20:17:18 -06:00
parent af4bd599ca
commit abe9b81e83
2 changed files with 76 additions and 1 deletions

View File

@ -11,6 +11,7 @@
#include "axp209.h"
#include "chip.h"
#include <console/console.h>
#include <device/device.h>
#include <device/i2c.h>
@ -231,6 +232,77 @@ enum cb_err axp209_set_ldo4_voltage(u8 bus, u16 millivolts)
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;
}
/*
* Usually, the AXP209 is enabled and configured in romstage, so there is no
* need for a full ramstage driver. Hence .enable_dev is NULL.

View File

@ -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);