vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Merge 2 DTS

Wed Apr 17, 2019 5:27 pm

Hallo,

i allready tried to merge 2 DTS to have 1 DTB after compiling to get my both cards connected via GPIO to work via I2S.

Hifiberry DAC uses this DTS

Code: Select all

// Definitions for HiFiBerry DAC
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2708";

	fragment@0 {
		target = <&sound>;
		__overlay__ {
			compatible = "hifiberry,hifiberry-dac";
			i2s-controller = <&i2s>;
			status = "okay";
		};
	};

	fragment@1 {
		target = <&i2s>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@2 {
		target-path = "/";
		__overlay__ {
			pcm5102a-codec {
				#sound-dai-cells = <0>;
				compatible = "ti,pcm5102a";
				status = "okay";
			};
		};
	};
};
DABboard uses this one (first code is decompiled from audiosense-pi second is the original one from github with include)

Code: Select all

/dts-v1/;

/ {
	compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&i2s>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			codec-reg-1v8 {
				compatible = "regulator-fixed";
				regulator-name = "tlv320aic3204_1v8";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};

	fragment@2 {
		target = <&gpio>;
		__overlay__ {
			codec-rst {
				brcm,pins = <0x1a>;
				brcm,function = <0x1>;
			};
		};
	};

	fragment@3 {
		target = <&i2c1>;

		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			codec_osc {
				compatible = "fixed-clock";
				#clock-cells = <0x0>;
				clock-frequency = <0xb71b00>;
			};

			tlv320aic32x4@18 {
				#sound-dai-cells = <0x0>;
				compatible = "ti,tlv320aic32x4";
				reg = <0x18>;
				clocks = <0x1>;
				clock-names = "mclk";
				iov-supply = <&vdd_3v3_reg>;
				ldoin-supply = <&vdd_3v3_reg>;
				gpio-controller;
				#gpio-cells = <0x2>;
				reset-gpios = <&gpio 0x1a 0x0>;
				status = "okay";
			};
		};
	};

	fragment@4 {
		target = <&sound>;

		__overlay__ {
			compatible = "as,audiosense-pi";
			i2s-controller = <&i2s>;
			status = "okay";
		};
	};

	__symbols__ {
		codec_reg_1v8 = "/fragment@1/__overlay__/codec-reg-1v8";
		codec_rst = "/fragment@2/__overlay__/codec-rst";
		codec_osc = "/fragment@3/__overlay__/codec_osc";
		codec = "/fragment@3/__overlay__/tlv320aic32x4@18";
	};

	__fixups__ {
		i2s = "/fragment@0:target:0", "/fragment@4/__overlay__:i2s-controller:0";
		gpio = "/fragment@2:target:0", "/fragment@3/__overlay__/tlv320aic32x4@18:reset-gpios:0";
		i2c1 = "/fragment@3:target:0";
		vdd_3v3_reg = "/fragment@3/__overlay__/tlv320aic32x4@18:iov-supply:0", "/fragment@3/__overlay__/tlv320aic32x4@18:ldoin-supply:0";
		sound = "/fragment@4:target:0";
	};

	__local_fixups__ {

		fragment@3 {

			__overlay__ {

				tlv320aic32x4@18 {
					clocks = <0x0>;
				};
			};
		};
	};
};
i wasn't able to compile this one, although i tried to use /include/ instead of #include

Code: Select all

// Definitions for audiosense add on soundcard
/dts-v1/;
/plugin/;
#include <dt-bindings/pinctrl/bcm2835.h>
#include <dt-bindings/gpio/gpio.h>

/ {
	compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&i2s>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			codec_reg_1v8: codec-reg-1v8 {
				compatible = "regulator-fixed";
				regulator-name = "tlv320aic3204_1v8";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};

	fragment@2 {
		target = <&gpio>;
		__overlay__ {
			codec_rst: codec-rst {
				brcm,pins = <26>;
				brcm,function = <BCM2835_FSEL_GPIO_OUT>;
			};
		};
	};

	fragment@3 {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			/* audio external oscillator */
			codec_osc: codec_osc {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency = <12000000>;	/* 12 MHz */
			};

			codec: tlv320aic32x4@18 {
				#sound-dai-cells = <0>;
				compatible = "ti,tlv320aic32x4";
				reg = <0x18>;

				clocks = <&codec_osc>;
				clock-names = "mclk";

				iov-supply = <&vdd_3v3_reg>;
				ldoin-supply = <&vdd_3v3_reg>;

				gpio-controller;
				#gpio-cells = <2>;
				reset-gpios = <&gpio 26 GPIO_ACTIVE_HIGH>;

				status = "okay";
			};
		};
	};

	fragment@4 {
		target = <&sound>;
		__overlay__ {
			compatible = "as,audiosense-pi";
			i2s-controller = <&i2s>;
			status = "okay";
		};
	};
};
So my first tries managed to mkae the Hifiberry work with this merged code:

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target = <&sound>;
        __overlay__ {
            compatible = "simple-audio-card";
            simple-audio-card,name = "Dual";

            status="okay";

            capture_link: simple-audio-card,dai-link@0 {
                format = "i2s";

                r_cpu_dai: cpu {
                    sound-dai = <&i2s>;

/* example TDM slot configuration
                    dai-tdm-slot-num = <2>;
                    dai-tdm-slot-width = <32>;
*/
                };

                r_codec_dai: codec {
                    sound-dai = <&codec_in>;
                };
            };

            playback_link: simple-audio-card,dai-link@1 {
                format = "i2s";

                p_cpu_dai: cpu {
                    sound-dai = <&i2s>;

/* example TDM slot configuration
                    dai-tdm-slot-num = <2>;
                    dai-tdm-slot-width = <32>;
*/
                };

                p_codec_dai: codec {
                    sound-dai = <&codec_out>;
                };
            };
        };
    };

    fragment@1 {
        target-path = "/";
        __overlay__ {
            codec_out: spdif-transmitter {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "ti,pcm5102a";
                status = "okay";
            };
            codec_in: spdif-receiver {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "linux,spdif-dir";
                status = "okay";
            };
        };
    };

    fragment@2 {
        target = <&i2s>;
        __overlay__ {
            #sound-dai-cells = <0>;
            status = "okay";
        };
    };
};
Trying to use

