Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] ASoC: ti: omap3pandora: broken built-in McBSP names and missing
  DT DAI parsing
- [High] ASoC: ti: omap3pandora: missing SND_SOC_PCM1754 select in
  Kconfig
- [Medium] ASoC: ti: omap3pandora: grab_sample_rate() rejects
  single-stream rate change
- [Medium] ASoC: ti: omap3pandora: static open-time rate constraint in
  startup()
- [Medium] ASoC: ti: omap3pandora: missing snd_soc_pm_ops on
  omap3pandora_driver
- [Medium] ASoC: ti: omap3pandora: missing TWL4030_CLOCK_APLL setup in
  capture hw_params
- [Low] ASoC: ti: omap3pandora: omap3pandora_probe() requires optional
  DT properties
- [Low] ASoC: ti: omap3pandora: unused codec_dai variable and
  mach-types.h include
--

commit b90618564a61935165b508799b8ef7f6f6a36708
Author: Stefan Leichter <[email protected]>

ASoC: ti: omap3pandora: Convert sound card to DT

This commit converts the OpenPandora ASoC machine driver to probe via a
Device Tree sound-card node, separates playback and capture handling
with shared TWL4030 APLL rate accounting, and switches to device-managed
resource registration.

> diff --git a/sound/soc/ti/omap3pandora.c b/sound/soc/ti/omap3pandora.c
> index 6c9c184cd9d6f..d747c0e6b48cb 100644
> --- a/sound/soc/ti/omap3pandora.c
> +++ b/sound/soc/ti/omap3pandora.c
> @@ -6,138 +6,274 @@

[ ... ]

