Skip to content

Commit 0db5d00

Browse files
committed
raspberry-pi-4: add gpio-fan overlay
Adds support for some PWM GPIO fans in a similar way to the official `gpio-fan` overlay. Tested with Argon Mini Fan.
1 parent c775c27 commit 0db5d00

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

raspberry-pi/4/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
./cpu-revision.nix
1515
./digi-amp-plus.nix
1616
./dwc2.nix
17+
./gpio-fan.nix
1718
./gpio.nix
1819
./i2c.nix
1920
./leds.nix

raspberry-pi/4/gpio-fan.nix

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{ config, lib, ... }:
2+
3+
let
4+
cfg = config.hardware.raspberry-pi."4".gpio-fan;
5+
in
6+
{
7+
options.hardware = {
8+
raspberry-pi."4".gpio-fan = {
9+
enable = lib.mkEnableOption "support for Raspberry Pi style gpio-fan control";
10+
11+
pin = lib.mkOption {
12+
type = lib.types.int;
13+
default = 18;
14+
description = "BCM GPIO pin used to switch the fan.";
15+
};
16+
17+
temperature = lib.mkOption {
18+
type = lib.types.int;
19+
default = 55000;
20+
description = "CPU temperature in millicelsius at which the fan turns on.";
21+
};
22+
23+
hysteresis = lib.mkOption {
24+
type = lib.types.int;
25+
default = 10000;
26+
description = "Temperature hysteresis in millicelsius before the fan turns off.";
27+
};
28+
};
29+
};
30+
31+
config = lib.mkIf cfg.enable {
32+
hardware.deviceTree.filter = "bcm2711-rpi-4*.dtb";
33+
34+
hardware.deviceTree = {
35+
overlays = [
36+
{
37+
name = "rpi4-gpio-fan";
38+
dtsText = ''
39+
/dts-v1/;
40+
/plugin/;
41+
42+
/ {
43+
compatible = "brcm,bcm2711";
44+
45+
fragment@0 {
46+
target-path = "/";
47+
__overlay__ {
48+
fan0: gpio-fan@0 {
49+
compatible = "gpio-fan";
50+
gpios = <&gpio ${toString cfg.pin} 0>;
51+
gpio-fan,speed-map = <0 0>,
52+
<5000 1>;
53+
#cooling-cells = <2>;
54+
};
55+
};
56+
};
57+
58+
fragment@1 {
59+
target = <&cpu_thermal>;
60+
__overlay__ {
61+
polling-delay = <2000>; /* milliseconds */
62+
};
63+
};
64+
65+
fragment@2 {
66+
target = <&thermal_trips>;
67+
__overlay__ {
68+
cpu_hot: trip-point@0 {
69+
temperature = <${toString cfg.temperature}>;
70+
hysteresis = <${toString cfg.hysteresis}>;
71+
type = "active";
72+
};
73+
};
74+
};
75+
76+
fragment@3 {
77+
target = <&cooling_maps>;
78+
__overlay__ {
79+
map0 {
80+
trip = <&cpu_hot>;
81+
cooling-device = <&fan0 1 1>;
82+
};
83+
};
84+
};
85+
};
86+
'';
87+
}
88+
];
89+
};
90+
};
91+
}

0 commit comments

Comments
 (0)