driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/4] Tegra Video Decoder driver power management corrections
@ 2020-05-14 21:08 Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 1/4] media: staging: tegra-vde: Balance runtime PM use-count on resume failure Dmitry Osipenko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-05-14 21:08 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Mauro Carvalho Chehab,
	Hans Verkuil, Dan Carpenter
  Cc: linux-tegra, devel, linux-kernel, linux-media

Hello,

This small series addresses a Runtime PM issue that was discovered during
of Tegra VI driver reviewing by balancing RPM usage count on RPM resume
failure. Secondly it fixes reboot on some Tegra devices due to bootloader
expecting VDE power partition to be ON at the boot time, which wasn't
happening in case of a warm re-booting (i.e. by PMC resetting).

Dmitry Osipenko (4):
  media: staging: tegra-vde: Balance runtime PM use-count on resume
    failure
  media: staging: tegra-vde: Runtime PM is always available on Tegra
  media: staging: tegra-vde: Turn ON power domain on shutdown
  media: staging: tegra-vde: Power-cycle hardware on probe

 drivers/staging/media/tegra-vde/vde.c | 45 +++++++++++++++++----------
 1 file changed, 29 insertions(+), 16 deletions(-)

-- 
2.26.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/4] media: staging: tegra-vde: Balance runtime PM use-count on resume failure
  2020-05-14 21:08 [PATCH v1 0/4] Tegra Video Decoder driver power management corrections Dmitry Osipenko
@ 2020-05-14 21:08 ` Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 2/4] media: staging: tegra-vde: Runtime PM is always available on Tegra Dmitry Osipenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-05-14 21:08 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Mauro Carvalho Chehab,
	Hans Verkuil, Dan Carpenter
  Cc: linux-tegra, devel, linux-kernel, linux-media

The RPM's use-count is getting incremented regardless of
pm_runtime_get_sync() success or fail. It's up to a driver how to
handle the failed RPM. In the case of VDE driver, the RPM's use-count
should be restored if runtime-resume fails.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/staging/media/tegra-vde/vde.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
index d3e63512a765..803e5dda4bb5 100644
--- a/drivers/staging/media/tegra-vde/vde.c
+++ b/drivers/staging/media/tegra-vde/vde.c
@@ -776,8 +776,10 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
 		goto release_dpb_frames;
 
 	ret = pm_runtime_get_sync(dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(dev);
 		goto unlock;
+	}
 
 	/*
 	 * We rely on the VDE registers reset value, otherwise VDE
-- 
2.26.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/4] media: staging: tegra-vde: Runtime PM is always available on Tegra
  2020-05-14 21:08 [PATCH v1 0/4] Tegra Video Decoder driver power management corrections Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 1/4] media: staging: tegra-vde: Balance runtime PM use-count on resume failure Dmitry Osipenko
@ 2020-05-14 21:08 ` Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 3/4] media: staging: tegra-vde: Turn ON power domain on shutdown Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 4/4] media: staging: tegra-vde: Power-cycle hardware on probe Dmitry Osipenko
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-05-14 21:08 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Mauro Carvalho Chehab,
	Hans Verkuil, Dan Carpenter
  Cc: linux-tegra, devel, linux-kernel, linux-media

Runtime PM is always available on Tegra nowadays since commit 40b2bb1b132a
("ARM: tegra: enforce PM requirement"), hence the case of unavailable RPM
doesn't need to be handled.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/staging/media/tegra-vde/vde.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
index 803e5dda4bb5..85cbbc8f70d3 100644
--- a/drivers/staging/media/tegra-vde/vde.c
+++ b/drivers/staging/media/tegra-vde/vde.c
@@ -1068,17 +1068,8 @@ static int tegra_vde_probe(struct platform_device *pdev)
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 300);
 
-	if (!pm_runtime_enabled(dev)) {
-		err = tegra_vde_runtime_resume(dev);
-		if (err)
-			goto err_misc_unreg;
-	}
-
 	return 0;
 
-err_misc_unreg:
-	misc_deregister(&vde->miscdev);
-
 err_deinit_iommu:
 	tegra_vde_iommu_deinit(vde);
 
@@ -1093,13 +1084,6 @@ static int tegra_vde_remove(struct platform_device *pdev)
 {
 	struct tegra_vde *vde = platform_get_drvdata(pdev);
 	struct device *dev = &pdev->dev;
-	int err;
-
-	if (!pm_runtime_enabled(dev)) {
-		err = tegra_vde_runtime_suspend(dev);
-		if (err)
-			return err;
-	}
 
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
-- 
2.26.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 3/4] media: staging: tegra-vde: Turn ON power domain on shutdown
  2020-05-14 21:08 [PATCH v1 0/4] Tegra Video Decoder driver power management corrections Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 1/4] media: staging: tegra-vde: Balance runtime PM use-count on resume failure Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 2/4] media: staging: tegra-vde: Runtime PM is always available on Tegra Dmitry Osipenko
