Skip to contentSkip to conversation

add a TDA998x CODEC

PATCH Superseded Jean-Francois Moine 4 participants 15 messages Jan 26, 2014 – Jan 28, 2014

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover add a TDA998x CODEC

The TDA998x HDMI transmitter accepts audio input from either I2S or S/PDIF.

Theses inputs have different intrinsic constraints and these constraints may be modified by the audio parameters of the connected video device.

The choice of I2S or S/PDIF may be the done by the user or by automatic processing (DPCM?) at each audio starting time. This asks for a dynamic audio input switch in the HDMI driver.

This patch series implements the TDA998x specific CODEC. A simple function call mechanism is used for exchanges between the CODEC and the HDMI driver.

Jean-Francois Moine (4):
drm/i2c: tda998x: add a function for dynamic audio input switch
ASoC: tda998x: add a codec driver for TDA998x
ASoC: tda998x: add DT documentation
ASoC: tda998x: adjust the audio hw parameters from EDID

 .../devicetree/bindings/sound/tda998x.txt          |  14 +
 drivers/gpu/drm/i2c/tda998x_drv.c                  |  58 +++-
 include/drm/i2c/tda998x.h                          |   8 +-
 sound/soc/codecs/Kconfig                           |   7 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/tda998x.c                         | 304 +++++++++++++++++++++
 6 files changed, 390 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/tda998x.txt
 create mode 100644 sound/soc/codecs/tda998x.c
Signature · 1 line
1.8.5.3
#1 lore raw

PATCH 1/4 drm/i2c: tda998x: add a function for dynamic audio input switch

When both I2S and S/PDIF are wired from the audio device to the TDA998x, the user or some internal mechanism may choose to do audio streaming via either inputs.

This patch adds an exported function in the TDA998x driver which initializes the audio input parameters according to the audio subsystem.

The audio format values in the encoder configuration interface are changed to non null values so that the value 0 is used in the audio function to indicate that audio streaming is stopped.

---
 drivers/gpu/drm/i2c/tda998x_drv.c | 43 ++++++++++++++++++++++++++++++++++++++-
 include/drm/i2c/tda998x.h         |  7 +++++--
 2 files changed, 47 insertions(+), 3 deletions(-)
drivers/gpu/drm/i2c/tda998x_drv.c +42 -1
index e5bbaf2..186c751 100644
@@ -34,6 +34,7 @@ struct tda998x_priv {
 	struct i2c_client *hdmi;
 	uint16_t rev;
 	uint8_t current_page;
+	u8 audio_active;
 	int dpms;
 	bool is_hdmi_sink;
 	u8 vip_cntrl_0;
@@ -729,6 +730,38 @@ tda998x_configure_audio(struct tda998x_priv *priv,
 	tda998x_write_aif(priv, p);
 }
 
+/* tda998x codec interface */
+void tda998x_audio_update(struct i2c_client *client,
+			int format,
+			int port)
+{
+	struct tda998x_priv *priv = i2c_get_clientdata(client);
+	struct tda998x_encoder_params *p = &priv->params;
+
+	/* if the audio output is active, it may be a second start or a stop */
+	if (format == 0 || priv->audio_active) {
+		if (format == 0) {
+			priv->audio_active = 0;
+			reg_write(priv, REG_ENA_AP, 0);
+		}
+		return;
+	}
+
+	p->audio_cfg = port;
+
+	/* don't restart audio if same input format */
+	if (format == p->audio_format) {
+		priv->audio_active = 1;
+		reg_write(priv, REG_ENA_AP, p->audio_cfg);
+		return;
+	}
+	p->audio_format = format;
+	priv->audio_active = 1;
+
+	tda998x_configure_audio(priv, &priv->encoder->crtc->hwmode, p);
+}
+EXPORT_SYMBOL_GPL(tda998x_audio_update);
+
 /* DRM encoder functions */
 
 static void
@@ -751,6 +784,9 @@ tda998x_encoder_set_config(struct drm_encoder *encoder, void *params)
 			    (p->mirr_f ? VIP_CNTRL_2_MIRR_F : 0);
 
 	priv->params = *p;
+
+	if (p->audio_cfg)
+		priv->audio_active = 1;
 }
 
 static void
@@ -1001,7 +1037,7 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
 
 		tda998x_write_avi(priv, adj_mode);
 
