linux icon indicating copy to clipboard operation
linux copied to clipboard

CM4 IO Board fan still running after shutdown

Open buismaarten opened this issue 4 years ago • 19 comments

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.

buismaarten avatar Oct 16 '21 13:10 buismaarten

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

pelwell avatar Oct 16 '21 14:10 pelwell

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

buismaarten avatar Oct 16 '21 14:10 buismaarten

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

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

buismaarten avatar Oct 16 '21 18:10 buismaarten

It would be nice if there had been a V2 to https://patchwork.kernel.org/project/linux-hwmon/patch/[email protected]/ 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.

6by9 avatar Oct 16 '21 19:10 6by9

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?

geerlingguy avatar Nov 21 '21 04:11 geerlingguy

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

icman003 avatar May 02 '22 10:05 icman003

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/[email protected]/

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 avatar May 10 '22 17:05 6by9

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.

6by9 avatar May 10 '22 17:05 6by9

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

YPyltiai avatar May 24 '22 15:05 YPyltiai

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

6by9 avatar May 24 '22 16:05 6by9

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

wadoli avatar May 25 '22 05:05 wadoli

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?

YPyltiai avatar May 25 '22 22:05 YPyltiai

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

6by9 avatar May 26 '22 10:05 6by9

In other words, all you should need is:

dtoverlay=i2c-fan,emc2301

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

pelwell avatar May 26 '22 10:05 pelwell

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

YPyltiai avatar May 26 '22 13:05 YPyltiai

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/[email protected]/

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!

wadoli avatar Aug 19 '22 09:08 wadoli

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?

kwinz avatar Aug 20 '22 10:08 kwinz

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 &

pelwell avatar Aug 22 '22 11:08 pelwell

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.

kwinz avatar Aug 23 '22 19:08 kwinz

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.

Hreimr avatar Dec 27 '22 22:12 Hreimr

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.

dmeziere avatar Oct 03 '23 22:10 dmeziere