Skip to contentSkip to conversation

ASoC: tda998x: add a codec to the HDMI transmitter

PATCH Superseded Jean-Francois Moine 4 participants 15 messages Jul 2, 2014 – Jul 3, 2014

Subsystems (3)

v1 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: tda998x: add a codec to the HDMI transmitter

This patch adds a CODEC function to the NXP TDA998x HDMI transmitter.

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

---
This patch applies against linux-next.

---
 .../devicetree/bindings/drm/i2c/tda998x.txt        |  13 ++
 drivers/gpu/drm/i2c/Makefile                       |   2 +-
 drivers/gpu/drm/i2c/tda998x_codec.c                | 241 +++++++++++++++++++++
 drivers/gpu/drm/i2c/tda998x_drv.c                  |  74 +++++--
 drivers/gpu/drm/i2c/tda998x_drv.h                  |  31 +++
 include/drm/i2c/tda998x.h                          |   1 +
 6 files changed, 341 insertions(+), 21 deletions(-)
 create mode 100644 drivers/gpu/drm/i2c/tda998x_codec.c
 create mode 100644 drivers/gpu/drm/i2c/tda998x_drv.h
Documentation/devicetree/bindings/drm/i2c/tda998x.txt +13 -0
index d7df01c..7ce4eac 100644
@@ -15,6 +15,15 @@ Optional properties:
   - video-ports: 24 bits value which defines how the video controller
 	output is wired to the TDA998x input - default: <0x230145>
 
+  - audio-ports: one or two values corresponding to entries in
+	the audio-port-names property.
+
+  - audio-port-names: must contain "i2s", "spdif" entries
+	matching entries in the audio-ports property.
+
+  - #sound-dai-cells: must be set to <1> for use with the simple-card.
+	The DAI 0 is the I2S input and the DAI 1 is the S/PDIF input.
+
 Example:
 
 	tda998x: hdmi-encoder {
@@ -24,4 +33,8 @@ Example:
 		interrupts = <27 2>;		/* falling edge */
 		pinctrl-0 = <&pmx_camera>;
 		pinctrl-names = "default";
+
+		audio-ports = <0x03>, <0x04>;
+		audio-port-names = "i2s", "spdif";
+		#sound-dai-cells = <1>;
 	};
drivers/gpu/drm/i2c/Makefile +1 -1
index 43aa33b..f2d625c 100644
@@ -6,5 +6,5 @@ obj-$(CONFIG_DRM_I2C_CH7006) += ch7006.o
 sil164-y := sil164_drv.o
 obj-$(CONFIG_DRM_I2C_SIL164) += sil164.o
 
-tda998x-y := tda998x_drv.o
+tda998x-y := tda998x_drv.o tda998x_codec.o
 obj-$(CONFIG_DRM_I2C_NXP_TDA998X) += tda998x.o
drivers/gpu/drm/i2c/tda998x_codec.c new file +241 -0

241 lines not on this page · raw message

drivers/gpu/drm/i2c/tda998x_drv.c +54 -20

149 lines not on this page · raw message

