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
40 /* Max buffer size supported by our tpm */
41 #define TPM_DEV_BUFSIZE 1260
57 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
58 unsigned long duration[3]; /* msec */
60 u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
61 enum i2c_chip_type chip_type;
64 struct tpm_input_header {
70 struct tpm_output_header {
90 struct timeout_t timeout;
91 struct duration_t duration;
94 struct tpm_getcap_params_in {
100 struct tpm_getcap_params_out {
105 union tpm_cmd_header {
106 struct tpm_input_header in;
107 struct tpm_output_header out;
110 union tpm_cmd_params {
111 struct tpm_getcap_params_out getcap_out;
112 struct tpm_getcap_params_in getcap_in;
116 union tpm_cmd_header header;
117 union tpm_cmd_params params;
120 /* Max number of iterations after i2c NAK */
124 * Max number of iterations after i2c NAK for 'long' commands
126 * We need this especially for sending TPM_READY, since the cleanup after the
127 * transtion to the ready state may take some time, but it is unpredictable
128 * how long it will take.
130 #define MAX_COUNT_LONG 50
132 #define TPM_HEADER_SIZE 10
135 TPM_ACCESS_VALID = 0x80,
136 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
137 TPM_ACCESS_REQUEST_PENDING = 0x04,
138 TPM_ACCESS_REQUEST_USE = 0x02,
142 TPM_STS_VALID = 0x80,
143 TPM_STS_COMMAND_READY = 0x40,
145 TPM_STS_DATA_AVAIL = 0x10,
146 TPM_STS_DATA_EXPECT = 0x08,
149 /* expected value for DIDVID register */
150 #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
151 #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
153 #define TPM_ACCESS(l) (0x0000 | ((l) << 4))
154 #define TPM_STS(l) (0x0001 | ((l) << 4))
155 #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
156 #define TPM_DID_VID(l) (0x0006 | ((l) << 4))
158 /* Extended error numbers from linux (see errno.h) */
159 #define ECANCELED 125 /* Operation Canceled */
161 /* Timer frequency. Corresponds to msec timer resolution */