]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
sunxi: axp221: Add VBUS detection support
authorChen-Yu Tsai <wens@csie.org>
Mon, 9 Mar 2015 07:44:15 +0000 (15:44 +0800)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 1 Sep 2015 12:28:32 +0000 (14:28 +0200)
Some of the AXP PMICs support VBUS detection, i.e. checking whether
VBUS power input is available and usable (supplied by an external
source). A few boards use this instead of a separate GPIO to detect
VBUS on USB OTG.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/power/axp221.c
include/axp221.h

index 3e07f23c20c621ba9cbfc101d788462aed93026d..c2c3988804b5ff625a8ce817e15bccdd5193c94a 100644 (file)
@@ -385,6 +385,22 @@ int axp221_get_sid(unsigned int *sid)
        return 0;
 }
 
+int axp_get_vbus(void)
+{
+       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;
+}
+
 static int axp_drivebus_setup(void)
 {
        int ret;
index a20e25c2f82740249c9333a7d49657d55ea2550c..be6058e43951105c603544b84f8d3d375645150b 100644 (file)
@@ -14,6 +14,9 @@
 #define AXP223_RUNTIME_ADDR 0x2d
 
 /* Page 0 addresses */
+#define AXP221_POWER_STATUS    0x00
+#define AXP221_POWER_STATUS_VBUS_AVAIL (1 << 5)
+#define AXP221_POWER_STATUS_VBUS_USABLE        (1 << 4)
 #define AXP221_CHIP_ID         0x03
 #define AXP221_OUTPUT_CTRL1    0x10
 #define AXP221_OUTPUT_CTRL1_DCDC0_EN   (1 << 0)
@@ -59,6 +62,9 @@
 /* Page 1 addresses */
 #define AXP221_SID             0x20
 
+/* We support vbus detection */
+#define AXP_VBUS_DETECT
+
 /* We support drivebus control */
 #define AXP_DRIVEBUS
 
@@ -77,5 +83,6 @@ 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);