trunks: add support for cr50 over SPI

The CR50 board has been assigned a unique vendor ID/device ID
combination, which should be accepted as valid by the trunks FTDI SPI
interface.

The 'establishment' status bit could be either present or not in the
STS register, so the code has been modified to ignore it.

Another tweak is adding a 10 ms delay between SPI transactions to
accommodate the currently slow cr50 SPS TPM driver.

BUG=chrome-os-partner:43025
TEST=with the appropriate cr50 driver modifications trunks recognizes
     cr50 as a valid device and tries to send commands to it.

Change-Id: I75e78e6895d64927487c5a36ade5743aeeade5f7
Reviewed-on: https://chromium-review.googlesource.com/288000
Tested-by: Vadim Bendebury <vbendeb@google.com>
Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org>
Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
diff --git a/trunks_ftdi_spi.cc b/trunks_ftdi_spi.cc
index a95d994..500b266 100644
--- a/trunks_ftdi_spi.cc
+++ b/trunks_ftdi_spi.cc
@@ -70,6 +70,9 @@
   unsigned char *response;
   SpiFrameHeader header;
 
+  usleep(10000);  // give it 10 ms. TODO(vbendeb): remove this once
+                  // cr50 SPS TPM driver performance is fixed.
+
   // The first byte of the frame header encodes the transaction type (read or
   // write) and size (set to lenth - 1).
   header.body[0] = (read_write ? 0x80 : 0) | 0x40 | (bytes - 1);
@@ -147,21 +150,23 @@
 
   FtdiReadReg(TPM_DID_VID_REG, sizeof(did_vid), &did_vid);
 
-  if ((did_vid & 0xffff) != 0x15d1) {
-    LOG(ERROR) << "unknown vid: 0x" << std::hex << (did_vid & 0xffff);
+  uint16_t vid = did_vid & 0xffff;
+  if ((vid != 0x15d1) && (vid != 0x1ae0)) {
+    LOG(ERROR) << "unknown did_vid: 0x" << std::hex << did_vid;
     return false;
   }
 
   // Try claiming locality zero.
   FtdiReadReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
-  if (cmd != (tpmRegValidSts | tpmEstablishment)) {
+  // tpmEstablishment can be either set or not.
+  if ((cmd & ~tpmEstablishment) != tpmRegValidSts) {
     LOG(ERROR) << "invalid reset status: 0x" << std::hex << (unsigned)cmd;
     return false;
   }
   cmd = requestUse;
   FtdiWriteReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
   FtdiReadReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
-  if (cmd != (tpmRegValidSts | activeLocality | tpmEstablishment)) {
+  if ((cmd &  ~tpmEstablishment) != (tpmRegValidSts | activeLocality)) {
     LOG(ERROR) << "failed to claim locality, status: 0x" << std::hex
                << (unsigned)cmd;
     return false;