drivers/gpu/drm/i2c/tda998x_drv.h new file +31 -0
new file mode 100644
index 0000000..6db5160
@@ -0,0 +1,31 @@
+/* tda998x private data */
+
+struct tda998x_priv {
+	struct i2c_client *cec;
+	struct i2c_client *hdmi;
+	uint16_t rev;
+	uint8_t current_page;
+	int dpms;
+	bool is_hdmi_sink;
+	u8 vip_cntrl_0;
+	u8 vip_cntrl_1;
+	u8 vip_cntrl_2;
+	struct tda998x_encoder_params params;
+
+	wait_queue_head_t wq_edid;
+	volatile int wq_edid_wait;
+	struct drm_encoder *encoder;
+
+	u8 audio_ports[2];
+	int audio_sample_format;
+
+	u8 *eld;
+
+	struct snd_pcm_hw_constraint_list rate_constraints;
+};
+
+int tda998x_codec_register(struct device *dev);
+void tda998x_codec_unregister(struct device *dev);
+
+void tda998x_audio_start(struct tda998x_priv *priv, int full);
+void tda998x_audio_stop(struct tda998x_priv *priv);
include/drm/i2c/tda998x.h +1 -0
index 3e419d9..31757df 100644
@@ -20,6 +20,7 @@ struct tda998x_encoder_params {
 	u8 audio_frame[6];
 
 	enum {
+		AFMT_NO_AUDIO = 0,
 		AFMT_SPDIF,
 		AFMT_I2S
 	} audio_format;
Signature · 10 lines
2.0.1


-- 
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 4 lines · Jean-Francois Moine

This patch adds a CODEC function to the NXP TDA998x HDMI transmitter.

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

Hi Jean-Francois

How well will this work with Russell concept of a front end and two backends? Can you uses your CODEC twice, once with the I2S backend and a second time with the S/PDIF backend?

Andrew

#2 lore raw
Quoted 3 lines · On Wed, 2 Jul 2014 18:56:28 +0200 Andrew Lunn <[email protected]> wrote:

How well will this work with Russell concept of a front end and two backends? Can you uses your CODEC twice, once with the I2S backend and a second time with the S/PDIF backend?

Hi Andrew,

The TDA998x CODEC has two functions:
- it sets the possible formats and rates when the screen connects and
- it sets the audio input port when audio streaming starts.

I tested this CODEC with both DAPM and DPCM. If the audio subsystem asks for streaming on both I2S and S/PDIF, only the last call is served (this depends on the order of the DAI links in the audio card creation table).

As I told to Russell, DPCM just asks for a 'system' DAI (front-end), but it also asks for some additional code in the kirkwood DMA driver because all PCMs are activated on streaming start.

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
Quoted 13 lines · Jean-Francois Moine
Quoted 3 lines · On Wed, 2 Jul 2014 18:56:28 +0200 Andrew Lunn <[email protected]> wrote:

How well will this work with Russell concept of a front end and two backends? Can you uses your CODEC twice, once with the I2S backend and a second time with the S/PDIF backend?

Hi Andrew,

The TDA998x CODEC has two functions:
- it sets the possible formats and rates when the screen connects and
- it sets the audio input port when audio streaming starts.

Quoted 8 lines

I tested this CODEC with both DAPM and DPCM. If the audio subsystem asks for streaming on both I2S and S/PDIF, only the last call is served (this depends on the order of the DAI links in the audio card creation table).

As I told to Russell, DPCM just asks for a 'system' DAI (front-end), but it also asks for some additional code in the kirkwood DMA driver because all PCMs are activated on streaming start.

Well, as far as I'm concerned right now, it's for Mark to sort out this situation, and tell us what he wants to do with the Kirkwood stuff. I suspect he's keeping quiet because he doesn't care about it.

Given that he's the one with the knowledge of DPCM, and he's the maintainer of ASoC, he has the ultimate responsibility for sorting out this and giving direction as to how he wants to proceed.

As I understand it though, my solution is the full and proper DPCM solution, and I believe that what's currently in mainline is not a DPCM solution.

Mark needs to correct that, because he is one of the few who knows this stuff.

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
#4 lore raw
Quoted 3 lines · Russell King - ARM Linux

Well, as far as I'm concerned right now, it's for Mark to sort out this situation, and tell us what he wants to do with the Kirkwood stuff. I suspect he's keeping quiet because he doesn't care about it.

Well, that and the general level of stress around the support for these boards in general.

Quoted 6 lines

Given that he's the one with the knowledge of DPCM, and he's the maintainer of ASoC, he has the ultimate responsibility for sorting out this and giving direction as to how he wants to proceed.

As I understand it though, my solution is the full and proper DPCM solution, and I believe that what's currently in mainline is not a DPCM solution.

That's right, from what I remember your last set of patches looked like it was pretty much there in terms of the code for the CPU. Liam's obviously the most in depth expert with DPCM but he's incredibly snowed under with work right now.

#5 lore raw
In reply to Jean-Francois Moine
Quoted 4 lines · Jean-Francois Moine

I tested this CODEC with both DAPM and DPCM. If the audio subsystem asks for streaming on both I2S and S/PDIF, only the last call is served (this depends on the order of the DAI links in the audio card creation table).

I'd expect this to return an error for the busy DAI rather than just silently ignore it failing to start or (better) implement some control to let the user select which of the DAIs is active.

#6 lore raw
Quoted 8 lines · On Wed, 2 Jul 2014 20:42:52 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines

I tested this CODEC with both DAPM and DPCM. If the audio subsystem asks for streaming on both I2S and S/PDIF, only the last call is served (this depends on the order of the DAI links in the audio card creation table).

I'd expect this to return an error for the busy DAI rather than just silently ignore it failing to start or (better) implement some control to let the user select which of the DAIs is active.

Mark,

This is not an error. If the audio subsystem (DPCM, not the user) chooses to activate both I2S and S/PDIF, this means the HDMI audio may be taken either from I2S or from S/PDIF: both inputs have the right format and rate.

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw
Quoted 10 lines · Jean-Francois Moine
Quoted 3 lines · Mark Brown

I'd expect this to return an error for the busy DAI rather than just silently ignore it failing to start or (better) implement some control to let the user select which of the DAIs is active.

This is not an error. If the audio subsystem (DPCM, not the user) chooses to activate both I2S and S/PDIF, this means the HDMI audio may be taken either from I2S or from S/PDIF: both inputs have the right format and rate.

Your board happens to only be able to present the same input on both I2S and S/PDIF but that might not apply to other boards, they may be able to route different signals to each which would present a practical problem.

#8 lore raw
Quoted 4 lines · On Thu, 3 Jul 2014 11:44:32 +0100 Mark Brown <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

I'd expect this to return an error for the busy DAI rather than just silently ignore it failing to start or (better) implement some control to let the user select which of the DAIs is active.

Quoted 8 lines
Quoted 4 lines

This is not an error. If the audio subsystem (DPCM, not the user) chooses to activate both I2S and S/PDIF, this means the HDMI audio may be taken either from I2S or from S/PDIF: both inputs have the right format and rate.

Your board happens to only be able to present the same input on both I2S and S/PDIF but that might not apply to other boards, they may be able to route different signals to each which would present a practical problem.

If there are two different streamss on I2S and S/PDIF, and if the audio subsystem wants to route these streams to the same connector (widget 'hdmi-out'), then, somewhere, there should be a software or a design bug. No?

Anyway, the tda998x cannot know if the double route is wanted or not.

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw
Quoted 10 lines · Jean-Francois Moine
Quoted 3 lines · Mark Brown

Your board happens to only be able to present the same input on both I2S and S/PDIF but that might not apply to other boards, they may be able to route different signals to each which would present a practical problem.

If there are two different streamss on I2S and S/PDIF, and if the audio subsystem wants to route these streams to the same connector (widget 'hdmi-out'), then, somewhere, there should be a software or a design bug. No?

Yes, which is why the driver shouldn't silently ignore the situation.

Quoted 1 line

Anyway, the tda998x cannot know if the double route is wanted or not.

It doesn't need to know, it just needs to identify something it can't support either by providing a way to pick which interface is used or by rejecting the second interface.

#10 lore raw
Quoted 9 lines · On Thu, 3 Jul 2014 12:59:24 +0100 Mark Brown <[email protected]> wrote:
Quoted 8 lines
Quoted 3 lines

Your board happens to only be able to present the same input on both I2S and S/PDIF but that might not apply to other boards, they may be able to route different signals to each which would present a practical problem.

If there are two different streamss on I2S and S/PDIF, and if the audio subsystem wants to route these streams to the same connector (widget 'hdmi-out'), then, somewhere, there should be a software or a design bug. No?

Quoted 7 lines

Yes, which is why the driver shouldn't silently ignore the situation.

Quoted 1 line

Anyway, the tda998x cannot know if the double route is wanted or not.

It doesn't need to know, it just needs to identify something it can't support either by providing a way to pick which interface is used or by rejecting the second interface.

OK. no problem, I can do that: only the first stream is switched and the second is rejected.

But, this means that there will be a lot of errors when DPCM will be used, because, in most cases for the Cubox (kirkwood audio + tda998x), both ways I2S and S/PDIF will be activated at the same time for a single stream (you may note that the routes from the second input cannot be blocked by the CODEC after it received the first input, because these routes have already been computed).

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw
Quoted 9 lines · Jean-Francois Moine

OK. no problem, I can do that: only the first stream is switched and the second is rejected.

But, this means that there will be a lot of errors when DPCM will be used, because, in most cases for the Cubox (kirkwood audio + tda998x), both ways I2S and S/PDIF will be activated at the same time for a single stream (you may note that the routes from the second input cannot be blocked by the CODEC after it received the first input, because these routes have already been computed).

This is /very/ easy to solve on the Cubox, if only you would listen to me - I've stated many times that I2S should not be used there.

Just because the hardware is wired up with both the SPDIF connected and the I2S connected, it does *not* mean that we have to wire them both up in software.

Indeed, *everything* works with just SPDIF. The same is not true of I2S. So, what we do for the Cubox is we just wire up SPDIF in software and be done with it - we then get a fully functional setup. So using I2S on the Cubox is mostly pointless - unless you wish to use I2S for testing purposes.

Let me also point out that adding your changes - including the addition of this codec patch - explicitly deny the possibility of:
* using compressed audio streams via the optical SPDIF out socket
* using compressed audio streams over HDMI
* using audio rates and formats not supported by the attached HDMI device via the optical SPDIF socket.

These are serious issues which thus far you have so far failed to respond on. People who use the Cubox as a media platform rather than (presumably) just a music jukebox want things like compressed audio out and SPDIF out to work.

Look, one reason to use the optical socket is because you want to push out a stream at (eg) 96kHz to your audio system, but your TV doesn't support it. With your approach, you explicitly block that because the TDA998x codec assocated with the Kirkwood CPU DAI refuses to allow that sample rate. Fine, if the attached device does not support that rate, then the right thing to do may be to disable audio transmission over HDMI, but with the Cubox hardware, limiting the sample rates is totally the wrong solution.

Signature · 6 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
--
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
#12 lore raw
Quoted 32 lines · On Thu, 3 Jul 2014 14:43:46 +0100 Russell King - ARM Linux…
Quoted 6 lines

But, this means that there will be a lot of errors when DPCM will be used, because, in most cases for the Cubox (kirkwood audio + tda998x), both ways I2S and S/PDIF will be activated at the same time for a single stream (you may note that the routes from the second input cannot be blocked by the CODEC after it received the first input, because these routes have already been computed).

This is /very/ easy to solve on the Cubox, if only you would listen to me - I've stated many times that I2S should not be used there.

Just because the hardware is wired up with both the SPDIF connected and the I2S connected, it does *not* mean that we have to wire them both up in software.

Indeed, *everything* works with just SPDIF. The same is not true of I2S. So, what we do for the Cubox is we just wire up SPDIF in software and be done with it - we then get a fully functional setup. So using I2S on the Cubox is mostly pointless - unless you wish to use I2S for testing purposes.

Let me also point out that adding your changes - including the addition of this codec patch - explicitly deny the possibility of:
* using compressed audio streams via the optical SPDIF out socket
* using compressed audio streams over HDMI
* using audio rates and formats not supported by the attached HDMI device via the optical SPDIF socket.

These are serious issues which thus far you have so far failed to respond on. People who use the Cubox as a media platform rather than (presumably) just a music jukebox want things like compressed audio out and SPDIF out to work.

Quoted 8 lines

Look, one reason to use the optical socket is because you want to push out a stream at (eg) 96kHz to your audio system, but your TV doesn't support it. With your approach, you explicitly block that because the TDA998x codec assocated with the Kirkwood CPU DAI refuses to allow that sample rate. Fine, if the attached device does not support that rate, then the right thing to do may be to disable audio transmission over HDMI, but with the Cubox hardware, limiting the sample rates is totally the wrong solution.

I think that you did not look at my code.

Both S/PDIF and I2S work with the TDA998x. It is a choice of the audio subsystem to do this choice, not Russell King. If you want only S/PDIF, it is easy: just declare the S/PDIF DAIs, on both sides, source (kirkwood) and sinks (tda998x and S/PDIF):

	dai-link@1 {		/* S/PDIF - HDMI */
		cpu {
			sound-dai = <&audio1 1>;
		};
		,codec {
			sound-dai = <&hdmi 1>;
		};
	};

	dai-link@2 {		/* S/PDIF - S/PDIF */
		cpu {
			sound-dai = <&audio1 1>;
		};
		codec {
			sound-dai = <&spdif_codec>;
		};
	};

When DPCM will handle the formats and rates, the audio subsystem will find by itself if such stream will go to the HDMI only or to the S/PDIF only or to both. The kirwood audio driver will work as it is and the tda998x CODEC will work as it is. There will be no need to change these drivers. All we need actually is some more code in DPCM or multi-codec or whatever mechanism which will route the stream according to the rates and formats.

Actually, as DPCM does not work, the user has to choose which PCM to use, otherwise, the application does a format and rate translation.

Anyway, if you want S/PDIF output with the actual kernel (3.16-rc3), in the DT, put:

	spdif_codec: spdif-codec {
		compatible = "linux,spdif-dit";
		#sound-dai-cells = <0>;
	};

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,name = "Cubox Audio";
		simple-audio-card,format = "i2s";

		simple-audio-card,dai-link {		/* S/PDIF - S/PDIF */
			simple-audio-card,cpu {
				sound-dai = <&audio1 1>;
			};
			simple-audio-card,codec {
				sound-dai = <&spdif_codec>;
			};
		};
	};
