Skip to content

Instantly share code, notes, and snippets.

@drahnreb
Created July 27, 2025 22:40
Show Gist options
  • Select an option

  • Save drahnreb/8403466d4884b50ff6d9c1f181741ff7 to your computer and use it in GitHub Desktop.

Select an option

Save drahnreb/8403466d4884b50ff6d9c1f181741ff7 to your computer and use it in GitHub Desktop.
Audio Amp SHIM (3W Mono Amp) by Pimoroni dts for Radxa Zero3W
/dts-v1/;
/plugin/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
/ {
// This metadata is for tools like dietpi-config
metadata {
title = "Enable Pimoroni Audio Amp SHIM on I2S3-M0";
compatible = "radxa,zero3"; // Specifically for Radxa Zero 3
category = "audio";
exclusive = "GPIO3_A4", "GPIO3_A5", "GPIO3_A6", "i2s3_2ch"; // Pins 12, 35, 40
description = "Enables the Pimoroni Audio Amp SHIM on the I2S3 interface.";
};
};
// This fragment adds nodes to the root of the device tree
&{/} {
// 1. Define the Codec.
// We are now using the compatible string for the actual chip on the board,
// as we have manually compiled and installed its driver.
max98357a_codec: max98357a-codec {
compatible = "maxim,max98357a";
#sound-dai-cells = <0>;
status = "okay";
};
// 2. Define the Sound Card, linking the CPU's I2S to the Codec
pimoroni_shim_sound: pimoroni-shim-sound {
compatible = "simple-audio-card";
simple-audio-card,name = "Pimoroni-Amp-SHIM"; // This name will appear in ALSA
simple-audio-card,format = "i2s";
// Add address and size cells to define the format for the 'reg' property
#address-cells = <1>;
#size-cells = <0>;
// This defines the link between the board and the DAC
simple-audio-card,dai-link@0 {
reg = <0>;
format = "i2s";
// FINAL FIX: Explicitly define the link as mono (1 channel)
// to match the MAX98357A hardware and driver.
channels = <1>;
// CPU side of the link
cpu {
sound-dai = <&i2s3_2ch>; // Using the Zero 3's I2S3 interface
};
// Codec side of the link
codec {
sound-dai = <&max98357a_codec>; // Linking to our MAX98357A codec above
};
};
};
};
// 3. Enable the I2S3 controller and assign the correct pins used by the SHIM
&i2s3_2ch {
pinctrl-0 = <&i2s3m0_sclk // Pin 12 (BCK)
&i2s3m0_lrck // Pin 35 (LRCK)
&i2s3m0_sdo>; // Pin 40 (DIN)
status = "okay";
};
// 4. Disable any conflicting interfaces.
// The I2S3 pins are multiplexed with I2C3. We must disable I2C3
// to prevent resource conflicts.
&i2c3 {
status = "disabled";
};
// 5. Disable the built-in HDMI audio to prevent resource conflicts.
// The node is called "hdmi-sound" and its label is "hdmi_sound".
&hdmi_sound {
status = "disabled";
};
@drahnreb

Copy link
Copy Markdown
Author
sudo apt install -y device-tree-compiler build-essential

mkdir -p /boot/overlay-user/dt-bindings/pinctrl
mkdir -p /boot/overlay-user/dt-bindings/gpio

wget -O /boot/overlay-user/dt-bindings/pinctrl/rockchip.h https://raw.githubusercontent.com/radxa/kernel/linux-6.1-stan-rkr5.1/include/dt-bindings/pinctrl/rockchip.h
wget -O /boot/overlay-user/dt-bindings/gpio/gpio.h https://raw.githubusercontent.com/radxa/kernel/linux-6.1-stan-rkr5.1/include/dt-bindings/gpio/gpio.h

cpp -nostdinc -undef -x assembler-with-cpp -E -I . /boot/overlay-user/pimoroni-dac.dts | dtc -@ -I dts -O dtb -o /boot/overlay-user/pimoroni-dac.dtbo -

in /boot/dietpiEnv.txt:
user_overlays=pimoroni-dac

then:
sudo reboot

@drahnreb

drahnreb commented Jul 27, 2025

Copy link
Copy Markdown
Author

before loading the device tree overlay, prepare the codec driver

wget https://mirrors.dotsrc.org/armbian-apt/pool/main/l/linux-headers-vendor-rk35xx/linux-headers-vendor-rk35xx_25.5.1_arm64__6.1.115-S5271-Dca91-P09c0-C26e6H2313-HK01ba-Vc222-Ba566-R448a.deb
sudo dpkg -i linux-headers-vendor-rk35xx_25.5.1_arm64__6.1.115-S5271-Dca91-P09c0-C26e6H2313-HK01ba-Vc222-Ba566-R448a.deb
sudo apt-get -f install

ls /lib/modules/$(uname -r)/build

mkdir -p ~/driver_build
cd ~/driver_build

wget https://raw.githubusercontent.com/torvalds/linux/v6.1/sound/soc/codecs/max98357a.c
nano Makefile

add this:

obj-m += snd-soc-max98357a.o
snd-soc-max98357a-objs := max98357a.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

then:

make
sudo cp snd-soc-max98357a.ko /lib/modules/$(uname -r)/kernel/sound/soc/codecs/

sudo depmod -a
sudo modprobe snd-soc-max98357a

verify:

lsmod | grep max98357a

zcat /proc/config.gz | grep MAX98357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment