From patchwork Wed Sep 7 06:25:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 666825 X-Patchwork-Delegate: hdegoede@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3sTYRy0kMxz9s4n for ; Wed, 7 Sep 2016 16:27:58 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 08134A75E5; Wed, 7 Sep 2016 08:27:54 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aNfysVWw23or; Wed, 7 Sep 2016 08:27:53 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1E8114B71E; Wed, 7 Sep 2016 08:27:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1AD3AA75D1 for ; Wed, 7 Sep 2016 08:25:41 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RjGLiMr_qeXx for ; Wed, 7 Sep 2016 08:25:37 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from wens.csie.org (mirror2.csie.ntu.edu.tw [140.112.30.76]) by theia.denx.de (Postfix) with ESMTPS id 2FBCEA75CE for ; Wed, 7 Sep 2016 08:25:28 +0200 (CEST) Received: by wens.csie.org (Postfix, from userid 1000) id EE36D5F8FE; Wed, 7 Sep 2016 14:25:21 +0800 (CST) From: Chen-Yu Tsai To: u-boot@lists.denx.de Date: Wed, 7 Sep 2016 14:25:21 +0800 Message-Id: <20160907062521.23056-1-wens@csie.org> X-Mailer: git-send-email 2.9.3 Cc: Ian Campbell Subject: [U-Boot] [PATCH] sunxi: musb: Power off OTG port VBUS when disabled X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The Linux kernel musb driver expects VBUS to be off while initializing musb. Having it on results in a repeating string of warnings, followed by an unusable peripheral. The peripheral is only usable after physically removing the OTG adapter, letting musb reset its state. This partially reverts commit c9f8947e6604 ("sunxi: usb-phy: Never power off the usb ports") Signed-off-by: Chen-Yu Tsai Reviewed-by: Hans de Goede --- arch/arm/include/asm/arch-sunxi/usb_phy.h | 1 - arch/arm/mach-sunxi/usb_phy.c | 7 ------- drivers/usb/musb-new/sunxi.c | 28 ++++++++++++---------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/arch/arm/include/asm/arch-sunxi/usb_phy.h b/arch/arm/include/asm/arch-sunxi/usb_phy.h index 6a14cad3ff39..cef6c985bc8d 100644 --- a/arch/arm/include/asm/arch-sunxi/usb_phy.h +++ b/arch/arm/include/asm/arch-sunxi/usb_phy.h @@ -16,7 +16,6 @@ void sunxi_usb_phy_init(int index); void sunxi_usb_phy_exit(int index); void sunxi_usb_phy_power_on(int index); void sunxi_usb_phy_power_off(int index); -int sunxi_usb_phy_power_is_on(int index); int sunxi_usb_phy_vbus_detect(int index); int sunxi_usb_phy_id_detect(int index); void sunxi_usb_phy_enable_squelch_detect(int index, int enable); diff --git a/arch/arm/mach-sunxi/usb_phy.c b/arch/arm/mach-sunxi/usb_phy.c index f9993d287551..bd1bbee410ba 100644 --- a/arch/arm/mach-sunxi/usb_phy.c +++ b/arch/arm/mach-sunxi/usb_phy.c @@ -296,13 +296,6 @@ void sunxi_usb_phy_power_off(int index) gpio_set_value(phy->gpio_vbus, 0); } -int sunxi_usb_phy_power_is_on(int index) -{ - struct sunxi_usb_phy *phy = &sunxi_usb_phy[index]; - - return phy->power_on_count > 0; -} - int sunxi_usb_phy_vbus_detect(int index) { struct sunxi_usb_phy *phy = &sunxi_usb_phy[index]; diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c index c016a0bb544d..dece7818dc3a 100644 --- a/drivers/usb/musb-new/sunxi.c +++ b/drivers/usb/musb-new/sunxi.c @@ -205,6 +205,8 @@ static struct musb *sunxi_musb; static int sunxi_musb_enable(struct musb *musb) { + int ret; + pr_debug("%s():\n", __func__); musb_ep_select(musb->mregs, 0); @@ -217,26 +219,17 @@ static int sunxi_musb_enable(struct musb *musb) musb_writeb(musb->mregs, USBC_REG_o_VEND0, 0); if (is_host_enabled(musb)) { - int id = sunxi_usb_phy_id_detect(0); - - if (id == 1 && sunxi_usb_phy_power_is_on(0)) - sunxi_usb_phy_power_off(0); - - if (!sunxi_usb_phy_power_is_on(0)) { - int vbus = sunxi_usb_phy_vbus_detect(0); - if (vbus == 1) { - printf("A charger is plugged into the OTG: "); - return -ENODEV; - } + ret = sunxi_usb_phy_vbus_detect(0); + if (ret == 1) { + printf("A charger is plugged into the OTG: "); + return -ENODEV; } - - if (id == 1) { + ret = sunxi_usb_phy_id_detect(0); + if (ret == 1) { printf("No host cable detected: "); return -ENODEV; } - - if (!sunxi_usb_phy_power_is_on(0)) - sunxi_usb_phy_power_on(0); + sunxi_usb_phy_power_on(0); /* port power on */ } USBC_ForceVbusValidToHigh(musb->mregs); @@ -252,6 +245,9 @@ static void sunxi_musb_disable(struct musb *musb) if (!enabled) return; + if (is_host_enabled(musb)) + sunxi_usb_phy_power_off(0); /* port power off */ + USBC_ForceVbusValidToLow(musb->mregs); mdelay(200); /* Wait for the current session to timeout */