Skip to contentSkip to conversation

ALSA: ASoC: add codec driver for TI TAS5086

PATCH In review Daniel Mack 4 participants 14 messages Mar 8, 2013 – May 22, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: ASoC: add codec driver for TI TAS5086

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

---
 .../devicetree/bindings/sound/ti,tas5086.txt       |  32 ++
 sound/soc/codecs/Kconfig                           |   4 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/tas5086.c                         | 587 +++++++++++++++++++++
 4 files changed, 625 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ti,tas5086.txt
 create mode 100644 sound/soc/codecs/tas5086.c
Documentation/devicetree/bindings/sound/ti,tas5086.txt new file +32 -0
new file mode 100644
index 0000000..8ea4f5b
@@ -0,0 +1,32 @@
+Texas Instruments TAS5086 6-channel PWM Processor
+
+Required properties:
+
+ - compatible:		Should contain "ti,tas5086".
+ - reg:			The i2c address. Should contain <0x1b>.
+
+Optional properties:
+
+ - reset-gpio: 		A GPIO spec to define which pin is connected to the
+			chip's !RESET pin. If specified, the driver will
+			assert a hardware reset at probe time.
+
+ - ti,charge-period:	This property should contain the time in microseconds
+			that closely matches the external single-ended
+			split-capacitor charge period. The hardware chip
+			waits for this period of time before starting the
+			PWM signals. This helps reduce pops and clicks.
+
+			When not specified, the hardware default of 1300ms
+			is retained.
+
+Examples:
+
+	i2c_bus {
+		tas5086@1b {
+			compatible = "ti,tas5086";
+			reg = <0x1b>;
+			reset-gpio = <&gpio 23 0>;
+			ti,charge-period = <156000>;
+		};
+	};
sound/soc/codecs/Kconfig +4 -0
index 45b7256..86b3524 100644
@@ -63,6 +63,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_STA32X if I2C
 	select SND_SOC_STA529 if I2C
 	select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
+	select SND_SOC_TAS5086 if I2C
 	select SND_SOC_TLV320AIC23 if I2C
 	select SND_SOC_TLV320AIC26 if SPI_MASTER
 	select SND_SOC_TLV320AIC32X4 if I2C
@@ -320,6 +321,9 @@ config SND_SOC_STA529
 config SND_SOC_STAC9766
 	tristate
 
+config SND_SOC_TAS5086
+	tristate
+
 config SND_SOC_TLV320AIC23
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 6a3b3c3..8077bc2 100644
@@ -55,6 +55,7 @@ snd-soc-ssm2602-objs := ssm2602.o
 snd-soc-sta32x-objs := sta32x.o
 snd-soc-sta529-objs := sta529.o
 snd-soc-stac9766-objs := stac9766.o
+snd-soc-tas5086-objs := tas5086.o
 snd-soc-tlv320aic23-objs := tlv320aic23.o
 snd-soc-tlv320aic26-objs := tlv320aic26.o
 snd-soc-tlv320aic3x-objs := tlv320aic3x.o
@@ -177,6 +178,7 @@ obj-$(CONFIG_SND_SOC_SSM2602)	+= snd-soc-ssm2602.o
 obj-$(CONFIG_SND_SOC_STA32X)   += snd-soc-sta32x.o
 obj-$(CONFIG_SND_SOC_STA529)   += snd-soc-sta529.o
 obj-$(CONFIG_SND_SOC_STAC9766)	+= snd-soc-stac9766.o
+obj-$(CONFIG_SND_SOC_TAS5086)	+= snd-soc-tas5086.o
 obj-$(CONFIG_SND_SOC_TLV320AIC23)	+= snd-soc-tlv320aic23.o
 obj-$(CONFIG_SND_SOC_TLV320AIC26)	+= snd-soc-tlv320aic26.o
 obj-$(CONFIG_SND_SOC_TLV320AIC3X)	+= snd-soc-tlv320aic3x.o
