raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.09k stars 4.97k forks source link

CM4 IO Board fan still running after shutdown #4632

Closed buismaarten closed 1 year ago

buismaarten commented 2 years ago

Is there any way to let the kernel the control the fan using the fan header on the CM4 IO Board? The fan always spins because it's plugged into a power adapter.

pelwell commented 2 years ago

What does the schematic show the header to be connected to?

buismaarten commented 2 years ago

What do you mean? I'm using the fan header on the IO board.

buismaarten commented 2 years ago

Is it possible to add support for the EMC2301 chip to handle the fan speed?

See: https://forums.raspberrypi.com/viewtopic.php?t=308787

6by9 commented 2 years ago

It would be nice if there had been a V2 to https://patchwork.kernel.org/project/linux-hwmon/patch/20200928104326.40386-1-biwen.li@oss.nxp.com/ to merge support into the mainline kernel. It's probably worth cherry-picking it back and seeing what state it is in as the requested changes appear not to be too huge. It's a little concerning that the original poster is reporting a nasty looking kernel splat from it.

geerlingguy commented 2 years ago

Just posting my support for something standardized, too. Right now it seems this project (https://github.com/neg2led/cm4io-fan) is the most common way people are getting any decent PWM control over the fan, other than writing up hackneyed scripts to control speeds like:

$ i2cset -y 10 0x2f 0x30 0x80

(to set it to 50%).

As an aside, and more on point with the thread's original topic of discussion, I noticed that the fan comes on after shutdown, but it seems to pulsate a bit, going faster and slower. Is there any particular reason for that? Or do I just have a ghost somewhere in my IO board or 120mm fan?

icman003 commented 2 years ago

same issue here after system shutdown the fan still on , I saw somewhere said need update bootloader don'y know how

6by9 commented 2 years ago

EMC230x driver merged with #5026. This is based on the more recent patch set that was sent to linux-hwmon in https://patchwork.kernel.org/project/linux-hwmon/cover/20220430114905.53448-1-michaelsh@nvidia.com/

dtoverlay=i2c-fan,emc2301,i2c_csi_dsi to load it with the default temps and speeds. Add midtemp=55000,maxtemp=65000 or similar to change the default switch temperatures, and minpwm=0,maxpwm=255 with alternative numbers to modify the PWM range used.

I have looked at what happens on shutdown, and the simple answer is nothing. The fan remains spinning at the speed that was requested previously. I've tried adding a reboot notifier hook via register_reboot_notifier, but it seems to make no difference (possibly I've messed it up, but it's a tricky one to debug).

The CM4 keeps the 3V3 rail powered up on shutdown, and the 12V is coming directly in from the power supply, so the EMC2301 remains powered and keeps the fan spinning. As noted in https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#POWER_OFF_ON_HALT, you should be able to alter that behaviour via sudo -E rpi-eeprom-config --edit when usbboot'ed (rpi-eeprom-config is disabled for EMMC boot). Kill the power to the EMC2301 and the fan should drop to a default speed, but there are no absolute guarantees over what that is.

6by9 commented 2 years ago

And just a minor warning should you have a pre-production CM4IO board (dated 13/5/2020) the TACH and PWM lines of the fan connector are reversed, so it won't work. That's unlikely to affect anyone outside Raspberry Pi or some of the alpha testers.

YPyltiai commented 2 years ago

Does anyone know when is the release with this change expected? Thanks!

6by9 commented 2 years ago

https://github.com/raspberrypi/rpi-firmware/commit/affbf52a45f2079aae6dc6c123eb67e2854f1dc4 So rpi-update will get it a kernel including it.

wadoli commented 2 years ago

Or I just wait until a Linux kernel version ≥ 5.15.38 becomes the stable version shipped via apt to Pi OS? (The current stable aarch64-version shipped via apt is 5.15.32-v8+)

YPyltiai commented 2 years ago

Just tested it on latest Kernel - doesn't seem to be working with LoveRPI POE Hat which now has EMC2301 and PWM connector. I can control fan via i2c commands fine but nothing happens automatically.

Fan is there:

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- 0c -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2f 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

And config.txt has:

dtparam=i2c_arm=on
dtoverlay=i2c-fan,emc2301,i2c0

What am I doing wrong?

6by9 commented 2 years ago

What am I doing wrong?

The default assumes that the fan is on i2c1 - no override needed. Adding i2c0 looks on i2c-0 (GPIOs 0&1, and CM4IO CAM0 and DISP0 connectors via jumpers J6), whilst i2c_csi_dsi looks on i2c-10 (CAM1 & DISP1 connectors, and where the fan controller and RTC are connected on a CM4IO).

pelwell commented 2 years ago

In other words, all you should need is:

dtoverlay=i2c-fan,emc2301

i2c_arm=on is included as part of the i2c-fan overlay.

YPyltiai commented 2 years ago

Thanks! Now it makes sense - I didn’t try that yesterday.

wadoli commented 2 years ago

EMC230x driver merged with #5026. This is based on the more recent patch set that was sent to linux-hwmon in https://patchwork.kernel.org/project/linux-hwmon/cover/20220430114905.53448-1-michaelsh@nvidia.com/

dtoverlay=i2c-fan,emc2301,i2c_csi_dsi to load it with the default temps and speeds. Add midtemp=55000,maxtemp=65000 or similar to change the default switch temperatures, and minpwm=0,maxpwm=255 with alternative numbers to modify the PWM range used.

Just wanted to say thank you for your work and help! 🙏 With the recently distributed default kernel 5.15.56-v8+ for Raspberry Pi OS (64-bit), my device (a SATANAS based on the Raspberry Pi Compute Module 4) works like a charm with your default setting. Thank you!

kwinz commented 2 years ago

Please let me know if this is too off topic: I have a fully updated Raspbian with kernel 5.15.56-v8+ #1575 SMP PREEMPT Fri Jul 22 20:31:26 BST 2022 aarch64 GNU/Linux with CM4 on an original Raspberry IO board.

My /boot/config.txt contains:

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2c_vc=on
#dtparam=i2s=on
#dtparam=spi=on

# Additional overlays and parameters are documented /boot/overlays/README
dtoverlay=i2c-fan,emc2301,i2c_csi_dsi,minpwm=0,maxpwm=255,midtemp=60000,maxtemp=70000,addr=0x2f
dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi,addr=0x51

The problem I have is that the fan spins up and down every few seconds. The temperature is nowhere near 60C, it should be off. So there is some PWM regulation going on but it seems like midtemp is ignored. I also tried without addr=0x2f, no difference.

The compute modules RTC works. Seems like i2c-rtc has no issues.

If I try to load the emc2301 module it fails

sudo modprobe emc2301
modprobe: FATAL: Module emc2301 not found in directory /lib/modules/5.15.56-v8+

And lsmod | grep "emc2301" returns nothing. Of course I kept rebooting in between tries.

How can I debug this? Is there any way to cofirm it loaded the correct midtemp?

pelwell commented 2 years ago

The second part of your issue is easy to explain - EMC2301 support is implemented by the EMC2305 driver. The correct module loading command is sudo modprobe emc2305, but it should not be required.

0x2f is the default address, so addr=0x2f makes no difference at all. Similarly, 0x51 is the default address for the pcf85063a,

You might be able to learn some more my running the following command to monitor the temperature and cooling states:

$ watch -n 1 "grep -s . /sys/class/thermal/thermal_zone*/* /sys/class/thermal/cooling_device*/*"

Leave that running while you raise and lower the temperature, paying particular attention to the temp and cur_state fields.

I find that a useful way to increase the temperature is to run a number of background threads that spin, essentially doing nothing:

$ while true; do true; done &
kwinz commented 2 years ago

Thank you that was super helpful! Especially knowing about the additional /sys/ variables in thermal_zone and cooling device directory:

/sys/class/thermal/thermal_zone0/temp:43816
/sys/class/thermal/thermal_zone0/trip_point_0_hyst:2000
/sys/class/thermal/thermal_zone0/trip_point_0_temp:70000
/sys/class/thermal/thermal_zone0/trip_point_0_type:active
/sys/class/thermal/thermal_zone0/trip_point_1_hyst:2000
/sys/class/thermal/thermal_zone0/trip_point_1_temp:60000
/sys/class/thermal/thermal_zone0/trip_point_1_type:active
/sys/class/thermal/thermal_zone0/type:cpu-thermal
/sys/class/thermal/cooling_device0/cur_state:0
/sys/class/thermal/cooling_device0/max_state:10
/sys/class/thermal/cooling_device0/type:emc2305_fan

I kept watching it, and as the temp increased the cur_state increased from 0 to 6 or 7. But that didn't seem to influence the fan speed at all. The fan spins, even if the cur_state is 0. And it doesn't seem to go any faster if the cur_state is at 7.

My PWM fan is a Fan-4010-PWM-12V that came in a Waveshare WS-19195 case bundle. Photo: https://www.dropbox.com/s/x2iv9ax1bs5gp3q/IMG_20220823_215237.jpg?dl=0 Maybe my fan's PWM controller is broken? I don't have another 12V PWM fan at hand right now to test.

Hreimr commented 1 year ago

Is there any way to get this to work in home assistant os? Some people has gotten their fans to work however that's on RPI 4s using the GPIO pins as fan control. I don't know how to get status of the fan nor of setting it's rpm in home assistant.

dmeziere commented 1 year ago

Let me just precise that after 2 long evenings trying different sets of parameters with "cur_state" at zero and the fan always off, a simple rpi-update raised my kernel from 6.1.21-v8+ to 6.1.54-v8+, and the fan started to spin according to temperature.

habibbenkhedher commented 2 months ago

Hi guys, I just got a CM4 with EMMC and a cm4 io board and I tried everything but still my fan are going full power and even with the changes to config.txt, I notice no changes in the rpms. can somebody provide me with a config.txt file to fix my problem or did anybody encounter this problem ? I'm running on pi os 64 (latest version) my "/boot/firmware/config.txt":

dtparam=i2c_arm=on dtparam=i2s=on dtparam=spi=on dtparam=i2c_vc=on

dtparam=audio=on

camera_auto_detect=1

auto_initramfs=1

dtoverlay=vc4-kms-v3d max_framebuffers=2

disable_fw_kms_setup=1

arm_64bit=1

disable_overscan=1

arm_boost=1

[cm4]

otg_mode=1

[cm5] dtoverlay=dwc2,dr_mode=host

[all] dtoverlay=i2c-fan,emc2301,midtemp=45000,maxtemp=65000,minpwm=0,maxpwm=255

rofehr commented 2 months ago

/boot/firmware/config.txt ?? but that is not the right directory

habibbenkhedher commented 2 months ago

Let me just precise that after 2 long evenings trying different sets of parameters with "cur_state" at zero and the fan always off, a simple rpi-update raised my kernel from 6.1.21-v8+ to 6.1.54-v8+, and the fan started to spin according to temperature.

is your solution still working ? if yes could you please tell me the exact steps that has to be made to get the fan rpm down (best case shutdown if temperature too low)

/boot/firmware/config.txt ?? but that is not the right directory

in /boot/config.txt, the following is written : " DO NOT EDIT THIS FILE

The file you are looking for has moved to /boot/firmware/config.txt " so I didn't Bother editing this one.

pelwell commented 2 months ago

Starting with Bookworm, the firmware partition moved from /boot to /boot/firmware. As a result, any references to /boot/config.txt should be read as /boot/firmware/config.txt.

The early Bookworm releases had symbolic links from /boot/config.txt and /boot/cmdline.txt to the real files in /boot/firmware, but we found that for some people - perhaps because of the editor they use - the symbolic links were being replaced by a copy of the file, which caused their changes to be ignored. Now there are placeholder files directing the user to the new locations.

habibbenkhedher commented 2 months ago

I managed to control the rpm through i2c-set but then it will mean that I will need a shell script that controls the fan rpms.

Starting with Bookworm, the firmware partition moved from /boot to /boot/firmware. As a result, any references to /boot/config.txt should be read as /boot/firmware/config.txt.

The early Bookworm releases had symbolic links from /boot/config.txt and /boot/cmdline.txt to the real files in /boot/firmware, but we found that for some people - perhaps because of the editor they use - the symbolic links were being replaced by a copy of the file, which caused their changes to be ignored. Now there are placeholder files directing the user to the new locations.

is there a known solution to fix it ?

pelwell commented 2 months ago

To fix what - the fan speed or the file locations?

habibbenkhedher commented 2 months ago

well the fan speed , I just rebooted and the fans are back at 100%. after excecuting dmesg | grep emc I got this message : [ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_headphones=0 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_hdmi=0 smsc95xx.macaddr=2C:CF:67:58:7A:31 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 overlayroot=tmpfs console=ttyS0,115200 console=tty1 root=PARTUUID=f0e0fde2-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=DE modprobe.blacklist=emc2305

pelwell commented 2 months ago
... modprobe.blacklist=emc2305

What's that doing there? It is disabling the fan driver that would be responsible for switching off the fan - no wonder it keeps spinning.

habibbenkhedher commented 2 months ago
... modprobe.blacklist=emc2305

What's that doing there? It is disabling the fan driver that would be responsible for switching off the fan - no wonder it keeps spinning.

thanks I just noticed it but on /etc/modprobe.d/rpi-blacklist.confthere is nothing written there so I'm wondering where it has to be modified.

pelwell commented 2 months ago

/boot/firmware/cmdline.txt?

habibbenkhedher commented 2 months ago

/boot/firmware/cmdline.txt?

yes just found it, thank you sir, I rebooted after deleting it but I still have 100% rpm back. my /boot/firmware/config.txt looks like this :

# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on
dtparam=i2c_vc=on

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Additional overlays and parameters are documented
# /boot/firmware/overlays/README

# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Automatically load initramfs files, if found
auto_initramfs=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1
# Run in 64-bit mode
arm_64bit=1

# Disable compensation for displays with overscan
disable_overscan=1

# Run as fast as firmware / board allows
arm_boost=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[cm5]
dtoverlay=dwc2,dr_mode=host

[all]
dtoverlay=i2c-fan,emc2305,midtemp=45000,maxtemp=65000,minpwm=0,maxpwm=100
enable_uart=1

i will continue searching for a solution but I think I'm getting closer