blob: b0b632607f98186f1403d6b7e488de80077362ff [file] [log] [blame]
Matt Spinler5c7c3882016-12-20 09:28:21 -06001#!/bin/bash
2# #########################################################
3# Script to run on witherspoon BMC to read/set vrm voltages
4
5
6# #########################################################
Patrick Williams9e1e3a72023-06-02 19:31:04 -05007function d2v() {
8 # usage: d2v <decimal volts>
Matt Spinler5c7c3882016-12-20 09:28:21 -06009
Patrick Williams9e1e3a72023-06-02 19:31:04 -050010 echo "$1" | awk '{print $1 * 256 + .5}' | cut -d '.' -f 1
Matt Spinler5c7c3882016-12-20 09:28:21 -060011}
12
13
14# #########################################################
Patrick Williams9e1e3a72023-06-02 19:31:04 -050015function v2d() {
16 # usage: v2d <hex val>
Matt Spinler5c7c3882016-12-20 09:28:21 -060017
Patrick Williams9e1e3a72023-06-02 19:31:04 -050018 printf " %0.3fV" "$(echo "$1" | awk '{print $1 / 256}')"
Matt Spinler5c7c3882016-12-20 09:28:21 -060019}
20
21
22# #########################################################
Patrick Williams9e1e3a72023-06-02 19:31:04 -050023function i2d() {
24 # usage: i2d <hex val> <current divisor>
Matt Spinler5c7c3882016-12-20 09:28:21 -060025
Patrick Williams9e1e3a72023-06-02 19:31:04 -050026 # 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 Spinler5c7c3882016-12-20 09:28:21 -060032
Patrick Williams9e1e3a72023-06-02 19:31:04 -050033 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 Spinler5c7c3882016-12-20 09:28:21 -060046}
47
48
49# #########################################################
Patrick Williams9e1e3a72023-06-02 19:31:04 -050050function rw_vc() {
51 # usage: rw_vc <bus> <addr> <current divisor> <channel> <value>
Matt Spinler5c7c3882016-12-20 09:28:21 -060052
Patrick Williams9e1e3a72023-06-02 19:31:04 -050053 # select channel
54 if [ "$4" != "x" ]
55 then
56 i2cset -y "$1" "$2" 0 "$4" b
57 fi
Matt Spinler5c7c3882016-12-20 09:28:21 -060058
Patrick Williams9e1e3a72023-06-02 19:31:04 -050059 # write new voltage set point
60 if [ ! -e "$5" ]
61 then
62 i2cset -y "$1" "$2" 0x21 "$(d2v "$5")" w
63 fi
Matt Spinler5c7c3882016-12-20 09:28:21 -060064
Patrick Williams9e1e3a72023-06-02 19:31:04 -050065 # print voltage set point
66 v2d "$(i2cget -y "$1" "$2" 0x21 w)"
Matt Spinler5c7c3882016-12-20 09:28:21 -060067
Patrick Williams9e1e3a72023-06-02 19:31:04 -050068 # print voltage
69 v2d "$(i2cget -y "$1" "$2" 0x8B w)"
Matt Spinler5c7c3882016-12-20 09:28:21 -060070
Patrick Williams9e1e3a72023-06-02 19:31:04 -050071 # print current
72 i2d "$(i2cget -y "$1" "$2" 0x8C w)" "$3"
Matt Spinler5c7c3882016-12-20 09:28:21 -060073
Patrick Williams9e1e3a72023-06-02 19:31:04 -050074 # default back to channel 0
75 if [ "$4" != "x" ]
76 then
77 i2cset -y "$1" "$2" 0 0 b
78 fi
Matt Spinler5c7c3882016-12-20 09:28:21 -060079}
80
81
82# #########################################################
83# Main
84
Patrick Williams9e1e3a72023-06-02 19:31:04 -050085if [ -e "$1" ]
Matt Spinler5c7c3882016-12-20 09:28:21 -060086then
Patrick Williams9e1e3a72023-06-02 19:31:04 -050087 $0 vdda vcsa vdna vioa vddra vppa vddb vcsb vdnb viob vddrb vppb
88 exit
Matt Spinler5c7c3882016-12-20 09:28:21 -060089fi
90
Patrick Williams9e1e3a72023-06-02 19:31:04 -050091if [ "$1" == "-h" ]
Matt Spinler5c7c3882016-12-20 09:28:21 -060092then
Patrick Williams9e1e3a72023-06-02 19:31:04 -050093 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 Spinler5c7c3882016-12-20 09:28:21 -0600100fi
101
102echo "rail set read current"
103echo "------- ------- ------- -------"
Patrick Williams9e1e3a72023-06-02 19:31:04 -0500104for param in "${@:1}"
Matt Spinler5c7c3882016-12-20 09:28:21 -0600105do
Patrick Williams9e1e3a72023-06-02 19:31:04 -0500106 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 Spinler5c7c3882016-12-20 09:28:21 -0600155done