From patchwork Tue Mar 20 22:01:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10298033 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 5D66C600F6 for ; Tue, 20 Mar 2018 22:01:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4465229671 for ; Tue, 20 Mar 2018 22:01:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3729C2969F; Tue, 20 Mar 2018 22:01:51 +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 F138129671 for ; Tue, 20 Mar 2018 22:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To: Subject:Message-ID:Date:From:References:In-Reply-To:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mht0KfzurFCVaSwdfLWQNQ2cHHBJkC7tQRBjumtJkdY=; b=jT5K2IOElSDzcd4CT8G3QXfvu 7m4q3EJbVdwxr0zyTNwXFRSOEFEtZAWK5Pu2tUquffGQZjpJBv5IdKQZ1TAeYtYoSo+D4wxu/n3l2 6gHi3VFu/ufiGdv+AfUB3iGfZ0AqP2VpI1/HJq2t80XSuE7xTJdF4NZJC5NjyNsaqxdzIkEPFw66g s4x/8sqAtBtxFIf88XIzQP4LnCBbi+l5uGKBJIE/PFQzfhsHitazE1+Gpd0BfGLzO8PvWhON07STo 0cmL+pYLA1/XeQXmVHRxUCaEKcZPriFOI0ZbS9hqgdKYwByO6XiyAbgPmwx3e06JxMlM21eGcZoia SzM1Y7S/w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyPKB-00031P-IH; Tue, 20 Mar 2018 22:01:43 +0000 Received: from mail-ot0-x235.google.com ([2607:f8b0:4003:c0f::235]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyPK5-0002w7-7w; Tue, 20 Mar 2018 22:01:40 +0000 Received: by mail-ot0-x235.google.com with SMTP id m7-v6so3517974otd.1; Tue, 20 Mar 2018 15:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3VfIb8zSXJZLIYMs6Mz4kQQzgjb40B+Du+d6yAWWv7E=; b=BbEggUOC1pIpUt5bQSWP5ryceZeOOJjwy0f5TemJBRGgg8QmxPbcUQtmHW9daHAMWk 7vQHk2ymbzdT6znPoD1NWQXuHSGDWex6K7GEJiFFrlMQSBx0QK2lbFcPi6UtNjPbuV25 QNr2TDlErxT4s159x88rgZEGCmucjbn3AwVTvCdClcz5co8B/e50UHY1tgLM3G8CIsVq un1cjWVBffTnJKx9oYCm7EIb32Q3gKx3vALm1Dm7luTXZ05IPHgJfdbmqVs+hGV/f/Ln muNLUC5twH7VrLWKzbz2G0IODeTXmobra2zn5xiT86/sT0f+962pe6Zi7I8kishFaWZS oQHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3VfIb8zSXJZLIYMs6Mz4kQQzgjb40B+Du+d6yAWWv7E=; b=dhMSs5W1DufRHas9AUD2ia36HcvtdgCzgMfUKT11SQJKbdthqveM5qfh7lwRQI/6bc R43wUjzBhaVsrtInCUfrxrR6j4HbHhlpyiY9PDL29ib+lSWrf01U0KkeyLnwhM3uCEdE VEiwu77FZNESh79+OhuEZt0qT3EQ3D//yVJLz3RRgNFcLvZxtaivsIZ23uq5KdFSs5zF uGgBEsqCILcSmTa9FDa5GoH3Ea6iCp9bP+ZWq0x1LyCx/2pq55vRW5z0b8HY8fjxpva2 qOcv+lneBnPJ7r3G7U/dXVG4uPuM1ouA2QghrQtKAKMXDR6tu7rUAStE4XYau00SphUP JadA== X-Gm-Message-State: AElRT7EHgOOlKg5O1SxpAO8/+SxjkbnnPoSXapcvtXdXbaHG2qHtozNW ZTbeJFBXmziL+PSz3flp5+W7Xtk7O4UkJSo/04o= X-Google-Smtp-Source: AG47ELsUD6BHbKkQJxrg+Ty/yOAaXvAvs11wkMM6/s89zkbTjBk9n5xSvfTWUaWqsZK5cz3h+tEl5Kd6+wuMYV5iVKw= X-Received: by 2002:a9d:5403:: with SMTP id j3-v6mr7380182oth.52.1521583285785; Tue, 20 Mar 2018 15:01:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.138.5.70 with HTTP; Tue, 20 Mar 2018 15:01:05 -0700 (PDT) In-Reply-To: <1521547467.3717.92.camel@mhfsdcap03> References: <20180218184504.3331-1-martin.blumenstingl@googlemail.com> <20180218184504.3331-4-martin.blumenstingl@googlemail.com> <7f511a6f-f3a2-2002-f601-5ce1742f4539@ti.com> <1521547467.3717.92.camel@mhfsdcap03> From: Martin Blumenstingl Date: Tue, 20 Mar 2018 23:01:05 +0100 Message-ID: Subject: Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD To: Chunfeng Yun , Roger Quadros X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180320_150137_360108_FCD0978C X-CRM114-Status: GOOD ( 30.23 ) 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, Peter.Chen@nxp.com, Neil Armstrong , linux-tegra@vger.kernel.org, thierry.reding@gmail.com, KISHON VIJAY ABRAHAM , linux@prisktech.co.nz, felipe.balbi@linux.intel.com, jonathanh@nvidia.com, stern@rowland.harvard.edu, devicetree@vger.kernel.org, arnd@arndb.de, yixun.lan@amlogic.com, robh+dt@kernel.org, linux-mediatek@lists.infradead.org, matthias.bgg@gmail.com, linux-amlogic@lists.infradead.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Gerlach, Dave" , Keerthy , linux-usb@vger.kernel.org, mathias.nyman@intel.com, gregkh@linuxfoundation.org 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 Hi Roger, Hi Chunfeng, On Tue, Mar 20, 2018 at 1:04 PM, Chunfeng Yun wrote: > Hi Martin & Roger: > > On Mon, 2018-03-19 at 17:12 +0100, Martin Blumenstingl wrote: >> Hi Roger, >> >> On Mon, Mar 19, 2018 at 9:49 AM, Roger Quadros wrote: >> > Hi, >> > >> > On 19/03/18 00:29, Martin Blumenstingl wrote: >> >> Hi Roger, >> >> >> >> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros wrote: >> >>> +some TI folks >> >>> >> >>> Hi Martin, >> >>> >> >>> On 18/02/18 20:44, Martin Blumenstingl wrote: >> >>>> Many SoC platforms have separate devices for the USB PHY which are >> >>>> registered through the generic PHY framework. These PHYs have to be >> >>>> enabled to make the USB controller actually work. They also have to be >> >>>> disabled again on shutdown/suspend. >> >>>> >> >>>> Currently (at least) the following HCI platform drivers are using custom >> >>>> code to obtain all PHYs via devicetree for the roothub/controller and >> >>>> disable/enable them when required: >> >>>> - ehci-platform.c has ehci_platform_power_{on,off} >> >>>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off} >> >>>> - ohci-platform.c has ohci_platform_power_{on,off} >> >>>> >> >>>> With this new wrapper the USB PHYs can be specified directly in the >> >>>> USB controller's devicetree node (just like on the drivers listed >> >>>> above). This allows SoCs like the Amlogic Meson GXL family to operate >> >>>> correctly once this is wired up correctly. These SoCs use a dwc3 >> >>>> controller and require all USB PHYs to be initialized (if one of the USB >> >>>> PHYs it not initialized then none of USB port works at all). >> >>>> >> >>>> Signed-off-by: Martin Blumenstingl >> >>>> Tested-by: Yixun Lan >> >>>> Cc: Neil Armstrong >> >>>> Cc: Chunfeng Yun >> >>> >> >>> This patch is breaking low power cases on TI SoCs when USB is in host mode. >> >>> I'll explain why below. >> >> based on your explanation and reading the TI PHY drivers I am assuming >> >> that the affected SoCs are using the "phy-omap-usb2" driver >> >> >> > yes and phy-ti-pipe3 as well i.e. "ti,phy-usb3" and "ti,omap-usb3" >> I missed that, thanks >> >> >>>> --- >> >>>> drivers/usb/core/Makefile | 2 +- >> >>>> drivers/usb/core/phy.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++ >> >>>> drivers/usb/core/phy.h | 7 ++ >> >>>> 3 files changed, 166 insertions(+), 1 deletion(-) >> >>>> create mode 100644 drivers/usb/core/phy.c >> >>>> create mode 100644 drivers/usb/core/phy.h >> >>>> >> >>>> diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile >> >>>> index 92c9cefb4317..18e874b0441e 100644 >> >>>> --- a/drivers/usb/core/Makefile >> >>>> +++ b/drivers/usb/core/Makefile >> >>>> @@ -6,7 +6,7 @@ >> >>>> usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o >> >>>> usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o >> >>>> usbcore-y += devio.o notify.o generic.o quirks.o devices.o >> >>>> -usbcore-y += port.o >> >>>> +usbcore-y += phy.o port.o >> >>>> >> >>>> usbcore-$(CONFIG_OF) += of.o >> >>>> usbcore-$(CONFIG_USB_PCI) += hcd-pci.o >> >>>> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c >> >>>> new file mode 100644 >> >>>> index 000000000000..09b7c43c0ea4 >> >>>> --- /dev/null >> >>>> +++ b/drivers/usb/core/phy.c >> >>>> @@ -0,0 +1,158 @@ >> >>>> +// SPDX-License-Identifier: GPL-2.0+ >> >>>> +/* >> >>>> + * A wrapper for multiple PHYs which passes all phy_* function calls to >> >>>> + * multiple (actual) PHY devices. This is comes handy when initializing >> >>>> + * all PHYs on a HCD and to keep them all in the same state. >> >>>> + * >> >>>> + * Copyright (C) 2018 Martin Blumenstingl >> >>>> + */ >> >>>> + >> >>>> +#include >> >>>> +#include >> >>>> +#include >> >>>> +#include >> >>>> + >> >>>> +#include "phy.h" >> >>>> + >> >>>> +struct usb_phy_roothub { >> >>>> + struct phy *phy; >> >>>> + struct list_head list; >> >>>> +}; >> >>>> + >> >>>> +static struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev) >> >>>> +{ >> >>>> + struct usb_phy_roothub *roothub_entry; >> >>>> + >> >>>> + roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL); >> >>>> + if (!roothub_entry) >> >>>> + return ERR_PTR(-ENOMEM); >> >>>> + >> >>>> + INIT_LIST_HEAD(&roothub_entry->list); >> >>>> + >> >>>> + return roothub_entry; >> >>>> +} >> >>>> + >> >>>> +static int usb_phy_roothub_add_phy(struct device *dev, int index, >> >>>> + struct list_head *list) >> >>>> +{ >> >>>> + struct usb_phy_roothub *roothub_entry; >> >>>> + struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index); >> >>>> + >> >>>> + if (IS_ERR_OR_NULL(phy)) { >> >>>> + if (!phy || PTR_ERR(phy) == -ENODEV) >> >>>> + return 0; >> >>>> + else >> >>>> + return PTR_ERR(phy); >> >>>> + } >> >>>> + >> >>>> + roothub_entry = usb_phy_roothub_alloc(dev); >> >>>> + if (IS_ERR(roothub_entry)) >> >>>> + return PTR_ERR(roothub_entry); >> >>>> + >> >>>> + roothub_entry->phy = phy; >> >>>> + >> >>>> + list_add_tail(&roothub_entry->list, list); >> >>>> + >> >>>> + return 0; >> >>>> +} >> >>>> + >> >>>> +struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev) >> >>>> +{ >> >>>> + struct usb_phy_roothub *phy_roothub; >> >>>> + struct usb_phy_roothub *roothub_entry; >> >>>> + struct list_head *head; >> >>>> + int i, num_phys, err; >> >>>> + >> >>>> + num_phys = of_count_phandle_with_args(dev->of_node, "phys", >> >>>> + "#phy-cells"); >> >>>> + if (num_phys <= 0) >> >>>> + return NULL; >> >>>> + >> >>>> + phy_roothub = usb_phy_roothub_alloc(dev); >> >>>> + if (IS_ERR(phy_roothub)) >> >>>> + return phy_roothub; >> >>>> + >> >>>> + for (i = 0; i < num_phys; i++) { >> >>>> + err = usb_phy_roothub_add_phy(dev, i, &phy_roothub->list); >> >>>> + if (err) >> >>>> + goto err_out; >> >>>> + } >> >>>> + >> >>>> + head = &phy_roothub->list; >> >>>> + >> >>>> + list_for_each_entry(roothub_entry, head, list) { >> >>>> + err = phy_init(roothub_entry->phy); >> >>> >> >>> The phy_init() function actually enables the PHY clocks. >> >>> It should be moved to the usb_phy_roothub_exit() routine just before calling phy_power_on(). >> >> do you mean that phy_init should be moved to usb_phy_roothub_power_on >> >> (just before phy_power_on is called within usb_phy_roothub_power_on)? >> >> >> > >> > Yes. >> > >> >> an earlier version of my patch did exactly this, but it caused >> >> problems during a suspend/resume cycle on Mediatek devices >> >> Chunfeng Yun reported that issue here [0], quote from that mail for >> >> easier reading: >> >> "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." >> >> >> >>>> + if (err) >> >>>> + goto err_exit_phys; >> >>>> + } >> >>>> + >> >>>> + return phy_roothub; >> >>>> + >> >>>> +err_exit_phys: >> >>>> + list_for_each_entry_continue_reverse(roothub_entry, head, list) >> >>>> + phy_exit(roothub_entry->phy); >> >>>> + >> >>>> +err_out: >> >>>> + return ERR_PTR(err); >> >>>> +} >> >>>> +EXPORT_SYMBOL_GPL(usb_phy_roothub_init); >> >>>> + >> >>>> +int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub) >> >>>> +{ >> >>>> + struct usb_phy_roothub *roothub_entry; >> >>>> + struct list_head *head; >> >>>> + int err, ret = 0; >> >>>> + >> >>>> + if (!phy_roothub) >> >>>> + return 0; >> >>>> + >> >>>> + head = &phy_roothub->list; >> >>>> + >> >>>> + list_for_each_entry(roothub_entry, head, list) { >> >>>> + err = phy_exit(roothub_entry->phy); >> >>>> + if (err) >> >>>> + ret = ret; >> >>>> + } >> >>> >> >>> phy_exit() should be moved to usb_phy_roothub_poweroff() just after calling phy_power_off(). >> >> if I understood Chunfeng Yun correctly this will require >> >> re-enumeration of the USB devices after a suspend/resume cycle on >> >> Mediatek SoCs >> >> >> > >> > OK. I suppose that there are 2 cases >> > 1) Mediatek's case: USB controller context retained across suspend/resume. >> > Remote wakeup probably required. >> > No re-enumeration preferred after resume. phy_exit()/phy_init() must not be called >> > during suspend/resume to keep PHY link active. >> Documentation/devicetree/bindings/usb/mediatek,mtu3.txt indeed shows >> that the parent of the USB controller can be marked as "wakeup-source" >> >> > 2) TI's case: low power important: USB context is lost, OK to re-enumerate. >> > phy_exit()/phy_init() must be called during suspend/resume. >> ACK >> >> >>> With that there is nothing else being done here. Shouldn't we be doing the equivalent of >> >>> usb_phy_roothub_del_phy() and usb_phy_roothub_free() here? >> >>> >> >>>> + >> >>>> + return ret; >> >>>> +} >> >>>> +EXPORT_SYMBOL_GPL(usb_phy_roothub_exit); >> >>>> + >> >>>> +int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub) >> >>>> +{ >> >>>> + struct usb_phy_roothub *roothub_entry; >> >>>> + struct list_head *head; >> >>>> + int err; >> >>>> + >> >>>> + if (!phy_roothub) >> >>>> + return 0; >> >>>> + >> >>>> + head = &phy_roothub->list; >> >>>> + >> >>>> + list_for_each_entry(roothub_entry, head, list) { >> >>>> + err = phy_power_on(roothub_entry->phy); >> >>>> + if (err) >> >>>> + goto err_out; >> >>>> + } >> >>>> + >> >>>> + return 0; >> >>>> + >> >>>> +err_out: >> >>>> + list_for_each_entry_continue_reverse(roothub_entry, head, list) >> >>>> + phy_power_off(roothub_entry->phy); >> >>>> + >> >>>> + return err; >> >>>> +} >> >>>> +EXPORT_SYMBOL_GPL(usb_phy_roothub_power_on); >> >>>> + >> >>>> +void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub) >> >>>> +{ >> >>>> + struct usb_phy_roothub *roothub_entry; >> >>>> + >> >>>> + if (!phy_roothub) >> >>>> + return; >> >>>> + >> >>>> + list_for_each_entry_reverse(roothub_entry, &phy_roothub->list, list) >> >>>> + phy_power_off(roothub_entry->phy); >> >>> >> >>> Not doing the phy_exit() here leaves the clocks enabled on our SoC and >> >>> we're no longer able to reach low power states on system suspend. >> >> I'm not sure where this problem should be solved: >> >> - set skip_phy_initialization in struct usb_hcd to 1 for the affected >> >> TI platforms >> > >> > Many TI platforms are affected, omap5*, dra7*, am43* >> > >> >> - fix this in the usb_phy_roothub code >> > >> > I'd vote for fixing it in the usb_phy_roothub code. How? >> > How about using the device_can_wakeup() to decide if we should call phy_exit()/init() or not? >> > If the USB device can't wakeup the system there is no point in keeping it powered/clocked right? >> @Chunfeng: can you confirm Roger's idea that we could call phy_exit if >> the controller is *NOT* marked as "wakeup-source"? >> I am also not sure if it would work, since the "wakeup-source" >> property is defined on the USB controller's parent node in case of the >> Mediatek MTU3 (Mediatek USB3.0 DRD) controller >> > Very sorry, I forgot that MTU3 & xHCI drivers always set them as wakeup > devices by device_init_wakeup(dev, true),but not dependent on > "wakeup-source" property, so maybe we can use device_can_wakeup() to > decide whether call phy_exit()/init() or not. the 64-bit Amlogic Meson GXL/GXM SoCs don't support suspend/resume yet, so I cannot test this based on this suggestion I threw up two patches which are *compile tested only* based on Greg's usb-next branch you can find them here: [0] (as well as attached to this mail) @Chunfeng: can you please test this on one of your Mediatek SoCs? @Roger: can you please test this on a TI SoC? (apologies in advance if these patches don't work) please note that I won't have access to my computer until Saturday. if these patches need to be rewritten/replaced/etc. then feel free to send your own version to the list >> >> - fix this in the PHY driver >> > >> > There is nothing to fix in the PHY driver. It is doing what it is supposed to do. >> I actually wonder if phy_ops should have explicit suspend/resume support: >> - assuming we define two new callbacks: .suspend and .resume >> - the PHY framework could call .power_off by default if .suspend is not defined >> - the PHY framework could call .power_on by default if .resume is not defined >> - drivers could set .suspend and .resume on their own, allowing more >> fine-grained control by for example *only* stopping the clock (but not >> re-initializing the registers, etc.) >> >> @Roger: what do you think about this? >> Kishon (the PHY framework maintainer) is also CC'ed - I would like to >> hear his opinion too >> >> >> - somewhere else >> >> >> >>>> +} >> >>>> +EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off); >> >>>> diff --git a/drivers/usb/core/phy.h b/drivers/usb/core/phy.h >> >>>> new file mode 100644 >> >>>> index 000000000000..6fde59bfbff8 >> >>>> --- /dev/null >> >>>> +++ b/drivers/usb/core/phy.h >> >>>> @@ -0,0 +1,7 @@ >> >>>> +struct usb_phy_roothub; >> >>>> + >> >>>> +struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev); >> >>>> +int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub); >> >>>> + >> >>>> +int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub); >> >>>> +void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub); >> >>>> >> >>> >> > >> > >> > >> > -- >> > cheers, >> > -roger >> > >> > Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki >> >> >> Regards >> Martin > > Regards Martin [0] https://github.com/xdarklight/linux/commits/usb-phy-roothub-suspend-rfc-v1 From 1367f49ff49cec249bd9ba95e5395dd1760eee8b Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Tue, 20 Mar 2018 22:47:38 +0100 Subject: [PATCH 2/2] usb: core: use phy_exit during suspend if wake up is not supported If the USB controller can wake up the system (which is the case for example with the Mediatek USB3 IP) then we must not call phy_exit during suspend to ensure that the USB controller doesn't have to re-enumerate the devices during resume. However, if the USB controller cannot wake up the system (which is the case for example on various TI platforms using a dwc3 controller) then we must call phy_exit during suspend. Otherwise the PHY driver keeps the clocks enabled, which prevents the system from entering the suspend state. Solve this by introducing two new functions in the PHY wrapper which are dedicated to the suspend and resume handling. If the controller can wake up the system the new usb_phy_roothub_suspend function will simply call usb_phy_roothub_power_off. However, if wake up is not supported by the controller it will also call usb_phy_roothub_exit. The also new usb_phy_roothub_resume function takes care of calling usb_phy_roothub_init (if the controller can't wake up the system) in addition to usb_phy_roothub_power_on. Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the HCD") Fixes: 178a0bce05cbc1 ("usb: core: hcd: integrate the PHY wrapper into the HCD core") Signed-off-by: Martin Blumenstingl --- drivers/usb/core/hcd.c | 6 +++--- drivers/usb/core/phy.c | 29 +++++++++++++++++++++++++++++ drivers/usb/core/phy.h | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 89b10d859047..6d4a4195ca00 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2262,7 +2262,7 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) hcd->state = HC_STATE_SUSPENDED; if (!PMSG_IS_AUTO(msg)) - usb_phy_roothub_power_off(hcd->phy_roothub); + usb_phy_roothub_suspend(hcd->phy_roothub); /* Did we race with a root-hub wakeup event? */ if (rhdev->do_remote_wakeup) { @@ -2302,7 +2302,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) } if (!PMSG_IS_AUTO(msg)) { - status = usb_phy_roothub_power_on(hcd->phy_roothub); + status = usb_phy_roothub_resume(hcd->phy_roothub); if (status) return status; } @@ -2344,7 +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); + usb_phy_roothub_suspend(hcd->phy_roothub); dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", "resume", status); if (status != -ESHUTDOWN) diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c index 50a80dbe776c..2eca371684fa 100644 --- a/drivers/usb/core/phy.c +++ b/drivers/usb/core/phy.c @@ -155,3 +155,32 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub) phy_power_off(roothub_entry->phy); } EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off); + +int usb_phy_roothub_suspend(struct device *dev, + struct usb_phy_roothub *phy_roothub) +{ + usb_phy_roothub_power_off(phy_roothub); + + /* keep the PHYs initialized so the device can wake up the system */ + if (device_can_wakeup(dev)) + return 0; + + return usb_phy_roothub_exit(phy_roothub); +} +EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend); + +int usb_phy_roothub_resume(struct device *dev, + struct usb_phy_roothub *phy_roothub) +{ + int err; + + /* if the device can't wake up the system _exit was called */ + if (device_can_wakeup(dev)) { + err = usb_phy_roothub_init(phy_roothub); + if (err) + return err; + } + + return usb_phy_roothub_power_on(phy_roothub); +} +EXPORT_SYMBOL_GPL(usb_phy_roothub_resume); diff --git a/drivers/usb/core/phy.h b/drivers/usb/core/phy.h index eb31253201ad..601aefd41878 100644 --- a/drivers/usb/core/phy.h +++ b/drivers/usb/core/phy.h @@ -7,3 +7,8 @@ int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub); int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub); void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub); + +int usb_phy_roothub_suspend(struct device *dev, + struct usb_phy_roothub *phy_roothub); +int usb_phy_roothub_resume(struct device *dev, + struct usb_phy_roothub *phy_roothub); -- 2.16.2