Code: Select all

compatible = "ti,tlv320aic32x4"
for the DABboard in fragment@1 caused aplay -l not to find the Hifiberry anymore.

With the merged DTS i have shown, the Hifiberry worked. Sound was clear.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2478
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Merge 2 DTS

Wed Apr 17, 2019 9:21 pm

First of all, you can make it easier to compile the audiosense overlay by replacing the symbols constant macros with their real values. The decompiled version handily tells us what to substitute:

Code: Select all

// Definitions for audiosense add on soundcard
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&i2s>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			codec_reg_1v8: codec-reg-1v8 {
				compatible = "regulator-fixed";
				regulator-name = "tlv320aic3204_1v8";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};

	fragment@2 {
		target = <&gpio>;
		__overlay__ {
			codec_rst: codec-rst {
				brcm,pins = <26>;
				brcm,function = <1>; // BCM2835_FSEL_GPIO_OUT
			};
		};
	};

	fragment@3 {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			/* audio external oscillator */
			codec_osc: codec_osc {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency = <12000000>;	/* 12 MHz */
			};

			codec: tlv320aic32x4@18 {
				#sound-dai-cells = <0>;
				compatible = "ti,tlv320aic32x4";
				reg = <0x18>;

				clocks = <&codec_osc>;
				clock-names = "mclk";

				iov-supply = <&vdd_3v3_reg>;
				ldoin-supply = <&vdd_3v3_reg>;

				gpio-controller;
				#gpio-cells = <2>;
				reset-gpios = <&gpio 26 0>; // GPIO_ACTIVE_HIGH

				status = "okay";
			};
		};
	};

	fragment@4 {
		target = <&sound>;
		__overlay__ {
			compatible = "as,audiosense-pi";
			i2s-controller = <&i2s>;
			status = "okay";
		};
	};
};
Otherwise you need to run cpp on the source with the correct include paths pointing to the kernel headers, feeding the output file to dtc.

The rest is more advanced and will take a bit longer.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Thu Apr 18, 2019 10:12 am

PhilE wrote:
Wed Apr 17, 2019 9:21 pm
First of all, you can make it easier to compile the audiosense overlay by replacing the symbols constant macros with their real values. The decompiled version handily tells us what to substitute:

Code: Select all

// Definitions for audiosense add on soundcard
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&i2s>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			codec_reg_1v8: codec-reg-1v8 {
				compatible = "regulator-fixed";
				regulator-name = "tlv320aic3204_1v8";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};

	fragment@2 {
		target = <&gpio>;
		__overlay__ {
			codec_rst: codec-rst {
				brcm,pins = <26>;
				brcm,function = <1>; // BCM2835_FSEL_GPIO_OUT
			};
		};
	};

	fragment@3 {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			/* audio external oscillator */
			codec_osc: codec_osc {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency = <12000000>;	/* 12 MHz */
			};

			codec: tlv320aic32x4@18 {
				#sound-dai-cells = <0>;
				compatible = "ti,tlv320aic32x4";
				reg = <0x18>;

				clocks = <&codec_osc>;
				clock-names = "mclk";

				iov-supply = <&vdd_3v3_reg>;
				ldoin-supply = <&vdd_3v3_reg>;

				gpio-controller;
				#gpio-cells = <2>;
				reset-gpios = <&gpio 26 0>; // GPIO_ACTIVE_HIGH

				status = "okay";
			};
		};
	};

	fragment@4 {
		target = <&sound>;
		__overlay__ {
			compatible = "as,audiosense-pi";
			i2s-controller = <&i2s>;
			status = "okay";
		};
	};
};
Otherwise you need to run cpp on the source with the correct include paths pointing to the kernel headers, feeding the output file to dtc.

The rest is more advanced and will take a bit longer.
Thanks for that. Compiled it to dtbo and at least this "custom" audiosense-pi dtbo works. So with this DTS i'm also able to make the DABboard work.

I will also try to combine these working DTS to one. But as you wrote this is more advanced. So if you also try to merge them, that would be great.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Sat Apr 20, 2019 9:54 am

So I tried a while to get this done but always failed. Now I tried to build one dtb for both. Somehow i get little success but still a big problem:

mixed dts

Code: Select all

// Definitions for HiFiBerry DAC
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&i2s>;
		__overlay__ {
			status = "okay";
		};
	};
	
	fragment@1 {
		target = <&sound>;
		__overlay__ {
			compatible = "hifiberry,hifiberry-dac";
			i2s-controller = <&i2s>;
			status = "okay";
		};
	};
	
	fragment@5 {
		target = <&soc>;
		__overlay__ {
			soundinput{
				compatible = "as,audiosense-pi";
				i2s-controller = <&i2s>;
				status = "okay";
			};
		};
	};

	fragment@2 {
		target-path = "/";
		__overlay__ {
			pcm5102a-codec {
				#sound-dai-cells = <0>;
				compatible = "ti,pcm5102a";
				status = "okay";
			};
			
			codec_reg_1v8: codec-reg-1v8 {
				compatible = "regulator-fixed";
				regulator-name = "tlv320aic3204_1v8";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};
	
	fragment@3 {
		target = <&gpio>;
		__overlay__ {
			codec_rst: codec-rst {
				brcm,pins = <26>;
				brcm,function = <1>; // BCM2835_FSEL_GPIO_OUT
			};
		};
	};
	
	fragment@4 {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			/* audio external oscillator */
			codec_osc: codec_osc {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency = <12000000>;	/* 12 MHz */
			};

			codec: tlv320aic32x4@18 {
				#sound-dai-cells = <0>;
				compatible = "ti,tlv320aic32x4";
				reg = <0x18>;

				clocks = <&codec_osc>;
				clock-names = "mclk";

				iov-supply = <&vdd_3v3_reg>;
				ldoin-supply = <&vdd_3v3_reg>;

				gpio-controller;
				#gpio-cells = <2>;
				reset-gpios = <&gpio 26 0>; // GPIO_ACTIVE_HIGH

				status = "okay";
			};
		};
	};
};
error in dmesg:

