Add a 'power_state' control to board daisy, spring and peach_pit

BUG=chromium:326738
TEST=tested all power_state settings against daisy and spring.
peach_pit will be verified after the build is staged in lab.

Change-Id: I9a524dd94a2f5a2efc00a8168237e013e3835fe4
Reviewed-on: https://chromium-review.googlesource.com/188182
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
diff --git a/servo/data/servo_daisy_overlay.xml b/servo/data/servo_daisy_overlay.xml
index 60de985..93246eb 100644
--- a/servo/data/servo_daisy_overlay.xml
+++ b/servo/data/servo_daisy_overlay.xml
@@ -8,4 +8,10 @@
     <params subtype="lid_open" interface="7" drv="daisy_ec" map="yesno"
             clobber_ok=""></params>
   </control>
+  <control>
+    <name>power_state</name>
+    <doc>Used to turn the DUT off and on</doc>
+    <params cmd="set" interface="servo" drv="daisy_power" input_type="str"
+      reset_hold="0.1" reset_recovery="0.0"/>
+  </control>
 </root>
diff --git a/servo/data/servo_peach_pit_overlay.xml b/servo/data/servo_peach_pit_overlay.xml
index 93b3452..bef3712 100644
--- a/servo/data/servo_peach_pit_overlay.xml
+++ b/servo/data/servo_peach_pit_overlay.xml
@@ -5,4 +5,11 @@
   <include>
     <name>arm_ec_common.xml</name>
   </include>
+  <!-- ******** Controls ******** -->
+  <control>
+    <name>power_state</name>
+    <doc>Used to turn the DUT off and on</doc>
+    <params cmd="set" interface="servo" drv="daisy_power" input_type="str"
+      reset_hold="0.1" reset_recovery="0.0"/>
+  </control>
 </root>
diff --git a/servo/data/servo_spring_overlay.xml b/servo/data/servo_spring_overlay.xml
index 93b3452..bef3712 100644
--- a/servo/data/servo_spring_overlay.xml
+++ b/servo/data/servo_spring_overlay.xml
@@ -5,4 +5,11 @@
   <include>
     <name>arm_ec_common.xml</name>
   </include>
+  <!-- ******** Controls ******** -->
+  <control>
+    <name>power_state</name>
+    <doc>Used to turn the DUT off and on</doc>
+    <params cmd="set" interface="servo" drv="daisy_power" input_type="str"
+      reset_hold="0.1" reset_recovery="0.0"/>
+  </control>
 </root>
diff --git a/servo/drv/__init__.py b/servo/drv/__init__.py
index 152137e..7aa7f40 100644
--- a/servo/drv/__init__.py
+++ b/servo/drv/__init__.py
@@ -9,6 +9,7 @@
 import alex_power
 import arm_ec
 import daisy_ec
+import daisy_power
 import ec
 import gpio
 import hw_driver
diff --git a/servo/drv/daisy_power.py b/servo/drv/daisy_power.py
new file mode 100644
index 0000000..b89066c
--- /dev/null
+++ b/servo/drv/daisy_power.py
@@ -0,0 +1,32 @@
+# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Driver for power_state for daisy boards.
+"""
+import time
+
+import power_state
+
+HOSTEVENT_KEYBOARD_RECOVERY = 0x00004000
+
+class daisyPower(power_state.PowerStateDriver):
+  _EC_CONSOLE_DELAY = 0.4
+
+  def _power_off(self):
+    self._cold_reset()
+    time.sleep(self._EC_CONSOLE_DELAY)
+    self._interface.power_long_press()
+
+  def _power_on(self, rec_mode):
+    if rec_mode == self.REC_ON:
+      # Reset the EC to force it back into RO code; this clears
+      # the EC_IN_RW signal, so the system CPU will trust the
+      # upcoming recovery mode request.
+      self._cold_reset()
+      # Restart the EC, but leave the system CPU off...
+      self._interface.set('ec_uart_cmd', 'reboot ap-off')
+      time.sleep(self._EC_CONSOLE_DELAY)
+      # ... and tell the EC to tell the CPU we're in recovery mode.
+      self._interface.set('ec_uart_cmd',
+                          'hostevent set %#x' % HOSTEVENT_KEYBOARD_RECOVERY)
+    self._interface.power_short_press()
\ No newline at end of file