blob: 31ebd8ff6c99c50997bf0ac7fd6feea8b5a745c1 [file] [log] [blame]
Brian Yangb0b8c642018-07-10 02:02:53 -04001#!/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="5"
8cpu1_i2c_bus="6"
Gunnar Mills7d273472018-08-31 12:38:46 -05009buses="$cpu0_i2c_bus $cpu1_i2c_bus"
Brian Yangb0b8c642018-07-10 02:02:53 -040010vdd_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# Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND
23# Sets OPERATION PMBUS register to
24# - Enable/Disable: On
25# - VOUT Source: AVSBus Target Rail Voltage
26# - AVSBus Copy: VOUT_COMMAND remains unchanged
27# Writes to VOUT setpoint over AVSBus will persist after the VRM is switched to
28# PMBus control. Switching back to AVSBus control restores this persisted
29# setpoint rather than re-initializing to PMBus VOUT_COMMAND. This behavior is
30# known to Intersil and writing VOUT_COMMAND over PMBus is the only workaround.
31vrm_avs_enable()
32{
33 vrm_set_page "$@"
34 echo Enabling AVSBus on bus $1 VRM @$2 rail $3...
35 local vout_command=`i2cget -y $1 $2 0x21 w`
36 i2cset -y $1 $2 0x21 $vout_command w
37 i2cset -y $1 $2 0x01 0xb0 b
38}
39
40# Usage: vrm_avs_disable <bus> <i2c_address> <page>
41# Sets OPERATION PMBUS register to
42# - Enable/Disable: On
43# - VOUT Source: VOUT_COMMAND
44# - AVSBus Copy: VOUT_COMMAND remains unchanged
45vrm_avs_disable()
46{
47 vrm_set_page "$@"
48 echo Disabling AVSBus on bus $1 VRM @$2 rail $3...
49 i2cset -y $1 $2 0x01 0x80 b
50}
51
52# Usage: vrm_vout_max_1v1 <bus> <i2c_address> <page>
53# Sets VOUT_MAX to 1.1V
54vrm_vout_max_1v1()
55{
56 vrm_set_page "$@"
57 echo Setting VOUT_MAX=[1.1V] on bus $1 VRM @$2 rail $3...
58 i2cset -y $1 $2 0x24 0x44c w
59}
60
61# Usage: vrm_print <bus> <i2c_address> <page>
62vrm_print()
63{
64 vrm_set_page "$@"
65 local operation=`i2cget -y $1 $2 0x01 b`
66 local vout=`i2cget -y $1 $2 0x8b w`
67 local iout=`i2cget -y $1 $2 0x8c w`
68 echo VRM on bus $1 @$2 rail $3: OPERATION=$operation VOUT=$vout IOUT=$iout
69}
70
71# Usage: for_each_rail <command>
72# <command> will be invoked with <bus> <i2c_address> <page>
73for_each_rail()
74{
Gunnar Mills7d273472018-08-31 12:38:46 -050075 for bus in $buses
Brian Yangb0b8c642018-07-10 02:02:53 -040076 do
77 for addr_page in $addrs_pages
78 do
79 $1 $bus `echo $addr_page | tr : " "`
80 done
81 done
82}
83
84if [ "$1" == "enable" ]
85then
86 for_each_rail vrm_avs_enable
87elif [ "$1" == "disable" ]
88then
89 for_each_rail vrm_avs_disable
90elif [ "$1" == "vdn_max" ]
91then
92 addrs_pages="$vdn_i2c_addr_page"
93 for_each_rail vrm_vout_max_1v1
94else
95 for_each_rail vrm_print
96 echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus"
97 echo "\"$0 <vdn_max>\" to set VDN rails VOUT_MAX to 1.1V"
98fi