meta-zaius: avsbus-control: Add VOUT_COMMAND workaround

When switching voltage regulator modules (VRM) on Zaius to AVSBus-
controlled operation, the initial output voltage should be copied from
the PMBus VOUT_COMMAND register. However, the Intersil VRM does not
perform the copy following the first switch from PMBus- to AVSBus-
controlled operation.

Add a workaround to the AVSBus enable step that writes the value of
VOUT_COMMAND to itself in order to initialize the otherwise BMC
inaccessible AVSBus voltage setpoint.

Signed-off-by: Xo Wang <xow@google.com>
Change-Id: I3335586d98e95eb52d44d6d31e688f9b7c292136
diff --git a/meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/recipes-phosphor/chassis/avsbus-control/zaius_avsbus.sh b/meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/recipes-phosphor/chassis/avsbus-control/zaius_avsbus.sh
index e8861f9..afe821c 100755
--- a/meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/recipes-phosphor/chassis/avsbus-control/zaius_avsbus.sh
+++ b/meta-openbmc-machines/meta-openpower/meta-ingrasys/meta-zaius/recipes-phosphor/chassis/avsbus-control/zaius_avsbus.sh
@@ -19,14 +19,21 @@
 }
 
 # Usage: vrm_avs_enable <bus> <i2c_address> <page>
+# Initializes the AVSBus VOUT setpoint to the value in PMBus VOUT_COMMAND
 # Sets OPERATION PMBUS register to
 # - Enable/Disable: On
 # - VOUT Source: AVSBus Target Rail Voltage
 # - AVSBus Copy: VOUT_COMMAND remains unchanged
+# Writes to VOUT setpoint over AVSBus will persist after the VRM is switched to
+# PMBus control. Switching back to AVSBus control restores this persisted
+# setpoint rather than re-initializing to PMBus VOUT_COMMAND. This behavior is
+# known to Intersil and writing VOUT_COMMAND over PMBus is the only workaround.
 vrm_avs_enable()
 {
     vrm_set_page "$@"
     echo Enabling AVSBus on bus $1 VRM @$2 rail $3...
+    local vout_command=`i2cget -y $1 $2 0x21 w`
+    i2cset -y $1 $2 0x21 $vout_command w
     i2cset -y $1 $2 0x01 0xb0 b
 }