summaryrefslogtreecommitdiff
path: root/src/drivers/xpowers/axp209
diff options
context:
space:
mode:
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>2013-12-30 01:21:55 -0500
committerAlexandru Gagniuc <mr.nuke.me@gmail.com>2014-01-13 04:01:48 +0100
commit428eeff923f8b4e18f4df093f8e8e389311cce3a (patch)
treeb1399c90e9f61d2f6581c1d62f91f1a9ecb4148c /src/drivers/xpowers/axp209
parent066dcec2fe3137bba049cbec669f57860ee21bbd (diff)
downloadcoreboot-428eeff923f8b4e18f4df093f8e8e389311cce3a.tar.xz
drivers: Add support for X-Powers AXP209 PMU
Change-Id: I1de0e656a38527b172af1d0b5bcd97acbfc03bf0 Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-on: http://review.coreboot.org/4591 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/drivers/xpowers/axp209')
-rw-r--r--src/drivers/xpowers/axp209/Kconfig15
-rw-r--r--src/drivers/xpowers/axp209/Makefile.inc3
-rw-r--r--src/drivers/xpowers/axp209/axp209.c230
-rw-r--r--src/drivers/xpowers/axp209/axp209.h17
4 files changed, 265 insertions, 0 deletions
diff --git a/src/drivers/xpowers/axp209/Kconfig b/src/drivers/xpowers/axp209/Kconfig
new file mode 100644
index 0000000000..684873c127
--- /dev/null
+++ b/src/drivers/xpowers/axp209/Kconfig
@@ -0,0 +1,15 @@
+config DRIVER_XPOWERS_AXP209
+ bool
+ default n
+ help
+ X-Powers AXP902 Power Management Unit
+
+if DRIVER_XPOWERS_AXP209
+
+config DRIVER_XPOWERS_AXP209_BOOTBLOCK
+ bool
+ default n
+ help
+ Make AXP209 functionality available in he bootblock.
+
+endif # DRIVER_XPOWERS_AXP209
diff --git a/src/drivers/xpowers/axp209/Makefile.inc b/src/drivers/xpowers/axp209/Makefile.inc
new file mode 100644
index 0000000000..5ac691e06d
--- /dev/null
+++ b/src/drivers/xpowers/axp209/Makefile.inc
@@ -0,0 +1,3 @@
+bootblock-$(CONFIG_DRIVER_XPOWERS_AXP209_BOOTBLOCK) += axp209.c
+romstage-$(CONFIG_DRIVER_XPOWERS_AXP209) += axp209.c
+ramstage-$(CONFIG_DRIVER_XPOWERS_AXP209) += axp209.c
diff --git a/src/drivers/xpowers/axp209/axp209.c b/src/drivers/xpowers/axp209/axp209.c
new file mode 100644
index 0000000000..68ab8a5d42
--- /dev/null
+++ b/src/drivers/xpowers/axp209/axp209.c
@@ -0,0 +1,230 @@
+/*
+ * Driver for X-Powers AXP 209 Power Management Unit
+ *
+ * Despite axp209_read/write only working on a byte at a time, there is no such
+ * limitation in the AXP209.
+ *
+ * Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
+ * Subject to the GNU GPL v2, or (at your option) any later version.
+ */
+
+#include "axp209.h"
+
+#include <device/i2c.h>
+
+/* Hide these definitions from the rest of the source, so keep them here */
+enum registers {
+ REG_POWER_STATUS = 0x00,
+ REG_POWER_MODE = 0x01,
+ REG_OTG_VBUS = 0x02,
+ REG_CHIP_ID = 0x03,
+ REG_CHIP_PWROUT_CTL = 0x12,
+ REG_DCDC2_VOLTAGE = 0x23,
+ REG_DCDC2_LDO3_CTL = 0x25,
+ REG_DCDC3_VOLTAGE = 0x27,
+ REG_LDO24_VOLTAGE = 0x28,
+ REG_LDO3_VOLTAGE = 0x29,
+ REG_VBUS_IPSOUT = 0x30,
+ REG_PWROFF_VOLTAGE = 0x31,
+ REG_SHTDWN_SETTING = 0x32,
+};
+
+/* REG_LDO24_VOLTAGE definitions */
+#define REG_LDO24_VOLTAGE_LDO2_MASK (0xf << 4)
+#define REG_LDO24_VOLTAGE_LDO2_VAL(x) ((x << 4) & REG_LDO24_VOLTAGE_LDO2_MASK)
+#define REG_LDO24_VOLTAGE_LDO4_MASK (0xf << 0)
+#define REG_LDO24_VOLTAGE_LDO4_VAL(x) ((x << 0) & REG_LDO24_VOLTAGE_LDO4_MASK)
+
+/*
+ * Read and write accessors. We only work on one register at a time, but there
+ * is no limitation on the AXP209 as to how many registers we may read or write
+ * in one transaction.
+ * These return the number of bytes read/written, or an error code. In this
+ * case, they return 1 on success, or an error code otherwise.
+ */
+static int axp209_read(u8 bus, u8 reg, u8 *val)
+{
+ return i2c_read(bus, AXP209_I2C_ADDR, reg, 1, val, 1);
+}
+
+static int axp209_write(u8 bus, u8 reg, u8 val)
+{
+ return i2c_write(bus, AXP209_I2C_ADDR, reg, 1, &val, 1);
+}
+
+/**
+ * \brief Identify and initialize an AXP209 on the I²C bus
+ *
+ * @param[in] bus I²C bus to which the AXP209 is connected
+ * @return CB_SUCCES on if an AXP209 is found, or an error code otherwise.
+ */
+enum cb_err axp209_init(u8 bus)
+{
+ u8 id;
+
+ if (axp209_read(bus, REG_CHIP_ID, &id) != 1)
+ return CB_ERR;
+
+ /* From U-Boot code : Low 4 bits is chip version */
+ if ((id & 0x0f) != 0x1)
+ return CB_ERR;
+
+ return CB_SUCCESS;
+}
+
+/**
+ * \brief Configure the output voltage of DC-DC2 converter
+ *
+ * If the requested voltage is not available, the next lowest voltage will
+ * be applied.
+ * Valid values are between 700mV and 2275mV
+ *
+ * @param[in] millivolts voltage in mV units.
+ * @param[in] bus I²C bus to which the AXP209 is connected
+ * @return CB_SUCCES on success,
+ * CB_ERR_ARG if voltage is out of range, or an error code otherwise.
+ */
+enum cb_err axp209_set_dcdc2_voltage(u8 bus, u16 millivolts)
+{
+ u8 val;
+
+ if (millivolts < 700 || millivolts > 2275)
+ return CB_ERR_ARG;
+
+ val = (millivolts - 700) / 25;
+
+ if (axp209_write(bus, REG_DCDC2_VOLTAGE, val) != 1)
+ return CB_ERR;
+
+ return CB_SUCCESS;
+}
+
+/**
+ * \brief Configure the output voltage of DC-DC3 converter
+ *
+ * If the requested voltage is not available, the next lowest voltage will
+ * be applied.
+ * Valid values are between 700mV and 3500mV
+ *
+ * @param[in] millivolts voltage in mV units.
+ * @param[in] bus I²C bus to which the AXP209 is connected
+ * @return CB_SUCCES on success,
+ * CB_ERR_ARG if voltage is out of range, or an error code otherwise.
+ */
+enum cb_err axp209_set_dcdc3_voltage(u8 bus, u16 millivolts)
+{
+ u8 val;
+
+ if (millivolts < 700 || millivolts > 3500)
+ return CB_ERR_ARG;
+
+ val = (millivolts - 700) / 25;
+
+ if (axp209_write(bus, REG_DCDC3_VOLTAGE, val) != 1)
+ return CB_ERR;
+
+ return CB_SUCCESS;
+}
+
+/**
+ * \brief Configure the output voltage of LDO2 regulator
+ *
+ * If the requested voltage is not available, the next lowest voltage will
+ * be applied.
+ * Valid values are between 700mV and 3300mV
+ *
+ * @param[in] millivolts voltage in mV units.
+ * @param[in] bus I²C bus to which the AXP209 is connected
+ * @return CB_SUCCES on success,
+ * CB_ERR_ARG if voltage is out of range, or an error code otherwise.
+ */
+enum cb_err axp209_set_ldo2_voltage(u8 bus, u16 millivolts)
+{
+ u8 reg8, val;
+
+ if (millivolts < 1800 || millivolts > 3300)
+ return CB_ERR_ARG;
+
+ /* Try to read the register first, and stop here on error */
+ if (axp209_read(bus, REG_LDO24_VOLTAGE, &reg8) != 1)
+ return CB_ERR;
+
+ val = (millivolts - 1800) / 100;
+ reg8 &= ~REG_LDO24_VOLTAGE_LDO2_MASK;
+ reg8 |= REG_LDO24_VOLTAGE_LDO2_VAL(val);
+
+ if (axp209_write(bus, REG_LDO24_VOLTAGE, reg8) != 1)
+ return CB_ERR;
+
+ return CB_SUCCESS;
+}
+
+/**
+ * \brief Configure the output voltage of LDO4 regulator
+ *
+ * If the requested voltage is not available, the next lowest voltage will
+ * be applied.
+ * Valid values are between 700mV and 3500mV. Datasheet lists maximum voltage at
+ * 2250mV, but hardware samples go as high as 3500mV.
+ *
+ * @param[in] millivolts voltage in mV units.
+ * @param[in] bus I²C bus to which the AXP209 is connected
+ * @return CB_SUCCES on success,
+ * CB_ERR_ARG if voltage is out of range, or an error code otherwise.
+ */
+enum cb_err axp209_set_ldo3_voltage(u8 bus, u16 millivolts)
+{
+ u8 val;
+
+ /* Datasheet lists 2250 max, but PMU will output up to 3500mV */
+ if (millivolts < 700 || millivolts > 3500)
+ return CB_ERR_ARG;
+
+ val = (millivolts - 700) / 25;
+
+ if (axp209_write(bus, REG_LDO3_VOLTAGE, val) != 1)
+ return CB_ERR;
+
+ return CB_SUCCESS;
+}
+
+/**
+ * \brief Configure the output voltage of DC-DC2 converter
+ *
+ * If the requested voltage is not available, the next lowest voltage will
+ * be applied.
+ * Valid values are between 1250V and 3300mV
+ *
+ * @param[in] millivolts voltage in mV units.
+ * @param[in] bus I²C bus to which the AXP209 is connected
+ * @return CB_SUCCES on success,
+ * CB_ERR_ARG if voltage is out of range, or an error code otherwise.
+ */
+enum cb_err axp209_set_ldo4_voltage(u8 bus, u16 millivolts)
+{
+ u8 reg8, val;
+
+ if (millivolts < 1250 || millivolts > 3300)
+ return CB_ERR_ARG;
+
+ /* Try to read the register first, and stop here on error */
+ if (axp209_read(bus, REG_LDO24_VOLTAGE, &reg8) != 1)
+ return CB_ERR;
+
+ if (millivolts <= 2000)
+ val = (millivolts - 1200) / 100;
+ else if (millivolts <= 2700)
+ val = 9 + (millivolts - 2500) / 100;
+ else if (millivolts <= 2800)
+ val = 11;
+ else
+ val = 12 + (millivolts - 3000) / 100;
+
+ reg8 &= ~REG_LDO24_VOLTAGE_LDO4_MASK;
+ reg8 |= REG_LDO24_VOLTAGE_LDO4_VAL(val);
+
+ if (axp209_write(bus, REG_LDO24_VOLTAGE, reg8) != 1)
+ return CB_ERR;
+
+ return CB_SUCCESS;
+}
diff --git a/src/drivers/xpowers/axp209/axp209.h b/src/drivers/xpowers/axp209/axp209.h
new file mode 100644
index 0000000000..1d369f590c
--- /dev/null
+++ b/src/drivers/xpowers/axp209/axp209.h
@@ -0,0 +1,17 @@
+/*
+ * Definitions for X-Powers AXP 209 Power Management Unit
+ *
+ * Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
+ * Subject to the GNU GPL v2, or (at your option) any later version.
+ */
+
+#include <types.h>
+
+#define AXP209_I2C_ADDR (0x68 >> 1)
+
+enum cb_err axp209_init(u8 bus);
+enum cb_err axp209_set_dcdc2_voltage(u8 bus, u16 millivolts);
+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);