> +#include <asm/mach-types.h>
> +#include <linux/mfd/twl4030-audio.h>
>  #include <linux/platform_data/asoc-ti-mcbsp.h>
>  
>  #include "omap-mcbsp.h"
>  
> -#define PREFIX "ASoC omap3pandora: "
> +struct omap3pandora_sound {
> +     struct gpio_desc *amp_gpio;
> +     struct regulator *amp_regulator;
> +
> +     struct snd_pcm_substream *playback_stream;
> +     struct snd_pcm_substream *capture_stream;
> +
> +     struct mutex sample_rate_lock; // protects all fields after
> +     unsigned int sample_rate;
> +     int sample_rate_users;
> +};
>  
> -static struct regulator *omap3pandora_dac_reg;
> -static struct gpio_desc *dac_power_gpio;
> -static struct gpio_desc *amp_power_gpio;
> +static struct snd_soc_dai_link omap3pandora_dai[];
>  
> -static int omap3pandora_hw_params(struct snd_pcm_substream *substream,
> -     struct snd_pcm_hw_params *params)
> +static int omap3pandora_common_hw_params(struct snd_pcm_substream *substream,
> +                                      struct snd_pcm_hw_params *params)
>  {
>       struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> -     struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
> +     __maybe_unused struct snd_soc_dai *codec_dai = 
> snd_soc_rtd_to_codec(rtd, 0);

[Severity: Low]
This isn't a bug, but codec_dai in omap3pandora_common_hw_params() and the
new <asm/mach-types.h> include are both unused and can be dropped.

[ ... ]

> +/* The McBSP playback and capture interfaces share the TWL4030 APLL. */
> +static int grab_sample_rate(struct omap3pandora_sound *ctx,
> +                         struct snd_pcm_substream **owner,
> +                         struct snd_pcm_substream *substream,
> +                         struct snd_pcm_hw_params *params,
> +                         bool *new_owner)
> +{
> +     unsigned int rate = params_rate(params);
> +     int ret = 0;
> +
> +     *new_owner = false;
> +     mutex_lock(&ctx->sample_rate_lock);
> +     if (*owner == substream) {
> +             if (ctx->sample_rate != rate)
> +                     ret = -EINVAL;
> +     } else if (*owner || (ctx->sample_rate_users &&
> +                             ctx->sample_rate != rate)) {
> +             ret = -EINVAL;
> +     } else {
> +             ctx->sample_rate = rate;
> +             ctx->sample_rate_users++;
> +             *owner = substream;
> +             *new_owner = true;
> +     }
> +     mutex_unlock(&ctx->sample_rate_lock);
> +
> +     return ret;
> +}

[Severity: Medium]
Does grab_sample_rate() reject sample-rate changes on a substream even
when no other stream is active?

ALSA allows userspace to call SNDRV_PCM_IOCTL_HW_PARAMS more than once on
an open substream without an intervening hw_free().  When *owner ==
substream and ctx->sample_rate_users == 1, returning -EINVAL on
ctx->sample_rate != rate causes snd_pcm_hw_params() to fail and call
hw_free(), dropping the reservation anyway.  If ctx->sample_rate_users ==
1, *owner == substream should be allowed to update ctx->sample_rate to the
new rate.

[ ... ]

> +static int omap3pandora_capture_hw_params(struct snd_pcm_substream 
> *substream,
> +                                       struct snd_pcm_hw_params *params)
> +{
> +     struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> +     struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
> +     struct device *dev = rtd->dev;
> +     struct snd_soc_card *card = rtd->card;
> +     struct omap3pandora_sound *ctx = snd_soc_card_get_drvdata(card);
> +     bool new_owner;
> +     int ret;
> +
> +     /* Set the codec system clock for DAC and ADC */
> +     ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
> +                                  SND_SOC_CLOCK_IN);
> +     if (ret < 0) {
> +             dev_err(dev, "cannot set TWL4030 system clock: %d\n", ret);
> +             return ret;
> +     }
> +
> +     ret = grab_sample_rate(ctx, &ctx->capture_stream, substream,
> +                            params, &new_owner);
> +     if (ret)
> +             return ret;
> +
> +     ret = omap3pandora_common_hw_params(substream, params);
> +     if (ret)
> +             goto err_release;
>       return 0;

[Severity: Medium]
Does omap3pandora_capture_hw_params() also need to program
TWL4030_CLOCK_APLL via snd_soc_dai_set_sysclk()?

In sound/soc/codecs/twl4030.c, twl4030_hw_params() sets
twl4030->configured = 1 on the first hw_params() call and returns early
without updating TWL4030_REG_CODEC_MODE until twl4030_shutdown() clears
twl4030->configured:

sound/soc/codecs/twl4030.c:twl4030_hw_params() {
    ...
         /* If the substream has no subscribers, the Giacinto
          * is already configured, so we can return */
        if (twl4030->configured)
                return 0;
    ...
}

If an open capture substream runs hw_params(), hw_free() (which releases
ctx->capture_stream), and then hw_params() at a new rate (or if playback
changed the APLL rate in the meantime), McBSP4 is reconfigured to 256 *
new_rate while the TWL4030 APLL stays at the old frequency.

[ ... ]

> +static int omap3pandora_common_startup(struct snd_pcm_substream *substream)
> +{
> +     struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> +     struct snd_soc_card *card = rtd->card;
> +     struct omap3pandora_sound *ctx = snd_soc_card_get_drvdata(card);
> +     unsigned int sample_rate;
> +
> +     mutex_lock(&ctx->sample_rate_lock);
> +     sample_rate = ctx->sample_rate;
> +     mutex_unlock(&ctx->sample_rate_lock);
> +
> +     if (!sample_rate)
> +             return 0;
> +
> +     return constrain_sample_rate(substream, sample_rate);
> +}

[Severity: Medium]
Can constraining the rate from a snapshot of ctx->sample_rate in startup()
leave a substream either unconstrained or locked to a stale rate?

Because ctx->sample_rate is only set later in hw_params(), a full-duplex
application that opens both playback and capture before configuring
hw_params() sees ctx->sample_rate == 0 in both startup() calls and gets no
rate constraint.  Conversely, if stream B opens while stream A is running
at rate R1, stream B is permanently constrained to R1 via
snd_pcm_hw_constraint_single(); if stream A then closes and reopens at
rate R2 != R1 before stream B runs hw_params(), stream B cannot succeed at
any rate.

> @@ -171,20 +307,40 @@ static int omap3pandora_in_init(struct 
> snd_soc_pcm_runtime *rtd)

[ ... ]

>  /* Digital audio interface glue - connects codec <--> CPU */
> +#if IS_BUILTIN(CONFIG_SND_SOC_OMAP3_PANDORA)
>  SND_SOC_DAILINK_DEFS(out,
>       DAILINK_COMP_ARRAY(COMP_CPU("omap-mcbsp.2")),
> -     DAILINK_COMP_ARRAY(COMP_CODEC("twl4030-codec", "twl4030-hifi")),
> +     DAILINK_COMP_ARRAY(COMP_CODEC("pcm1773-codec", "pcm1773")),
>       DAILINK_COMP_ARRAY(COMP_PLATFORM("omap-mcbsp.2")));
>  
>  SND_SOC_DAILINK_DEFS(in,
>       DAILINK_COMP_ARRAY(COMP_CPU("omap-mcbsp.4")),
>       DAILINK_COMP_ARRAY(COMP_CODEC("twl4030-codec", "twl4030-hifi")),
>       DAILINK_COMP_ARRAY(COMP_PLATFORM("omap-mcbsp.4")));
> +#else /* IS_BUILTIN(CONFIG_SND_SOC_OMAP3_PANDORA) */
> +SND_SOC_DAILINK_DEFS(out,
> +                  DAILINK_COMP_ARRAY(COMP_CPU("49022000.mcbsp")),
> +     DAILINK_COMP_ARRAY(COMP_CODEC("pcm1773-codec", "pcm1773")),
> +     DAILINK_COMP_ARRAY(COMP_PLATFORM("49022000.mcbsp")));
> +
> +SND_SOC_DAILINK_DEFS(in,
> +                  DAILINK_COMP_ARRAY(COMP_CPU("49026000.mcbsp")),
> +     DAILINK_COMP_ARRAY(COMP_CODEC("twl4030-codec", "twl4030-hifi")),
> +     DAILINK_COMP_ARRAY(COMP_PLATFORM("49026000.mcbsp")));
> +#endif /* IS_BUILTIN(CONFIG_SND_SOC_OMAP3_PANDORA) */

[Severity: High]
Does SND_SOC_OMAP3_PANDORA in sound/soc/ti/Kconfig need to select
SND_SOC_PCM1754 now that the playback DAI link binds to the pcm1773 DAI?

Without select SND_SOC_PCM1754 in Kconfig, configs enabling
CONFIG_SND_SOC_OMAP3_PANDORA (such as omap2plus_defconfig) do not build
sound/soc/codecs/pcm1754.c, leaving the playback link unbound.

[Severity: High]
Why do the DAI links hardcode component names and branch on
IS_BUILTIN(CONFIG_SND_SOC_OMAP3_PANDORA) instead of populating the DAI
link of_node pointers from Device Tree?

On DT-based OMAP3 kernels, the McBSP devices are always named
"49022000.mcbsp" and "49026000.mcbsp" regardless of whether this driver is
built-in or a module, so CONFIG_SND_SOC_OMAP3_PANDORA=y searches for
"omap-mcbsp.2" and "omap-mcbsp.4" and never binds.  In addition,
sound/soc/codecs/pcm1754.c leaves soc_component_dev_pcm1754.name NULL, so
the codec component is named after the DT node (for example "dac" in the
binding example) rather than "pcm1773-codec", and omap3pandora_probe()
never parses the sound-dai phandles into cpus->of_node, platforms->of_node
and codecs->of_node.

> @@ -192,100 +348,122 @@ static struct snd_soc_dai_link omap3pandora_dai[] = {

[ ... ]

> +     if (dev->of_node) {
> +             ret = snd_soc_of_parse_card_name(card, "label");
> +             if (ret)
> +                     card->name = "omap3pandora";
> +
> +             ret = snd_soc_of_parse_audio_simple_widgets(card, "widgets");
> +             if (ret) {
> +                     dev_err(dev, "Failed to parse DAPM widgets: %d\n", ret);
> +                     return ret;
> +             }
> +
> +             ret = snd_soc_of_parse_audio_routing(card, "routing");
> +             if (ret) {
> +                     dev_err(dev, "Failed to parse audio routing: %d\n", 
> ret);
> +                     return ret;
> +             }
>       }

[Severity: Low]
Should omap3pandora_probe() check whether the "widgets" and "routing"
properties exist before calling snd_soc_of_parse_audio_simple_widgets()
and snd_soc_of_parse_audio_routing()?

Both helpers return -EINVAL when the property is absent, whereas the DT
binding only lists compatible and sound-dai as required.

[ ... ]

> +static struct platform_driver omap3pandora_driver = {
> +     .driver = {
> +             .name = "omap3pandora-sound",
> +             .of_match_table = omap3pandora_of_match,
> +     },
> +     .probe = omap3pandora_probe,
> +};

[Severity: Medium]
Should omap3pandora_driver.driver set .pm = &snd_soc_pm_ops?

Previously, registering a "soc-audio" platform device bound the card to
soc_driver in sound/soc/soc-core.c, which wires up snd_soc_pm_ops.
Omitting .pm here disables ASoC card suspend, resume, and poweroff
callbacks.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=7

Reply via email to