Device tree overlays with mainline

Post Reply
brad
Posts: 1418
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 126 times
Been thanked: 206 times
Contact:

Device tree overlays with mainline

Post by brad »

Hi wondering if someone has an idea on my problem. 'Im working to produce a devicetree overlay for C4 to enable hifi shield 2 and here is the WIP example:

Code: Select all

/dts-v1/;
/plugin/;

/ {
	fragment@0 {
		// i2c2 aliased with i2c0.
		target = <&i2c2>;

		__overlay__ {
			status = "okay";

			#address-cells = <1>;
			#size-cells = <0>;

			pcm5122: pcm5122@4c {
				#sound-dai-cells = <0>;
				compatible = "ti,pcm5122";
				reg = <0x4c>;
				AVDD-supply = <&vddao_3v3>;
				DVDD-supply = <&vddao_3v3>;
				CPVDD-supply = <&vddao_3v3>;
				status = "okay";
			};
		};
	};

    	fragment@1 {
		target-path = "/sound";
        	sound_overlay: __overlay__ {
			dai-link-3 {
				sound-dai = <&tdmif_b>;
				dai-format = "i2s";
	                        dai-tdm-slot-num = <2>;
                        	dai-tdm-slot-width = <32>;
				dai-tdm-slot-tx-mask-0 = <1 1>;
                   		dai-tdm-slot-tx-mask-1 = <0 0>;
                        	dai-tdm-slot-tx-mask-2 = <0 0>;
                        	dai-tdm-slot-tx-mask-3 = <0 0>;
				mclk-fs = <128>;

				codec {
                                	sound-dai = <&pcm5122>;
                       		};
        		};
		};
    	};
	
        fragment@2 {
                // Enable tdmif_b clock pins for I2S output
                target = <&tdmif_b>;

                __overlay__ {
                       pinctrl-0 = <&mclk0_ao_pins>, <&tdm_ao_b_fs_pins>, <&tdm_ao_b_sclk_pins>,
	                    <&tdm_ao_b_dout0_pins>;

        		pinctrl-names = "default";
        		status = "okay";

        		assigned-clocks = <&clkc_audio AUD_CLKID_TDM_MCLK_PAD0>,
                          		  <&clkc_audio AUD_CLKID_TDM_SCLK_PAD1>,
                          		  <&clkc_audio AUD_CLKID_TDM_LRCLK_PAD1>;
        		assigned-clock-parents = <&clkc_audio AUD_CLKID_MST_B_MCLK>,
                                 		 <&clkc_audio AUD_CLKID_MST_B_SCLK>,
                                 		 <&clkc_audio AUD_CLKID_MST_B_LRCLK>;
        		assigned-clock-rates = <0>, <0>, <0>;

		};
        };
};

I have problems with fragment@2 where by I see a syntax error setting the clock pins

Eg: it has a problem with AUD_CLKID_TDM_MCLK_PAD0

This pin is valid and is ok if I modify the device tree itself but causes a syntax error if I add it to an overlay and try to compile:

Code: Select all

odroid@groovy-server:~/overlays/linux$ make dtbs
  DTCO    arch/arm64/boot/dts/amlogic/overlays/odroidc4/hifi2.dtbo
Error: arch/arm64/boot/dts/amlogic/overlays/odroidc4/hifi2.dts:55.42-43 syntax error
FATAL ERROR: Unable to parse input tree
make[3]: *** [scripts/Makefile.lib:358: arch/arm64/boot/dts/amlogic/overlays/odroidc4/hifi2.dtbo] Error 1
make[2]: *** [scripts/Makefile.build:496: arch/arm64/boot/dts/amlogic/overlays/odroidc4] Error 2
make[1]: *** [scripts/Makefile.build:496: arch/arm64/boot/dts/amlogic] Error 2
make: *** [Makefile:1349: dtbs] Error 2
I wonder if I need to somehow tell the dtbo to include the dtsi reference file which defined the pin or maybe tell it to ignore unknown references so they can be found at runtime?

If anyone has any ideas I would be happy to hear from you.

Thanks, Brad.

brad
Posts: 1418
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 126 times
Been thanked: 206 times
Contact:

Re: Device tree overlays with mainline

Post by brad »

I edited my example above (to fix some issues) but still the compile error.

When I manually merge the changes into device tree the hifi2 shield is working so assuming I have some formatting issue (or doing something dumb) in the overlay above.

It is essentially replacing the HDMI sound config for Hifi Shield 2. It is missing SPDIF optical output and sound channels are swapped but working nicely otherwise.

brad
Posts: 1418
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 126 times
Been thanked: 206 times
Contact:

Re: Device tree overlays with mainline

Post by brad »

Yeah i'm not sure it has done my head in today, maybe i need to have a dummy setup to define the pins in the devicetree and just use overlays to switch it.

User avatar
tobetter
Posts: 7754
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 428 times
Been thanked: 1192 times
Contact:

Re: Device tree overlays with mainline

Post by tobetter »

brad wrote:
Sun Apr 18, 2021 10:10 pm
Yeah i'm not sure it has done my head in today, maybe i need to have a dummy setup to define the pins in the devicetree and just use overlays to switch it.
By adding one line to your .dts, the compiliation error would be fixed but I guess you may need to add more header files to run.

Code: Select all

@@ -1,6 +1,8 @@
 /dts-v1/;
 /plugin/;
 
