blob: d960ba77c4409c3b827376cf9bf87b0083882b7f [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
Robert Lippertbd3c3862017-05-26 12:48:59 -070015i2c_path="/sys/bus/i2c/devices/"
Xo Wang61a10012016-12-15 18:29:58 -080016
17# Usage: vrm_avs_enable <bus> <i2c_address> <page>
Xo Wang02fd4a02017-03-14 16:15:29 -070018# Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND
Xo Wang61a10012016-12-15 18:29:58 -080019vrm_avs_enable()
20{
Xo Wang61a10012016-12-15 18:29:58 -080021 echo Enabling AVSBus on bus $1 VRM @$2 rail $3...
Robert Lippertbd3c3862017-05-26 12:48:59 -070022 echo 1 > $(echo ${i2c_path}/$1-$(printf "%04x" $2)/hwmon/hwmon*/avs$(printf "%d" $3)_enable)
Xo Wang61a10012016-12-15 18:29:58 -080023}
24
25# Usage: vrm_avs_disable <bus> <i2c_address> <page>
26# Sets OPERATION PMBUS register to
27# - Enable/Disable: On
28# - VOUT Source: VOUT_COMMAND
29# - AVSBus Copy: VOUT_COMMAND remains unchanged
30vrm_avs_disable()
31{
Xo Wang61a10012016-12-15 18:29:58 -080032 echo Disabling AVSBus on bus $1 VRM @$2 rail $3...
Robert Lippertbd3c3862017-05-26 12:48:59 -070033 echo 0 > $(echo ${i2c_path}/$1-$(printf "%04x" $2)/hwmon/hwmon*/avs$(printf "%d" $3)_enable)
Xo Wang61a10012016-12-15 18:29:58 -080034}
35
Xo Wang41c193f2017-02-15 17:10:15 -080036# Usage: vrm_vout_max_1v1 <bus> <i2c_address> <page>
37# Sets VOUT_MAX to 1.1V
38vrm_vout_max_1v1()
39{
Xo Wang41c193f2017-02-15 17:10:15 -080040 echo Setting VOUT_MAX=[1.1V] on bus $1 VRM @$2 rail $3...
Robert Lippertbd3c3862017-05-26 12:48:59 -070041 echo 1100 > ${i2c_path}/$1-$(printf "%04x" $2)/vout$(printf "%d" $3)_max
Xo Wang61a10012016-12-15 18:29:58 -080042}
43
44# Usage: for_each_rail <command>
45# <command> will be invoked with <bus> <i2c_address> <page>
46for_each_rail()
47{
Gunnar Mills46ca7cd2018-06-13 15:54:55 -050048 for bus in $buses
Xo Wang61a10012016-12-15 18:29:58 -080049 do
50 for addr_page in $addrs_pages
51 do
52 $1 $bus `echo $addr_page | tr : " "`
53 done
54 done
55}
56
57if [ "$1" == "enable" ]
58then
59 for_each_rail vrm_avs_enable
60elif [ "$1" == "disable" ]
61then
62 for_each_rail vrm_avs_disable
Xo Wang41c193f2017-02-15 17:10:15 -080063elif [ "$1" == "vdn_max" ]
64then
65 addrs_pages="$vdn_i2c_addr_page"
66 for_each_rail vrm_vout_max_1v1
Xo Wang61a10012016-12-15 18:29:58 -080067else
Xo Wang61a10012016-12-15 18:29:58 -080068 echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus"
Xo Wang41c193f2017-02-15 17:10:15 -080069 echo "\"$0 <vdn_max>\" to set VDN rails VOUT_MAX to 1.1V"
Xo Wang61a10012016-12-15 18:29:58 -080070fi