Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 1 | #!/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 | |
| 7 | cpu0_i2c_bus="7" |
| 8 | cpu1_i2c_bus="8" |
Gunnar Mills | 46ca7cd | 2018-06-13 15:54:55 -0500 | [diff] [blame] | 9 | buses="$cpu0_i2c_bus $cpu1_i2c_bus" |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 10 | vdd_i2c_addr_page="0x60:0x01" |
| 11 | vdn_i2c_addr_page="0x64:0x01" |
| 12 | vcs_i2c_addr_page="0x64:0x00" |
| 13 | addrs_pages="$vdd_i2c_addr_page $vdn_i2c_addr_page $vcs_i2c_addr_page" |
| 14 | |
Robert Lippert | bd3c386 | 2017-05-26 12:48:59 -0700 | [diff] [blame^] | 15 | i2c_path="/sys/bus/i2c/devices/" |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 16 | |
| 17 | # Usage: vrm_avs_enable <bus> <i2c_address> <page> |
Xo Wang | 02fd4a0 | 2017-03-14 16:15:29 -0700 | [diff] [blame] | 18 | # Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 19 | vrm_avs_enable() |
| 20 | { |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 21 | echo Enabling AVSBus on bus $1 VRM @$2 rail $3... |
Robert Lippert | bd3c386 | 2017-05-26 12:48:59 -0700 | [diff] [blame^] | 22 | echo 1 > $(echo ${i2c_path}/$1-$(printf "%04x" $2)/hwmon/hwmon*/avs$(printf "%d" $3)_enable) |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 23 | } |
| 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 |
| 30 | vrm_avs_disable() |
| 31 | { |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 32 | echo Disabling AVSBus on bus $1 VRM @$2 rail $3... |
Robert Lippert | bd3c386 | 2017-05-26 12:48:59 -0700 | [diff] [blame^] | 33 | echo 0 > $(echo ${i2c_path}/$1-$(printf "%04x" $2)/hwmon/hwmon*/avs$(printf "%d" $3)_enable) |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Xo Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 36 | # Usage: vrm_vout_max_1v1 <bus> <i2c_address> <page> |
| 37 | # Sets VOUT_MAX to 1.1V |
| 38 | vrm_vout_max_1v1() |
| 39 | { |
Xo Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 40 | echo Setting VOUT_MAX=[1.1V] on bus $1 VRM @$2 rail $3... |
Robert Lippert | bd3c386 | 2017-05-26 12:48:59 -0700 | [diff] [blame^] | 41 | echo 1100 > ${i2c_path}/$1-$(printf "%04x" $2)/vout$(printf "%d" $3)_max |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | # Usage: for_each_rail <command> |
| 45 | # <command> will be invoked with <bus> <i2c_address> <page> |
| 46 | for_each_rail() |
| 47 | { |
Gunnar Mills | 46ca7cd | 2018-06-13 15:54:55 -0500 | [diff] [blame] | 48 | for bus in $buses |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 49 | do |
| 50 | for addr_page in $addrs_pages |
| 51 | do |
| 52 | $1 $bus `echo $addr_page | tr : " "` |
| 53 | done |
| 54 | done |
| 55 | } |
| 56 | |
| 57 | if [ "$1" == "enable" ] |
| 58 | then |
| 59 | for_each_rail vrm_avs_enable |
| 60 | elif [ "$1" == "disable" ] |
| 61 | then |
| 62 | for_each_rail vrm_avs_disable |
Xo Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 63 | elif [ "$1" == "vdn_max" ] |
| 64 | then |
| 65 | addrs_pages="$vdn_i2c_addr_page" |
| 66 | for_each_rail vrm_vout_max_1v1 |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 67 | else |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 68 | echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus" |
Xo Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 69 | echo "\"$0 <vdn_max>\" to set VDN rails VOUT_MAX to 1.1V" |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 70 | fi |