Rong Chang | f626799 | 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 | 4cd7b78 | 2015-08-22 18:31:22 -0600 | [diff] [blame] | 16 | * SPDX-License-Identifier: GPL-2.0 |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
Simon Glass | 4cd7b78 | 2015-08-22 18:31:22 -0600 | [diff] [blame] | 19 | #ifndef _TPM_TIS_I2C_H |
| 20 | #define _TPM_TIS_I2C_H |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 21 | |
| 22 | #include <linux/compiler.h> |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 23 | #include <linux/types.h> |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 24 | |
| 25 | enum tpm_timeout { |
| 26 | TPM_TIMEOUT = 5, /* msecs */ |
| 27 | }; |
| 28 | |
| 29 | /* Size of external transmit buffer (used in tpm_transmit)*/ |
| 30 | #define TPM_BUFSIZE 4096 |
| 31 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 32 | /* Index of Count field in TPM response buffer */ |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 33 | #define TPM_RSP_SIZE_BYTE 2 |
| 34 | #define TPM_RSP_RC_BYTE 6 |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 35 | |
Simon Glass | 13932b0 | 2015-08-22 18:31:25 -0600 | [diff] [blame^] | 36 | /* Max buffer size supported by our tpm */ |
| 37 | #define TPM_DEV_BUFSIZE 1260 |
| 38 | |
| 39 | enum i2c_chip_type { |
| 40 | SLB9635, |
| 41 | SLB9645, |
| 42 | UNKNOWN, |
| 43 | }; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 44 | |
Simon Glass | 7c73537 | 2015-08-22 18:31:24 -0600 | [diff] [blame] | 45 | struct tpm_chip { |
| 46 | int is_open; |
| 47 | u8 req_complete_mask; |
| 48 | u8 req_complete_val; |
| 49 | u8 req_canceled; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 50 | int irq; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 51 | int locality; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 52 | unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ |
| 53 | unsigned long duration[3]; /* msec */ |
Simon Glass | 13932b0 | 2015-08-22 18:31:25 -0600 | [diff] [blame^] | 54 | struct udevice *dev; |
| 55 | u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */ |
| 56 | enum i2c_chip_type chip_type; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 59 | struct tpm_input_header { |
| 60 | __be16 tag; |
| 61 | __be32 length; |
| 62 | __be32 ordinal; |
| 63 | } __packed; |
| 64 | |
| 65 | struct tpm_output_header { |
| 66 | __be16 tag; |
| 67 | __be32 length; |
| 68 | __be32 return_code; |
| 69 | } __packed; |
| 70 | |
| 71 | struct timeout_t { |
| 72 | __be32 a; |
| 73 | __be32 b; |
| 74 | __be32 c; |
| 75 | __be32 d; |
| 76 | } __packed; |
| 77 | |
| 78 | struct duration_t { |
| 79 | __be32 tpm_short; |
| 80 | __be32 tpm_medium; |
| 81 | __be32 tpm_long; |
| 82 | } __packed; |
| 83 | |
| 84 | union cap_t { |
| 85 | struct timeout_t timeout; |
| 86 | struct duration_t duration; |
| 87 | }; |
| 88 | |
| 89 | struct tpm_getcap_params_in { |
| 90 | __be32 cap; |
| 91 | __be32 subcap_size; |
| 92 | __be32 subcap; |
| 93 | } __packed; |
| 94 | |
| 95 | struct tpm_getcap_params_out { |
| 96 | __be32 cap_size; |
| 97 | union cap_t cap; |
| 98 | } __packed; |
| 99 | |
| 100 | union tpm_cmd_header { |
| 101 | struct tpm_input_header in; |
| 102 | struct tpm_output_header out; |
| 103 | }; |
| 104 | |
| 105 | union tpm_cmd_params { |
| 106 | struct tpm_getcap_params_out getcap_out; |
| 107 | struct tpm_getcap_params_in getcap_in; |
| 108 | }; |
| 109 | |
| 110 | struct tpm_cmd_t { |
| 111 | union tpm_cmd_header header; |
| 112 | union tpm_cmd_params params; |
| 113 | } __packed; |
| 114 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 115 | #endif |