blob: 45e60664adb52a19ebc4a7f5371299b10aa3b376 [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"
Gunnar Mills46ca7cd2018-06-13 15:54:55 -05009buses="$cpu0_i2c_bus $cpu1_i2c_bus"
Xo Wang61a10012016-12-15 18:29:58 -080010vdd_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>
Xo Wang02fd4a02017-03-14 16:15:29 -070022# Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND
Xo Wang61a10012016-12-15 18:29:58 -080023# Sets OPERATION PMBUS register to
24# - Enable/Disable: On
25# - VOUT Source: AVSBus Target Rail Voltage
26# - AVSBus Copy: VOUT_COMMAND remains unchanged
Xo Wang02fd4a02017-03-14 16:15:29 -070027# 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.
Xo Wang61a10012016-12-15 18:29:58 -080031vrm_avs_enable()
32{
33 vrm_set_page "$@"
34 echo Enabling AVSBus on bus $1 VRM @$2 rail $3...
Xo Wang02fd4a02017-03-14 16:15:29 -070035 local vout_command=`i2cget -y $1 $2 0x21 w`
36 i2cset -y $1 $2 0x21 $vout_command w
Xo Wang61a10012016-12-15 18:29:58 -080037 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
Xo Wang41c193f2017-02-15 17:10:15 -080052# 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
Xo Wang61a10012016-12-15 18:29:58 -080061# 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 Mills46ca7cd2018-06-13 15:54:55 -050075 for bus in $buses
Xo Wang61a10012016-12-15 18:29:58 -080076 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
Xo Wang41c193f2017-02-15 17:10:15 -080090elif [ "$1" == "vdn_max" ]
91then
92 addrs_pages="$vdn_i2c_addr_page"
93 for_each_rail vrm_vout_max_1v1
Xo Wang61a10012016-12-15 18:29:58 -080094else
95 for_each_rail vrm_print
96 echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus"
Xo Wang41c193f2017-02-15 17:10:15 -080097 echo "\"$0 <vdn_max>\" to set VDN rails VOUT_MAX to 1.1V"
Xo Wang61a10012016-12-15 18:29:58 -080098fi