blob: 3b510d101e773baf3aa6db107d8e78cc5ca2a6fe [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 -060040enum i2c_chip_type {
41 SLB9635,
42 SLB9645,
43 UNKNOWN,
44};
Rong Changf6267992013-04-12 10:44:57 +000045
Simon Glass7c735372015-08-22 18:31:24 -060046struct tpm_chip {
47 int is_open;
Rong Changf6267992013-04-12 10:44:57 +000048 int locality;
Simon Glassb697e0f2015-08-22 18:31:38 -060049 u32 vend_dev;
Tom Wai-Hong Tam1b393db2013-04-12 11:04:37 +000050 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
Simon Glass13932b02015-08-22 18:31:25 -060051 enum i2c_chip_type chip_type;
Rong Changf6267992013-04-12 10:44:57 +000052};
53
Rong Changf6267992013-04-12 10:44:57 +000054struct tpm_input_header {
55 __be16 tag;
56 __be32 length;
57 __be32 ordinal;
58} __packed;
59
60struct tpm_output_header {
61 __be16 tag;
62 __be32 length;
63 __be32 return_code;
64} __packed;
65
66struct timeout_t {
67 __be32 a;
68 __be32 b;
69 __be32 c;
70 __be32 d;
71} __packed;
72
73struct duration_t {
74 __be32 tpm_short;
75 __be32 tpm_medium;
76 __be32 tpm_long;
77} __packed;
78
79union cap_t {
80 struct timeout_t timeout;
81 struct duration_t duration;
82};
83
84struct tpm_getcap_params_in {
85 __be32 cap;
86 __be32 subcap_size;
87 __be32 subcap;
88} __packed;
89
90struct tpm_getcap_params_out {
91 __be32 cap_size;
92 union cap_t cap;
93} __packed;
94
95union tpm_cmd_header {
96 struct tpm_input_header in;
97 struct tpm_output_header out;
98};
99
100union tpm_cmd_params {
101 struct tpm_getcap_params_out getcap_out;
102 struct tpm_getcap_params_in getcap_in;
103};
104
105struct tpm_cmd_t {
106 union tpm_cmd_header header;
107 union tpm_cmd_params params;
108} __packed;
109
Simon Glass13894bd2015-08-22 18:31:27 -0600110/* Max number of iterations after i2c NAK */
111#define MAX_COUNT 3
112
113/*
114 * Max number of iterations after i2c NAK for 'long' commands
115 *
116 * We need this especially for sending TPM_READY, since the cleanup after the
117 * transtion to the ready state may take some time, but it is unpredictable
118 * how long it will take.
119 */
120#define MAX_COUNT_LONG 50
121
Simon Glass13894bd2015-08-22 18:31:27 -0600122enum tis_access {
123 TPM_ACCESS_VALID = 0x80,
124 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
125 TPM_ACCESS_REQUEST_PENDING = 0x04,
126 TPM_ACCESS_REQUEST_USE = 0x02,
127};
128
129enum tis_status {
130 TPM_STS_VALID = 0x80,
131 TPM_STS_COMMAND_READY = 0x40,
132 TPM_STS_GO = 0x20,
133 TPM_STS_DATA_AVAIL = 0x10,
134 TPM_STS_DATA_EXPECT = 0x08,
135};
136
Simon Glass13894bd2015-08-22 18:31:27 -0600137/* expected value for DIDVID register */
138#define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
139#define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
140
141#define TPM_ACCESS(l) (0x0000 | ((l) << 4))
142#define TPM_STS(l) (0x0001 | ((l) << 4))
143#define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
144#define TPM_DID_VID(l) (0x0006 | ((l) << 4))
145
Rong Changf6267992013-04-12 10:44:57 +0000146#endif