pvdmeer
Posts: 18
Joined: Mon Feb 22, 2016 10:29 am

PT8211 I2S ASOC driver

Tue Dec 20, 2016 9:01 pm

Hi!

I recently hacked the Hifiberry-DAC driver so that it would support the PT8211 16 bit stereo DAC. This works flawlessly, and it's damn easy to wire this up to the pi. I'd like to make this a real driver and contribute to rpi-linux repository. Unfortunately, when I change the name from snd-soc-hifiberry-dac.ko to snd-soc-pt8211.ko, it just refuses to work. Is this a driver tree issue? Can anybody help me? I'd like to contribute, especially since the PT8211 is so easy to work with and nice for beginners...

Cheers!

Pieter

rglenn
Posts: 1
Joined: Thu Mar 07, 2013 6:54 pm

Re: PT8211 I2S ASOC driver

Sat Feb 24, 2018 4:27 am

What changes did you have to make to the Hifiberry DAC driver to make it work? I'd really like to get one of these working on a Pi.

Thanks!

pvdmeer
Posts: 18
Joined: Mon Feb 22, 2016 10:29 am

Re: PT8211 I2S ASOC driver

Fri Mar 09, 2018 1:40 pm

you need to add a case in the switch statement for LEFT_JUSTIFIED mode, from the top of my head. but beware. the PT8211 is not a HIFI DAC, and without a really good LDO regulator it will sounds like S%%^T :D

bricolodu13
Posts: 32
Joined: Tue Aug 07, 2012 2:05 pm

Re: PT8211 I2S ASOC driver

Wed Apr 11, 2018 6:58 pm

Hello pvdmeer,

I have the same need for another Japanese format DAC.

Could you post your code ?

It would help.

Thank you,
Jean

pvdmeer
Posts: 18
Joined: Mon Feb 22, 2016 10:29 am

Re: PT8211 I2S ASOC driver

Wed Apr 11, 2018 7:21 pm

just check hifiberry_dac.c in the kernel sources and change:
.dai_fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS,

notice the LEFT_J define in t here..

bcm2835-i2s.c needs an additional case in the switch:

switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
data_delay = 1;
break;
case SND_SOC_DAIFMT_LEFT_J:
data_delay = 0;
break;

that's all IIRC

HiassofT
Posts: 134
Joined: Fri Jun 30, 2017 10:07 pm

Re: PT8211 I2S ASOC driver

Thu Apr 12, 2018 8:14 am

No need to hack up any drivers, the 4.14 kernel in Raspbian has everything you need on board - support for I2S, justified and DSP formats, generic input and output codec drivers ("spdif transmitter/receiver") and support for simple audio card and the more modern audio graph card.

All you need to do is create a devicetree overlay:

Code: Select all

/*
 * Audio Graph Card overlay for generic DAC in left-justified mode
 *
 * compile with:
 * dtc [email protected] -H epapr -O dtb -o generic-lj.dtbo -Wno-unit_address_vs_reg generic-lj.dts
 * 
 */
/dts-v1/;
/plugin/;

/ {
	[email protected] {
		target = <&i2s>;
		__overlay__ {
			#sound-dai-cells = <0>;
			status = "okay";

			cpu_port: port {
				cpu_endpoint: endpoint {
					remote-endpoint = <&codec_endpoint>;
					dai-format = "left_j";
					bitclock-master;
					frame-master;
				};
			};
		};
	};

	[email protected] {
		target-path = "/";
		__overlay__ {
			spdif-transmitter {
				#address-cells = <0>;
				#size-cells = <0>;
				#sound-dai-cells = <0>;
				compatible = "linux,spdif-dit";
				status = "okay";

				codec_port: port {
					codec_endpoint: endpoint {
						remote-endpoint = <&cpu_endpoint>;
					};
				};
			};
		};
	};

	[email protected] {
		target = <&sound>;
		__overlay__ {
			compatible = "audio-graph-card";
			label = "GenericLJ";
			dais = <&cpu_port>;
			status = "okay";
		};
	};
};
Compile the overlay, copy it to /boot/overlays/ and then load it from config.txt or via the "dtoverlay" command.

so long,

Hias

bricolodu13
Posts: 32
Joined: Tue Aug 07, 2012 2:05 pm

Re: PT8211 I2S ASOC driver

Thu Apr 12, 2018 4:49 pm

Thank you pvdmeer,

Thank you Hias,

Hias, I get the board listed with your code, however I didn't tested it yet with the TDA1543A.
I don't understand though why you make reference to spdif as my dac is japanese format right justified.
I have changed your code from left justifed to right justified.

Best regards,