@ 2020-05-14 21:08 ` Dmitry Osipenko
  2020-05-14 21:08 ` [PATCH v1 4/4] media: staging: tegra-vde: Power-cycle hardware on probe Dmitry Osipenko
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-05-14 21:08 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Mauro Carvalho Chehab,
	Hans Verkuil, Dan Carpenter
  Cc: linux-tegra, devel, linux-kernel, linux-media

On some devices bootloader isn't ready to a clamped VDE power, and thus,
machine hangs on a warm reboot (CPU reset). The VDE power partition is
turned ON by default on a cold boot, hence VDE driver should keep power
partition enabled on system's reboot too. This fixes hang on a warm reboot
on a Tegra20 Acer A500 device, which is handy if Embedded Controller
driver is unavailable, i.e. cold reboot can't be performed.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/staging/media/tegra-vde/vde.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
index 85cbbc8f70d3..b64e35b86fb4 100644
--- a/drivers/staging/media/tegra-vde/vde.c
+++ b/drivers/staging/media/tegra-vde/vde.c
@@ -1085,9 +1085,17 @@ static int tegra_vde_remove(struct platform_device *pdev)
 	struct tegra_vde *vde = platform_get_drvdata(pdev);
 	struct device *dev = &pdev->dev;
 
+	pm_runtime_get_sync(dev);
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 
+	/*
+	 * Balance RPM state, the VDE power domain is left ON and hardware
+	 * is clock-gated. It's safe to reboot machine now.
+	 */
+	pm_runtime_put_noidle(dev);
+	clk_disable_unprepare(vde->clk);
+
 	misc_deregister(&vde->miscdev);
 
 	tegra_vde_dmabuf_cache_unmap_all(vde);
@@ -1099,6 +1107,16 @@ static int tegra_vde_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void tegra_vde_shutdown(struct platform_device *pdev)
+{
+	/*
+	 * On some devices bootloader isn't ready to a power-gated VDE on
+	 * a warm-reboot, machine will hang in that case.
+	 */
+	if (pm_runtime_status_suspended(&pdev->dev))
+		tegra_vde_runtime_resume(&pdev->dev);
+}
+
 static __maybe_unused int tegra_vde_pm_suspend(struct device *dev)
 {
 	struct tegra_vde *vde = dev_get_drvdata(dev);
@@ -1144,6 +1162,7 @@ MODULE_DEVICE_TABLE(of, tegra_vde_of_match);
 static struct platform_driver tegra_vde_driver = {
 	.probe		= tegra_vde_probe,
 	.remove		= tegra_vde_remove,
+	.shutdown	= tegra_vde_shutdown,
 	.driver		= {
 		.name		= "tegra-vde",
 		.of_match_table = tegra_vde_of_match,
-- 
2.26.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 4/4] media: staging: tegra-vde: Power-cycle hardware on probe
  2020-05-14 21:08 [PATCH v1 0/4] Tegra Video Decoder driver power management corrections Dmitry Osipenko
                   ` (2 preceding siblings ...)
  2020-05-14 21:08 ` [PATCH v1 3/4] media: staging: tegra-vde: Turn ON power domain on shutdown Dmitry Osipenko
@ 2020-05-14 21:08 ` Dmitry Osipenko
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Osipenko @ 2020-05-14 21:08 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Mauro Carvalho Chehab,
	Hans Verkuil, Dan Carpenter
  Cc: linux-tegra, devel, linux-kernel, linux-media

VDE partition is left turned ON after bootloader on most devices, hence
let's ensure that it's turned OFF in order to lower power leakage while
hardware is idling by turning it ON and OFF during of the driver's probe.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/staging/media/tegra-vde/vde.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
index b64e35b86fb4..3be96c36bf43 100644
--- a/drivers/staging/media/tegra-vde/vde.c
+++ b/drivers/staging/media/tegra-vde/vde.c
@@ -1068,6 +1068,14 @@ static int tegra_vde_probe(struct platform_device *pdev)
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 300);
 
+	/*
+	 * VDE partition may be left ON after bootloader, hence let's
+	 * power-cycle it in order to put hardware into a predictable lower
+	 * power state.
+	 */
+	pm_runtime_get_sync(dev);
+	pm_runtime_put(dev);
+
 	return 0;
 
 err_deinit_iommu:
-- 
2.26.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-14 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 21:08 [PATCH v1 0/4] Tegra Video Decoder driver power management corrections Dmitry Osipenko
2020-05-14 21:08 ` [PATCH v1 1/4] media: staging: tegra-vde: Balance runtime PM use-count on resume failure Dmitry Osipenko
2020-05-14 21:08 ` [PATCH v1 2/4] media: staging: tegra-vde: Runtime PM is always available on Tegra Dmitry Osipenko
2020-05-14 21:08 ` [PATCH v1 3/4] media: staging: tegra-vde: Turn ON power domain on shutdown Dmitry Osipenko
2020-05-14 21:08 ` [PATCH v1 4/4] media: staging: tegra-vde: Power-cycle hardware on probe Dmitry Osipenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).