Skip to content

Commit 7cfa16c

Browse files
herbingkpelwell
authored andcommitted
Add and update files for pwm-gpio-fan overlay
Add and update files for pwm-gpio-fan overlay Signed-off-by: Kai-Uwe Herbing <[email protected]>
1 parent 19c885c commit 7cfa16c

File tree

3 files changed

+211
-0
lines changed

3 files changed

+211
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
221221
pwm.dtbo \
222222
pwm-2chan.dtbo \
223223
pwm-gpio.dtbo \
224+
pwm-gpio-fan.dtbo \
224225
pwm-ir-tx.dtbo \
225226
pwm-pio.dtbo \
226227
pwm1.dtbo \

arch/arm/boot/dts/overlays/README

+40
Original file line numberDiff line numberDiff line change
@@ -4076,6 +4076,46 @@ Load: dtoverlay=pwm-gpio,<param>=<val>
40764076
Params: gpio Output pin (default 4)
40774077

40784078

4079+
Name: pwm-gpio-fan
4080+
Info: Configure a GPIO connected PWM cooling fan controlled by the
4081+
software-based GPIO PWM kernel module
4082+
Load: dtoverlay=pwm-gpio-fan,<param>=<val>
4083+
Params: fan_gpio BCM number of the pin driving the fan,
4084+
default 18 (GPIO 18)
4085+
fan_temp0 CPU temperature at which fan is started with
4086+
low speed in millicelsius,
4087+
default 55000 (55 °C)
4088+
fan_temp1 CPU temperature at which fan is switched
4089+
to medium speed in millicelsius,
4090+
default 60000 (60 °C)
4091+
fan_temp2 CPU temperature at which fan is switched
4092+
to high speed in millicelsius,
4093+
default 67500 (67.5 °C)
4094+
fan_temp3 CPU temperature at which fan is switched
4095+
to max speed in millicelsius,
4096+
default 75000 (75 °C)
4097+
fan_temp0_hyst Temperature hysteris at which fan is stopped
4098+
in millicelsius,default 5000 (resulting
4099+
in 50 °C)
4100+
fan_temp1_hyst Temperature hysteris at which fan is switched
4101+
back to low speed in millicelsius,
4102+
default 5000 (resulting in 55 °C)
4103+
fan_temp2_hyst Temperature hysteris at which fan is switched
4104+
back to medium speed in millicelsius,
4105+
default 5000 (resulting in 62.5 °C)
4106+
fan_temp3_hyst Temperature hysteris at which fan is switched
4107+
back to high speed in millicelsius,
4108+
default 5000 (resulting in 70 °C)
4109+
fan_temp0_speed Fan speed for low cooling state in range
4110+
0 to 255, default 114 (45% PWM duty cycle)
4111+
fan_temp1_speed Fan speed for medium cooling state in range
4112+
0 to 255, default 152 (60% PWM duty cycle)
4113+
fan_temp2_speed Fan speed for high cooling state in range
4114+
0 to 255, default 204 (80% PWM duty cycle)
4115+
fan_temp3_speed Fan speed for max cooling state in range
4116+
0 to 255, default 255 (100% PWM duty cycle)
4117+
4118+
40794119
Name: pwm-ir-tx
40804120
Info: Use GPIO pin as pwm-assisted infrared transmitter output.
40814121
This is an alternative to "gpio-ir-tx". pwm-ir-tx makes use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* Overlay for a GPIO connected PWM cooling fan controlled by software GPIO PWM
3+
*
4+
* Optional parameters:
5+
* - "fan_gpio" BCM number of the pin driving the fan, default 18 (GPIO18)
6+
*
7+
* - "fan_temp0" CPU temperature at which fan is started with low speed in millicelsius,
8+
* default 55000 (55 °C)
9+
* - "fan_temp1" CPU temperature at which fan is switched to medium speed in millicelsius,
10+
* default 60000 (60 °C)
11+
* - "fan_temp2" CPU temperature at which fan is switched to high speed in millicelsius,
12+
* default 67500 (67.5 °C)
13+
* - "fan_temp3" CPU temperature at which fan is switched to max speed in millicelsius,
14+
* default 75000 (75 °C)
15+
* - "fan_temp0_hyst" Temperature hysteris at which fan is stopped in millicelsius,
16+
* default 5000 (resulting in 50 °C)
17+
* - "fan_temp1_hyst" Temperature hysteris at which fan is switched back to low speed
18+
* in millicelsius, default 5000 (resulting in 55 °C)
19+
* - "fan_temp2_hyst" Temperature hysteris at which fan is switched back to medium speed
20+
* in millicelsius, default 5000 (resulting in 62.5 °C)
21+
* - "fan_temp3_hyst" Temperature hysteris at which fan is switched back to high speed
22+
* in millicelsius, default 5000 (resulting in 70 °C)
23+
* - "fan_temp0_speed" Fan speed for low cooling state in range 0 to 255,
24+
* default 114 (45% PWM duty cycle)
25+
* - "fan_temp1_speed" Fan speed for medium cooling state in range 0 to 255,
26+
* default 152 (60% PWM duty cycle)
27+
* - "fan_temp2_speed" Fan speed for high cooling state in range 0 to 255,
28+
* default 204 (80% PWM duty cycle)
29+
* - "fan_temp3_speed" Fan speed for max cooling state in range 0 to 255,
30+
* default 255 (100% PWM duty cycle)
31+
*
32+
* N.B.
33+
* - Uses the software GPIO PWM kernel module instead of the Pis hardware PWMs (PWM0/PWM1).
34+
* This will allow for an undisturbed concurrent usage of the Pis analogue audio output.
35+
*
36+
* Requires:
37+
* - A PWM controlled cooling fan connected to the GPIO, such as an
38+
* Argon mini-fan, HighPi Pro Fan or Waveshare FAN-4020-PWM-5V
39+
* - Raspberry Pi OS Bookworm with kernel 6.6.62 or above
40+
*
41+
* Build:
42+
* - sudo dtc -I dts -O dtb -o /boot/firmware/overlays/pwm-gpiofan.dtbo pwm-gpiofan-overlay.dts
43+
*
44+
* Activate:
45+
* - sudo nano /boot/firmware/config.txt add "dtoverlay=pwm-gpiofan"
46+
*
47+
*/
48+
/dts-v1/;
49+
/plugin/;
50+
51+
/ {
52+
compatible = "brcm,bcm2835";
53+
54+
fragment@0 {
55+
target = <&gpio>;
56+
__overlay__ {
57+
pwm_gpio_pins: pwm_gpio_pins {
58+
brcm,pins = <18>; /* gpio-pin = 18 */
59+
brcm,function = <1>; /* gpio function = output */
60+
brcm,pull = <0>; /* gpio pull up/down = off */
61+
};
62+
};
63+
};
64+
65+
fragment@1 {
66+
target-path = "/";
67+
__overlay__ {
68+
pwm_gpio: pwm_gpio {
69+
compatible="pwm-gpio";
70+
#pwm-cells = <2>;
71+
pinctrl-names = "default";
72+
pinctrl-0 = <&pwm_gpio_pins>;
73+
gpios = <&gpio 18 0>; /* gpio-pin = 18 */
74+
};
75+
};
76+
};
77+
78+
fragment@2 {
79+
target-path = "/";
80+
__overlay__ {
81+
fan0: pwm-fan {
82+
compatible = "pwm-fan";
83+
#cooling-cells = <2>;
84+
/* in ns = 20ms = 50 Hz */
85+
pwms = <&pwm_gpio 0 20000000 0>;
86+
87+
cooling-min-state = <0>;
88+
cooling-max-state = <4>;
89+
/* PWM duty cycle values in a range from 0 to 255 */
90+
/* which correspond to thermal cooling states 0 to 4 */
91+
cooling-levels = <0 114 152 204 255>;
92+
};
93+
};
94+
};
95+
96+
fragment@3 {
97+
target = <&cpu_thermal>;
98+
__overlay__ {
99+
/* in ms = poll every 2s */
100+
polling-delay = <2000>;
101+
};
102+
};
103+
104+
fragment@4 {
105+
target = <&thermal_trips>;
106+
__overlay__ {
107+
/* below temperatures in millicelsius */
108+
trip0: trip0 {
109+
temperature = <55000>; /* 55 °C */
110+
hysteresis = <5000>; /* 5 °C */
111+
type = "active";
112+
};
113+
trip1: trip1 {
114+
temperature = <60000>; /* 60 °C */
115+
hysteresis = <5000>; /* 5 °C */
116+
type = "active";
117+
};
118+
trip2: trip2 {
119+
temperature = <67500>; /* 67.5 °C */
120+
hysteresis = <5000>; /* 5 °C */
121+
type = "active";
122+
};
123+
trip3: trip3 {
124+
temperature = <75000>; /* 75 °C */
125+
hysteresis = <5000>; /* 5 °C */
126+
type = "active";
127+
};
128+
};
129+
};
130+
131+
fragment@5 {
132+
target = <&cooling_maps>;
133+
__overlay__ {
134+
map0 {
135+
cooling-device = <&fan0 0 1>;
136+
trip = <&trip0>;
137+
};
138+
map1 {
139+
cooling-device = <&fan0 1 2>;
140+
trip = <&trip1>;
141+
};
142+
map2 {
143+
cooling-device = <&fan0 2 3>;
144+
trip = <&trip2>;
145+
};
146+
map3 {
147+
cooling-device = <&fan0 3 4>;
148+
trip = <&trip3>;
149+
};
150+
};
151+
};
152+
153+
__overrides__ {
154+
fan_gpio = <&pwm_gpio>,"gpios:4",
155+
<&pwm_gpio_pins>,"brcm,pins:0";
156+
fan_temp0 = <&trip0>,"temperature:0";
157+
fan_temp0_hyst = <&trip0>,"hysteresis:0";
158+
fan_temp0_speed = <&fan0>,"cooling-levels:4";
159+
fan_temp1 = <&trip1>,"temperature:0";
160+
fan_temp1_hyst = <&trip1>,"hysteresis:0";
161+
fan_temp1_speed = <&fan0>,"cooling-levels:8";
162+
fan_temp2 = <&trip2>,"temperature:0";
163+
fan_temp2_hyst = <&trip2>,"hysteresis:0";
164+
fan_temp2_speed = <&fan0>,"cooling-levels:12";
165+
fan_temp3 = <&trip3>,"temperature:0";
166+
fan_temp3_hyst = <&trip3>,"hysteresis:0";
167+
fan_temp3_speed = <&fan0>,"cooling-levels:16";
168+
};
169+
170+
};

0 commit comments

Comments
 (0)