Skip to content

Instantly share code, notes, and snippets.

@softminus
Created February 6, 2020 01:58

Revisions

  1. softminus created this gist Feb 6, 2020.
    106 changes: 106 additions & 0 deletions min_duty_cycle_settei.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,106 @@
    #!/bin/bash

    # Copyright (C) 2020 Kia
    # Licensed under Zero Clause BSD License


    if [[ $# -ne 3 ]]; then
    echo "usage: $0 (BMC I2C BUS NUMBER) (FAN PAGE) (DUTY CYCLE FLOOR)"
    echo ""
    echo "BMC I2C BUS NUMBER can be found as follows"
    echo "$ ls /sys/bus/i2c/devices/*/hwmon/hwmon*/fan1_input"
    echo ""
    echo "if the output of that command is:"
    echo "/sys/bus/i2c/devices/7-0073/hwmon/hwmon4/fan1_input"
    echo "that means that the I2C bus number is 7"
    echo "Check /sys/module/ftsteutates/drivers/i2c\:ftsteutates/ to be sure"
    echo ""
    echo "FAN PAGE = 0x48 + index of fan"
    echo "On my system, FAN PAGE can be (0x48, 0x49, 0x4a, 0x4b)"
    echo ""
    echo "DUTY CYCLE FLOOR can be any number from 0 to 255, but please"
    echo "don't set it lower than it already is."
    echo ""
    echo "This tool asks the Teutates BMC (in a way that does not survive"
    echo "reboots/power-cycles/shutdowns) to keep the PWM waveform that is"
    echo "fed to the fan corresponding to FAN PAGE to have a duty cycle that"
    echo "is greater or equal to (DUTY CYCLE FLOOR) / 255"
    echo ""
    echo "A fan that runs at MAX_RPM without a PWM signal (or with a DC PWM"
    echo "signal) will never run slower than MAX_RPM * (DUTY CYCLE FLOOR) / 255"
    echo ""
    echo "#########################################################################"
    echo " ☢CAUTION!!☢"
    echo "The supplied I2C bus number MUST correspond to the bus where the"
    echo "Teutates BMC lives on."
    echo ""
    echo "The supplied fan page must be between 0x48-0x4f inclusive and"
    echo "must correspond to a fan in your system connected to the Teutates BMC."
    echo ""
    echo "Incorrectly specifying the I2C bus number or fan page may BRICK"
    echo "or IRREVERSIBLY DESTROY your system!"
    echo " ☢CAUTION!!☢"
    echo "#########################################################################"
    echo ""
    echo "It is likely that this tool will not produce expected results if"
    echo "SilentFanConfig-Manager has been run -- which writes fan config stuff"
    echo "into nonvolatile storage. The aforementioned fan config stuff might"
    echo "set a different set of control modes, causing the write to 0x86 to"
    echo "not have the desired effect. I don't have the full Teutates"
    echo "documentation, so i do not know any of the control laws are."
    echo ""
    echo "However, if you have access to SilentFanConfig-Manager, why do you even"
    echo "need this?"
    echo ""
    echo "This tool has only been tested on a single motherboard:"
    echo "FUJITSU /D3641-S1, BIOS V5.0.0.13 R1.7.0 for D3641-S1x"
    echo "with FTS Teutates chip revision: 3.11"
    echo ""
    echo "FOR USE ONLY ON FUJITSU/KONTRON MOTHERBOARDS WITH TEUTATES BMC"
    echo ""
    exit 1
    fi



    case $2 in
    0x48|0x49|0x4a|0x4b|0x4c|0x4d|0x4e|0x4f)
    echo "supplied fan page is "$2
    ;;
    *)
    echo "INVALID FAN PAGE!!"
    exit 2
    ;;
    esac




    set -e

    echo -n "Testing for Teutates BMC presence... "
    # test that we have a teutates bmc, ideally this modprobe fails otherwise
    sudo modprobe ftsteutates
    # but we need it not be loaded, so we can have the i2c bus to ourselves
    sudo rmmod ftsteutates

    echo "present"
    # this lets us do i2cset
    sudo modprobe i2c-dev

    # switch the page for the fan in question. the user is responsible
    # for making sure this is between 0x48 and 0x4f
    echo "writing to the i2c bus; hope you gave us the correct one!"
    sudo i2cset -y $1 0x73 0x7f $2

    # set PWM duty cycle
    sudo i2cset -y $1 0x73 0x86 $3

    # set the page back to 0x00 just to be kind to whoever (the kernel module) talks with the BMC after us
    sudo i2cset -y $1 0x73 0x7f 0x00

    echo "writes done"
    # let us look at our handiwork via sensors(1).
    # be patient, i think the BMC only updates RPM every second or so
    sudo modprobe ftsteutates