summaryrefslogtreecommitdiff
path: root/src/drivers/spi/tpm/tis.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/spi/tpm/tis.c')
-rw-r--r--src/drivers/spi/tpm/tis.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/src/drivers/spi/tpm/tis.c b/src/drivers/spi/tpm/tis.c
index 6fa6c82848..90d7f59ba9 100644
--- a/src/drivers/spi/tpm/tis.c
+++ b/src/drivers/spi/tpm/tis.c
@@ -5,8 +5,6 @@
#include "tpm.h"
-static unsigned int tpm_is_open;
-
static const struct {
uint16_t vid;
uint16_t did;
@@ -29,31 +27,33 @@ static const char *tis_get_dev_name(struct tpm2_info *info)
return "Unknown";
}
-tpm_result_t tis_open(void)
+static tpm_result_t tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
+ uint8_t *recvbuf, size_t *rbuf_len)
{
- if (tpm_is_open) {
- printk(BIOS_ERR, "%s() called twice.\n", __func__);
+ int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
+
+ if (len == 0)
return TPM_CB_FAIL;
- }
+
+ *rbuf_len = len;
+
return TPM_SUCCESS;
}
-tpm_result_t tis_init(void)
+tis_sendrecv_fn tis_probe(void)
{
struct spi_slave spi;
struct tpm2_info info;
- tpm_result_t rc = TPM_SUCCESS;
if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS,
CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) {
printk(BIOS_ERR, "Failed to setup TPM SPI slave\n");
- return TPM_CB_FAIL;
+ return NULL;
}
- rc = tpm2_init(&spi);
- if (rc) {
+ if (tpm2_init(&spi)) {
printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n");
- return rc;
+ return NULL;
}
tpm2_get_info(&info);
@@ -61,18 +61,5 @@ tpm_result_t tis_init(void)
printk(BIOS_INFO, "Initialized TPM device %s revision %d\n",
tis_get_dev_name(&info), info.revision);
- return TPM_SUCCESS;
-}
-
-tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
- uint8_t *recvbuf, size_t *rbuf_len)
-{
- int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
-
- if (len == 0)
- return TPM_CB_FAIL;
-
- *rbuf_len = len;
-
- return TPM_SUCCESS;
+ return &tpm_sendrecv;
}