Firefly-RK3399 fan control

I noticed that according to schematics FAN_12V is switched with Q20 that is controlled by Q21 over BL_EN line. And the latter corresponds to GPIO1_A1. So if I export the correct gpio number I can write a simple script that reads temperature from /sys/class/thermal/thermal_zone0/temp and turns the fan on/off due to setpoint (t_high and t_low for hysteresis).
Supposing GPIO1_A1 should be 33 I do:

echo 33 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio33/direction
echo 0 > /sys/class/gpio/gpio33/value

And see the fan keeps turnung. Please correct me if I’m wrong with that idea or I just picked the wrong number for gpio.

UPD1: Seems I have to desolder 10K R702 from PWR_EN_SYS and put it on R701

It was a kind of surgery to perform soldering, I’ve lost original 0402 so had to put 0805 with wire :slight_smile:
And finally it does work:

#!/bin/bash

FAN_ON_TEMP="39000"    # operating temperature range in milliC
FAN_OFF_TEMP="35000"   # OFF is less than ON for hysteresis

if [ ! -d /sys/class/gpio/gpio33 ];
    then
    echo 33 > /sys/class/gpio/export;
    echo out > /sys/class/gpio/gpio33/direction;
fi

echo 1 > /sys/class/gpio/gpio33/value;

while [ 1 ]; do
  read CPUTEMP < /sys/class/thermal/thermal_zone0/temp
  if [ "$CPUTEMP" -gt "$FAN_ON_TEMP" ]; then echo 1 > /sys/class/gpio/gpio33/value; fi
  if [ "$CPUTEMP" -lt "$FAN_OFF_TEMP" ]; then echo 0 > /sys/class/gpio/gpio33/value; fi
  sleep 30
done

You can even create a systemd service if you wish.

Great work! Thanks for sharing!