Audio Support Rock Pi S

Hi everybody,
I don’t know if this post could help someone out.
Here is how you can set up the I2S and PDM lines of the board so that you can use MEMs digital microphones, either by using I2S or PDM interface.

First of all, I installed on the SD card Radxa official ROM Ubuntu bionic (released on 19 Dec 2019).
Then I did updates and installed required packages for audio and set up

For updates
sudo apt-get update
sudo apt-get upgrade

For audio recording (I use SoX Ubuntu package)
sudo apt-get install libasound2 alsa-utils alsa-oss
sudo apt-get install sox -y

Then, in order to set up I2S/PDM pins on the board, you need to modify the device tree and recompile it. So you need to install the device tree compiler.

sudo apt-get install device-tree-compiler

Then go to /boot/dtbs/your_kernel_version/rockchip and decompile the device tree being used by the bootloader, that is rockpi-s-linux.dtb. To do so, you have to run

dtc -I dtb -O dts -f rockpi-s-linux.dtb -o rockpi-s-linux.dts

Once you have the dts file, open it and go to acodec-sound part

acodec-sound {
	compatible = "rockchip,multicodecs-card";
	rockchip,card-name = "rockchip,rk3308-acodec";
	rockchip,codec-hp-det;
	rockchip,mclk-fs = <0x100>;
	rockchip,cpu = <0xc3>;
	rockchip,codec = <0x8b>;
	phandle = <0x13d>;
};

You will have to change the cpu field. If you want to use up to 8 I2S microphones, you will have to change the value to <0xbe>, which is the phandle of the I2S0 controller (which is exposed on the pinouts layout). Remember you also need to enable the I2S0 interface, so go to i2s@ff300000 and change the status to “okay”.

i2s@ff300000 {
	compatible = "rockchip,rk3308-i2s-tdm";
	reg = <0x0 0xff300000 0x0 0x1000>;
	interrupts = <0x0 0x30 0x4>;
	clocks = <0x2 0x4c 0x2 0x4e 0x2 0xa4 0x2 0x6e 0x2 0x6f 0x2 0x3 0x2 0x4>;
	clock-names = "mclk_tx", "mclk_rx", "hclk", "mclk_tx_src", "mclk_rx_src", "mclk_root0", "mclk_root1";
	dmas = <0x25 0x0 0x25 0x1>;
	dma-names = "tx", "rx";
	resets = <0x2 0x89 0x2 0x8a>;
	reset-names = "tx-m", "rx-m";
	rockchip,cru = <0x2>;
	rockchip,grf = <0x4b>;
	rockchip,mclk-calibrate;
	pinctrl-names = "default";
	pinctrl-0 = <0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a>;
	status = "okay";
	phandle = <0xbe>;
};

Once you have done all the changes, re-compile the dts file to get the binary format (dtb).

sudo dtc -I dts -O dtb -f rockpi-s-linux.dts -o rockpi-s-linux.dtb

Then reboot and enjoy!

In case you want to use PDM interface, just change the cpu field in the acodec-sound to <0xc3>, which is the phandle of the PDM controller. Then remember to enable the interface by changing its status to “okay”.

pdm@ff380000 {
	compatible = "rockchip,rk3308-pdm", "rockchip,pdm";
	reg = <0x0 0xff380000 0x0 0x1000>;
	clocks = <0x2 0x4b 0x2 0xa1>;
	clock-names = "pdm_clk", "pdm_hclk";
	dmas = <0x25 0xc>;
	dma-names = "rx";
	resets = <0x2 0x83>;
	reset-names = "pdm-m";
	pinctrl-names = "default";
	pinctrl-0 = <0x5f 0x60 0x61 0x62 0x63>;
	status = "okay";
	phandle = <0xc3>;
};
5 Likes