From patchwork Wed Aug 16 22:17:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Franklin Cooper X-Patchwork-Id: 9904691 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 2E14A60231 for ; Wed, 16 Aug 2017 22:39:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15DE628518 for ; Wed, 16 Aug 2017 22:39:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09584286FB; Wed, 16 Aug 2017 22:39:06 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW 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 7452428518 for ; Wed, 16 Aug 2017 22:39:05 +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=W8e/TlrQWsWGJHFDPA/VypbvOpXuWpDi3pEUTCtHN2k=; b=tJ1+ZQgsoY58x3 N2mJDYtGt+kXt3rm5/vtvrVPA2kJabmQrkqjooIAQJpUOz7l9EP1cb4vskOwIeDcBWjRrV3HOH5Qc 2xDANBAhLhdIdS5GCmXtYjOhFSxi1/reuo3dVaCVWBn4cwyikvXBmoghrfquiq2PqKcyQuf6w3zhO h8O/Gvfa/RV4G06L/xA1wVfR6pjHkXIlbzIR0W5MmPM67/M1Y3Rm5ccxqyBfSynzE/YiPTeupA+tW DhwDauRICLJmtG1W9/mLhJf1RhLlZxD/rbpD4qYoVl3J9FH8ag8r9LAJCh4rguu+f9s4muWoRAKoT CuIRG6sKjiOWZXQhl9bg==; 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 1di6xn-0000Pt-J4; Wed, 16 Aug 2017 22:38:59 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1di6xl-0000Em-Cu for linux-arm-kernel@bombadil.infradead.org; Wed, 16 Aug 2017 22:38:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hImjKq7p3BE9ztHbYOtgVK6NktZQUarK9i5Xo4DI3yc=; b=Dp4jd6Nm9dvlXpo0zFDwgDMXZ Wc+9xBClr9HIDd7VMudfL4AH14jtwWl3JCn3omwKCAcwmDj9cEUacT4zX6dvMLpx2ydokcWiiFf71 HBs+3eXco6rh1ktDadLtk/ek0bH2/f0iJbNdnJCIY2jPuMIqurwvvabwlXgWW6PixucuyoGuBO1lS n+0eoySre8qNCdFxEfLqU8lgD7iynVnudYhU4SPwFROMvUgDIG9dxrAGZtqA1T408gP0yfVY0ELPP 3WMTMRqfGmTrvhoMsSDolxyoc6GTbS0VNj0T0DHWCpxIxgMHSRACYTVO/6fjgQAjyeLLRnhhapWn+ /bfGsFATA==; Received: from fllnx209.ext.ti.com ([198.47.19.16]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1di6gN-0005by-Ii for linux-arm-kernel@lists.infradead.org; Wed, 16 Aug 2017 22:21:01 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v7GMHdQS017344; Wed, 16 Aug 2017 17:17:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1502921859; bh=vHMuVlUjTfOUt52NhHStPRv0uN5pSz5qF7fq8ZBi/yA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=s4A2uQyRguknF0pyJT06fwFUYkcHfLUB0j68ZBksxTCdJAYv5FaPKZwLEtC5a+IDk JhN6UhqbSqPyl4T/p3dGkh1wrSsVIfAVSakkE31qnOB5ZtFki+Ta+2pW/9TnOAYEyl ucz8BVlV/JQJ1dgpsS6tQYSzhPWLDb6TrEpu1T4k= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v7GMHYE9026041; Wed, 16 Aug 2017 17:17:34 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Wed, 16 Aug 2017 17:17:33 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Wed, 16 Aug 2017 17:17:33 -0500 Received: from dbdmail01.india.ti.com (dbdmail01.india.ti.com [172.24.162.206]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v7GMHWLQ003850; Wed, 16 Aug 2017 17:17:33 -0500 Received: from uda0273011.dhcp.ti.com (uda0273011.dhcp.ti.com [128.247.59.135]) by dbdmail01.india.ti.com (8.14.3/8.14.3/SuSE Linux 0.8) with ESMTP id v7GMHKkN028296; Thu, 17 Aug 2017 03:47:28 +0530 From: Franklin S Cooper Jr To: , , , , , , , , , Subject: [PATCH v2 2/3] i2c: davinci: Add PM Runtime Support Date: Wed, 16 Aug 2017 17:17:14 -0500 Message-ID: <20170816221715.15027-3-fcooper@ti.com> X-Mailer: git-send-email 2.9.4.dirty In-Reply-To: <20170816221715.15027-1-fcooper@ti.com> References: <20170816221715.15027-1-fcooper@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170816_232059_835097_BD65108F X-CRM114-Status: GOOD ( 18.52 ) 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: Franklin S Cooper Jr 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 66AK2G has I2C instances that are not apart of the ALWAYS_ON power domain like other Keystone 2 SoCs and OMAPL138. Therefore, pm_runtime is required to insure the power domain used by the specific I2C instance is properly turned on along with its functional clock. Signed-off-by: Franklin S Cooper Jr --- Version 2 changes: Move initial calls to pm runtime autosuspend before pm_runtime_enable drivers/i2c/busses/i2c-davinci.c | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index b8c4353..6b1930d 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -36,6 +36,7 @@ #include #include #include +#include /* ----- global defines ----------------------------------------------- */ @@ -122,6 +123,9 @@ /* set the SDA GPIO low */ #define DAVINCI_I2C_DCLR_PDCLR1 BIT(1) +/* timeout for pm runtime autosuspend */ +#define DAVINCI_I2C_PM_TIMEOUT 1000 /* ms */ + struct davinci_i2c_dev { struct device *dev; void __iomem *base; @@ -541,10 +545,17 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); + ret = pm_runtime_get_sync(dev->dev); + if (ret < 0) { + dev_err(dev->dev, "Failed to runtime_get device: %d\n", ret); + pm_runtime_put_noidle(dev->dev); + return ret; + } + ret = i2c_davinci_wait_bus_not_busy(dev); if (ret < 0) { dev_warn(dev->dev, "timeout waiting for bus ready\n"); - return ret; + goto out; } for (i = 0; i < num; i++) { @@ -552,14 +563,19 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num, ret); if (ret < 0) - return ret; + goto out; } + ret = num; #ifdef CONFIG_CPU_FREQ complete(&dev->xfr_complete); #endif - return num; +out: + pm_runtime_mark_last_busy(dev->dev); + pm_runtime_put_autosuspend(dev->dev); + + return ret; } static u32 i2c_davinci_func(struct i2c_adapter *adap) @@ -599,6 +615,9 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) int count = 0; u16 w; + if (pm_runtime_suspended(dev->dev)) + return IRQ_NONE; + while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) { dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); if (count++ == 100) { @@ -802,7 +821,6 @@ static int davinci_i2c_probe(struct platform_device *pdev) dev->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(dev->clk)) return PTR_ERR(dev->clk); - clk_prepare_enable(dev->clk); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); dev->base = devm_ioremap_resource(&pdev->dev, mem); @@ -811,6 +829,18 @@ static int davinci_i2c_probe(struct platform_device *pdev) goto err_unuse_clocks; } + pm_runtime_set_autosuspend_delay(dev->dev, + DAVINCI_I2C_PM_TIMEOUT); + pm_runtime_use_autosuspend(dev->dev); + + pm_runtime_enable(dev->dev); + + r = pm_runtime_get_sync(dev->dev); + if (r < 0) { + dev_err(dev->dev, "failed to runtime_get device: %d\n", r); + goto err_unuse_clocks; + } + i2c_davinci_init(dev); r = devm_request_irq(&pdev->dev, dev->irq, i2c_davinci_isr, 0, @@ -849,10 +879,16 @@ static int davinci_i2c_probe(struct platform_device *pdev) if (r) goto err_unuse_clocks; + pm_runtime_mark_last_busy(dev->dev); + pm_runtime_put_autosuspend(dev->dev); + return 0; err_unuse_clocks: - clk_disable_unprepare(dev->clk); + pm_runtime_dont_use_autosuspend(dev->dev); + pm_runtime_put_sync(dev->dev); + pm_runtime_disable(dev->dev); + dev->clk = NULL; return r; } @@ -860,16 +896,26 @@ static int davinci_i2c_probe(struct platform_device *pdev) static int davinci_i2c_remove(struct platform_device *pdev) { struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); + int ret; i2c_davinci_cpufreq_deregister(dev); i2c_del_adapter(&dev->adapter); - clk_disable_unprepare(dev->clk); + ret = pm_runtime_get_sync(&pdev->dev); + if (ret < 0) { + pm_runtime_put_noidle(&pdev->dev); + return ret; + } + dev->clk = NULL; davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); + pm_runtime_dont_use_autosuspend(dev->dev); + pm_runtime_put_sync(dev->dev); + pm_runtime_disable(dev->dev); + return 0; } @@ -880,7 +926,6 @@ static int davinci_i2c_suspend(struct device *dev) /* put I2C into reset */ davinci_i2c_reset_ctrl(i2c_dev, 0); - clk_disable_unprepare(i2c_dev->clk); return 0; } @@ -889,7 +934,6 @@ static int davinci_i2c_resume(struct device *dev) { struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev); - clk_prepare_enable(i2c_dev->clk); /* take I2C out of reset */ davinci_i2c_reset_ctrl(i2c_dev, 1); @@ -899,6 +943,8 @@ static int davinci_i2c_resume(struct device *dev) static const struct dev_pm_ops davinci_i2c_pm = { .suspend = davinci_i2c_suspend, .resume = davinci_i2c_resume, + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) }; #define davinci_i2c_pm_ops (&davinci_i2c_pm)