-		if (priv->params.audio_cfg)
+		if (priv->audio_active)
 			tda998x_configure_audio(priv, adj_mode, &priv->params);
 	}
 }
@@ -1233,10 +1269,15 @@ tda998x_encoder_init(struct i2c_client *client,
 	if (!priv)
 		return -ENOMEM;
 
+	i2c_set_clientdata(client, priv);
+
 	priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3);
 	priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1);
 	priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5);
 
+	priv->params.audio_frame[1] = 1;		/* channels - 1 */
+	priv->params.audio_sample_rate = 48000;		/* 48kHz */
+
 	priv->current_page = 0xff;
 	priv->hdmi = client;
 	priv->cec = i2c_new_dummy(client->adapter, 0x34);
include/drm/i2c/tda998x.h +5 -2
index f3bb25c..0459931 100644
@@ -19,11 +19,14 @@ struct tda998x_encoder_params {
 	u8 audio_frame[6];
 
 	enum {
-		AFMT_SPDIF,
-		AFMT_I2S
+		AFMT_I2S = 1,
+		AFMT_SPDIF
 	} audio_format;
 
 	unsigned audio_sample_rate;
 };
 
+void tda998x_audio_update(struct i2c_client *client,
+			int format,
+			int port);
 #endif
Signature · 1 line
1.8.5.3
#2 lore raw

PATCH 2/4 ASoC: tda998x: add a codec driver for TDA998x

In reply to Jean-Francois Moine

This patch adds a CODEC driver for the NXP TDA998x HDMI transmitter.

The CODEC handles both I2S and S/PDIF input and does dynamic input switch in the TDA998x I2C driver on audio streaming start/stop.

---
 sound/soc/codecs/Kconfig   |   7 ++
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/tda998x.c | 227 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 236 insertions(+)
 create mode 100644 sound/soc/codecs/tda998x.c
sound/soc/codecs/Kconfig +7 -0
index b33b45d..7cec76e 100644
@@ -71,6 +71,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_STA529 if I2C
 	select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
 	select SND_SOC_TAS5086 if I2C
+	select SND_SOC_TDA998X if I2C
 	select SND_SOC_TLV320AIC23 if I2C
 	select SND_SOC_TLV320AIC26 if SPI_MASTER
 	select SND_SOC_TLV320AIC32X4 if I2C
@@ -352,6 +353,12 @@ config SND_SOC_STAC9766
 config SND_SOC_TAS5086
 	tristate
 
+config SND_SOC_TDA998X
+	tristate
+	depends on OF
+	default y if DRM_I2C_NXP_TDA998X=y
+	default m if DRM_I2C_NXP_TDA998X=m
+
 config SND_SOC_TLV320AIC23
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index bc12676..a53d09e 100644
@@ -62,6 +62,7 @@ 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-tda998x-objs := tda998x.o
 snd-soc-tlv320aic23-objs := tlv320aic23.o
 snd-soc-tlv320aic26-objs := tlv320aic26.o
 snd-soc-tlv320aic3x-objs := tlv320aic3x.o
@@ -192,6 +193,7 @@ 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_TDA998X)	+= snd-soc-tda998x.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/tda998x.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
1.8.5.3
maintainer
#3 lore raw

Re: [PATCH 2/4] ASoC: tda998x: add a codec driver for TDA998x

sound/soc/codecs/Kconfig config SND_SOC_STAC9766 · line 361

Quoted 10 lines · Jean-Francois Moine
sound/soc/codecs/Kconfig +7 -0
 	select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
 	select SND_SOC_TAS5086 if I2C
+	select SND_SOC_TDA998X if I2C
 
+config SND_SOC_TDA998X
+	tristate
+	depends on OF
+	default y if DRM_I2C_NXP_TDA998X=y
+	default m if DRM_I2C_NXP_TDA998X=m
+

These two things don't seem to agree with each other, and I expect this breaks the build for ALL_CODECS.