Code: Select all

pi@raspberrypi:~ $ dmesg | grep hifi
[    3.656689] snd-rpi-simple soc:sound: pcm5102a-hifi <-> 3f203000.i2s mapping ok
[    3.671581] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    3.919697] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    3.935110] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.038907] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.068096] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.122563] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.208576] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.209630] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.353417] audiosense-snd-card soc:soundinput: ASoC: CODEC DAI tlv320aic32x4-hifi not registered - will retry
[    4.504262] bcm2835-i2s 3f203000.i2s: Trying to bind component to card "audiosense-pi" but is already bound to card "snd_rpi_hifiberry_dac"
both are listed:

Code: Select all

pi@raspberrypi:~ $ /sbin/lsmod | grep snd
snd_soc_tlv320aic32x4_i2c    16384  0
snd_soc_tlv320aic32x4    40960  1 snd_soc_tlv320aic32x4_i2c
snd_soc_audiosense_pi    16384  0
snd_soc_rpi_simple_soundcard    16384  2
snd_soc_bcm2835_i2s    20480  0
snd_soc_pcm5102a       16384  1
snd_soc_core          192512  6 snd_soc_audiosense_pi,vc4,snd_soc_bcm2835_i2s,snd_soc_tlv320aic32x4,snd_soc_pcm5102a,snd_soc_rpi_simple_soundcard
snd_compress           20480  1 snd_soc_core
snd_pcm_dmaengine      16384  1 snd_soc_core
snd_pcm               102400  7 snd_soc_audiosense_pi,vc4,snd_pcm_dmaengine,snd_soc_bcm2835_i2s,snd_soc_tlv320aic32x4,snd_soc_core,snd_soc_rpi_simple_soundcard
snd_timer              32768  1 snd_pcm
snd                    73728  9 snd_compress,snd_timer,snd_soc_tlv320aic32x4,snd_soc_core,snd_pcm

HiassofT
Posts: 222
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: Merge 2 DTS

Sat Apr 20, 2019 12:14 pm

In your DT overlay you are trying to load 2 sound card drivers (the Hifiberry one and the Audiosense one) which both need (exclusive access to) bcm2835-i2s - and dmesg is telling you that the second driver can't be loaded because the first one already grabbed bsm2835-i2s

Code: Select all

bcm2835-i2s 3f203000.i2s: Trying to bind component to card "audiosense-pi" but is already bound to card "snd_rpi_hifiberry_dac"
What you would need to get this working is one sound card driver that connects both codecs (pcm5102 and tlv320aic32x4) to bcm2835-i2s.

Looking at the code this is going to be rather problematic, as pcm5102 is configured as a clock slave (SND_SOC_DAIFMT_CBS_CFS) and tlv320aic32x4 as a clock master (SND_SOC_DAIFMT_CBM_CFM). If both codecs were used in slave mode (thus bcm2835-i2s driving the clock) it might have been feasible but I guess you're out of luck in this case. There may be some solution, but it certainly won't be simple.

so long,

Hias

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Sun Apr 21, 2019 9:29 am

Where is the driver located?

I only need the capture function of the dabboard. The si ic is able to do much more like line in mic in and line out but i only need the dab and fm function.

So hifiberry needs to be slave for the pi and the dabboard.

HiassofT
Posts: 222
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: Merge 2 DTS

Sun Apr 21, 2019 3:10 pm

The driver source code is here https://github.com/raspberrypi/linux/tr ... nd/soc/bcm (hifiberry-dac uses the rpi-simple-soundcard driver).

On a second thought with a Hifiberry DAC (not dacplus!) things will be a lot easier (sorry, had the dacplus in mind first). The driver is pure boilerplate code to create an audio interface (it only defines allowed sample rates and formats) and doesn't do any actual codec configuration.

So just loading the audiosense-pi overlay should work - you'll be playing sound on the audiosense card (which seems to support both playback and capture), but the hifiberry dac can just pick these up and output sound.

So, don't care about any hifiberry dac overlays / drivers at all.

so long,

Hias

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Sun Apr 21, 2019 4:07 pm

Sounds interesting but how should the hifiberry get registered by the pi when it's not activated in the config.txt?

HiassofT
Posts: 222
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: Merge 2 DTS

Sun Apr 21, 2019 4:38 pm

vitalic wrote:
Sun Apr 21, 2019 4:07 pm
Sounds interesting but how should the hifiberry get registered by the pi when it's not activated in the config.txt?
It won't be registered - you just record from and play to the audiosense pi. No need to tell the system you hooked up another card for playback in parallel :-)

so long,

Hias

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Sun Apr 21, 2019 5:16 pm

Ah, ok, so i guess you mean that the hifiberry will only listen to the I2S in stealth mode...

So i just tried to play a wav file, but can't get no sound out of the speaker connected to the hifiberry.

What is the right command to record from and to the same card ?

aplay -l

Code: Select all

pi@raspberrypi:~ $ aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: audiosensepi [audiosense-pi], Gerät 0: TLV320AIC3204 Hifi Audio tlv320aic32x4-hifi-0 []
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
arecord -l

Code: Select all

pi@raspberrypi:~ $ arecord -l
**** Liste der Hardware-Geräte (CAPTURE) ****
Karte 0: audiosensepi [audiosense-pi], Gerät 0: TLV320AIC3204 Hifi Audio tlv320aic32x4-hifi-0 []
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
  
As you can see, both got the same hw adress 0.

So i tried

Code: Select all

