blob: 2a160fe05c9a56828f51bf2eb5dfb1bc479166d3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Rong Chang8faa9452013-04-12 10:44:57 +00002/*
3 * Copyright (C) 2011 Infineon Technologies
4 *
5 * Authors:
6 * Peter Huewe <huewe.external@infineon.com>
7 *
8 * Version: 2.1.1
9 *
10 * Description:
11 * Device driver for TCG/TCPA TPM (trusted platform module).
12 * Specifications at www.trustedcomputinggroup.org
13 *
14 * It is based on the Linux kernel driver tpm.c from Leendert van
15 * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
Rong Chang8faa9452013-04-12 10:44:57 +000016 */
17
Simon Glass94576272015-08-22 18:31:22 -060018#ifndef _TPM_TIS_I2C_H
19#define _TPM_TIS_I2C_H
Rong Chang8faa9452013-04-12 10:44:57 +000020
21#include <linux/compiler.h>
Tom Wai-Hong Tame49fed52013-04-12 11:04:37 +000022#include <linux/types.h>
Rong Chang8faa9452013-04-12 10:44:57 +000023
24enum tpm_timeout {
Simon Glassa57bcee2015-08-22 18:31:30 -060025 TPM_TIMEOUT_MS = 5,
26 TIS_SHORT_TIMEOUT_MS = 750,
27 TIS_LONG_TIMEOUT_MS = 2000,
28 SLEEP_DURATION_US = 60,
29 SLEEP_DURATION_LONG_US = 210,
Rong Chang8faa9452013-04-12 10:44:57 +000030};
31
32/* Size of external transmit buffer (used in tpm_transmit)*/
33#define TPM_BUFSIZE 4096
34
Rong Chang8faa9452013-04-12 10:44:57 +000035/* Index of Count field in TPM response buffer */
Tom Wai-Hong Tame49fed52013-04-12 11:04:37 +000036#define TPM_RSP_SIZE_BYTE 2
37#define TPM_RSP_RC_BYTE 6
Rong Chang8faa9452013-04-12 10:44:57 +000038
Simon Glassab79b002015-08-22 18:31:24 -060039struct tpm_chip {
40 int is_open;
Rong Chang8faa9452013-04-12 10:44:57 +000041 int locality;
Simon Glasscd8cc672015-08-22 18:31:38 -060042 u32 vend_dev;
Miquel Raynal3c43d542018-05-15 11:57:04 +020043 u8 rid;
Tom Wai-Hong Tame49fed52013-04-12 11:04:37 +000044 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
Christophe Ricard26549522016-01-21 23:27:12 +010045 ulong chip_type;
Rong Chang8faa9452013-04-12 10:44:57 +000046};
47
Rong Chang8faa9452013-04-12 10:44:57 +000048struct tpm_input_header {
49 __be16 tag;
50 __be32 length;
51 __be32 ordinal;
52} __packed;
53
54struct tpm_output_header {
55 __be16 tag;
56 __be32 length;
57 __be32 return_code;
58} __packed;
59
60struct timeout_t {
61 __be32 a;
62 __be32 b;
63 __be32 c;
64 __be32 d;
65} __packed;
66
67struct duration_t {
68 __be32 tpm_short;
69 __be32 tpm_medium;
70 __be32 tpm_long;
71} __packed;
72
73union cap_t {
74 struct timeout_t timeout;
75 struct duration_t duration;
76};
77
78struct tpm_getcap_params_in {
79 __be32 cap;
80 __be32 subcap_size;
81 __be32 subcap;
82} __packed;
83
84struct tpm_getcap_params_out {
85 __be32 cap_size;
86 union cap_t cap;
87} __packed;
88
89union tpm_cmd_header {
90 struct tpm_input_header in;
91 struct tpm_output_header out;
92};
93
94union tpm_cmd_params {
95 struct tpm_getcap_params_out getcap_out;
96 struct tpm_getcap_params_in getcap_in;
97};
98
99struct tpm_cmd_t {
100 union tpm_cmd_header header;
101 union tpm_cmd_params params;
102} __packed;
103
Simon Glass6a7e7cc2015-08-22 18:31:27 -0600104/* Max number of iterations after i2c NAK */
105#define MAX_COUNT 3
106
Johannes Holland5010edd2020-05-11 15:22:25 +0200107#ifndef __TPM_V2_H
Simon Glass6a7e7cc2015-08-22 18:31:27 -0600108/*
109 * Max number of iterations after i2c NAK for 'long' commands
110 *
111 * We need this especially for sending TPM_READY, since the cleanup after the
112 * transtion to the ready state may take some time, but it is unpredictable
113 * how long it will take.
114 */
115#define MAX_COUNT_LONG 50
116
Simon Glass6a7e7cc2015-08-22 18:31:27 -0600117enum tis_access {
118 TPM_ACCESS_VALID = 0x80,
119 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
120 TPM_ACCESS_REQUEST_PENDING = 0x04,
121 TPM_ACCESS_REQUEST_USE = 0x02,
122};
123
124enum tis_status {
125 TPM_STS_VALID = 0x80,
126 TPM_STS_COMMAND_READY = 0x40,
127 TPM_STS_GO = 0x20,
128 TPM_STS_DATA_AVAIL = 0x10,
129 TPM_STS_DATA_EXPECT = 0x08,
130};
Johannes Holland5010edd2020-05-11 15:22:25 +0200131#endif
Simon Glass6a7e7cc2015-08-22 18:31:27 -0600132
Rong Chang8faa9452013-04-12 10:44:57 +0000133#endif