&audio1 {
	status = "okay";
	clocks = <&gate_clk 13>, <&si5351 2>;
	clock-names = "internal", "extclk";
	pinctrl-0 = <&pmx_audio1_i2s1_spdifo &pmx_audio1_extclk>;
	pinctrl-names = "default";
	#sound-dai-cells = <1>;
};

and the sound should get out of your S/PDIF optical connector.

Eventually, the TDA998x is used in other machines. Are you sure that the audio controllers of all these machines have a S/PDIF output connected to the S/PDIF input of the tda998x?

The tda998x CODEC I propose works in all configurations.

Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#13 lore raw
Quoted 4 lines · Jean-Francois Moine

I think that you did not look at my code.

Both S/PDIF and I2S work with the TDA998x. It is a choice of the audio subsystem to do this choice, not Russell King.

If you think I'm arguing because I personally want something, then we're not going to make any progress.

What I want is for this to be _correct_ and _not_ to introduce silly restrictions which break people's setups.

Quoted 4 lines

When DPCM will handle the formats and rates, the audio subsystem will find by itself if such stream will go to the HDMI only or to the S/PDIF only or to both. The kirwood audio driver will work as it is and the tda998x CODEC will work as it is. There will be no need to change these drivers.

Except, as Mark has already pointed out, and as I keep pointing out to you, and you keep refusing to accept, the kirkwood driver as it stands is *not* a DPCM driver. It makes no use of that stuff at all.

