Skip to contentSkip to conversation

ALSA: hda/tegra: enable clock during probe

PATCH Superseded Sameer Pujar 3 participants 13 messages Jan 24, 2019 – Jan 30, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda/tegra: enable clock during probe

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

---
 sound/pci/hda/hda_tegra.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)
sound/pci/hda/hda_tegra.c +22 -9
index c8d18dc..155c2f5 100644
@@ -219,7 +219,6 @@ static int hda_tegra_enable_clocks(struct hda_tegra *data)
 	return rc;
 }
 
-#ifdef CONFIG_PM_SLEEP
 static void hda_tegra_disable_clocks(struct hda_tegra *data)
 {
 	clk_disable_unprepare(data->hda2hdmi_clk);
@@ -227,6 +226,7 @@ static void hda_tegra_disable_clocks(struct hda_tegra *data)
 	clk_disable_unprepare(data->hda_clk);
 }
 
+#ifdef CONFIG_PM_SLEEP
 /*
  * power management
  */
@@ -257,7 +257,6 @@ static int hda_tegra_resume(struct device *dev)
 }
 #endif /* CONFIG_PM_SLEEP */
 
-#ifdef CONFIG_PM
 static int hda_tegra_runtime_suspend(struct device *dev)
 {
 	struct snd_card *card = dev_get_drvdata(dev);
@@ -283,7 +282,7 @@ static int hda_tegra_runtime_resume(struct device *dev)
 	int rc;
 
 	rc = hda_tegra_enable_clocks(hda);
-	if (rc != 0)
+	if (rc)
 		return rc;
 	if (chip && chip->running) {
 		hda_tegra_init(hda);
@@ -292,7 +291,6 @@ static int hda_tegra_runtime_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM */
 
 static const struct dev_pm_ops hda_tegra_pm = {
 	SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume)
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);
 
 	return 0;
@@ -571,7 +576,14 @@ static void hda_tegra_probe_work(struct work_struct *work)
 	struct platform_device *pdev = to_platform_device(hda->dev);
 	int err;
 
-	pm_runtime_get_sync(hda->dev);
+	err = pm_runtime_get_sync(hda->dev);
+	if (err < 0) {
+		dev_err(hda->dev,
+			"failed in pm_runtime_get_syc with err = %d\n",
+			err);
+		return;
+	}
+
 	err = hda_tegra_first_init(chip, pdev);
 	if (err < 0)
 		goto out_free;
@@ -599,12 +611,13 @@ static void hda_tegra_probe_work(struct work_struct *work)
 
 static int hda_tegra_remove(struct platform_device *pdev)
 {
-	int ret;
-
-	ret = snd_card_free(dev_get_drvdata(&pdev->dev));
 	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		hda_tegra_runtime_suspend(&pdev->dev);
+		pm_runtime_set_suspended(&pdev->dev);
+	}
 
-	return ret;
+	return snd_card_free(dev_get_drvdata(&pdev->dev));
 }
 
 static void hda_tegra_shutdown(struct platform_device *pdev)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 16 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 12 lines
sound/pci/hda/hda_tegra.c +7 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

sound/pci/hda/hda_tegra.c static void hda_tegra_probe_work(struct work_struct *work) · line 585

Quoted 12 lines
sound/pci/hda/hda_tegra.c +7 -1
@@ -571,7 +576,14 @@ static void hda_tegra_probe_work(struct work_struct *work)
 	struct platform_device *pdev = to_platform_device(hda->dev);
 	int err;
 
-	pm_runtime_get_sync(hda->dev);
+	err = pm_runtime_get_sync(hda->dev);
+	if (err < 0) {
+		dev_err(hda->dev,
+			"failed in pm_runtime_get_syc with err = %d\n",
+			err);
+		return;
+	}

This pm_runtime_get_sync() is needed just because you enabled runtime PM before probe_work. Why not deferring the runtime PM enablement after probing done?

That is what we need is the hda_tegra_enable_clocks() call at probe unconditionally before enabling runtime PM.

