Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1C2EC636D3 for ; Tue, 7 Feb 2023 21:17:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjBGVR5 (ORCPT ); Tue, 7 Feb 2023 16:17:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbjBGVR4 (ORCPT ); Tue, 7 Feb 2023 16:17:56 -0500 Received: from smtp.smtpout.orange.fr (smtp-22.smtpout.orange.fr [80.12.242.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 774FD17175 for ; Tue, 7 Feb 2023 13:17:49 -0800 (PST) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id PVLUp8FlEPPaiPVLUpiiRq; Tue, 07 Feb 2023 22:17:46 +0100 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 07 Feb 2023 22:17:46 +0100 X-ME-IP: 86.243.2.178 Message-ID: Date: Tue, 7 Feb 2023 22:17:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH 2/3] ASoC: codecs: Add support for the Infineon PEB2466 codec To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Linus Walleij , Bartosz Golaszewski , Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni References: <20230206144904.91078-1-herve.codina@bootlin.com> <20230206144904.91078-3-herve.codina@bootlin.com> Content-Language: fr From: Christophe JAILLET In-Reply-To: <20230206144904.91078-3-herve.codina@bootlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 > + > +static const struct of_device_id peb2466_of_match[] = { > + { .compatible = "infineon,peb2466", }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, peb2466_of_match); > + > +static const struct spi_device_id peb2466_id_table[] = { > + { "peb2466", 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(spi, peb2466_id_table); > + > +static struct spi_driver peb2466_spi_driver = { > + .driver = { > + .name = "peb2466", > + .of_match_table = peb2466_of_match, > + }, > + .id_table = peb2466_id_table, > + .probe = peb2466_spi_probe, > + .remove = peb2466_spi_remove, > +}; > + > +module_spi_driver(peb2466_spi_driver); > + > +MODULE_AUTHOR("Herve Codina "); > +MODULE_DESCRIPTION("PEB2466 ALSA SoC driver"); > +MODULE_LICENSE("GPL");