mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 2/3] ASoC: codecs: tlv320dac33: Add default value for burst_bclkdiv
@ 2025-09-01 18:40 Alex Tran
  2025-09-01 18:40 ` [PATCH v3 3/3] ASoC: codecs: tlv320dac33: Convert to use gpiod api Alex Tran
  2025-09-01 18:40 ` [PATCH v3 1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h Alex Tran
  0 siblings, 2 replies; 4+ messages in thread
From: Alex Tran @ 2025-09-01 18:40 UTC (permalink / raw)
  To: broonie
  Cc: lgirdwood, shenghao-ding, kevin-lu, baojun.xu, perex, tiwai,
	linux-sound, linux-kernel, Alex Tran

Add default value for field burst_bclkdiv as initializing it to 0
is incorrect, potentially leading to a divide by 0 issue.
Valid range is 2-17 per TI datasheet. 8 was chosen as a
dummy value.

Reference <https://www.ti.com/lit/ds/symlink/tlv320dac32.pdf>.

Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
---
Changes in v2:
- Included removal of struct 'tlv320dac33_platform_data'
  and header file 'tlv320dac33-plat.h'
Changes in v3:
- Split into separate patches as per request
- Moved inter-version changelogs after '---' line

 sound/soc/codecs/tlv320dac33.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 36b3de75a..feefc777c 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -1480,6 +1480,8 @@ static int dac33_i2c_probe(struct i2c_client *client)
 
 	i2c_set_clientdata(client, dac33);
 
+	if (!dac33->burst_bclkdiv)
+		dac33->burst_bclkdiv = 8;
 	if (!dac33->mode1_latency)
 		dac33->mode1_latency = 10000; /* 10ms */
 	dac33->irq = client->irq;
-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 3/3] ASoC: codecs: tlv320dac33: Convert to use gpiod api
  2025-09-01 18:40 [PATCH v3 2/3] ASoC: codecs: tlv320dac33: Add default value for burst_bclkdiv Alex Tran
@ 2025-09-01 18:40 ` Alex Tran
  2025-09-01 18:40 ` [PATCH v3 1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h Alex Tran
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Tran @ 2025-09-01 18:40 UTC (permalink / raw)
  To: broonie
  Cc: lgirdwood, shenghao-ding, kevin-lu, baojun.xu, perex, tiwai,
	linux-sound, linux-kernel, Alex Tran

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>
---
Changes in v2:
- Included removal of struct 'tlv320dac33_platform_data'
  and header file 'tlv320dac33-plat.h'
Changes in v3:
- Split into separate patches as per request
- Moved inter-version changelogs after '---' line

 sound/soc/codecs/tlv320dac33.c | 55 ++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index feefc777c..c495be1cf 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -14,7 +14,7 @@
 #include <linux/pm.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <sound/core.h>
@@ -79,7 +79,7 @@ struct tlv320dac33_priv {
 	struct snd_soc_component *component;
 	struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES];
 	struct snd_pcm_substream *substream;
-	int power_gpio;
+	struct gpio_desc *reset_gpiod;
 	int chip_power;
 	int irq;
 	unsigned int refclk;
@@ -382,14 +382,26 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
 			goto exit;
 		}
 
-		if (dac33->power_gpio >= 0)
-			gpio_set_value(dac33->power_gpio, 1);
+		if (dac33->reset_gpiod) {
+			ret = gpiod_set_value(dac33->reset_gpiod, 1);
+			if (ret < 0) {
+				dev_err(&dac33->i2c->dev,
+					"Failed to set reset GPIO: %d\n", ret);
+				goto exit;
+			}
+		}
 
 		dac33->chip_power = 1;
 	} else {
 		dac33_soft_power(component, 0);
-		if (dac33->power_gpio >= 0)
-			gpio_set_value(dac33->power_gpio, 0);
+		if (dac33->reset_gpiod) {
+			ret = gpiod_set_value(dac33->reset_gpiod, 0);
+			if (ret < 0) {
+				dev_err(&dac33->i2c->dev,
+					"Failed to set reset GPIO: %d\n", ret);
+				goto exit;
+			}
+		}
 
 		ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
 					     dac33->supplies);
@@ -1488,16 +1500,14 @@ static int dac33_i2c_probe(struct i2c_client *client)
 	/* Disable FIFO use by default */
 	dac33->fifo_mode = DAC33_FIFO_BYPASS;
 
-	/* Check if the reset GPIO number is valid and request it */
-	if (dac33->power_gpio >= 0) {
-		ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
-		if (ret < 0) {
-			dev_err(&client->dev,
-				"Failed to request reset GPIO (%d)\n",
-				dac33->power_gpio);
-			goto err_gpio;
-		}
-		gpio_direction_output(dac33->power_gpio, 0);
+	/* request optional reset GPIO */
+	dac33->reset_gpiod =
+		devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(dac33->reset_gpiod)) {
+		ret = PTR_ERR(dac33->reset_gpiod);
+		dev_err_probe(&client->dev, ret,
+			      "Failed to get reset GPIO\n");
+		goto err;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
@@ -1508,19 +1518,17 @@ static int dac33_i2c_probe(struct i2c_client *client)
 
 	if (ret != 0) {
 		dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
-		goto err_get;
+		goto err;
 	}
 
 	ret = devm_snd_soc_register_component(&client->dev,
 			&soc_component_dev_tlv320dac33, &dac33_dai, 1);
 	if (ret < 0)
-		goto err_get;
+		goto err;
 
 	return ret;
-err_get:
-	if (dac33->power_gpio >= 0)
-		gpio_free(dac33->power_gpio);
-err_gpio:
+
+err:
 	return ret;
 }
 