Quoted 7 lines
sound/pci/hda/hda_tegra.c +0 -0
 	err = hda_tegra_first_init(chip, pdev);
 	if (err < 0)
 		goto out_free;
@@ -599,12 +611,13 @@ static void hda_tegra_probe_work(struct work_struct *work)
 
 static int hda_tegra_remove(struct platform_device *pdev)
 {

sound/pci/hda/hda_tegra.c static void hda_tegra_probe_work(struct work_struct *work) · line 619

Quoted 10 lines
sound/pci/hda/hda_tegra.c +5 -4
-	int ret;
-
-	ret = snd_card_free(dev_get_drvdata(&pdev->dev));
 	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		hda_tegra_runtime_suspend(&pdev->dev);
+		pm_runtime_set_suspended(&pdev->dev);
+	}
-	return ret;
+	return snd_card_free(dev_get_drvdata(&pdev->dev));

Forcing the suspend *before* snd_card_free() doesn't sound right. It's the point before the disconnect and release procedure of all the rest. That is, the other hardware components are still active at this point.

thanks,

Takashi

#2 lore raw
Quoted 37 lines · Takashi Iwai
Quoted 15 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 12 lines
sound/pci/hda/hda_tegra.c +7 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
  	if (!azx_has_pm_runtime(chip))
  		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
  	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 4 lines
sound/pci/hda/hda_tegra.c +0 -0
@@ -571,7 +576,14 @@ static void hda_tegra_probe_work(struct work_struct *work)
  	struct platform_device *pdev = to_platform_device(hda->dev);
  	int err;
 
Quoted 11 lines

sound/pci/hda/hda_tegra.c static void hda_tegra_probe_work(struct work_struct *work) · line 585

Quoted 8 lines
sound/pci/hda/hda_tegra.c +7 -1
-	pm_runtime_get_sync(hda->dev);
+	err = pm_runtime_get_sync(hda->dev);
+	if (err < 0) {
+		dev_err(hda->dev,
+			"failed in pm_runtime_get_syc with err = %d\n",
+			err);
+		return;
+	}

This pm_runtime_get_sync() is needed just because you enabled runtime PM before probe_work. Why not deferring the runtime PM enablement after probing done?

I think what you are suggesting can be done and simplify things further. I can get rid of pm_runtime_get_sync/pm_runtime_put in probe work.

Quoted 17 lines

That is what we need is the hda_tegra_enable_clocks() call at probe unconditionally before enabling runtime PM.

Quoted 14 lines
sound/pci/hda/hda_tegra.c +3 -3
  	err = hda_tegra_first_init(chip, pdev);
  	if (err < 0)
  		goto out_free;
@@ -599,12 +611,13 @@ static void hda_tegra_probe_work(struct work_struct *work)
 
  static int hda_tegra_remove(struct platform_device *pdev)
  {
-	int ret;
-
-	ret = snd_card_free(dev_get_drvdata(&pdev->dev));
  	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		hda_tegra_runtime_suspend(&pdev->dev);
+		pm_runtime_set_suspended(&pdev->dev);
Quoted 8 lines

sound/pci/hda/hda_tegra.c static void hda_tegra_probe_work(struct work_struct *work) · line 620

Quoted 3 lines
sound/pci/hda/hda_tegra.c +2 -1
+	}
-	return ret;
+	return snd_card_free(dev_get_drvdata(&pdev->dev));

Forcing the suspend *before* snd_card_free() doesn't sound right. It's the point before the disconnect and release procedure of all the rest. That is, the other hardware components are still active at this point.

Ok, I will keep the sequence same and publish updated version.

Thanks,
Sameer.

Quoted 4 lines

thanks,

Takashi

maintainer
#3 lore raw
In reply to Takashi Iwai
Quoted 23 lines · Takashi Iwai
Quoted 16 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

Quoted 4 lines
sound/pci/hda/hda_tegra.c +0 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
Quoted 10 lines

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 8 lines
sound/pci/hda/hda_tegra.c +7 -0
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Why? IMO it is better to have a single handler for resuming the device and so if RPM is not enabled we call the handler directly. This is what we have been advised to do in the past and do in other drivers. See ...

