From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jagan Teki Date: Mon, 28 May 2018 16:48:31 +0530 Subject: [U-Boot] [PATCH v10 20/35] board: sunxi: Use generic-phy for board_usb_cable_connected In-Reply-To: <20180528111846.14316-1-jagan@amarulasolutions.com> References: <20180528111846.14316-1-jagan@amarulasolutions.com> Message-ID: <20180528111846.14316-21-jagan@amarulasolutions.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Allwinner PHY USB code is now part of generic-phy framework, so use it in board_usb_cable_connected. Signed-off-by: Jagan Teki Acked-by: Jun Nie --- board/sunxi/board.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 3d364c6db5..8208989adf 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -11,8 +11,11 @@ */ #include +#include #include #include +#include +#include #include #include #include @@ -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 -- 2.14.3