Change to bb-symlinks for FAN header

@RobertCNelson do you think it would be a good idea to add a symlink for the fan pwm to the bb-symlink file.

Depending on pwms enabled might this not move ? I notice originally it was at
/sys/class/pwm/pwmchip6

Having just flash the latest minimal version, being the only pwm enabled it is at pwmchip0

I have made a small change to bb-symlinks to also map this pwm to a fixed location
/dev/bone/fan

	3030000.pwm)
		mkdir -p /dev/bone/fan/
		if [ -d /sys/class/pwm/pwmchip$i/pwm0/ ] ; then
			ln -sTf /sys/class/pwm/pwmchip$i/pwm0/ /dev/bone/fan/a
		fi
		if [ -d /sys/class/pwm/pwmchip$i/pwm1/ ] ; then
			ln -sTf /sys/class/pwm/pwmchip$i/pwm1/ /dev/bone/fan/b
		fi
		;;

I have also added a service file and a couple of scripts. see attached file.

bb-fan.tar.gz (1.0 KB)

Hi @benedict.hewson actually there is a mainline pwm-fan node:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi#n174

	fan: pwm-fan {
		compatible = "pwm-fan";
		cooling-levels = <0 150 200 255>;
		#cooling-cells = <2>;
		fan-supply = <&vsys_5v0>;
		pwms = <&pwm0 0 40000 0>;
	};

I’m at home today, so i have my logic analyser available, so i’ll tweak the device tree with this…

Regards,

Hi thanks. I was looking at trying to create a fan device.

I wasn’t sure how easy that would be as the PWM’s have 2 channels and both need to be set with the same period and only channel b needs the duty cycle set.

Plus at least in your snippet it appears the duty cycle is an 8 bit value.
The documentation under devicetree did not really explain much.

Also not sure about the tacho input, although I am not that worried about that.

I agree, it’s completely missing! :wink: ‘pwm-fan’…

edit found it…

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/hwmon/pwm-fan.txt

hwmon/pwm-fan.txt gives a couple of examples, but doesn’t help that much.

perhaps I will have a look at the source code and see if that is any clearer

Ok, so I assume where we have

pwms = <&pwm 0 40000 0>;

the digits correspond to periods for channels ? Looking through various devicetrees some have 3 values, some 2.

Assuming that is the case, it doesn’t look too complicated.

There are thermal zones setup already, however would need to add more trip entries as currently there is only a critical one at 125C for each zone

I will see if I can create an overlay and make it work

@RobertCNelson Ok with some trial and error and a fair bit of head scratching I managed to make this work. I have attached the devicetree overlay file I currently have running.

To work though, the udev rule that automatically exports the PWM’s needs to be disabled.
If ehrpwm3 is exported the pwm-fan driver fails as the device is busy.

I removed 81-pwm-noroot.rules from /etc/udev/rules.d to start, then spent 5 minutes wondering why it was still being exported. Removed it from initrd and then the pwm-fan driver loaded and worked.

Heated up my heatsink with a hot air gun to make it change states and it seems to work.

Of course the downside to using the pwm-fan driver is that if you want to modify the fan settings you need to modify the overlay and reboot.

Using the exported PWM device does make this easier, although you then need some sort of script to poll the temperatures and adjust the fan speed.

BONE-FAN.zip (932 Bytes)

Awesome job! i’ll work on the pwm interaction, we should be able to add some temp set points… PS, please add your sign-off, i’ll commit it directly, but you can do a pull rquest to to get set…

I will play around with it a little more over the weekend.

I am not 100% sure about the cooling-map values. I think the 2 values in
<&fan0 0 0> are min/max values, and I have a feeling they are not quite right.

Also strictly speaking I have the lowest temperature trips as type=“passive” but the fan still spins. I can’t find a decent explanation of what the type is actually used for as I think it is the cooling-maps section that dictates fan speed.

It would also be nice to get the tacho input working as well.

edit. Just checking the pwm on a scope and I notice it tends to jump around a bit when it gets to a trip boundary. This is a result of mapping every thermal zone to the same fan and the zones never quite have the same temperature. Hysteresis is on a per trip bases so does not really help.

It might be better to just map one of the thermal zones to the fan. It would make things a bit simpler. Given that the thermal sensors are all on the same die, I would expect them to track fairly well.

Hi @RobertCNelson

Ok, I now have the fan tacho working as well.
It is reported @ /sys/class/hwmon/hwmon0/fan1_input

Seems pretty accurate measured against a frequency counter.

I have also simplified the cooling-maps and trip points to only one of the thermal zones. I added a fifth cooling level to make testing a little easier.

BONE-FAN.zip (952 Bytes)

Awesome! pushed…

Regards,