VitS
Posts: 15
Joined: Wed Nov 07, 2018 8:54 pm

Re: PT8211 I2S ASOC driver

Tue Nov 27, 2018 8:23 pm

HiassofT wrote:
Thu Apr 12, 2018 8:14 am
No need to hack up any drivers, the 4.14 kernel in Raspbian has everything you need on board - support for I2S, justified and DSP formats, generic input and output codec drivers ("spdif transmitter/receiver") and support for simple audio card and the more modern audio graph card.

All you need to do is create a devicetree overlay:

Code: Select all

/*
 * Audio Graph Card overlay for generic DAC in left-justified mode
 *
 * compile with:
 * dtc [email protected] -H epapr -O dtb -o generic-lj.dtbo -Wno-unit_address_vs_reg generic-lj.dts
 * 
 */
/dts-v1/;
/plugin/;

/ {
	[email protected] {
		target = <&i2s>;
		__overlay__ {
			#sound-dai-cells = <0>;
			status = "okay";

			cpu_port: port {
				cpu_endpoint: endpoint {
					remote-endpoint = <&codec_endpoint>;
					dai-format = "left_j";
					bitclock-master;
					frame-master;
				};
			};
		};
	};

	[email protected] {
		target-path = "/";
		__overlay__ {
			spdif-transmitter {
				#address-cells = <0>;
				#size-cells = <0>;
				#sound-dai-cells = <0>;
				compatible = "linux,spdif-dit";
				status = "okay";

				codec_port: port {
					codec_endpoint: endpoint {
						remote-endpoint = <&cpu_endpoint>;
					};
				};
			};
		};
	};

	[email protected] {
		target = <&sound>;
		__overlay__ {
			compatible = "audio-graph-card";
			label = "GenericLJ";
			dais = <&cpu_port>;
			status = "okay";
		};
	};
};
Compile the overlay, copy it to /boot/overlays/ and then load it from config.txt or via the "dtoverlay" command.

so long,

Hias
Hello Hias,

Could you please help me to set up and ADC overlay, that will create a device available to arecord? What shall I change in the script above?
For i2s, while Pi is slave, ADC is master...

Thank you!

xaled
Posts: 4
Joined: Sun Dec 02, 2018 11:35 am

Re: PT8211 I2S ASOC driver

Sun Dec 02, 2018 11:44 am

Hi,

I successfully compiled and install the sample overlay and it is working well so far for the LJ format. The only problem is that I need a 32bit frame output but only get 24bit frame out. I assume that it is due to the spdif-transmitter part of the overlay.
Could somebody clarify the need for the spdif-transmitter part of the overlay and how to avoid it. I tried deleting the spdif-transmitter section and changing audio-graph-card fragment number to 1, but the resulting overlay will not compile.

/*
* Audio Graph Card overlay for generic DAC in left-justified mode
*
* compile with:
* dtc [email protected] -H epapr -O dtb -o generic-lj.dtbo -Wno-unit_address_vs_reg generic-lj.dts
*
*/
/dts-v1/;
/plugin/;

/ {
[email protected] {
target = <&i2s>;
__overlay__ {
#sound-dai-cells = <0>;
status = "okay";

cpu_port: port {
cpu_endpoint: endpoint {
remote-endpoint = <&codec_endpoint>;
dai-format = "left_j";
bitclock-master;
frame-master;
};
};
};
};


[email protected] {
target = <&sound>;
__overlay__ {
compatible = "audio-graph-card";
label = "GenericLJ";
dais = <&cpu_port>;
status = "okay";
};
};
};

HiassofT
Posts: 134
Joined: Fri Jun 30, 2017 10:07 pm

Re: PT8211 I2S ASOC driver

Sun Dec 02, 2018 12:46 pm

By default bcm2835-i2s sets the number of bclk cycles to the data width - 16 for 16bit samples, 24 for 24bit etc.

To use a fixed amount of cycles add the dai-tdm-slot-num (must be 2, as we have 2 channes) and dai-tdm-slot-width (set it to 32 to use 32 cycles per sample) to the cpu endpoint. eg

Code: Select all

cpu_endpoint: endpoint {
  remote-endpoint = <&codec_endpoint>;
  dai-format = "left_j";
  dai-tdm-slot-num = <2>;
  dai-tdm-slot-width = <32>;
  bitclock-master;
  frame-master;
};
so long,

Hias

xaled
Posts: 4
Joined: Sun Dec 02, 2018 11:35 am

Re: PT8211 I2S ASOC driver

Sun Dec 02, 2018 8:18 pm

Hi Hias,

thank you for looking at the issue, appreciate it.

Sorry I was not clear enough about my intend.

