From patchwork Sun Oct 8 21:17:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9992005 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 79B5860594 for ; Sun, 8 Oct 2017 21:18:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A834285FE for ; Sun, 8 Oct 2017 21:18:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C56B2862C; Sun, 8 Oct 2017 21:18:07 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 AA43E2860A for ; Sun, 8 Oct 2017 21:18:06 +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=pXo0sKiKW2mdKkScrlp4N1XIvh2WCb19jNWPLK5HKx0=; b=my1NERrWN0m32rDdVM767Fuk7b ideK06WuBvulbu1aKgzygW0lXv+CFnf402jHmg6Hnu6IdUVrrCmE1UjXQLxrXYe7bKi/A8WQTTSN+ SkRT/Rntes8OcuMXeFcUXcnespyIqxZittuByhrzAsUpt4jcEsY53jE/+lrFPp5TSm92mELGspC/l 3zmWT2qQ8MQEpHLhyeGBQ/wfTzz7uPLDE6BO2vfEFJVhnLPuUVNiU3x5HNIDQdQwCw0hEUB2d0V9g GvMXV2jYugeCoCC0uNy6yyWG+qYZa1bIPzE1XSKfr9sUgrENYaMoVTzdLEIqfJtx057qvU8YE80uZ zL4UkIfQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e1IxK-0006WG-Sw; Sun, 08 Oct 2017 21:17:50 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e1IxF-0006Dk-Gt for linux-amlogic@lists.infradead.org; Sun, 08 Oct 2017 21:17:48 +0000 Received: by mail-wm0-x244.google.com with SMTP id l68so18694597wmd.5 for ; Sun, 08 Oct 2017 14:17:25 -0700 (PDT) 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=h8k31rwdaNS1f1i1Ln2LXTj4uYHebievkaiHvqc3kwA=; b=SZnwnB/1qawrMQBu63/lNytp8pbhEns1PrrVOsT72V5G6GEXOlQ2RQFnB/BtWiFhTJ bsPEqng7twsAv8xYgfGE1aLXToxilMcFJ0sv6JQC7lPms2atROMQMahuIkG0PFJAFILz 5wZOvHOxeQycvB6k2yYld7TuZngCs2fb345cHoyH7VtpcV5yYeKoOInmrY0mzaTO15kN y03qj0+p77meVFLb8ILwOw0NirA1edN0e7b8re/jTfXvyCCfgSlUd/KYwtICZkcYQ/ua d3DCUKYQl/KsLeWOd3VSTsI/c8p9yeGw2wDQMu/9K4vkIhFMBUFHLVheoCpzetQIZC5H UV9w== 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=h8k31rwdaNS1f1i1Ln2LXTj4uYHebievkaiHvqc3kwA=; b=Qf79rPsgCwJRZsQP6h81rhen4aE7nAfea4rNLqkqiEzSIje1BwETE+1KrNmHMlR/Fu ZNlIPAyPItzS1Pw/GMRDuMJX1Q5CYA6iwHCi20Y1aoQ4WXRrbCHfvPYGCDf5n4ZcflS3 qh2+3/q7mq0B0sOQ8UhjiFUNKh2PSamQcZklJk4zs2kdHVp2WHQN9kXByVWZ/SYff7fh /VzRHE7YCZNgmxgM8gPN1QN0T6x1S8EjQSTckvOw7qpbT9FThFOsBgx8igdme7GRUT34 YNPoyNlX/PPVQpvEETGfq6YxotfymcsDRSMtZqn/1morXIdFiwo5OkyO0JXg19V+tdeT YRsg== X-Gm-Message-State: AMCzsaX6sJJHW7YDUzkLJGpNA3aU4yXQSszNb3Cu00p3eABCkcl8l034 vKCwuZ5Zj4hwj/X48aeaIF0= X-Google-Smtp-Source: AOwi7QA6cihqn8X/MdI+amJUDB5jAEikGGw9ke8qE1DnNY12MucTDm4PXPYWdntkUrcp8eH5csysAg== X-Received: by 10.28.55.2 with SMTP id e2mr7037323wma.60.1507497443775; Sun, 08 Oct 2017 14:17:23 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3DC7704A06B630ABD9CCA81.dip0.t-ipconnect.de. [2003:dc:d3dc:7704:a06b:630a:bd9c:ca81]) by smtp.googlemail.com with ESMTPSA id i16sm11772150wrf.19.2017.10.08.14.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Oct 2017 14:17:23 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, felipe.balbi@linux.intel.com, mathias.nyman@intel.com Subject: [RFC usb-next v5 3/3] usb: core: hcd: integrate the PHY roothub wrapper Date: Sun, 8 Oct 2017 23:17:13 +0200 Message-Id: <20171008211713.18696-4-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171008211713.18696-1-martin.blumenstingl@googlemail.com> References: <20171008211713.18696-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171008_141745_722479_90BAAB43 X-CRM114-Status: GOOD ( 13.26 ) X-BeenThere: linux-amlogic@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, arnd@arndb.de, Martin Blumenstingl , robh+dt@kernel.org, chunfeng.yun@mediatek.com, linux-amlogic@lists.infradead.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This integrates the PHY roothub wrapper into the core hcd infrastructure. Multiple PHYs which are part of the roothub devicetree node (which is a sub-node of the sysdev's node) are now managed (= powered on/off when needed), by the new usb_phy_roothub code. 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. Using only the top-level "phy" properties does not work here since one can only specify one "usb2-phy" and one "usb3-phy", while actually at least two "usb2-phy" have to be specified. Signed-off-by: Martin Blumenstingl --- drivers/usb/core/hcd.c | 30 +++++++++++++++++++++++++++++- include/linux/usb/hcd.h | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 67aa3d039b9b..56704dd10c15 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -50,6 +50,7 @@ #include #include "usb.h" +#include "phy.h" /*-------------------------------------------------------------------------*/ @@ -2292,7 +2293,11 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", "suspend", status); } - return status; + + if (status == 0) + return usb_phy_roothub_power_off(hcd->phy_roothub); + else + return status; } int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) @@ -2307,6 +2312,11 @@ 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; } + + 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)) @@ -2344,6 +2354,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) @@ -2780,6 +2791,16 @@ int usb_add_hcd(struct usb_hcd *hcd, } } + 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]. */ @@ -2944,6 +2965,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); @@ -3028,6 +3053,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 a1f03ebfde47..6915b2afc209 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -103,6 +103,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