devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Sverdlin <alexander.sverdlin@gmail.com>
To: Herve Codina <herve.codina@bootlin.com>,
	David Rhodes	 <david.rhodes@cirrus.com>,
	Richard Fitzgerald <rf@opensource.cirrus.com>,
	 Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski	 <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jaroslav Kysela	 <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Nikita Shubin	 <nikita.shubin@maquefel.me>,
	Axel Lin <axel.lin@ingics.com>,
	Brian Austin	 <brian.austin@cirrus.com>
Cc: linux-sound@vger.kernel.org, patches@opensource.cirrus.com,
	 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH 3/3] ASoC: cs4271: Add support for the external mclk
Date: Thu, 16 Oct 2025 21:14:46 +0200	[thread overview]
Message-ID: <f8bdecb31664317e28fff9244507944adb7c939d.camel@gmail.com> (raw)
In-Reply-To: <20251016130340.1442090-4-herve.codina@bootlin.com>

Hello Herve,

On Thu, 2025-10-16 at 15:03 +0200, Herve Codina wrote:
> The mclk (master clock) of the cs4271 codec can be an input clock.
> 
> In this case the connected clock needs to be enabled outside of any
> audio stream. Indeed, this clock is needed for i2c communication.
> 
> Add support of this clock and enable it before the first i2c transfer.

what about suspend/resume, would it make sense to disable/enable the clock
there?

> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
>  sound/soc/codecs/cs4271.c | 34 +++++++++++++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
> index ff9c6628224c..481a2c20b7cf 100644
> --- a/sound/soc/codecs/cs4271.c
> +++ b/sound/soc/codecs/cs4271.c
> @@ -10,6 +10,7 @@
>   * DAPM support not implemented.
>   */
>  
> +#include <linux/clk.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
>  #include <linux/delay.h>
> @@ -163,6 +164,7 @@ struct cs4271_private {
>  	/* enable soft reset workaround */
>  	bool				enable_soft_reset;
>  	struct regulator_bulk_data      supplies[ARRAY_SIZE(supply_names)];
> +	struct clk *clk;
>  };
>  
>  static const struct snd_soc_dapm_widget cs4271_dapm_widgets[] = {
> @@ -567,22 +569,36 @@ static int cs4271_component_probe(struct snd_soc_component *component)
>  		cs4271->enable_soft_reset = cs4271plat->enable_soft_reset;
>  	}
>  
> +	ret = clk_prepare_enable(cs4271->clk);
> +	if (ret) {
> +		dev_err(component->dev, "Failed to enable clk: %d\n", ret);
> +		goto err_disable_regulators;
> +	}
> +
> +	/*
> +	 * Be sure to have the clock and power-supplies stable before releasing
> +	 * the reset.
> +	 */

Would "if (cs4271->clk)" make sense for the fsleep() call?

> +	fsleep(1000);
> +
>  	/* Reset codec */
>  	cs4271_reset(component);
>  
>  	ret = regcache_sync(cs4271->regmap);
>  	if (ret < 0)
> -		return ret;
> +		goto err_force_reset;
>  
>  	ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
>  				 CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
>  				 CS4271_MODE2_PDN | CS4271_MODE2_CPEN);
>  	if (ret < 0)
> -		return ret;
> +		goto err_force_reset;
> +
>  	ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
>  				 CS4271_MODE2_PDN, 0);
>  	if (ret < 0)
> -		return ret;
> +		goto err_force_reset;
> +
>  	/* Power-up sequence requires 85 uS */
>  	udelay(85);
>  
> @@ -592,6 +608,13 @@ static int cs4271_component_probe(struct snd_soc_component *component)
>  				   CS4271_MODE2_MUTECAEQUB);
>  
>  	return 0;
> +
> +err_force_reset:
> +	gpiod_set_value(cs4271->reset, 1);

Is the reset line assertion really required here?

> +	clk_disable_unprepare(cs4271->clk);
> +err_disable_regulators:
> +	regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies);

Would it make sense to fix the error path regarding regulators handling
in a separate patch (especially if you decide to extend suspend/resume)?

> +	return ret;
>  }
>  
>  static void cs4271_component_remove(struct snd_soc_component *component)
> @@ -603,6 +626,7 @@ static void cs4271_component_remove(struct snd_soc_component *component)
>  
>  	regcache_mark_dirty(cs4271->regmap);
>  	regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies);
> +	clk_disable_unprepare(cs4271->clk);
>  };
>  
>  static const struct snd_soc_component_driver soc_component_dev_cs4271 = {
> @@ -637,6 +661,10 @@ static int cs4271_common_probe(struct device *dev,
>  				     "error retrieving RESET GPIO\n");
>  	gpiod_set_consumer_name(cs4271->reset, "CS4271 Reset");
>  
> +	cs4271->clk = devm_clk_get_optional(dev, "mclk");
> +	if (IS_ERR(cs4271->clk))
> +		return dev_err_probe(dev, PTR_ERR(cs4271->clk), "Failed to get mclk\n");
> +
>  	for (i = 0; i < ARRAY_SIZE(supply_names); i++)
>  		cs4271->supplies[i].supply = supply_names[i];
>  

-- 
Alexander Sverdlin.

  reply	other threads:[~2025-10-16 19:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 13:03 [PATCH 0/3] Add support for an external Master Clock in the Cirrus CS4271 codec Herve Codina
2025-10-16 13:03 ` [PATCH 1/3] ASoC: cs4271: Fix cs4271 I2C and SPI drivers automatic module loading Herve Codina
2025-10-16 18:40   ` Alexander Sverdlin
2025-10-17  6:32     ` Herve Codina
2025-10-17 13:25       ` Alexander Sverdlin
2025-10-17 14:41         ` Alexander Sverdlin
2025-10-17 15:01           ` Mark Brown
2025-10-17 18:14             ` Alexander Sverdlin
2025-10-21 19:00               ` Mark Brown
2025-10-21 19:12                 ` Alexander Sverdlin
2025-10-22 14:56                   ` Mark Brown
2025-10-22 17:46                     ` Alexander Sverdlin
2025-10-22 18:01                       ` Mark Brown
2025-10-23 11:40                       ` Javier Martinez Canillas
2025-10-23 12:32                         ` Alexander Sverdlin
2025-10-17 15:10         ` Herve Codina
2025-10-17 15:35           ` Alexander Sverdlin
2025-10-17 16:03             ` Herve Codina
2025-10-21 17:25               ` Herve Codina
2025-10-16 13:03 ` [PATCH 2/3] ASoC: dt-bindings: cirrus,cs4271: Document mclk clock Herve Codina
2025-10-22  7:57   ` Krzysztof Kozlowski
2025-10-16 13:03 ` [PATCH 3/3] ASoC: cs4271: Add support for the external mclk Herve Codina
2025-10-16 19:14   ` Alexander Sverdlin [this message]
2025-10-16 19:17   ` Mark Brown

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=f8bdecb31664317e28fff9244507944adb7c939d.camel@gmail.com \
    --to=alexander.sverdlin@gmail.com \
    --cc=axel.lin@ingics.com \
    --cc=brian.austin@cirrus.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=david.rhodes@cirrus.com \
    --cc=devicetree@vger.kernel.org \
    --cc=herve.codina@bootlin.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=nikita.shubin@maquefel.me \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=rf@opensource.cirrus.com \
    --cc=robh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).