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>
26 TPM_TIMEOUT = 5, /* msecs */
29 /* Size of external transmit buffer (used in tpm_transmit)*/
30 #define TPM_BUFSIZE 4096
32 /* Index of Count field in TPM response buffer */
33 #define TPM_RSP_SIZE_BYTE 2
34 #define TPM_RSP_RC_BYTE 6
36 /* Max buffer size supported by our tpm */
37 #define TPM_DEV_BUFSIZE 1260
53 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
54 unsigned long duration[3]; /* msec */
56 u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
57 enum i2c_chip_type chip_type;
60 struct tpm_input_header {
66 struct tpm_output_header {
86 struct timeout_t timeout;
87 struct duration_t duration;
90 struct tpm_getcap_params_in {
96 struct tpm_getcap_params_out {
101 union tpm_cmd_header {
102 struct tpm_input_header in;
103 struct tpm_output_header out;
106 union tpm_cmd_params {
107 struct tpm_getcap_params_out getcap_out;
108 struct tpm_getcap_params_in getcap_in;
112 union tpm_cmd_header header;
113 union tpm_cmd_params params;
116 /* Max number of iterations after i2c NAK */
120 * Max number of iterations after i2c NAK for 'long' commands
122 * We need this especially for sending TPM_READY, since the cleanup after the
123 * transtion to the ready state may take some time, but it is unpredictable
124 * how long it will take.
126 #define MAX_COUNT_LONG 50
128 #define SLEEP_DURATION 60 /* in usec */
129 #define SLEEP_DURATION_LONG 210 /* in usec */
131 #define TPM_HEADER_SIZE 10
134 TPM_ACCESS_VALID = 0x80,
135 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
136 TPM_ACCESS_REQUEST_PENDING = 0x04,
137 TPM_ACCESS_REQUEST_USE = 0x02,
141 TPM_STS_VALID = 0x80,
142 TPM_STS_COMMAND_READY = 0x40,
144 TPM_STS_DATA_AVAIL = 0x10,
145 TPM_STS_DATA_EXPECT = 0x08,
149 TIS_SHORT_TIMEOUT = 750, /* ms */
150 TIS_LONG_TIMEOUT = 2000, /* ms */
153 /* expected value for DIDVID register */
154 #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
155 #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
157 #define TPM_ACCESS(l) (0x0000 | ((l) << 4))
158 #define TPM_STS(l) (0x0001 | ((l) << 4))
159 #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
160 #define TPM_DID_VID(l) (0x0006 | ((l) << 4))
169 /* Extended error numbers from linux (see errno.h) */
170 #define ECANCELED 125 /* Operation Canceled */
172 /* Timer frequency. Corresponds to msec timer resolution*/
175 #define TPM_MAX_ORDINAL 243
176 #define TPM_MAX_PROTECTED_ORDINAL 12
177 #define TPM_PROTECTED_ORDINAL_MASK 0xFF
179 #define TPM_CMD_COUNT_BYTE 2
180 #define TPM_CMD_ORDINAL_BYTE 6
183 * Array with one entry per ordinal defining the maximum amount
184 * of time the chip could take to return the result. The ordinal
185 * designation of short, medium or long is defined in a table in
186 * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
187 * values of the SHORT, MEDIUM, and LONG durations are retrieved
188 * from the chip during initialization with a call to tpm_get_timeouts.
190 static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = {
191 TPM_UNDEFINED, /* 0 */
196 TPM_UNDEFINED, /* 5 */
205 static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
206 TPM_UNDEFINED, /* 0 */
211 TPM_UNDEFINED, /* 5 */
261 TPM_UNDEFINED, /* 55 */
281 TPM_UNDEFINED, /* 75 */
291 TPM_UNDEFINED, /* 85 */
301 TPM_UNDEFINED, /* 95 */
306 TPM_MEDIUM, /* 100 */
311 TPM_UNDEFINED, /* 105 */
341 TPM_UNDEFINED, /* 135 */
351 TPM_UNDEFINED, /* 145 */
361 TPM_UNDEFINED, /* 155 */
371 TPM_UNDEFINED, /* 165 */
381 TPM_UNDEFINED, /* 175 */
386 TPM_MEDIUM, /* 180 */
391 TPM_MEDIUM, /* 185 */
396 TPM_UNDEFINED, /* 190 */
401 TPM_UNDEFINED, /* 195 */
416 TPM_MEDIUM, /* 210 */
421 TPM_UNDEFINED, /* 215 */
431 TPM_UNDEFINED, /* 225 */
441 TPM_UNDEFINED, /* 235 */