Received: by 10.192.165.148 with SMTP id m20csp2242828imm; Thu, 26 Apr 2018 08:01:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrhQ1WvU/OPfVJao24DoHqpY/ZU7tRBGALE5JP6Ax9DaDhfUTC8/hTVkwwsDJzB0OnzOUv5 X-Received: by 2002:a17:902:b949:: with SMTP id h9-v6mr913624pls.146.1524754869437; Thu, 26 Apr 2018 08:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524754869; cv=none; d=google.com; s=arc-20160816; b=eCVrsCi0ArYNH1UVQy3jdYXi0xQELf3j4N8GT6OXAFjeAtUbgFXvUVYWuIqf+TAYJh tQN5iB43Nr9u+rPO7lkM8dRz8tZ7vI0XLgdZTfXX0j1W4wDffhS76DjEeYhSJBgOU0T9 E3evE45IdCzswc36YkiTrLYZ2fdaVtBeizWbFl96nrCdnK1wJf33pkdLXZPyoNyd2SaW v4RXVJsl4twEAZ1qSxJT9H58Y75w0Ezlbxd3yCWj8ZBSZeIia9/gG56pNJA3a8pU8oZI MEV6LWVy9rxdn44IpgF5xJDRL4/tiPS9PKZkmskGJnqcnEY8tqv/2VHd8+1ZthNRkff6 LXnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=XLTknJZrcqzN2w09pdzxVwnOxJUx9vZJ0+z5AZSKvnA=; b=wvsVTF7ebQXGYcoGstW0ttAvUiSJDFnPhSRk7OMsu8Yp3OkD/Z+TuUbd1p0PzPgjIO 32IsLcUQizO3I327zgwIYDQeqleAG1/9g/Op/4lpakTxcfBQ6lYdWxpUBpuVIOHlP0Ii 0L/Tr8N126UMzJ2uA+yKZptIHBAzx/wcVWMVBs0W/RBgFN/0IHimE/+TNp5+2hwVp++k GHjm5O1tApQApCVRHc1qlxpPj7pHs+LLELSQro9SOCOUv5giJKotsfI9XeUj2yMKbw9v l9z4lc6GaLh5wH8a/txOMr1X3RQMwCGpbL1w4bBszvS5Ul+9aXRitbaDrgJUfRzPPBS5 aD4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t13si6825860pfc.333.2018.04.26.08.00.54; Thu, 26 Apr 2018 08:01:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756683AbeDZO7Z (ORCPT + 99 others); Thu, 26 Apr 2018 10:59:25 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:1809 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756613AbeDZO7T (ORCPT ); Thu, 26 Apr 2018 10:59:19 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com id ; Thu, 26 Apr 2018 07:59:17 -0700 Received: from HQMAIL108.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 26 Apr 2018 07:59:19 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 26 Apr 2018 07:59:19 -0700 Received: from HQMAIL108.nvidia.com (172.18.146.13) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 26 Apr 2018 14:59:18 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server id 15.0.1347.2 via Frontend Transport; Thu, 26 Apr 2018 14:59:18 +0000 Received: from moonraker.nvidia.com (Not Verified[10.21.132.129]) by hqnvemgw02.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Thu, 26 Apr 2018 07:59:18 -0700 From: Jon Hunter To: Mathias Nyman , Greg Kroah-Hartman , Thierry Reding CC: , , , Jon Hunter Subject: [PATCH V2 2/3] usb: xhci: tegra: Add runtime PM support Date: Thu, 26 Apr 2018 15:59:09 +0100 Message-ID: <1524754750-3633-2-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524754750-3633-1-git-send-email-jonathanh@nvidia.com> References: <1524754750-3633-1-git-send-email-jonathanh@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add runtime PM support to the Tegra XHCI driver and move the function calls to enable/disable the clocks, regulators and PHY into the runtime PM callbacks. Signed-off-by: Jon Hunter --- Changes since V1: - Re-worked change to handle case where runtime PM is disabled. drivers/usb/host/xhci-tegra.c | 89 ++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 02b0b24faa58..85f2381883ad 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -761,6 +762,50 @@ static void tegra_xusb_phy_disable(struct tegra_xusb *tegra) } } +static int tegra_xusb_runtime_suspend(struct device *dev) +{ + struct tegra_xusb *tegra = dev_get_drvdata(dev); + + tegra_xusb_phy_disable(tegra); + regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); + tegra_xusb_clk_disable(tegra); + + return 0; +} + +static int tegra_xusb_runtime_resume(struct device *dev) +{ + struct tegra_xusb *tegra = dev_get_drvdata(dev); + int err; + + err = tegra_xusb_clk_enable(tegra); + if (err) { + dev_err(dev, "failed to enable clocks: %d\n", err); + return err; + } + + err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); + if (err) { + dev_err(dev, "failed to enable regulators: %d\n", err); + goto disable_clk; + } + + err = tegra_xusb_phy_enable(tegra); + if (err < 0) { + dev_err(dev, "failed to enable PHYs: %d\n", err); + goto disable_regulator; + } + + return 0; + +disable_regulator: + regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); +disable_clk: + tegra_xusb_clk_disable(tegra); + return err; +} + + static int tegra_xusb_load_firmware(struct tegra_xusb *tegra) { unsigned int code_tag_blocks, code_size_blocks, code_blocks; @@ -1067,22 +1112,15 @@ static int tegra_xusb_probe(struct platform_device *pdev) */ platform_set_drvdata(pdev, tegra); - err = tegra_xusb_clk_enable(tegra); - if (err) { - dev_err(&pdev->dev, "failed to enable clocks: %d\n", err); - goto put_usb2; - } + pm_runtime_enable(&pdev->dev); + if (!pm_runtime_enabled(&pdev->dev)) + err = pm_runtime_get_sync(&pdev->dev); + else + err = tegra_xusb_runtime_resume(&pdev->dev); - err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); - if (err) { - dev_err(&pdev->dev, "failed to enable regulators: %d\n", err); - goto disable_clk; - } - - err = tegra_xusb_phy_enable(tegra); if (err < 0) { - dev_err(&pdev->dev, "failed to enable PHYs: %d\n", err); - goto disable_regulator; + dev_err(&pdev->dev, "failed to enable device: %d\n", err); + goto disable_rpm; } tegra_xusb_ipfs_config(tegra, regs); @@ -1090,7 +1128,7 @@ static int tegra_xusb_probe(struct platform_device *pdev) err = tegra_xusb_load_firmware(tegra); if (err < 0) { dev_err(&pdev->dev, "failed to load firmware: %d\n", err); - goto disable_phy; + goto put_rpm; } tegra->hcd->regs = tegra->regs; @@ -1100,7 +1138,7 @@ static int tegra_xusb_probe(struct platform_device *pdev) err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED); if (err < 0) { dev_err(&pdev->dev, "failed to add USB HCD: %d\n", err); - goto disable_phy; + goto put_rpm; } device_wakeup_enable(tegra->hcd->self.controller); @@ -1155,13 +1193,11 @@ static int tegra_xusb_probe(struct platform_device *pdev) usb_put_hcd(xhci->shared_hcd); remove_usb2: usb_remove_hcd(tegra->hcd); -disable_phy: - tegra_xusb_phy_disable(tegra); -disable_regulator: - regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); -disable_clk: - tegra_xusb_clk_disable(tegra); -put_usb2: +put_rpm: + if (!pm_runtime_status_suspended(&pdev->dev)) + tegra_xusb_runtime_suspend(&pdev->dev); +disable_rpm: + pm_runtime_disable(&pdev->dev); usb_put_hcd(tegra->hcd); put_padctl: tegra_xusb_padctl_put(tegra->padctl); @@ -1181,9 +1217,8 @@ static int tegra_xusb_remove(struct platform_device *pdev) dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, tegra->fw.phys); - tegra_xusb_phy_disable(tegra); - regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); - tegra_xusb_clk_disable(tegra); + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); tegra_xusb_padctl_put(tegra->padctl); @@ -1211,6 +1246,8 @@ static int tegra_xusb_resume(struct device *dev) #endif static const struct dev_pm_ops tegra_xusb_pm_ops = { + SET_RUNTIME_PM_OPS(tegra_xusb_runtime_suspend, + tegra_xusb_runtime_resume, NULL) SET_SYSTEM_SLEEP_PM_OPS(tegra_xusb_suspend, tegra_xusb_resume) }; -- 2.7.4