blob: a899bc0b46a1f7180e8dfce3891d35138d95ec1c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Rong Changf6267992013-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 Changf6267992013-04-12 10:44:57 +000016 */
17
Simon Glass4cd7b782015-08-22 18:31:22 -060018#ifndef _TPM_TIS_I2C_H
19#define _TPM_TIS_I2C_H
Rong Changf6267992013-04-12 10:44:57 +000020
21#include <linux/compiler.h>
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000022#include <linux/types.h>
Rong Changf6267992013-04-12 10:44:57 +000023
24enum tpm_timeout {
Simon Glass42c8ec52015-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 Changf6267992013-04-12 10:44:57 +000030};
31
32/* Size of external transmit buffer (used in tpm_transmit)*/
33#define TPM_BUFSIZE 4096
34
Rong Changf6267992013-04-12 10:44:57 +000035/* Index of Count field in TPM response buffer */
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000036#define TPM_RSP_SIZE_BYTE 2
37#define TPM_RSP_RC_BYTE 6
Rong Changf6267992013-04-12 10:44:57 +000038
Simon Glass7c735372015-08-22 18:31:24 -060039struct tpm_chip {
40 int is_open;
Rong Changf6267992013-04-12 10:44:57 +000041 int locality;
Simon Glassb697e0f2015-08-22 18:31:38 -060042 u32 vend_dev;
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000043 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
Christophe Ricard1259dcd2016-01-21 23:27:12 +010044 ulong chip_type;
Rong Changf6267992013-04-12 10:44:57 +000045};
46
Rong Changf6267992013-04-12 10:44:57 +000047struct tpm_input_header {
48 __be16 tag;
49 __be32 length;
50 __be32 ordinal;
51} __packed;
52
53struct tpm_output_header {
54 __be16 tag;
55 __be32 length;
56 __be32 return_code;
57} __packed;
58
59struct timeout_t {
60 __be32 a;
61 __be32 b;
62 __be32 c;
63 __be32 d;
64} __packed;
65
66struct duration_t {
67 __be32 tpm_short;
68 __be32 tpm_medium;
69 __be32 tpm_long;
70} __packed;
71
72union cap_t {
73 struct timeout_t timeout;
74 struct duration_t duration;
75};
76
77struct tpm_getcap_params_in {
78 __be32 cap;
79 __be32 subcap_size;
80 __be32 subcap;
81} __packed;
82
83struct tpm_getcap_params_out {
84 __be32 cap_size;
85 union cap_t cap;
86} __packed;
87
88union tpm_cmd_header {
89 struct tpm_input_header in;
90 struct tpm_output_header out;
91};
92
93union tpm_cmd_params {
94 struct tpm_getcap_params_out getcap_out;
95 struct tpm_getcap_params_in getcap_in;
96};
97
98struct tpm_cmd_t {
99 union tpm_cmd_header header;
100 union tpm_cmd_params params;
101} __packed;
102
Simon Glass13894bd2015-08-22 18:31:27 -0600103/* Max number of iterations after i2c NAK */
104#define MAX_COUNT 3
105
106/*
107 * Max number of iterations after i2c NAK for 'long' commands
108 *
109 * We need this especially for sending TPM_READY, since the cleanup after the
110 * transtion to the ready state may take some time, but it is unpredictable
111 * how long it will take.
112 */
113#define MAX_COUNT_LONG 50
114
Simon Glass13894bd2015-08-22 18:31:27 -0600115enum tis_access {
116 TPM_ACCESS_VALID = 0x80,
117 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
118 TPM_ACCESS_REQUEST_PENDING = 0x04,
119 TPM_ACCESS_REQUEST_USE = 0x02,
120};
121
122enum tis_status {
123 TPM_STS_VALID = 0x80,
124 TPM_STS_COMMAND_READY = 0x40,
125 TPM_STS_GO = 0x20,
126 TPM_STS_DATA_AVAIL = 0x10,
127 TPM_STS_DATA_EXPECT = 0x08,
128};
129
Rong Changf6267992013-04-12 10:44:57 +0000130#endif