I don't want to have fixed data width, I want to get rid of 24bit limit. I have a 16 bit 44Khz wav file. If I play it out using the sample overlay with the spdif-transmitter I see the 16bit frame and LJ format as needed. If I use sox to convert the sample wave file to 24bit frame I see 24bit frame with LJ format - fine. Now if I convert the sample file to 32bit frame I see that only 24bit frame is outputted. I want to have all the formats as they are without the limit to 24bit frame.

I want to use genericLJ overlay that can be added on top of existing dac overlays changing it behavior to LJ.

Given HIFI berry DAC overlay:

https://github.com/krzk/tizen-tv-rpi-li ... verlay.dts

dtoverlay=hifiberry
dtoverlay=genericLJ

Add genericLJ overlay after hifiberry in config.txt. It works now with genericLJ being your sample overlay with spdif-transmitter part but with the described 24bit frame limitation.

If this stacked overlay approach is not possible would it be enough to add:

Code: Select all

cpu_port: port {
		cpu_endpoint: endpoint {
		remote-endpoint = <&codec_endpoint>;
		dai-format = "left_j";
	};
};
to the i2s target of hifiberry-dac-overlay changing it behaviour to LJ, as the hifiberry-dac-overlay is good enough for me?

Thanks

HiassofT
Posts: 134
Joined: Fri Jun 30, 2017 10:07 pm

Re: PT8211 I2S ASOC driver

Mon Dec 03, 2018 10:13 am

If you update to kernel 4.19 the spdif transmitter codec will support 32bit as well (this was added in 4.16).

On kernel 4.14 you can use the pcm5102a codec that the hifiberry dac driver is using (it's basically a dummy codec as well that's only available in the RPi kernel and was added with the hifiberry dac driver). See the hifiberry dac overlay: https://github.com/raspberrypi/linux/bl ... ts#L15-L24

"Stacking" overlays in the way you outlined it won't work. The hifiberry dac driver is setup via it's own driver module that hardcodes I2S mode https://github.com/raspberrypi/linux/bl ... .c#L56-L57

So you have to create a separate overlay/driver, eg by using the generic audio graph card driver as you're currently doing.

so long,

Hias

xaled
Posts: 4
Joined: Sun Dec 02, 2018 11:35 am

Re: PT8211 I2S ASOC driver

Mon Dec 03, 2018 5:03 pm

Hi Hias,

thank you for the guidance. I have almost everything I need.

One more thing though:

If I have two overlays in config.txt it does not mean that they get "stacked", but only the lowest in the list gets used, right?

dtoverlay=hifiberry
dtoverlay=genericLJ

with this two lines only the genericLJ overlay gets loaded?

Thanks

HiassofT
Posts: 134
Joined: Fri Jun 30, 2017 10:07 pm

Re: PT8211 I2S ASOC driver

Mon Dec 03, 2018 11:57 pm

In your particular case the outcome was that the second dtoverlay somewhat disabled the first one.

But this is nothing you can count on, if you have conflicting overlays enabled the result isn't clear - it could also be that none of them will work. So better don't do that.

For example the hifiberry-dac overlay will load the pcm5102a driver (which is harmless), and that driver will still be present, even if you add another overlay. If that driver would grab some resources (gpio pins, ...) that your other drivers would need too you'd have a conflict.

so long,

Hias

xaled
Posts: 4
Joined: Sun Dec 02, 2018 11:35 am

Re: PT8211 I2S ASOC driver

Wed Dec 05, 2018 5:25 pm

Ok, this overlay based on hifiberry dac seems to be working:

Thanks for help!

Code: Select all

// Definitions for Generic-LJ DAC
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2708";

        [email protected] {
                target = <&sound>;
                __overlay__ {
                        compatible = "hifiberry,hifiberry-dac";
                        i2s-controller = <&i2s>;
                        dais = <&cpu_port>;
                        status = "okay";
                };
        };

        [email protected] {
                target = <&i2s>;
                __overlay__ {
                        status = "okay";

                        cpu_port: port {
                                cpu_endpoint: endpoint {
                                        remote-endpoint = <&codec_endpoint>;
                                        dai-format = "left_j";
                                };
                        };
                };
        };

        [email protected] {
                target-path = "/";
                __overlay__ {
                        pcm5102a-codec {
                                #sound-dai-cells = <0>;
                                compatible = "ti,pcm5102a";
                                status = "okay";

                                codec_port: port {
                                        codec_endpoint: endpoint {
                                                remote-endpoint = <&cpu_endpoint>;
                                        };
                                };
                        };
                };
        };
};


Return to “Interfacing (DSI, CSI, I2C, etc.)”