1#!/bin/bash
2#
3# Set all fans to pwm mode.
4
5# Provide source directive to shellcheck.
6# shellcheck source=meta-fii/meta-kudo/recipes-kudo/kudo-fw-utility/kudo-fw/kudo-lib.sh
7source /usr/libexec/kudo-fw/kudo-lib.sh
8
9# Set all pwm_enable to 1
10find /sys/class/hwmon/hwmon*/ -name 'pwm*_enable' -exec bash -c 'echo "$1" && echo 1 > "$1" && cat "$1"' -- {} \;
11
12for i in {0..5}
13do
14    fan_pwm_rate_of_change=0x$(printf '%02x' $((8 + i)) | \
15            awk '{print $1}')
16    # Set Fan PWM Rate-of-Change Bits(bits 4:2) to 000b
17    # Register 08h to 0Dh
18    oriRegVal=$(i2cget -y -f "${I2C_FANCTRL[0]}" 0x"${I2C_FANCTRL[1]}" \
19        "${fan_pwm_rate_of_change}")
20    updateVal=$((oriRegVal & 0xe3))
21    updateVal=0x$(printf "%x" ${updateVal})
22    i2cset -y -f "${I2C_FANCTRL[0]}" 0x"${I2C_FANCTRL[1]}" \
23        "${fan_pwm_rate_of_change}" "${updateVal}"
24done
25