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