From: Herve Codina <herve.codina@bootlin.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH 2/3] ASoC: codecs: Add support for the Infineon PEB2466 codec
Date: Wed, 8 Feb 2023 08:10:48 +0100 [thread overview]
Message-ID: <20230208081048.0708037f@bootlin.com> (raw)
In-Reply-To: <fd3ccda3-f964-6904-6056-f93c43b85a0f@wanadoo.fr>
On Tue, 7 Feb 2023 22:17:39 +0100
Hi Christophe,
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> Le 06/02/2023 à 15:49, Herve Codina a écrit :
> > The Infineon PEB2466 codec is a programmable DSP-based four channels
> > codec with filters capabilities.
> > It also provides signals as GPIOs.
> >
> > Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> > ---
> > sound/soc/codecs/Kconfig | 12 +
> > sound/soc/codecs/Makefile | 2 +
> > sound/soc/codecs/peb2466.c | 2071 ++++++++++++++++++++++++++++++++++++
> > 3 files changed, 2085 insertions(+)
> > create mode 100644 sound/soc/codecs/peb2466.c
> >
>
> [...]
>
> > +static int peb2466_spi_probe(struct spi_device *spi)
> > +{
> > + struct peb2466 *peb2466;
> > + unsigned long mclk_rate;
> > + int ret;
> > + u8 xr5;
> > +
> > + spi->bits_per_word = 8;
> > + ret = spi_setup(spi);
> > + if (ret < 0)
> > + return ret;
> > +
> > + peb2466 = devm_kzalloc(&spi->dev, sizeof(*peb2466), GFP_KERNEL);
> > + if (!peb2466)
> > + return -ENOMEM;
> > +
> > + peb2466->spi = spi;
> > +
> > + peb2466->regmap = devm_regmap_init(&peb2466->spi->dev, NULL, peb2466,
> > + &peb2466_regmap_config);
> > + if (IS_ERR(peb2466->regmap))
> > + return PTR_ERR(peb2466->regmap);
> > +
> > + peb2466->reset_gpio = devm_gpiod_get_optional(&peb2466->spi->dev,
> > + "reset", GPIOD_OUT_LOW);
> > + if (IS_ERR(peb2466->reset_gpio))
> > + return PTR_ERR(peb2466->reset_gpio);
> > +
> > + peb2466->mclk = devm_clk_get(&peb2466->spi->dev, "mclk");
>
> Hi,
>
> Up to you to decide if it is a good idea or not, but using
> devm_clk_get_enabled() would save the 'mclk' field in peb2466 ...
>
> > + if (IS_ERR(peb2466->mclk))
> > + return PTR_ERR(peb2466->mclk);
> > + ret = clk_prepare_enable(peb2466->mclk);
> > + if (ret)
> > + return ret;
>
> ... these 3 lines ...
>
> > +
> > + if (peb2466->reset_gpio) {
> > + gpiod_set_value_cansleep(peb2466->reset_gpio, 1);
> > + udelay(4);
> > + gpiod_set_value_cansleep(peb2466->reset_gpio, 0);
> > + udelay(4);
> > + }
> > +
> > + spi_set_drvdata(spi, peb2466);
>
> ... this spi_set_drvdata() call ...
>
> > +
> > + mclk_rate = clk_get_rate(peb2466->mclk);
> > + switch (mclk_rate) {
> > + case 1536000:
> > + xr5 = PEB2466_XR5_MCLK_1536;
> > + break;
> > + case 2048000:
> > + xr5 = PEB2466_XR5_MCLK_2048;
> > + break;
> > + case 4096000:
> > + xr5 = PEB2466_XR5_MCLK_4096;
> > + break;
> > + case 8192000:
> > + xr5 = PEB2466_XR5_MCLK_8192;
> > + break;
> > + default:
> > + dev_err(&peb2466->spi->dev, "Unsupported clock rate %lu\n",
> > + mclk_rate);
> > + ret = -EINVAL;
> > + goto failed;
> > + }
> > + ret = regmap_write(peb2466->regmap, PEB2466_XR5, xr5);
> > + if (ret) {
> > + dev_err(&peb2466->spi->dev, "Setting MCLK failed (%d)\n", ret);
> > + goto failed;
> > + }
> > +
> > + ret = devm_snd_soc_register_component(&spi->dev, &peb2466_component_driver,
> > + &peb2466_dai_driver, 1);
> > + if (ret)
> > + goto failed;
> > +
> > + if (IS_ENABLED(CONFIG_GPIOLIB)) {
> > + ret = peb2466_gpio_init(peb2466);
> > + if (ret)
> > + goto failed;
> > + }
> > +
> > + return 0;
> > +
> > +failed:
> > + clk_disable_unprepare(peb2466->mclk);
> > + return ret;
>
> ... this error handling path ...
>
> > +}
> > +
> > +static void peb2466_spi_remove(struct spi_device *spi)
> > +{
> > + struct peb2466 *peb2466 = spi_get_drvdata(spi);
> > +
> > + clk_disable_unprepare(peb2466->mclk);
> > +}
>
> ... and the remove function.
>
> CJ
>
Thanks for pointing this.
I will use devm_clk_get_enabled() in the next series iteration as suggested.
Best regards,
Hervé
--
Hervé Codina, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2023-02-08 7:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 14:49 [PATCH 0/3] Add the Infineon PEB2466 codec support Herve Codina
2023-02-06 14:49 ` [PATCH 1/3] dt-bindings: sound: Add the Infineon PEB2466 codec Herve Codina
2023-02-07 21:06 ` Rob Herring
2023-02-06 14:49 ` [PATCH 2/3] ASoC: codecs: Add support for " Herve Codina
2023-02-07 21:17 ` Christophe JAILLET
2023-02-08 7:10 ` Herve Codina [this message]
2023-02-06 14:49 ` [PATCH 3/3] MAINTAINERS: add the Infineon PEB2466 codec entry Herve Codina
2023-02-09 18:36 ` [PATCH 0/3] Add the Infineon PEB2466 codec support 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=20230208081048.0708037f@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=alsa-devel@alsa-project.org \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=christophe.leroy@csgroup.eu \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=robh+dt@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).