From 9d09a7452ccf99f2ddfca1a349758312cc5d569c Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 14 Nov 2023 20:47:59 +0100 Subject: [PATCH 1/3] raspberry-pi/4: format --- raspberry-pi/4/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix index 5645d47..1c55265 100644 --- a/raspberry-pi/4/default.nix +++ b/raspberry-pi/4/default.nix @@ -5,17 +5,17 @@ ./audio.nix ./backlight.nix ./cpu-revision.nix + ./digi-amp-plus.nix ./dwc2.nix ./i2c.nix ./modesetting.nix + ./pkgs-overlays.nix ./poe-hat.nix ./poe-plus-hat.nix + ./pwm0.nix ./tc358743.nix ./touch-ft5406.nix - ./pwm0.nix - ./pkgs-overlays.nix ./xhci.nix - ./digi-amp-plus.nix ]; boot = { @@ -24,7 +24,7 @@ "usbhid" "usb_storage" "vc4" - "pcie_brcmstb" # required for the pcie bus to work + "pcie_brcmstb" # required for the pcie bus to work "reset-raspberrypi" # required for vl805 firmware to load ]; From a742fe3a04105756d6a700ef1e885b326b7e57cd Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 14 Nov 2023 20:48:59 +0100 Subject: [PATCH 2/3] raspberry-pi/4: add led disable overlay --- raspberry-pi/4/default.nix | 1 + raspberry-pi/4/leds.nix | 116 +++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 raspberry-pi/4/leds.nix diff --git a/raspberry-pi/4/default.nix b/raspberry-pi/4/default.nix index 1c55265..41d065a 100644 --- a/raspberry-pi/4/default.nix +++ b/raspberry-pi/4/default.nix @@ -8,6 +8,7 @@ ./digi-amp-plus.nix ./dwc2.nix ./i2c.nix + ./leds.nix ./modesetting.nix ./pkgs-overlays.nix ./poe-hat.nix diff --git a/raspberry-pi/4/leds.nix b/raspberry-pi/4/leds.nix new file mode 100644 index 0000000..1f2404d --- /dev/null +++ b/raspberry-pi/4/leds.nix @@ -0,0 +1,116 @@ +{ config, lib, ... }: + +let + cfg = config.hardware.raspberry-pi."4".leds; +in +{ + options.hardware = { + raspberry-pi."4".leds = { + disable-eth = lib.mkEnableOption '' + disable ethernet LEDs. + ''; + disable-act = lib.mkEnableOption '' + disable activity LED. + ''; + disable-pwr = lib.mkEnableOption '' + disable power LED. + ''; + }; + }; + + # Adapted from: https://gist.github.com/SFrijters/206d2c09656affb04284f076c75a1969 + config = lib.mkMerge [ + (lib.mkIf cfg.disable-eth { + hardware.deviceTree = { + overlays = [ + # https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README + # eth_led0 Set mode of LED0 - amber on Pi3B+ (default "1"), + # green on Pi4 (default "0"). + # The legal values are: + # + # Pi4 + # + # 0=Speed/Activity 1=Speed + # 2=Flash activity 3=FDX + # 4=Off 5=On + # 6=Alt 7=Speed/Flash + # 8=Link 9=Activity + # + # Debugging: + # $ hexdump /proc/device-tree/scb/ethernet@7d580000/mdio@e14/ethernet-phy@1/led-modes + { + name = "disable-eth-leds"; + filter = "*rpi-4-b*"; + dtsText = '' + /dts-v1/; + /plugin/; + /{ + compatible = "raspberrypi,4-model-b"; + fragment@0 { + target = <&phy1>; + __overlay__ { + led-modes = <0x04 0x04>; + }; + }; + }; + ''; + } + ]; + }; + }) + (lib.mkIf cfg.disable-act { + hardware.deviceTree = { + overlays = [ + # Debugging: + # $ hexdump /proc/device-tree/leds/led-act/gpios + # $ cat /proc/device-tree/leds/led-act/linux,default-trigger + { + name = "disable-act-led"; + filter = "*rpi-4-b*"; + dtsText = '' + /dts-v1/; + /plugin/; + /{ + compatible = "raspberrypi,4-model-b"; + fragment@0 { + target = <&act_led>; + __overlay__ { + gpios = <&gpio 42 0>; /* first two values copied from bcm2711-rpi-4-b.dts */ + linux,default-trigger = "none"; + }; + }; + }; + ''; + } + ]; + }; + }) + (lib.mkIf cfg.disable-pwr { + hardware.deviceTree = { + overlays = [ + # Debugging: + # $ hexdump /proc/device-tree/leds/led-pwr/gpios + # $ cat /proc/device-tree/leds/led-pwr/linux,default-trigger + { + name = "disable-pwr-led"; + filter = "*rpi-4-b*"; + dtsText = '' + /dts-v1/; + /plugin/; + /{ + compatible = "raspberrypi,4-model-b"; + fragment@0 { + target = <&pwr_led>; + __overlay__ { + gpios = <&expgpio 2 0>; /* first two values copied from bcm2711-rpi-4-b.dts */ + linux,default-trigger = "default-on"; + }; + }; + }; + ''; + } + ]; + }; + }) + ]; +} From 89e68213709d78509994178dc3e56643cc2af629 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sat, 18 Nov 2023 15:44:43 +0100 Subject: [PATCH 3/3] add and use mkDisableOption --- raspberry-pi/4/leds.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/raspberry-pi/4/leds.nix b/raspberry-pi/4/leds.nix index 1f2404d..95a6d05 100644 --- a/raspberry-pi/4/leds.nix +++ b/raspberry-pi/4/leds.nix @@ -2,25 +2,25 @@ let cfg = config.hardware.raspberry-pi."4".leds; + mkDisableOption = name: lib.mkOption { + default = false; + example = true; + description = "Whether to disable ${name}."; + type = lib.types.bool; + }; in { options.hardware = { raspberry-pi."4".leds = { - disable-eth = lib.mkEnableOption '' - disable ethernet LEDs. - ''; - disable-act = lib.mkEnableOption '' - disable activity LED. - ''; - disable-pwr = lib.mkEnableOption '' - disable power LED. - ''; + eth.disable = mkDisableOption ''ethernet LEDs.''; + act.disable = mkDisableOption ''activity LED.''; + pwr.disable = mkDisableOption ''power LED.''; }; }; # Adapted from: https://gist.github.com/SFrijters/206d2c09656affb04284f076c75a1969 config = lib.mkMerge [ - (lib.mkIf cfg.disable-eth { + (lib.mkIf cfg.eth.disable { hardware.deviceTree = { overlays = [ # https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README @@ -58,7 +58,7 @@ in ]; }; }) - (lib.mkIf cfg.disable-act { + (lib.mkIf cfg.act.disable { hardware.deviceTree = { overlays = [ # Debugging: @@ -85,7 +85,7 @@ in ]; }; }) - (lib.mkIf cfg.disable-pwr { + (lib.mkIf cfg.pwr.disable { hardware.deviceTree = { overlays = [ # Debugging: