ASoC: dmic: Add optional wakeup delay
Subsystems (3)
PATCH 1/1 ASoC: dmic: Add optional wakeup delay
On some systems a delay is needed after switching on the clocks, to allow the DMIC output to stabilize and avoid a popping noise at the beginning of the recording. Add the optional device tree property 'wakeup-delay-ms' and apply the specified delay in the new dmic_daiops_prepare().
--- .../devicetree/bindings/sound/dmic.txt | 2 + sound/soc/codecs/dmic.c | 54 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-)
Documentation/devicetree/bindings/sound/dmic.txt +2 -0
@@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - wakeup-delay-ms: Delay (in ms) after enabling the DMIC Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + wakeup-delay-ms <50>; };
sound/soc/codecs/dmic.c +40 -14
90 lines not on this page · raw message
Signature · 6 lines
2.16.1.291.g4437f3f132-goog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Matthias,
Quoted 75 lines · Matthias Kaehlcke
On some systems a delay is needed after switching on the clocks, to allow the DMIC output to stabilize and avoid a popping noise at the beginning of the recording. Add the optional device tree property 'wakeup-delay-ms' and apply the specified delay in the new
dmic_daiops_prepare().Signed-off-by Matthias Kaehlcke <[email protected]>--- .../devicetree/bindings/sound/dmic.txt | 2 + sound/soc/codecs/dmic.c | 54 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-)Documentation/devicetree/bindings/sound/dmic.txt +2
-0@@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - wakeup-delay-ms: Delay (in ms) after enabling the DMIC Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + wakeup-delay-ms <50>; };sound/soc/codecs/dmic.c +22
-3@@ -19,6 +19,7 @@* */ +#include <linux/delay.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/platform_device.h> @@ -29,24 +30,38 @@#include <sound/soc.h> #include <sound/soc-dapm.h> +struct dmic { +struct gpio_desc *gpio_en; +int wakeup_delay; +}; + +static int dmic_daiops_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); + +if (dmic->gpio_en) +gpiod_set_value (dmic->gpio_en,1 ); + +if (dmic->wakeup_delay) +msleep (dmic->wakeup_delay); + +return 0 ; +} +static int dmic_daiops_trigger (struct snd_pcm_substream *substream,int cmd,struct snd_soc_dai *dai) { -struct gpio_desc *dmic_en =snd_soc_dai_get_drvdata (dai); +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); -if (!dmic_en) +if (!dmic->gpio_en)return 0 ;switch (cmd) { -case SNDRV_PCM_TRIGGER_START :
sound/soc/codecs/dmic.c line 65
Quoted 10 lines
sound/soc/codecs/dmic.c +1
-5-case SNDRV_PCM_TRIGGER_RESUME : -case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : -gpiod_set_value (dmic_en,1 ); -break ;case SNDRV_PCM_TRIGGER_STOP :case SNDRV_PCM_TRIGGER_SUSPEND :case SNDRV_PCM_TRIGGER_PAUSE_PUSH : -gpiod_set_value (dmic_en,0 ); +gpiod_set_value (dmic->gpio_en,0 );break ;
N00b question: are you sure this is legit? Is it possible to get START/STOP/START (or similar) with no prepare() in between?
Quoted 24 lines
sound/soc/codecs/dmic.c +10
-1}@@ -54,6 +69,7 @@ static int dmic_daiops_trigger(struct snd_pcm_substream *substream, }static const struct snd_soc_dai_ops dmic_dai_ops = { + .prepare = dmic_daiops_prepare, .trigger = dmic_daiops_trigger, };@@ -73,14 +89,24 @@ static struct snd_soc_dai_driver dmic_dai = {static int dmic_codec_probe (struct snd_soc_codec *codec) { -struct gpio_desc *dmic_en; +struct dmic *dmic; +int err; + + dmic =devm_kzalloc (codec->dev,sizeof (*dmic),GFP_KERNEL ); +if (!dmic) +return -ENOMEM ; + + dmic->gpio_en =devm_gpiod_get_optional (codec->dev, +"dmicen" ,GPIOD_OUT_LOW );
sound/soc/codecs/dmic.c static struct snd_soc_dai_driver dmic_dai = { · line 106
Quoted 10 lines
sound/soc/codecs/dmic.c +5
-4+if (IS_ERR (dmic->gpio_en)) +return PTR_ERR (dmic->gpio_en); - dmic_en =devm_gpiod_get_optional (codec->dev, -"dmicen" ,GPIOD_OUT_LOW ); -if (IS_ERR (dmic_en)) -return PTR_ERR (dmic_en); + err =device_property_read_u32 (codec->dev,"wakeup-delay-ms" , + &dmic->wakeup_delay); +if (err && (err != -EINVAL ))
You really want to be strict about error codes? What about -ENXIO ("no suitable firmware interface is present")? Seems like we should ignore that one too.
In practice, it looks like many drivers that are reading optional properties like this just tend to ignore the return code entirely.
Brian
Quoted 10 lines
sound/soc/codecs/dmic.c +2
-1+return err; -snd_soc_codec_set_drvdata (codec, dmic_en); +snd_soc_codec_set_drvdata (codec, dmic);return 0 ; }Signature · 1 line
2.16.1.291.g4437f3f132-goog
El Wed, Feb 14, 2018 at 04:22:54PM -0800 Brian Norris ha dit:
Quoted 76 lines
Hi Matthias,
Quoted 73 lines · Matthias Kaehlcke
On some systems a delay is needed after switching on the clocks, to allow the DMIC output to stabilize and avoid a popping noise at the beginning of the recording. Add the optional device tree property 'wakeup-delay-ms' and apply the specified delay in the new
dmic_daiops_prepare().Signed-off-by Matthias Kaehlcke <[email protected]>--- .../devicetree/bindings/sound/dmic.txt | 2 + sound/soc/codecs/dmic.c | 54 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-)Documentation/devicetree/bindings/sound/dmic.txt +2
-0@@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - wakeup-delay-ms: Delay (in ms) after enabling the DMIC Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + wakeup-delay-ms <50>; };sound/soc/codecs/dmic.c +22
-2@@ -19,6 +19,7 @@* */ +#include <linux/delay.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/platform_device.h> @@ -29,24 +30,38 @@#include <sound/soc.h> #include <sound/soc-dapm.h> +struct dmic { +struct gpio_desc *gpio_en; +int wakeup_delay; +}; + +static int dmic_daiops_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); + +if (dmic->gpio_en) +gpiod_set_value (dmic->gpio_en,1 ); + +if (dmic->wakeup_delay) +msleep (dmic->wakeup_delay); + +return 0 ; +} +static int dmic_daiops_trigger (struct snd_pcm_substream *substream,int cmd,struct snd_soc_dai *dai) { -struct gpio_desc *dmic_en =snd_soc_dai_get_drvdata (dai); +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); -if (!dmic_en) +if (!dmic->gpio_en)return 0 ;
Quoted 15 lines
sound/soc/codecs/dmic.c line 65
Quoted 12 lines
sound/soc/codecs/dmic.c +1
-6switch (cmd) { -case SNDRV_PCM_TRIGGER_START : -case SNDRV_PCM_TRIGGER_RESUME : -case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : -gpiod_set_value (dmic_en,1 ); -break ;case SNDRV_PCM_TRIGGER_STOP :case SNDRV_PCM_TRIGGER_SUSPEND :case SNDRV_PCM_TRIGGER_PAUSE_PUSH : -gpiod_set_value (dmic_en,0 ); +gpiod_set_value (dmic->gpio_en,0 );break ;N00b question: are you sure this is legit? Is it possible to get START/STOP/START (or similar) with no
prepare()in between?
To be honest I can't answer this question with authority and have to defer it to the experts.
Quoted 39 lines
Quoted 24 lines
sound/soc/codecs/dmic.c +10
-1}@@ -54,6 +69,7 @@ static int dmic_daiops_trigger(struct snd_pcm_substream *substream, }static const struct snd_soc_dai_ops dmic_dai_ops = { + .prepare = dmic_daiops_prepare, .trigger = dmic_daiops_trigger, };@@ -73,14 +89,24 @@ static struct snd_soc_dai_driver dmic_dai = {static int dmic_codec_probe (struct snd_soc_codec *codec) { -struct gpio_desc *dmic_en; +struct dmic *dmic; +int err; + + dmic =devm_kzalloc (codec->dev,sizeof (*dmic),GFP_KERNEL ); +if (!dmic) +return -ENOMEM ; + + dmic->gpio_en =devm_gpiod_get_optional (codec->dev, +"dmicen" ,GPIOD_OUT_LOW );sound/soc/codecs/dmic.c static struct snd_soc_dai_driver dmic_dai = { · line 106
Quoted 10 lines
sound/soc/codecs/dmic.c +5
-4+if (IS_ERR (dmic->gpio_en)) +return PTR_ERR (dmic->gpio_en); - dmic_en =devm_gpiod_get_optional (codec->dev, -"dmicen" ,GPIOD_OUT_LOW ); -if (IS_ERR (dmic_en)) -return PTR_ERR (dmic_en); + err =device_property_read_u32 (codec->dev,"wakeup-delay-ms" , + &dmic->wakeup_delay); +if (err && (err != -EINVAL ))You really want to be strict about error codes? What about
-ENXIO("no suitable firmware interface is present")? Seems like we should ignore that one too.
Quoted 2 lines
In practice, it looks like many drivers that are reading optional properties like this just tend to ignore the return code entirely.
Ok, let's follow the common practice for optional properties then. I'll update it in v2.
Thanks
Matthias
Quoted 7 lines
sound/soc/codecs/dmic.c static struct snd_soc_dai_driver dmic_dai = { · line 112
Quoted 7 lines
sound/soc/codecs/dmic.c +2
-1+return err; -snd_soc_codec_set_drvdata (codec, dmic_en); +snd_soc_codec_set_drvdata (codec, dmic);return 0 ; }
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 46 lines · Matthias Kaehlcke
On some systems a delay is needed after switching on the clocks, to allow the DMIC output to stabilize and avoid a popping noise at the beginning of the recording. Add the optional device tree property 'wakeup-delay-ms' and apply the specified delay in the new
dmic_daiops_prepare().Signed-off-by Matthias Kaehlcke <[email protected]>--- .../devicetree/bindings/sound/dmic.txt | 2 + sound/soc/codecs/dmic.c | 54 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-)Documentation/devicetree/bindings/sound/dmic.txt +2
-0@@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - wakeup-delay-ms: Delay (in ms) after enabling the DMIC Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + wakeup-delay-ms <50>; };sound/soc/codecs/dmic.c +3
-0@@ -19,6 +19,7 @@* */ +#include <linux/delay.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/platform_device.h> @@ -29,24 +30,38 @@#include <sound/soc.h> #include <sound/soc-dapm.h> +struct dmic { +struct gpio_desc *gpio_en;
sound/soc/codecs/dmic.c line 44
Quoted 10 lines
sound/soc/codecs/dmic.c +10
-0+int wakeup_delay; +}; + +static int dmic_daiops_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); + +if (dmic->gpio_en) +gpiod_set_value (dmic->gpio_en,1 );
You don't need the 'if (dmic->gpio_en)'
Quoted 20 lines
sound/soc/codecs/dmic.c +9
-4+ +if (dmic->wakeup_delay) +msleep (dmic->wakeup_delay); + +return 0 ; +} +static int dmic_daiops_trigger (struct snd_pcm_substream *substream,int cmd,struct snd_soc_dai *dai) { -struct gpio_desc *dmic_en =snd_soc_dai_get_drvdata (dai); +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); -if (!dmic_en) +if (!dmic->gpio_en)return 0 ;switch (cmd) { -case SNDRV_PCM_TRIGGER_START : -case SNDRV_PCM_TRIGGER_RESUME :
sound/soc/codecs/dmic.c line 66
Quoted 10 lines
sound/soc/codecs/dmic.c +1
-4-case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : -gpiod_set_value (dmic_en,1 ); -break ;case SNDRV_PCM_TRIGGER_STOP :case SNDRV_PCM_TRIGGER_SUSPEND :case SNDRV_PCM_TRIGGER_PAUSE_PUSH : -gpiod_set_value (dmic_en,0 ); +gpiod_set_value (dmic->gpio_en,0 );break ; }
What if instead of this trickery we try to handle the gpio/delay via DAPM? SND_SOC_DAPM_AIF_OUT_E() might be just what we need?
We could remove the trigger, and will have no need for the prepare callback either..
Quoted 31 lines
sound/soc/codecs/dmic.c +12
-5@@ -54,6 +69,7 @@ static int dmic_daiops_trigger(struct snd_pcm_substream *substream, }static const struct snd_soc_dai_ops dmic_dai_ops = { + .prepare = dmic_daiops_prepare, .trigger = dmic_daiops_trigger, };@@ -73,14 +89,24 @@ static struct snd_soc_dai_driver dmic_dai = {static int dmic_codec_probe (struct snd_soc_codec *codec) { -struct gpio_desc *dmic_en; +struct dmic *dmic; +int err; + + dmic =devm_kzalloc (codec->dev,sizeof (*dmic),GFP_KERNEL ); +if (!dmic) +return -ENOMEM ; + + dmic->gpio_en =devm_gpiod_get_optional (codec->dev, +"dmicen" ,GPIOD_OUT_LOW ); +if (IS_ERR (dmic->gpio_en)) +return PTR_ERR (dmic->gpio_en); - dmic_en =devm_gpiod_get_optional (codec->dev, -"dmicen" ,GPIOD_OUT_LOW ); -if (IS_ERR (dmic_en)) -return PTR_ERR (dmic_en);
sound/soc/codecs/dmic.c static struct snd_soc_dai_driver dmic_dai = { · line 112
Quoted 10 lines
sound/soc/codecs/dmic.c +5
-1+ err =device_property_read_u32 (codec->dev,"wakeup-delay-ms" , + &dmic->wakeup_delay); +if (err && (err != -EINVAL )) +return err; -snd_soc_codec_set_drvdata (codec, dmic_en); +snd_soc_codec_set_drvdata (codec, dmic);return 0 ; }
- Péter
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
El Thu, Feb 15, 2018 at 09:42:01AM +0200 Peter Ujfalusi ha dit:
Quoted 47 lines · Matthias Kaehlcke
Quoted 44 lines
On some systems a delay is needed after switching on the clocks, to allow the DMIC output to stabilize and avoid a popping noise at the beginning of the recording. Add the optional device tree property 'wakeup-delay-ms' and apply the specified delay in the new
dmic_daiops_prepare().Signed-off-by Matthias Kaehlcke <[email protected]>--- .../devicetree/bindings/sound/dmic.txt | 2 + sound/soc/codecs/dmic.c | 54 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-)Documentation/devicetree/bindings/sound/dmic.txt +2
-0@@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - wakeup-delay-ms: Delay (in ms) after enabling the DMIC Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + wakeup-delay-ms <50>; };sound/soc/codecs/dmic.c +1
-0@@ -19,6 +19,7 @@* */ +#include <linux/delay.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/platform_device.h> @@ -29,24 +30,38 @@#include <sound/soc.h> #include <sound/soc-dapm.h>
Quoted 14 lines
sound/soc/codecs/dmic.c line 44
Quoted 12 lines
sound/soc/codecs/dmic.c +12
-0+struct dmic { +struct gpio_desc *gpio_en; +int wakeup_delay; +}; + +static int dmic_daiops_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); + +if (dmic->gpio_en) +gpiod_set_value (dmic->gpio_en,1 );You don't need the 'if (
dmic->gpio_en)'
True, personally I think the if statement makes it clearer that the GPIO is optional. I'm fine with removing it if the general sense is that it's just noise.
Quoted 34 lines
Quoted 20 lines
sound/soc/codecs/dmic.c +9
-4+ +if (dmic->wakeup_delay) +msleep (dmic->wakeup_delay); + +return 0 ; +} +static int dmic_daiops_trigger (struct snd_pcm_substream *substream,int cmd,struct snd_soc_dai *dai) { -struct gpio_desc *dmic_en =snd_soc_dai_get_drvdata (dai); +struct dmic *dmic =snd_soc_dai_get_drvdata (dai); -if (!dmic_en) +if (!dmic->gpio_en)return 0 ;switch (cmd) { -case SNDRV_PCM_TRIGGER_START : -case SNDRV_PCM_TRIGGER_RESUME :sound/soc/codecs/dmic.c line 66
Quoted 10 lines
sound/soc/codecs/dmic.c +1
-4-case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : -gpiod_set_value (dmic_en,1 ); -break ;case SNDRV_PCM_TRIGGER_STOP :case SNDRV_PCM_TRIGGER_SUSPEND :case SNDRV_PCM_TRIGGER_PAUSE_PUSH : -gpiod_set_value (dmic_en,0 ); +gpiod_set_value (dmic->gpio_en,0 );break ; }What if instead of this trickery we try to handle the gpio/delay via DAPM?
SND_SOC_DAPM_AIF_OUT_E()might be just what we need?
Quoted 2 lines
We could remove the trigger, and will have no need for the prepare callback either..
SND_SOC_DAPM_AIF_OUT_E() looks promising, thanks for the pointer!
Quoted 37 lines
Quoted 37 lines
sound/soc/codecs/dmic.c +17
-6@@ -54,6 +69,7 @@ static int dmic_daiops_trigger(struct snd_pcm_substream *substream, }static const struct snd_soc_dai_ops dmic_dai_ops = { + .prepare = dmic_daiops_prepare, .trigger = dmic_daiops_trigger, };@@ -73,14 +89,24 @@ static struct snd_soc_dai_driver dmic_dai = {static int dmic_codec_probe (struct snd_soc_codec *codec) { -struct gpio_desc *dmic_en; +struct dmic *dmic; +int err; + + dmic =devm_kzalloc (codec->dev,sizeof (*dmic),GFP_KERNEL ); +if (!dmic) +return -ENOMEM ; + + dmic->gpio_en =devm_gpiod_get_optional (codec->dev, +"dmicen" ,GPIOD_OUT_LOW ); +if (IS_ERR (dmic->gpio_en)) +return PTR_ERR (dmic->gpio_en); - dmic_en =devm_gpiod_get_optional (codec->dev, -"dmicen" ,GPIOD_OUT_LOW ); -if (IS_ERR (dmic_en)) -return PTR_ERR (dmic_en); + err =device_property_read_u32 (codec->dev,"wakeup-delay-ms" , + &dmic->wakeup_delay); +if (err && (err != -EINVAL )) +return err; -snd_soc_codec_set_drvdata (codec, dmic_en); +snd_soc_codec_set_drvdata (codec, dmic);
Quoted 8 lines
sound/soc/codecs/dmic.c static struct snd_soc_dai_driver dmic_dai = { · line 112
Quoted 3 lines
sound/soc/codecs/dmic.c +0
-0return 0 ; }- Péter
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel