<p>Vadim Bendebury has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/22321">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">spi/tpm.c do not waste time on wake pulses unless necessary<br><br>The Cr50 secure chip implementation is guaranteed not to fall asleep<br>for 1 second after any SPI slave activity.<br><br>Let's not waste time on the wake up ping when it is not necessary.<br><br>BRANCH=cr50<br>BUG=b:68012381<br>TEST=using a protocol analyzer verified that the wake pulses are<br>     generated only when the new Coreboot stage or Depthcharge start,<br>     not on every SPI slave transaction.<br><br>Change-Id: Id8def1470ba3eab533075b9e7180f8a58e0b00b6<br>Signed-off-by: Vadim Bendebury <vbendeb@chromium.org><br>---<br>M src/drivers/spi/tpm/tpm.c<br>1 file changed, 28 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/21/22321/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c<br>index 58bf842..c47b807 100644<br>--- a/src/drivers/spi/tpm/tpm.c<br>+++ b/src/drivers/spi/tpm/tpm.c<br>@@ -109,6 +109,9 @@<br>   struct stopwatch sw;<br>  static int tpm_sync_needed CAR_GLOBAL;<br>        struct spi_slave *spi_slave = car_get_var_ptr(&g_spi_slave);<br>+     int wakeup_needed = 1;<br>+       static long prev_us CAR_GLOBAL;<br>+      struct mono_time mt;<br> <br>       /* Wait for tpm to finish previous transaction if needed */<br>   if (car_get_var(tpm_sync_needed))<br>@@ -116,11 +119,31 @@<br>      else<br>          car_set_var(tpm_sync_needed, 1);<br> <br>-  /* Try to wake cr50 if it is asleep. */<br>-      spi_claim_bus(spi_slave);<br>-    udelay(1);<br>-   spi_release_bus(spi_slave);<br>-  udelay(100);<br>+ if (IS_ENABLED(CONFIG_HAVE_MONOTONIC_TIMER)) {<br>+               timer_monotonic_get(&mt);<br>+<br>+             if (car_get_var(prev_us))<br>+                    /*<br>+                    * If there is a timestamp, check if SPI slave timeout<br>+                        * has expired.<br>+                       *<br>+                    * The Cr50 on H1 does not go to sleep for 1 second<br>+                   * after any SPI slave activity, let's be conservative<br>+                    * and limit the window to 900 ms.<br>+                    */<br>+                  if (mt.microseconds <<br>+                         (car_get_var(prev_us) + 900 * 1000))<br>+                             wakeup_needed = 0;<br>+           car_set_var(prev_us, mt.microseconds);<br>+       }<br>+<br>+ if (wakeup_needed) {<br>+         /* Just in case Cr50 is asleep. */<br>+           spi_claim_bus(spi_slave);<br>+            udelay(1);<br>+           spi_release_bus(spi_slave);<br>+          udelay(100);<br>+ }<br> <br>  /*<br>     * The first byte of the frame header encodes the transaction type<br></pre><p>To view, visit <a href="https://review.coreboot.org/22321">change 22321</a>. To unsubscribe, 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/22321"/><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: Id8def1470ba3eab533075b9e7180f8a58e0b00b6 </div>
<div style="display:none"> Gerrit-Change-Number: 22321 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Vadim Bendebury <vbendeb@chromium.org> </div>