ASoC: sun4i-i2s: move code from startup/shutdown hooks into pm_runtime hooks
Subsystems (3)
PATCH v2 1/1 ASoC: sun4i-i2s: move code from startup/shutdown hooks into pm_runtime hooks
startup() and shutdown() hooks are called for both substreams, so stopping either substream when another is running breaks the latter.
E.g. playback breaks if capture is stopped when playback is running.
Move code from startup() and shutdown() to resume() and suspend() hooks respectively to fix this issue
---
v2: - rename from "ASoC: sun4i-i2s: don't try to start up
or shut down DAI if it's active"
- move code from startup/shutdown hooks into pm_runtime
sound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)
sound/soc/sunxi/sun4i-i2s.c +25 -36
@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); - -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {
@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = { .hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk, - .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };
@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(struct device *dev) goto err_disable_clk; } +/* Enable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); + +/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + } +return 0 ; err_disable_clk:
@@ -880,6 +859,16 @@ static int sun4i_i2s_runtime_suspend(struct device *dev) {struct sun4i_i2s *i2s =dev_get_drvdata (dev); +clk_disable_unprepare (i2s->mod_clk); + +/* Disable our output lines */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); + +/* Disable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,0 ); +regcache_cache_only (i2s->regmap, true);clk_disable_unprepare (i2s->bus_clk);
Signature · 1 line
2.19.0
Quoted 73 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start up
or shut down DAI if it's active"
- move code from startup/shutdown hooks intopm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-36@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); - -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = { .hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk, - .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };
sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 839
Quoted 7 lines
sound/soc/sunxi/sun4i-i2s.c +4
-0@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(struct device *dev) goto err_disable_clk; } +/* Enable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); +
So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 849
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }
But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and we'll need additional information from ASoC when we'll do.
Maxime
Signature · 3 lines
Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 96 lines · Maxime Ripard
Quoted 73 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start up
or shut down DAI if it's active"
- move code from startup/shutdown hooks intopm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-36@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); - -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = { .hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk, - .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 839
Quoted 7 lines
sound/soc/sunxi/sun4i-i2s.c +4
-0@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(struct device *dev) goto err_disable_clk; } +/* Enable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); +So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 849
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }
Quoted 5 lines
But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and we'll need additional information from ASoC when we'll do.
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep startup() and shutdown() hooks.
Quoted 6 lines
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Quoted 98 lines · Vasily Khoruzhick
Quoted 96 lines · Maxime Ripard
Quoted 73 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start up
or shut down DAI if it's active"
- move code from startup/shutdown hooks intopm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-36@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); - -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = { .hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk, - .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 839
Quoted 7 lines
sound/soc/sunxi/sun4i-i2s.c +4
-0@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(struct device *dev) goto err_disable_clk; } +/* Enable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); +So this is definitely needed
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }
Quoted 8 lines
Quoted 5 lines
But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and we'll need additional information from ASoC when we'll do.
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep
startup()andshutdown()hooks.
I'd go for something in between. runtime_pm already provides whether the device is active or not, so you can just move the SUN4I_I2S_CTRL_GL_EN write to the runtime_resume and runtime_suspend functions, and that should fix your issue.
Maxime
Signature · 10 lines
Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181017/65c9e55c/attachment.sig>
Quoted 106 lines · Maxime Ripard
Quoted 104 lines · Vasily Khoruzhick
Quoted 101 lines · Maxime Ripard
Quoted 73 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start up
or shut down DAI if it's active"
- move code from startup/shutdown hooks intopm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-36@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); - -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = { .hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk, - .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 839
Quoted 7 lines
sound/soc/sunxi/sun4i-i2s.c +4
-0@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(struct device *dev) goto err_disable_clk; } +/* Enable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); +So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 849
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and we'll need additional information from ASoC when we'll do.
Quoted 7 lines
Quoted 2 lines
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep
startup()andshutdown()hooks.I'd go for something in between.
runtime_pmalready provides whether the device is active or not, so you can just move theSUN4I_I2S_CTRL_GL_ENwrite to theruntime_resumeandruntime_suspendfunctions, and that should fix your issue.
I still need to guard enabling output line with "if (dai->active) return", so it doesn't fix the issue unfortunately.
Quoted 7 lines
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Quoted 111 lines · Vasily Khoruzhick
Quoted 109 lines · Maxime Ripard
Quoted 106 lines · Vasily Khoruzhick
Quoted 96 lines · Maxime Ripard
Quoted 73 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start up
or shut down DAI if it's active"
- move code from startup/shutdown hooks intopm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-36@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); - -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = { .hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk, - .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 839
Quoted 7 lines
sound/soc/sunxi/sun4i-i2s.c +4
-0@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(struct device *dev) goto err_disable_clk; } +/* Enable the whole hardware block */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_GL_EN ,SUN4I_I2S_CTRL_GL_EN ); +So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 849
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }Quoted 5 lines
But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and we'll need additional information from ASoC when we'll do.
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep
startup()andshutdown()hooks.
Quoted 7 lines
Quoted 4 lines
I'd go for something in between.
runtime_pmalready provides whether the device is active or not, so you can just move theSUN4I_I2S_CTRL_GL_ENwrite to theruntime_resumeandruntime_suspendfunctions, and that should fix your issue.I still need to guard enabling output line with "if (
dai->active) return", so it doesn't fix the issue unfortunately.
Why? The configuration is static, so it probably doesn't change much?
Maxime
Signature · 3 lines
Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 139 lines · PDT Maxime Ripard
Quoted 138 lines · Vasily Khoruzhick
On Wed, Oct 17, 2018 at 12:45 AM Maxime Ripard
Quoted 134 lines · <[email protected]> wrote:
Quoted 126 lines · Vasily Khoruzhick
On Tue, Oct 16, 2018 at 12:16 AM Maxime Ripard
Quoted 116 lines · <[email protected]> wrote:
Quoted 99 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start upor shut down DAI if it's active"
- move code from startup/shutdown hooks into
pm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-0@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct
snd_pcm_substream*substream, int cmd,> > > > >return 0;}
sound/soc/sunxi/sun4i-i2s.c +0
-8-static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ - regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, - SUN4I_I2S_CTRL_GL_EN,
SUN4I_I2S_CTRL_GL_EN);sound/soc/sunxi/sun4i-i2s.c +0
-11- -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown(struct snd_pcm_substream*substream,
sound/soc/sunxi/sun4i-i2s.c +0
-15- struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops
sun4i_i2s_dai_ops= {> > > > >.hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk,sound/soc/sunxi/sun4i-i2s.c +0
-2- .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(structdevice *dev)> > > > >
goto err_disable_clk; }sound/soc/sunxi/sun4i-i2s.c +3
-0+/* Enable the whole hardware block */ + regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, + SUN4I_I2S_CTRL_GL_EN,Quoted 2 lines
SUN4I_I2S_CTRL_GL_EN);
+So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_runtime_resume(struct device *dev) · line 849
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }Quoted 6 lines
But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and
we'll need additional information from ASoC when we'll do.Quoted 2 lines
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep
startup()andshutdown()hooks.I'd go for something in between.
runtime_pmalready provides whether the device is active or not, so you can just move theSUN4I_I2S_CTRL_GL_ENwrite to theruntime_resumeandruntime_suspendfunctions, and that should fix your issue.
Quoted 4 lines
Quoted 2 lines
I still need to guard enabling output line with "if (
dai->active) return", so it doesn't fix the issue unfortunately.Why? The configuration is static, so it probably doesn't change much?
startup() and shutdown() are called once for each substream, i.e. for capture and playback.
If we start playback and capture and the stop either we end up with calling startup() twice and then shutdown() once. Since it disables I2S output it breaks substream that is still working.
Quoted 2 lines
Maxime
Maxime Ripard
Acked-byQuoted 143 lines · Vasily Khoruzhick
Quoted 142 lines · PDT Maxime Ripard
Quoted 140 lines · Vasily Khoruzhick
On Wed, Oct 17, 2018 at 12:45 AM Maxime Ripard
Quoted 127 lines · <[email protected]> wrote:
Quoted 126 lines · Vasily Khoruzhick
On Tue, Oct 16, 2018 at 12:16 AM Maxime Ripard
Quoted 122 lines · <[email protected]> wrote:
Quoted 99 lines · Vasily Khoruzhick
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start upor shut down DAI if it's active"
- move code from startup/shutdown hooks into
pm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-0@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct
snd_pcm_substream*substream, int cmd,> > > > >return 0;}
sound/soc/sunxi/sun4i-i2s.c +0
-8-static int sun4i_i2s_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ - regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, - SUN4I_I2S_CTRL_GL_EN,
SUN4I_I2S_CTRL_GL_EN);sound/soc/sunxi/sun4i-i2s.c +0
-11- -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown(struct snd_pcm_substream*substream,
sound/soc/sunxi/sun4i-i2s.c +0
-15- struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops
sun4i_i2s_dai_ops= {> > > > >.hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk,sound/soc/sunxi/sun4i-i2s.c +0
-2- .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };@@ -869,6 +833,21 @@ static int sun4i_i2s_runtime_resume(structdevice *dev)> > > > >
goto err_disable_clk; }sound/soc/sunxi/sun4i-i2s.c +3
-0+/* Enable the whole hardware block */ + regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, + SUN4I_I2S_CTRL_GL_EN,Quoted 2 lines
SUN4I_I2S_CTRL_GL_EN);
+So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make more sense to keep the output enable configuration there as well, since it's likely that we will have support for it in the future, and
we'll need additional information from ASoC when we'll do.Quoted 7 lines
Quoted 2 lines
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep
startup()andshutdown()hooks.I'd go for something in between.
runtime_pmalready provides whether the device is active or not, so you can just move theSUN4I_I2S_CTRL_GL_ENwrite to theruntime_resumeandruntime_suspendfunctions, and that should fix your issue.I still need to guard enabling output line with "if (
dai->active) return", so it doesn't fix the issue unfortunately.
Quoted 8 lines
Quoted 1 line
Why? The configuration is static, so it probably doesn't change much?
startup()andshutdown()are called once for each substream, i.e. for capture and playback.If we start playback and capture and the stop either we end up with calling
startup()twice and thenshutdown()once. Since it disables I2S output it breaks substream that is still working.
Ah, right, I forgot that case. In this case, yeah, your patch makes sense
Thanks!
Maxime
Signature · 3 lines
Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 11 lines · PDT Maxime Ripard
Quoted 10 lines · Vasily Khoruzhick
Quoted 9 lines · PDT Maxime Ripard
Quoted 8 lines · Vasily Khoruzhick
On Wed, Oct 17, 2018 at 12:45 AM Maxime Ripard
Quoted 5 lines · <[email protected]> wrote:
Quoted 4 lines · Vasily Khoruzhick
On Tue, Oct 16, 2018 at 12:16 AM Maxime Ripard
Quoted 1 line · <[email protected]> wrote:
On Mon, Oct 15, 2018 at 08:11:41PM -0700, Vasily Khoruzhick
Quoted 148 lines · wrote:
Quoted 148 lines
Quoted 140 lines
Quoted 140 lines
Quoted 139 lines
Quoted 132 lines
Quoted 122 lines
Quoted 106 lines
startup()andshutdown()hooks are called for both substreams, so stopping either substream when another is running breaks the
latter.E.g. playback breaks if capture is stopped when playback is running.
Move code from
startup()andshutdown()toresume()andsuspend()
hooks respectively to fix this issueSigned-off-by Vasily Khoruzhick <[email protected]>---
v2: - rename from "ASoC: sun4i-i2s: don't try to start upor shut down DAI if it's active"
- move code from startup/shutdown hooks into
pm_runtimesound/soc/sunxi/sun4i-i2s.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-)sound/soc/sunxi/sun4i-i2s.c +0
-0@@ -644,40 +644,6 @@ static int sun4i_i2s_trigger(struct
snd_pcm_substream*substream, int cmd,> > > > >return 0;}
-static int sun4i_i2s_startup(struct
snd_pcm_substream*substream,sound/soc/sunxi/sun4i-i2s.c +0
-7- struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -/* Enable the whole hardware block */ - regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, - SUN4I_I2S_CTRL_GL_EN,
SUN4I_I2S_CTRL_GL_EN);sound/soc/sunxi/sun4i-i2s.c +0
-11- -/* Enable the first output line */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK , -SUN4I_I2S_CTRL_SDO_EN (0 )); - - -return clk_prepare_enable (i2s->mod_clk); -} - -static void sun4i_i2s_shutdown(struct snd_pcm_substream*substream,
sound/soc/sunxi/sun4i-i2s.c +0
-15- struct snd_soc_dai *dai) -{ -struct sun4i_i2s *i2s =snd_soc_dai_get_drvdata (dai); - -clk_disable_unprepare (i2s->mod_clk); - -/* Disable our output lines */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_SDO_EN_MASK ,0 ); - -/* Disable the whole hardware block */ -regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , -SUN4I_I2S_CTRL_GL_EN ,0 ); -} -static int sun4i_i2s_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int freq,int dir) {@@ -695,8 +661,6 @@ static const struct snd_soc_dai_ops
sun4i_i2s_dai_ops= {> > > > >.hw_params = sun4i_i2s_hw_params, .set_fmt = sun4i_i2s_set_fmt, .set_sysclk = sun4i_i2s_set_sysclk,sound/soc/sunxi/sun4i-i2s.c +0
-2- .shutdown = sun4i_i2s_shutdown, - .startup = sun4i_i2s_startup, .trigger = sun4i_i2s_trigger, };@@ -869,6 +833,21 @@ static intsun4i_i2s_runtime_resume(struct
device *dev)> > > > >goto err_disable_clk; }sound/soc/sunxi/sun4i-i2s.c +3
-0+/* Enable the whole hardware block */ + regmap_update_bits(i2s->regmap, SUN4I_I2S_CTRL_REG, + SUN4I_I2S_CTRL_GL_EN,Quoted 2 lines
SUN4I_I2S_CTRL_GL_EN);
+So this is definitely needed
sound/soc/sunxi/sun4i-i2s.c
Quoted 10 lines
sound/soc/sunxi/sun4i-i2s.c +10
-0+/* Enable the first output line */ +regmap_update_bits (i2s->regmap,SUN4I_I2S_CTRL_REG , +SUN4I_I2S_CTRL_SDO_EN_MASK , +SUN4I_I2S_CTRL_SDO_EN (0 )); + + ret =clk_prepare_enable (i2s->mod_clk); +if (ret) { +dev_err (dev,"Failed to enable module clock\n" ); + goto err_disable_clk; + }Quoted 9 lines
But we really don't want to enable the module clock before the playback / capture actually starts. And I'm guessing it would make
more sense to keep the output enable configuration there as well,
since it's likely that we will have support for it in the future,
and
we'll need additional information from ASoC when we'll do.Quoted 2 lines
Should we go with v1 version of my patch then? I see no reason to shuffle code around if we keep
startup()andshutdown()hooks.I'd go for something in between.
runtime_pmalready provides whether the device is active or not, so you can just move theSUN4I_I2S_CTRL_GL_ENwrite to theruntime_resumeandruntime_suspendfunctions, and that should fix your issue.Quoted 4 lines
Quoted 2 lines
I still need to guard enabling output line with "if (
dai->active) return", so it doesn't fix the issue unfortunately.Why? The configuration is static, so it probably doesn't change much?
startup()andshutdown()are called once for each substream, i.e. for capture and playback.
Quoted 8 lines
Quoted 4 lines
If we start playback and capture and the stop either we end up with calling
startup()twice and thenshutdown()once. Since it disables I2S output it breaks substream that is still working.Ah, right, I forgot that case. In this case, yeah, your patch makes sense
Acked-by Maxime Ripard <[email protected]>
Mark, can you pick up this one please? Thanks!
Regards,
Vasily
Quoted 3 lines
Thanks!
Maxime
Mark Brown
maintainerQuoted 5 lines · Vasily Khoruzhick
Quoted 4 lines · PDT Maxime Ripard
Quoted 3 lines · Vasily Khoruzhick
Quoted 2 lines · PDT Maxime Ripard
Quoted 1 line · Vasily Khoruzhick
On Wed, Oct 17, 2018 at 12:45 AM Maxime Ripard
Please delete unneeded context from mails when replying. Doing this makes it much easier to find your reply in the message, helping ensure it won't be missed by people scrolling through the irrelevant quoted material.
Quoted 1 line
Mark, can you pick up this one please? Thanks!
Please resend, I dropped it due to the (initial) negative review
comments.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181021/b7ba89f4/attachment-0001.sig>