2023-10-25 14:51:48 +02:00
{ config , lib , . . . }:
let
cfg = config . hardware . raspberry-pi . " 4 " . digi-amp-plus ;
in
{
options . hardware = {
raspberry-pi . " 4 " . digi-amp-plus = {
enable = lib . mkEnableOption ''
support for the IQaudIO DigiAMP + Hat .
'' ;
unmuteAmp = lib . mkOption {
type = lib . types . bool ;
default = false ;
2024-07-29 23:37:28 +02:00
description = ''
2023-10-25 14:51:48 +02:00
" o n e - s h o t " unmute when kernel module first loads .
'' ;
} ;
autoMuteAmp = lib . mkOption {
type = lib . types . bool ;
default = true ;
2024-07-29 23:37:28 +02:00
description = ''
2023-10-25 14:51:48 +02:00
Unmute the amp when an ALSA device is opened by a client . Mute , with a five-second delay when the ALSA device is closed .
( Reopening the device within the five-second close window will cancel mute . )
'' ;
} ;
} ;
} ;
config = lib . mkIf cfg . enable {
hardware . raspberry-pi . " 4 " . apply-overlays-dtmerge . enable = lib . mkDefault true ;
hardware . deviceTree = {
overlays = [
# Adapted from to: https://github.com/raspberrypi/linux/blob/3ed6d34d53e94ecbebc64c8fa3d1b6d3c41db8fb/arch/arm/boot/dts/overlays/iqaudio-dacplus-overlay.dts
# changes:
# - modified top-level "compatible" field from bcm2835 to bcm2711
# - s/i2s_clk_producer/i2s/ (name on bcm2711 platform)
{
name = " i q a u d i o - d i g i a m p p l u s - o v e r l a y " ;
dtsText = ''
/dts-v1 / ;
/plugin / ;
/ {
compatible = " b r c m , b c m 2 7 1 1 " ;
fragment @ 0 {
target = < & i2s > ;
__overlay__ {
status = " o k a y " ;
} ;
} ;
fragment @ 1 {
target = < & i2c1 > ;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = " o k a y " ;
pcm5122 @ 4 c {
#sound-dai-cells = <0>;
compatible = " t i , p c m 5 1 2 2 " ;
reg = <0x4c> ;
AVDD-supply = < & vdd_3v3_reg > ;
DVDD-supply = < & vdd_3v3_reg > ;
CPVDD-supply = < & vdd_3v3_reg > ;
status = " o k a y " ;
} ;
} ;
} ;
fragment @ 2 {
target = < & sound > ;
iqaudio_dac : __overlay__ {
compatible = " i q a u d i o , i q a u d i o - d a c " ;
i2s-controller = < & i2s > ;
mute-gpios = < & gpio 22 0 > ;
status = " o k a y " ;
$ { lib . optionalString cfg . unmuteAmp " i q a u d i o - d a c , u n m u t e - a m p ; " }
$ { lib . optionalString cfg . autoMuteAmp " i q a u d i o - d a c , a u t o - m u t e - a m p ; " }
} ;
} ;
} ;
'' ;
}
] ;
} ;
} ;
}