blob: c946179e023c5f49a21dcaeae26bff833ee260e8 [file] [log] [blame]
Xo Wang61a10012016-12-15 18:29:58 -08001#!/bin/sh -e
2# AVSBus control for PMBUS voltage regulator modules (VRMs)
3# Switches output voltage target between
4# - VOUT_COMMAND register (AVSBus disabled, default on Zaius)
5# - AVSBus target output (AVSBus enabled, voltage set by host)
6
7cpu0_i2c_bus="7"
8cpu1_i2c_bus="8"
9busses="$cpu0_i2c_bus $cpu1_i2c_bus"
10vdd_i2c_addr_page="0x60:0x01"
11vdn_i2c_addr_page="0x64:0x01"
12vcs_i2c_addr_page="0x64:0x00"
13addrs_pages="$vdd_i2c_addr_page $vdn_i2c_addr_page $vcs_i2c_addr_page"
14
15# Usage: vrm_set_page <bus> <i2c_address> <page>
16vrm_set_page()
17{
18 i2cset -y $1 $2 0x00 $3 b
19}
20
21# Usage: vrm_avs_enable <bus> <i2c_address> <page>
22# Sets OPERATION PMBUS register to
23# - Enable/Disable: On
24# - VOUT Source: AVSBus Target Rail Voltage
25# - AVSBus Copy: VOUT_COMMAND remains unchanged
26vrm_avs_enable()
27{
28 vrm_set_page "$@"
29 echo Enabling AVSBus on bus $1 VRM @$2 rail $3...
30 i2cset -y $1 $2 0x01 0xb0 b
31}
32
33# Usage: vrm_avs_disable <bus> <i2c_address> <page>
34# Sets OPERATION PMBUS register to
35# - Enable/Disable: On
36# - VOUT Source: VOUT_COMMAND
37# - AVSBus Copy: VOUT_COMMAND remains unchanged
38vrm_avs_disable()
39{
40 vrm_set_page "$@"
41 echo Disabling AVSBus on bus $1 VRM @$2 rail $3...
42 i2cset -y $1 $2 0x01 0x80 b
43}
44
45# Usage: vrm_print <bus> <i2c_address> <page>
46vrm_print()
47{
48 vrm_set_page "$@"
49 local operation=`i2cget -y $1 $2 0x01 b`
50 local vout=`i2cget -y $1 $2 0x8b w`
51 local iout=`i2cget -y $1 $2 0x8c w`
52 echo VRM on bus $1 @$2 rail $3: OPERATION=$operation VOUT=$vout IOUT=$iout
53}
54
55# Usage: for_each_rail <command>
56# <command> will be invoked with <bus> <i2c_address> <page>
57for_each_rail()
58{
59 for bus in $busses
60 do
61 for addr_page in $addrs_pages
62 do
63 $1 $bus `echo $addr_page | tr : " "`
64 done
65 done
66}
67
68if [ "$1" == "enable" ]
69then
70 for_each_rail vrm_avs_enable
71elif [ "$1" == "disable" ]
72then
73 for_each_rail vrm_avs_disable
74else
75 for_each_rail vrm_print
76 echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus"
77fi