2 * Copyright (C) 2011 Infineon Technologies
5 * Peter Huewe <huewe.external@infineon.com>
10 * Device driver for TCG/TCPA TPM (trusted platform module).
11 * Specifications at www.trustedcomputinggroup.org
13 * It is based on the Linux kernel driver tpm.c from Leendert van
14 * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
16 * SPDX-License-Identifier: GPL-2.0
19 #ifndef _TPM_TIS_I2C_H
20 #define _TPM_TIS_I2C_H
22 #include <linux/compiler.h>
23 #include <linux/types.h>
27 TIS_SHORT_TIMEOUT_MS = 750,
28 TIS_LONG_TIMEOUT_MS = 2000,
29 SLEEP_DURATION_US = 60,
30 SLEEP_DURATION_LONG_US = 210,
33 /* Size of external transmit buffer (used in tpm_transmit)*/
34 #define TPM_BUFSIZE 4096
36 /* Index of Count field in TPM response buffer */
37 #define TPM_RSP_SIZE_BYTE 2
38 #define TPM_RSP_RC_BYTE 6
50 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
51 enum i2c_chip_type chip_type;
54 struct tpm_input_header {
60 struct tpm_output_header {
80 struct timeout_t timeout;
81 struct duration_t duration;
84 struct tpm_getcap_params_in {
90 struct tpm_getcap_params_out {
95 union tpm_cmd_header {
96 struct tpm_input_header in;
97 struct tpm_output_header out;
100 union tpm_cmd_params {
101 struct tpm_getcap_params_out getcap_out;
102 struct tpm_getcap_params_in getcap_in;
106 union tpm_cmd_header header;
107 union tpm_cmd_params params;
110 /* Max number of iterations after i2c NAK */
114 * Max number of iterations after i2c NAK for 'long' commands
116 * We need this especially for sending TPM_READY, since the cleanup after the
117 * transtion to the ready state may take some time, but it is unpredictable
118 * how long it will take.
120 #define MAX_COUNT_LONG 50
123 TPM_ACCESS_VALID = 0x80,
124 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
125 TPM_ACCESS_REQUEST_PENDING = 0x04,
126 TPM_ACCESS_REQUEST_USE = 0x02,
130 TPM_STS_VALID = 0x80,
131 TPM_STS_COMMAND_READY = 0x40,
133 TPM_STS_DATA_AVAIL = 0x10,
134 TPM_STS_DATA_EXPECT = 0x08,
137 /* expected value for DIDVID register */
138 #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
139 #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
141 #define TPM_ACCESS(l) (0x0000 | ((l) << 4))
142 #define TPM_STS(l) (0x0001 | ((l) << 4))
143 #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
144 #define TPM_DID_VID(l) (0x0006 | ((l) << 4))