Introduce dmic mode switch delay parameter
v3 cover Introduce dmic mode switch delay parameter
Some DMICs need clock to be running for a specified duration as per the DMIC spec to complete the mode transition like sleep to normal, off to normal etc. This series add a mode-switch delay which will prevent the clock from being turned off without complying with manufacturer timing specifications. Also introduces a module parameter for the wakeup_delay parameter.
v1: First patch set
v2:
1). Removed ACPI device entry since a) The DMIC vendor doesn't have an ACPI vendor ID b) The ACPI enumeration creates one more device and conflicts with the existing skl.c dmic platform device registration.
2). Updated commit message
v3: Updated commit message and introduced module param for wakeup_delay
Jenny TC (2):
ASoC: dmic: introduce mode switch delay
ASoC: dmic: introduce module_param wakeup_delay
sound/soc/codecs/dmic.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
Signature · 1 line
1.9.1
PATCH v3 1/2 ASoC: dmic: introduce mode switch delay
On startup, applications such as PulseAudio or CRAS enable playback or capture on all PCM devices to verify that configurations are correct, and close them immediately. For DMICs, this can result in the clock being turned off very quickly, which may not compatible with internal state machine transition requirements.
This patch add a mode-switch delay which will prevent the clock from being turned off without complying with manufacturer timing specifications. While the DMIC clock may be controlled at a lower level, be it with hardware or firmware, applying the delay during the STOP_TRIGGER phase ensures that there is no race condition, e.g. with the hardware/firmware turning off the clock earlier
--- sound/soc/codecs/dmic.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
sound/soc/codecs/dmic.c +31 -0
@@ -30,9 +30,35 @@#include <sound/soc.h> #include <sound/soc-dapm.h> +static int modeswitch_delay_ms; +module_param (modeswitch_delay_ms, uint,0644 ); +struct dmic {struct gpio_desc *gpio_en;int wakeup_delay; +/* Delay after DMIC mode switch */ +int modeswitch_delay_ms; +}; + +int dmic_daiops_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct snd_soc_component *component = dai->component; +struct dmic *dmic =snd_soc_component_get_drvdata (component); + +switch (cmd) { +case SNDRV_PCM_TRIGGER_STOP : +if (dmic->modeswitch_delay_ms) +mdelay (dmic->modeswitch_delay_ms); + +break ; + } + +return 0 ; +} + +static const struct snd_soc_dai_ops dmic_dai_ops = { + .trigger = dmic_daiops_trigger, }; static int dmic_aif_event(struct snd_soc_dapm_widget *w,
@@ -68,6 +94,7 @@ static int dmic_aif_event(struct snd_soc_dapm_widget *w, | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, }, + .ops = &dmic_dai_ops, };static int dmic_component_probe (struct snd_soc_component *component)
@@ -85,6 +112,10 @@ static int dmic_component_probe(struct snd_soc_component *component)device_property_read_u32 (component->dev,"wakeup-delay-ms" , &dmic->wakeup_delay); +device_property_read_u32 (component->dev,"modeswitch_delay_ms" , + &dmic->modeswitch_delay_ms); +if (modeswitch_delay_ms) + dmic->modeswitch_delay_ms = modeswitch_delay_ms;snd_soc_component_set_drvdata (component, dmic);
Signature · 1 line
1.9.1
Jaroslav Kysela
maintainerRe: [PATCH 1/2] ASoC: dmic: introduce mode switch delay
Dne 16.11.2018 v 12:10 Jenny TC napsal(a):
Quoted 69 lines
On startup, applications such as PulseAudio or CRAS enable playback or capture on all PCM devices to verify that configurations are correct, and close them immediately. For DMICs, this can result in the clock being turned off very quickly, which may not compatible with internal state machine transition requirements.
This patch add a mode-switch delay which will prevent the clock from being turned off without complying with manufacturer timing specifications. While the DMIC clock may be controlled at a lower level, be it with hardware or firmware, applying the delay during the
STOP_TRIGGERphase ensures that there is no race condition, e.g. with the hardware/firmware turning off the clock earlierSigned-off-by Sathyanarayana Nujella <[email protected]>Signed-off-by Jairaj Arava <[email protected]>Signed-off-by Harsha Priya <[email protected]>--- sound/soc/codecs/dmic.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)sound/soc/codecs/dmic.c +27
-0@@ -30,9 +30,35 @@#include <sound/soc.h> #include <sound/soc-dapm.h> +static int modeswitch_delay_ms; +module_param (modeswitch_delay_ms, uint,0644 ); +struct dmic {struct gpio_desc *gpio_en;int wakeup_delay; +/* Delay after DMIC mode switch */ +int modeswitch_delay_ms; +}; + +int dmic_daiops_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct snd_soc_component *component = dai->component; +struct dmic *dmic =snd_soc_component_get_drvdata (component); + +switch (cmd) { +case SNDRV_PCM_TRIGGER_STOP : +if (dmic->modeswitch_delay_ms) +mdelay (dmic->modeswitch_delay_ms); + +break ; + } + +return 0 ; +} + +static const struct snd_soc_dai_ops dmic_dai_ops = { + .trigger = dmic_daiops_trigger, }; static int dmic_aif_event(struct snd_soc_dapm_widget *w,@@ -68,6 +94,7 @@ static int dmic_aif_event(struct snd_soc_dapm_widget *w, | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, }, + .ops = &dmic_dai_ops, };static int dmic_component_probe (struct snd_soc_component *component)
sound/soc/codecs/dmic.c static int dmic_component_probe(struct snd_soc_component *component) · line 116
Quoted 5 lines
sound/soc/codecs/dmic.c +2
-0@@ -85,6 +112,10 @@ static int dmic_component_probe(struct snd_soc_component *component)device_property_read_u32 (component->dev,"wakeup-delay-ms" , &dmic->wakeup_delay); +device_property_read_u32 (component->dev,"modeswitch_delay_ms" , + &dmic->modeswitch_delay_ms);
This should be probably consistent with the previous property name. Use "modeswitch-delay-ms".
sound/soc/codecs/dmic.c static int dmic_component_probe(struct snd_soc_component *component) · line 121
Quoted 6 lines
sound/soc/codecs/dmic.c +2
-0+if (modeswitch_delay_ms) + dmic->modeswitch_delay_ms = modeswitch_delay_ms;snd_soc_component_set_drvdata (component, dmic);
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH 1/2] ASoC: dmic: introduce mode switch delay
Quoted 71 lines · Jaroslav Kysela
Dne 16.11.2018 v 12:10 Jenny TC napsal(a):
Quoted 70 lines
On startup, applications such as PulseAudio or CRAS enable playback or capture on all PCM devices to verify that configurations are correct, and close them immediately. For DMICs, this can result in the clock being turned off very quickly, which may not compatible with internal state machine transition requirements.
This patch add a mode-switch delay which will prevent the clock from being turned off without complying with manufacturer timing specifications. While the DMIC clock may be controlled at a lower level, be it with hardware or firmware, applying the delay during the
STOP_TRIGGERphase ensures that there is no race condition, e.g. with the hardware/firmware turning off the clock earlierSigned-off-by Sathyanarayana Nujella <[email protected]>Signed-off-by Jairaj Arava <[email protected]>Signed-off-by Harsha Priya <[email protected]>--- sound/soc/codecs/dmic.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)sound/soc/codecs/dmic.c +27
-0@@ -30,9 +30,35 @@#include <sound/soc.h> #include <sound/soc-dapm.h> +static int modeswitch_delay_ms; +module_param (modeswitch_delay_ms, uint,0644 ); +struct dmic {struct gpio_desc *gpio_en;int wakeup_delay; +/* Delay after DMIC mode switch */ +int modeswitch_delay_ms; +}; + +int dmic_daiops_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct snd_soc_component *component = dai->component; +struct dmic *dmic =snd_soc_component_get_drvdata (component); + +switch (cmd) { +case SNDRV_PCM_TRIGGER_STOP : +if (dmic->modeswitch_delay_ms) +mdelay (dmic->modeswitch_delay_ms); + +break ; + } + +return 0 ; +} + +static const struct snd_soc_dai_ops dmic_dai_ops = { + .trigger = dmic_daiops_trigger, }; static int dmic_aif_event(struct snd_soc_dapm_widget *w,@@ -68,6 +94,7 @@ static int dmic_aif_event(struct snd_soc_dapm_widget *w, | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, }, + .ops = &dmic_dai_ops, };static int dmic_component_probe (struct snd_soc_component *component)@@ -85,6 +112,10 @@ static int dmic_component_probe(struct snd_soc_component *component)
Quoted 6 lines
sound/soc/codecs/dmic.c static int dmic_component_probe(struct snd_soc_component *component) · line 116
Quoted 4 lines
sound/soc/codecs/dmic.c +2
-0device_property_read_u32 (component->dev,"wakeup-delay-ms" , &dmic->wakeup_delay); +device_property_read_u32 (component->dev,"modeswitch_delay_ms" , + &dmic->modeswitch_delay_ms);This should be probably consistent with the previous property name. Use "modeswitch-delay-ms".
Indeed. I'd go even further in the nitpicks department and only use the the -ms suffix in the property and use a modeswitch_delay field and parameter for naming consistency with the existing wake_delay.
The patches look good otherwise, it's a useful patch to add. Jenny, can you do this cosmetic fix and resubmit?
Quoted 9 lines
sound/soc/codecs/dmic.c static int dmic_component_probe(struct snd_soc_component *component) · line 121
Quoted 7 lines
sound/soc/codecs/dmic.c +2
-0+if (modeswitch_delay_ms) + dmic->modeswitch_delay_ms = modeswitch_delay_ms;snd_soc_component_set_drvdata (component, dmic);Jaroslav
Mark Brown
maintainerRe: [PATCH 1/2] ASoC: dmic: introduce mode switch delay
Quoted 6 lines · Pierre-Louis Bossart
Indeed. I'd go even further in the nitpicks department and only use the the -ms suffix in the property and use a
modeswitch_delayfield and parameter for naming consistency with the existingwake_delay.The patches look good otherwise, it's a useful patch to add. Jenny, can you do this cosmetic fix and resubmit?
Indeed. Please also send a patch to update the DT binding (even if you're using this with ACPI it's also a DT binding):
Documentation/devicetree/bindings/sound/dmic.txt
PATCH v3 2/2 ASoC: dmic: introduce module_param wakeup_delay
In reply to Jenny TCIntroducing a module param for wakeup_delay in order to align with modeswitch_delay parameter. With this change, both wakeup_delay and modeswitch_delay_ms parameters can be passed as module parameters.
--- sound/soc/codecs/dmic.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/soc/codecs/dmic.c +5 -0
@@ -33,6 +33,9 @@static int modeswitch_delay_ms;module_param (modeswitch_delay_ms, uint,0644 ); +static int wakeup_delay; +module_param (wakeup_delay, uint,0644 ); +struct dmic {struct gpio_desc *gpio_en;int wakeup_delay;
@@ -116,6 +119,8 @@ static int dmic_component_probe(struct snd_soc_component *component) &dmic->modeswitch_delay_ms);if (modeswitch_delay_ms) dmic->modeswitch_delay_ms = modeswitch_delay_ms; +if (wakeup_delay) + dmic->wakeup_delay = wakeup_delay;snd_soc_component_set_drvdata (component, dmic);
Signature · 1 line
1.9.1