File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments