From 60e1780ef27c626c7eaabae6103a218102b6e6ba Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Tue, 28 Nov 2017 06:05:46 +0000 Subject: [PATCH 1/6] ASoC: use snd_soc_component_init_regmap() on cq93vc To setup regmap, ALSA SoC has snd_soc_component_init_regmap() and .get_regmap. But these are duplicated feature. Let's use snd_soc_component_init_regmap() and remove .get_regmap Signed-off-by: Kuninori Morimoto Signed-off-by: Mark Brown --- sound/soc/codecs/cq93vc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c index 6ed2cc374768..3bf93652bb31 100644 --- a/sound/soc/codecs/cq93vc.c +++ b/sound/soc/codecs/cq93vc.c @@ -121,17 +121,19 @@ static struct snd_soc_dai_driver cq93vc_dai = { .ops = &cq93vc_dai_ops, }; -static struct regmap *cq93vc_get_regmap(struct device *dev) +static int cq93vc_probe(struct snd_soc_component *component) { - struct davinci_vc *davinci_vc = dev->platform_data; + struct davinci_vc *davinci_vc = component->dev->platform_data; - return davinci_vc->regmap; + snd_soc_component_init_regmap(component, davinci_vc->regmap); + + return 0; } static const struct snd_soc_codec_driver soc_codec_dev_cq93vc = { .set_bias_level = cq93vc_set_bias_level, - .get_regmap = cq93vc_get_regmap, .component_driver = { + .probe = cq93vc_probe, .controls = cq93vc_snd_controls, .num_controls = ARRAY_SIZE(cq93vc_snd_controls), }, From e5acfc7d3562ae251cb786b5b52d4345dd16a02c Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Tue, 5 Dec 2017 04:23:05 +0000 Subject: [PATCH 2/6] ASoC: don't use rtd->codec on snd_soc_new_compress() rtd->codec will be removed soon. rtd->codec = rtd->codec_dai->codec, thus, we can use rtd->codec_dai->component instead of it. Signed-off-by: Kuninori Morimoto Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index d9b1e6417fb9..81232f4ab614 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -1096,7 +1096,6 @@ static struct snd_compr_ops soc_compr_dyn_ops = { */ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) { - struct snd_soc_codec *codec = rtd->codec; struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; @@ -1199,8 +1198,9 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) ret = snd_compress_new(rtd->card->snd_card, num, direction, new_name, compr); if (ret < 0) { + component = rtd->codec_dai->component; pr_err("compress asoc: can't create compress for codec %s\n", - codec->component.name); + component->name); goto compr_err; } From 7fb59e940f6225beed0b24cd09e9fad9aebb7565 Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Fri, 5 Jan 2018 12:39:57 -0800 Subject: [PATCH 3/6] ASoC: codecs: dmic: Make number of channels configurable The DMIC DAI driver specifies a number of 1 to 8 channels for each DAI. The actual number of mics can currently not be configured in the device tree or audio glue, but is derived from the min/max channels of the CPU and codec DAI. A typical CPU DAI has two or more channels, in consequence a single mic is treated as a stereo/multi channel device, even though only one channel carries audio data. This change adds the option to specify the number of used DMIC channels in the device tree. When specified this value overwrites the default channels_max value of 8 in the snd_soc_dai_driver struct of the codec. Signed-off-by: Matthias Kaehlcke Reviewed-by: Rob Herring Acked-by: Arnaud Pouliquen Signed-off-by: Mark Brown --- .../devicetree/bindings/sound/dmic.txt | 2 ++ sound/soc/codecs/dmic.c | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/sound/dmic.txt b/Documentation/devicetree/bindings/sound/dmic.txt index 54c8ef6498a8..f7bf65611453 100644 --- a/Documentation/devicetree/bindings/sound/dmic.txt +++ b/Documentation/devicetree/bindings/sound/dmic.txt @@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - num-channels: Number of microphones on this DAI Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + num-channels = <1>; }; diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c index b88a1ee66f80..c88f974ebe3e 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -107,8 +107,30 @@ static const struct snd_soc_codec_driver soc_dmic = { static int dmic_dev_probe(struct platform_device *pdev) { + int err; + u32 chans; + struct snd_soc_dai_driver *dai_drv = &dmic_dai; + + if (pdev->dev.of_node) { + err = of_property_read_u32(pdev->dev.of_node, "num-channels", &chans); + if (err && (err != -ENOENT)) + return err; + + if (!err) { + if (chans < 1 || chans > 8) + return -EINVAL; + + dai_drv = devm_kzalloc(&pdev->dev, sizeof(*dai_drv), GFP_KERNEL); + if (!dai_drv) + return -ENOMEM; + + memcpy(dai_drv, &dmic_dai, sizeof(*dai_drv)); + dai_drv->capture.channels_max = chans; + } + } + return snd_soc_register_codec(&pdev->dev, - &soc_dmic, &dmic_dai, 1); + &soc_dmic, dai_drv, 1); } static int dmic_dev_remove(struct platform_device *pdev) From 8d5737a5f53902a916ee1e1cb248c9b8b883b2ea Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Wed, 17 Jan 2018 13:50:50 +0100 Subject: [PATCH 4/6] ASoC: bcm2835: fix hw_params error when device is in prepared state If bcm2835 is configured as bitclock master calling hw_params() after prepare() fails with EBUSY. This also makes it impossible to use bcm2835 in full duplex mode. The error is caused by the split clock setup: clk_set_rate is called in hw_params, clk_prepare_enable in prepare. As hw_params doesn't check if the clock was already enabled clk_set_rate fails with EBUSY. Fix this by moving clock startup from prepare to hw_params and let hw_params properly deal with an already set up or enabled clock. Signed-off-by: Matthias Reichl Signed-off-by: Mark Brown --- sound/soc/bcm/bcm2835-i2s.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c index 2e449d7173fc..d5f73a8ab893 100644 --- a/sound/soc/bcm/bcm2835-i2s.c +++ b/sound/soc/bcm/bcm2835-i2s.c @@ -130,6 +130,7 @@ struct bcm2835_i2s_dev { struct regmap *i2s_regmap; struct clk *clk; bool clk_prepared; + int clk_rate; }; static void bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev) @@ -419,10 +420,19 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, } /* Clock should only be set up here if CPU is clock master */ - if (bit_clock_master) { - ret = clk_set_rate(dev->clk, bclk_rate); - if (ret) - return ret; + if (bit_clock_master && + (!dev->clk_prepared || dev->clk_rate != bclk_rate)) { + if (dev->clk_prepared) + bcm2835_i2s_stop_clock(dev); + + if (dev->clk_rate != bclk_rate) { + ret = clk_set_rate(dev->clk, bclk_rate); + if (ret) + return ret; + dev->clk_rate = bclk_rate; + } + + bcm2835_i2s_start_clock(dev); } /* Setup the frame format */ @@ -618,8 +628,6 @@ static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream, struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai); uint32_t cs_reg; - bcm2835_i2s_start_clock(dev); - /* * Clear both FIFOs if the one that should be started * is not empty at the moment. This should only happen From b2154d729edad549842cdbaae4beda18dbb425ff Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Fri, 26 Jan 2018 13:08:44 +0000 Subject: [PATCH 5/6] ASoC: compress: Remove some extraneous blank lines Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 7973f92cd40f..b1cf758e3be2 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -145,7 +145,6 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) } } - if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) { ret = platform->driver->compr_ops->open(cstream); if (ret < 0) { @@ -307,7 +306,6 @@ static int soc_compr_free(struct snd_compr_stream *cstream) if (!codec_dai->active) codec_dai->rate = 0; - if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) rtd->dai_link->compr_ops->shutdown(cstream); @@ -460,7 +458,6 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); - switch (cmd) { case SNDRV_PCM_TRIGGER_START: snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); From 141dfc9e3751f5f245fa71416d03511b05f4e1de Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Fri, 26 Jan 2018 13:08:45 +0000 Subject: [PATCH 6/6] ASoC: compress: Fixup error messages The error message prints are a little inconsisent, tidy them up to be a little more consistent with current style recommendations. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 68 ++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index b1cf758e3be2..82402688bd8e 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -40,7 +40,8 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); if (ret < 0) { - dev_err(cpu_dai->dev, "Compress ASoC: can't open interface %s: %d\n", + dev_err(cpu_dai->dev, + "Compress ASoC: can't open interface %s: %d\n", cpu_dai->name, ret); goto out; } @@ -49,8 +50,9 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) { ret = platform->driver->compr_ops->open(cstream); if (ret < 0) { - pr_err("compress asoc: can't open platform %s\n", - platform->component.name); + dev_err(platform->dev, + "Compress ASoC: can't open platform %s: %d\n", + platform->component.name, ret); goto plat_err; } } @@ -68,8 +70,9 @@ static int soc_compr_open(struct snd_compr_stream *cstream) __ret = component->driver->compr_ops->open(cstream); if (__ret < 0) { - pr_err("compress asoc: can't open platform %s\n", - component->name); + dev_err(component->dev, + "Compress ASoC: can't open platform %s: %d\n", + component->name, __ret); ret = __ret; } } @@ -79,7 +82,9 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { ret = rtd->dai_link->compr_ops->startup(cstream); if (ret < 0) { - pr_err("compress asoc: %s startup failed\n", rtd->dai_link->name); + dev_err(rtd->dev, + "Compress ASoC: %s startup failed: %d\n", + rtd->dai_link->name, ret); goto machine_err; } } @@ -139,7 +144,8 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); if (ret < 0) { - dev_err(cpu_dai->dev, "Compress ASoC: can't open interface %s: %d\n", + dev_err(cpu_dai->dev, + "Compress ASoC: can't open interface %s: %d\n", cpu_dai->name, ret); goto out; } @@ -148,8 +154,9 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) { ret = platform->driver->compr_ops->open(cstream); if (ret < 0) { - pr_err("compress asoc: can't open platform %s\n", - platform->component.name); + dev_err(platform->dev, + "Compress ASoC: can't open platform %s: %d\n", + platform->component.name, ret); goto plat_err; } } @@ -167,8 +174,9 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) __ret = component->driver->compr_ops->open(cstream); if (__ret < 0) { - pr_err("compress asoc: can't open platform %s\n", - component->name); + dev_err(component->dev, + "Compress ASoC: can't open platform %s: %d\n", + component->name, __ret); ret = __ret; } } @@ -178,7 +186,8 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { ret = fe->dai_link->compr_ops->startup(cstream); if (ret < 0) { - pr_err("compress asoc: %s startup failed\n", fe->dai_link->name); + pr_err("Compress ASoC: %s startup failed: %d\n", + fe->dai_link->name, ret); goto machine_err; } } @@ -189,7 +198,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (ret < 0) goto fe_err; else if (ret == 0) - dev_dbg(fe->dev, "ASoC: %s no valid %s route\n", + dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n", fe->dai_link->name, stream ? "capture" : "playback"); /* calculate valid and active FE <-> BE dpcms */ @@ -264,10 +273,11 @@ static void close_delayed_work(struct work_struct *work) mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); - dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n", - codec_dai->driver->playback.stream_name, - codec_dai->playback_active ? "active" : "inactive", - rtd->pop_wait ? "yes" : "no"); + dev_dbg(rtd->dev, + "Compress ASoC: pop wq checking: %s status: %s waiting: %s\n", + codec_dai->driver->playback.stream_name, + codec_dai->playback_active ? "active" : "inactive", + rtd->pop_wait ? "yes" : "no"); /* are we waiting on this codec DAI stream */ if (rtd->pop_wait == 1) { @@ -374,7 +384,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) ret = dpcm_be_dai_hw_free(fe, stream); if (ret < 0) - dev_err(fe->dev, "compressed hw_free failed %d\n", ret); + dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret); ret = dpcm_be_dai_shutdown(fe, stream); @@ -1105,7 +1115,8 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) int playback = 0, capture = 0; if (rtd->num_codecs > 1) { - dev_err(rtd->card->dev, "Multicodec not supported for compressed stream\n"); + dev_err(rtd->card->dev, + "Compress ASoC: Multicodec not supported\n"); return -EINVAL; } @@ -1123,8 +1134,9 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) * should be set, check for that (xor) */ if (playback + capture != 1) { - dev_err(rtd->card->dev, "Invalid direction for compress P %d, C %d\n", - playback, capture); + dev_err(rtd->card->dev, + "Compress ASoC: Invalid direction for P %d, C %d\n", + playback, capture); return -EINVAL; } @@ -1152,8 +1164,9 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) rtd->dai_link->dpcm_playback, rtd->dai_link->dpcm_capture, &be_pcm); if (ret < 0) { - dev_err(rtd->card->dev, "ASoC: can't create compressed for %s\n", - rtd->dai_link->name); + dev_err(rtd->card->dev, + "Compress ASoC: can't create compressed for %s: %d\n", + rtd->dai_link->name, ret); goto compr_err; } @@ -1196,8 +1209,9 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) new_name, compr); if (ret < 0) { component = rtd->codec_dai->component; - pr_err("compress asoc: can't create compress for codec %s\n", - component->name); + dev_err(component->dev, + "Compress ASoC: can't create compress for codec %s: %d\n", + component->name, ret); goto compr_err; } @@ -1207,8 +1221,8 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) rtd->compr = compr; compr->private_data = rtd; - printk(KERN_INFO "compress asoc: %s <-> %s mapping ok\n", codec_dai->name, - cpu_dai->name); + dev_info(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n", + codec_dai->name, cpu_dai->name); return ret; compr_err: