Skip to content

Commit 1cf8786

Browse files
alectric-trbroonie
authored andcommitted
ASoC: codecs: tlv320dac33: Convert to use gpiod api
Convert driver to use the gpiod api instead of the legacy GPIO interface. Replace power_gpio integer with reset_gpiod descriptor in the dac33 struct. Use devm_gpiod_get_optional() to automatically handle resource cleanup and add proper error checking when setting GPIO values. Signed-off-by: Alex Tran <alex.t.tran@gmail.com> Message-ID: <20250901184008.1249535-2-alex.t.tran@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 960ef52 commit 1cf8786

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

sound/soc/codecs/tlv320dac33.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <linux/pm.h>
1515
#include <linux/i2c.h>
1616
#include <linux/interrupt.h>
17-
#include <linux/gpio.h>
17+
#include <linux/gpio/consumer.h>
1818
#include <linux/regulator/consumer.h>
1919
#include <linux/slab.h>
2020
#include <sound/core.h>
@@ -79,7 +79,7 @@ struct tlv320dac33_priv {
7979
struct snd_soc_component *component;
8080
struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES];
8181
struct snd_pcm_substream *substream;
82-
int power_gpio;
82+
struct gpio_desc *reset_gpiod;
8383
int chip_power;
8484
int irq;
8585
unsigned int refclk;
@@ -382,14 +382,26 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
382382
goto exit;
383383
}
384384

385-
if (dac33->power_gpio >= 0)
386-
gpio_set_value(dac33->power_gpio, 1);
385+
if (dac33->reset_gpiod) {
386+
ret = gpiod_set_value(dac33->reset_gpiod, 1);
387+
if (ret < 0) {
388+
dev_err(&dac33->i2c->dev,
389+
"Failed to set reset GPIO: %d\n", ret);
390+
goto exit;
391+
}
392+
}
387393

388394
dac33->chip_power = 1;
389395
} else {
390396
dac33_soft_power(component, 0);
391-
if (dac33->power_gpio >= 0)
392-
gpio_set_value(dac33->power_gpio, 0);
397+
if (dac33->reset_gpiod) {
398+
ret = gpiod_set_value(dac33->reset_gpiod, 0);
399+
if (ret < 0) {
400+
dev_err(&dac33->i2c->dev,
401+
"Failed to set reset GPIO: %d\n", ret);
402+
goto exit;
403+
}
404+
}
393405

394406
ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
395407
dac33->supplies);
@@ -1488,16 +1500,14 @@ static int dac33_i2c_probe(struct i2c_client *client)
14881500
/* Disable FIFO use by default */
14891501
dac33->fifo_mode = DAC33_FIFO_BYPASS;
14901502

1491-
/* Check if the reset GPIO number is valid and request it */
1492-
if (dac33->power_gpio >= 0) {
1493-
ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
1494-
if (ret < 0) {
1495-
dev_err(&client->dev,
1496-
"Failed to request reset GPIO (%d)\n",
1497-
dac33->power_gpio);
1498-
goto err_gpio;
1499-
}
1500-
gpio_direction_output(dac33->power_gpio, 0);
1503+
/* request optional reset GPIO */
1504+
dac33->reset_gpiod =
1505+
devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);
1506+
if (IS_ERR(dac33->reset_gpiod)) {
1507+
ret = PTR_ERR(dac33->reset_gpiod);
1508+
dev_err_probe(&client->dev, ret,
1509+
"Failed to get reset GPIO\n");
1510+
goto err;
15011511
}
15021512

15031513
for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
@@ -1508,19 +1518,17 @@ static int dac33_i2c_probe(struct i2c_client *client)
15081518

15091519
if (ret != 0) {
15101520
dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
1511-
goto err_get;
1521+
goto err;
15121522
}
15131523

15141524
ret = devm_snd_soc_register_component(&client->dev,
15151525
&soc_component_dev_tlv320dac33, &dac33_dai, 1);
15161526
if (ret < 0)
1517-
goto err_get;
1527+
goto err;
15181528

15191529
return ret;
1520-
err_get:
1521-
if (dac33->power_gpio >= 0)
1522-
gpio_free(dac33->power_gpio);
1523-
err_gpio:
1530+
1531+
err:
15241532
return ret;
15251533
}
15261534

@@ -1530,9 +1538,6 @@ static void dac33_i2c_remove(struct i2c_client *client)
15301538

15311539
if (unlikely(dac33->chip_power))
15321540
dac33_hard_power(dac33->component, 0);
1533-
1534-
if (dac33->power_gpio >= 0)
1535-
gpio_free(dac33->power_gpio);
15361541
}
15371542

15381543
static const struct i2c_device_id tlv320dac33_i2c_id[] = {

0 commit comments

Comments
 (0)