summaryrefslogtreecommitdiff
path: root/src/drivers/xpowers/axp209
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/xpowers/axp209')
-rw-r--r--src/drivers/xpowers/axp209/axp209.c74
-rw-r--r--src/drivers/xpowers/axp209/axp209.h3
2 files changed, 76 insertions, 1 deletions
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 <console/console.h>
#include <device/device.h>
#include <device/i2c.h>
@@ -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;
}
diff --git a/src/drivers/xpowers/axp209/axp209.h b/src/drivers/xpowers/axp209/axp209.h
index 1d369f590c..c9cdd7efba 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);