blob: 57e7f99b206e5208edc0791d937d602858fa2150 [file] [log] [blame]
Xo Wangb13aa512016-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 Mills8b8ba532018-06-13 15:54:55 -05009buses="$cpu0_i2c_bus $cpu1_i2c_bus"
Xo Wangb13aa512016-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
Brad Bishopaddb1462019-04-20 09:59:37 -040015i2c_path="/sys/bus/i2c/devices/"
Xo Wangb13aa512016-12-15 18:29:58 -080016
17# Usage: vrm_avs_enable <bus> <i2c_address> <page>
Xo Wangf0a463a2017-03-14 16:15:29 -070018# Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND
Xo Wangb13aa512016-12-15 18:29:58 -080019vrm_avs_enable()
20{
Xo Wangb13aa512016-12-15 18:29:58 -080021 echo Enabling AVSBus on bus $1 VRM @$2 rail $3...
Brad Bishopaddb1462019-04-20 09:59:37 -040022 echo 1 > $(echo ${i2c_path}/$1-$(printf "%04x" $2)/hwmon/hwmon*/avs$(printf "%d" $3)_enable)
Xo Wangb13aa512016-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 Wangb13aa512016-12-15 18:29:58 -080032 echo Disabling AVSBus on bus $1 VRM @$2 rail $3...
Brad Bishopaddb1462019-04-20 09:59:37 -040033 echo 0 > $(echo ${i2c_path}/$1-$(printf "%04x" $2)/hwmon/hwmon*/avs$(printf "%d" $3)_enable)
Xo Wangb13aa512016-12-15 18:29:58 -080034}
35
36# Usage: for_each_rail <command>
37# <command> will be invoked with <bus> <i2c_address> <page>
38for_each_rail()
39{
Gunnar Mills8b8ba532018-06-13 15:54:55 -050040 for bus in $buses
Xo Wangb13aa512016-12-15 18:29:58 -080041 do
42 for addr_page in $addrs_pages
43 do
44 $1 $bus `echo $addr_page | tr : " "`
45 done
46 done
47}
48
49if [ "$1" == "enable" ]
50then
51 for_each_rail vrm_avs_enable
52elif [ "$1" == "disable" ]
53then
54 for_each_rail vrm_avs_disable
55else
Xo Wangb13aa512016-12-15 18:29:58 -080056 echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus"
Xo Wangc5fa8ee2017-02-15 17:10:15 -080057 echo "\"$0 <vdn_max>\" to set VDN rails VOUT_MAX to 1.1V"
Xo Wangb13aa512016-12-15 18:29:58 -080058fi