sound/soc/tegra/tegra30_i2s.c

Quoted 5 lines
Quoted 5 lines
sound/pci/hda/hda_tegra.c +0 -0
@@ -571,7 +576,14 @@ static void hda_tegra_probe_work(struct work_struct *work)
 	struct platform_device *pdev = to_platform_device(hda->dev);
 	int err;
 
Quoted 12 lines

sound/pci/hda/hda_tegra.c static void hda_tegra_probe_work(struct work_struct *work) · line 585

Quoted 8 lines
sound/pci/hda/hda_tegra.c +7 -1
-	pm_runtime_get_sync(hda->dev);
+	err = pm_runtime_get_sync(hda->dev);
+	if (err < 0) {
+		dev_err(hda->dev,
+			"failed in pm_runtime_get_syc with err = %d\n",
+			err);
+		return;
+	}

This pm_runtime_get_sync() is needed just because you enabled runtime PM before probe_work. Why not deferring the runtime PM enablement after probing done?

That would be fine with me.

Quoted 2 lines

That is what we need is the hda_tegra_enable_clocks() call at probe unconditionally before enabling runtime PM.

I think that calling hda_tegra_runtime_resume as above is sufficient. The nice thing about calling the runtime_resume function is that if for a future device there is something else in addition to clocks, say a reset, that also needs to be handled, we just added to the runtime_resume/suspend handlers and we are done.

Cheers
Jon

Signature · 1 line
nvpublic
#4 lore raw
Quoted 37 lines · Jon Hunter
Quoted 23 lines · Takashi Iwai
Quoted 16 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

Quoted 4 lines
sound/pci/hda/hda_tegra.c +0 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
Quoted 10 lines

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 8 lines
sound/pci/hda/hda_tegra.c +7 -0
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 3 lines

Why? IMO it is better to have a single handler for resuming the device and so if RPM is not enabled we call the handler directly. This is what we have been advised to do in the past and do in other drivers. See ...

The point is that we're not "resuming" anything there. It's in the early probe stage, and the device state is uninitialized, not really suspended. It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Takashi

maintainer
#5 lore raw
Quoted 39 lines · Takashi Iwai
Quoted 37 lines · Jon Hunter
Quoted 33 lines · Takashi Iwai
Quoted 16 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 12 lines
sound/pci/hda/hda_tegra.c +7 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 8 lines
Quoted 3 lines

Why? IMO it is better to have a single handler for resuming the device and so if RPM is not enabled we call the handler directly. This is what we have been advised to do in the past and do in other drivers. See ...

The point is that we're not "resuming" anything there. It's in the early probe stage, and the device state is uninitialized, not really suspended. It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

Furthermore, there are other various drivers in the kernel that do the same ...

drivers/i2c/busses/i2c-img-scb.c
drivers/dma/xilinx/zynqmp_dma.c
drivers/gpu/drm/arm/malidp_drv.c

Cheers
Jon

Signature · 1 line
nvpublic
#6 lore raw
Quoted 51 lines · Jon Hunter
Quoted 39 lines · Takashi Iwai
Quoted 37 lines · Jon Hunter
Quoted 33 lines · Takashi Iwai
Quoted 16 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 12 lines
sound/pci/hda/hda_tegra.c +7 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 8 lines
Quoted 3 lines

Why? IMO it is better to have a single handler for resuming the device and so if RPM is not enabled we call the handler directly. This is what we have been advised to do in the past and do in other drivers. See ...