sound/soc/codecs/tas5086.c new file +587 -0

587 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 5 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Well, now we have the no-bus mechanism so... doesn't matter anyway though given that in this version the funky registers aren't used.

Quoted 5 lines

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

We should be able to interoperate with regmap for this somehow, though it'll need us to add lock/unlock access to ensure that the core won't interfere.

sound/soc/codecs/tas5086.c line 129

Quoted 5 lines
sound/soc/codecs/tas5086.c new file +5 -0
+static bool tas5086_volatile_reg(struct device *dev, unsigned int reg)
+{
+	return reg == TAS5086_DEV_ID ||
+	       reg == TAS5086_ERROR_STATUS;
+}

switch please.

sound/soc/codecs/tas5086.c line 198

Quoted 13 lines
sound/soc/codecs/tas5086.c new file +13 -0
+static int tas5086_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+				  int clk_id, unsigned int freq, int dir)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
+
+	switch (clk_id) {
+	case 0:		/* MCLK */
+		priv->mclk = freq;
+		break;
+	case 1:		/* SCLK */
+		priv->sclk = freq;
+		break;

Defines in a header please.

sound/soc/codecs/tas5086.c line 347

Quoted 7 lines
sound/soc/codecs/tas5086.c new file +7 -0
+static int tas5086_digital_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
+
+	return regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
+			    mute ? 0x3f : 0x00);

Please avoid the ternery operator. It'd be nice to switch over to mute_stream() too.

sound/soc/codecs/tas5086.c line 392

Quoted 5 lines
sound/soc/codecs/tas5086.c new file +5 -0
+#ifdef CONFIG_PM
+static int tas5086_soc_suspend(struct snd_soc_codec *codec)
+{
+	return 0;
+}

Empty functions can just be omitted, though it might make sense to hold the device in reset over suspend.

sound/soc/codecs/tas5086.c line 448

Quoted 5 lines
sound/soc/codecs/tas5086.c new file +5 -0
+		/* Codec needs ~15ms to wake up */
+		msleep(15);
+	}
+msleep(300);
+	priv->gpio_nreset = gpio_nreset;

Indentation.

Quoted 11 lines
sound/soc/codecs/tas5086.c new file +11 -0
+static int tas5086_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{
+	struct tas5086_private *priv;
+	int ret;
+
+	priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->regmap = devm_regmap_init_i2c(i2c, &tas5086_regmap);

sound/soc/codecs/tas5086.c line 553

Quoted 10 lines
sound/soc/codecs/tas5086.c new file +10 -0
+	if (IS_ERR(priv->regmap)) {
+		ret = PTR_ERR(priv->regmap);
+		dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
+		return ret;
+	}
+
+	i2c_set_clientdata(i2c, priv);
+
+	return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_tas5086,
+		&tas5086_dai, 1);

I'd expect things like checking the device ID (and probably most if not all of the basic setup and GPIO free stuff) to be pulled out to the I2C level.

#2 lore raw

Hi Mark,

thanks for your quick review.

Quoted 12 lines · Mark Brown

sound/soc/codecs/tas5086.c line 347

Quoted 7 lines · Daniel Mack
sound/soc/codecs/tas5086.c new file +7 -0
+static int tas5086_digital_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
+
+	return regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
+			    mute ? 0x3f : 0x00);

Please avoid the ternery operator. It'd be nice to switch over to mute_stream() too.

I wasn't aware of steam_mute. How's that supposed to be used? I'm asking because when using 4-channel playback, the driver gets this callback for stream == 0 only. Am I supposed to (un)mute all channels here, regardless of the stream parameter passed in?

Quoted 8 lines

sound/soc/codecs/tas5086.c line 392

Quoted 5 lines
sound/soc/codecs/tas5086.c new file +5 -0
+#ifdef CONFIG_PM
+static int tas5086_soc_suspend(struct snd_soc_codec *codec)
+{
+	return 0;
+}