What you're doing in kirkwood-i2s is providing two plain DAI links, and then insisting that only one can be active any any one time.

A DPCM solution provides at least one frontend DAI link and at least one backend DAI link. Your code does not do this.

The second point is that - and as I keep telling you - that as soon as you couple your existing code (which restricts things like the sample rates) you can no longer output anything else through the optical out ON THE CUBOX. For this statement, I'm not talking _generally_, I'm talking _specifically_ about _one_ _platform_.

Quoted 3 lines

All we need actually is some more code in DPCM or multi-codec or whatever mechanism which will route the stream according to the rates and formats.

Yes, DPCM currently lacks full support, that's been known about for some time - I've reported it to Mark, but it seems that this isn't something that is going to get fixed until others put work into it.

Quoted 3 lines

Eventually, the TDA998x is used in other machines. Are you sure that the audio controllers of all these machines have a S/PDIF output connected to the S/PDIF input of the tda998x?

Which bit of "we need to support both I2S and SPDIF" in my previous emails was not clear. Which bit of "We should only support SPDIF on the Cubox" was not clear?

I *fully* acknowledge that we need to support both, but I'm putting a _strong_ recommendation to you _with_ technical reasons why we should _only_ support SPDIF on the Cubox.

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
#14 lore raw
Quoted 5 lines · On Thu, 3 Jul 2014 16:43:25 +0100 Russell King - ARM Linux…

What you're doing in kirkwood-i2s is providing two plain DAI links, and then insisting that only one can be active any any one time.

A DPCM solution provides at least one frontend DAI link and at least one backend DAI link. Your code does not do this.

You know why I did not insert the DPCM code in the kirkwood driver: it does not work. But, as I tested it end 2013, I still have the code. Do you want I propose a patch?

Quoted 7 lines

Which bit of "we need to support both I2S and SPDIF" in my previous emails was not clear. Which bit of "We should only support SPDIF on the Cubox" was not clear?

I *fully* acknowledge that we need to support both, but I'm putting a _strong_ recommendation to you _with_ technical reasons why we should _only_ support SPDIF on the Cubox.

Sorry, I still don't see why only S/PDIF should be supported on the Cubox. I have both, and both are working on HDMI. I hope someone will tell me it also works on S/PDIF: there is no reason it could not.

I don't see your technical reasons: you know the constraints of each protocol I2S and S/PDIF. If you don't want I2S, just don't declare it in the DT (see my previous mail). You may also note that I did not put any change relative to the Cubox DT in my patch.

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel