From patchwork Sun Feb 18 18:45:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10226891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70EB560244 for ; Sun, 18 Feb 2018 18:49:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DA11286EE for ; Sun, 18 Feb 2018 18:49:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51D7B2891B; Sun, 18 Feb 2018 18:49:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D9C48286EE for ; Sun, 18 Feb 2018 18:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pTDiDuWJKtWHA6B+zXtv3vB0S/ZZJRf+wPj0kqg1ilM=; b=EllMD/cqTRu9yRdGHcrKmyYoO3 QMQvGaK9tNltBhS3MYMkuZ3xbnJ0RB/VdrOwnphNz6nh0kAcG9ugdJnjrAP3xveFQcd5XVSJCrvZ7 aIZZ8TXqtDtLapnxP7ByfDzREKBe/bHkUOP6/z6R/2m8st8DYleADa1PiLz6ITyIWzIv5+sdxkCaY Z1dzgxnVzVZrQpp9ltnmaRmWZhu80a68mM/LqledXfMYPUlhVuGJjteNLrBJiJC88nRFoUZ+bDbj+ y127ecdhhzOiq9XTw5oO7HFJc5GMl8TrdPMs8KkqR5darZDCkEKUm/T4oWnrRUjUyG2N0cvp6YgkB 6DZLXCog==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1enU19-000854-56; Sun, 18 Feb 2018 18:48:55 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1enTxu-0006R0-H8; Sun, 18 Feb 2018 18:45:41 +0000 Received: by mail-wm0-x244.google.com with SMTP id z81so11388133wmb.4; Sun, 18 Feb 2018 10:45:25 -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:in-reply-to:references; bh=7p21QshI2CIuc1vbpCpNGZ+nUvAYuUuXj++nrobXTYw=; b=L472/CLqFwX8EsmQUWYCMpzBFW+X8SKtGLLfUzlczBHTdfyeH84Pn3Qf9kQ056Fm+r I5bJtaO9tEuTZBAZC+Sz37r1TZ2BnAV6xUfUXcNfeFmrtwMbY2CqLTxeVVzJbB4NuXMj ssRU569W4JVZIDc5xp0A1psJmCSnnbKEc/DofrGXg9l4J4TsIPGPaDxX1Uom5iXy194M kh2vz3ypzXcveJu5ygs2nwnoAgaz4+f+ntNWNe/LsqF38sReEHZppC9ra1LS1nJquaiD qtk3Kz9o7g3LY/TK+4hQtikXtKP1ASypJJXjesvIyjRbzc+ycBfm/47iw3S+T2SpSmu3 3VAg== 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:in-reply-to :references; bh=7p21QshI2CIuc1vbpCpNGZ+nUvAYuUuXj++nrobXTYw=; b=PfNAa+5BqYgpE0hKAkVI73VS5ZTvfSIZOD0bvpss23qRKZJBMUHnw27vfOHzqNViLU Mf7gvfUNm5Nx/VrRtC9UCC0tGqLSnhq2/s8F/U4091IXLe0n+5VQu1NuRrZTxlVnGiSB hsxdVEDEKfN+IO1wvJN4bFzQQQDLHqi1MGvMPkR9VYsCwcuLPKSEwBE/yam/k5iUNuQu 9UIJNxrsIIOAnrez2Ao4vyuhxPSmfdMwGbKHr5Et9tlkKSxA1SNJe7Ea1MriIUB4YFaH cOPWov86qVddo42UMjp9ILYy1xaWz0JE2vAqMok7bAjIHR8uVOXrPMCCUZPO495WdhgG HrJA== X-Gm-Message-State: APf1xPD881rwulK+mo1T74KqqPDeQrw2bVwjmNZBuQ7sU9wKikYVRy+2 TFVxCGBJGsonOCupeczI1cI= X-Google-Smtp-Source: AH8x226vpg0IZsdAcpLx3n7vGu8zCUCE+J+9HWBfo/IgfffUSKeafNDe63OzJsbz0GHqR7Wrpgwb2Q== X-Received: by 10.28.184.21 with SMTP id i21mr428955wmf.94.1518979523926; Sun, 18 Feb 2018 10:45:23 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD7404304DD6DB7B324975560.dip0.t-ipconnect.de. [2003:dc:d740:4304:dd6d:b7b3:2497:5560]) by smtp.googlemail.com with ESMTPSA id 63sm22860290wms.46.2018.02.18.10.45.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 10:45:23 -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 Subject: [PATCH usb-next v10 4/8] usb: core: hcd: integrate the PHY wrapper into the HCD core Date: Sun, 18 Feb 2018 19:45:00 +0100 Message-Id: <20180218184504.3331-5-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180218184504.3331-1-martin.blumenstingl@googlemail.com> References: <20180218184504.3331-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180218_104534_648660_79DE96C3 X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, Peter.Chen@nxp.com, Martin Blumenstingl , narmstrong@baylibre.com, yixun.lan@amlogic.com, robh+dt@kernel.org, jonathanh@nvidia.com, linux@prisktech.co.nz, matthias.bgg@gmail.com, thierry.reding@gmail.com, linux-mediatek@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-tegra@vger.kernel.org, stern@rowland.harvard.edu, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This integrates the PHY wrapper into the core hcd infrastructure. Multiple PHYs which are part of the HCD's device tree node are now managed (= powered on/off when needed), by the new usb_phy_roothub code. Suspend and resume is also supported, however not for runtime/auto-suspend (which is triggered for example when no devices are connected to the USB bus). This is needed on some SoCs (for example Amlogic Meson GXL) because if the PHYs are disabled during auto-suspend then devices which are plugged in afterwards are not seen by the host. One example where this is required is the Amlogic GXL and GXM SoCs: They are using a dwc3 USB controller with up to three ports enabled on the internal roothub. Each port has it's own PHY which must be enabled (if one of the PHYs is left disabled then none of the USB ports works at all). The new logic works on the Amlogic GXL and GXM SoCs because the dwc3 driver internally creates a xhci-hcd which then registers a HCD which then triggers our new PHY wrapper. USB controller drivers can opt out of this by setting "skip_phy_initialization" in struct usb_hcd to true. This is identical to how it works for a single USB PHY, so the "multiple PHY" handling is disabled for drivers that opted out of the management logic of a single PHY. Signed-off-by: Martin Blumenstingl Acked-by: Alan Stern Acked-by: Chunfeng Yun Tested-by: Yixun Lan --- drivers/usb/core/hcd.c | 31 +++++++++++++++++++++++++++++++ include/linux/usb/hcd.h | 1 + 2 files changed, 32 insertions(+) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index f2307470a31e..32797c25ac3b 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -37,6 +37,7 @@ #include #include "usb.h" +#include "phy.h" /*-------------------------------------------------------------------------*/ @@ -2260,6 +2261,9 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) usb_set_device_state(rhdev, USB_STATE_SUSPENDED); hcd->state = HC_STATE_SUSPENDED; + if (!PMSG_IS_AUTO(msg)) + usb_phy_roothub_power_off(hcd->phy_roothub); + /* Did we race with a root-hub wakeup event? */ if (rhdev->do_remote_wakeup) { char buffer[6]; @@ -2296,6 +2300,13 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); return 0; } + + if (!PMSG_IS_AUTO(msg)) { + status = usb_phy_roothub_power_on(hcd->phy_roothub); + if (status) + return status; + } + if (!hcd->driver->bus_resume) return -ENOENT; if (HCD_RH_RUNNING(hcd)) @@ -2333,6 +2344,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) } } else { hcd->state = old_state; + usb_phy_roothub_power_off(hcd->phy_roothub); dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", "resume", status); if (status != -ESHUTDOWN) @@ -2769,6 +2781,18 @@ int usb_add_hcd(struct usb_hcd *hcd, } } + if (!hcd->skip_phy_initialization) { + hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev); + if (IS_ERR(hcd->phy_roothub)) { + retval = PTR_ERR(hcd->phy_roothub); + goto err_phy_roothub_init; + } + + retval = usb_phy_roothub_power_on(hcd->phy_roothub); + if (retval) + goto err_usb_phy_roothub_power_on; + } + dev_info(hcd->self.controller, "%s\n", hcd->product_desc); /* Keep old behaviour if authorized_default is not in [0, 1]. */ @@ -2933,6 +2957,10 @@ int usb_add_hcd(struct usb_hcd *hcd, err_register_bus: hcd_buffer_destroy(hcd); err_create_buf: + usb_phy_roothub_power_off(hcd->phy_roothub); +err_usb_phy_roothub_power_on: + usb_phy_roothub_exit(hcd->phy_roothub); +err_phy_roothub_init: if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->remove_phy && hcd->phy) { phy_power_off(hcd->phy); phy_exit(hcd->phy); @@ -3017,6 +3045,9 @@ void usb_remove_hcd(struct usb_hcd *hcd) usb_deregister_bus(&hcd->self); hcd_buffer_destroy(hcd); + usb_phy_roothub_power_off(hcd->phy_roothub); + usb_phy_roothub_exit(hcd->phy_roothub); + if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->remove_phy && hcd->phy) { phy_power_off(hcd->phy); phy_exit(hcd->phy); diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 693502c84c04..a042675e03ba 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -104,6 +104,7 @@ struct usb_hcd { */ struct usb_phy *usb_phy; struct phy *phy; + struct usb_phy_roothub *phy_roothub; /* Flags that need to be manipulated atomically because they can * change while the host controller is running. Always use