blob: 02cc2eba42543c208f97b9c98be2a19edc62920e [file] [log] [blame]
Rong Changf6267992013-04-12 10:44:57 +00001/*
2 * Copyright (C) 2011 Infineon Technologies
3 *
4 * Authors:
5 * Peter Huewe <huewe.external@infineon.com>
6 *
7 * Version: 2.1.1
8 *
9 * Description:
10 * Device driver for TCG/TCPA TPM (trusted platform module).
11 * Specifications at www.trustedcomputinggroup.org
12 *
13 * It is based on the Linux kernel driver tpm.c from Leendert van
14 * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
15 *
Simon Glass4cd7b782015-08-22 18:31:22 -060016 * SPDX-License-Identifier: GPL-2.0
Rong Changf6267992013-04-12 10:44:57 +000017 */
18
Simon Glass4cd7b782015-08-22 18:31:22 -060019#ifndef _TPM_TIS_I2C_H
20#define _TPM_TIS_I2C_H
Rong Changf6267992013-04-12 10:44:57 +000021
22#include <linux/compiler.h>
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000023#include <linux/types.h>
Rong Changf6267992013-04-12 10:44:57 +000024
25enum tpm_timeout {
Simon Glass42c8ec52015-08-22 18:31:30 -060026 TPM_TIMEOUT_MS = 5,
27 TIS_SHORT_TIMEOUT_MS = 750,
28 TIS_LONG_TIMEOUT_MS = 2000,
29 SLEEP_DURATION_US = 60,
30 SLEEP_DURATION_LONG_US = 210,
Rong Changf6267992013-04-12 10:44:57 +000031};
32
33/* Size of external transmit buffer (used in tpm_transmit)*/
34#define TPM_BUFSIZE 4096
35
Rong Changf6267992013-04-12 10:44:57 +000036/* Index of Count field in TPM response buffer */
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000037#define TPM_RSP_SIZE_BYTE 2
38#define TPM_RSP_RC_BYTE 6
Rong Changf6267992013-04-12 10:44:57 +000039
Simon Glass13932b02015-08-22 18:31:25 -060040/* Max buffer size supported by our tpm */
41#define TPM_DEV_BUFSIZE 1260
42
43enum i2c_chip_type {
44 SLB9635,
45 SLB9645,
46 UNKNOWN,
47};
Rong Changf6267992013-04-12 10:44:57 +000048
Simon Glass7c735372015-08-22 18:31:24 -060049struct tpm_chip {
Simon Glass605152a2015-08-22 18:31:26 -060050 bool inited;
Simon Glass7c735372015-08-22 18:31:24 -060051 int is_open;
52 u8 req_complete_mask;
53 u8 req_complete_val;
54 u8 req_canceled;
Rong Changf6267992013-04-12 10:44:57 +000055 int irq;
Rong Changf6267992013-04-12 10:44:57 +000056 int locality;
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000057 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
58 unsigned long duration[3]; /* msec */
Simon Glass13932b02015-08-22 18:31:25 -060059 struct udevice *dev;
60 u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
61 enum i2c_chip_type chip_type;
Rong Changf6267992013-04-12 10:44:57 +000062};
63
Rong Changf6267992013-04-12 10:44:57 +000064struct tpm_input_header {
65 __be16 tag;
66 __be32 length;
67 __be32 ordinal;
68} __packed;
69
70struct tpm_output_header {
71 __be16 tag;
72 __be32 length;
73 __be32 return_code;
74} __packed;
75
76struct timeout_t {
77 __be32 a;
78 __be32 b;
79 __be32 c;
80 __be32 d;
81} __packed;
82
83struct duration_t {
84 __be32 tpm_short;
85 __be32 tpm_medium;
86 __be32 tpm_long;
87} __packed;
88
89union cap_t {
90 struct timeout_t timeout;
91 struct duration_t duration;
92};
93
94struct tpm_getcap_params_in {
95 __be32 cap;
96 __be32 subcap_size;
97 __be32 subcap;
98} __packed;
99
100struct tpm_getcap_params_out {
101 __be32 cap_size;
102 union cap_t cap;
103} __packed;
104
105union tpm_cmd_header {
106 struct tpm_input_header in;
107 struct tpm_output_header out;
108};
109
110union tpm_cmd_params {
111 struct tpm_getcap_params_out getcap_out;
112 struct tpm_getcap_params_in getcap_in;
113};
114
115struct tpm_cmd_t {
116 union tpm_cmd_header header;
117 union tpm_cmd_params params;
118} __packed;
119
Simon Glass13894bd2015-08-22 18:31:27 -0600120/* Max number of iterations after i2c NAK */
121#define MAX_COUNT 3
122
123/*
124 * Max number of iterations after i2c NAK for 'long' commands
125 *
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.
129 */
130#define MAX_COUNT_LONG 50
131
Simon Glass13894bd2015-08-22 18:31:27 -0600132#define TPM_HEADER_SIZE 10
133
134enum tis_access {
135 TPM_ACCESS_VALID = 0x80,
136 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
137 TPM_ACCESS_REQUEST_PENDING = 0x04,
138 TPM_ACCESS_REQUEST_USE = 0x02,
139};
140
141enum tis_status {
142 TPM_STS_VALID = 0x80,
143 TPM_STS_COMMAND_READY = 0x40,
144 TPM_STS_GO = 0x20,
145 TPM_STS_DATA_AVAIL = 0x10,
146 TPM_STS_DATA_EXPECT = 0x08,
147};
148
Simon Glass13894bd2015-08-22 18:31:27 -0600149/* expected value for DIDVID register */
150#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
151#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
152
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))
157
Simon Glass13894bd2015-08-22 18:31:27 -0600158/* Extended error numbers from linux (see errno.h) */
159#define ECANCELED 125 /* Operation Canceled */
160
Simon Glass42c8ec52015-08-22 18:31:30 -0600161/* Timer frequency. Corresponds to msec timer resolution */
Simon Glass13894bd2015-08-22 18:31:27 -0600162#define HZ 1000
163
Rong Changf6267992013-04-12 10:44:57 +0000164#endif