Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 1 | /* |
| 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 Glass | 9457627 | 2015-08-22 18:31:22 -0600 | [diff] [blame] | 16 | * SPDX-License-Identifier: GPL-2.0 |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
Simon Glass | 9457627 | 2015-08-22 18:31:22 -0600 | [diff] [blame] | 19 | #ifndef _TPM_TIS_I2C_H |
| 20 | #define _TPM_TIS_I2C_H |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 21 | |
| 22 | #include <linux/compiler.h> |
Tom Wai-Hong Tam | e49fed5 | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 23 | #include <linux/types.h> |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 24 | |
| 25 | enum tpm_timeout { |
Simon Glass | a57bcee | 2015-08-22 18:31:30 -0600 | [diff] [blame] | 26 | 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 Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | /* Size of external transmit buffer (used in tpm_transmit)*/ |
| 34 | #define TPM_BUFSIZE 4096 |
| 35 | |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 36 | /* Index of Count field in TPM response buffer */ |
Tom Wai-Hong Tam | e49fed5 | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 37 | #define TPM_RSP_SIZE_BYTE 2 |
| 38 | #define TPM_RSP_RC_BYTE 6 |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 39 | |
Simon Glass | ab79b00 | 2015-08-22 18:31:24 -0600 | [diff] [blame] | 40 | struct tpm_chip { |
| 41 | int is_open; |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 42 | int locality; |
Simon Glass | cd8cc67 | 2015-08-22 18:31:38 -0600 | [diff] [blame] | 43 | u32 vend_dev; |
Tom Wai-Hong Tam | e49fed5 | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 44 | unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ |
Christophe Ricard | 2654952 | 2016-01-21 23:27:12 +0100 | [diff] [blame^] | 45 | ulong chip_type; |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 48 | struct tpm_input_header { |
| 49 | __be16 tag; |
| 50 | __be32 length; |
| 51 | __be32 ordinal; |
| 52 | } __packed; |
| 53 | |
| 54 | struct tpm_output_header { |
| 55 | __be16 tag; |
| 56 | __be32 length; |
| 57 | __be32 return_code; |
| 58 | } __packed; |
| 59 | |
| 60 | struct timeout_t { |
| 61 | __be32 a; |
| 62 | __be32 b; |
| 63 | __be32 c; |
| 64 | __be32 d; |
| 65 | } __packed; |
| 66 | |
| 67 | struct duration_t { |
| 68 | __be32 tpm_short; |
| 69 | __be32 tpm_medium; |
| 70 | __be32 tpm_long; |
| 71 | } __packed; |
| 72 | |
| 73 | union cap_t { |
| 74 | struct timeout_t timeout; |
| 75 | struct duration_t duration; |
| 76 | }; |
| 77 | |
| 78 | struct tpm_getcap_params_in { |
| 79 | __be32 cap; |
| 80 | __be32 subcap_size; |
| 81 | __be32 subcap; |
| 82 | } __packed; |
| 83 | |
| 84 | struct tpm_getcap_params_out { |
| 85 | __be32 cap_size; |
| 86 | union cap_t cap; |
| 87 | } __packed; |
| 88 | |
| 89 | union tpm_cmd_header { |
| 90 | struct tpm_input_header in; |
| 91 | struct tpm_output_header out; |
| 92 | }; |
| 93 | |
| 94 | union tpm_cmd_params { |
| 95 | struct tpm_getcap_params_out getcap_out; |
| 96 | struct tpm_getcap_params_in getcap_in; |
| 97 | }; |
| 98 | |
| 99 | struct tpm_cmd_t { |
| 100 | union tpm_cmd_header header; |
| 101 | union tpm_cmd_params params; |
| 102 | } __packed; |
| 103 | |
Simon Glass | 6a7e7cc | 2015-08-22 18:31:27 -0600 | [diff] [blame] | 104 | /* Max number of iterations after i2c NAK */ |
| 105 | #define MAX_COUNT 3 |
| 106 | |
| 107 | /* |
| 108 | * Max number of iterations after i2c NAK for 'long' commands |
| 109 | * |
| 110 | * We need this especially for sending TPM_READY, since the cleanup after the |
| 111 | * transtion to the ready state may take some time, but it is unpredictable |
| 112 | * how long it will take. |
| 113 | */ |
| 114 | #define MAX_COUNT_LONG 50 |
| 115 | |
Simon Glass | 6a7e7cc | 2015-08-22 18:31:27 -0600 | [diff] [blame] | 116 | enum tis_access { |
| 117 | TPM_ACCESS_VALID = 0x80, |
| 118 | TPM_ACCESS_ACTIVE_LOCALITY = 0x20, |
| 119 | TPM_ACCESS_REQUEST_PENDING = 0x04, |
| 120 | TPM_ACCESS_REQUEST_USE = 0x02, |
| 121 | }; |
| 122 | |
| 123 | enum tis_status { |
| 124 | TPM_STS_VALID = 0x80, |
| 125 | TPM_STS_COMMAND_READY = 0x40, |
| 126 | TPM_STS_GO = 0x20, |
| 127 | TPM_STS_DATA_AVAIL = 0x10, |
| 128 | TPM_STS_DATA_EXPECT = 0x08, |
| 129 | }; |
| 130 | |
Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 131 | #endif |