Skip to content

Commit 2b80dc8

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 2b80dc8

2 files changed

Lines changed: 90 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: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 = {
33+
overlays = [
34+
{
35+
name = "rpi4-gpio-fan";
36+
dtsText = ''
37+
/dts-v1/;
38+
/plugin/;
39+
40+
/ {
41+
compatible = "brcm,bcm2711";
42+
43+
fragment@0 {
44+
target-path = "/";
45+
__overlay__ {
46+
fan0: gpio-fan@0 {
47+
compatible = "gpio-fan";
48+
gpios = <&gpio ${toString cfg.pin} 0>;
49+
gpio-fan,speed-map = <0 0>,
50+
<5000 1>;
51+
#cooling-cells = <2>;
52+
};
53+
};
54+
};
55+
56+
fragment@1 {
57+
target = <&cpu_thermal>;
58+
__overlay__ {
59+
polling-delay = <2000>; /* milliseconds */
60+
};
61+
};
62+
63+
fragment@2 {
64+
target = <&thermal_trips>;
65+
__overlay__ {
66+
cpu_hot: trip-point@0 {
67+
temperature = <${toString cfg.temperature}>;
68+
hysteresis = <${toString cfg.hysteresis}>;
69+
type = "active";
70+
};
71+
};
72+
};
73+
74+
fragment@3 {
75+
target = <&cooling_maps>;
76+
__overlay__ {
77+
map0 {
78+
trip = <&cpu_hot>;
79+
cooling-device = <&fan0 1 1>;
80+
};
81+
};
82+
};
83+
};
84+
'';
85+
}
86+
];
87+
};
88+
};
89+
}

0 commit comments

Comments
 (0)