The point is that we're not "resuming" anything there. It's in the early probe stage, and the device state is uninitialized, not really suspended. It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 5 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Although there are some magical pm_runtime_*() in some places, most of such pm_runtime_get_sync() is for the actual runtime PM management (to prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls. Really.

Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

thanks,

Takashi

maintainer
#7 lore raw
Quoted 59 lines · Takashi Iwai
Quoted 51 lines · Jon Hunter
Quoted 39 lines · Takashi Iwai
Quoted 37 lines · Jon Hunter
Quoted 33 lines · Takashi Iwai
Quoted 16 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

sound/pci/hda/hda_tegra.c static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 12 lines
sound/pci/hda/hda_tegra.c +7 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
 	if (!azx_has_pm_runtime(chip))
 		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
 	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 8 lines
Quoted 3 lines

Why? IMO it is better to have a single handler for resuming the device and so if RPM is not enabled we call the handler directly. This is what we have been advised to do in the past and do in other drivers. See ...

The point is that we're not "resuming" anything there. It's in the early probe stage, and the device state is uninitialized, not really suspended. It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 5 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Quoted 7 lines

Although there are some magical pm_runtime_*() in some places, most of such pm_runtime_get_sync() is for the actual runtime PM management (to prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls. Really.

Yes agree.

Quoted 4 lines
Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

I don't its less readable. However, I do think it is less error prone :-)

Jon

Signature · 1 line
nvpublic
#8 lore raw
Quoted 57 lines · Jon Hunter
Quoted 56 lines · Takashi Iwai
Quoted 44 lines · Jon Hunter
Quoted 35 lines · Takashi Iwai
Quoted 33 lines · Jon Hunter
Quoted 31 lines · Takashi Iwai
Quoted 15 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not. If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
* return code check for pm_runtime_get_sync() to take care of failure and exit gracefully.
* In remove path runtime PM is disabled before calling snd_card_free().
* hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
* runtime PM callbacks moved out of CONFIG_PM check

(snip)

Review static int hda_tegra_probe(struct platform_device *pdev) · line 563

Quoted 12 lines
(quoted diff) +7 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct platform_device *pdev)
  	if (!azx_has_pm_runtime(chip))
  		pm_runtime_forbid(hda->dev);
 
+	/* explicit resume if runtime PM is disabled */
+	if (!pm_runtime_enabled(hda->dev)) {
+		err = hda_tegra_runtime_resume(hda->dev);
+		if (err)
+			goto out_free;
+	}
+
  	schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 7 lines
Quoted 3 lines

Why? IMO it is better to have a single handler for resuming the device and so if RPM is not enabled we call the handler directly. This is what we have been advised to do in the past and do in other drivers. See ...

The point is that we're not "resuming" anything there. It's in the early probe stage, and the device state is uninitialized, not really suspended. It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 5 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Although there are some magical pm_runtime_*() in some places, most of such pm_runtime_get_sync() is for the actual runtime PM management (to prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

Quoted 8 lines
Quoted 2 lines

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls. Really.

Yes agree.

Quoted 3 lines
Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

I don't its less readable. However, I do think it is less error prone :-)

Do we have a consensus here? Request others to provide opinions to help close on this.

Thanks,
Sameer.

Quoted 2 lines

Jon

maintainer
#9 lore raw
Quoted 71 lines · Sameer Pujar
Quoted 69 lines · Jon Hunter
Quoted 59 lines · Takashi Iwai
Quoted 52 lines · Jon Hunter
Quoted 46 lines · Takashi Iwai
Quoted 38 lines · Jon Hunter
Quoted 23 lines · Takashi Iwai
Quoted 20 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks
will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not.
If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
   * return code check for pm_runtime_get_sync() to take care of failure
     and exit gracefully.
   * In remove path runtime PM is disabled before calling snd_card_free().
   * hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
   * runtime PM callbacks moved out of CONFIG_PM check

(snip)

Quoted 13 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct
 platform_device *pdev)
       if (!azx_has_pm_runtime(chip))
           pm_runtime_forbid(hda->dev);
Quoted 8 lines

  +    /* explicit resume if runtime PM is disabled */ +    if (!pm_runtime_enabled(hda->dev)) {
+        err = hda_tegra_runtime_resume(hda->dev); +        if (err)
+            goto out_free;
+    }
+
      schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 6 lines

Why? IMO it is better to have a single handler for resuming the device
and so if RPM is not enabled we call the handler directly. This is what
we have been advised to do in the past and do in other drivers. See ...

Quoted 4 lines

The point is that we're not "resuming" anything there.  It's in the early probe stage, and the device state is uninitialized, not really suspended.  It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 5 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Quoted 7 lines

Although there are some magical pm_runtime_*() in some places, most of such pm_runtime_get_sync() is for the actual runtime PM management (to prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls.  Really.

Yes agree.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

I don't its less readable. However, I do think it is less error prone :-)

Do we have a consensus here? Request others to provide opinions to help close on this.

I am not going to block this and ultimately it is Iwai-san call.

However, I wonder if it would be appropriate to move the whole ...

if (pm_runtime_enabled())

         ret = pm_runtime_get_sync();
 else
         ret = hda_tegra_runtime_resume();

... into the probe_work function? In other words, we are just resuming when we really need to. Unless I am still misunderstanding Iwai-san comment. Otherwise if Iwai-san is happy with V2 then go with that.

Cheers
Jon

Signature · 1 line
nvpublic
#10 lore raw
Quoted 86 lines · Jon Hunter
Quoted 71 lines · Sameer Pujar
Quoted 69 lines · Jon Hunter
Quoted 59 lines · Takashi Iwai
Quoted 52 lines · Jon Hunter
Quoted 46 lines · Takashi Iwai
Quoted 38 lines · Jon Hunter
Quoted 23 lines · Takashi Iwai
Quoted 20 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks
will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not.
If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
   * return code check for pm_runtime_get_sync() to take care of failure
     and exit gracefully.
   * In remove path runtime PM is disabled before calling snd_card_free().
   * hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
   * runtime PM callbacks moved out of CONFIG_PM check

(snip)

Quoted 13 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct
 platform_device *pdev)
       if (!azx_has_pm_runtime(chip))
           pm_runtime_forbid(hda->dev);
Quoted 8 lines

  +    /* explicit resume if runtime PM is disabled */ +    if (!pm_runtime_enabled(hda->dev)) {
+        err = hda_tegra_runtime_resume(hda->dev); +        if (err)
+            goto out_free;
+    }
+
      schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 6 lines

Why? IMO it is better to have a single handler for resuming the device
and so if RPM is not enabled we call the handler directly. This is what
we have been advised to do in the past and do in other drivers. See ...

Quoted 4 lines

The point is that we're not "resuming" anything there.  It's in the early probe stage, and the device state is uninitialized, not really suspended.  It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 5 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Quoted 7 lines

Although there are some magical pm_runtime_*() in some places, most of such pm_runtime_get_sync() is for the actual runtime PM management (to prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls.  Really.

Yes agree.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

I don't its less readable. However, I do think it is less error prone :-)

Do we have a consensus here? Request others to provide opinions to help close on this.

I am not going to block this and ultimately it is Iwai-san call.

However, I wonder if it would be appropriate to move the whole ...

Quoted 8 lines

if (pm_runtime_enabled())

         ret = pm_runtime_get_sync();
 else
         ret = hda_tegra_runtime_resume();

... into the probe_work function? In other words, we are just resuming when we really need to. Unless I am still misunderstanding Iwai-san comment. Otherwise if Iwai-san is happy with V2 then go with that.

Only from my personal taste, I find the v2 patch is better. It like simpler, after all. That is, the code in v1 patch

	probe() {
		....
		pm_runtime_enable();
		....
		if (!pm_runtime_enabled())
			hda_tegra_runtime_resume();
		schedule_work();
	}

	work() {
		pm_runtime_get_sync();
		....
		pm_runtime_put();
	}

becomes shorter in v2:

	probe() {
		....
		hda_tegra_enable_clocks();
		schedule_work();
	}

	work() {
		....
		pm_runtime_enable();
	}

However, the point about hda_tegra_remove() you raised in the v2 patch is still valid. (BTW, I guess the discussion followed in that thread was somehow misunderstood; your argument was about hda_tegra_remove() while Sameer discussed about the probe.) It can be with hda_tegra_disable_clocks() if we want more consistency.

Though, I don't mind too much about that as long as the proper comment is given.

thanks,

Takashi

#11 lore raw
Quoted 122 lines · Takashi Iwai
Quoted 80 lines · Jon Hunter
Quoted 66 lines · Sameer Pujar
Quoted 65 lines · Jon Hunter
Quoted 64 lines · Takashi Iwai
Quoted 50 lines · Jon Hunter
Quoted 45 lines · Takashi Iwai
Quoted 37 lines · Jon Hunter
Quoted 23 lines · Takashi Iwai
Quoted 20 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks
will not be ON. This could cause issue during probe, where hda init setup is done. This patch checks whether runtime PM is enabled or not.
If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
   * return code check for pm_runtime_get_sync() to take care of
failure
     and exit gracefully.
   * In remove path runtime PM is disabled before calling
snd_card_free().
   * hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP
check.
   * runtime PM callbacks moved out of CONFIG_PM check

(snip)

Quoted 13 lines

Review static int hda_tegra_probe(struct · line 563

Quoted 12 lines
(quoted diff) +6 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct
 platform_device *pdev)
       if (!azx_has_pm_runtime(chip))
           pm_runtime_forbid(hda->dev);
   +    /* explicit resume if runtime PM is disabled */
+    if (!pm_runtime_enabled(hda->dev)) {
+        err = hda_tegra_runtime_resume(hda->dev);
+        if (err)
+            goto out_free;
+    }
+
       schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 6 lines

Why? IMO it is better to have a single handler for resuming the device
and so if RPM is not enabled we call the handler directly. This is what
we have been advised to do in the past and do in other drivers. See ...

Quoted 4 lines

The point is that we're not "resuming" anything there.  It's in the early probe stage, and the device state is uninitialized, not really suspended.  It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 5 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have never been suspended.

Although there are some magical pm_runtime_*() in some places, most of such pm_runtime_get_sync() is for the actual runtime PM management (to prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls.  Really.

Quoted 8 lines
Quoted 6 lines

Yes agree.

Quoted 3 lines
Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

I don't its less readable. However, I do think it is less error prone :-)

Do we have a consensus here? Request others to provide opinions to help close on this.

I am not going to block this and ultimately it is Iwai-san call.

However, I wonder if it would be appropriate to move the whole ...

Quoted 8 lines
  if (pm_runtime_enabled())
          ret = pm_runtime_get_sync();
  else
          ret = hda_tegra_runtime_resume();

... into the probe_work function? In other words, we are just resuming when we really need to. Unless I am still misunderstanding Iwai-san comment. Otherwise if Iwai-san is happy with V2 then go with that.

Only from my personal taste, I find the v2 patch is better. It like simpler, after all. That is, the code in v1 patch

	probe() {
		....
		pm_runtime_enable();
		....
		if (!pm_runtime_enabled())
			hda_tegra_runtime_resume();
		schedule_work();
	}

	work() {
		pm_runtime_get_sync();
		....
		pm_runtime_put();
	}

becomes shorter in v2:

	probe() {
		....
		hda_tegra_enable_clocks();
		schedule_work();
	}

	work() {
		....
		pm_runtime_enable();
	}
Quoted 8 lines

However, the point about hda_tegra_remove() you raised in the v2 patch is still valid. (BTW, I guess the discussion followed in that thread was somehow misunderstood; your argument was about hda_tegra_remove() while Sameer discussed about the probe.) It can be with hda_tegra_disable_clocks() if we want more consistency.

Though, I don't mind too much about that as long as the proper comment is given.

We might need entire functionality of hda_tegra_runtime_suspend() replicated here, if hda_tegra_disable_clocks() were to be used. Right now it takes care of both the cases where runtime PM is enabled/disabled. If you all agree, we can move the discussion to v2 patch.

Thanks,
Sameer.

Quoted 4 lines

thanks,

Takashi

maintainer
#12 lore raw
Quoted 141 lines · Sameer Pujar
Quoted 131 lines · Takashi Iwai
Quoted 89 lines · Jon Hunter
Quoted 75 lines · Sameer Pujar
Quoted 74 lines · Jon Hunter
Quoted 69 lines · Takashi Iwai
Quoted 54 lines · Jon Hunter
Quoted 48 lines · Takashi Iwai
Quoted 40 lines · Jon Hunter
Quoted 26 lines · Takashi Iwai
Quoted 23 lines · Sameer Pujar

If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks
will not be ON. This could cause issue during probe, where hda init
setup is done. This patch checks whether runtime PM is enabled or not.
If disabled, clocks are enabled in probe() and disabled in remove()

This patch does following minor changes as cleanup,
    * return code check for pm_runtime_get_sync() to take care of
failure
      and exit gracefully.
    * In remove path runtime PM is disabled before calling snd_card_free().
    * hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check.
    * runtime PM callbacks moved out of CONFIG_PM check

(snip)

Quoted 13 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -555,6 +553,13 @@ static int hda_tegra_probe(struct
 platform_device *pdev)
        if (!azx_has_pm_runtime(chip))
            pm_runtime_forbid(hda->dev);
Quoted 8 lines

   +    /* explicit resume if runtime PM is disabled */ +    if (!pm_runtime_enabled(hda->dev)) {
+        err = hda_tegra_runtime_resume(hda->dev); +        if (err)
+            goto out_free;
+    }
+
       schedule_work(&hda->probe_work);

Calling runtime_resume here is really confusing...

Quoted 6 lines

Why? IMO it is better to have a single handler for resuming the device
and so if RPM is not enabled we call the handler directly. This is what
we have been advised to do in the past and do in other drivers. See ...

Quoted 5 lines

The point is that we're not "resuming" anything there.  It's in the early probe stage, and the device state is uninitialized, not really
suspended.  It'd end up with just calling the same helper (hda_tegra_enable_clocks()), though.

Quoted 6 lines

Yes and you can make the same argument for every driver that calls pm_runtime_get_sync() during probe to turn on clocks, handle resets, etc, because at the end of the day the very first call to pm_runtime_get_sync() invokes the runtime_resume callback, when we have
never been suspended.

Although there are some magical pm_runtime_*() in some places, most of
such pm_runtime_get_sync() is for the actual runtime PM management (to
prevent the runtime suspend), while the code above is for explicitly setting up something for non-PM cases.

Quoted 2 lines

And if pm_runtime_get_sync() is obviously superfluous, we should remove such calls.  Really.

Yes agree.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Yes at the end of the day it is the same and given that we have done this elsewhere I think it is good to be consistent if/where we can.

The code becomes less readable, and that's a good reason against it :)

I don't its less readable. However, I do think it is less error prone :-)

Do we have a consensus here? Request others to provide opinions to help close on this.

I am not going to block this and ultimately it is Iwai-san call.

However, I wonder if it would be appropriate to move the whole ...

Quoted 8 lines

  if (pm_runtime_enabled())
          ret = pm_runtime_get_sync();
  else
          ret = hda_tegra_runtime_resume();

... into the probe_work function? In other words, we are just resuming when we really need to. Unless I am still misunderstanding Iwai-san comment. Otherwise if Iwai-san is happy with V2 then go with that.

Only from my personal taste, I find the v2 patch is better. It like simpler, after all.  That is, the code in v1 patch

    probe() {
        ....
        pm_runtime_enable();
        ....
        if (!pm_runtime_enabled())
            hda_tegra_runtime_resume();
        schedule_work();
    }

    work() {
        pm_runtime_get_sync();
        ....
        pm_runtime_put();
    }

becomes shorter in v2:

    probe() {
        ....
        hda_tegra_enable_clocks();
        schedule_work();
    }

    work() {
        ....
        pm_runtime_enable();
    }

Quoted 8 lines

However, the point about hda_tegra_remove() you raised in the v2 patch is still valid.  (BTW, I guess the discussion followed in that thread was somehow misunderstood; your argument was about hda_tegra_remove() while Sameer discussed about the probe.)  It can be with hda_tegra_disable_clocks() if we want more consistency.

Though, I don't mind too much about that as long as the proper comment is given.

Quoted 7 lines

We might need entire functionality of hda_tegra_runtime_suspend() replicated here,
if hda_tegra_disable_clocks() were to be used. Right now it takes care of both the
cases where runtime PM is enabled/disabled. If you all agree, we can move the
discussion to v2 patch.

We should avoid replicating the function.

Jon

Signature · 1 line
nvpublic