Skip to contentSkip to conversation

ASoC: Convert PCM codecs to GPIO descriptors

PATCH In review Linus Walleij 2 participants 5 messages Mar 12, 2025 – Mar 17, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ASoC: Convert PCM codecs to GPIO descriptors

Three remaining TI PCM codecs use the old GPIO API in different ways, fix them all up and move over to <linux/gpio/consumer.h> and get rid of <linux/gpio.h>.

---
Linus Walleij (3):
ASoC: pcm1681: Drop unused include
ASoC: pcm3008: Convert to GPIO descriptors
ASoC: pcm6240: Drop bogus code handling IRQ as GPIO

 sound/soc/codecs/pcm1681.c |  1 -
 sound/soc/codecs/pcm3008.c | 61 ++++++++++++++++++++++++----------------------
 sound/soc/codecs/pcm3008.h | 19 ---------------
 sound/soc/codecs/pcm6240.c | 28 ++++++---------------
 sound/soc/codecs/pcm6240.h |  7 +-----
 5 files changed, 40 insertions(+), 76 deletions(-)

---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250312-pcm-codecs-e624f236e0c5

Best regards,

Signature · 1 line
Linus Walleij <[email protected]>
#1 lore raw

PATCH 1/3 ASoC: pcm1681: Drop unused include

This driver includes the legacy GPIO header <linux/gpio.h> but does not use any symbols from it so drop the include.

---
 sound/soc/codecs/pcm1681.c | 1 -
 1 file changed, 1 deletion(-)
sound/soc/codecs/pcm1681.c +0 -1
index fc152496d5dc53dae527a537146f18a44387222c..a1ec881d70841ad10cbb65ad7d59419ebb6f7722 100644
@@ -9,7 +9,6 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/regmap.h>
 #include <linux/of.h>
Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/3 ASoC: pcm3008: Convert to GPIO descriptors

In reply to Linus Walleij

This converts the PCM3008 driver to look up the GPIO lines using descriptors.

Apparently there are no in-tree users of the platform data struct, so users need to adopt.

New users can associate the GPIO lines with the platform device "pcm3008-codec".

---
 sound/soc/codecs/pcm3008.c | 61 ++++++++++++++++++++++++----------------------
 sound/soc/codecs/pcm3008.h | 19 ---------------
 2 files changed, 32 insertions(+), 48 deletions(-)
sound/soc/codecs/pcm3008.c +32 -29
index 09c6c1326833d66dd12c60ff243c9bd9ffda36d9..d3d2e7f40170c8335f5f8ca4d20863accb638c61 100644
@@ -14,7 +14,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <sound/core.h>
@@ -22,17 +22,22 @@
 #include <sound/initval.h>
 #include <sound/soc.h>
 
-#include "pcm3008.h"
+struct pcm3008 {
+	struct gpio_desc *dem0_pin;
+	struct gpio_desc *dem1_pin;
+	struct gpio_desc *pdad_pin;
+	struct gpio_desc *pdda_pin;
+};
 
 static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
 			  struct snd_kcontrol *kcontrol,
 			  int event)
 {
 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
-	struct pcm3008_setup_data *setup = component->dev->platform_data;
+	struct pcm3008 *pcm = component->dev->platform_data;
 
-	gpio_set_value_cansleep(setup->pdda_pin,
-				SND_SOC_DAPM_EVENT_ON(event));
+	gpiod_set_value_cansleep(pcm->pdda_pin,
+				 SND_SOC_DAPM_EVENT_ON(event));
 
 	return 0;
 }
@@ -42,10 +47,10 @@ static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
 			  int event)
 {
 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
-	struct pcm3008_setup_data *setup = component->dev->platform_data;
+	struct pcm3008 *pcm = component->dev->platform_data;
 
-	gpio_set_value_cansleep(setup->pdad_pin,
-				SND_SOC_DAPM_EVENT_ON(event));
+	gpiod_set_value_cansleep(pcm->pdad_pin,
+				 SND_SOC_DAPM_EVENT_ON(event));
 
 	return 0;
 }
