]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
sunxi: musb: Check Vbus-det before enabling otg port power
authorHans de Goede <hdegoede@redhat.com>
Mon, 16 Feb 2015 21:13:43 +0000 (22:13 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 1 Sep 2015 11:53:55 +0000 (13:53 +0200)
Sending out 5V when there is a charger connected to the otg port is not a
good idea, so check for this and error out.

Note this commit currently breaks otg support on the q8h tablets, as we need
to do some magic with the pmic there to get vbus info, this is deliberate
(better safe then sorry), fixing this is on my TODO list.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
board/sunxi/Kconfig
configs/Ampe_A76_defconfig
configs/Chuwi_V7_CW0825_defconfig
configs/Hyundai_A7HD_defconfig
configs/Inet_86VS_defconfig
configs/TZX-Q8-713B7_defconfig
drivers/usb/musb-new/sunxi.c

index f5471a14c58b8c802f36b9794c9be716406ac533..9cf54e51ac9d41728955720ba4c64dbae72c7122 100644 (file)
@@ -223,6 +223,14 @@ config USB0_VBUS_PIN
        Set the Vbus enable pin for usb0 (otg). This takes a string in the
        format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
 
+config USB0_VBUS_DET
+       string "Vbus detect pin for usb0 (otg)"
+       depends on USB_MUSB_SUNXI
+       default ""
+       ---help---
+       Set the Vbus detect pin for usb0 (otg). This takes a string in the
+       format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
+
 config USB1_VBUS_PIN
        string "Vbus enable pin for usb1 (ehci0)"
        default "PH6" if MACH_SUN4I || MACH_SUN7I
index 2054fc3c9643cc1ddffabc5a11b2c79c416e5745..f8ceb6cea61596bbd8bbb90aa71f5b92031d0666 100644 (file)
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,AXP209_POWER"
 CONFIG_FDTFILE="sun5i-a13-ampe-a76.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PG12"
+CONFIG_USB0_VBUS_DET="PG01"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:45,ri:82,up:22,lo:22,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="AXP0-0"
 CONFIG_VIDEO_LCD_BL_EN="AXP0-1"
index 680b6317df723260cb11a6052868390f86028314..1ef23e4f16b8fef98cbd1ec734f695f35a40e648 100644 (file)
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER"
 CONFIG_FDTFILE="sun4i-a10-chuwi-v7-cw0825.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PB9"
+CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_VIDEO_LCD_MODE="x:1024,y:768,depth:24,pclk_khz:51000,le:19,ri:300,up:6,lo:31,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="PH8"
 CONFIG_VIDEO_LCD_BL_EN="PH7"
index 204640ee24e3964fe5b9b5c768ab3964d0e4aa53..6b784e2408d2d8c535670964177a5d82d95c63cd 100644 (file)
@@ -6,6 +6,7 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER"
 CONFIG_FDTFILE="sun4i-a10-hyundai-a7hd.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PB09"
+CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_USB1_VBUS_PIN=""
 CONFIG_USB2_VBUS_PIN="PH6"
 CONFIG_VIDEO_LCD_MODE="x:1024,y:600,depth:18,pclk_khz:51000,le:45,ri:274,up:22,lo:12,hs:1,vs:1,sync:3,vmode:0"
index ce9985affeabaf6dfd77d226fef445e790cf15b1..50c073a2e5f47d4a965eef964fe393ce4f991581 100644 (file)
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER"
 CONFIG_FDTFILE="sun5i-a13-inet-86vs.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PG12"
+CONFIG_USB0_VBUS_DET="PG1"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:45,ri:209,up:22,lo:22,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="AXP0-0"
 CONFIG_VIDEO_LCD_BL_EN="AXP0-1"
index 7b7b9ddf8e64ed7c7550143c36b0d15e232debf2..c22286abe958a663c6aba6e66cfdccabfb0edfec 100644 (file)
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,AXP209_POWER"
 CONFIG_FDTFILE="sun5i-a13-tzx-q8-713b7.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PG12"
+CONFIG_USB0_VBUS_DET="PG1"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="AXP0-0"
 CONFIG_VIDEO_LCD_BL_EN="AXP0-1"
index 4646a3d9fe673b95bff45cbfaca6e9818893c68d..fe45db1e064fc1e5398e5ea824e612531eee40f8 100644 (file)
@@ -22,7 +22,9 @@
  */
 #include <common.h>
 #include <asm/arch/cpu.h>
+#include <asm/arch/gpio.h>
 #include <asm/arch/usbc.h>
+#include <asm-generic/gpio.h>
 #include "linux-compat.h"
 #include "musb_core.h"
 
@@ -224,6 +226,33 @@ static int sunxi_musb_init(struct musb *musb)
 
        pr_debug("%s():\n", __func__);
 
+       if (is_host_enabled(musb)) {
+               int vbus_det = sunxi_name_to_gpio(CONFIG_USB0_VBUS_DET);
+               if (vbus_det == -1) {
+                       eprintf("Error invalid Vusb-det pin\n");
+                       return -EINVAL;
+               }
+
+               err = gpio_request(vbus_det, "vbus0_det");
+               if (err)
+                       return err;
+
+               err = gpio_direction_input(vbus_det);
+               if (err) {
+                       gpio_free(vbus_det);
+                       return err;
+               }
+
+               err = gpio_get_value(vbus_det);
+               if (err) {
+                       eprintf("Error: A charger is plugged into the OTG\n");
+                       gpio_free(vbus_det);
+                       return -EIO;
+               }
+
+               gpio_free(vbus_det);
+       }
+
        err = sunxi_usbc_request_resources(0);
        if (err)
                return err;