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" |
| 9 | busses="$cpu0_i2c_bus $cpu1_i2c_bus" |
| 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 | |
| 15 | # Usage: vrm_set_page <bus> <i2c_address> <page> |
| 16 | vrm_set_page() |
| 17 | { |
| 18 | i2cset -y $1 $2 0x00 $3 b |
| 19 | } |
| 20 | |
| 21 | # Usage: vrm_avs_enable <bus> <i2c_address> <page> |
Xo Wang | 02fd4a0 | 2017-03-14 16:15:29 -0700 | [diff] [blame] | 22 | # Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 23 | # Sets OPERATION PMBUS register to |
| 24 | # - Enable/Disable: On |
| 25 | # - VOUT Source: AVSBus Target Rail Voltage |
| 26 | # - AVSBus Copy: VOUT_COMMAND remains unchanged |
Xo Wang | 02fd4a0 | 2017-03-14 16:15:29 -0700 | [diff] [blame] | 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. |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 31 | vrm_avs_enable() |
| 32 | { |
| 33 | vrm_set_page "$@" |
| 34 | echo Enabling AVSBus on bus $1 VRM @$2 rail $3... |
Xo Wang | 02fd4a0 | 2017-03-14 16:15:29 -0700 | [diff] [blame] | 35 | local vout_command=`i2cget -y $1 $2 0x21 w` |
| 36 | i2cset -y $1 $2 0x21 $vout_command w |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 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 |
| 45 | vrm_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 Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 52 | # Usage: vrm_vout_max_1v1 <bus> <i2c_address> <page> |
| 53 | # Sets VOUT_MAX to 1.1V |
| 54 | vrm_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 Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 61 | # Usage: vrm_print <bus> <i2c_address> <page> |
| 62 | vrm_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> |
| 73 | for_each_rail() |
| 74 | { |
| 75 | for bus in $busses |
| 76 | do |
| 77 | for addr_page in $addrs_pages |
| 78 | do |
| 79 | $1 $bus `echo $addr_page | tr : " "` |
| 80 | done |
| 81 | done |
| 82 | } |
| 83 | |
| 84 | if [ "$1" == "enable" ] |
| 85 | then |
| 86 | for_each_rail vrm_avs_enable |
| 87 | elif [ "$1" == "disable" ] |
| 88 | then |
| 89 | for_each_rail vrm_avs_disable |
Xo Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 90 | elif [ "$1" == "vdn_max" ] |
| 91 | then |
| 92 | addrs_pages="$vdn_i2c_addr_page" |
| 93 | for_each_rail vrm_vout_max_1v1 |
Xo Wang | 61a1001 | 2016-12-15 18:29:58 -0800 | [diff] [blame] | 94 | else |
| 95 | for_each_rail vrm_print |
| 96 | echo "\"$0 <enable|disable>\" to control whether VRMs use AVSBus" |
Xo Wang | 41c193f | 2017-02-15 17:10:15 -0800 | [diff] [blame] | 97 | 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] | 98 | fi |