diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2023-06-03 03:31:04 +0300 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2023-06-06 02:58:41 +0300 |
commit | 9e1e3a73c2e8b82dd66a2b3fa07d2f3083c72ceb (patch) | |
tree | ebd2c48e51c33ee575124be7da99c22a22dc2152 /meta-ibm/meta-romulus/recipes-phosphor | |
parent | 0a0da3684ff462a5edd465744a5eb1a09c786d4f (diff) | |
download | openbmc-9e1e3a73c2e8b82dd66a2b3fa07d2f3083c72ceb.tar.xz |
meta-ibm: fix some shellcheck issues
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I3792c2aa7f4bcd92254717c5bd00bc438f9101be
Diffstat (limited to 'meta-ibm/meta-romulus/recipes-phosphor')
-rw-r--r-- | meta-ibm/meta-romulus/recipes-phosphor/chassis/vrm-control/vrm-control.sh | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/meta-ibm/meta-romulus/recipes-phosphor/chassis/vrm-control/vrm-control.sh b/meta-ibm/meta-romulus/recipes-phosphor/chassis/vrm-control/vrm-control.sh index 870124296a..b39e14e237 100644 --- a/meta-ibm/meta-romulus/recipes-phosphor/chassis/vrm-control/vrm-control.sh +++ b/meta-ibm/meta-romulus/recipes-phosphor/chassis/vrm-control/vrm-control.sh @@ -4,134 +4,134 @@ # ######################################################### -d2v () { -# usage: d2v <decimal volts> +function d2v() { + # usage: d2v <decimal volts> -echo $1 | awk '{print $1 * 256 + .5}' | cut -d '.' -f 1 + echo "$1" | awk '{print $1 * 256 + .5}' | cut -d '.' -f 1 } # ######################################################### -v2d () { -# usage: v2d <hex val> +function v2d() { + # usage: v2d <hex val> -printf " %0.3fV" `echo $1 | awk '{print $1 / 256}'` + printf " %0.3fV" "$(echo "$1" | awk '{print $1 / 256}')" } # ######################################################### -i2d () { -# usage: i2d <hex val> <current divisor> - -# parse current mantisa and exponent -# format: SEEE ESMM MMMM MMMM -let e=$1/0x800 -let esign=e/0x10 -let m=$1\&0x07FF -let msign=m/0x0400 - -if [ $msign -eq 1 ] -then - # calc ones compliment - let m=($m^0x07FF)+1 - m="-$m" -fi -if [ $esign -eq 1 ] -then - # calc ones compliment - let e=(e^0x1F)+1 - e="-$e" -fi -printf " %0.3fA\n" `echo $m $e $2 | awk '{print ($1 * 2^$2) / $3}'` +function i2d() { + # usage: i2d <hex val> <current divisor> + + # parse current mantisa and exponent + # format: SEEE ESMM MMMM MMMM + e=$(( $1/0x800 )) + esign=$(( e/0x10 )) + m=$(( $1 & 0x07FF )) + msign=$(( m/0x0400 )) + + if [ $msign -eq 1 ] + then + # calc ones compliment + m=$(( (m^0x07FF)+1 )) + m=$(( -m )) + fi + if [ $esign -eq 1 ] + then + # calc ones compliment + e=$(( (e^0x1F)+1 )) + e=$(( -e )) + fi + printf " %0.3fA\n" "$(echo $m $e "$2" | awk '{print ($1 * 2^$2) / $3}')" } # ######################################################### -rw_vc () { -# usage: rw_vc <bus> <addr> <current divisor> <channel> <value> - -# select channel -if [ $4 != "x" ] -then - i2cset -y $1 $2 0 $4 b -fi - -# write new voltage set point -if [ ! -e $5 ] -then - i2cset -y $1 $2 0x21 `d2v $5` w -fi - -# print voltage set point -v2d `i2cget -y $1 $2 0x21 w` - -# print voltage -v2d `i2cget -y $1 $2 0x8B w` - -# print current -i2d `i2cget -y $1 $2 0x8C w` $3 - -# default back to channel 0 -if [ $4 != "x" ] -then - i2cset -y $1 $2 0 0 b -fi +function rw_vc() { + # usage: rw_vc <bus> <addr> <current divisor> <channel> <value> + + # select channel + if [ "$4" != "x" ] + then + i2cset -y "$1" "$2" 0 "$4" b + fi + + # write new voltage set point + if [ ! -e "$5" ] + then + i2cset -y "$1" "$2" 0x21 "$(d2v "$5")" w + fi + + # print voltage set point + v2d "$(i2cget -y "$1" "$2" 0x21 w)" + + # print voltage + v2d "$(i2cget -y "$1" "$2" 0x8B w)" + + # print current + i2d "$(i2cget -y "$1" "$2" 0x8C w)" "$3" + + # default back to channel 0 + if [ "$4" != "x" ] + then + i2cset -y "$1" "$2" 0 0 b + fi } # ######################################################### # Main -if [ -e $1 ] +if [ -e "$1" ] then - $0 vdda vcsa vdna vioa vddb vcsb vdnb viob - exit + $0 vdda vcsa vdna vioa vddb vcsb vdnb viob + exit fi -if [ $1 == "-h" ] +if [ "$1" == "-h" ] then - echo " Usage: vrm [<rail>=[value] [<rail>=[value]] ...]" - echo " rail: vdda vcsa vdna vioa vddb vcsb vdnb viob" - echo " value: volts" - echo - echo " e.g., vrm vioa=1.0 viob=1.0" - echo - exit + echo " Usage: vrm [<rail>=[value] [<rail>=[value]] ...]" + echo " rail: vdda vcsa vdna vioa vddb vcsb vdnb viob" + echo " value: volts" + echo + echo " e.g., vrm vioa=1.0 viob=1.0" + echo + exit fi echo "rail set read current" echo "------- ------- ------- -------" -for param in ${@:1} +for param in "${@:1}" do - rail=`echo $param | cut -d'=' -f 1` - val=`echo ${param}= | cut -d'=' -f 2` - echo -n "$rail" - case "$rail" in - vdda) - rw_vc 4 0x70 2 0 $val - ;; - vddb) - rw_vc 5 0x70 2 0 $val - ;; - vcsa) - rw_vc 4 0x70 4 1 $val - ;; - vcsb) - rw_vc 5 0x70 4 1 $val - ;; - vdna) - rw_vc 4 0x73 2 0 $val - ;; - vdnb) - rw_vc 5 0x73 2 0 $val - ;; - vioa) - rw_vc 4 0x73 2 1 $val - ;; - viob) - rw_vc 5 0x73 2 1 $val - ;; - *) - echo " non-existant" - esac + rail=$(echo "$param" | cut -d'=' -f 1) + val=$(echo "${param}=" | cut -d'=' -f 2) + echo -n "$rail" + case "$rail" in + vdda) + rw_vc 4 0x70 2 0 "$val" + ;; + vddb) + rw_vc 5 0x70 2 0 "$val" + ;; + vcsa) + rw_vc 4 0x70 4 1 "$val" + ;; + vcsb) + rw_vc 5 0x70 4 1 "$val" + ;; + vdna) + rw_vc 4 0x73 2 0 "$val" + ;; + vdnb) + rw_vc 5 0x73 2 0 "$val" + ;; + vioa) + rw_vc 4 0x73 2 1 "$val" + ;; + viob) + rw_vc 5 0x73 2 1 "$val" + ;; + *) + echo " non-existant" + esac done |