cm4/super6 preliminary support

This commit is contained in:
robert jakub 2024-11-24 09:29:44 +01:00
parent b4d5366d82
commit f5f8836994
3 changed files with 143 additions and 0 deletions

37
cm4/default.nix Normal file
View File

@ -0,0 +1,37 @@
{
config,
lib,
fn,
nixos-hardware,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption types;
cfg = config.hardware.cm4;
in {
options.hardware.cm4 = {
enable = mkEnableOption "custom CM4";
};
imports = [nixos-hardware.nixosModules.raspberry-pi-4] ++ (fn.scanPaths ./.);
config = mkIf cfg.enable {
hardware.raspberry-pi."4" = {
apply-overlays-dtmerge.enable = true;
xhci.enable = true;
overlays = {
audremap.enable = true;
spi-gpio40-45.enable = true;
};
};
hardware.deviceTree = {
enable = true;
filter = "*-rpi-cm4.dtb";
};
users.groups.spi = {};
services.udev.extraRules = ''
SUBSYSTEM=="spidev", KERNEL=="spidev0.0", GROUP="spi", MODE="0660"
'';
};
}

51
cm4/dtb-audremap.nix Normal file
View File

@ -0,0 +1,51 @@
{
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkIf mkMerge;
cfg = config.hardware.raspberry-pi."4".overlays;
in {
options.hardware = {
raspberry-pi."4".overlays.audremap.enable = mkEnableOption ''audremap enable '';
};
config = mkMerge [
(mkIf cfg.audremap.enable {
hardware.deviceTree.overlays = [
{
name = "audremap.overlay";
filter = "*rpi-cm4*";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
target = <&audio_pins>;
frag0: __overlay__ {
brcm,pins = <12 13>;
brcm,function = <4>; /* alt0 alt0 */
};
};
fragment@1 {
target = <&chosen>;
__overlay__ {
bootargs = "snd_bcm2835.enable_headphones=1";
};
};
__overrides__ {
swap_lr = <&frag0>, "swap_lr?";
enable_jack = <&frag0>, "enable_jack?";
pins_12_13 = <&frag0>,"brcm,pins:0=12", <&frag0>,"brcm,pins:4=13", <&frag0>,"brcm,function:0=4";
pins_18_19 = <&frag0>,"brcm,pins:0=18", <&frag0>,"brcm,pins:4=19", <&frag0>,"brcm,function:0=2";
pins_40_41 = <&frag0>,"brcm,pins:0=40", <&frag0>,"brcm,pins:4=41", <&frag0>,"brcm,function:0=4";
pins_40_45 = <&frag0>,"brcm,pins:0=40", <&frag0>,"brcm,pins:4=45", <&frag0>,"brcm,function:0=4";
};
};
'';
}
];
})
];
}

55
cm4/dtb-gpio40-45.nix Normal file
View File

@ -0,0 +1,55 @@
{
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkIf mkMerge;
cfg = config.hardware.raspberry-pi."4".overlays;
in {
options.hardware = {
raspberry-pi."4".overlays.spi-gpio40-45.enable = mkEnableOption ''spi-gpio40-45 enable '';
};
config = mkMerge [
(mkIf cfg.spi-gpio40-45.enable {
hardware.deviceTree = {
overlays = [
{
name = "spi-gpio40-45.overlay";
filter = "*rpi-cm4*";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
target = <&spi0>;
__overlay__ {
cs-gpios = <&gpio 43 1>, <&gpio 44 1>, <&gpio 45 1>;
status = "okay";
};
};
fragment@1 {
target = <&spi0_cs_pins>;
__overlay__ {
brcm,pins = <45 44 43>;
brcm,function = <1>; /* output */
status = "okay";
};
};
fragment@2 {
target = <&spi0_pins>;
__overlay__ {
brcm,pins = <40 41 42>;
brcm,function = <3>; /* alt4 */
status = "okay";
};
};
};
'';
}
];
};
})
];
}