Empty functions can just be omitted, though it might make sense to hold the device in reset over suspend.

I can't test this at the moment, so I'll skip suspend functionality support for now. Will send another follow-up patch in the future for this.

Thanks,
Daniel

#3 lore raw
Quoted 9 lines · Daniel Mack
Quoted 2 lines · Mark Brown

Please avoid the ternery operator. It'd be nice to switch over to mute_stream() too.

I wasn't aware of steam_mute. How's that supposed to be used? I'm asking because when using 4-channel playback, the driver gets this callback for stream == 0 only. Am I supposed to (un)mute all channels here, regardless of the stream parameter passed in?

The stream parameter is _PLAYBACK or _CAPTURE - it's just the same as digital_mute() except it can be applied to a capture stream too.

#4 lore raw
In reply to Daniel Mack
Quoted 18 lines · Daniel Mack

Hi Mark,

thanks for your quick review.

Quoted 12 lines · Mark Brown

sound/soc/codecs/tas5086.c line 347

Quoted 7 lines · Daniel Mack
sound/soc/codecs/tas5086.c new file +7 -0
+static int tas5086_digital_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
+
+	return regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
+			    mute ? 0x3f : 0x00);

Please avoid the ternery operator. It'd be nice to switch over to mute_stream() too.

Quoted 4 lines

I wasn't aware of steam_mute. How's that supposed to be used? I'm asking because when using 4-channel playback, the driver gets this callback for stream == 0 only. Am I supposed to (un)mute all channels here, regardless of the stream parameter passed in?

Ah, sorry. Got it. stream == SNDRV_PCM_STREAM_PLAYBACK. Will send a new version soon.

Daniel

#5 lore raw
In reply to Daniel Mack
Quoted 11 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

--
Jon Smirl
[email protected]

#6 lore raw
Quoted 13 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 11 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Quoted 4 lines

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

On a slightly different note: why isn't your driver in the mainline kernel?

Thanks,
Daniel

#7 lore raw
Quoted 19 lines · Daniel Mack
Quoted 13 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 11 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Quoted 4 lines

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Quoted 6 lines

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

On a slightly different note: why isn't your driver in the mainline kernel?

TI doesn't make the chip any more.

Quoted 5 lines

Thanks,
Daniel

--
Jon Smirl
[email protected]

#8 lore raw
Quoted 8 lines · On Wed, May 22, 2013 at 2:01 PM, [email protected] <[email protected]> wrote:
Quoted 7 lines · Daniel Mack
Quoted 6 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 5 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

These ST amps are more recent that the TI parts.

http://www.st.com/web/catalog/sense_power/FM125/SC1756

Quoted 30 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Quoted 6 lines

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

On a slightly different note: why isn't your driver in the mainline kernel?

TI doesn't make the chip any more.

Quoted 5 lines

Thanks,
Daniel

Quoted 3 lines

--
Jon Smirl
[email protected]

--
Jon Smirl
[email protected]

#9 lore raw
Quoted 6 lines · On Wed, May 22, 2013 at 2:20 PM, [email protected] <[email protected]> wrote:
Quoted 5 lines · On Wed, May 22, 2013 at 2:01 PM, [email protected] <[email protected]> wrote:
Quoted 4 lines · Daniel Mack
Quoted 3 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 2 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

These ST amps are more recent that the TI parts.

http://www.st.com/web/catalog/sense_power/FM125/SC1756

TI has stopped making the TAS5504 but they still make the TAS5508 which is very similar.

TAS5508 eval board is $399.
http://www.ti.com/tool/tas5508-5142k7evm

TAS5086 eval for $299
http://www.ti.com/tool/tas5086-5186v6evm

Quoted 37 lines
Quoted 31 lines
Quoted 13 lines
Quoted 8 lines
Quoted 7 lines

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Quoted 4 lines

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Quoted 6 lines

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

