Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 2 | |
Martin Roth | cddd600 | 2019-09-23 17:38:27 -0600 | [diff] [blame] | 3 | /* |
| 4 | * Description: |
| 5 | * Device driver for TCG/TCPA TPM (trusted platform module). |
| 6 | * Specifications at www.trustedcomputinggroup.org |
| 7 | * |
| 8 | * It is based on the Linux kernel driver tpm.c from Leendert van |
| 9 | * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall. |
| 10 | */ |
| 11 | |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 12 | #ifndef __DRIVERS_TPM_SLB9635_I2C_TPM_H__ |
| 13 | #define __DRIVERS_TPM_SLB9635_I2C_TPM_H__ |
| 14 | |
| 15 | #include <stdint.h> |
| 16 | |
| 17 | enum tpm_timeout { |
| 18 | TPM_TIMEOUT = 1, /* msecs */ |
| 19 | }; |
| 20 | |
Julius Werner | e6cf3c6 | 2014-12-19 14:38:51 -0800 | [diff] [blame] | 21 | /* Size of external transmit buffer (used for stack buffer in tpm_sendrecv) */ |
| 22 | #define TPM_BUFSIZE 1260 |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 23 | |
Duncan Laurie | dca223c | 2016-09-14 16:27:04 -0700 | [diff] [blame] | 24 | /* Number of bytes in the TPM header */ |
| 25 | #define TPM_HEADER_SIZE 10 |
| 26 | |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 27 | /* Index of fields in TPM command buffer */ |
| 28 | #define TPM_CMD_SIZE_BYTE 2 |
| 29 | #define TPM_CMD_ORDINAL_BYTE 6 |
| 30 | |
| 31 | /* Index of Count field in TPM response buffer */ |
| 32 | #define TPM_RSP_SIZE_BYTE 2 |
| 33 | #define TPM_RSP_RC_BYTE 6 |
| 34 | |
Duncan Laurie | dca223c | 2016-09-14 16:27:04 -0700 | [diff] [blame] | 35 | #define TPM_ACCESS(l) (0x0000 | ((l) << 4)) |
| 36 | #define TPM_STS(l) (0x0001 | ((l) << 4)) |
| 37 | #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4)) |
| 38 | #define TPM_DID_VID(l) (0x0006 | ((l) << 4)) |
| 39 | |
Sergii Dmytruk | 86f845a | 2022-10-29 18:55:24 +0300 | [diff] [blame] | 40 | struct tpm_chip { |
Sergii Dmytruk | 4ee0317 | 2022-12-22 19:35:25 +0200 | [diff] [blame^] | 41 | int is_open; |
Duncan Laurie | 40ae170 | 2016-08-31 13:51:14 -0700 | [diff] [blame] | 42 | uint8_t req_complete_mask; |
| 43 | uint8_t req_complete_val; |
| 44 | uint8_t req_canceled; |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 45 | |
Sergii Dmytruk | 86f845a | 2022-10-29 18:55:24 +0300 | [diff] [blame] | 46 | int (*recv)(uint8_t *buf, size_t len); |
| 47 | int (*send)(uint8_t *buf, size_t len); |
| 48 | void (*cancel)(void); |
| 49 | uint8_t (*status)(void); |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 52 | /* ---------- Interface for TPM vendor ------------ */ |
| 53 | |
Lee Leahy | 52ab30b | 2017-03-15 09:22:11 -0700 | [diff] [blame] | 54 | int tpm_vendor_probe(unsigned int bus, uint32_t addr); |
Duncan Laurie | 1ca1968 | 2016-09-07 10:52:12 -0700 | [diff] [blame] | 55 | |
Lee Leahy | 52ab30b | 2017-03-15 09:22:11 -0700 | [diff] [blame] | 56 | int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr); |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 57 | |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 58 | #endif /* __DRIVERS_TPM_SLB9635_I2C_TPM_H__ */ |