blob: 870124296a676e29cf1a8511685ad31c4432a2ce [file] [log] [blame]
Lei YUaaad5a52016-12-27 14:43:14 +08001#!/bin/bash
2# #########################################################
Lei YU574034e2017-01-05 11:15:47 +08003# Script to run on Romulus BMC to read/set vrm voltages
Lei YUaaad5a52016-12-27 14:43:14 +08004
5
6# #########################################################
7d2v () {
8# usage: d2v <decimal volts>
9
10echo $1 | awk '{print $1 * 256 + .5}' | cut -d '.' -f 1
11}
12
13
14# #########################################################
15v2d () {
16# usage: v2d <hex val>
17
18printf " %0.3fV" `echo $1 | awk '{print $1 / 256}'`
19}
20
21
22# #########################################################
23i2d () {
24# usage: i2d <hex val> <current divisor>
25
26# parse current mantisa and exponent
27# format: SEEE ESMM MMMM MMMM
28let e=$1/0x800
29let esign=e/0x10
30let m=$1\&0x07FF
31let msign=m/0x0400
32
33if [ $msign -eq 1 ]
34then
35 # calc ones compliment
36 let m=($m^0x07FF)+1
37 m="-$m"
38fi
39if [ $esign -eq 1 ]
40then
41 # calc ones compliment
42 let e=(e^0x1F)+1
43 e="-$e"
44fi
45printf " %0.3fA\n" `echo $m $e $2 | awk '{print ($1 * 2^$2) / $3}'`
46}
47
48
49# #########################################################
50rw_vc () {
51# usage: rw_vc <bus> <addr> <current divisor> <channel> <value>
52
53# select channel
54if [ $4 != "x" ]
55then
56 i2cset -y $1 $2 0 $4 b
57fi
58
59# write new voltage set point
60if [ ! -e $5 ]
61then
62 i2cset -y $1 $2 0x21 `d2v $5` w
63fi
64
65# print voltage set point
66v2d `i2cget -y $1 $2 0x21 w`
67
68# print voltage
69v2d `i2cget -y $1 $2 0x8B w`
70
71# print current
72i2d `i2cget -y $1 $2 0x8C w` $3
73
74# default back to channel 0
75if [ $4 != "x" ]
76then
77 i2cset -y $1 $2 0 0 b
78fi
79}
80
81
82# #########################################################
83# Main
84
85if [ -e $1 ]
86then
Lei YU574034e2017-01-05 11:15:47 +080087 $0 vdda vcsa vdna vioa vddb vcsb vdnb viob
Lei YUaaad5a52016-12-27 14:43:14 +080088 exit
89fi
90
91if [ $1 == "-h" ]
92then
93 echo " Usage: vrm [<rail>=[value] [<rail>=[value]] ...]"
Lei YU574034e2017-01-05 11:15:47 +080094 echo " rail: vdda vcsa vdna vioa vddb vcsb vdnb viob"
Lei YUaaad5a52016-12-27 14:43:14 +080095 echo " value: volts"
96 echo
97 echo " e.g., vrm vioa=1.0 viob=1.0"
98 echo
99 exit
100fi
101
102echo "rail set read current"
103echo "------- ------- ------- -------"
104for param in ${@:1}
105do
106 rail=`echo $param | cut -d'=' -f 1`
107 val=`echo ${param}= | cut -d'=' -f 2`
108 echo -n "$rail"
109 case "$rail" in
Lei YUaaad5a52016-12-27 14:43:14 +0800110 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 0x73 2 0 $val
124 ;;
125 vdnb)
126 rw_vc 5 0x73 2 0 $val
127 ;;
128 vioa)
129 rw_vc 4 0x73 2 1 $val
130 ;;
131 viob)
132 rw_vc 5 0x73 2 1 $val
133 ;;
Lei YUaaad5a52016-12-27 14:43:14 +0800134 *)
135 echo " non-existant"
136 esac
137done