drivers: Get rid of unnecessary blank lines {before,after} brace
[coreboot.git] / src / drivers / spi / tpm / tis.c
blobda4c1a882ca6fb13041a736d87f43ba07d2271b8
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <console/console.h>
4 #include <security/tpm/tis.h>
6 #include "tpm.h"
8 static unsigned int tpm_is_open;
10 static const struct {
11 uint16_t vid;
12 uint16_t did;
13 const char *device_name;
14 } dev_map[] = {
15 { 0x15d1, 0x001b, "SLB9670" },
16 { 0x1ae0, 0x0028, "CR50" },
17 { 0x104a, 0x0000, "ST33HTPH2E32" },
20 static const char *tis_get_dev_name(struct tpm2_info *info)
22 int i;
24 for (i = 0; i < ARRAY_SIZE(dev_map); i++)
25 if ((dev_map[i].vid == info->vendor_id) &&
26 (dev_map[i].did == info->device_id))
27 return dev_map[i].device_name;
28 return "Unknown";
31 int tis_open(void)
33 if (tpm_is_open) {
34 printk(BIOS_ERR, "%s() called twice.\n", __func__);
35 return -1;
37 return 0;
40 int tis_close(void)
42 if (tpm_is_open) {
44 * Do we need to do something here, like waiting for a
45 * transaction to stop?
47 tpm_is_open = 0;
50 return 0;
53 int tis_init(void)
55 struct spi_slave spi;
56 struct tpm2_info info;
58 if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS,
59 CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) {
60 printk(BIOS_ERR, "Failed to setup TPM SPI slave\n");
61 return -1;
64 if (tpm2_init(&spi)) {
65 printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n");
66 return -1;
69 tpm2_get_info(&info);
71 printk(BIOS_INFO, "Initialized TPM device %s revision %d\n",
72 tis_get_dev_name(&info), info.revision);
74 return 0;
77 int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
78 uint8_t *recvbuf, size_t *rbuf_len)
80 int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
82 if (len == 0)
83 return -1;
85 *rbuf_len = len;
87 return 0;