1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2011 Infineon Technologies
11 * Device driver for TCG/TCPA TPM (trusted platform module).
12 * Specifications at www.trustedcomputinggroup.org
14 * It is based on the Linux kernel driver tpm.c from Leendert van
15 * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
18 #ifndef _TPM_TIS_I2C_H
19 #define _TPM_TIS_I2C_H
21 #include <linux/compiler.h>
22 #include <linux/types.h>
25 * struct tpm_tis_phy_ops - low-level TPM bus operations
27 struct tpm_tis_phy_ops {
28 /* read_bytes() - Read a number of bytes from the device
31 * @addr: offset from device base
35 * @return: 0 on success, negative on failure
37 int (*read_bytes)(struct udevice *udev, u32 addr, u16 len,
39 /* write_bytes() - Read a number of bytes from the device
42 * @addr: offset from device base
44 * @value: data to write
46 * @return: 0 on success, negative on failure
48 int (*write_bytes)(struct udevice *udev, u32 addr, u16 len,
50 /* read32() - Read a 32bit value of the device
53 * @addr: offset from device base
56 * @return: 0 on success, negative on failure
58 int (*read32)(struct udevice *udev, u32 addr, u32 *result);
59 /* write32() - write a 32bit value to the device
62 * @addr: offset from device base
65 * @return: 0 on success, negative on failure
67 int (*write32)(struct udevice *udev, u32 addr, u32 src);
71 TPM_GLOBAL_INT_ENABLE = 0x80000000,
72 TPM_INTF_BURST_COUNT_STATIC = 0x100,
73 TPM_INTF_CMD_READY_INT = 0x080,
74 TPM_INTF_INT_EDGE_FALLING = 0x040,
75 TPM_INTF_INT_EDGE_RISING = 0x020,
76 TPM_INTF_INT_LEVEL_LOW = 0x010,
77 TPM_INTF_INT_LEVEL_HIGH = 0x008,
78 TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
79 TPM_INTF_STS_VALID_INT = 0x002,
80 TPM_INTF_DATA_AVAIL_INT = 0x001,
83 #define TPM_ACCESS(l) (0x0000 | ((l) << 12))
84 #define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
85 #define TPM_STS(l) (0x0018 | ((l) << 12))
86 #define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
87 #define TPM_DID_VID(l) (0x0f00 | ((l) << 12))
88 #define TPM_RID(l) (0x0f04 | ((l) << 12))
89 #define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
93 TIS_SHORT_TIMEOUT_MS = 750,
94 TIS_LONG_TIMEOUT_MS = 2000,
95 SLEEP_DURATION_US = 60,
96 SLEEP_DURATION_LONG_US = 210,
99 /* Size of external transmit buffer (used in tpm_transmit)*/
100 #define TPM_BUFSIZE 4096
102 /* Index of Count field in TPM response buffer */
103 #define TPM_RSP_SIZE_BYTE 2
104 #define TPM_RSP_RC_BYTE 6
111 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
113 struct tpm_tis_phy_ops *phy_ops;
116 struct tpm_input_header {
122 struct tpm_output_header {
142 struct timeout_t timeout;
143 struct duration_t duration;
146 struct tpm_getcap_params_in {
152 struct tpm_getcap_params_out {
157 union tpm_cmd_header {
158 struct tpm_input_header in;
159 struct tpm_output_header out;
162 union tpm_cmd_params {
163 struct tpm_getcap_params_out getcap_out;
164 struct tpm_getcap_params_in getcap_in;
168 union tpm_cmd_header header;
169 union tpm_cmd_params params;
172 /* Max number of iterations after i2c NAK */
177 * Max number of iterations after i2c NAK for 'long' commands
179 * We need this especially for sending TPM_READY, since the cleanup after the
180 * transtion to the ready state may take some time, but it is unpredictable
181 * how long it will take.
183 #define MAX_COUNT_LONG 50
186 TPM_ACCESS_VALID = 0x80,
187 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
188 TPM_ACCESS_REQUEST_PENDING = 0x04,
189 TPM_ACCESS_REQUEST_USE = 0x02,
193 TPM_STS_VALID = 0x80,
194 TPM_STS_COMMAND_READY = 0x40,
196 TPM_STS_DATA_AVAIL = 0x10,
197 TPM_STS_DATA_EXPECT = 0x08,
202 * tpm_tis_open - Open the device and request locality 0
206 * @return: 0 on success, negative on failure
208 int tpm_tis_open(struct udevice *udev);
210 * tpm_tis_close - Close the device and release locality
214 * @return: 0 on success, negative on failure
216 int tpm_tis_close(struct udevice *udev);
217 /** tpm_tis_cleanup - Get the device in ready state and release locality
223 int tpm_tis_cleanup(struct udevice *udev);
225 * tpm_tis_send - send data to the device
228 * @buf: buffer to send
229 * @len: size of the buffer
231 * @return: number of bytes sent or negative on failure
233 int tpm_tis_send(struct udevice *udev, const u8 *buf, size_t len);
235 * tpm_tis_recv_data - Receive data from a device. Wrapper for tpm_tis_recv
238 * @buf: buffer to copy data
241 * @return: bytes read or negative on failure
243 int tpm_tis_recv(struct udevice *udev, u8 *buf, size_t count);
245 * tpm_tis_get_desc - Get the TPM description
248 * @buf: buffer to fill data
251 * @return: Number of characters written (or would have been written) in buffer
253 int tpm_tis_get_desc(struct udevice *udev, char *buf, int size);
255 * tpm_tis_init - inititalize the device
259 * @return: 0 on success, negative on failure
261 int tpm_tis_init(struct udevice *udev);
263 * tpm_tis_ops_register - register the PHY ops for the device
266 * @ops: tpm_tis_phy_ops ops for the device
268 void tpm_tis_ops_register(struct udevice *udev, struct tpm_tis_phy_ops *ops);