Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: pcm3008: Convert to GPIO descriptors

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".

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://patch.msgid.link/20250312-pcm-codecs-v1-2-41ffc4f8fc5c@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
ef5aa8bd 98dba9da

+32 -48
+32 -29
sound/soc/codecs/pcm3008.c
··· 14 14 #include <linux/init.h> 15 15 #include <linux/kernel.h> 16 16 #include <linux/device.h> 17 - #include <linux/gpio.h> 17 + #include <linux/gpio/consumer.h> 18 18 #include <linux/slab.h> 19 19 #include <linux/module.h> 20 20 #include <sound/core.h> ··· 22 22 #include <sound/initval.h> 23 23 #include <sound/soc.h> 24 24 25 - #include "pcm3008.h" 25 + struct pcm3008 { 26 + struct gpio_desc *dem0_pin; 27 + struct gpio_desc *dem1_pin; 28 + struct gpio_desc *pdad_pin; 29 + struct gpio_desc *pdda_pin; 30 + }; 26 31 27 32 static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w, 28 33 struct snd_kcontrol *kcontrol, 29 34 int event) 30 35 { 31 36 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 32 - struct pcm3008_setup_data *setup = component->dev->platform_data; 37 + struct pcm3008 *pcm = component->dev->platform_data; 33 38 34 - gpio_set_value_cansleep(setup->pdda_pin, 35 - SND_SOC_DAPM_EVENT_ON(event)); 39 + gpiod_set_value_cansleep(pcm->pdda_pin, 40 + SND_SOC_DAPM_EVENT_ON(event)); 36 41 37 42 return 0; 38 43 } ··· 47 42 int event) 48 43 { 49 44 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 50 - struct pcm3008_setup_data *setup = component->dev->platform_data; 45 + struct pcm3008 *pcm = component->dev->platform_data; 51 46 52 - gpio_set_value_cansleep(setup->pdad_pin, 53 - SND_SOC_DAPM_EVENT_ON(event)); 47 + gpiod_set_value_cansleep(pcm->pdad_pin, 48 + SND_SOC_DAPM_EVENT_ON(event)); 54 49 55 50 return 0; 56 51 } ··· 111 106 112 107 static int pcm3008_codec_probe(struct platform_device *pdev) 113 108 { 114 - struct pcm3008_setup_data *setup = pdev->dev.platform_data; 115 - int ret; 109 + struct device *dev = &pdev->dev; 110 + struct pcm3008 *pcm; 116 111 117 - if (!setup) 118 - return -EINVAL; 112 + pcm = devm_kzalloc(dev, sizeof(*pcm), GFP_KERNEL); 113 + if (!pcm) 114 + return -ENOMEM; 115 + platform_set_drvdata(pdev, pcm); 119 116 120 117 /* DEM1 DEM0 DE-EMPHASIS_MODE 121 118 * Low Low De-emphasis 44.1 kHz ON ··· 127 120 */ 128 121 129 122 /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ 130 - ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin, 131 - GPIOF_OUT_INIT_HIGH, "codec_dem0"); 132 - if (ret != 0) 133 - return ret; 123 + pcm->dem0_pin = devm_gpiod_get(dev, "dem0", GPIOD_OUT_HIGH); 124 + if (IS_ERR(pcm->dem0_pin)) 125 + return PTR_ERR(pcm->dem0_pin); 134 126 135 127 /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ 136 - ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin, 137 - GPIOF_OUT_INIT_LOW, "codec_dem1"); 138 - if (ret != 0) 139 - return ret; 128 + pcm->dem1_pin = devm_gpiod_get(dev, "dem1", GPIOD_OUT_LOW); 129 + if (IS_ERR(pcm->dem1_pin)) 130 + return PTR_ERR(pcm->dem1_pin); 140 131 141 132 /* Configure PDAD GPIO. */ 142 - ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin, 143 - GPIOF_OUT_INIT_LOW, "codec_pdad"); 144 - if (ret != 0) 145 - return ret; 133 + pcm->pdad_pin = devm_gpiod_get(dev, "pdad", GPIOD_OUT_LOW); 134 + if (IS_ERR(pcm->pdad_pin)) 135 + return PTR_ERR(pcm->pdad_pin); 146 136 147 137 /* Configure PDDA GPIO. */ 148 - ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin, 149 - GPIOF_OUT_INIT_LOW, "codec_pdda"); 150 - if (ret != 0) 151 - return ret; 138 + pcm->pdda_pin = devm_gpiod_get(dev, "pdda", GPIOD_OUT_LOW); 139 + if (IS_ERR(pcm->pdda_pin)) 140 + return PTR_ERR(pcm->pdda_pin); 152 141 153 - return devm_snd_soc_register_component(&pdev->dev, 142 + return devm_snd_soc_register_component(dev, 154 143 &soc_component_dev_pcm3008, &pcm3008_dai, 1); 155 144 } 156 145
-19
sound/soc/codecs/pcm3008.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * PCM3008 ALSA SoC Layer 4 - * 5 - * Author: Hugo Villeneuve 6 - * Copyright (C) 2008 Lyrtech inc 7 - */ 8 - 9 - #ifndef __LINUX_SND_SOC_PCM3008_H 10 - #define __LINUX_SND_SOC_PCM3008_H 11 - 12 - struct pcm3008_setup_data { 13 - unsigned dem0_pin; 14 - unsigned dem1_pin; 15 - unsigned pdad_pin; 16 - unsigned pdda_pin; 17 - }; 18 - 19 - #endif