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: 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>

authored by

Alex Tran and committed by
Mark Brown
1cf87861 960ef523

+30 -25
+30 -25
sound/soc/codecs/tlv320dac33.c
··· 14 14 #include <linux/pm.h> 15 15 #include <linux/i2c.h> 16 16 #include <linux/interrupt.h> 17 - #include <linux/gpio.h> 17 + #include <linux/gpio/consumer.h> 18 18 #include <linux/regulator/consumer.h> 19 19 #include <linux/slab.h> 20 20 #include <sound/core.h> ··· 79 79 struct snd_soc_component *component; 80 80 struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES]; 81 81 struct snd_pcm_substream *substream; 82 - int power_gpio; 82 + struct gpio_desc *reset_gpiod; 83 83 int chip_power; 84 84 int irq; 85 85 unsigned int refclk; ··· 382 382 goto exit; 383 383 } 384 384 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 + } 387 393 388 394 dac33->chip_power = 1; 389 395 } else { 390 396 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 + } 393 405 394 406 ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies), 395 407 dac33->supplies); ··· 1500 1488 /* Disable FIFO use by default */ 1501 1489 dac33->fifo_mode = DAC33_FIFO_BYPASS; 1502 1490 1503 - /* Check if the reset GPIO number is valid and request it */ 1504 - if (dac33->power_gpio >= 0) { 1505 - ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset"); 1506 - if (ret < 0) { 1507 - dev_err(&client->dev, 1508 - "Failed to request reset GPIO (%d)\n", 1509 - dac33->power_gpio); 1510 - goto err_gpio; 1511 - } 1512 - gpio_direction_output(dac33->power_gpio, 0); 1491 + /* request optional reset GPIO */ 1492 + dac33->reset_gpiod = 1493 + devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW); 1494 + if (IS_ERR(dac33->reset_gpiod)) { 1495 + ret = PTR_ERR(dac33->reset_gpiod); 1496 + dev_err_probe(&client->dev, ret, 1497 + "Failed to get reset GPIO\n"); 1498 + goto err; 1513 1499 } 1514 1500 1515 1501 for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++) ··· 1518 1508 1519 1509 if (ret != 0) { 1520 1510 dev_err(&client->dev, "Failed to request supplies: %d\n", ret); 1521 - goto err_get; 1511 + goto err; 1522 1512 } 1523 1513 1524 1514 ret = devm_snd_soc_register_component(&client->dev, 1525 1515 &soc_component_dev_tlv320dac33, &dac33_dai, 1); 1526 1516 if (ret < 0) 1527 - goto err_get; 1517 + goto err; 1528 1518 1529 1519 return ret; 1530 - err_get: 1531 - if (dac33->power_gpio >= 0) 1532 - gpio_free(dac33->power_gpio); 1533 - err_gpio: 1520 + 1521 + err: 1534 1522 return ret; 1535 1523 } 1536 1524 ··· 1538 1530 1539 1531 if (unlikely(dac33->chip_power)) 1540 1532 dac33_hard_power(dac33->component, 0); 1541 - 1542 - if (dac33->power_gpio >= 0) 1543 - gpio_free(dac33->power_gpio); 1544 1533 } 1545 1534 1546 1535 static const struct i2c_device_id tlv320dac33_i2c_id[] = {