<p>Patrick Rudolph has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/29204">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ec/lenovo/h8: Wait for sense ready<br><br>Wait for the EC to fully boot before jumping to payload.<br>The probed registers reads as zero until the EC is ready.<br><br>Tested on Lenovo T500.<br><br>Change-Id: Ie27e2881a256c4efb3def11f05070c446db6e5fc<br>Signed-off-by: Patrick Rudolph <siro@das-labor.org><br>---<br>M src/ec/lenovo/h8/Makefile.inc<br>M src/ec/lenovo/h8/h8.c<br>M src/ec/lenovo/h8/h8.h<br>A src/ec/lenovo/h8/sense.c<br>4 files changed, 79 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/04/29204/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/ec/lenovo/h8/Makefile.inc b/src/ec/lenovo/h8/Makefile.inc</span><br><span>index e4408f1..6e98636 100644</span><br><span>--- a/src/ec/lenovo/h8/Makefile.inc</span><br><span>+++ b/src/ec/lenovo/h8/Makefile.inc</span><br><span>@@ -1,5 +1,9 @@</span><br><span> ifeq ($(CONFIG_EC_LENOVO_H8),y)</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += sense.c</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-y += sense.c</span><br><span style="color: hsl(120, 100%, 40%);">+smm-y += sense.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ifneq ($(filter y,$(CONFIG_H8_BEEP_ON_DEATH) $(CONFIG_H8_FLASH_LEDS_ON_DEATH)),)</span><br><span> romstage-y += panic.c</span><br><span> ramstage-y += panic.c</span><br><span>diff --git a/src/ec/lenovo/h8/h8.c b/src/ec/lenovo/h8/h8.c</span><br><span>index 1f1655d..b4f1baa 100644</span><br><span>--- a/src/ec/lenovo/h8/h8.c</span><br><span>+++ b/src/ec/lenovo/h8/h8.c</span><br><span>@@ -24,6 +24,7 @@</span><br><span> #include <smbios.h></span><br><span> #include <pc80/mc146818rtc.h></span><br><span> #include <pc80/keyboard.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <delay.h></span><br><span> </span><br><span> #include "h8.h"</span><br><span> #include "chip.h"</span><br><span>@@ -316,7 +317,25 @@</span><br><span> #endif</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void h8_final(void *chip_info)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    int timeout = 3 * 1000;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /*</span><br><span style="color: hsl(120, 100%, 40%);">+     * Wait for sense ready.</span><br><span style="color: hsl(120, 100%, 40%);">+       * May help preventing keyboard timeouts observed in the payload.</span><br><span style="color: hsl(120, 100%, 40%);">+      */</span><br><span style="color: hsl(120, 100%, 40%);">+   while (timeout && !h8_get_sense_ready()) {</span><br><span style="color: hsl(120, 100%, 40%);">+            mdelay(1);</span><br><span style="color: hsl(120, 100%, 40%);">+            timeout--;</span><br><span style="color: hsl(120, 100%, 40%);">+    };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!timeout)</span><br><span style="color: hsl(120, 100%, 40%);">+         printk(BIOS_ERR, "H8: Failed waiting for sense ready\n");</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct chip_operations ec_lenovo_h8_ops = {</span><br><span>      CHIP_NAME("Lenovo H8 EC")</span><br><span>  .enable_dev = h8_enable,</span><br><span style="color: hsl(120, 100%, 40%);">+      .final = h8_final,</span><br><span> };</span><br><span>diff --git a/src/ec/lenovo/h8/h8.h b/src/ec/lenovo/h8/h8.h</span><br><span>index 4ac395a..c92a084 100644</span><br><span>--- a/src/ec/lenovo/h8/h8.h</span><br><span>+++ b/src/ec/lenovo/h8/h8.h</span><br><span>@@ -31,6 +31,9 @@</span><br><span> </span><br><span> void h8_mainboard_init_dock (void);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int h8_get_fn_key(void);</span><br><span style="color: hsl(120, 100%, 40%);">+int h8_get_sense_ready(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void h8_bluetooth_enable(int on);</span><br><span> bool h8_bluetooth_nv_enable(void);</span><br><span> bool h8_has_bdc(struct device *dev);</span><br><span>@@ -89,6 +92,8 @@</span><br><span> #define H8_USB_ALWAYS_ON_ENABLE               0x01</span><br><span> #define H8_USB_ALWAYS_ON_AC_ONLY        0x0c</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define H8_PASSWD_SCANCODE            0x27</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define H8_FAN_CONTROL                        0x2f</span><br><span> #define H8_FAN_CONTROL_AUTO             0x80</span><br><span> </span><br><span>@@ -130,6 +135,7 @@</span><br><span> #define H8_STATUS0            0x46</span><br><span> #define H8_STATUS1              0x47</span><br><span> #define H8_STATUS2              0x48</span><br><span style="color: hsl(120, 100%, 40%);">+#define H8_STATUS3                0x49</span><br><span> </span><br><span> #define H8_EVENT_BAT0               0x4a</span><br><span> #define H8_EVENT_BAT0_STATE     0x4b</span><br><span>diff --git a/src/ec/lenovo/h8/sense.c b/src/ec/lenovo/h8/sense.c</span><br><span>new file mode 100644</span><br><span>index 0000000..5e1f4bf</span><br><span>--- /dev/null</span><br><span>+++ b/src/ec/lenovo/h8/sense.c</span><br><span>@@ -0,0 +1,50 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Patrick Rudolph <siro@das-labor.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <ec/acpi/ec.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "h8.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Return the EC boot state.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Some registers are all zero until the EC has booted.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Wait for any register having at least one bit set.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Unlikely that all register will be zero after booting has</span><br><span style="color: hsl(120, 100%, 40%);">+ * finished.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * @return 1 if the EC provides valid data in sense status registers</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int h8_get_sense_ready(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  static const u8 regs[] = { H8_STATUS0, H8_STATUS1, H8_STATUS2,</span><br><span style="color: hsl(120, 100%, 40%);">+                        H8_STATUS3, H8_PASSWD_SCANCODE};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    for (size_t i = 0; i < ARRAY_SIZE(regs); i++)</span><br><span style="color: hsl(120, 100%, 40%);">+              if (ec_read(regs[i]))</span><br><span style="color: hsl(120, 100%, 40%);">+                 return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/**</span><br><span style="color: hsl(120, 100%, 40%);">+ * Return the state of Fn key.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Only valid if sense ready is true.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * @return 1 if the key is pressed.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int h8_get_fn_key(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  return ec_read(H8_STATUS0) & H8_STATUS0_FN_KEY_DOWN;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/29204">change 29204</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/29204"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ie27e2881a256c4efb3def11f05070c446db6e5fc </div>
<div style="display:none"> Gerrit-Change-Number: 29204 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Patrick Rudolph <siro@das-labor.org> </div>