From patchwork Tue Jun 27 15:45:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 9812687 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 8539960351 for ; Tue, 27 Jun 2017 15:47:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74A6328696 for ; Tue, 27 Jun 2017 15:47:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68317286E0; Tue, 27 Jun 2017 15:47:09 +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_SIGNED, DKIM_VALID autolearn=unavailable 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 1A7DA28696 for ; Tue, 27 Jun 2017 15:47:08 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=Wbje1D20k81/JcScAfbfOwaPId1PDbFduGqKwxLL0LI=; b=Q0OiBKhnWsHQI1 7QkPm3m9qjtLKBWQ0iH0+NfIl25IlJ/AEV0YZK5h4I2MA0RaD25SjJM8mNM+3lht78UTPkd9qsjXX 1WVBMvgvv/zde39xxW5z91kU0FCrCeIEpPsEUNUHU+DHRvM8e8pToqrIOaMwkelXH5bD0UBlFJ2ya 6StlnN8lVq+AsoLwEUrSFcpCRRY8eCRUVaPSmC5CMPaLOHkQqWnLvivzX4utZVFWdpzWbq/Am41qr pDwQ0vRK5R6JO3E3FWw2tCyRHs6tncAZUI2inEl11b0h5ZBcj6swWDrOSAYLqcYUug4VGZWNgftCc LJCG2tf6W3CH809INOHA==; 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 1dPshk-00084O-VW; Tue, 27 Jun 2017 15:47:05 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dPsgp-0006rm-Rf for linux-arm-kernel@lists.infradead.org; Tue, 27 Jun 2017 15:46:10 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v5RFi7vo007667; Tue, 27 Jun 2017 17:45:42 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 2battv0d7m-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 27 Jun 2017 17:45:42 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 68F1738; Tue, 27 Jun 2017 15:45:41 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 50E0D2571; Tue, 27 Jun 2017 15:45:41 +0000 (GMT) Received: from localhost (10.201.23.160) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Tue, 27 Jun 2017 17:45:41 +0200 From: Amelie Delaunay To: Mark Brown , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue Subject: [PATCHv2 6/9] spi: stm32: add runtime PM support Date: Tue, 27 Jun 2017 17:45:18 +0200 Message-ID: <1498578321-13980-7-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498578321-13980-1-git-send-email-amelie.delaunay@st.com> References: <1498578321-13980-1-git-send-email-amelie.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.160] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-27_09:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170627_084608_424197_61AAD3F0 X-CRM114-Status: GOOD ( 12.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: devicetree@vger.kernel.org, Amelie Delaunay , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.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 This patch reworks suspend and resume callbacks and add runtime_suspend and runtime_resume callbacks. Signed-off-by: Amelie Delaunay --- drivers/spi/spi-stm32.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 72efc63..209afda 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1164,6 +1165,9 @@ static int stm32_spi_probe(struct platform_device *pdev) if (spi->dma_tx || spi->dma_rx) master->can_dma = stm32_spi_can_dma; + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + ret = devm_spi_register_master(&pdev->dev, master); if (ret) { dev_err(&pdev->dev, "spi master registration failed: %d\n", @@ -1203,6 +1207,8 @@ static int stm32_spi_probe(struct platform_device *pdev) dma_release_channel(spi->dma_tx); if (spi->dma_rx) dma_release_channel(spi->dma_rx); + + pm_runtime_disable(&pdev->dev); err_clk_disable: clk_disable_unprepare(spi->clk); err_master_put: @@ -1225,23 +1231,42 @@ static int stm32_spi_remove(struct platform_device *pdev) clk_disable_unprepare(spi->clk); + pm_runtime_disable(&pdev->dev); + return 0; } +#ifdef CONFIG_PM +static int stm32_spi_runtime_suspend(struct device *dev) +{ + struct spi_master *master = dev_get_drvdata(dev); + struct stm32_spi *spi = spi_master_get_devdata(master); + + clk_disable_unprepare(spi->clk); + + return 0; +} + +static int stm32_spi_runtime_resume(struct device *dev) +{ + struct spi_master *master = dev_get_drvdata(dev); + struct stm32_spi *spi = spi_master_get_devdata(master); + + return clk_prepare_enable(spi->clk); +} +#endif + #ifdef CONFIG_PM_SLEEP static int stm32_spi_suspend(struct device *dev) { struct spi_master *master = dev_get_drvdata(dev); - struct stm32_spi *spi = spi_master_get_devdata(master); int ret; ret = spi_master_suspend(master); if (ret) return ret; - clk_disable_unprepare(spi->clk); - - return ret; + return pm_runtime_force_suspend(dev); } static int stm32_spi_resume(struct device *dev) @@ -1250,9 +1275,10 @@ static int stm32_spi_resume(struct device *dev) struct stm32_spi *spi = spi_master_get_devdata(master); int ret; - ret = clk_prepare_enable(spi->clk); + ret = pm_runtime_force_resume(dev); if (ret) return ret; + ret = spi_master_resume(master); if (ret) clk_disable_unprepare(spi->clk); @@ -1261,8 +1287,11 @@ static int stm32_spi_resume(struct device *dev) } #endif -static SIMPLE_DEV_PM_OPS(stm32_spi_pm_ops, - stm32_spi_suspend, stm32_spi_resume); +static const struct dev_pm_ops stm32_spi_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(stm32_spi_suspend, stm32_spi_resume) + SET_RUNTIME_PM_OPS(stm32_spi_runtime_suspend, + stm32_spi_runtime_resume, NULL) +}; static struct platform_driver stm32_spi_driver = { .probe = stm32_spi_probe,