Skip to content

Instantly share code, notes, and snippets.

@kth5
Created January 9, 2024 08:29
Show Gist options
  • Save kth5/62a1dbd4fbea879da1403110d98ee794 to your computer and use it in GitHub Desktop.
Save kth5/62a1dbd4fbea879da1403110d98ee794 to your computer and use it in GitHub Desktop.
Milk-V Pioneer fan control

DRAFT status

This is very much a draft still as I go along. Everything in here is subhect to change heavily, could be wrong and your mileage may vary greatly.

Everything here assumes native build on Arch POWER riscv64.

This is probably broken in some way but works for me.

#!/bin/bash

MAXTEMP=70000 # 70C
MEDTEMP=65000 # 65C

while [ true ]; do
  TEMP1=$(cat /sys/class/hwmon/hwmon0/temp1_input)
  TEMP2=$(cat /sys/class/hwmon/hwmon0/temp2_input)

  echo "${TEMP1} ${TEMP2}"

  if [ ${TEMP1} -lt ${MAXTEMP} -o ${TEMP2} -lt ${MAXTEMP} ]; then
    if [ ${TEMP1} -lt ${MEDTEMP} -o ${TEMP2} -lt ${MEDTEMP} ]; then
      echo ":: limit to 20%"
      echo 180 > /sys/class/hwmon/hwmon2/pwm1
    else
      echo ":: limit to 40%"
      echo 120 > /sys/class/hwmon/hwmon2/pwm1
    fi
  fi
  sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment