Received: by 10.192.165.156 with SMTP id m28csp956398imm; Mon, 16 Apr 2018 11:26:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx48fyht3DyO68AubE/VEmFCReW03Ahn2TSHGbOOQIBFsAyfDSuQf6SVbPSg71ft9op1Kr2OD X-Received: by 10.99.112.91 with SMTP id a27mr13782150pgn.432.1523903196872; Mon, 16 Apr 2018 11:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523903196; cv=none; d=google.com; s=arc-20160816; b=WSGWRr+8+g8yz43JkByCIkRp26wPvMHU7DYhG5rSgsOMk8zs9W35Dp4tTYW7p6nQbG MLmRpLsG+Us1g35k90JdPD9YT5Am5GozylUb3M4Wkkrx7ULVcGkQ4JOnFvEXJ8mPmIlV yVaM/doc5DgbZ5gDJTMOREbqtsowiyaxtdvMPYpbTiHI2DLvqDp7Xr7B4FofnaCZOfUq Ce4XDAjKytiD4Fgk9oZHEbexGNURZoXYKkFhgXBz8FzJbnF5Cfy5McA++lBIK5TBaHVF P2Dw8MGNYN0/z8EbB/GFFvAcR0pSDAIVhCtmDTgFw+q9GfGeB95FaZ4/+LA/6OwIP8om 1khw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:in-reply-to:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=L6I/B4SLFpaZEIiweba3CbtmGHnLC7IKT8xBjRz0XUk=; b=xPluTo6FouvZSxAK5azuzvtHnXJfZoYJyENRrtiDNCWK5tJS/Vo7BAo51C0BXfLxoN cI0MirVxc+hMrK+7ezMroUBwskqysLsS8AWpG8zra+jy7mN5ed50CsQx74xhJuUyZz5E HyKS4fb2tdoHNo+08gACTP5qnNSiFsm5Cy7NIEC9y6eK4p0RTh8WmG+7ZE11Z6U+Exay lMxIFmerNGaPBlseaIj6slRdV+M8rs5DW+YapuWQTEREFa8E4FoG4BWomEeBspsTgODP HEzSeK5sW1UPMIQ7YpXpdm2avZfHjtiJs4qaY5GharV/F94CHYlxvlo6TQKrZRUSMusI /d2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=OVA/JrpI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si11417360pfi.355.2018.04.16.11.26.21; Mon, 16 Apr 2018 11:26:36 -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; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=OVA/JrpI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753153AbeDPSZK (ORCPT + 99 others); Mon, 16 Apr 2018 14:25:10 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:60504 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753013AbeDPSZJ (ORCPT ); Mon, 16 Apr 2018 14:25:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=L6I/B4SLFpaZEIiweba3CbtmGHnLC7IKT8xBjRz0XUk=; b=OVA/JrpIMtle +yZl/6YzRiBak8zFn6KJ1Ys+/v1E0c4kleDPf7n3nw39nP7K/+EBFaXer6wAjezGIRdpmithuPP/O qIcr9hQ00sNIuzL3Z5uXI7uLcqKP/G1Ct22QWMgOoV3s/4fRjXOzyOFWjAqb/2rJU3Wip8shpyult elXd0=; Received: from debutante.sirena.org.uk ([2001:470:1f1d:6b5::3] helo=debutante) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1f88oL-0006FH-N9; Mon, 16 Apr 2018 18:25:05 +0000 Received: from broonie by debutante with local (Exim 4.90_1) (envelope-from ) id 1f88oL-0005ek-70; Mon, 16 Apr 2018 19:25:05 +0100 From: Mark Brown To: Naga Sureshkumar Relli Cc: Shubhrajyoti Datta , Naga Sureshkumar Relli , Mark Brown , broonie@kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, michal.simek@xilinx.com, nagasuresh12@gmail.com, shubhrajyoti.datta@xilinx.com, Naga Sureshkumar Relli , linux-spi@vger.kernel.org Subject: Applied "spi: zynqmp: Add pm runtime support" to the spi tree In-Reply-To: <1522069460-4703-1-git-send-email-nagasure@xilinx.com> Message-Id: Date: Mon, 16 Apr 2018 19:25:05 +0100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch spi: zynqmp: Add pm runtime support has been applied to the spi tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 5662c997a3b5e2d267c879c0613be7d7c5c87c37 Mon Sep 17 00:00:00 2001 From: Naga Sureshkumar Relli Date: Mon, 26 Mar 2018 18:34:20 +0530 Subject: [PATCH] spi: zynqmp: Add pm runtime support This patch adds runtime pm functions. Signed-off-by: Shubhrajyoti Datta Signed-off-by: Naga Sureshkumar Relli Signed-off-by: Mark Brown --- drivers/spi/spi-zynqmp-gqspi.c | 86 +++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 18aeaceee286..26d1ac3bf496 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -135,6 +136,7 @@ #define GQSPI_DMA_UNALIGN 0x3 #define GQSPI_DEFAULT_NUM_CS 1 /* Default number of chip selects */ +#define SPI_AUTOSUSPEND_TIMEOUT 3000 enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA}; /** @@ -356,21 +358,9 @@ static void zynqmp_qspi_copy_read_data(struct zynqmp_qspi *xqspi, static int zynqmp_prepare_transfer_hardware(struct spi_master *master) { struct zynqmp_qspi *xqspi = spi_master_get_devdata(master); - int ret; - - ret = clk_enable(xqspi->refclk); - if (ret) - return ret; - - ret = clk_enable(xqspi->pclk); - if (ret) - goto clk_err; zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK); return 0; -clk_err: - clk_disable(xqspi->refclk); - return ret; } /** @@ -387,8 +377,6 @@ static int zynqmp_unprepare_transfer_hardware(struct spi_master *master) struct zynqmp_qspi *xqspi = spi_master_get_devdata(master); zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0); - clk_disable(xqspi->refclk); - clk_disable(xqspi->pclk); return 0; } @@ -959,11 +947,67 @@ static int __maybe_unused zynqmp_qspi_resume(struct device *dev) spi_master_resume(master); + clk_disable(xqspi->refclk); + clk_disable(xqspi->pclk); return 0; } -static SIMPLE_DEV_PM_OPS(zynqmp_qspi_dev_pm_ops, zynqmp_qspi_suspend, - zynqmp_qspi_resume); +/** + * zynqmp_runtime_suspend - Runtime suspend method for the SPI driver + * @dev: Address of the platform_device structure + * + * This function disables the clocks + * + * Return: Always 0 + */ +static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct spi_master *master = platform_get_drvdata(pdev); + struct zynqmp_qspi *xqspi = spi_master_get_devdata(master); + + clk_disable(xqspi->refclk); + clk_disable(xqspi->pclk); + + return 0; +} + +/** + * zynqmp_runtime_resume - Runtime resume method for the SPI driver + * @dev: Address of the platform_device structure + * + * This function enables the clocks + * + * Return: 0 on success and error value on error + */ +static int __maybe_unused zynqmp_runtime_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct spi_master *master = platform_get_drvdata(pdev); + struct zynqmp_qspi *xqspi = spi_master_get_devdata(master); + int ret; + + ret = clk_enable(xqspi->pclk); + if (ret) { + dev_err(dev, "Cannot enable APB clock.\n"); + return ret; + } + + ret = clk_enable(xqspi->refclk); + if (ret) { + dev_err(dev, "Cannot enable device clock.\n"); + clk_disable(xqspi->pclk); + return ret; + } + + return 0; +} + +static const struct dev_pm_ops zynqmp_qspi_dev_pm_ops = { + SET_RUNTIME_PM_OPS(zynqmp_runtime_suspend, + zynqmp_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(zynqmp_qspi_suspend, zynqmp_qspi_resume) +}; /** * zynqmp_qspi_probe: Probe method for the QSPI driver @@ -1023,9 +1067,15 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto clk_dis_pclk; } + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); /* QSPI controller initializations */ zynqmp_qspi_init_hw(xqspi); + pm_runtime_mark_last_busy(&pdev->dev); + pm_runtime_put_autosuspend(&pdev->dev); xqspi->irq = platform_get_irq(pdev, 0); if (xqspi->irq <= 0) { ret = -ENXIO; @@ -1063,6 +1113,8 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) return 0; clk_dis_all: + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_disable(&pdev->dev); clk_disable_unprepare(xqspi->refclk); clk_dis_pclk: clk_disable_unprepare(xqspi->pclk); @@ -1090,6 +1142,8 @@ static int zynqmp_qspi_remove(struct platform_device *pdev) zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0); clk_disable_unprepare(xqspi->refclk); clk_disable_unprepare(xqspi->pclk); + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_disable(&pdev->dev); spi_unregister_master(master); -- 2.17.0