witherspoon: Only rebind ucd9000 if we unbound it

This makes way for an incoming kernel patch affecting Witherspoon[1],
where we disable the UCD90160 device in the devicetree. If the driver
hasn't been bound to the device we can immediately proceed to invoking
i2c{g,s}et. Finally if it wasn't bound before the script was executed
then don't try to rebind it, as it was disabled for a reason

[1] https://lists.ozlabs.org/pipermail/openbmc/2017-March/007015.html

Change-Id: Icc1fd1aa978e1a5cd62f1609bae97aa7dbfcde41
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/meta-witherspoon/recipes-phosphor/chassis/vcs-pre-post/ucd_disable_vcs.sh b/meta-witherspoon/recipes-phosphor/chassis/vcs-pre-post/ucd_disable_vcs.sh
index b52a68b..e529049 100644
--- a/meta-witherspoon/recipes-phosphor/chassis/vcs-pre-post/ucd_disable_vcs.sh
+++ b/meta-witherspoon/recipes-phosphor/chassis/vcs-pre-post/ucd_disable_vcs.sh
@@ -6,13 +6,17 @@
 # 11/10/16 PGR - unbind/bind UCD driver
 
 ucd_retries=5
+ucd=
 
 # unbind ucd driver to permit i2cset
 ucdpath="/sys/bus/i2c/drivers/ucd9000"
 if [ -e $ucdpath ]
 then
-  ucd=`ls $ucdpath | grep 64`
-  echo $ucd > $ucdpath/unbind
+  ucd=`ls -1 $ucdpath | grep 64`
+  if [ -n "$ucd" ]
+  then
+    echo $ucd > $ucdpath/unbind
+  fi
 fi
 
 # Setup UCD module (in standby) to disable VCS rails from power-on:
@@ -28,8 +32,8 @@
 i2cset -y 11 0x64 0x00 0x0F i
 i2cset -y 11 0x64 0x02 0x1A i
 
-# re-bind ucd driver
-if [ -e $ucdpath ]; then
+# re-bind ucd driver only if we unbound it (i.e. ucd has been set with a value)
+if [ -e $ucdpath -a -n "$ucd" ]; then
   j=0
   until [ $j -ge $ucd_retries ] || [ -e $ucdpath/$ucd ]; do
     j=$((j+1))