Alexandru Gagniuc (mr.nuke.me(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4599
-gerrit
commit da2661ffbc117be887e3946767310a2db9a1a41f
Author: Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
Date: Thu Jan 2 03:59:24 2014 -0500
cpu/allwinner/a10: Add functions for driving GPIO pins
Change-Id: I9473a6e574c3af02d154a7e30245f0dc0b238300
Signed-off-by: Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
---
src/cpu/allwinner/a10/Makefile.inc | 1 +
src/cpu/allwinner/a10/gpio.c | 98 ++++++++++++++++++++++++++++++++++++++
src/cpu/allwinner/a10/gpio.h | 8 ++++
3 files changed, 107 insertions(+)
diff --git a/src/cpu/allwinner/a10/Makefile.inc b/src/cpu/allwinner/a10/Makefile.inc
index 6865529..8e743a2 100644
--- a/src/cpu/allwinner/a10/Makefile.inc
+++ b/src/cpu/allwinner/a10/Makefile.inc
@@ -1,4 +1,5 @@
bootblock-y += clock.c
+bootblock-y += gpio.c
bootblock-y += pinmux.c
bootblock-y += bootblock_media.c
bootblock-$(CONFIG_BOOTBLOCK_CONSOLE) += uart.c
diff --git a/src/cpu/allwinner/a10/gpio.c b/src/cpu/allwinner/a10/gpio.c
new file mode 100644
index 0000000..295cdf2
--- /dev/null
+++ b/src/cpu/allwinner/a10/gpio.c
@@ -0,0 +1,98 @@
+/*
+ * Basic GPIO helpers for Allwinner CPUs
+ *
+ * Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
+ * Subject to the GNU GPL v2, or (at your option) any later version.
+ */
+
+#include "gpio.h"
+
+#include <arch/io.h>
+
+static struct a10_gpio *const gpio = (void *)GPIO_BASE;
+
+/**
+ * \brief Set a single output pin
+ *
+ * @param[in] port GPIO port of the pin (GPA -> GPS)
+ * @param[in] pin the pin number in the given port (1 -> 31)
+ */
+void gpio_set(u8 port, u8 pin)
+{
+ u32 reg32;
+
+ if ((port > GPS))
+ return;
+
+ reg32 = gpio_read(port);
+ reg32 |= (1 << pin);
+ gpio_write(port, reg32);
+}
+
+/**
+ * \brief Clear a single output pin
+ *
+ * @param[in] port GPIO port of the pin (GPA -> GPS)
+ * @param[in] pin the pin number in the given port (1 -> 31)
+ */
+void gpio_clear(u8 port, u8 pin)
+{
+ u32 reg32;
+ if ((port > GPS))
+ return;
+
+ reg32 = gpio_read(port);
+ reg32 &= ~(1 << pin);
+ gpio_write(port, reg32);
+}
+
+/**
+ * \brief Get the status of a single input pin
+ *
+ * @param[in] port GPIO port of the pin (GPA -> GPS)
+ * @param[in] pin the pin number in the given port (1 -> 31)
+ * @return 1 if the pin is high, or 0 if the pin is low
+ */
+int gpio_get(u8 port, u8 pin)
+{
+ if ((port > GPS))
+ return 0;
+
+ return (gpio_read(port) & (1 << pin)) ? 1 : 0;
+}
+
+/**
+ * \brief Write to a GPIO port
+ *
+ * Write the state of all output pins in the GPIO port. This only affects pins
+ * configured as output pins.
+ *
+ * @param[in] port GPIO port of the pin (GPA -> GPS)
+ * @param[in] value 32-bit mask indicating which pins to set. For a set bit, the
+ * corresponding pin will be set. Otherwise, it will be cleared
+ */
+void gpio_write(u8 port, u32 val)
+{
+ if ((port > GPS))
+ return;
+
+ write32(val, &gpio->port[port].dat);
+}
+
+/**
+ * \brief Write to a GPIO port
+ *
+ * Read the state of all input pins in the GPIO port.
+ *
+ * @param[in] port GPIO port of the pin (GPA -> GPS)
+ * @return 32-bit mask indicating which pins are high. For each set bit, the
+ * corresponding pin is high. The value of bits corresponding to pins
+ * which are not configured as inputs is undefined.
+ */
+u32 gpio_read(u8 port)
+{
+ if ((port > GPS))
+ return 0;
+
+ return read32(&gpio->port[port].dat);
+}
diff --git a/src/cpu/allwinner/a10/gpio.h b/src/cpu/allwinner/a10/gpio.h
index e4b24ea..b20d759 100644
--- a/src/cpu/allwinner/a10/gpio.h
+++ b/src/cpu/allwinner/a10/gpio.h
@@ -50,6 +50,14 @@ struct a10_gpio {
u32 sdr_pad_pul;
} __attribute__ ((packed));
+/* gpio.c */
+void gpio_set(u8 port, u8 pin);
+void gpio_clear(u8 port, u8 pin);
+int gpio_get(u8 port, u8 pin);
+void gpio_write(u8 port, u32 val);
+u32 gpio_read(u8 port);
+
+/* pinmux.c */
void gpio_set_pin_func(u8 port, u8 pin, u8 pad_func);
void gpio_set_multipin_func(u8 port, u32 pin_mask, u8 pad_func);
Alexandru Gagniuc (mr.nuke.me(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4591
-gerrit
commit 3c6a1087c298c2f63ab6ab19faf35d0a3d259ac0
Author: Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
Date: Mon Dec 30 01:21:55 2013 -0500
drivers: Add support for X-Powers AXP209 PMU
Change-Id: I1de0e656a38527b172af1d0b5bcd97acbfc03bf0
Signed-off-by: Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
---
src/drivers/Kconfig | 1 +
src/drivers/Makefile.inc | 1 +
src/drivers/xpowers/Kconfig | 1 +
src/drivers/xpowers/Makefile.inc | 1 +
src/drivers/xpowers/axp209/Kconfig | 15 +++
src/drivers/xpowers/axp209/Makefile.inc | 3 +
src/drivers/xpowers/axp209/axp209.c | 230 ++++++++++++++++++++++++++++++++
src/drivers/xpowers/axp209/axp209.h | 17 +++
8 files changed, 269 insertions(+)
diff --git a/src/drivers/Kconfig b/src/drivers/Kconfig
index b187419..8da7b05 100644
--- a/src/drivers/Kconfig
+++ b/src/drivers/Kconfig
@@ -37,3 +37,4 @@ source src/drivers/sil/Kconfig
source src/drivers/spi/Kconfig
source src/drivers/ti/Kconfig
source src/drivers/trident/Kconfig
+source src/drivers/xpowers/Kconfig
diff --git a/src/drivers/Makefile.inc b/src/drivers/Makefile.inc
index 7b1e4ca..34ae62e 100644
--- a/src/drivers/Makefile.inc
+++ b/src/drivers/Makefile.inc
@@ -34,4 +34,5 @@ subdirs-y += spi
subdirs-y += ti
subdirs-y += ipmi
subdirs-y += elog
+subdirs-y += xpowers
subdirs-$(CONFIG_ARCH_X86) += pc80
diff --git a/src/drivers/xpowers/Kconfig b/src/drivers/xpowers/Kconfig
new file mode 100644
index 0000000..3ac2748
--- /dev/null
+++ b/src/drivers/xpowers/Kconfig
@@ -0,0 +1 @@
+source src/drivers/xpowers/axp209/Kconfig
diff --git a/src/drivers/xpowers/Makefile.inc b/src/drivers/xpowers/Makefile.inc
new file mode 100644
index 0000000..ef6dffc
--- /dev/null
+++ b/src/drivers/xpowers/Makefile.inc
@@ -0,0 +1 @@
+subdirs-$(CONFIG_DRIVER_XPOWERS_AXP209) += axp209
diff --git a/src/drivers/xpowers/axp209/Kconfig b/src/drivers/xpowers/axp209/Kconfig
new file mode 100644
index 0000000..684873c
--- /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 0000000..5ac691e
--- /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 0000000..68ab8a5
--- /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(a)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, ®8) != 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, ®8) != 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 0000000..1d369f5
--- /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(a)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);
Vladimir Serbinenko (phcoder(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4603
-gerrit
commit 83152a7da586627ea3a84f98d63e22129c053fcd
Author: Vladimir Serbinenko <phcoder(a)gmail.com>
Date: Thu Jan 2 10:10:14 2014 +0100
nehalem: Simplify acpi.c by using __SIMPLE_DEVICE__
Change-Id: I93351a2716cd58c2006400cecca1390b1704e94b
Signed-off-by: Vladimir Serbinenko <phcoder(a)gmail.com>
---
src/northbridge/intel/nehalem/acpi.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/northbridge/intel/nehalem/acpi.c b/src/northbridge/intel/nehalem/acpi.c
index df6cc1a..e175977 100644
--- a/src/northbridge/intel/nehalem/acpi.c
+++ b/src/northbridge/intel/nehalem/acpi.c
@@ -21,6 +21,8 @@
* MA 02110-1301 USA
*/
+#define __SIMPLE_DEVICE__
+
#include <types.h>
#include <string.h>
#include <console/console.h>
@@ -38,10 +40,8 @@ unsigned long acpi_fill_mcfg(unsigned long current)
u32 pciexbar_reg;
int max_buses;
- /* Quickpath bus is not in standard coreboot device tree,
- so read register directly. */
- pciexbar_reg = read32(DEFAULT_PCIEXBAR
- | (QUICKPATH_BUS << 20) | 0x1050);
+ pciexbar_reg =
+ pci_read_config32 (PCI_DEV (QUICKPATH_BUS, 0, 1), 0x50);
// MMCFG not supported or not enabled.
if (!(pciexbar_reg & (1 << 0)))
@@ -173,7 +173,7 @@ int init_igd_opregion(igd_opregion_t * opregion)
/* TODO This needs to happen in S3 resume, too.
* Maybe it should move to the finalize handler
*/
- igd = dev_find_slot(0, PCI_DEVFN(0x2, 0));
+ igd = PCI_DEV (0, 0x2, 0);
pci_write_config32(igd, ASLS, (u32) opregion);
reg16 = pci_read_config16(igd, SWSCI);