Quoted 19 lines
sound/soc/codecs/tda998x.c new file +19 -0
+static void tda_get_encoder(struct tda_priv *priv)
+{
+	struct snd_soc_codec *codec = priv->codec;
+	struct device_node *np;
+	struct i2c_client *i2c_client;
+	static const struct of_device_id tda_dt[] = {
+		{ .compatible = "nxp,tda998x" },
+		{ },
+	};
+
+	/* search the tda998x device */
+	np = of_find_matching_node_and_match(NULL, tda_dt, NULL);
+	if (!np || !of_device_is_available(np)) {
+		dev_err(codec->dev, "No tda998x in DT\n");
+		return;
+	}
+	i2c_client = of_find_i2c_device_by_node(np);
+	of_node_put(np);
+	if (!i2c_client) {

sound/soc/codecs/tda998x.c line 62

Quoted 10 lines
sound/soc/codecs/tda998x.c new file +10 -0
+		dev_err(codec->dev, "no tda998x i2c client\n");
+		return;
+	}
+	if (!i2c_get_clientdata(i2c_client)) {
+		dev_err(codec->dev, "tda998x not initialized\n");
+		return;
+	}
+
+	priv->i2c_client = i2c_client;
+}

The normal way of doing this would be to make the device a MFD - that way the frameworks make sure probe ordering and so on are sorted out. Other than that this looks basically OK, a few small comments below.

sound/soc/codecs/tda998x.c line 76

Quoted 2 lines
sound/soc/codecs/tda998x.c new file +2 -0
+	/* give the audio input type and ports to the HDMI encoder */
+	format = start ? priv->dai_id : 0;

It's not clear to me what the above is doing (I think I know but it requires thinking about rather than being clear).

sound/soc/codecs/tda998x.c line 118