pi@raspberrypi:~ $ arecord -D plughw:0 -c 2 -r 48000 -f S16_LE -q | aplay -D hw:0 -c 2 -q &
[1] 1068
and if i try to play a wav on hw 0 i get the error that device is already in use.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Mon Apr 22, 2019 12:05 pm

So still playing around a little bit with merging both overlays.

This is the dts i'm testing right now based on a dual.dts with 2 cards addes to simple-audio-card:

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target = <&sound>;
        __overlay__ {
            compatible = "simple-audio-card";
            simple-audio-card,name = "Dual";
	
            status="okay";

            capture_link: simple-audio-card,dai-link@0 {
                format = "i2s";

                r_cpu_dai: cpu {
                    sound-dai = <&i2s>;

                };

                r_codec_dai: codec {
                    sound-dai = <&codec_in>;
                };
            };

            playback_link: simple-audio-card,dai-link@1 {
                format = "i2s";

                p_cpu_dai: cpu {
                    sound-dai = <&i2s>;

                };

                p_codec_dai: codec {
                    sound-dai = <&codec_out>;
                };
            };
        };
    };

    fragment@1 {
        target-path = "/";
        __overlay__ {
            codec_out: hifiberry {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "ti,pcm5102a";
		i2s-controller = <&i2s>;
                status = "okay";
            };
            codec_in: dabboard {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "as,audiosense-pi";
		i2s-controller = <&i2s>;
                status = "okay";
            };
        };
    };

    fragment@2 {
        target = <&i2s>;
        __overlay__ {
            #sound-dai-cells = <0>;
            status = "okay";
        };
    };
	
	fragment@3 {
		target-path = "/";
		__overlay__ {
			codec_reg_1v8: codec-reg-1v8 {
				compatible = "regulator-fixed";
				regulator-name = "tlv320aic3204_1v8";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};
	
	fragment@4 {
		target = <&gpio>;
		__overlay__ {
			codec_rst: codec-rst {
				brcm,pins = <26>;
				brcm,function = <1>; // BCM2835_FSEL_GPIO_OUT
			};
		};
	};
	
	fragment@5 {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			/* audio external oscillator */
			codec_osc: codec_osc {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency = <12000000>;	/* 12 MHz */
			};

			codec: tlv320aic32x4@18 {
				#sound-dai-cells = <0>;
				compatible = "ti,tlv320aic32x4";
				reg = <0x18>;

				clocks = <&codec_osc>;
				clock-names = "mclk";

				iov-supply = <&vdd_3v3_reg>;
				ldoin-supply = <&vdd_3v3_reg>;

				gpio-controller;
				#gpio-cells = <2>;
				reset-gpios = <&gpio 26 0>; // GPIO_ACTIVE_HIGH

				status = "okay";
			};
		};
	};
};

This way i get audiosense-pi to work but not the hifiberry.

Code: Select all

pi@raspberrypi:~ $ aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: audiosensepi [audiosense-pi], Gerät 0: TLV320AIC3204 Hifi Audio tlv320aic32x4-hifi-0 []
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
When i replace "as,audiosense-pi" with "linux,spdif-dir" i get this:

Code: Select all

pi@raspberrypi:~ $ aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: Dual [Dual], Gerät 0: bcm2835-i2s-pcm5102a-hifi pcm5102a-hifi-0 []
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
  
  pi@raspberrypi:~ $ arecord -l
**** Liste der Hardware-Geräte (CAPTURE) ****
Karte 0: Dual [Dual], Gerät 1: bcm2835-i2s-dir-hifi dir-hifi-1 []
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0

So there are two different devices. That's what i would expect too, if i use the first compiled dts, but somehow the audiosense-pi overwrites the hifiberry. Any ideas?

HiassofT
Posts: 222
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: Merge 2 DTS

Mon Apr 22, 2019 12:46 pm

The "arecord | aplay" command should work fine - I tested it on my Cirrus Logic Audio Card with current rpi-update kernel and it worked.

No idea what's going wrong. There might be a bug in the audiosense pi driver (or the codec) or something odd is going on with the DAB board.

Unfortunately the docs of the DAB board don't provide much hints about the hardware - the schematics only shows the Si4869 DAB chip (which, according to the datasheet supports I2S slave mode) connected to the RPi, but no signs of a TI TLV320AIC3204 chip, as required by the audiosense-pi drver. Something doesn't quite add up here...

so long,

Hias

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Mon Apr 22, 2019 12:59 pm

That's right. There is no TI TLV320AIC3204 ic soldered on the board. Just the Si4869 DAB ic. Don't know why they use the audiosense-pi overlay for this board.

I also tried to just use the hifiberry in stealth mode. That was working, but only when i wanted to hear DAB. All other sounds were not played anymore, because thi Si4869 ic is not designed to perform as output soundcard.

As long as i can't use both at the same time, this dab board is useless.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Mon Apr 22, 2019 7:17 pm

Some searches about the Si486x brought me to github https://github.com/teknoid/dabpi/blob/m ... DABP.patch, where a rpi-dabpi overlay is placed.

Therefor i need to compile a new kernel module (snd-soc-si468x).

Is there an easy way to do so? Never compiled something for the kernel before.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Tue Apr 23, 2019 11:55 am

So I managed to compile the module and it also loads:

Code: Select all

pi@raspberrypi:~ $ lsmod | grep si468x
si468x                 16384  0
snd_soc_core          188416  3 vc4,snd_soc_bcm2835_i2s,si468x
but dmesg tells me that there must be an error:

Code: Select all

pi@raspberrypi:~ $ dmesg | grep snd
[    3.528581] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.528597] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.644677] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.644709] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.645931] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.645948] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.698130] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.698149] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.722735] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.722750] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.842394] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.842418] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.972811] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.972848] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
[    3.974996] snd-rpi-dabpi soc:sound: ASoC: CODEC DAI si468x-hifi not registered - will retry
[    3.975013] snd-rpi-dabpi soc:sound: snd_soc_register_card() failed: -517
I compiled the module and named it snd-rpi-dabpi.ko according to the code in the c file. It is placed in

