From patchwork Sat Apr 7 20:47:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 0v3rdr0n3@gmail.com X-Patchwork-Id: 10328041 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 42B9C6020F for ; Sun, 8 Apr 2018 00:49:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 307DC28DB1 for ; Sun, 8 Apr 2018 00:49:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 209AB28DFC; Sun, 8 Apr 2018 00:49:21 +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.4 required=2.0 tests=BAYES_00, DATE_IN_PAST_03_06, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 56D3228DB1 for ; Sun, 8 Apr 2018 00:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752012AbeDHAtS (ORCPT ); Sat, 7 Apr 2018 20:49:18 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:37746 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751975AbeDHAtR (ORCPT ); Sat, 7 Apr 2018 20:49:17 -0400 Received: by mail-it0-f68.google.com with SMTP id 71-v6so6078856ith.2; Sat, 07 Apr 2018 17:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W2cKF0kvFxknNLRz2y2ceZ2DB+Itk8GkZflW8BB9QRA=; b=rqTC1A4bLvSg72Ej93eoqHfj8KMzg2+lieDA/x/OPCSGIuVdpZ0OQ8yDSKSkY7Ry7P PznTDkC/tJsawyshGwSClYg3gP8YehI0VLveIJHT3lRE+oIazXgt9Hv0pIC59XacodwX TmQtTGGoI9rUEz8Pye0AnKazCgehiof2JDIC8rOq6tpfbg4TAuqZ7mVILNQc/ZGYd3XH PL7Vz6Y6d4tl5qOsiESXxEigxJzXGMVCOusmgwFEB1XB/4btB2PWP074SrkhPaGnXhHF UrULX6Jom3WFiiKio7lTCuRe1Uiyb0JTkZBf7BGatvAyIl3uFFFZ3EGJPW1Xx47BA23E hMgg== 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=W2cKF0kvFxknNLRz2y2ceZ2DB+Itk8GkZflW8BB9QRA=; b=Jg2GwFPInxQk1hyhCS4majfkoNbqvdimo+XdcPoFPKqhCUK0iNANL+jJvCCTOxJrkM /m4JKSypUO88/4AQAsZ1nvnsxrqpZMRRIYhUam/pzVx/wqIMGlrrBR5AGRjqFmT1w+dP H4KFBjw9VcfMh7G/Tp1wS+NuoBurxabCobYSwDGqrTtkaxKgkoD4WUTQCmgXzLPNP9qL GcxvwvvNL+Nl50+DozJtWHH24ntfgNcQyW9ln3iQQP9lQ2D2UJ7oi8oi5kMo2xg9m14Y 6bt+jVz8s3Azs/kzBYDtOIjY3b6bN7ARieREVwj8QybFM9aAMYhQoUcJ2+LcsS2V4Hhu MQuQ== X-Gm-Message-State: ALQs6tA9Ix4O1wLa0AUQxL7OX4/r14eiR4PlGkFNHTsokOzDhx0h7uUx GmvG3vnBEyFq3F7F8YUY1HZ6xQ== X-Google-Smtp-Source: AIpwx48ruCno60IQd1qNYqLw2wmPHxiCfQ7r5Pt8A0I5NPgjlVmt22obRQdOEt71JLXyZVAOdimT8Q== X-Received: by 2002:a24:5f93:: with SMTP id r141-v6mr21490013itb.107.1523148556557; Sat, 07 Apr 2018 17:49:16 -0700 (PDT) Received: from pride.cinci.rr.com (cpe-74-136-84-14.kya.res.rr.com. [74.136.84.14]) by smtp.gmail.com with ESMTPSA id s142-v6sm7850750itb.4.2018.04.07.17.49.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Apr 2018 17:49:16 -0700 (PDT) From: 0v3rdr0n3@gmail.com To: linux-pm@vger.kernel.org, linux-ide@vger.kernel.org Cc: samorris@lexmark.com Subject: [PATCH 2/3] ata: ahci_platform: allow disabling of hotplug to save power Date: Sat, 7 Apr 2018 20:47:37 +0000 Message-Id: <20180407204738.28308-2-0v3rdr0n3@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180407204738.28308-1-0v3rdr0n3@gmail.com> References: <20180407204738.28308-1-0v3rdr0n3@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Samuel Morris A number of resources remain powered to support hotplug. On platforms I've worked with, allowing the ahci_platform to suspend saves about 150mW. This patch allows the device to be auto suspended if the config parameter is set. Signed-off-by: Samuel Morris --- drivers/ata/Kconfig | 10 +++++ drivers/ata/ahci_platform.c | 9 ++++- drivers/ata/libahci_platform.c | 86 ++++++++++++++++++++++++++++++++++-------- include/linux/ahci_platform.h | 2 + 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 2b16e7c8fff3..866663dd11ab 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -119,6 +119,16 @@ config SATA_AHCI_PLATFORM If unsure, say N. +config AHCI_HOTPLUG_DISABLED + tristate "Platform AHCI SATA hotplug disable" + default n + help + This option allows the AHCI Platform resources usually kept on + to support hotplug to be runtime suspended, effectively disabling + hotplug, but saving power. + + If unsure, say N. + config AHCI_BRCM tristate "Broadcom AHCI SATA support" depends on ARCH_BRCMSTB || BMIPS_GENERIC || ARCH_BCM_NSP diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 99f9a895a459..e58d971df5d1 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -68,8 +68,13 @@ static int ahci_probe(struct platform_device *pdev) return rc; } -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, - ahci_platform_resume); +static const struct dev_pm_ops ahci_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(ahci_platform_suspend, ahci_platform_resume) +#ifdef CONFIG_AHCI_HOTPLUG_DISABLED + SET_RUNTIME_PM_OPS(ahci_platform_runtime_suspend, + ahci_platform_runtime_resume, NULL) +#endif +}; static const struct of_device_id ahci_of_match[] = { { .compatible = "generic-ahci", }, diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 46a762442dc5..17fc4f19a53d 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -268,10 +268,14 @@ static void ahci_platform_put_resources(struct device *dev, void *res) struct ahci_host_priv *hpriv = res; int c; +#ifdef CONFIG_AHCI_HOTPLUG_DISABLED + pm_runtime_disable(dev); +#else if (hpriv->got_runtime_pm) { pm_runtime_put_sync(dev); pm_runtime_disable(dev); } +#endif for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) clk_put(hpriv->clks[c]); @@ -493,9 +497,15 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) if (rc == -EPROBE_DEFER) goto err_out; } + +#ifdef CONFIG_AHCI_HOTPLUG_DISABLED + pm_runtime_set_active(dev); + pm_runtime_enable(dev); +#else pm_runtime_enable(dev); pm_runtime_get_sync(dev); hpriv->got_runtime_pm = true; +#endif devres_remove_group(dev, NULL); return hpriv; @@ -723,6 +733,21 @@ int ahci_platform_resume_host(struct device *dev) } EXPORT_SYMBOL_GPL(ahci_platform_resume_host); +static int _ahci_platform_suspend(struct device *dev) +{ + struct ata_host *host = dev_get_drvdata(dev); + struct ahci_host_priv *hpriv = host->private_data; + int rc; + + rc = ahci_platform_suspend_host(dev); + if (rc) + return rc; + + ahci_platform_disable_resources(hpriv); + + return 0; +} + /** * ahci_platform_suspend - Suspend an ahci-platform device * @dev: the platform device to suspend @@ -734,20 +759,45 @@ EXPORT_SYMBOL_GPL(ahci_platform_resume_host); * 0 on success otherwise a negative error code */ int ahci_platform_suspend(struct device *dev) +{ + return _ahci_platform_suspend(dev); +} +EXPORT_SYMBOL_GPL(ahci_platform_suspend); + +/** + * ahci_platform_runtime_suspend - Runtime suspend an ahci-platform device + * @dev: the platform device to suspend + * + * This function suspends the host associated with the device, followed by + * disabling all the resources of the device. + * + * RETURNS: + * 0 on success otherwise a negative error code + */ +int ahci_platform_runtime_suspend(struct device *dev) +{ + return _ahci_platform_suspend(dev); +} +EXPORT_SYMBOL_GPL(ahci_platform_runtime_suspend); + +static int _ahci_platform_resume(struct device *dev) { struct ata_host *host = dev_get_drvdata(dev); struct ahci_host_priv *hpriv = host->private_data; int rc; - rc = ahci_platform_suspend_host(dev); + rc = ahci_platform_enable_resources(hpriv); if (rc) return rc; - ahci_platform_disable_resources(hpriv); + rc = ahci_platform_resume_host(dev); + if (rc) { + ahci_platform_disable_resources(hpriv); + return rc; + } return 0; } -EXPORT_SYMBOL_GPL(ahci_platform_suspend); /** * ahci_platform_resume - Resume an ahci-platform device @@ -761,31 +811,37 @@ EXPORT_SYMBOL_GPL(ahci_platform_suspend); */ int ahci_platform_resume(struct device *dev) { - struct ata_host *host = dev_get_drvdata(dev); - struct ahci_host_priv *hpriv = host->private_data; int rc; - rc = ahci_platform_enable_resources(hpriv); + rc = _ahci_platform_resume(dev); if (rc) return rc; - rc = ahci_platform_resume_host(dev); - if (rc) - goto disable_resources; - /* We resumed so update PM runtime state */ pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); return 0; - -disable_resources: - ahci_platform_disable_resources(hpriv); - - return rc; } EXPORT_SYMBOL_GPL(ahci_platform_resume); + +/** + * ahci_platform_runtime_resume - Runtime resume an ahci-platform device + * @dev: the platform device to resume + * + * This function enables all the resources of the device followed by + * resuming the host associated with the device. + * + * RETURNS: + * 0 on success otherwise a negative error code + */ +int ahci_platform_runtime_resume(struct device *dev) +{ + return _ahci_platform_resume(dev); +} +EXPORT_SYMBOL_GPL(ahci_platform_runtime_resume); + #endif MODULE_DESCRIPTION("AHCI SATA platform library"); diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h index 1b0a17b22cd3..6396e6982103 100644 --- a/include/linux/ahci_platform.h +++ b/include/linux/ahci_platform.h @@ -42,5 +42,7 @@ int ahci_platform_suspend_host(struct device *dev); int ahci_platform_resume_host(struct device *dev); int ahci_platform_suspend(struct device *dev); int ahci_platform_resume(struct device *dev); +int ahci_platform_runtime_suspend(struct device *dev); +int ahci_platform_runtime_resume(struct device *dev); #endif /* _AHCI_PLATFORM_H */