From owner-svn-src-head@freebsd.org Tue Sep 26 19:20:52 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0E0A4E164FA; Tue, 26 Sep 2017 19:20:52 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D1D507274D; Tue, 26 Sep 2017 19:20:51 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8QJKpb9006141; Tue, 26 Sep 2017 19:20:51 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8QJKp9M006140; Tue, 26 Sep 2017 19:20:51 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201709261920.v8QJKp9M006140@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Tue, 26 Sep 2017 19:20:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324021 - head/sys/arm/allwinner X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/arm/allwinner X-SVN-Commit-Revision: 324021 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2017 19:20:52 -0000 Author: manu Date: Tue Sep 26 19:20:50 2017 New Revision: 324021 URL: https://svnweb.freebsd.org/changeset/base/324021 Log: aw_usbphy: Only reroute OTG for phy0 We only need to route OTG port to host mode on phy0 and if no VBUS is present on the port, otherwise leave the port in periperal mode. Modified: head/sys/arm/allwinner/aw_usbphy.c Modified: head/sys/arm/allwinner/aw_usbphy.c ============================================================================== --- head/sys/arm/allwinner/aw_usbphy.c Tue Sep 26 19:19:44 2017 (r324020) +++ head/sys/arm/allwinner/aw_usbphy.c Tue Sep 26 19:20:50 2017 (r324021) @@ -160,13 +160,6 @@ awusbphy_configure(device_t dev, int phyno) if (sc->phy_conf->pmu_unk1 == true) CLR4(sc->pmu[phyno], PMU_UNK_H3, PMU_UNK_H3_CLR); - if (sc->phy_conf->phy0_route == true) { - if (phyno == 0) - SET4(sc->phy_ctrl, OTG_PHY_CFG, OTG_PHY_ROUTE_OTG); - else - CLR4(sc->phy_ctrl, OTG_PHY_CFG, OTG_PHY_ROUTE_OTG); - } - SET4(sc->pmu[phyno], PMU_IRQ_ENABLE, PMU_ULPI_BYPASS | PMU_AHB_INCR8 | PMU_AHB_INCR4 | PMU_AHB_INCRX_ALIGN); } @@ -266,8 +259,11 @@ awusbphy_vbus_detect(device_t dev, int *val) if (sc->vbus_det_valid) { error = gpio_pin_is_active(sc->vbus_det_pin, &active); - if (error != 0) + if (error != 0) { + device_printf(dev, "Cannot get status of id pin %d\n", + error); return (error); + } *val = active; return (0); } @@ -300,7 +296,21 @@ awusbphy_phy_enable(device_t dev, intptr_t phy, bool e /* If an external vbus is detected, do not enable phy 0 */ if (phy == 0) { error = awusbphy_vbus_detect(dev, &vbus_det); - if (error == 0 && vbus_det == 1) + if (error) + goto out; + + /* Depending on the PHY we need to route OTG to OHCI/EHCI */ + if (sc->phy_conf->phy0_route == true) { + if (vbus_det == 0) + /* Host mode */ + CLR4(sc->phy_ctrl, OTG_PHY_CFG, + OTG_PHY_ROUTE_OTG); + else + /* Peripheral mode */ + SET4(sc->phy_ctrl, OTG_PHY_CFG, + OTG_PHY_ROUTE_OTG); + } + if (vbus_det == 1) return (0); } else error = 0; @@ -308,6 +318,8 @@ awusbphy_phy_enable(device_t dev, intptr_t phy, bool e error = regulator_enable(reg); } else error = regulator_disable(reg); + +out: if (error != 0) { device_printf(dev, "couldn't %s regulator for phy %jd\n",