#!/bin/sh
#
# set Elbrus 4.4/804 fan speeds by hand
# (first stop pwmd service)
#
# argument:
#           10..255 for roughly 4k..15k rpm
#           nothing is 70, about 10k rpm
#           0 is really 0 which is dangerous!
#
# see also:
#           sensors(1), sensors-detect(8)

[ "$1" = 0 ] && echo 'WARNING: disabling fans can overheat your system!' >&2

exec 2>/dev/null

modprobe -a i2c-dev ltc4306 lm63 adt7475
echo lm96163 0x4c > /sys/bus/i2c/devices/i2c-0/new_device

for pwm in /sys/class/i2c-dev/i2c-?/device/?-004c/hwmon/hwmon?/pwm1; do
	echo ${1:-70} >$pwm
done

# large jumps might actually need 2--3 seconds to catch up
sleep 1.5
sensors | grep ^fan | awk '{print $2" "$3}'
