All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <andy.shevchenko@gmail.com>
Cc: <broonie@kernel.org>, <lee@kernel.org>, <robh+dt@kernel.org>,
	<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
	<linus.walleij@linaro.org>, <vkoul@kernel.org>,
	<lgirdwood@gmail.com>, <yung-chuan.liao@linux.intel.com>,
	<sanyog.r.kale@intel.com>, <pierre-louis.bossart@linux.intel.com>,
	<alsa-devel@alsa-project.org>, <patches@opensource.cirrus.com>,
	<devicetree@vger.kernel.org>, <linux-gpio@vger.kernel.org>,
	<linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v7 6/6] ASoC: cs42l43: Add support for the cs42l43
Date: Fri, 19 Jan 2024 16:59:17 +0000	[thread overview]
Message-ID: <20240119165917.GC16899@ediswmail.ad.cirrus.com> (raw)
In-Reply-To: <Zali4qxdegY7H6eY@surfacebook.localdomain>

On Thu, Jan 18, 2024 at 07:41:54PM +0200, andy.shevchenko@gmail.com wrote:
> Fri, Aug 04, 2023 at 11:46:02AM +0100, Charles Keepax kirjoitti:
> > +static const unsigned int cs42l43_accdet_us[] = {
> > +	20, 100, 1000, 10000, 50000, 75000, 100000, 200000
> 
> + comma.
> 
> > +};
> > +
> > +static const unsigned int cs42l43_accdet_db_ms[] = {
> > +	0, 125, 250, 500, 750, 1000, 1250, 1500
> 
> Ditto.
> 

Can do.

> > +		device_property_read_u32_array(cs42l43->dev, "cirrus,buttons-ohms",
> > +					       priv->buttons, ret);
> 
> Strictly speaking this might fail, better to check the error code again.
> 

Yeah should probably add an error check there.

> > +	int timeout_ms = ((2 * priv->detect_us) / 1000) + 200;
> 
> USEC_PER_MSEC ?
> 

Can do.

> > +	BUILD_BUG_ON(ARRAY_SIZE(cs42l43_jack_override_modes) !=
> > +		     ARRAY_SIZE(cs42l43_jack_text) - 1);
> 
> Use static_assert() instead.
> 

I am happy either way, but for my own education what is the
reason to prefer static_assert here, is it just to be able to use
== rather than !=? Or is there in general a preference to use
static_assert, there is no obvious since BUILD_BUG_ON is being
deprecated?

> > +static void cs42l43_mask_to_slots(struct cs42l43_codec *priv, unsigned int mask, int *slots)
> > +{
> > +	int i;
> > +
> > +	for (i = 0; i < CS42L43_ASP_MAX_CHANNELS; ++i) {
> > +		int slot = ffs(mask) - 1;
> > +
> > +		if (slot < 0)
> > +			return;
> > +
> > +		slots[i] = slot;
> > +
> > +		mask &= ~(1 << slot);
> > +	}
> 
> for_each_set_bit() ?
> 
> > +	if (mask)
> > +		dev_warn(priv->dev, "Too many channels in TDM mask\n");
> > +}
> 

Can do.

> > +static int cs42l43_decim_get(struct snd_kcontrol *kcontrol,
> > +			     struct snd_ctl_elem_value *ucontrol)
> > +{
> > +	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
> > +	struct cs42l43_codec *priv = snd_soc_component_get_drvdata(component);
> > +	int ret;
> > +
> > +	ret = cs42l43_shutter_get(priv, CS42L43_STATUS_MIC_SHUTTER_MUTE_SHIFT);
> > +	if (ret < 0)
> > +		return ret;
> > +	else if (!ret)
> 
> Reundant 'else'
> 
> > +		ucontrol->value.integer.value[0] = ret;
> > +	else
> > +		ret = cs42l43_dapm_get_volsw(kcontrol, ucontrol);
> 
> and why not positive check?
> 
> > +	return ret;
> 
> Or even simply as
> 
> 	if (ret > 0)
> 		ret = cs42l43_dapm_get_volsw(kcontrol, ucontrol);
> 	else if (ret == 0)
> 		ucontrol->value.integer.value[0] = ret;
> 
> 	return ret;

Yeah will update, that is definitely neater.

> > +	while (freq > cs42l43_pll_configs[ARRAY_SIZE(cs42l43_pll_configs) - 1].freq) {
> > +		div++;
> > +		freq /= 2;
> > +	}
> 
> fls() / fls_long()?

Apologies but I might need a little bit more of a pointer here.
We need to scale freq down to under 3.072MHz and I am struggling
a little to see how to do that with fls.

> > +	// Don't use devm as we need to get against the MFD device
> 
> This is weird...
> 
> > +	priv->mclk = clk_get_optional(cs42l43->dev, "mclk");
> > +	if (IS_ERR(priv->mclk)) {
> > +		dev_err_probe(priv->dev, PTR_ERR(priv->mclk), "Failed to get mclk\n");
> > +		goto err_pm;
> > +	}
> > +
> > +	ret = devm_snd_soc_register_component(priv->dev, &cs42l43_component_drv,
> > +					      cs42l43_dais, ARRAY_SIZE(cs42l43_dais));
> > +	if (ret) {
> > +		dev_err_probe(priv->dev, ret, "Failed to register component\n");
> > +		goto err_clk;
> > +	}
> > +
> > +	pm_runtime_mark_last_busy(priv->dev);
> > +	pm_runtime_put_autosuspend(priv->dev);
> > +
> > +	return 0;
> > +
> > +err_clk:
> > +	clk_put(priv->mclk);
> > +err_pm:
> > +	pm_runtime_put_sync(priv->dev);
> > +
> > +	return ret;
> > +}
> > +
> > +static int cs42l43_codec_remove(struct platform_device *pdev)
> > +{
> > +	struct cs42l43_codec *priv = platform_get_drvdata(pdev);
> > +
> > +	clk_put(priv->mclk);
> 
> You have clocks put before anything else, and your remove order is broken now.
> 
> To fix this (in case you may not used devm_clk_get() call), you should drop
> devm calls all way after the clk_get(). Do we have
> snd_soc_register_component()? If yes, use it to fix.
> 
> I believe you never tested rmmod/modprobe in a loop.
> 

Hmm... will need to think this through a little bit, so might take
a little longer on this one. But I guess this only becomes a problem
if you attempt to remove the driver whilst you are currently playing
audio, and I would expect the card tear down would stop the clock
running before we get here.

> > +static const struct dev_pm_ops cs42l43_codec_pm_ops = {
> > +	SET_RUNTIME_PM_OPS(NULL, cs42l43_codec_runtime_resume, NULL)
> > +};
> 
> Why not new PM macros?
> 

Already been updated in another patch.

> > +		.pm	= &cs42l43_codec_pm_ops,
> 
> pm_sleep_ptr()?
> 

Can do.

> > +#include <linux/clk.h>
> > +#include <linux/device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/soundwire/sdw.h>
> > +#include <linux/types.h>
> > +#include <sound/cs42l43.h>
> > +#include <sound/pcm.h>
> > +#include <sound/soc-jack.h>
> 
> This block is messed up. Some headers can be replaced by forward declarations,
> some are missing... Please, follow IWYU principle.
> 
> > +#ifndef CS42L43_ASOC_INT_H
> > +#define CS42L43_ASOC_INT_H
> 
> Why not guarding other inclusions? It makes build slower!
> 

Will shuffle these headers around as well.

Thanks,
Charles

  parent reply	other threads:[~2024-01-19 16:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04 10:45 [PATCH v7 0/6] Add cs42l43 PC focused SoundWire CODEC Charles Keepax
2023-08-04 10:45 ` [PATCH v7 1/6] soundwire: bus: Allow SoundWire peripherals to register IRQ handlers Charles Keepax
2024-01-18 16:16   ` andy.shevchenko
2023-08-04 10:45 ` [PATCH v7 2/6] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding Charles Keepax
2023-08-04 10:45 ` [PATCH v7 3/6] mfd: cs42l43: Add support for cs42l43 core driver Charles Keepax
2023-08-29 14:06   ` Guenter Roeck
2023-08-29 16:22     ` Charles Keepax
2023-08-31 13:54     ` Guenter Roeck
2024-01-18 16:42   ` andy.shevchenko
2024-01-19 11:32     ` Charles Keepax
2024-01-19 16:01       ` Andy Shevchenko
2023-08-04 10:46 ` [PATCH v7 4/6] pinctrl: cs42l43: Add support for the cs42l43 Charles Keepax
2024-01-18 16:56   ` andy.shevchenko
2023-08-04 10:46 ` [PATCH v7 5/6] spi: cs42l43: Add SPI controller support Charles Keepax
2024-01-18 17:06   ` andy.shevchenko
2024-01-19 11:49     ` Charles Keepax
2024-01-19 16:09       ` Andy Shevchenko
2024-01-31 15:41       ` Charles Keepax
2024-01-31 20:17         ` Andy Shevchenko
2023-08-04 10:46 ` [PATCH v7 6/6] ASoC: cs42l43: Add support for the cs42l43 Charles Keepax
2024-01-18 17:41   ` andy.shevchenko
2024-01-18 18:11     ` Mark Brown
2024-01-18 20:46       ` Andy Shevchenko
2024-01-18 22:07         ` Mark Brown
2024-01-19 16:13           ` Andy Shevchenko
2024-01-19 16:59     ` Charles Keepax [this message]
2024-01-19 17:24       ` Andy Shevchenko
2023-08-17 11:09 ` (subset) [PATCH v7 0/6] Add cs42l43 PC focused SoundWire CODEC Lee Jones
2023-08-17 11:26   ` Lee Jones
2023-08-18 15:40 ` [GIT PULL] Immutable branch between MFD, Pinctrl and soundwire due for the v6.6 merge window Lee Jones
2023-08-18 22:39 ` (subset) [PATCH v7 0/6] Add cs42l43 PC focused SoundWire CODEC Mark Brown
2023-08-22 16:33 ` Mark Brown
2024-01-18 16:58 ` andy.shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240119165917.GC16899@ediswmail.ad.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=robh+dt@kernel.org \
    --cc=sanyog.r.kale@intel.com \
    --cc=vkoul@kernel.org \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.