Code: Select all

 /lib/modules/4.14.98-v7+/kernel/sound/soc/bcm/
.

I also compiled the dts file but arecord and aplay don't show any cards.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2478
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Merge 2 DTS

Tue Apr 23, 2019 12:06 pm

A brief explanation of the messages you are seeing:

-517 is -EPROBE_DEFER, Linux's alternative to a way of defining startup dependencies. When a component's probe function requests a resource which doesn't exist (yet) it gets -EPROBE_DEFER as an error - effectively "Try again later". The kernel will then repeat the probe function after other components have been loaded in the hope that the resource may now be available. Most drivers now hide this process from the user by masking the warning message for this particular error, but that does mean that if the resource never appears then there is no clue in the kernel log as to what went wrong. Note that many drivers don't report successful loading, making it impossible to tell from the logs whether loading was eventually successful.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Tue Apr 23, 2019 3:24 pm

ok, so after rechecking the git sources i found out that i only compiled the driver but not the codec.

Code: Select all

/*
 * sound/soc/codecs/si468x.c -- Codec driver for SI468X chips
 *
 * Copyright (C) 2012 Innovative Converged Devices(ICD)
 * Copyright (C) 2013 Andrey Smirnov
 * Copyright (C) 2014 Bjoern Biesenbach
 * Copyright (C) 2016 Heiko Jehmlich
 *
 * Author: Bjoern Biesenbach <bjoern.biesenbach@gmail.com>; Heiko Jehmlich <hje@jecons.de>
 * Based on si468x.c of Andrey Smirnov <andrew.smirnov@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <linux/platform_device.h>


static int si468x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
		unsigned int fmt)
{
	return 0;
}

static int si468x_codec_hw_params(struct snd_pcm_substream *substream,
		struct snd_pcm_hw_params *params,
		struct snd_soc_dai *dai)
{
	int rate;

	rate = params_rate(params);
	if (rate != 48000) {
		dev_err(dai->codec->dev, "Rate: %d is not supported\n", rate);
		return -EINVAL;
	}
	return 0;
}

static struct snd_soc_dai_ops si468x_dai_ops = {
	.hw_params	= si468x_codec_hw_params,
	.set_fmt	= si468x_codec_set_dai_fmt,
};

static const struct snd_soc_dapm_widget si468x_dapm_widgets[] = {
	SND_SOC_DAPM_OUTPUT("LOUT"),
	SND_SOC_DAPM_OUTPUT("ROUT"),
};

static const struct snd_soc_dapm_route si468x_dapm_routes[] = {
	{ "Capture", NULL, "LOUT" },
	{ "Capture", NULL, "ROUT" },
};

static struct snd_soc_dai_driver si468x_dai = {
	.name		= "si468x-hifi",
	.capture	= {
		.stream_name	= "Capture",
		.channels_min	= 2,
		.channels_max	= 2,
		.rates 			= SNDRV_PCM_RATE_48000,
		.formats		= SNDRV_PCM_FMTBIT_S16_BE
	},
	.ops		= &si468x_dai_ops,
};

static struct snd_soc_codec_driver soc_codec_dev_si468x = {
	.dapm_widgets = si468x_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
	.dapm_routes = si468x_dapm_routes,
	.num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
};

static int si468x_probe(struct platform_device *pdev)
{
	return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_si468x, &si468x_dai, 1);
}

static int si468x_remove(struct platform_device *pdev)
{
	snd_soc_unregister_codec(&pdev->dev);
	return 0;
}

static const struct of_device_id si468x_of_match[] = {
        { .compatible = "ti,si468x", },
        { }
};
MODULE_DEVICE_TABLE(of, si468x_of_match);

static struct platform_driver si468x_platform_driver = {
	.probe		= si468x_probe,
	.remove		= si468x_remove,
	.driver		= {
		.name	= "si468x-codec",
		.owner	= THIS_MODULE,
		.of_match_table = of_match_ptr(si468x_of_match),
	},
};

module_platform_driver(si468x_platform_driver);

MODULE_AUTHOR("Bjoern Biesenbach <bjoern@bjoern-b.de>");
MODULE_DESCRIPTION("ASoC Si468X codec driver");
MODULE_LICENSE("GPL");
So now i try to compile the codec c but get build errors.

Code: Select all

pi@raspberrypi:~/module/codec $ make
make[1]: Verzeichnis „/usr/src/linux-headers-4.14.98-v7+“ wird betreten
  CC [M]  /home/pi/module/codec/snd-soc-si468x.o
/home/pi/module/codec/snd-soc-si468x.c:80:2: error: unknown field ‘dapm_widgets’ specified in initializer
  .dapm_widgets = si468x_dapm_widgets,
  ^
/home/pi/module/codec/snd-soc-si468x.c:80:18: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .dapm_widgets = si468x_dapm_widgets,
                  ^~~~~~~~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:80:18: note: (near initialization for ‘soc_codec_dev_si468x.probe’)
/home/pi/module/codec/snd-soc-si468x.c:81:2: error: unknown field ‘num_dapm_widgets’ specified in initializer
  .num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
  ^
In file included from ./include/linux/list.h:9:0,
                 from ./include/linux/module.h:9,
                 from /home/pi/module/codec/snd-soc-si468x.c:23:
./include/linux/kernel.h:71:25: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
                         ^
/home/pi/module/codec/snd-soc-si468x.c:81:22: note: in expansion of macro ‘ARRAY_SIZE’
  .num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
                      ^~~~~~~~~~
./include/linux/kernel.h:71:25: note: (near initialization for ‘soc_codec_dev_si468x.remove’)
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
                         ^
/home/pi/module/codec/snd-soc-si468x.c:81:22: note: in expansion of macro ‘ARRAY_SIZE’
  .num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
                      ^~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:82:2: error: unknown field ‘dapm_routes’ specified in initializer
  .dapm_routes = si468x_dapm_routes,
  ^
/home/pi/module/codec/snd-soc-si468x.c:82:17: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .dapm_routes = si468x_dapm_routes,
                 ^~~~~~~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:82:17: note: (near initialization for ‘soc_codec_dev_si468x.suspend’)
/home/pi/module/codec/snd-soc-si468x.c:83:2: error: unknown field ‘num_dapm_routes’ specified in initializer
  .num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
  ^
In file included from ./include/linux/list.h:9:0,
                 from ./include/linux/module.h:9,
                 from /home/pi/module/codec/snd-soc-si468x.c:23:
./include/linux/kernel.h:71:25: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
                         ^
/home/pi/module/codec/snd-soc-si468x.c:83:21: note: in expansion of macro ‘ARRAY_SIZE’
  .num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
                     ^~~~~~~~~~
./include/linux/kernel.h:71:25: note: (near initialization for ‘soc_codec_dev_si468x.resume’)
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
                         ^
/home/pi/module/codec/snd-soc-si468x.c:83:21: note: in expansion of macro ‘ARRAY_SIZE’
  .num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
                     ^~~~~~~~~~
cc1: some warnings being treated as errors
scripts/Makefile.build:332: die Regel für Ziel „/home/pi/module/codec/snd-soc-si468x.o“ scheiterte
make[2]: *** [/home/pi/module/codec/snd-soc-si468x.o] Fehler 1
Makefile:1535: die Regel für Ziel „_module_/home/pi/module/codec“ scheiterte
make[1]: *** [_module_/home/pi/module/codec] Fehler 2
make[1]: Verzeichnis „/usr/src/linux-headers-4.14.98-v7+“ wird verlassen
Makefile:9: die Regel für Ziel „modules“ scheiterte
make: *** [modules] Fehler 2
looks like the metioned errors have to be rewritten in the code. does someone know how they are replaced in kernel 4? the code was for kernel 3...

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2478
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Merge 2 DTS

Tue Apr 23, 2019 3:36 pm

Try changing line 79 to:

Code: Select all

static struct snd_soc_component_driver soc_codec_dev_si468x = {
If you get more build errors, compare the source with another codec such as https://github.com/raspberrypi/linux/bl ... adau1977.c in case the difference is obvious.

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Tue Apr 23, 2019 5:18 pm

thx, that fixed the first errors but brought some new:
/home/pi/module/codec/snd-soc-si468x.c: In function ‘si468x_probe’:
/home/pi/module/codec/snd-soc-si468x.c:88:44: error: passing argument 2 of ‘snd_soc_register_codec’ from incompatible pointer type [-Werror=incompatible-pointer-types]
return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_si468x, &si468x_dai, 1);
^
In file included from /home/pi/module/codec/snd-soc-si468x.c:27:0:
./include/sound/soc.h:467:5: note: expected ‘const struct snd_soc_codec_driver *’ but argument is of type ‘struct snd_soc_component_driver *’
int snd_soc_register_codec(struct device *dev,
^~~~~~~~~~~~~~~~~~~~~~
tried to compare with suggested example. error seems to be in &pdev->dev ?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2478
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Merge 2 DTS

Tue Apr 23, 2019 7:37 pm

Change:

Code: Select all

static struct snd_soc_codec_driver soc_codec_dev_si468x = {
	.dapm_widgets = si468x_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
	.dapm_routes = si468x_dapm_routes,
	.num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
};

static int si468x_probe(struct platform_device *pdev)
{
	return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_si468x, &si468x_dai, 1);
}

static int si468x_remove(struct platform_device *pdev)
{
	snd_soc_unregister_codec(&pdev->dev);
	return 0;
}

static const struct of_device_id si468x_of_match[] = {
        { .compatible = "ti,si468x", },
        { }
};
MODULE_DEVICE_TABLE(of, si468x_of_match);

static struct platform_driver si468x_platform_driver = {
	.probe		= si468x_probe,
	.remove		= si468x_remove,
	.driver		= {
		.name	= "si468x-codec",
		.owner	= THIS_MODULE,
		.of_match_table = of_match_ptr(si468x_of_match),
	},
};
to

Code: Select all

static struct snd_soc_component_driver soc_codec_dev_si468x = {
	.dapm_widgets = si468x_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
	.dapm_routes = si468x_dapm_routes,
	.num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
};

static int si468x_probe(struct platform_device *pdev)
{
	return devm_snd_soc_register_component(&pdev->dev,
		&soc_codec_dev_si468x, &si468x_dai, 1);
}

static const struct of_device_id si468x_of_match[] = {
        { .compatible = "ti,si468x", },
        { }
};
MODULE_DEVICE_TABLE(of, si468x_of_match);

static struct platform_driver si468x_platform_driver = {
	.driver		= {
		.name	= "si468x-codec",
		.of_match_table = of_match_ptr(si468x_of_match),
	},
	.probe		= si468x_probe,
};

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Tue Apr 23, 2019 8:21 pm

some little progress, but still no compilation:

Code: Select all

pi@raspberrypi:~/module/codec $ make
make[1]: Verzeichnis „/usr/src/linux-headers-4.14.98-v7+“ wird betreten
  CC [M]  /home/pi/module/codec/snd-soc-si468x.o
/home/pi/module/codec/snd-soc-si468x.c: In function ‘si468x_probe’:
/home/pi/module/codec/snd-soc-si468x.c:91:12: error: invalid storage class for function ‘si468x_remove’
 static int si468x_remove(struct platform_device *pdev)
            ^~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:91:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 static int si468x_remove(struct platform_device *pdev)
 ^~~~~~
/home/pi/module/codec/snd-soc-si468x.c:101:1: warning: ‘alias’ attribute ignored [-Wattributes]
 MODULE_DEVICE_TABLE(of, si468x_of_match);
 ^~~~~~~~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:105:13: error: initializer element is not constant
  .remove  = si468x_remove,
             ^~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:105:13: note: (near initialization for ‘si468x_platform_driver.remove’)
In file included from ./include/linux/pm_qos.h:10:0,
                 from ./include/sound/pcm.h:32,
                 from /home/pi/module/codec/snd-soc-si468x.c:25:
/home/pi/module/codec/snd-soc-si468x.c:113:24: error: invalid storage class for function ‘si468x_platform_driver_init’
 module_platform_driver(si468x_platform_driver);
                        ^
./include/linux/device.h:1500:19: note: in definition of macro ‘module_driver’
 static int __init __driver##_init(void) \
                   ^~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: note: in expansion of macro ‘module_platform_driver’
 module_platform_driver(si468x_platform_driver);
 ^~~~~~~~~~~~~~~~~~~~~~
In file included from /home/pi/module/codec/snd-soc-si468x.c:23:0:
./include/linux/module.h:129:42: error: invalid storage class for function ‘__inittest’
  static inline initcall_t __maybe_unused __inittest(void)  \
                                          ^
./include/linux/device.h:1504:1: note: in expansion of macro ‘module_init’
 module_init(__driver##_init); \
 ^~~~~~~~~~~
./include/linux/platform_device.h:228:2: note: in expansion of macro ‘module_driver’
  module_driver(__platform_driver, platform_driver_register, \
  ^~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: note: in expansion of macro ‘module_platform_driver’
 module_platform_driver(si468x_platform_driver);
 ^~~~~~~~~~~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: warning: ‘alias’ attribute ignored [-Wattributes]
In file included from ./include/linux/pm_qos.h:10:0,
                 from ./include/sound/pcm.h:32,
                 from /home/pi/module/codec/snd-soc-si468x.c:25:
/home/pi/module/codec/snd-soc-si468x.c:113:24: error: invalid storage class for function ‘si468x_platform_driver_exit’
 module_platform_driver(si468x_platform_driver);
                        ^
./include/linux/device.h:1505:20: note: in definition of macro ‘module_driver’
 static void __exit __driver##_exit(void) \
                    ^~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: note: in expansion of macro ‘module_platform_driver’
 module_platform_driver(si468x_platform_driver);
 ^~~~~~~~~~~~~~~~~~~~~~
./include/linux/device.h:1505:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 static void __exit __driver##_exit(void) \
 ^
./include/linux/platform_device.h:228:2: note: in expansion of macro ‘module_driver’
  module_driver(__platform_driver, platform_driver_register, \
  ^~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: note: in expansion of macro ‘module_platform_driver’
 module_platform_driver(si468x_platform_driver);
 ^~~~~~~~~~~~~~~~~~~~~~
In file included from /home/pi/module/codec/snd-soc-si468x.c:23:0:
./include/linux/module.h:135:42: error: invalid storage class for function ‘__exittest’
  static inline exitcall_t __maybe_unused __exittest(void)  \
                                          ^
./include/linux/device.h:1509:1: note: in expansion of macro ‘module_exit’
 module_exit(__driver##_exit);
 ^~~~~~~~~~~
./include/linux/platform_device.h:228:2: note: in expansion of macro ‘module_driver’
  module_driver(__platform_driver, platform_driver_register, \
  ^~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: note: in expansion of macro ‘module_platform_driver’
 module_platform_driver(si468x_platform_driver);
 ^~~~~~~~~~~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:113:1: warning: ‘alias’ attribute ignored [-Wattributes]
In file included from ./include/linux/module.h:18:0,
                 from /home/pi/module/codec/snd-soc-si468x.c:23:
./include/linux/moduleparam.h:22:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 static const char __UNIQUE_ID(name)[]       \
 ^
./include/linux/module.h:160:32: note: in expansion of macro ‘__MODULE_INFO’
 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
                                ^~~~~~~~~~~~~
./include/linux/module.h:204:32: note: in expansion of macro ‘MODULE_INFO’
 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
                                ^~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:115:1: note: in expansion of macro ‘MODULE_AUTHOR’
 MODULE_AUTHOR("Bjoern Biesenbach <bjoern@bjoern-b.de>");
 ^~~~~~~~~~~~~
/home/pi/module/codec/snd-soc-si468x.c:117:1: error: expected declaration or statement at end of input
 MODULE_LICENSE("GPL");
 ^~~~~~~~~~~~~~
At top level:
/home/pi/module/codec/snd-soc-si468x.c:86:12: warning: ‘si468x_probe’ defined but not used [-Wunused-function]
 static int si468x_probe(struct platform_device *pdev)
            ^~~~~~~~~~~~
scripts/Makefile.build:332: die Regel für Ziel „/home/pi/module/codec/snd-soc-si468x.o“ scheiterte
make[2]: *** [/home/pi/module/codec/snd-soc-si468x.o] Fehler 1
Makefile:1535: die Regel für Ziel „_module_/home/pi/module/codec“ scheiterte
make[1]: *** [_module_/home/pi/module/codec] Fehler 2
make[1]: Verzeichnis „/usr/src/linux-headers-4.14.98-v7+“ wird verlassen
Makefile:9: die Regel für Ziel „modules“ scheiterte
make: *** [modules] Fehler 2


PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2478
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Merge 2 DTS

Tue Apr 23, 2019 8:43 pm

The remove function should have been deleted. Here's the whole file:

Code: Select all

/*
 * sound/soc/codecs/si468x.c -- Codec driver for SI468X chips
 *
 * Copyright (C) 2012 Innovative Converged Devices(ICD)
 * Copyright (C) 2013 Andrey Smirnov
 * Copyright (C) 2014 Bjoern Biesenbach
 * Copyright (C) 2016 Heiko Jehmlich
 *
 * Author: Bjoern Biesenbach <bjoern.biesenbach@gmail.com>; Heiko Jehmlich <hje@jecons.de>
 * Based on si468x.c of Andrey Smirnov <andrew.smirnov@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#include <linux/module.h>
#include <linux/slab.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <linux/platform_device.h>


static int si468x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
		unsigned int fmt)
{
	return 0;
}

static int si468x_codec_hw_params(struct snd_pcm_substream *substream,
		struct snd_pcm_hw_params *params,
		struct snd_soc_dai *dai)
{
	int rate;

	rate = params_rate(params);
	if (rate != 48000) {
		dev_err(dai->component->dev, "Rate: %d is not supported\n", rate);
		return -EINVAL;
	}
	return 0;
}

static struct snd_soc_dai_ops si468x_dai_ops = {
	.hw_params	= si468x_codec_hw_params,
	.set_fmt	= si468x_codec_set_dai_fmt,
};

static const struct snd_soc_dapm_widget si468x_dapm_widgets[] = {
	SND_SOC_DAPM_OUTPUT("LOUT"),
	SND_SOC_DAPM_OUTPUT("ROUT"),
};

static const struct snd_soc_dapm_route si468x_dapm_routes[] = {
	{ "Capture", NULL, "LOUT" },
	{ "Capture", NULL, "ROUT" },
};

static struct snd_soc_dai_driver si468x_dai = {
	.name		= "si468x-hifi",
	.capture	= {
		.stream_name	= "Capture",
		.channels_min	= 2,
		.channels_max	= 2,
		.rates 			= SNDRV_PCM_RATE_48000,
		.formats		= SNDRV_PCM_FMTBIT_S16_BE
	},
	.ops		= &si468x_dai_ops,
};

static struct snd_soc_component_driver soc_codec_dev_si468x = {
	.dapm_widgets = si468x_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(si468x_dapm_widgets),
	.dapm_routes = si468x_dapm_routes,
	.num_dapm_routes = ARRAY_SIZE(si468x_dapm_routes),
};

static int si468x_probe(struct platform_device *pdev)
{
	return devm_snd_soc_register_component(&pdev->dev, &soc_codec_dev_si468x, &si468x_dai, 1);
}

static const struct of_device_id si468x_of_match[] = {
        { .compatible = "ti,si468x", },
        { }
};
MODULE_DEVICE_TABLE(of, si468x_of_match);

static struct platform_driver si468x_platform_driver = {
	.driver		= {
		.name	= "si468x-codec",
		.of_match_table = of_match_ptr(si468x_of_match),
	},
	.probe		= si468x_probe,
};

module_platform_driver(si468x_platform_driver);

MODULE_AUTHOR("Bjoern Biesenbach <bjoern@bjoern-b.de>");
MODULE_DESCRIPTION("ASoC Si468X codec driver");
MODULE_LICENSE("GPL");

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Wed Apr 24, 2019 9:29 am

First of all Thx @ PhilE for that support.

With the new code i succeded compiling the codec.

The problem right now is, to get both modules loaded (snd-soc-468x and snd-soc-rpi-dabpi). I allready wrote both to /etc/modules and copied each in the right directory ((snd-soc-468x.ko is in /lib/modules/4.14.98-v7+/kernel/sound/soc/codecs | snd-soc-rpi-dabpi.ko is in /lib/modules/4.14.98-v7+/kernel/sound/soc/bcm)

I can load each with insmod, but modprobe gives for both this error:

Code: Select all

pi@raspberrypi:/lib/modules/4.14.98-v7+/kernel/sound/soc/codecs $ sudo modprobe snd-soc-si468x
modprobe: FATAL: Module snd-soc-si468x not found in directory /lib/modules/4.14.98-v7+

pi@raspberrypi:~ $ sudo modprobe snd-soc-rpi-dabpi
modprobe: FATAL: Module snd-soc-rpi-dabpi not found in directory /lib/modules/4.14.98-v7+
I guess thats why nothing is loaded to at boot, because /etc/modules also doesn't find them

Code: Select all

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

i2c-dev

snd-soc-rpi-dabpi
snd-soc-si468x

And at last i tried depmod but this also throws an error for both th same:

Code: Select all

pi@raspberrypi:~ $ sudo depmod snd-soc-rpi-dabpi.ko
depmod: ERROR: Bad version passed snd-soc-rpi-dabpi.ko
The Makefile for each looks something like that:

Code: Select all

KERNEL_HEADERS=/lib/modules/$(shell uname -r)/build
KERNEL_MODULES=/lib/modules/$(shell uname -r)

VERBOSE=1

obj-m += snd-soc-rpi-dabpi.o

modules:
        @$(MAKE) -C $(KERNEL_HEADERS) M=$(PWD) modules

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2478
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Merge 2 DTS

Wed Apr 24, 2019 9:33 am

Did you run "sudo depmod" to update the modules aliases, etc?

vitalic
Posts: 34
Joined: Tue Sep 20, 2016 7:29 pm

Re: Merge 2 DTS

Wed Apr 24, 2019 9:40 am

No, didn't know that this has to be done. Did it on my first tries but not with the new files...

Thx man, seems to work

Code: Select all

pi@raspberrypi:~ $ arecord -l
**** Liste der Hardware-Geräte (CAPTURE) ****
Karte 1: sndrpirpidabpi [snd_rpi_rpi_dabpi], Gerät 0: DABPi Hifi si468x-codec-0 []
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
Although there is still an errormessage in DMESG

Code: Select all

[   13.988186] ASoC: si468x-codec <-> 3f203000.i2s No matching formats
[   13.997713] ASoC: si468x-codec <-> 3f203000.i2s No matching formats
[   14.007802] ASoC: si468x-codec <-> 3f203000.i2s No matching formats
But that has something to do with

Code: Select all

static struct snd_soc_dai_driver si468x_dai = {
	.name		= "si468x-hifi",
	.capture	= {
		.stream_name	= "Capture",
		.channels_min	= 2,
		.channels_max	= 2,
		.rates 			= SNDRV_PCM_RATE_48000,
		.formats		= SNDRV_PCM_FMTBIT_S16_BE
	},
	.ops		= &si468x_dai_ops,
};
So now i will try to get both loaded by the merged overlay.

Return to “Device Tree”