]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
power: axp221: Virtual VBUS detect and enable GPIOs to replace separate logic
authorPaul Kocialkowski <contact@paulk.fr>
Sun, 22 Mar 2015 17:07:09 +0000 (18:07 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 19:47:13 +0000 (21:47 +0200)
This converts the VBUS detection and enable logic to GPIO instead of separate
axp functions and checks that have to be used aside usual GPIO functions.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
arch/arm/include/asm/arch-sunxi/gpio.h
drivers/gpio/sunxi_gpio.c
drivers/power/axp221.c
include/axp221.h

index a66e45caffa4c970a1e77ba36e4179b21881cf7b..3a4b8c3165eedefd4aa12ecc4b7211fb51da295e 100644 (file)
@@ -201,6 +201,10 @@ enum sunxi_gpio_number {
 #define SUNXI_GPIO_PULL_UP     1
 #define SUNXI_GPIO_PULL_DOWN   2
 
+/* Virtual AXP0 GPIOs */
+#define SUNXI_GPIO_AXP0_VBUS_DETECT    8
+#define SUNXI_GPIO_AXP0_VBUS_ENABLE    9
+
 void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
 void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
 int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset);
index 62960929ade9cca68185f758d482928aef0fec4f..670af0c383c5d981043873be9a9348e5613c7e6f 100644 (file)
@@ -21,6 +21,9 @@
 #ifdef CONFIG_AXP209_POWER
 #include <axp209.h>
 #endif
+#ifdef CONFIG_AXP221_POWER
+#include <axp221.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -125,6 +128,12 @@ int sunxi_name_to_gpio(const char *name)
 #ifdef AXP_GPIO
        if (strncasecmp(name, "AXP0-", 5) == 0) {
                name += 5;
+               if (strcmp(name, "VBUS-DETECT") == 0)
+                       return SUNXI_GPIO_AXP0_START +
+                               SUNXI_GPIO_AXP0_VBUS_DETECT;
+               if (strcmp(name, "VBUS-ENABLE") == 0)
+                       return SUNXI_GPIO_AXP0_START +
+                               SUNXI_GPIO_AXP0_VBUS_ENABLE;
                pin = simple_strtol(name, &eptr, 10);
                if (!*name || *eptr)
                        return -1;
index c2c3988804b5ff625a8ce817e15bccdd5193c94a..f758a75e9a6ac4604593e4ce0d34e0738cc1882f 100644 (file)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <asm/arch/p2wi.h>
 #include <asm/arch/rsb.h>
+#include <asm/arch/gpio.h>
 #include <axp221.h>
 
 /*
@@ -385,54 +386,66 @@ int axp221_get_sid(unsigned int *sid)
        return 0;
 }
 
-int axp_get_vbus(void)
+int axp_gpio_direction_input(unsigned int pin)
 {
-       int ret;
-       u8 val;
-
-       ret = axp221_init();
-       if (ret)
-               return ret;
-
-       ret = pmic_bus_read(AXP221_POWER_STATUS, &val);
-       if (ret)
-               return ret;
-
-       return (val & AXP221_POWER_STATUS_VBUS_USABLE) ? 1 : 0;
+       switch (pin) {
+       case SUNXI_GPIO_AXP0_VBUS_DETECT:
+               return 0;
+       default:
+               return -EINVAL;
+       }
 }
 
-static int axp_drivebus_setup(void)
+int axp_gpio_direction_output(unsigned int pin, unsigned int val)
 {
        int ret;
 
-       ret = axp221_init();
-       if (ret)
-               return ret;
+       switch (pin) {
+       case SUNXI_GPIO_AXP0_VBUS_ENABLE:
+               ret = axp221_clrbits(AXP221_MISC_CTRL,
+                                    AXP221_MISC_CTRL_N_VBUSEN_FUNC);
+               if (ret)
+                       return ret;
 
-       /* Set N_VBUSEN pin to output / DRIVEBUS function */
-       return axp221_clrbits(AXP221_MISC_CTRL, AXP221_MISC_CTRL_N_VBUSEN_FUNC);
+               return axp_gpio_set_value(pin, val);
+       default:
+               return -EINVAL;
+       }
 }
 
-int axp_drivebus_enable(void)
+int axp_gpio_get_value(unsigned int pin)
 {
        int ret;
+       u8 val;
 
-       ret = axp_drivebus_setup();
-       if (ret)
-               return ret;
+       switch (pin) {
+       case SUNXI_GPIO_AXP0_VBUS_DETECT:
+               ret = pmic_bus_read(AXP221_POWER_STATUS, &val);
+               if (ret)
+                       return ret;
 
-       /* Set DRIVEBUS high */
-       return axp221_setbits(AXP221_VBUS_IPSOUT, AXP221_VBUS_IPSOUT_DRIVEBUS);
+               return !!(val & AXP221_POWER_STATUS_VBUS_USABLE);
+       default:
+               return -EINVAL;
+       }
 }
 
-int axp_drivebus_disable(void)
+int axp_gpio_set_value(unsigned int pin, unsigned int val)
 {
        int ret;
 
-       ret = axp_drivebus_setup();
-       if (ret)
-               return ret;
+       switch (pin) {
+       case SUNXI_GPIO_AXP0_VBUS_ENABLE:
+               if (val)
+                       ret = axp221_setbits(AXP221_VBUS_IPSOUT,
+                                            AXP221_VBUS_IPSOUT_DRIVEBUS);
+               else
+                       ret = axp221_clrbits(AXP221_VBUS_IPSOUT,
+                                            AXP221_VBUS_IPSOUT_DRIVEBUS);
 
-       /* Set DRIVEBUS low */
-       return axp221_clrbits(AXP221_VBUS_IPSOUT, AXP221_VBUS_IPSOUT_DRIVEBUS);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
 }
index be6058e43951105c603544b84f8d3d375645150b..0aac04dfebda3f9c84462d1ddf6371bc71810d73 100644 (file)
 /* Page 1 addresses */
 #define AXP221_SID             0x20
 
-/* We support vbus detection */
-#define AXP_VBUS_DETECT
-
-/* We support drivebus control */
-#define AXP_DRIVEBUS
+#define AXP_GPIO
 
 int axp221_set_dcdc1(unsigned int mvolt);
 int axp221_set_dcdc2(unsigned int mvolt);
@@ -83,6 +79,8 @@ int axp221_set_aldo3(unsigned int mvolt);
 int axp221_set_eldo(int eldo_num, unsigned int mvolt);
 int axp221_init(void);
 int axp221_get_sid(unsigned int *sid);
-int axp_get_vbus(void);
-int axp_drivebus_enable(void);
-int axp_drivebus_disable(void);
+
+int axp_gpio_direction_input(unsigned int pin);
+int axp_gpio_direction_output(unsigned int pin, unsigned int val);
+int axp_gpio_get_value(unsigned int pin);
+int axp_gpio_set_value(unsigned int pin, unsigned int val);