All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: linux-pm@vger.kernel.org, Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org,
	Kevin Hilman <khilman@kernel.org>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Jisheng Zhang <jszhang@marvell.com>,
	John Stultz <john.stultz@linaro.org>,
	Guodong Xu <guodong.xu@linaro.org>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	Haojian Zhuang <haojian.zhuang@linaro.org>,
	Johannes Stezenbach <js@sig21.net>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Lee Jones <lee.jones@linaro.org>, Rajat Jain <rajatja@google.com>
Subject: [Update][PATCH v5 1/3] PM: i2c-designware-platdrv: Clean up PM handling in probe
Date: Mon, 25 Sep 2017 23:10:06 +0200	[thread overview]
Message-ID: <188302021.o3ml4PkeyZ@aspire.rjw.lan> (raw)
In-Reply-To: <2813826.3DA0fVXnVa@aspire.rjw.lan>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The power management handling in dw_i2c_plat_probe() is somewhat
messy and it is rather hard to figure out the code intention for
the case when pm_disabled is set.  In that case, the driver doesn't
enable runtime PM at all, but in addition to that it calls
pm_runtime_forbid() as though it wasn't sure if runtime PM might
be enabled for the device later by someone else.

Although that concern doesn't seem to be actually valid, the
device is clearly still expected to be PM-capable even in the
pm_disabled set case, so a better approach would be to enable
runtime PM for it unconditionally and prevent it from being
runtime-suspended by using pm_runtime_get_noresume().

Make the driver do that.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v4 -> v5: Address the Ulf's comment that pm_runtime_forbid() was not
  suitable for preventing runtime suspends of the device from occurring
  (as it could be overridden by user space) and update the changelog.

  Also drop the tags as the patch changed (although that change shouldn't
  matter on systems where pm_disabled is not set).

v3 -> v4: Added Tested-by tags.

-> v3: Small update of the changelog.

---
 drivers/i2c/busses/i2c-designware-platdrv.c |   34 ++++++++++++++++++----------
 1 file changed, 22 insertions(+), 12 deletions(-)

Index: linux-pm/drivers/i2c/busses/i2c-designware-platdrv.c
===================================================================
--- linux-pm.orig/drivers/i2c/busses/i2c-designware-platdrv.c
+++ linux-pm/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -249,6 +249,14 @@ static void dw_i2c_set_fifo_size(struct
 	}
 }
 