On a slightly different note: why isn't your driver in the mainline kernel?

TI doesn't make the chip any more.

Quoted 5 lines

Thanks,
Daniel

Quoted 3 lines

--
Jon Smirl
[email protected]

Quoted 3 lines

--
Jon Smirl
[email protected]

--
Jon Smirl
[email protected]

#10 lore raw
In reply to [email protected]
Quoted 20 lines · On 22.05.2013 20:01, [email protected] wrote:
Quoted 19 lines · Daniel Mack
Quoted 17 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 11 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Quoted 8 lines
Quoted 6 lines

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

On a slightly different note: why isn't your driver in the mainline kernel?

TI doesn't make the chip any more.

That might be, but we have tons of drivers for devices in the mainline kernel which aren't in production anymore.

Daniel

#11 lore raw
Quoted 26 lines · Daniel Mack
Quoted 25 lines · On 22.05.2013 20:01, [email protected] wrote:
Quoted 24 lines · Daniel Mack
Quoted 13 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 11 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Quoted 4 lines

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

On a slightly different note: why isn't your driver in the mainline kernel?

TI doesn't make the chip any more.

That might be, but we have tons of drivers for devices in the mainline kernel which aren't in production anymore.

Yes, but they were added before the chips went out of production.

Mark/Liam - you can add my TAS5504 driver if you want it. As far as I know there is no Linux based hardware using the chip except for a few prototypes we built about five years ago.

Of course it is easier to find CPU boards with exposed I2S (we had to build a CPU board too) now than it was five years ago so these chips may see more activity. Those TI evals board should easily attach to a Beaglebone.

Quoted 4 lines

Daniel

--
Jon Smirl
[email protected]

#12 lore raw
Quoted 31 lines · On 22.05.2013 20:33, [email protected] wrote:
Quoted 30 lines · Daniel Mack
Quoted 28 lines · On 22.05.2013 20:01, [email protected] wrote:
Quoted 19 lines · Daniel Mack
Quoted 13 lines · On 22.05.2013 19:50, [email protected] wrote:
Quoted 11 lines · Daniel Mack

This patch adds a driver for TI's TA5086 6-channel PWM processor.

This chip has a very unusual register layout, specifically because the registers are of unequal size, and multi-byte registers require bulk writes to take effect. Regmap does not support these kind of mappings.

Currently, the driver does not touch any of the registers >= 0x20, so it doesn't matter, because the register map is mapped to an 8-bit array. In case more features will be added in the future that require access to higher registers, the entire regmap H/W I/O routines have to be open-coded.

Quoted 4 lines

Check out my tas5504 driver from a long time ago. It dealt with those registers.

https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.c
https://github.com/jonsmirl/mpc5200/blob/master/sound/soc/codecs/tas5504.h

Quoted 6 lines

Sure, without any regmap abstractions, things are somehow manageable. Though you lose all the nice things that regmap gives you, such as hardware independence and caching. I might have a different solution, but I need to get my hands on one of these devices to test.

On a slightly different note: why isn't your driver in the mainline kernel?

TI doesn't make the chip any more.

Quoted 8 lines
Quoted 2 lines

That might be, but we have tons of drivers for devices in the mainline kernel which aren't in production anymore.

Yes, but they were added before the chips went out of production.

Mark/Liam - you can add my TAS5504 driver if you want it. As far as I know there is no Linux based hardware using the chip except for a few prototypes we built about five years ago.

Ok, I guess that's enough justification to not add it now, at least for the fact that nobody is able to test this driver now ...

Thanks,
Daniel

maintainer
#13 lore raw
In reply to [email protected]
Quoted 3 lines · On Wed, May 22, 2013 at 02:33:45PM -0400, [email protected] wrote:

Mark/Liam - you can add my TAS5504 driver if you want it. As far as I know there is no Linux based hardware using the chip except for a few prototypes we built about five years ago.

I'll apply any sensible driver that gets submitted.