Servo V3: Remap fw_wp to gpio.

fw_wp is no longer controlled via i2c rather it is now a gpio: gpio2_2.

However gpio2_2 is not properly labelled in the omap_muxes. So it's
muxfile needs to be hard-coded rather than found automatically. This
change allows muxfile to be properly piped into the gpio wr_rd function.

BUG=chromium:268611
TEST=dut-control with link at desk. FAFT test failed before to set fw_wp
and now the test works and passes.

Change-Id: Id8b233bd2a317eef19805273058c75c1ee78750b
Reviewed-on: https://gerrit.chromium.org/gerrit/64803
Tested-by: Simran Basi <sbasi@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
diff --git a/servo/bbgpio.py b/servo/bbgpio.py
index 653ab31..f47118c 100644
--- a/servo/bbgpio.py
+++ b/servo/bbgpio.py
@@ -15,6 +15,7 @@
 UNEXPORT_FILE = os.path.join(GPIO_ROOT, 'unexport')
 GPIO_PIN_PATTERN = os.path.join(GPIO_ROOT, 'gpio%d')
 GPIO_MODE_VALUE = 0x3
+GPIO_SELECT_VALUE = 7
 DIR_IN = 0
 DIR_OUT = 1
 DIR_VAL_MAP = {DIR_IN  : 'in',
@@ -103,7 +104,8 @@
       f.write(DIR_VAL_MAP[dir_val])
 
 
-  def wr_rd(self, offset, width, dir_val=None, wr_val=None, chip=None):
+  def wr_rd(self, offset, width, dir_val=None, wr_val=None, chip=None,
+            muxfile=None):
     """Write and/or read GPIO bit.
 
     Args:
@@ -116,12 +118,16 @@
       wr_val  : value to write to the GPIO.  Note wr_val is irrelevant if
                 dir_val = 0
       chip    : beaglebone gpio chip number.
+      muxfile : used to specify the correct omap_mux muxfile to select this
+                gpio.
+
 
     Returns:
       integer value from reading the gpio value ( masked & aligned )
     """
     self._logger.debug('offset: %s, width:%s, dir_val: %s, wr_val: %s, '
-                       'chip: %s', offset, width, dir_val, wr_val, chip)
+                       'chip: %s, muxfile: %s', offset, width, dir_val, wr_val,
+                       chip, muxfile)
     if not chip:
       raise BBgpioError('BBgpio requires chip id for writes and reads.')
     rd_val = 0
@@ -129,7 +135,11 @@
     gpio_name = 'gpio%s_%s' % (chip, offset)
     gpio_index = 32 * int(chip, 0) + offset
 
-    self._bbmux_controller.set_pin_mode(gpio_name, GPIO_MODE_VALUE)
+    if muxfile:
+        self._bbmux_controller.set_muxfile(muxfile, GPIO_MODE_VALUE,
+                                           GPIO_SELECT_VALUE)
+    else:
+        self._bbmux_controller.set_pin_mode(gpio_name, GPIO_MODE_VALUE)
 
     self._export_gpio(gpio_index)
     gpio_path = GPIO_PIN_PATTERN % gpio_index
diff --git a/servo/data/servo_v3_r0.xml b/servo/data/servo_v3_r0.xml
index abc8994..edb15f4 100644
--- a/servo/data/servo_v3_r0.xml
+++ b/servo/data/servo_v3_r0.xml
@@ -117,8 +117,8 @@
     <doc>Firmware write-protect GPIO</doc>
     <params cmd="get" interface="2" drv="tca6416" slv="0x20"
     port="1" offset="3" map="onoff_i"></params>
-    <params cmd="set" interface="2" drv="tca6416" slv="0x22"
-    port="1" offset="5" map="onoff_i"></params>
+    <params cmd="set" interface="1" muxfile="gpmc_advn_ale" drv="gpio" chip="2"
+    offset="2" map="onoff_i"></params>
   </control>
   <control>
     <name>pwr_button</name>
diff --git a/servo/drv/gpio.py b/servo/drv/gpio.py
index b31cff9..5665c44 100644
--- a/servo/drv/gpio.py
+++ b/servo/drv/gpio.py
@@ -26,8 +26,9 @@
 
   def __init__(self, interface, params):
     super(gpio, self).__init__(interface, params)
-    # TODO (sbasi/tbroch) crbug.com/241507 - Deprecate Chip param.
+    # TODO (sbasi/tbroch) crbug.com/241507 - Deprecate chip & muxfile params.
     self._chip = params.get('chip', None)
+    self._muxfile = params.get('muxfile', None)
 
   def get(self):
     """Get value for gpio driver
@@ -44,7 +45,8 @@
     if hasattr(self._interface, 'gpio_wr_rd'):
       return self._interface.gpio_wr_rd(offset, width)
     else:
-      return self._interface.wr_rd(offset, width, chip=self._chip)
+      return self._interface.wr_rd(offset, width, chip=self._chip,
+                                   muxfile=self._muxfile)
 
   def set(self, value):
     """Set value for gpio driver
@@ -71,7 +73,8 @@
     if hasattr(self._interface, 'gpio_wr_rd'):
       self._interface.gpio_wr_rd(offset, width, is_output, value)
     else:
-      self._interface.wr_rd(offset, width, is_output, value, chip=self._chip)
+      self._interface.wr_rd(offset, width, is_output, value, chip=self._chip,
+                            muxfile=self._muxfile)
 
   def _get_common_params(self):
     """Get common parameters for gpio control
diff --git a/servo/ftdigpio.py b/servo/ftdigpio.py
index b57323e..3c852d8 100755
--- a/servo/ftdigpio.py
+++ b/servo/ftdigpio.py
@@ -110,7 +110,8 @@
       raise FgpioError("doing fgpio_close", err)
     self._is_closed = True
 
-  def wr_rd(self, offset, width, dir_val=None, wr_val=None, chip=None):
+  def wr_rd(self, offset, width, dir_val=None, wr_val=None, chip=None,
+            muxfile=None):
     """Write and/or read GPIO bit.
 
     Args:
@@ -123,6 +124,7 @@
       wr_val  : value to write to the GPIO.  Note wr_val is irrelevant if
                 dir_val = 0
       chip    : Not used. defaulted to None.
+      muxfile : Not used. defaulted to None.
 
     Returns:
       integer value from reading the gpio value ( masked & aligned )
diff --git a/servo/gpio_interface.py b/servo/gpio_interface.py
index 7369c39..15c4fee 100644
--- a/servo/gpio_interface.py
+++ b/servo/gpio_interface.py
@@ -13,7 +13,8 @@
     """Close access to GPIO's."""
     raise NotImplementedError('close not yet implemented.')
 
-  def wr_rd(self, offset, width, dir_val=None, wr_val=None, chip=None):
+  def wr_rd(self, offset, width, dir_val=None, wr_val=None, chip=None,
+            muxfile=None):
     """Write and/or read GPIO bit.
 
     Args:
@@ -26,6 +27,8 @@
       wr_val  : value to write to the GPIO.  Note wr_val is irrelevant if
                 dir_val = 0
       chip    : beaglebone gpio chip number. [IF REQUIRED]
+      muxfile : used to specify the correct omap_mux muxfile to select this
+                gpio. [IF REQUIRED]
 
     Returns:
       integer value from reading the gpio value ( masked & aligned )