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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: uda1380: Modernize the driver

This codec driver depended on the legacy GPIO API, and nothing
in the kernel is defining the platform data, so get rid of this.

Two in-kernel device trees are defining this codec using
undocumented device tree properties, so support these for now.
The same properties can be defined using software nodes if board
files are desired. The device tree use the "-gpio" rather than
"-gpios" suffix but the GPIO DT parser will deal with that.

Since there may be out of tree users, migrate to GPIO descriptors,
drop the platform data that is unused, and assign the dac_clk the
value that was used in all platforms found in a historical dig,
and support setting the clock to the PLL using the undocumented
device tree property.

Add some menuconfig so the codec can be selected and tested.

Signed-off-by: Linus Walleij <linusw@kernel.org>
Link: https://patch.msgid.link/20260409-asoc-uda1380-v3-1-b3d5a53f31be@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
0cb7aa96 fbb1f8ba

+37 -51
-19
include/sound/uda1380.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * UDA1380 ALSA SoC Codec driver 4 - * 5 - * Copyright 2009 Philipp Zabel 6 - */ 7 - 8 - #ifndef __UDA1380_H 9 - #define __UDA1380_H 10 - 11 - struct uda1380_platform_data { 12 - int gpio_power; 13 - int gpio_reset; 14 - int dac_clk; 15 - #define UDA1380_DAC_CLK_SYSCLK 0 16 - #define UDA1380_DAC_CLK_WSPLL 1 17 - }; 18 - 19 - #endif /* __UDA1380_H */
+4 -2
sound/soc/codecs/Kconfig
··· 2373 2373 mic inputs), stereo audio DAC, with basic audio processing. 2374 2374 2375 2375 config SND_SOC_UDA1380 2376 - tristate 2376 + tristate "Philips UDA1380 CODEC" 2377 2377 depends on I2C 2378 - depends on GPIOLIB_LEGACY 2378 + help 2379 + The UDA1380 codec is used in the HTC Magician and on a number of 2380 + Samsung reference boards, as well as the LPC32xx series. 2379 2381 2380 2382 config SND_SOC_WCD_CLASSH 2381 2383 tristate
+33 -30
sound/soc/codecs/uda1380.c
··· 16 16 #include <linux/types.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/errno.h> 19 - #include <linux/gpio.h> 19 + #include <linux/gpio/consumer.h> 20 20 #include <linux/delay.h> 21 21 #include <linux/i2c.h> 22 + #include <linux/property.h> 22 23 #include <linux/workqueue.h> 23 24 #include <sound/core.h> 24 25 #include <sound/control.h> 25 26 #include <sound/initval.h> 26 27 #include <sound/soc.h> 27 28 #include <sound/tlv.h> 28 - #include <sound/uda1380.h> 29 + 30 + #define UDA1380_DAC_CLK_SYSCLK 0 31 + #define UDA1380_DAC_CLK_WSPLL 1 29 32 30 33 #include "uda1380.h" 31 34 ··· 39 36 struct work_struct work; 40 37 struct i2c_client *i2c; 41 38 u16 *reg_cache; 39 + struct gpio_desc *power; 40 + struct gpio_desc *reset; 42 41 }; 43 42 44 43 /* ··· 174 169 175 170 static int uda1380_reset(struct snd_soc_component *component) 176 171 { 177 - struct uda1380_platform_data *pdata = component->dev->platform_data; 178 172 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component); 179 173 180 - if (gpio_is_valid(pdata->gpio_reset)) { 181 - gpio_set_value(pdata->gpio_reset, 1); 174 + if (uda1380->reset) { 175 + gpiod_set_value(uda1380->reset, 1); 182 176 mdelay(1); 183 - gpio_set_value(pdata->gpio_reset, 0); 177 + gpiod_set_value(uda1380->reset, 0); 184 178 } else { 185 179 u8 data[3]; 186 180 ··· 612 608 enum snd_soc_bias_level level) 613 609 { 614 610 struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); 611 + struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component); 615 612 int pm = uda1380_read_reg_cache(component, UDA1380_PM); 616 613 int reg; 617 - struct uda1380_platform_data *pdata = component->dev->platform_data; 618 614 619 615 switch (level) { 620 616 case SND_SOC_BIAS_ON: ··· 624 620 break; 625 621 case SND_SOC_BIAS_STANDBY: 626 622 if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) { 627 - if (gpio_is_valid(pdata->gpio_power)) { 628 - gpio_set_value(pdata->gpio_power, 1); 623 + if (uda1380->power) { 624 + gpiod_set_value(uda1380->power, 1); 629 625 mdelay(1); 630 626 uda1380_reset(component); 631 627 } ··· 635 631 uda1380_write(component, UDA1380_PM, 0x0); 636 632 break; 637 633 case SND_SOC_BIAS_OFF: 638 - if (!gpio_is_valid(pdata->gpio_power)) 634 + if (!uda1380->power) 639 635 break; 640 636 641 - gpio_set_value(pdata->gpio_power, 0); 637 + gpiod_set_value(uda1380->power, 0); 642 638 643 639 /* Mark mixer regs cache dirty to sync them with 644 640 * codec regs on power on. ··· 717 713 718 714 static int uda1380_probe(struct snd_soc_component *component) 719 715 { 720 - struct uda1380_platform_data *pdata =component->dev->platform_data; 721 716 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component); 722 717 int ret; 723 718 724 719 uda1380->component = component; 725 720 726 - if (!gpio_is_valid(pdata->gpio_power)) { 721 + if (!uda1380->power) { 727 722 ret = uda1380_reset(component); 728 723 if (ret) 729 724 return ret; ··· 731 728 INIT_WORK(&uda1380->work, uda1380_flush_work); 732 729 733 730 /* set clock input */ 734 - switch (pdata->dac_clk) { 731 + switch (uda1380->dac_clk) { 735 732 case UDA1380_DAC_CLK_SYSCLK: 736 733 uda1380_write_reg_cache(component, UDA1380_CLK, 0); 737 734 break; ··· 763 760 764 761 static int uda1380_i2c_probe(struct i2c_client *i2c) 765 762 { 766 - struct uda1380_platform_data *pdata = i2c->dev.platform_data; 763 + struct device *dev = &i2c->dev; 767 764 struct uda1380_priv *uda1380; 768 765 int ret; 769 - 770 - if (!pdata) 771 - return -EINVAL; 772 766 773 767 uda1380 = devm_kzalloc(&i2c->dev, sizeof(struct uda1380_priv), 774 768 GFP_KERNEL); 775 769 if (uda1380 == NULL) 776 770 return -ENOMEM; 777 771 778 - if (gpio_is_valid(pdata->gpio_reset)) { 779 - ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_reset, 780 - GPIOF_OUT_INIT_LOW, "uda1380 reset"); 781 - if (ret) 782 - return ret; 783 - } 772 + uda1380->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 773 + if (IS_ERR(uda1380->reset)) 774 + return dev_err_probe(dev, PTR_ERR(uda1380->reset), 775 + "error obtaining reset GPIO\n"); 776 + gpiod_set_consumer_name(uda1380->reset, "uda1380 reset"); 784 777 785 - if (gpio_is_valid(pdata->gpio_power)) { 786 - ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_power, 787 - GPIOF_OUT_INIT_LOW, "uda1380 power"); 788 - if (ret) 789 - return ret; 790 - } 778 + uda1380->power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW); 779 + if (IS_ERR(uda1380->power)) 780 + return dev_err_probe(dev, PTR_ERR(uda1380->power), 781 + "error obtaining power GPIO\n"); 782 + gpiod_set_consumer_name(uda1380->power, "uda1380 power"); 783 + 784 + /* This is just some default */ 785 + uda1380->dac_clk = UDA1380_DAC_CLK_SYSCLK; 786 + if (device_property_match_string(dev, "dac-clk", "wspll") >= 0) 787 + uda1380->dac_clk = UDA1380_DAC_CLK_WSPLL; 791 788 792 789 uda1380->reg_cache = devm_kmemdup_array(&i2c->dev, uda1380_reg, ARRAY_SIZE(uda1380_reg), 793 790 sizeof(uda1380_reg[0]), GFP_KERNEL);