How to Read and Control PWM Fan Speed on AML-A311D-CC and AML-S905D3-CC

This guide is for controlling a fan via the 40P GPIO header. For the PoE HAT, please see the EMC2301 fan controller guide.

PWM fans come with 4 wires:

  1. Ground
  2. Power (3.3V, 5V, 12V)
  3. Tachometer
  4. PWM speed control

Per the GPIO map, use:

  • 5V Pin 2 or Pin 4 for Power
  • GND Pin 6 for Ground
  • Pin 33 for PWM
  • Pin 35 for Tach.

On the 40-pin header, there are 7 hardware PWM pins we can use per our PWM guide. We do not want to waste CPU cycles to generate inaccurate PWM via software GPIO bitbanging.

We can hook these up to the fan via female to male jumper wires or a case directly with a PWM fan.

To test with PWM C on pin 33:

# we cannot enable like we do on Le Potato because pwm-d is already initialized
sudo ldto merge pwm-c-x5
sudo ldto merge pwm-c-x5-fan
sudo reboot

This will create a hwmon device in /sys/class/hwmon/.
The fan speed can be read from the file fan1_input in the hwmon device directory: cat fan1_input
The pwm level (0-255) can be set by the file pwm1 in the hwmon device directory. echo 0 | sudo tee pwm1

To make it permanent:

sudo ldto merge pwm-c-x5
sudo ldto merge pwm-c-x5-fan

From here, you can write userspace software in any language to implement control systems by reading fan1_input and writing to pwm1.

Most users prefer to link fan speed to SoC temperatures. To enable temperature-based fan speed control, run the previous merge commands and then add:

sudo ldto merge pwm-c-x5-fan-auto

After rebooting, fan speed should be directly controlled by SoC temperatures. This profile deactivates the fan < 50C and peaks at 60C for maintaining maximum performance.

How much power can be supplied to the fan attached to the board?

The 5V pins can pass around 2A without any issue so 10W as long as your power supply can keep the voltage stable enough for the rest of the board. Fans usually use around 100mA to 500mA. The overall current limit is around 4A for the entire board.

1 Like

PWM shows me 255, I tried changing it , but on reboot it goes back to 255. Any thoughts on how to make it stick?

Doing this doesn’t help, it goes back to 255:
sudo ldto merge pwm-c-x5
sudo ldto merge pwm-c-x5-fan

Also, I’m using the LoverPi PoE HAT, I imagine it uses all the same pins and this should work as expected?

There’s no way to pre-configure the fan on boot if you don’t attach the pwm-fan to a control source in device tree (such as with pwm-c-x5-fan-auto which attaches it to the CPU temperature).

The bindings do not specify any additional fields you can add to the overlay for a static custom. You need to do it in userspace (since kernel does not handle policy).

https://www.kernel.org/doc/Documentation/devicetree/bindings/hwmon/pwm-fan.yaml

Changing the value in pwm1 in userspace from 255 to eg 1 doesn’t seem to affect the fan speed though. Is c-x5 the right gpio when using the LoverPi PoE HAT?

This has nothing to do with the PoE HAT. The PoE HAT controls a fan through emc2301.

1 Like