Quoted 3 lines
sound/soc/codecs/tda998x.c new file +3 -0
+static const struct snd_soc_dai_driver tda998x_dai[] = {
+    {
+	.name = "i2s-hifi",

Coding style, indents are tabs.

#4 lore raw

PATCH 3/4 ASoC: tda998x: add DT documentation

In reply to Jean-Francois Moine

Add devicetree documentation about the NXP TDA998x CODEC.

---
 Documentation/devicetree/bindings/sound/tda998x.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/tda998x.txt
Documentation/devicetree/bindings/sound/tda998x.txt new file +14 -0
new file mode 100644
index 0000000..30273a6
@@ -0,0 +1,14 @@
+Device-Tree bindings for the NXP TDA998x HDMI transmitter
+
+Required properties:
+	- compatible: must be "nxp,tda998x-codec".
+	- audio-ports: one or two values.
+		The first value defines the I2S input port.
+		The second one, if present, defines the S/PDIF input port.
+
+Example node:
+
+	hdmi_codec: hdmi-codec {
+		compatible = "nxp,tda998x-codec";
+		audio-ports = <0x03>, <0x04>;
+	};
Signature · 1 line
1.8.5.3
maintainer
#5 lore raw

Re: [PATCH 3/4] ASoC: tda998x: add DT documentation

Documentation/devicetree/bindings/sound/tda998x.txt line 7

Quoted 4 lines · Jean-Francois Moine
Documentation/devicetree/bindings/sound/tda998x.txt new file +4 -0
+	- compatible: must be "nxp,tda998x-codec".
+	- audio-ports: one or two values.
+		The first value defines the I2S input port.
+		The second one, if present, defines the S/PDIF input port.

I take it these are port numbers on the device and it's not possible to do something like having multiple I2S ports?

#6 lore raw

Re: [PATCH 3/4] ASoC: tda998x: add DT documentation

Quoted 9 lines · Mark Brown

Documentation/devicetree/bindings/sound/tda998x.txt line 7

Quoted 4 lines · Jean-Francois Moine
Documentation/devicetree/bindings/sound/tda998x.txt new file +4 -0
+	- compatible: must be "nxp,tda998x-codec".
+	- audio-ports: one or two values.
+		The first value defines the I2S input port.
+		The second one, if present, defines the S/PDIF input port.

I take it these are port numbers on the device and it's not possible to do something like having multiple I2S ports?

You can feed it with multiple synchronised I2S streams for the additional channels.

Signature · 7 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#7 lore raw

Re: [PATCH 3/4] ASoC: tda998x: add DT documentation

Quoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Mark Brown

Documentation/devicetree/bindings/sound/tda998x.txt line 7

Quoted 3 lines · Jean-Francois Moine
Documentation/devicetree/bindings/sound/tda998x.txt new file +3 -0
+	- audio-ports: one or two values.
+		The first value defines the I2S input port.
+		The second one, if present, defines the S/PDIF input port.

I take it these are port numbers on the device and it's not possible to do something like having multiple I2S ports?

Quoted 2 lines

You can feed it with multiple synchronised I2S streams for the additional channels.

Ah, I feared as much. The bindings ought to take account of that posibility even if the code can't use additional ports yet. Perhaps separate properties for I2S and S/PDIF?

#8 lore raw

PATCH 4/4 ASoC: tda998x: adjust the audio hw parameters from EDID

In reply to Jean-Francois Moine

The supported audio parameters are described in the EDID which is received by the HDMI transmitter from the connected screen. Use these ones to adjust the audio stream parameters.

---
 drivers/gpu/drm/i2c/tda998x_drv.c | 15 ++++++++
 include/drm/i2c/tda998x.h         |  1 +
 sound/soc/codecs/tda998x.c        | 79 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 1 deletion(-)
drivers/gpu/drm/i2c/tda998x_drv.c +15 -0
index 186c751..3c8b4d7 100644
@@ -45,6 +45,8 @@ struct tda998x_priv {
 	wait_queue_head_t wq_edid;
 	volatile int wq_edid_wait;
 	struct drm_encoder *encoder;
+
+	u8 *eld;
 };
 
 #define to_tda998x_priv(x)  ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv)
@@ -731,6 +733,14 @@ tda998x_configure_audio(struct tda998x_priv *priv,
 }
 
 /* tda998x codec interface */
+u8 *tda998x_audio_get_eld(struct i2c_client *client)
+{
+	struct tda998x_priv *priv = i2c_get_clientdata(client);
+
+	return priv->eld;
+}
+EXPORT_SYMBOL_GPL(tda998x_audio_get_eld);
+
 void tda998x_audio_update(struct i2c_client *client,
 			int format,
 			int port)
@@ -1186,6 +1196,11 @@ tda998x_encoder_get_modes(struct drm_encoder *encoder,
 		drm_mode_connector_update_edid_property(connector, edid);
 		n = drm_add_edid_modes(connector, edid);
 		priv->is_hdmi_sink = drm_detect_hdmi_monitor(edid);
+
+		/* keep the EDID as ELD for the audio subsystem */
+		drm_edid_to_eld(connector, edid);
+		priv->eld = connector->eld;
+
 		kfree(edid);
 	}
 
include/drm/i2c/tda998x.h +1 -0
index 0459931..64aaaa8 100644
@@ -26,6 +26,7 @@ struct tda998x_encoder_params {
 	unsigned audio_sample_rate;
 };
 
+u8 *tda998x_audio_get_eld(struct i2c_client *client);
 void tda998x_audio_update(struct i2c_client *client,
 			int format,
 			int port);
sound/soc/codecs/tda998x.c +78 -1

97 lines not on this page · raw message

Signature · 1 line
1.8.5.3
maintainer
#9 lore raw

Re: [PATCH 4/4] ASoC: tda998x: adjust the audio hw parameters from EDID

sound/soc/codecs/tda998x.c static int tda_startup(struct snd_pcm_substream *substream, · line 133

Quoted 10 lines · Jean-Francois Moine
sound/soc/codecs/tda998x.c +10 -0
+		eld_ver = eld[0] >> 3;
+		if (eld_ver != 2 && eld_ver != 31)
+			return 0;
+
+		mnl = eld[4] & 0x1f;
+		if (mnl > 16)
+			return 0;
+
+		sad_count = eld[5] >> 4;
+		sad = eld + 20 + mnl;

Can this parsing code be factored out - it (or large parts of it) should be usable by other HDMI devices shouldn't it?

#10 lore raw

Re: [PATCH 4/4] ASoC: tda998x: adjust the audio hw parameters from EDID

Quoted 15 lines · Mark Brown

sound/soc/codecs/tda998x.c static int tda_startup(struct snd_pcm_substream *substream, · line 133

Quoted 10 lines · Jean-Francois Moine
sound/soc/codecs/tda998x.c +10 -0
+		eld_ver = eld[0] >> 3;
+		if (eld_ver != 2 && eld_ver != 31)
+			return 0;
+
+		mnl = eld[4] & 0x1f;
+		if (mnl > 16)
+			return 0;
+
+		sad_count = eld[5] >> 4;
+		sad = eld + 20 + mnl;

Can this parsing code be factored out - it (or large parts of it) should be usable by other HDMI devices shouldn't it?

Yes, preferably as a generic ALSA helper rather than an ASoC helper - I don't see any need for this to be ASoC specific (I have a pure ALSA driver which has very similar code in it.)

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
maintainer
#11 lore raw

Re: [PATCH 4/4] ASoC: tda998x: adjust the audio hw parameters from EDID

Quoted 8 lines · Russell King - ARM Linux
Quoted 2 lines · Mark Brown

Can this parsing code be factored out - it (or large parts of it) should be usable by other HDMI devices shouldn't it?

Yes, preferably as a generic ALSA helper rather than an ASoC helper - I don't see any need for this to be ASoC specific (I have a pure ALSA driver which has very similar code in it.)

Indeed, definitely ALSA generic - ideally we could factor a lot of the integration with the video side out.

#12 lore raw

Re: [alsa-devel] [PATCH 4/4] ASoC: tda998x: adjust the audio hw parameters from EDID

At Mon, 27 Jan 2014 20:54:37 +0000,

Quoted 7 lines · Mark Brown
Quoted 4 lines · Russell King - ARM Linux
Quoted 2 lines · Mark Brown

Can this parsing code be factored out - it (or large parts of it) should be usable by other HDMI devices shouldn't it?

Quoted 6 lines
Quoted 3 lines

Yes, preferably as a generic ALSA helper rather than an ASoC helper - I don't see any need for this to be ASoC specific (I have a pure ALSA driver which has very similar code in it.)

Indeed, definitely ALSA generic - ideally we could factor a lot of the integration with the video side out.

Yes, indeed.

OTOH, as discussed recently, we're heading to move from ELD parsing to more direct communication between video and audio drivers for HD-audio. ELD will be still provided to user-space, but not evaluated any longer in the new scenario.

Takashi

maintainer
#13 lore raw

Re: [alsa-devel] [PATCH 4/4] ASoC: tda998x: adjust the audio hw parameters from EDID

Quoted 10 lines · Takashi Iwai
Quoted 8 lines · Mark Brown
Quoted 3 lines · Russell King - ARM Linux

Yes, preferably as a generic ALSA helper rather than an ASoC helper - I don't see any need for this to be ASoC specific (I have a pure ALSA driver which has very similar code in it.)

Indeed, definitely ALSA generic - ideally we could factor a lot of the integration with the video side out.

Quoted 6 lines

Yes, indeed.

OTOH, as discussed recently, we're heading to move from ELD parsing to more direct communication between video and audio drivers for HD-audio. ELD will be still provided to user-space, but not evaluated any longer in the new scenario.

That sort of refactoring being one of the best reasons to keep things out of individual drivers! Having said all this I don't know if it's worth blocking Jean-Francois' work on that, it's an improvement in itself. Splitting the code out a bit would be good to help prepare but having the full refactoring done might be too much of a blocker.

#14 lore raw

Re: [alsa-devel] [PATCH 4/4] ASoC: tda998x: adjust the audio hw parameters from EDID

At Tue, 28 Jan 2014 11:00:51 +0000,

Quoted 19 lines · Mark Brown
Quoted 10 lines · Takashi Iwai
Quoted 8 lines · Mark Brown
Quoted 3 lines · Russell King - ARM Linux

Yes, preferably as a generic ALSA helper rather than an ASoC helper - I don't see any need for this to be ASoC specific (I have a pure ALSA driver which has very similar code in it.)

Indeed, definitely ALSA generic - ideally we could factor a lot of the integration with the video side out.

Quoted 6 lines

Yes, indeed.

OTOH, as discussed recently, we're heading to move from ELD parsing to more direct communication between video and audio drivers for HD-audio. ELD will be still provided to user-space, but not evaluated any longer in the new scenario.

Quoted 5 lines

That sort of refactoring being one of the best reasons to keep things out of individual drivers! Having said all this I don't know if it's worth blocking Jean-Francois' work on that, it's an improvement in itself. Splitting the code out a bit would be good to help prepare but having the full refactoring done might be too much of a blocker.

I just rather wanted to point out the general direction for the further development, didn't mean NAK. Jean-Francois' patch itself looks simple enough, so I see no problem to take it for now as is.

Takashi