@@ -1530,9 +1538,6 @@ static void dac33_i2c_remove(struct i2c_client *client)
 
 	if (unlikely(dac33->chip_power))
 		dac33_hard_power(dac33->component, 0);
-
-	if (dac33->power_gpio >= 0)
-		gpio_free(dac33->power_gpio);
 }
 
 static const struct i2c_device_id tlv320dac33_i2c_id[] = {
-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h
  2025-09-01 18:40 [PATCH v3 2/3] ASoC: codecs: tlv320dac33: Add default value for burst_bclkdiv Alex Tran
  2025-09-01 18:40 ` [PATCH v3 3/3] ASoC: codecs: tlv320dac33: Convert to use gpiod api Alex Tran
@ 2025-09-01 18:40 ` Alex Tran
  2025-09-09 15:15   ` Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Alex Tran @ 2025-09-01 18:40 UTC (permalink / raw)
  To: broonie
  Cc: lgirdwood, shenghao-ding, kevin-lu, baojun.xu, perex, tiwai,
	linux-sound, linux-kernel, Alex Tran

Remove the tlv320dac33_platform_data struct and header file
tlv320dac33-plat.h as they are not used anywhere in the kernel
or outside this driver.

Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
---
Changes in v2:
- Included removal of struct 'tlv320dac33_platform_data'
  and header file 'tlv320dac33-plat.h'
Changes in v3:
- Split into separate patches as per request
- Moved inter-version changelogs after '---' line

 include/sound/tlv320dac33-plat.h | 21 ---------------------
 sound/soc/codecs/tlv320dac33.c   | 12 ------------
 2 files changed, 33 deletions(-)
 delete mode 100644 include/sound/tlv320dac33-plat.h

diff --git a/include/sound/tlv320dac33-plat.h b/include/sound/tlv320dac33-plat.h
deleted file mode 100644
index 7a7249a89..000000000
--- a/include/sound/tlv320dac33-plat.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Platform header for Texas Instruments TLV320DAC33 codec driver
- *
- * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
- *
- * Copyright:   (C) 2009 Nokia Corporation
- */
-
-#ifndef __TLV320DAC33_PLAT_H
-#define __TLV320DAC33_PLAT_H
-
-struct tlv320dac33_platform_data {
-	int power_gpio;
-	int mode1_latency; /* latency caused by the i2c writes in us */
-	int auto_fifo_config; /* FIFO config based on the period size */
-	int keep_bclk;	/* Keep the BCLK running in FIFO modes */
-	u8 burst_bclkdiv;
-};
-
-#endif /* __TLV320DAC33_PLAT_H */
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 423b9264a..36b3de75a 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -24,7 +24,6 @@
 #include <sound/initval.h>
 #include <sound/tlv.h>
 
-#include <sound/tlv320dac33-plat.h>
 #include "tlv320dac33.h"
 
 /*
@@ -1462,16 +1461,9 @@ static struct snd_soc_dai_driver dac33_dai = {
 
 static int dac33_i2c_probe(struct i2c_client *client)
 {
-	struct tlv320dac33_platform_data *pdata;
 	struct tlv320dac33_priv *dac33;
 	int ret, i;
 
-	if (client->dev.platform_data == NULL) {
-		dev_err(&client->dev, "Platform data not set\n");
-		return -ENODEV;
-	}
-	pdata = client->dev.platform_data;
-
 	dac33 = devm_kzalloc(&client->dev, sizeof(struct tlv320dac33_priv),
 			     GFP_KERNEL);
 	if (dac33 == NULL)
@@ -1488,10 +1480,6 @@ static int dac33_i2c_probe(struct i2c_client *client)
 
 	i2c_set_clientdata(client, dac33);
 
-	dac33->power_gpio = pdata->power_gpio;
-	dac33->burst_bclkdiv = pdata->burst_bclkdiv;
-	dac33->keep_bclk = pdata->keep_bclk;
-	dac33->mode1_latency = pdata->mode1_latency;
 	if (!dac33->mode1_latency)
 		dac33->mode1_latency = 10000; /* 10ms */
 	dac33->irq = client->irq;
-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h
  2025-09-01 18:40 ` [PATCH v3 1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h Alex Tran
@ 2025-09-09 15:15   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-09-09 15:15 UTC (permalink / raw)
  To: Alex Tran
  Cc: lgirdwood, shenghao-ding, kevin-lu, baojun.xu, perex, tiwai,
	linux-sound, linux-kernel

On Mon, 01 Sep 2025 11:40:08 -0700, Alex Tran wrote:
> Remove the tlv320dac33_platform_data struct and header file
> tlv320dac33-plat.h as they are not used anywhere in the kernel
> or outside this driver.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h
      commit: 06aba2126b414248a34b13584f22a78787c95450
[2/3] ASoC: codecs: tlv320dac33: Add default value for burst_bclkdiv
      commit: 960ef523cfe420ae8fdd801f1d12be0fb7ed8719
[3/3] ASoC: codecs: tlv320dac33: Convert to use gpiod api
      commit: 1cf87861a2e02432fb68f8bcc8f20a8e42acde59

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-09 15:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-01 18:40 [PATCH v3 2/3] ASoC: codecs: tlv320dac33: Add default value for burst_bclkdiv Alex Tran
2025-09-01 18:40 ` [PATCH v3 3/3] ASoC: codecs: tlv320dac33: Convert to use gpiod api Alex Tran
2025-09-01 18:40 ` [PATCH v3 1/3] ASoC: codecs: tlv320dac33: Remove unused struct tlv320dac33_platform_data and header file tlv320dac33-plat.h Alex Tran
2025-09-09 15:15   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®