I want to have an overlay to control a fan connected to PI gpio12 (BCM) and turn it on/off depending on cpu temperature (on gpio18 I have a buzzer, both are connected to gpios via N-MOSFET 22N7002).
Similar to https://github.com/raspberrypi/linux/bl ... verlay.dts.
Starting from https://github.com/raspberrypi/linux/bl ... hermal.txt,
https://github.com/raspberrypi/linux/bl ... io-fan.txt and above dts file I have created 2 new dts file:
"gpio-fan.dts"
Code: Select all
/*
* Overlay for the Raspberry Pi GPIO Fan @ BCM GPIO12.
* sudo dtc -W no-unit_address_vs_reg [email protected] -I dts -O dtb -o /boot/overlays/gpio-fan.dtbo gpio-fan.dts
* nano /boot/config.txt , dtoverlay=gpio-fan
* or
* sudo sed -i '25,/pwm-fan/s/pwm-fan/"gpio-fan/' /boot/config.txt
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2708";
[email protected] {
target-path = "/";
__overlay__ {
fan0: [email protected] {
compatible = "gpio-fan";
gpios = <&gpio 12 1>;
gpio-fan,speed-map = <0 0 3000 1>;
#cooling-cells = <2>;
status = "okay";
};
};
};
[email protected] {
target = <&cpu_thermal>;
__overlay__ {
trips {
threshold: [email protected] {
temperature = <45000>;
hysteresis = <5000>;
type = "active";
};
target: trip-poi[email protected] {
temperature = <50000>;
hysteresis = <2000>;
type = "active";
};
cpu_hot: [email protected] {
temperature = <55000>;
hysteresis = <2000>;
type = "active";
};
};
cooling-maps {
map0 {
trip = <&threshold>;
cooling-device = <&fan0 0 1>;
};
map1 {
trip = <&target>;
cooling-device = <&fan0 1 1>;
};
map2 {
trip = <&cpu_hot>;
cooling-device = <&fan0 1 1>;
};
};
};
};
};
"pwm-fan.dts"
Code: Select all
/*
* Overlay for the Raspberry Pi GPIO Fan @ BCM GPIO12.
* sudo dtc -W no-unit_address_vs_reg [email protected] -I dts -O dtb -o /boot/overlays/pwm-fan.dtbo pwm-fan.dts
* nano /boot/config.txt , dtoverlay=pwm-fan
* or
* sudo sed -i '25,/gpio-fan/s/gpio-fan/pwm-fan/' /boot/config.txt
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2708";
[email protected] {
target = <&gpio>;
__overlay__ {
fan0: pwm-fan {
compatible = "pwm-fan";
cooling-min-state = <0>;
cooling-max-state = <3>;
#cooling-cells = <2>;
pwms = <&pwm 0 10000 0>;
cooling-levels = <0 255 255 255>;
};
};
};
[email protected] {
target = <&cpu_thermal>;
__overlay__ {
trips {
threshold: [email protected] {
temperature = <44000>;
hysteresis = <5000>;
type = "active";
};
target: [email protected] {
temperature = <50000>;
hysteresis = <2000>;
type = "passive";
};
cpu_hot: [email protected] {
temperature = <55000>;
hysteresis = <2000>;
type = "active";
};
};
cooling-maps {
map0 {
trip = <&threshold>;
cooling-device = <&fan0 0 1>;
};
map1 {
trip = <&target>;
cooling-device = <&fan0 1 2>;
};
map2 {
trip = <&cpu_hot>;
cooling-device = <&fan0 1 3>;
};
};
};
};
};
Please advise what am I doing wrong.
Thank you,
Paul
EDIT: config.txt
Code: Select all
[email protected]:/home/pi# cat /boot/config.txt
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Enable PI_OS LivePIN
dtoverlay=gpio-poweroff,gpiopin=27,active_low
# Enable MCP74912 RTC
dtoverlay=i2c-rtc,mcp7941x
# ttySC2, ttySC3
dtoverlay=sc16is752-i2c-02
# ttySC0, ttySC1
dtoverlay=sc16is752-i2c-01
# Enable SPI TPM
dtoverlay=letstrust-tpm
# Enable PI UART
enable_uart=1
# Enable GPIO12 Fan
dtoverlay=gpio-fan
#dtoverlay=pwm,pin=12,func=4
#using "dtoverlay=pwm,pin=12,func=4" and sysfs commands fan is working properly.