Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ######################################################### |
| 3 | # Script to run on witherspoon BMC to read/set vrm voltages |
| 4 | |
| 5 | |
| 6 | # ######################################################### |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 7 | function d2v() { |
| 8 | # usage: d2v <decimal volts> |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 9 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 10 | echo "$1" | awk '{print $1 * 256 + .5}' | cut -d '.' -f 1 |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | |
| 14 | # ######################################################### |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 15 | function v2d() { |
| 16 | # usage: v2d <hex val> |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 17 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 18 | printf " %0.3fV" "$(echo "$1" | awk '{print $1 / 256}')" |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | |
| 22 | # ######################################################### |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 23 | function i2d() { |
| 24 | # usage: i2d <hex val> <current divisor> |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 25 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 26 | # parse current mantisa and exponent |
| 27 | # format: SEEE ESMM MMMM MMMM |
| 28 | e=$(( $1/0x800 )) |
| 29 | esign=$(( e/0x10 )) |
| 30 | m=$(( $1 & 0x07FF )) |
| 31 | msign=$(( m/0x0400 )) |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 32 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 33 | if [ $msign -eq 1 ] |
| 34 | then |
| 35 | # calc ones compliment |
| 36 | m=$(( (m^0x07FF)+1 )) |
| 37 | m=$(( -m )) |
| 38 | fi |
| 39 | if [ $esign -eq 1 ] |
| 40 | then |
| 41 | # calc ones compliment |
| 42 | e=$(( (e^0x1F)+1 )) |
| 43 | e=$(( -e )) |
| 44 | fi |
| 45 | printf " %0.3fA\n" "$(echo $m $e "$2" | awk '{print ($1 * 2^$2)}')" |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | |
| 49 | # ######################################################### |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 50 | function rw_vc() { |
| 51 | # usage: rw_vc <bus> <addr> <current divisor> <channel> <value> |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 52 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 53 | # select channel |
| 54 | if [ "$4" != "x" ] |
| 55 | then |
| 56 | i2cset -y "$1" "$2" 0 "$4" b |
| 57 | fi |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 58 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 59 | # write new voltage set point |
| 60 | if [ ! -e "$5" ] |
| 61 | then |
| 62 | i2cset -y "$1" "$2" 0x21 "$(d2v "$5")" w |
| 63 | fi |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 64 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 65 | # print voltage set point |
| 66 | v2d "$(i2cget -y "$1" "$2" 0x21 w)" |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 67 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 68 | # print voltage |
| 69 | v2d "$(i2cget -y "$1" "$2" 0x8B w)" |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 70 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 71 | # print current |
| 72 | i2d "$(i2cget -y "$1" "$2" 0x8C w)" "$3" |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 73 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 74 | # default back to channel 0 |
| 75 | if [ "$4" != "x" ] |
| 76 | then |
| 77 | i2cset -y "$1" "$2" 0 0 b |
| 78 | fi |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
| 82 | # ######################################################### |
| 83 | # Main |
| 84 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 85 | if [ -e "$1" ] |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 86 | then |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 87 | $0 vdda vcsa vdna vioa vddra vppa vddb vcsb vdnb viob vddrb vppb |
| 88 | exit |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 89 | fi |
| 90 | |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 91 | if [ "$1" == "-h" ] |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 92 | then |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 93 | echo " Usage: vrm [<rail>=[value] [<rail>=[value]] ...]" |
| 94 | echo " rail: vdda vcsa vdna vioa vddra vppa vddb vcsb vdnb viob vddrb vppb vdnd viod" |
| 95 | echo " value: volts" |
| 96 | echo |
| 97 | echo " e.g., vrm vioa=1.0 viob=1.0" |
| 98 | echo |
| 99 | exit |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 100 | fi |
| 101 | |
| 102 | echo "rail set read current" |
| 103 | echo "------- ------- ------- -------" |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 104 | for param in "${@:1}" |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 105 | do |
Patrick Williams | 9e1e3a7 | 2023-06-02 19:31:04 -0500 | [diff] [blame] | 106 | rail=$(echo "$param" | cut -d'=' -f 1) |
| 107 | val=$(echo "${param}=" | cut -d'=' -f 2) |
| 108 | echo -n "$rail" |
| 109 | case "$rail" in |
| 110 | vdda) |
| 111 | rw_vc 4 0x70 2 0 "$val" |
| 112 | ;; |
| 113 | vddb) |
| 114 | rw_vc 5 0x70 2 0 "$val" |
| 115 | ;; |
| 116 | vcsa) |
| 117 | rw_vc 4 0x70 4 1 "$val" |
| 118 | ;; |
| 119 | vcsb) |
| 120 | rw_vc 5 0x70 4 1 "$val" |
| 121 | ;; |
| 122 | vdna) |
| 123 | rw_vc 4 0x71 2 0 "$val" |
| 124 | ;; |
| 125 | vdnb) |
| 126 | rw_vc 5 0x71 2 0 "$val" |
| 127 | ;; |
| 128 | vioa) |
| 129 | rw_vc 4 0x40 2 x "$val" |
| 130 | ;; |
| 131 | viob) |
| 132 | rw_vc 5 0x40 2 x "$val" |
| 133 | ;; |
| 134 | vddra) |
| 135 | rw_vc 4 0x71 2 1 "$val" |
| 136 | ;; |
| 137 | vddrb) |
| 138 | rw_vc 5 0x71 2 1 "$val" |
| 139 | ;; |
| 140 | vppa) |
| 141 | rw_vc 12 0x41 2 x "$val" |
| 142 | ;; |
| 143 | vppb) |
| 144 | rw_vc 13 0x41 2 x "$val" |
| 145 | ;; |
| 146 | vdnd) |
| 147 | rw_vc 2 0x70 2 0 "$val" |
| 148 | ;; |
| 149 | viod) |
| 150 | rw_vc 2 0x70 2 1 "$val" |
| 151 | ;; |
| 152 | *) |
| 153 | echo " non-existant" |
| 154 | esac |
Matt Spinler | 5c7c388 | 2016-12-20 09:28:21 -0600 | [diff] [blame] | 155 | done |