[alsa-devel] [PATCH v4 0/2] 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
v4: Addressed parameter name to align with existing parameter. Added dt entry in Documentation
Jenny TC (2): ASoC: dmic: introduce mode switch delay ASoC: dmic: introduce module_param wakeup_delay
Documentation/devicetree/bindings/sound/dmic.txt | 2 ++ sound/soc/codecs/dmic.c | 36 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+)

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
Signed-off-by: Sathyanarayana Nujella sathyanarayana.nujella@intel.com Signed-off-by: Jairaj Arava jairaj.arava@intel.com Signed-off-by: Harsha Priya harshapriya.n@intel.com --- Documentation/devicetree/bindings/sound/dmic.txt | 2 ++ sound/soc/codecs/dmic.c | 31 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/dmic.txt b/Documentation/devicetree/bindings/sound/dmic.txt index e957b41..32e8710 100644 --- a/Documentation/devicetree/bindings/sound/dmic.txt +++ b/Documentation/devicetree/bindings/sound/dmic.txt @@ -9,6 +9,7 @@ Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop - num-channels: Number of microphones on this DAI - wakeup-delay-ms: Delay (in ms) after enabling the DMIC + - modeswitch-delay-ms: Delay (in ms) to complete DMIC mode switch
Example node:
@@ -17,4 +18,5 @@ Example node: dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; num-channels = <1>; wakeup-delay-ms <50>; + modeswitch-delay-ms <35>; }; diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c index 8c4926d..d8b7da7 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -30,9 +30,35 @@ #include <sound/soc.h> #include <sound/soc-dapm.h>
+static int modeswitch_delay; +module_param(modeswitch_delay, uint, 0644); + struct dmic { struct gpio_desc *gpio_en; int wakeup_delay; + /* Delay after DMIC mode switch */ + int modeswitch_delay; +}; + +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) + mdelay(dmic->modeswitch_delay); + + 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); + if (modeswitch_delay) + dmic->modeswitch_delay = modeswitch_delay;
snd_soc_component_set_drvdata(component, dmic);

On Mon, Nov 19, 2018 at 10:23:05PM +0530, Jenny TC wrote:
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_STOP:
if (dmic->modeswitch_delay)
mdelay(dmic->modeswitch_delay);
Given that this is a busy waiting delay in atomic context it would be better to have some validation when we parse the property to make sure the value is half way sensible.

On Mon, Nov 19, 2018 at 10:23:05PM +0530, Jenny TC wrote:
Signed-off-by: Sathyanarayana Nujella sathyanarayana.nujella@intel.com Signed-off-by: Jairaj Arava jairaj.arava@intel.com Signed-off-by: Harsha Priya harshapriya.n@intel.com
You haven't provided your own Signed-off-by for this, that's needed for legal reasons - see submitting-patches.rst for the details.

Introducing a module param for wakeup_delay in order to align with modeswitch_delay parameter. With this change, both wakeup_delay and modeswitch_delay parameters can be passed as module parameters.
Signed-off-by: Jenny TC jenny.tc@intel.com --- sound/soc/codecs/dmic.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c index d8b7da7..b007ec6 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -33,6 +33,9 @@ static int modeswitch_delay; module_param(modeswitch_delay, uint, 0644);
+static int wakeup_delay; +module_param(wakeup_delay, uint, 0644); + struct dmic { struct gpio_desc *gpio_en; int wakeup_delay; @@ -114,6 +117,8 @@ static int dmic_component_probe(struct snd_soc_component *component) &dmic->wakeup_delay); device_property_read_u32(component->dev, "modeswitch-delay-ms", &dmic->modeswitch_delay); + if (wakeup_delay) + dmic->wakeup_delay = wakeup_delay; if (modeswitch_delay) dmic->modeswitch_delay = modeswitch_delay;

On 11/19/18 10:53 AM, Jenny TC wrote:
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
v4: Addressed parameter name to align with existing parameter. Added dt entry in Documentation
Jenny TC (2): ASoC: dmic: introduce mode switch delay ASoC: dmic: introduce module_param wakeup_delay
Thanks Jenny, LGTM. Both patches
Acked-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com
Documentation/devicetree/bindings/sound/dmic.txt | 2 ++ sound/soc/codecs/dmic.c | 36 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
participants (3)
-
Jenny TC
-
Mark Brown
-
Pierre-Louis Bossart