-
Notifications
You must be signed in to change notification settings - Fork 3
/
power-button.nix
89 lines (77 loc) · 2.33 KB
/
power-button.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
{ config, lib, pkgs, ... }:
let cfg = config.hardware.argon-one.power-button;
in {
options.hardware = {
argon-one.power-button = {
enable = lib.mkEnableOption ''
Use the Argon ONE power button to shut down the machine
'';
};
};
config = lib.mkIf cfg.enable {
# Add a script to make the case power board turn off the power once
# the Pi has shut down
systemd.services.argonone-power-off = {
wantedBy = [ "poweroff.target" ];
after = [ "systemd-poweroff.service" ];
script = "${pkgs.i2c-tools}/bin/i2cset -y 1 0x01a 0xff";
unitConfig = { DefaultDependencies = "no"; };
serviceConfig = {
Type = "oneshot";
User = "root";
Group = "i2c";
TimeoutStartSec = "0";
};
};
# Add the device tree overlay to expose the power button for the gpio-keys module
hardware.deviceTree = {
overlays = [{
name = "power-button";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "raspberrypi,4-model-b";
fragment@0 {
// Configure the gpio pin controller
target = <&gpio>;
__overlay__ {
pin_state: button_pins@0 {
brcm,pins = <4>; // gpio number
brcm,function = <0>; // 0 = input, 1 = output
brcm,pull = <1>; // 0 = none, 1 = pull down, 2 = pull up
};
};
};
fragment@1 {
target-path = "/";
__overlay__ {
button: button@0 {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&pin_state>;
status = "okay";
key: key {
linux,code = <116>;
gpios = <&gpio 4 1>;
label = "KEY_POWER";
};
};
};
};
__overrides__ {
gpio = <&key>,"gpios:4",
<&button>,"reg:0",
<&pin_state>,"brcm,pins:0",
<&pin_state>,"reg:0";
label = <&key>,"label";
keycode = <&key>,"linux,code:0";
gpio_pull = <&pin_state>,"brcm,pull:0";
active_high = <&key>,"gpios:4";
};
};
'';
}];
};
};
}