@@ -106,11 +111,13 @@ static const struct snd_soc_component_driver soc_component_dev_pcm3008 = {
 
 static int pcm3008_codec_probe(struct platform_device *pdev)
 {
-	struct pcm3008_setup_data *setup = pdev->dev.platform_data;
-	int ret;
+	struct device *dev = &pdev->dev;
+	struct pcm3008 *pcm;
 
-	if (!setup)
-		return -EINVAL;
+	pcm = devm_kzalloc(dev, sizeof(*pcm), GFP_KERNEL);
+	if (!pcm)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, pcm);
 
 	/* DEM1  DEM0  DE-EMPHASIS_MODE
 	 * Low   Low   De-emphasis 44.1 kHz ON
@@ -120,30 +127,26 @@ static int pcm3008_codec_probe(struct platform_device *pdev)
 	 */
 
 	/* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
-	ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
-				    GPIOF_OUT_INIT_HIGH, "codec_dem0");
-	if (ret != 0)
-		return ret;
+	pcm->dem0_pin = devm_gpiod_get(dev, "dem0", GPIOD_OUT_HIGH);
+	if (IS_ERR(pcm->dem0_pin))
+		return PTR_ERR(pcm->dem0_pin);
 
 	/* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
-	ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
-				    GPIOF_OUT_INIT_LOW, "codec_dem1");
-	if (ret != 0)
-		return ret;
+	pcm->dem1_pin = devm_gpiod_get(dev, "dem1", GPIOD_OUT_LOW);
+	if (IS_ERR(pcm->dem1_pin))
+		return PTR_ERR(pcm->dem1_pin);
 
 	/* Configure PDAD GPIO. */
-	ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
-				    GPIOF_OUT_INIT_LOW, "codec_pdad");
-	if (ret != 0)
-		return ret;
+	pcm->pdad_pin = devm_gpiod_get(dev, "pdad", GPIOD_OUT_LOW);
+	if (IS_ERR(pcm->pdad_pin))
+		return PTR_ERR(pcm->pdad_pin);
 
 	/* Configure PDDA GPIO. */
-	ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
-				    GPIOF_OUT_INIT_LOW, "codec_pdda");
-	if (ret != 0)
-		return ret;
+	pcm->pdda_pin = devm_gpiod_get(dev, "pdda", GPIOD_OUT_LOW);
+	if (IS_ERR(pcm->pdda_pin))
+		return PTR_ERR(pcm->pdda_pin);
 
-	return devm_snd_soc_register_component(&pdev->dev,
+	return devm_snd_soc_register_component(dev,
 			&soc_component_dev_pcm3008, &pcm3008_dai, 1);
 }
 
sound/soc/codecs/pcm3008.h deleted +0 -19
deleted file mode 100644
index f7f4fbbd89db2bd4fb8d29059bf404d34d939dad..0000000000000000000000000000000000000000
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * PCM3008 ALSA SoC Layer
- *
- * Author:	Hugo Villeneuve
- * Copyright (C) 2008 Lyrtech inc
- */
-
-#ifndef __LINUX_SND_SOC_PCM3008_H
-#define __LINUX_SND_SOC_PCM3008_H
-
-struct pcm3008_setup_data {
-	unsigned dem0_pin;
-	unsigned dem1_pin;
-	unsigned pdad_pin;
-	unsigned pdda_pin;
-};
-
-#endif
Signature · 1 line
2.48.1
#3 lore raw

PATCH 3/3 ASoC: pcm6240: Drop bogus code handling IRQ as GPIO

In reply to Linus Walleij

The current code for the IRQ in pcm6240 makes no sense:
it looks up an IRQ with of_irq_get(), treat it as a GPIO by issuing gpio_request(), gpio_direction_input() and gpio_to_irq() on it.

This is just wrong, if the device tree assigns the IRQ from a GPIO number this is just incorrect: it is clearly stated that GPIO providers and IRQ providers are orthogonal.

It is possible to look up an IRQ to a corresponding GPIO line but this is taking an IRQ and pretending it's a GPIO, which is just semantically wrong.

Drop the offending code and treat the IRQ that we get from the device tree as any other IRQ, see for example other codec drivers.

The DT bindings for this codec does not have any in-tree DTS files, which may explain why things are weird.

As a bonus, this moves the driver away from the legacy <linux/gpio.h> include.

---
 sound/soc/codecs/pcm6240.c | 28 +++++++---------------------
 sound/soc/codecs/pcm6240.h |  7 +------
 2 files changed, 8 insertions(+), 27 deletions(-)
