From patchwork Fri Feb 16 17:14:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Kemnade X-Patchwork-Id: 10225207 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 B700D602CB for ; Fri, 16 Feb 2018 17:33:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A699E2961A for ; Fri, 16 Feb 2018 17:33:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B39F2961E; Fri, 16 Feb 2018 17:33:11 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEA652961A for ; Fri, 16 Feb 2018 17:33:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162046AbeBPRdD (ORCPT ); Fri, 16 Feb 2018 12:33:03 -0500 Received: from mail.andi.de1.cc ([85.214.239.24]:54633 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161052AbeBPRdA (ORCPT ); Fri, 16 Feb 2018 12:33:00 -0500 Received: from p5dcc363c.dip0.t-ipconnect.de ([93.204.54.60] helo=aktux) by h2641619.stratoserver.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1emjsV-00036A-Kh; Fri, 16 Feb 2018 18:32:55 +0100 Received: from andi by aktux with local (Exim 4.89) (envelope-from ) id 1emjaS-00028i-RJ; Fri, 16 Feb 2018 18:14:16 +0100 From: Andreas Kemnade To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-omap@vger.kernel.org, rogerq@ti.com, Discussions about the Letux Kernel Cc: Andreas Kemnade Subject: [PATCH RFC] ehci-omap: simple suspend implementation Date: Fri, 16 Feb 2018 18:14:14 +0100 Message-Id: <20180216171414.8097-1-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This powers down the phy and on a gta04 it reduces suspend current by 13 mA. For unknown reasons usb does not power on properly. Also calling usb_phy_shutdown() here feels wrong apparently the reset line has to be activated. usb_phy_set_suspend is not enough here. The power consumption still stays approximately the same as without any patch. With a device connected the device does not enumerate after resume. A rmmod ehci-omap ; modprobe ehci-omap does not make it reenumerade. So there is still something wrong here. Signed-off-by: Andreas Kemnade --- drivers/usb/host/ehci-omap.c | 59 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c index 8d8bafc70c1f..0be2ccf8182a 100644 --- a/drivers/usb/host/ehci-omap.c +++ b/drivers/usb/host/ehci-omap.c @@ -266,6 +266,58 @@ static int ehci_hcd_omap_remove(struct platform_device *pdev) return 0; } + +static int __maybe_unused ehci_omap_suspend(struct device *dev) +{ + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct omap_hcd *omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv; + int ret; + int i; + + ret = ehci_suspend(hcd, false); + if (ret) { + dev_err(dev, "ehci suspend failed: %d\n", ret); + return ret; + } + for (i = 0; i < omap->nports; i++) { + if (omap->phy[i]) + usb_phy_shutdown(omap->phy[i]); + } + pm_runtime_put_sync(dev); + + return 0; +} + +static int __maybe_unused ehci_omap_resume(struct device *dev) +{ + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct omap_hcd *omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv; + int i; + + pm_runtime_get_sync(dev); + /* + * An undocumented "feature" in the OMAP3 EHCI controller, + * causes suspended ports to be taken out of suspend when + * the USBCMD.Run/Stop bit is cleared (for example when + * we do ehci_bus_suspend). + * This breaks suspend-resume if the root-hub is allowed + * to suspend. Writing 1 to this undocumented register bit + * disables this feature and restores normal behavior. + */ + ehci_write(hcd->regs, EHCI_INSNREG04, + EHCI_INSNREG04_DISABLE_UNSUSPEND); + + for (i = 0; i < omap->nports; i++) { + if (omap->phy[i]) { + usb_phy_init(omap->phy[i]); + usb_phy_set_suspend(omap->phy[i], false); + } + } + + ehci_resume(hcd, true); + return 0; +} + static const struct of_device_id omap_ehci_dt_ids[] = { { .compatible = "ti,ehci-omap" }, { } @@ -273,14 +325,17 @@ static const struct of_device_id omap_ehci_dt_ids[] = { MODULE_DEVICE_TABLE(of, omap_ehci_dt_ids); +static SIMPLE_DEV_PM_OPS(ehci_omap_pm_ops, ehci_omap_suspend, + ehci_omap_resume); + + static struct platform_driver ehci_hcd_omap_driver = { .probe = ehci_hcd_omap_probe, .remove = ehci_hcd_omap_remove, .shutdown = usb_hcd_platform_shutdown, - /*.suspend = ehci_hcd_omap_suspend, */ - /*.resume = ehci_hcd_omap_resume, */ .driver = { .name = hcd_name, + .pm = &ehci_omap_pm_ops, .of_match_table = omap_ehci_dt_ids, } };