]> git.sur5r.net Git - u-boot/commitdiff
board: sunxi: Use generic-phy for board_usb_cable_connected
authorJagan Teki <jagan@amarulasolutions.com>
Mon, 7 May 2018 07:33:36 +0000 (13:03 +0530)
committerJagan Teki <jagan@amarulasolutions.com>
Mon, 28 May 2018 11:10:43 +0000 (16:40 +0530)
Allwinner PHY USB code is now part of generic-phy framework,
so use it in board_usb_cable_connected.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
Acked-by: Jun Nie <jun.nie@linaro.org>
board/sunxi/board.c

index 3d364c6db58fbf9290b711243c4645e7f17d2dca..8208989adf2f3da510e194a571c0c0c8c08baf35 100644 (file)
  */
 
 #include <common.h>
+#include <dm.h>
 #include <mmc.h>
 #include <axp_pmic.h>
+#include <generic-phy.h>
+#include <phy-sun4i-usb.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/display.h>
@@ -595,7 +598,35 @@ void sunxi_board_init(void)
 #ifdef CONFIG_USB_GADGET
 int g_dnl_board_usb_cable_connected(void)
 {
-       return sunxi_usb_phy_vbus_detect(0);
+       struct udevice *dev;
+       struct phy phy;
+       int ret;
+
+       ret = uclass_get_device(UCLASS_USB_DEV_GENERIC, 0, &dev);
+       if (ret) {
+               pr_err("%s: Cannot find USB device\n", __func__);
+               return ret;
+       }
+
+       ret = generic_phy_get_by_name(dev, "usb", &phy);
+       if (ret) {
+               pr_err("failed to get %s USB PHY\n", dev->name);
+               return ret;
+       }
+
+       ret = generic_phy_init(&phy);
+       if (ret) {
+               pr_err("failed to init %s USB PHY\n", dev->name);
+               return ret;
+       }
+
+       ret = sun4i_usb_phy_vbus_detect(&phy);
+       if (ret == 1) {
+               pr_err("A charger is plugged into the OTG\n");
+               return -ENODEV;
+       }
+
+       return ret;
 }
 #endif