blob: d4176cc5114c549b4154b703f54afd8eb7283ec4 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer7cb01e02013-08-29 16:05:02 -07002
Martin Rothcddd6002019-09-23 17:38:27 -06003/*
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 Reinauer7cb01e02013-08-29 16:05:02 -070012#ifndef __DRIVERS_TPM_SLB9635_I2C_TPM_H__
13#define __DRIVERS_TPM_SLB9635_I2C_TPM_H__
14
15#include <stdint.h>
16
17enum tpm_timeout {
18 TPM_TIMEOUT = 1, /* msecs */
19};
20
Julius Wernere6cf3c62014-12-19 14:38:51 -080021/* Size of external transmit buffer (used for stack buffer in tpm_sendrecv) */
22#define TPM_BUFSIZE 1260
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070023
Duncan Lauriedca223c2016-09-14 16:27:04 -070024/* Number of bytes in the TPM header */
25#define TPM_HEADER_SIZE 10
26
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070027/* 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 Lauriedca223c2016-09-14 16:27:04 -070035#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 Dmytruk86f845a2022-10-29 18:55:24 +030040struct tpm_chip {
Sergii Dmytruk4ee03172022-12-22 19:35:25 +020041 int is_open;
Duncan Laurie40ae1702016-08-31 13:51:14 -070042 uint8_t req_complete_mask;
43 uint8_t req_complete_val;
44 uint8_t req_canceled;
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070045
Sergii Dmytruk86f845a2022-10-29 18:55:24 +030046 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 Reinauer7cb01e02013-08-29 16:05:02 -070050};
51
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070052/* ---------- Interface for TPM vendor ------------ */
53
Lee Leahy52ab30b2017-03-15 09:22:11 -070054int tpm_vendor_probe(unsigned int bus, uint32_t addr);
Duncan Laurie1ca19682016-09-07 10:52:12 -070055
Lee Leahy52ab30b2017-03-15 09:22:11 -070056int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr);
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070057
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070058#endif /* __DRIVERS_TPM_SLB9635_I2C_TPM_H__ */