Skip to content

Commit 0cb7aa9

Browse files
linuswbroonie
authored andcommitted
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>
1 parent fbb1f8b commit 0cb7aa9

3 files changed

Lines changed: 38 additions & 52 deletions

File tree

include/sound/uda1380.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

sound/soc/codecs/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,9 +2373,11 @@ config SND_SOC_UDA1342
23732373
mic inputs), stereo audio DAC, with basic audio processing.
23742374

23752375
config SND_SOC_UDA1380
2376-
tristate
2376+
tristate "Philips UDA1380 CODEC"
23772377
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.
23792381

23802382
config SND_SOC_WCD_CLASSH
23812383
tristate

sound/soc/codecs/uda1380.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616
#include <linux/types.h>
1717
#include <linux/slab.h>
1818
#include <linux/errno.h>
19-
#include <linux/gpio.h>
19+
#include <linux/gpio/consumer.h>
2020
#include <linux/delay.h>
2121
#include <linux/i2c.h>
22+
#include <linux/property.h>
2223
#include <linux/workqueue.h>
2324
#include <sound/core.h>
2425
#include <sound/control.h>
2526
#include <sound/initval.h>
2627
#include <sound/soc.h>
2728
#include <sound/tlv.h>
28-
#include <sound/uda1380.h>
29+
30+
#define UDA1380_DAC_CLK_SYSCLK 0
31+
#define UDA1380_DAC_CLK_WSPLL 1
2932

3033
#include "uda1380.h"
3134

@@ -36,6 +39,8 @@ struct uda1380_priv {
3639
struct work_struct work;
3740
struct i2c_client *i2c;
3841
u16 *reg_cache;
42+
struct gpio_desc *power;
43+
struct gpio_desc *reset;
3944
};
4045

4146
/*
@@ -169,13 +174,12 @@ static void uda1380_sync_cache(struct snd_soc_component *component)
169174

170175
static int uda1380_reset(struct snd_soc_component *component)
171176
{
172-
struct uda1380_platform_data *pdata = component->dev->platform_data;
173177
struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
174178

175-
if (gpio_is_valid(pdata->gpio_reset)) {
176-
gpio_set_value(pdata->gpio_reset, 1);
179+
if (uda1380->reset) {
180+
gpiod_set_value(uda1380->reset, 1);
177181
mdelay(1);
178-
gpio_set_value(pdata->gpio_reset, 0);
182+
gpiod_set_value(uda1380->reset, 0);
179183
} else {
180184
u8 data[3];
181185

@@ -608,9 +612,9 @@ static int uda1380_set_bias_level(struct snd_soc_component *component,
608612
enum snd_soc_bias_level level)
609613
{
610614
struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
615+
struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
611616
int pm = uda1380_read_reg_cache(component, UDA1380_PM);
612617
int reg;
613-
struct uda1380_platform_data *pdata = component->dev->platform_data;
614618

615619
switch (level) {
616620
case SND_SOC_BIAS_ON:
@@ -620,8 +624,8 @@ static int uda1380_set_bias_level(struct snd_soc_component *component,
620624
break;
621625
case SND_SOC_BIAS_STANDBY:
622626
if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) {
623-
if (gpio_is_valid(pdata->gpio_power)) {
624-
gpio_set_value(pdata->gpio_power, 1);
627+
if (uda1380->power) {
628+
gpiod_set_value(uda1380->power, 1);
625629
mdelay(1);
626630
uda1380_reset(component);
627631
}
@@ -631,10 +635,10 @@ static int uda1380_set_bias_level(struct snd_soc_component *component,
631635
uda1380_write(component, UDA1380_PM, 0x0);
632636
break;
633637
case SND_SOC_BIAS_OFF:
634-
if (!gpio_is_valid(pdata->gpio_power))
638+
if (!uda1380->power)
635639
break;
636640

637-
gpio_set_value(pdata->gpio_power, 0);
641+
gpiod_set_value(uda1380->power, 0);
638642

639643
/* Mark mixer regs cache dirty to sync them with
640644
* codec regs on power on.
@@ -713,13 +717,12 @@ static struct snd_soc_dai_driver uda1380_dai[] = {
713717

714718
static int uda1380_probe(struct snd_soc_component *component)
715719
{
716-
struct uda1380_platform_data *pdata =component->dev->platform_data;
717720
struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
718721
int ret;
719722

720723
uda1380->component = component;
721724

722-
if (!gpio_is_valid(pdata->gpio_power)) {
725+
if (!uda1380->power) {
723726
ret = uda1380_reset(component);
724727
if (ret)
725728
return ret;
@@ -728,7 +731,7 @@ static int uda1380_probe(struct snd_soc_component *component)
728731
INIT_WORK(&uda1380->work, uda1380_flush_work);
729732

730733
/* set clock input */
731-
switch (pdata->dac_clk) {
734+
switch (uda1380->dac_clk) {
732735
case UDA1380_DAC_CLK_SYSCLK:
733736
uda1380_write_reg_cache(component, UDA1380_CLK, 0);
734737
break;
@@ -760,31 +763,31 @@ static const struct snd_soc_component_driver soc_component_dev_uda1380 = {
760763

761764
static int uda1380_i2c_probe(struct i2c_client *i2c)
762765
{
763-
struct uda1380_platform_data *pdata = i2c->dev.platform_data;
766+
struct device *dev = &i2c->dev;
764767
struct uda1380_priv *uda1380;
765768
int ret;
766769

767-
if (!pdata)
768-
return -EINVAL;
769-
770770
uda1380 = devm_kzalloc(&i2c->dev, sizeof(struct uda1380_priv),
771771
GFP_KERNEL);
772772
if (uda1380 == NULL)
773773
return -ENOMEM;
774774

775-
if (gpio_is_valid(pdata->gpio_reset)) {
776-
ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_reset,
777-
GPIOF_OUT_INIT_LOW, "uda1380 reset");
778-
if (ret)
779-
return ret;
780-
}
781-
782-
if (gpio_is_valid(pdata->gpio_power)) {
783-
ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_power,
784-
GPIOF_OUT_INIT_LOW, "uda1380 power");
785-
if (ret)
786-
return ret;
787-
}
775+
uda1380->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
776+
if (IS_ERR(uda1380->reset))
777+
return dev_err_probe(dev, PTR_ERR(uda1380->reset),
778+
"error obtaining reset GPIO\n");
779+
gpiod_set_consumer_name(uda1380->reset, "uda1380 reset");
780+
781+
uda1380->power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
782+
if (IS_ERR(uda1380->power))
783+
return dev_err_probe(dev, PTR_ERR(uda1380->power),
784+
"error obtaining power GPIO\n");
785+
gpiod_set_consumer_name(uda1380->power, "uda1380 power");
786+
787+
/* This is just some default */
788+
uda1380->dac_clk = UDA1380_DAC_CLK_SYSCLK;
789+
if (device_property_match_string(dev, "dac-clk", "wspll") >= 0)
790+
uda1380->dac_clk = UDA1380_DAC_CLK_WSPLL;
788791

789792
uda1380->reg_cache = devm_kmemdup_array(&i2c->dev, uda1380_reg, ARRAY_SIZE(uda1380_reg),
790793
sizeof(uda1380_reg[0]), GFP_KERNEL);

0 commit comments

Comments
 (0)