forked from NixOS/nixos-hardware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leds.nix
116 lines (114 loc) · 3.64 KB
/
leds.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{ config, lib, ... }:
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 = {
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.eth.disable {
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.act.disable {
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.pwr.disable {
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";
};
};
};
'';
}
];
};
})
];
}