sound/soc/codecs/pcm6240.c +7 -21
index 4ff39e0b95b272c9c6b6f5cca50f595ae39ef056..b2bd2f172ae76e6baa7e6f4ef5fe894701ea4385 100644
@@ -14,7 +14,7 @@
 
 #include <linux/unaligned.h>
 #include <linux/firmware.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/of_irq.h>
@@ -2035,10 +2035,8 @@ static const struct regmap_config pcmdevice_i2c_regmap = {
 
 static void pcmdevice_remove(struct pcmdevice_priv *pcm_dev)
 {
-	if (gpio_is_valid(pcm_dev->irq_info.gpio)) {
-		gpio_free(pcm_dev->irq_info.gpio);
-		free_irq(pcm_dev->irq_info.nmb, pcm_dev);
-	}
+	if (pcm_dev->irq)
+		free_irq(pcm_dev->irq, pcm_dev);
 	mutex_destroy(&pcm_dev->codec_lock);
 }
 
@@ -2109,7 +2107,7 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c)
 		ndev = 1;
 		dev_addrs[0] = i2c->addr;
 	}
-	pcm_dev->irq_info.gpio = of_irq_get(np, 0);
+	pcm_dev->irq = of_irq_get(np, 0);
 
 	for (i = 0; i < ndev; i++)
 		pcm_dev->addr[i] = dev_addrs[i];
@@ -2132,22 +2130,10 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c)
 
 	if (pcm_dev->chip_id == PCM1690)
 		goto skip_interrupt;
-	if (gpio_is_valid(pcm_dev->irq_info.gpio)) {
-		dev_dbg(pcm_dev->dev, "irq-gpio = %d", pcm_dev->irq_info.gpio);
-
-		ret = gpio_request(pcm_dev->irq_info.gpio, "PCMDEV-IRQ");
-		if (!ret) {
-			int gpio = pcm_dev->irq_info.gpio;
-
-			gpio_direction_input(gpio);
-			pcm_dev->irq_info.nmb = gpio_to_irq(gpio);
-
-		} else
-			dev_err(pcm_dev->dev, "%s: GPIO %d request error\n",
-				__func__, pcm_dev->irq_info.gpio);
+	if (pcm_dev->irq) {
+		dev_dbg(pcm_dev->dev, "irq = %d", pcm_dev->irq);
 	} else
-		dev_err(pcm_dev->dev, "Looking up irq-gpio failed %d\n",
-			pcm_dev->irq_info.gpio);
+		dev_err(pcm_dev->dev, "No irq provided\n");
 
 skip_interrupt:
 	ret = devm_snd_soc_register_component(&i2c->dev,
sound/soc/codecs/pcm6240.h +1 -6
index 1e125bb97286030f7e6006970d0be9f40348e952..2d8f9e798139ac7df30606c0e5381a7b24d84728 100644
@@ -208,11 +208,6 @@ struct pcmdevice_regbin {
 	struct pcmdevice_config_info **cfg_info;
 };
 
-struct pcmdevice_irqinfo {
-	int gpio;
-	int nmb;
-};
-
 struct pcmdevice_priv {
 	struct snd_soc_component *component;
 	struct i2c_client *client;
@@ -221,7 +216,7 @@ struct pcmdevice_priv {
 	struct gpio_desc *hw_rst;
 	struct regmap *regmap;
 	struct pcmdevice_regbin regbin;
-	struct pcmdevice_irqinfo irq_info;
+	int irq;
 	unsigned int addr[PCMDEVICE_MAX_I2C_DEVICES];
 	unsigned int chip_id;
 	int cur_conf;
Signature · 1 line
2.48.1
maintainer
#4 lore raw
In reply to Linus Walleij
Quoted 5 lines · Linus Walleij

Three remaining TI PCM codecs use the old GPIO API in different ways, fix them all up and move over to <linux/gpio/consumer.h> and get rid of <linux/gpio.h>.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] ASoC: pcm1681: Drop unused include

      commit: 98dba9dab5d9af3c25e61a5d751bc943fec3f918
[2/3] ASoC: pcm3008: Convert to GPIO descriptors
      commit: ef5aa8bd22372dd67b7fe19613b86181cd765af8
[3/3] ASoC: pcm6240: Drop bogus code handling IRQ as GPIO
      commit: 17fdf318f5fbe5c27353ae917c0c5a2899d9c259

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark