From patchwork Sun Feb 11 21:06:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 871803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.b="i/5XZCYi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zfhGl5nHwz9t2l for ; Mon, 12 Feb 2018 08:08:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932259AbeBKVIN (ORCPT ); Sun, 11 Feb 2018 16:08:13 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:56285 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932199AbeBKVIL (ORCPT ); Sun, 11 Feb 2018 16:08:11 -0500 Received: by mail-wm0-f65.google.com with SMTP id 143so6256785wma.5; Sun, 11 Feb 2018 13:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=L0jkaI2kCZMjjmm/Nw3lKAV9myKCOHJSnpwcIJwcCM8=; b=i/5XZCYiH8UIgdVVN6ym6kJ2ESU33fH530xKeKj5AD2qefv+yrd3qRKHI08iIkUIeK l+Tr4P3nxZAN9Iy++FNFYRMXMtpwteNoZ8cV4G0TF82A5aQSej0IyzJQqrWifFJT0OEN XuENDzKafhHor6E5nqI+huNNhq4bNWQE+QB1SUx/oDtA5Gb5Xz4mhSnjx/fdY+c+B+In KlyCEIJPS+7tJv6PrHZWVKcH5ZpS9gyLd04LxQprmj8NNFW674vbv8J9jnPBaSelhz8i M8J3MaMCXMpgRybCfm2Y7pHqIxRfYGpem8UyA8mgDEFq1qtcg40x7zNhcIaRC0RHXGrT RP5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=L0jkaI2kCZMjjmm/Nw3lKAV9myKCOHJSnpwcIJwcCM8=; b=Y1PDsQg5cfVyET4y1oICY4aCi6q0hQwI7Ztz2kghacmd3c79IeHZpMbNGKLs12Dqs4 Ntim/MFdnlU5ToBKvqlB4hBgX4jPE4Qitz9nusFOqY4NdBy1+A0meaIUzUG0OS4Wk2OG 7Cqt4LIQqIIh7qF9kY4tMdkOnXKqi1bKe4beNYPezBnnf9CDTHa8g8DkhD/1rauYEtth L3+mS1Cnwnk8k/bTRXppkrqDxp9vO9fTuBUbA9LMHqHqmdeaixBVxL+5XPzu5t4pHBtS e3ur1cHhshzv3BLkGyJE9FbX1SSluiiDtj5EtuiAnbYxm9T+C0qELunVvNk4mqOffg81 9H/g== X-Gm-Message-State: APf1xPCswACFcU968ahYWaY9ms6py+r5/8Q6jkqykEWB8oHDWMdFIU8a rvLRQh7l7gemoRkATESGhrqeISVK X-Google-Smtp-Source: AH8x225+ttYUss5U8i709FrKNwxdVrRMuBS69nRz+cwaaz5LcfzIuFt6HKTrFXcZ01iR18sNl5cW7w== X-Received: by 10.28.0.207 with SMTP id 198mr1905577wma.115.1518383288626; Sun, 11 Feb 2018 13:08:08 -0800 (PST) Received: from blackbox.darklights.net (p5B056154.dip0.t-ipconnect.de. [91.5.97.84]) by smtp.googlemail.com with ESMTPSA id k13sm6301773wrd.61.2018.02.11.13.08.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Feb 2018 13:08:07 -0800 (PST) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, mathias.nyman@intel.com, arnd@arndb.de, gregkh@linuxfoundation.org, felipe.balbi@linux.intel.com Cc: linux-omap@vger.kernel.org, linux-tegra@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, jonathanh@nvidia.com, thierry.reding@gmail.com, stern@rowland.harvard.edu, linux@prisktech.co.nz, Peter.Chen@nxp.com, matthias.bgg@gmail.com, mark.rutland@arm.com, robh+dt@kernel.org, narmstrong@baylibre.com, linux-amlogic@lists.infradead.org, yixun.lan@amlogic.com, Martin Blumenstingl Subject: [PATCH usb-next v9 0/8] initialize (multiple) PHYs for a HCD Date: Sun, 11 Feb 2018 22:06:43 +0100 Message-Id: <20180211210651.2046-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.1 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The goal of this series is to initialize multiple PHYs on a USB host controller, which is needed on Amlogic Meson GXL and GXM SoCs. - Amlogic Meson GXL and GXM SoCs come with a dwc3 IP block which has two or three USB2 ports enabled on the internal root-hub. The SoCs also provide separate USB2 PHYs, one per port. All USB2 PHYs (which are internally "connected" to the dwc3 roothub) need to be powered on, otherwise USB devices cannot be enumerated (even if just one PHY is disabled and if the device is plugged into another, enabled port) - dwc3 already takes one USB2 and one USB3 PHY and initializes these correctly - some other HCI platform drivers (like ehci-platform.c, xhci-mtk.c and ohci-platform.c) do not have a limitation on the number of PHYs - they support any number of USB PHYs (typically one PHY per actual port) This series adds a new "PHY wrapper". This can be configured through devicetree by passing a "phys" property (with any number of PHY handles) to the USB controller. Additionally it this integrates this new PHY wrapper into hcd.c which automatically enables it for all USB controller drivers (tested on an Amlogic Meson GXL SoC which uses a dwc3 controller). Since this leaves some duplicate code (which now becomes obsolete!) in various drivers this is being cleaned up as well. Changes since v8 at [10]: - add new patch #2 which allows disabling "USB PHY management" in the USB HCD core driver. this also affects patch #4 which now checks the skip_phy_initialization flag before calling usb_phy_roothub_{init,power_on} (other functions don't need to be guarded since they are null-safe - see patch #3) - integrated my other series 'remove driver-specific "multiple PHY" handling' from [11] into this one so the result of this "generic" code (= removing duplicate code in various drivers) can be seen directly. affects patches #5-8. (note: patch #1 "usb: mtu3: remove custom USB PHY handling" from that series was dropped, because it broke device mode support - Chunfeng Yun will come up with a separate patch later. patch #5 "usb: chipidea: do not set the "phy" field in struct usb_hcd" from that series was rewritten and is now integrated into the new patch #2 from this series) - collected all {Reviewed,Tested,Acked}-by - dropped RfC prefix since this v8 was out for review for two weeks and it only got Reviewed-by's and Tested-by's since then Changes since v7 at [8]: - updated the description in the cover-letter - wrapped the only call usb_phy_roothub_power_{on,off} in hcd_bus_{resume,suspend} during system-suspend (excluding it from being called during runtime/auto suspend). this also fixes a problem on Meson GXL which does not detect that a new device has been connected if the PHYs are powered off. Thanks to Manu Gautam for suggesting this! (affects patch #3) - after a discussion about the dt-bindings of this patch I went back to simply specifying a "phys" property (without a corresponding phy-names property) to pass all PHYs directly in the node of the USB controller. From my understanding the root hub node was "artificial" and we should describe it's properties as part of the controller, rather than introducing a sub-node. see also the discussion with Arnd in [9] (this affects patch #1 and #2) - dropped patch #4 ("dt-bindings: usb: xhci: include the roothub and a device in the example") because we're back to just specifying a "phys" property directly within the controller. NOTE: some HCI platform drivers are using the "phys" property as well. With this series phy_{init,power_on,power_off,exit} will be called twice for each PHY when using a ehci-platform.c or xhci-mtk.c USB controller (because the controller driver and our new, generic code now manage the PHYs). the PHY framework handles this gracefully (by ref-counting all operations). a follow-up series will be sent which removes the custom handling from the affected drivers (so only the new PHY wrapper will manage the PHYs state after that follow-up series). - fixed an unnecessary whitespace change spotted by Alan Stern (thanks!) in patch #3 - removed all Tested-by's since we're changing code again Changes since v6 at [6]: - fixed unnecessary whitespace change (noticed by Alan Stern - thanks) - added PATCH #4 to clarify (with an example) how I understood how Rob wanted the dt-binding to look like (see [0]). please wait for an ACK from Rob on this one to make sure that we're not introducing some broken binding (as discussed with Arnd: [7]) - added Alan Stern's ACK on PATCH #3 - added Neil's Tested-by on PATCH #2 and #3 Changes since RfC v5 at [5]: - dropped RfC prefix - removed noisy dev_err if no roothub node was found (spotted by Xiaolong Ye's kbuild test robot - thank you for that!) - moved the call to usb_phy_roothub_power_off() within hcd_bus_suspend() to make sure that the PHYs are turned off if the "race with a root-hub wakeup event" condition is met (in this case the PHYs are turned on again, with the old code we did break the PHYs internal ref-counting because we never turned the PHYs off before turning them on again in case of that special "race with a root-hub wakeup event"). additionally we're not handling the status returned by usb_phy_roothub_power_off() anymore (the bus is already turned off and we tried to turn off all PHYs as well - only the PHYs which failed to power off will stay in the current state). thanks to Alan Stern for the suggestion - removed return value from usb_phy_roothub_power_off() because none of my code uses it anymore. thanks to Alan Stern for the suggestion Changes since v4 at [4]: - renamed the subject of the cover-letter (old name was: "initialize (multiple) PHYs in xhci-plat") - back into RFC status (see below for the reasons) - dropped Tested-by from Chunfeng Yun (same reasons as RFC status) - reworded cover-letter and commit messages from "platform-roothub" to "roothub PHY wrapper" - moved code from drivers/usb/host/platform-roothub.* to drivers/usb/core/phy.* and the changes to drivers/usb/host/xhci-plat.c to drivers/usb/core/hcd.c as suggested by Mathias Nyman (as a benefit this will enable the new logic for non-xHCI controllers as well - however this was not tested yet) - rename the structs, function names, etc from platform_roothub_* to usb_phy_roothub* Changes since RFCv3 at [3]: - moved the DT binding change from patch #3 to patch #1 as suggested by Rob Herring (and slightly adjusted the commit message to account for that) - added Tested-by from Chunfeng Yun (who confirmed that the whole concept and implementation works fine on Mediatek SoCs - many thanks again!) to patch #2 - added Rob Herring's ACK to patches 1 and 3 - dropped RFC status (RFCv3 -> PATCH v4) Changes since RFCv2 at [2]: - split phy_{init,exit} and phy_power_{on,off} handling. up until RFCv2 I called phy_init plus phy_power_on in platform_roothub_power_on and phy_power_off plus phy_exit in platform_roothub_power_off. However, Chunfeng Yun (a Mediatek SoC developer - many thanks for testing my series and providing great feedback) reported that only using phy_power_off (and omitting phy_exit) during system suspend fixes an issue where USB devices would be re-enumerated when resuming. His original problem description: "In order to keep link state on mt8173, we just power off all phys(not exit) when system enter suspend, then power on them again (needn't init, otherwise device will be disconnected) when system resume, this can avoid re-enumerating device.". This fix affects patch #2 and #3 as we now have platform_roothub_init (which calls phy_init internally), platform_roothub_power_on (which calls phy_power_on internally), platform_roothub_power_off (which calls phy_power_off internally) and platform_roothub_exit (which calls phy_exit internally). suspend and resume only call platform_roothub_power_{on,off} to prevent the issue described by Chunfeng Yun (unfortunately I cannot test this because the Amlogic platform currently does not support system suspend). - dropped two struct forward declarations from platform-roothub.h which are not used in the header file (thanks to Chunfeng Yun for spotting this) Changes since RFCv1 at [1]: - split the usb-xhci dt-binding documentation into a separate patch - fixed a typo ("usb-phy" -> "phys" in the dt-binding example) - rebased to apply against latest usb-next [0] http://lists.infradead.org/pipermail/linux-amlogic/2016-November/001818.html [1] http://marc.info/?l=linux-usb&m=148414866303604&w=2 [2] https://www.spinics.net/lists/linux-usb/msg158967.html [3] https://www.spinics.net/lists/devicetree/msg190426.html [4] http://lists.infradead.org/pipermail/linux-amlogic/2017-September/004685.html [5] http://lists.infradead.org/pipermail/linux-amlogic/2017-October/004924.html [6] http://lists.infradead.org/pipermail/linux-amlogic/2017-October/005049.html [7] http://lists.infradead.org/pipermail/linux-amlogic/2017-October/005121.html [8] http://lists.infradead.org/pipermail/linux-amlogic/2017-October/005124.html [9] http://lists.infradead.org/pipermail/linux-amlogic/2017-October/005192.html [10] http://lists.infradead.org/pipermail/linux-amlogic/2018-January/006274.html [11] https://marc.info/?l=linux-usb&m=151683941207898&w=2 Martin Blumenstingl (8): dt-bindings: usb: add the documentation for USB HCDs usb: add a flag to skip PHY initialization to struct usb_hcd usb: core: add a wrapper for the USB PHYs on the HCD usb: core: hcd: integrate the PHY wrapper into the HCD core usb: host: xhci-mtk: remove custom USB PHY handling usb: host: ehci-platform: remove custom USB PHY handling usb: host: ohci-platform: remove custom USB PHY handling usb: core: hcd: remove support for initializing a single PHY .../devicetree/bindings/usb/mediatek,mtk-xhci.txt | 5 +- .../devicetree/bindings/usb/mediatek,mtu3.txt | 5 +- Documentation/devicetree/bindings/usb/usb-ehci.txt | 6 +- Documentation/devicetree/bindings/usb/usb-hcd.txt | 9 ++ Documentation/devicetree/bindings/usb/usb-ohci.txt | 6 +- Documentation/devicetree/bindings/usb/usb-uhci.txt | 3 + Documentation/devicetree/bindings/usb/usb-xhci.txt | 5 + drivers/usb/chipidea/host.c | 5 +- drivers/usb/core/Makefile | 2 +- drivers/usb/core/hcd.c | 64 ++++----- drivers/usb/core/phy.c | 158 +++++++++++++++++++++ drivers/usb/core/phy.h | 7 + drivers/usb/host/ehci-fsl.c | 2 + drivers/usb/host/ehci-platform.c | 55 +------ drivers/usb/host/ehci-tegra.c | 1 + drivers/usb/host/ohci-omap.c | 1 + drivers/usb/host/ohci-platform.c | 56 +------- drivers/usb/host/xhci-mtk.c | 98 +------------ drivers/usb/host/xhci-plat.c | 1 + include/linux/usb/hcd.h | 8 +- 20 files changed, 252 insertions(+), 245 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/usb-hcd.txt create mode 100644 drivers/usb/core/phy.c create mode 100644 drivers/usb/core/phy.h