+#include <dt-bindings/clock/axg-audio-clkc.h>
+
 / {
        fragment@0 {
                // i2c2 aliased with i2c0.

brad
Posts: 1418
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 126 times
Been thanked: 206 times
Contact:

Re: Device tree overlays with mainline

Post by brad »

Thanks for the help :) I was assuming they would be included automatically which is my mistake. Let me check what else is needed.

brad
Posts: 1418
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 126 times
Been thanked: 206 times
Contact:

Re: Device tree overlays with mainline

Post by brad »

@tobetter yes now working as expected with the following (I knew I was doing something silly)

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/clock/axg-audio-clkc.h>

/ {
        fragment@0 {
                // i2c2 aliased with i2c0.
                target = <&i2c2>;

                __overlay__ {
                        status = "okay";

                        #address-cells = <1>;
                        #size-cells = <0>;

                        pcm5122: pcm5122@4c {
                                #sound-dai-cells = <0>;
                                compatible = "ti,pcm5122";
                                reg = <0x4c>;
                                AVDD-supply = <&vddao_3v3>;
                                DVDD-supply = <&vddao_3v3>;
                                CPVDD-supply = <&vddao_3v3>;
                                status = "okay";
                        };
                };
        };

        fragment@1 {
                target-path = "/sound";
                sound_overlay: __overlay__ {
                        dai-link-3 {
                                sound-dai = <&tdmif_b>;
                                dai-format = "i2s";
                                dai-tdm-slot-num = <2>;
                                dai-tdm-slot-width = <32>;
                                dai-tdm-slot-tx-mask-0 = <1 1>;
                                dai-tdm-slot-tx-mask-1 = <0 0>;
                                dai-tdm-slot-tx-mask-2 = <0 0>;
                                dai-tdm-slot-tx-mask-3 = <0 0>;
                                mclk-fs = <128>;

                                codec {
                                        sound-dai = <&pcm5122>;
                                };
                        };
                };
        };

        fragment@2 {
                target = <&tdmif_b>;

                __overlay__ {
                       pinctrl-0 = <&mclk0_ao_pins>, <&tdm_ao_b_fs_pins>, <&tdm_ao_b_sclk_pins>,
                            <&tdm_ao_b_dout0_pins>;

                        pinctrl-names = "default";
                        status = "okay";

                        assigned-clocks = <&clkc_audio AUD_CLKID_TDM_MCLK_PAD0>,
                                          <&clkc_audio AUD_CLKID_TDM_SCLK_PAD1>,
                                          <&clkc_audio AUD_CLKID_TDM_LRCLK_PAD1>;
                        assigned-clock-parents = <&clkc_audio AUD_CLKID_MST_B_MCLK>,
                                                 <&clkc_audio AUD_CLKID_MST_B_SCLK>,
                                                 <&clkc_audio AUD_CLKID_MST_B_LRCLK>;
                        assigned-clock-rates = <0>, <0>, <0>;

                };
        };
};
Some alsamixer settings might need to be changed to activate the sound by default so will try to work if anything is needed.

Need to also swap sound channels and maybe add the SPDIF output if I can work that out.

lastly will try to put it on another tdm so HDMI can be supported at the same time and maybe you could accept a patch to enable in your repository once complete.

Thanks, Brad.
These users thanked the author brad for the post:
odroid (Tue Apr 20, 2021 8:56 am)

brad
Posts: 1418
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 126 times
Been thanked: 206 times
Contact:

Re: Device tree overlays with mainline

Post by brad »

Hi tobetter,
attached is a basic patch if you are willing to test or add your repository. It will output to both HDMI and Hifi Shield 2 simultaneously but HDMI can be disabled in alsamixer

- It is only supporting the analog output at this stage as SPDIF has not been added for amlogic sm1 devices as yet to mainline
- Shared configuration with HDMI as HDMI is configured to use TDM_B and TDM_B is required for 7 pin header (my attempts to move HDMI to TDM_A not successful as yet)
- Sound channels are physically swapped on the Hifishield 2 and unable to fix via software at this stage due to being shared with HDMI output
- overlay is compatible with odroid-alsa package on Ubuntu
- Should be compatible with 5.10 / 5.11 / 5.12

The /boot/config.ini should look like this to enable the overlay

Code: Select all

[generic]
overlay_resize=16384
overlay_profile="hifishield2"
overlays="spi0 i2c0 i2c1"

[overlay_custom]
overlays="i2c0 i2c1"

[overlay_hktft32]
overlays="hktft32"

[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"

[overlay_hifishield2]
overlays="hifishield2"
On initial setup sound volume may need to be reduced in alsamixer to prevent clipping, note the digital slider control in the pic. You could try the other pcm512x dsp options to your preference
Screenshot from 2021-04-20 11-42-54.png
Screenshot from 2021-04-20 11-42-54.png (152.14 KiB) Viewed 152 times
Sound quality is excellent
Attachments
odroidc4-hifishield2-overlay.patch.txt
(2.68 KiB) Downloaded 10 times
These users thanked the author brad for the post:
odroid (Thu Apr 22, 2021 10:09 am)

User avatar
tobetter
Posts: 7754
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 428 times
Been thanked: 1192 times
Contact:

Re: Device tree overlays with mainline

Post by tobetter »

@brad, I've merged your patch and it will be published with new kernel package after fundamental testing in a couple of days. Then let's figure out how alsa can manage it.

Thanks for the patch!!

User avatar
tobetter
Posts: 7754
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 428 times
Been thanked: 1192 times
Contact:

Re: Device tree overlays with mainline

Post by tobetter »

@brad, your device tree overlay file will come with new kernel package 5.11.15.
Thanks.
These users thanked the author tobetter for the post:
brad (Wed Apr 21, 2021 11:15 pm)

Post Reply

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 1 guest