]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
sunxi: Add axp152 pmic support
authorHans de Goede <hdegoede@redhat.com>
Fri, 13 Jun 2014 20:55:51 +0000 (22:55 +0200)
committerIan Campbell <ijc@hellion.org.uk>
Fri, 18 Jul 2014 18:42:16 +0000 (19:42 +0100)
Add support for the x-powers axp152 pmic which is found on most A10s boards
and enable it for the r7-tv-dongle board.

Signed-off-by: Henrik Nordstrom <henrik@henriknordstrom.net>
Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
board/sunxi/board.c
boards.cfg
drivers/power/Makefile
drivers/power/axp152.c [new file with mode: 0644]
include/axp152.h [new file with mode: 0644]

index 8375711d1ef0ed4be5d2e037b5f4524d43644bff..8607eb3aa30d327e8d7c2648562bdc3d3f54e602 100644 (file)
@@ -12,6 +12,9 @@
  */
 
 #include <common.h>
+#ifdef CONFIG_AXP152_POWER
+#include <axp152.h>
+#endif
 #ifdef CONFIG_AXP209_POWER
 #include <axp209.h>
 #endif
@@ -122,6 +125,13 @@ void sunxi_board_init(void)
        int power_failed = 0;
        unsigned long ramsize;
 
+#ifdef CONFIG_AXP152_POWER
+       power_failed = axp152_init();
+       power_failed |= axp152_set_dcdc2(1400);
+       power_failed |= axp152_set_dcdc3(1500);
+       power_failed |= axp152_set_dcdc4(1250);
+       power_failed |= axp152_set_ldo2(3000);
+#endif
 #ifdef CONFIG_AXP209_POWER
        power_failed |= axp209_init();
        power_failed |= axp209_set_dcdc2(1400);
index 8e6afe7876f1d45f7bb425bdd3fb205fa4e0d89a..58873b6fa021b462354eec17b1d23624d141b0a2 100644 (file)
@@ -381,7 +381,7 @@ Active  arm         armv7          sunxi       -               sunxi
 Active  arm         armv7          sunxi       -               sunxi               Cubieboard                            sun4i:CUBIEBOARD,SPL,AXP209_POWER,SUNXI_EMAC                                                                                      Hans de Goede <hdegoede@redhat.com>
 Active  arm         armv7          sunxi       -               sunxi               Cubietruck                            sun7i:CUBIETRUCK,SPL,AXP209_POWER,SUNXI_GMAC,RGMII                                                                                Ian Campbell <ijc@hellion.org.uk>:Hans de Goede <hdegoede@redhat.com>
 Active  arm         armv7          sunxi       -               sunxi               Cubietruck_FEL                        sun7i:CUBIETRUCK,SPL_FEL,AXP209_POWER,SUNXI_GMAC,RGMII                                                                            Ian Campbell <ijc@hellion.org.uk>:Hans de Goede <hdegoede@redhat.com>
-Active  arm         armv7          sunxi       -               sunxi               r7-tv-dongle                          sun5i:R7DONGLE,SPL                                                                                                                Hans de Goede <hdegoede@redhat.com>
+Active  arm         armv7          sunxi       -               sunxi               r7-tv-dongle                          sun5i:R7DONGLE,SPL,AXP152_POWER                                                                                                   Hans de Goede <hdegoede@redhat.com>
 Active  arm         armv7          u8500       st-ericsson     snowball            snowball                              -                                                                                                                                 Mathieu Poirier <mathieu.poirier@linaro.org>
 Active  arm         armv7          u8500       st-ericsson     u8500               u8500_href                            -                                                                                                                                 -
 Active  arm         armv7          vf610       freescale       vf610twr            vf610twr                              vf610twr:IMX_CONFIG=board/freescale/vf610twr/imximage.cfg                                                                         Alison Wang <b18965@freescale.com>
index 063ac8f9d6f5b65e84fee9e1ec7788d1084a4a55..dc64e4d32bffb6d56e679620e229caa1f9f14909 100644 (file)
@@ -5,6 +5,7 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
+obj-$(CONFIG_AXP152_POWER)     += axp152.o
 obj-$(CONFIG_AXP209_POWER)     += axp209.o
 obj-$(CONFIG_EXYNOS_TMU)       += exynos-tmu.o
 obj-$(CONFIG_FTPMU010_POWER)   += ftpmu010.o
diff --git a/drivers/power/axp152.c b/drivers/power/axp152.c
new file mode 100644 (file)
index 0000000..fa4ea05
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * (C) Copyright 2012
+ * Henrik Nordstrom <henrik@henriknordstrom.net>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+#include <common.h>
+#include <i2c.h>
+#include <axp152.h>
+
+enum axp152_reg {
+       AXP152_CHIP_VERSION = 0x3,
+       AXP152_DCDC2_VOLTAGE = 0x23,
+       AXP152_DCDC3_VOLTAGE = 0x27,
+       AXP152_DCDC4_VOLTAGE = 0x2B,
+       AXP152_LDO2_VOLTAGE = 0x2A,
+       AXP152_SHUTDOWN = 0x32,
+};
+
+#define AXP152_POWEROFF                        (1 << 7)
+
+static int axp152_write(enum axp152_reg reg, u8 val)
+{
+       return i2c_write(0x30, reg, 1, &val, 1);
+}
+
+static int axp152_read(enum axp152_reg reg, u8 *val)
+{
+       return i2c_read(0x30, reg, 1, val, 1);
+}
+
+static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
+{
+       if (mvolt < min)
+               mvolt = min;
+       else if (mvolt > max)
+               mvolt = max;
+
+       return (mvolt - min) / div;
+}
+
+int axp152_set_dcdc2(int mvolt)
+{
+       int rc;
+       u8 current, target;
+
+       target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
+
+       /* Do we really need to be this gentle? It has built-in voltage slope */
+       while ((rc = axp152_read(AXP152_DCDC2_VOLTAGE, &current)) == 0 &&
+              current != target) {
+               if (current < target)
+                       current++;
+               else
+                       current--;
+               rc = axp152_write(AXP152_DCDC2_VOLTAGE, current);
+               if (rc)
+                       break;
+       }
+       return rc;
+}
+
+int axp152_set_dcdc3(int mvolt)
+{
+       u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
+
+       return axp152_write(AXP152_DCDC3_VOLTAGE, target);
+}
+
+int axp152_set_dcdc4(int mvolt)
+{
+       u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
+
+       return axp152_write(AXP152_DCDC4_VOLTAGE, target);
+}
+
+int axp152_set_ldo2(int mvolt)
+{
+       u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
+
+       return axp152_write(AXP152_LDO2_VOLTAGE, target);
+}
+
+int axp152_init(void)
+{
+       u8 ver;
+       int rc;
+
+       rc = axp152_read(AXP152_CHIP_VERSION, &ver);
+       if (rc)
+               return rc;
+
+       if (ver != 0x05)
+               return -1;
+
+       return 0;
+}
diff --git a/include/axp152.h b/include/axp152.h
new file mode 100644 (file)
index 0000000..3e5ccbd
--- /dev/null
@@ -0,0 +1,10 @@
+/*
+ * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+int axp152_set_dcdc2(int mvolt);
+int axp152_set_dcdc3(int mvolt);
+int axp152_set_dcdc4(int mvolt);
+int axp152_set_ldo2(int mvolt);
+int axp152_init(void);