+static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
+{
+	pm_runtime_disable(dev->dev);
+
+	if (dev->pm_disabled)
+		pm_runtime_put_noidle(dev->dev);
+}
+
 static int dw_i2c_plat_probe(struct platform_device *pdev)
 {
 	struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -362,14 +370,17 @@ static int dw_i2c_plat_probe(struct plat
 	ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
 	adap->dev.of_node = pdev->dev.of_node;
 
-	if (dev->pm_disabled) {
-		pm_runtime_forbid(&pdev->dev);
-	} else {
-		pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
-		pm_runtime_use_autosuspend(&pdev->dev);
-		pm_runtime_set_active(&pdev->dev);
-		pm_runtime_enable(&pdev->dev);
-	}
+	/* The code below assumes runtime PM to be disabled. */
+	WARN_ON(pm_runtime_enabled(&pdev->dev));
+
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+
+	if (dev->pm_disabled)
+		pm_runtime_get_noresume(&pdev->dev);
+
+	pm_runtime_enable(&pdev->dev);
 
 	if (dev->mode == DW_IC_SLAVE)
 		ret = i2c_dw_probe_slave(dev);
@@ -382,8 +393,7 @@ static int dw_i2c_plat_probe(struct plat
 	return ret;
 
 exit_probe:
-	if (!dev->pm_disabled)
-		pm_runtime_disable(&pdev->dev);
+	dw_i2c_plat_pm_cleanup(dev);
 exit_reset:
 	if (!IS_ERR_OR_NULL(dev->rst))
 		reset_control_assert(dev->rst);
@@ -402,8 +412,8 @@ static int dw_i2c_plat_remove(struct pla
 
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_put_sync(&pdev->dev);
-	if (!dev->pm_disabled)
-		pm_runtime_disable(&pdev->dev);
+	dw_i2c_plat_pm_cleanup(dev);
+
 	if (!IS_ERR_OR_NULL(dev->rst))
 		reset_control_assert(dev->rst);
 

  parent reply	other threads:[~2017-09-25 21:10 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-03 23:05 [RFT][PATCH 0/2] i2c: designware: Runtime PM aware system sleep handling Rafael J. Wysocki
2017-09-03 23:08 ` [RFT][PATCH 1/2] i2c: designware: Clean up PM handling in dw_i2c_plat_probe() Rafael J. Wysocki
2017-09-05 14:40   ` Jarkko Nikula
2017-09-05 14:41     ` Rafael J. Wysocki
2017-09-03 23:14 ` [RFT][PATCH 2/2] PM / i2c: designware: Clean up system sleep handling without ACPI Rafael J. Wysocki
2017-09-04 10:01   ` [RFT][PATCH v2 " Rafael J. Wysocki
2017-09-05 14:45     ` Mika Westerberg
2017-09-05 14:46       ` Rafael J. Wysocki
2017-09-05 14:58         ` Mika Westerberg
2017-09-05 14:55           ` Rafael J. Wysocki
2017-09-05 15:02             ` Rafael J. Wysocki
2017-09-05 15:07             ` Mika Westerberg
2017-09-05 15:04               ` Rafael J. Wysocki
2017-09-05 15:24                 ` Mika Westerberg
2017-09-05 15:32                   ` Rafael J. Wysocki
2017-09-05 15:41                     ` Mika Westerberg
2017-09-05 21:00                       ` Johannes Stezenbach
2017-09-05 21:22                         ` Rafael J. Wysocki
2017-09-04 10:07   ` [RFT][PATCH " Rafael J. Wysocki
2017-09-05 15:46   ` Andy Shevchenko
2017-09-05 23:41 ` [RFT][PATCH v3 0/3] i2c: designware: Runtime PM aware system sleep handling Rafael J. Wysocki
2017-09-05 23:43   ` [RFT][PATCH v3 1/3] i2c: designware: Clean up PM handling in dw_i2c_plat_probe() Rafael J. Wysocki
2017-09-05 23:46   ` [RFT][PATCH v3 2/3] PM / mfd: intel-lpss: Push system sleep callbacks to late/early stages Rafael J. Wysocki
2017-09-05 23:48   ` [RFT][PATCH v3 3/3] PM / i2c: designware: Clean up system sleep handling Rafael J. Wysocki
2017-09-06  9:16   ` [RFT][PATCH v3 0/3] i2c: designware: Runtime PM aware " Johannes Stezenbach
2017-09-06  9:55     ` Rafael J. Wysocki
2017-09-06 19:59       ` Johannes Stezenbach
2017-09-06 21:37         ` Rafael J. Wysocki
2017-09-08  7:34       ` Johannes Stezenbach
2017-09-06 11:06   ` Mika Westerberg
2017-09-06 11:14     ` Rafael J. Wysocki
2017-09-06 13:46     ` Jarkko Nikula
2017-09-24 23:13   ` [PATCH v4 " Rafael J. Wysocki
2017-09-24 23:17     ` [PATCH v4 1/3] PM: i2c-designware-platdrv: Clean up PM handling in probe Rafael J. Wysocki
2017-09-25 19:12       ` Ulf Hansson
2017-09-25 20:45         ` Rafael J. Wysocki
2017-09-25 21:10       ` Rafael J. Wysocki [this message]
2017-10-05 11:00         ` [Update][PATCH v5 " Wolfram Sang
2017-09-24 23:20     ` [PATCH v4 2/3] PM / mfd: intel-lpss: Push system sleep callbacks to late/early stages Rafael J. Wysocki
2017-09-25  7:28       ` Wolfram Sang
2017-09-25 12:50         ` Rafael J. Wysocki
2017-09-25 14:24           ` Wolfram Sang
2017-10-02 23:58         ` Rafael J. Wysocki
2017-09-28 19:19       ` Lee Jones
2017-09-28 20:51         ` Rafael J. Wysocki
2017-10-05 11:00       ` Wolfram Sang
2017-09-24 23:30     ` [PATCH v4 3/3] PM: i2c-designware-platdrv: Suspend/resume at the " Rafael J. Wysocki
2017-10-05 11:00       ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=188302021.o3ml4PkeyZ@aspire.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=guodong.xu@linaro.org \
    --cc=haojian.zhuang@linaro.org \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=john.stultz@linaro.org \
    --cc=js@sig21.net \
    --cc=jszhang@marvell.com \
    --cc=khilman@kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rajatja@google.com \
    --cc=sumit.semwal@linaro.org \
    --cc=ulf.hansson@linaro.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.