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 | * Description: |
| 8 | * Device driver for TCG/TCPA TPM (trusted platform module). |
| 9 | * Specifications at www.trustedcomputinggroup.org |
| 10 | * |
| 11 | * This device driver implements the TPM interface as defined in |
| 12 | * the TCG TPM Interface Spec version 1.2, revision 1.0 and the |
| 13 | * Infineon I2C Protocol Stack Specification v0.20. |
| 14 | * |
| 15 | * It is based on the Linux kernel driver tpm.c from Leendert van |
| 16 | * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall. |
| 17 | * |
| 18 | * Version: 2.1.1 |
| 19 | * |
| 20 | * See file CREDITS for list of people who contributed to this |
| 21 | * project. |
| 22 | * |
| 23 | * This program is free software; you can redistribute it and/or |
| 24 | * modify it under the terms of the GNU General Public License as |
| 25 | * published by the Free Software Foundation, version 2 of the |
| 26 | * License. |
| 27 | * |
| 28 | * This program is distributed in the hope that it will be useful, |
| 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 | * GNU General Public License for more details. |
| 32 | * |
| 33 | * You should have received a copy of the GNU General Public License |
| 34 | * along with this program; if not, write to the Free Software |
| 35 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 36 | * MA 02111-1307 USA |
| 37 | */ |
| 38 | |
| 39 | #include <common.h> |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 40 | #include <dm.h> |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 41 | #include <fdtdec.h> |
Masahiro Yamada | afc366f | 2014-11-26 16:00:58 +0900 | [diff] [blame] | 42 | #include <linux/compiler.h> |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 43 | #include <i2c.h> |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 44 | #include <tpm.h> |
| 45 | #include <asm-generic/errno.h> |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 46 | #include <linux/types.h> |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 47 | #include <linux/unaligned/be_byteshift.h> |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 48 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 49 | #include "tpm_private.h" |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 50 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 51 | DECLARE_GLOBAL_DATA_PTR; |
| 52 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 53 | /* Address of the TPM on the I2C bus */ |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 54 | #define TPM_I2C_ADDR 0x20 |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 55 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 56 | /* Max buffer size supported by our tpm */ |
| 57 | #define TPM_DEV_BUFSIZE 1260 |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 58 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 59 | /* Max number of iterations after i2c NAK */ |
| 60 | #define MAX_COUNT 3 |
| 61 | |
| 62 | /* |
| 63 | * Max number of iterations after i2c NAK for 'long' commands |
| 64 | * |
| 65 | * We need this especially for sending TPM_READY, since the cleanup after the |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 66 | * transtion to the ready state may take some time, but it is unpredictable |
| 67 | * how long it will take. |
| 68 | */ |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 69 | #define MAX_COUNT_LONG 50 |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 70 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 71 | #define SLEEP_DURATION 60 /* in usec */ |
| 72 | #define SLEEP_DURATION_LONG 210 /* in usec */ |
| 73 | |
| 74 | #define TPM_HEADER_SIZE 10 |
| 75 | |
| 76 | /* |
| 77 | * Expected value for DIDVID register |
| 78 | * |
| 79 | * The only device the system knows about at this moment is Infineon slb9635. |
| 80 | */ |
| 81 | #define TPM_TIS_I2C_DID_VID 0x000b15d1L |
| 82 | |
| 83 | enum tis_access { |
| 84 | TPM_ACCESS_VALID = 0x80, |
| 85 | TPM_ACCESS_ACTIVE_LOCALITY = 0x20, |
| 86 | TPM_ACCESS_REQUEST_PENDING = 0x04, |
| 87 | TPM_ACCESS_REQUEST_USE = 0x02, |
| 88 | }; |
| 89 | |
| 90 | enum tis_status { |
| 91 | TPM_STS_VALID = 0x80, |
| 92 | TPM_STS_COMMAND_READY = 0x40, |
| 93 | TPM_STS_GO = 0x20, |
| 94 | TPM_STS_DATA_AVAIL = 0x10, |
| 95 | TPM_STS_DATA_EXPECT = 0x08, |
| 96 | }; |
| 97 | |
| 98 | enum tis_defaults { |
| 99 | TIS_SHORT_TIMEOUT = 750, /* ms */ |
| 100 | TIS_LONG_TIMEOUT = 2000, /* ms */ |
| 101 | }; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 102 | |
| 103 | /* expected value for DIDVID register */ |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 104 | #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L |
| 105 | #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L |
| 106 | |
| 107 | enum i2c_chip_type { |
| 108 | SLB9635, |
| 109 | SLB9645, |
| 110 | UNKNOWN, |
| 111 | }; |
| 112 | |
| 113 | static const char * const chip_name[] = { |
| 114 | [SLB9635] = "slb9635tt", |
| 115 | [SLB9645] = "slb9645tt", |
| 116 | [UNKNOWN] = "unknown/fallback to slb9635", |
| 117 | }; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 118 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 119 | #define TPM_ACCESS(l) (0x0000 | ((l) << 4)) |
| 120 | #define TPM_STS(l) (0x0001 | ((l) << 4)) |
| 121 | #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4)) |
| 122 | #define TPM_DID_VID(l) (0x0006 | ((l) << 4)) |
| 123 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 124 | /* Structure to store I2C TPM specific stuff */ |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 125 | struct tpm_dev { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 126 | #ifdef CONFIG_DM_I2C |
| 127 | struct udevice *dev; |
| 128 | #else |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 129 | uint addr; |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 130 | #endif |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 131 | u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */ |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 132 | enum i2c_chip_type chip_type; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 135 | static struct tpm_dev tpm_dev = { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 136 | #ifndef CONFIG_DM_I2C |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 137 | .addr = TPM_I2C_ADDR |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 138 | #endif |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 141 | static struct tpm_dev tpm_dev; |
| 142 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 143 | /* |
| 144 | * iic_tpm_read() - read from TPM register |
| 145 | * @addr: register address to read from |
| 146 | * @buffer: provided by caller |
| 147 | * @len: number of bytes to read |
| 148 | * |
| 149 | * Read len bytes from TPM register and put them into |
| 150 | * buffer (little-endian format, i.e. first byte is put into buffer[0]). |
| 151 | * |
| 152 | * NOTE: TPM is big-endian for multi-byte values. Multi-byte |
| 153 | * values have to be swapped. |
| 154 | * |
| 155 | * Return -EIO on error, 0 on success. |
| 156 | */ |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 157 | static int iic_tpm_read(u8 addr, u8 *buffer, size_t len) |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 158 | { |
| 159 | int rc; |
| 160 | int count; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 161 | uint32_t addrbuf = addr; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 162 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 163 | if ((tpm_dev.chip_type == SLB9635) || (tpm_dev.chip_type == UNKNOWN)) { |
| 164 | /* slb9635 protocol should work in both cases */ |
| 165 | for (count = 0; count < MAX_COUNT; count++) { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 166 | #ifdef CONFIG_DM_I2C |
| 167 | rc = dm_i2c_write(tpm_dev.dev, 0, (uchar *)&addrbuf, 1); |
| 168 | #else |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 169 | rc = i2c_write(tpm_dev.addr, 0, 0, |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 170 | (uchar *)&addrbuf, 1); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 171 | #endif |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 172 | if (rc == 0) |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 173 | break; /* Success, break to skip sleep */ |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 174 | udelay(SLEEP_DURATION); |
| 175 | } |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 176 | if (rc) |
| 177 | return -rc; |
| 178 | |
| 179 | /* After the TPM has successfully received the register address |
| 180 | * it needs some time, thus we're sleeping here again, before |
| 181 | * retrieving the data |
| 182 | */ |
| 183 | for (count = 0; count < MAX_COUNT; count++) { |
| 184 | udelay(SLEEP_DURATION); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 185 | #ifdef CONFIG_DM_I2C |
| 186 | rc = dm_i2c_read(tpm_dev.dev, 0, buffer, len); |
| 187 | #else |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 188 | rc = i2c_read(tpm_dev.addr, 0, 0, buffer, len); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 189 | #endif |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 190 | if (rc == 0) |
| 191 | break; /* success, break to skip sleep */ |
| 192 | } |
| 193 | } else { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 194 | /* |
| 195 | * Use a combined read for newer chips. |
| 196 | * Unfortunately the smbus functions are not suitable due to |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 197 | * the 32 byte limit of the smbus. |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 198 | * Retries should usually not be needed, but are kept just to |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 199 | * be safe on the safe side. |
| 200 | */ |
| 201 | for (count = 0; count < MAX_COUNT; count++) { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 202 | #ifdef CONFIG_DM_I2C |
| 203 | rc = dm_i2c_read(tpm_dev.dev, addr, buffer, len); |
| 204 | #else |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 205 | rc = i2c_read(tpm_dev.addr, addr, 1, buffer, len); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 206 | #endif |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 207 | if (rc == 0) |
| 208 | break; /* break here to skip sleep */ |
| 209 | udelay(SLEEP_DURATION); |
| 210 | } |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 213 | /* Take care of 'guard time' */ |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 214 | udelay(SLEEP_DURATION); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 215 | if (rc) |
| 216 | return -rc; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len, |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 222 | unsigned int sleep_time, u8 max_count) |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 223 | { |
| 224 | int rc = 0; |
| 225 | int count; |
| 226 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 227 | /* Prepare send buffer */ |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 228 | #ifndef CONFIG_DM_I2C |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 229 | tpm_dev.buf[0] = addr; |
| 230 | memcpy(&(tpm_dev.buf[1]), buffer, len); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 231 | buffer = tpm_dev.buf; |
| 232 | len++; |
| 233 | #endif |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 234 | |
| 235 | for (count = 0; count < max_count; count++) { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 236 | #ifdef CONFIG_DM_I2C |
| 237 | rc = dm_i2c_write(tpm_dev.dev, addr, buffer, len); |
| 238 | #else |
| 239 | rc = i2c_write(tpm_dev.addr, 0, 0, buffer, len); |
| 240 | #endif |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 241 | if (rc == 0) |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 242 | break; /* Success, break to skip sleep */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 243 | udelay(sleep_time); |
| 244 | } |
| 245 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 246 | /* take care of 'guard time' */ |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 247 | udelay(sleep_time); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 248 | if (rc) |
| 249 | return -rc; |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * iic_tpm_write() - write to TPM register |
| 256 | * @addr: register address to write to |
| 257 | * @buffer: containing data to be written |
| 258 | * @len: number of bytes to write |
| 259 | * |
| 260 | * Write len bytes from provided buffer to TPM register (little |
| 261 | * endian format, i.e. buffer[0] is written as first byte). |
| 262 | * |
| 263 | * NOTE: TPM is big-endian for multi-byte values. Multi-byte |
| 264 | * values have to be swapped. |
| 265 | * |
| 266 | * NOTE: use this function instead of the iic_tpm_write_generic function. |
| 267 | * |
| 268 | * Return -EIO on error, 0 on success |
| 269 | */ |
| 270 | static int iic_tpm_write(u8 addr, u8 *buffer, size_t len) |
| 271 | { |
| 272 | return iic_tpm_write_generic(addr, buffer, len, SLEEP_DURATION, |
| 273 | MAX_COUNT); |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * This function is needed especially for the cleanup situation after |
| 278 | * sending TPM_READY |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 279 | */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 280 | static int iic_tpm_write_long(u8 addr, u8 *buffer, size_t len) |
| 281 | { |
| 282 | return iic_tpm_write_generic(addr, buffer, len, SLEEP_DURATION_LONG, |
| 283 | MAX_COUNT_LONG); |
| 284 | } |
| 285 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 286 | static int check_locality(struct tpm_chip *chip, int loc) |
| 287 | { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 288 | const u8 mask = TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 289 | u8 buf; |
| 290 | int rc; |
| 291 | |
| 292 | rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1); |
| 293 | if (rc < 0) |
| 294 | return rc; |
| 295 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 296 | if ((buf & mask) == mask) { |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 297 | chip->vendor.locality = loc; |
| 298 | return loc; |
| 299 | } |
| 300 | |
| 301 | return -1; |
| 302 | } |
| 303 | |
| 304 | static void release_locality(struct tpm_chip *chip, int loc, int force) |
| 305 | { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 306 | const u8 mask = TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 307 | u8 buf; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 308 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 309 | if (iic_tpm_read(TPM_ACCESS(loc), &buf, 1) < 0) |
| 310 | return; |
| 311 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 312 | if (force || (buf & mask) == mask) { |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 313 | buf = TPM_ACCESS_ACTIVE_LOCALITY; |
| 314 | iic_tpm_write(TPM_ACCESS(loc), &buf, 1); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | static int request_locality(struct tpm_chip *chip, int loc) |
| 319 | { |
| 320 | unsigned long start, stop; |
| 321 | u8 buf = TPM_ACCESS_REQUEST_USE; |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 322 | int rc; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 323 | |
| 324 | if (check_locality(chip, loc) >= 0) |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 325 | return loc; /* We already have the locality */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 326 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 327 | rc = iic_tpm_write(TPM_ACCESS(loc), &buf, 1); |
| 328 | if (rc) |
| 329 | return rc; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 330 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 331 | /* Wait for burstcount */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 332 | start = get_timer(0); |
| 333 | stop = chip->vendor.timeout_a; |
| 334 | do { |
| 335 | if (check_locality(chip, loc) >= 0) |
| 336 | return loc; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 337 | udelay(TPM_TIMEOUT * 1000); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 338 | } while (get_timer(start) < stop); |
| 339 | |
| 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | static u8 tpm_tis_i2c_status(struct tpm_chip *chip) |
| 344 | { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 345 | /* NOTE: Since i2c read may fail, return 0 in this case --> time-out */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 346 | u8 buf; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 347 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 348 | if (iic_tpm_read(TPM_STS(chip->vendor.locality), &buf, 1) < 0) |
| 349 | return 0; |
| 350 | else |
| 351 | return buf; |
| 352 | } |
| 353 | |
| 354 | static void tpm_tis_i2c_ready(struct tpm_chip *chip) |
| 355 | { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 356 | int rc; |
| 357 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 358 | /* This causes the current command to be aborted */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 359 | u8 buf = TPM_STS_COMMAND_READY; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 360 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 361 | debug("%s\n", __func__); |
| 362 | rc = iic_tpm_write_long(TPM_STS(chip->vendor.locality), &buf, 1); |
| 363 | if (rc) |
| 364 | debug("%s: rc=%d\n", __func__, rc); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static ssize_t get_burstcount(struct tpm_chip *chip) |
| 368 | { |
| 369 | unsigned long start, stop; |
| 370 | ssize_t burstcnt; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 371 | u8 addr, buf[3]; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 372 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 373 | /* Wait for burstcount */ |
| 374 | /* XXX: Which timeout value? Spec has 2 answers (c & d) */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 375 | start = get_timer(0); |
| 376 | stop = chip->vendor.timeout_d; |
| 377 | do { |
| 378 | /* Note: STS is little endian */ |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 379 | addr = TPM_STS(chip->vendor.locality) + 1; |
| 380 | if (iic_tpm_read(addr, buf, 3) < 0) |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 381 | burstcnt = 0; |
| 382 | else |
| 383 | burstcnt = (buf[2] << 16) + (buf[1] << 8) + buf[0]; |
| 384 | |
| 385 | if (burstcnt) |
| 386 | return burstcnt; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 387 | udelay(TPM_TIMEOUT * 1000); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 388 | } while (get_timer(start) < stop); |
| 389 | |
| 390 | return -EBUSY; |
| 391 | } |
| 392 | |
| 393 | static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 394 | int *status) |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 395 | { |
| 396 | unsigned long start, stop; |
| 397 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 398 | /* Check current status */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 399 | *status = tpm_tis_i2c_status(chip); |
| 400 | if ((*status & mask) == mask) |
| 401 | return 0; |
| 402 | |
| 403 | start = get_timer(0); |
| 404 | stop = timeout; |
| 405 | do { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 406 | udelay(TPM_TIMEOUT * 1000); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 407 | *status = tpm_tis_i2c_status(chip); |
| 408 | if ((*status & mask) == mask) |
| 409 | return 0; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 410 | } while (get_timer(start) < stop); |
| 411 | |
| 412 | return -ETIME; |
| 413 | } |
| 414 | |
| 415 | static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) |
| 416 | { |
| 417 | size_t size = 0; |
| 418 | ssize_t burstcnt; |
| 419 | int rc; |
| 420 | |
| 421 | while (size < count) { |
| 422 | burstcnt = get_burstcount(chip); |
| 423 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 424 | /* burstcount < 0 -> tpm is busy */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 425 | if (burstcnt < 0) |
| 426 | return burstcnt; |
| 427 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 428 | /* Limit received data to max left */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 429 | if (burstcnt > (count - size)) |
| 430 | burstcnt = count - size; |
| 431 | |
| 432 | rc = iic_tpm_read(TPM_DATA_FIFO(chip->vendor.locality), |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 433 | &(buf[size]), burstcnt); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 434 | if (rc == 0) |
| 435 | size += burstcnt; |
| 436 | } |
| 437 | |
| 438 | return size; |
| 439 | } |
| 440 | |
| 441 | static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count) |
| 442 | { |
| 443 | int size = 0; |
| 444 | int expected, status; |
| 445 | |
| 446 | if (count < TPM_HEADER_SIZE) { |
| 447 | size = -EIO; |
| 448 | goto out; |
| 449 | } |
| 450 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 451 | /* Read first 10 bytes, including tag, paramsize, and result */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 452 | size = recv_data(chip, buf, TPM_HEADER_SIZE); |
| 453 | if (size < TPM_HEADER_SIZE) { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 454 | error("Unable to read header\n"); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 455 | goto out; |
| 456 | } |
| 457 | |
| 458 | expected = get_unaligned_be32(buf + TPM_RSP_SIZE_BYTE); |
| 459 | if ((size_t)expected > count) { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 460 | error("Error size=%x, expected=%x, count=%x\n", size, expected, |
| 461 | count); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 462 | size = -EIO; |
| 463 | goto out; |
| 464 | } |
| 465 | |
| 466 | size += recv_data(chip, &buf[TPM_HEADER_SIZE], |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 467 | expected - TPM_HEADER_SIZE); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 468 | if (size < expected) { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 469 | error("Unable to read remainder of result\n"); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 470 | size = -ETIME; |
| 471 | goto out; |
| 472 | } |
| 473 | |
| 474 | wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status); |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 475 | if (status & TPM_STS_DATA_AVAIL) { /* Retry? */ |
| 476 | error("Error left over data\n"); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 477 | size = -EIO; |
| 478 | goto out; |
| 479 | } |
| 480 | |
| 481 | out: |
| 482 | tpm_tis_i2c_ready(chip); |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 483 | /* |
| 484 | * The TPM needs some time to clean up here, |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 485 | * so we sleep rather than keeping the bus busy |
| 486 | */ |
| 487 | udelay(2000); |
| 488 | release_locality(chip, chip->vendor.locality, 0); |
| 489 | |
| 490 | return size; |
| 491 | } |
| 492 | |
| 493 | static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len) |
| 494 | { |
| 495 | int rc, status; |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 496 | size_t burstcnt; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 497 | size_t count = 0; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 498 | int retry = 0; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 499 | u8 sts = TPM_STS_GO; |
| 500 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 501 | debug("%s: len=%d\n", __func__, len); |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 502 | if (len > TPM_DEV_BUFSIZE) |
| 503 | return -E2BIG; /* Command is too long for our tpm, sorry */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 504 | |
| 505 | if (request_locality(chip, 0) < 0) |
| 506 | return -EBUSY; |
| 507 | |
| 508 | status = tpm_tis_i2c_status(chip); |
| 509 | if ((status & TPM_STS_COMMAND_READY) == 0) { |
| 510 | tpm_tis_i2c_ready(chip); |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 511 | if (wait_for_stat(chip, TPM_STS_COMMAND_READY, |
| 512 | chip->vendor.timeout_b, &status) < 0) { |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 513 | rc = -ETIME; |
| 514 | goto out_err; |
| 515 | } |
| 516 | } |
| 517 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 518 | burstcnt = get_burstcount(chip); |
| 519 | |
| 520 | /* burstcount < 0 -> tpm is busy */ |
| 521 | if (burstcnt < 0) |
| 522 | return burstcnt; |
| 523 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 524 | while (count < len) { |
| 525 | udelay(300); |
| 526 | if (burstcnt > len - count) |
| 527 | burstcnt = len - count; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 528 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 529 | #ifdef CONFIG_TPM_TIS_I2C_BURST_LIMITATION |
| 530 | if (retry && burstcnt > CONFIG_TPM_TIS_I2C_BURST_LIMITATION) |
| 531 | burstcnt = CONFIG_TPM_TIS_I2C_BURST_LIMITATION; |
| 532 | #endif /* CONFIG_TPM_TIS_I2C_BURST_LIMITATION */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 533 | |
| 534 | rc = iic_tpm_write(TPM_DATA_FIFO(chip->vendor.locality), |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 535 | &(buf[count]), burstcnt); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 536 | if (rc == 0) |
| 537 | count += burstcnt; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 538 | else { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 539 | debug("%s: error\n", __func__); |
| 540 | if (retry++ > 10) { |
| 541 | rc = -EIO; |
| 542 | goto out_err; |
| 543 | } |
| 544 | rc = wait_for_stat(chip, TPM_STS_VALID, |
| 545 | chip->vendor.timeout_c, &status); |
| 546 | if (rc) |
| 547 | goto out_err; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 548 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 549 | if ((status & TPM_STS_DATA_EXPECT) == 0) { |
| 550 | rc = -EIO; |
| 551 | goto out_err; |
| 552 | } |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 556 | /* Go and do it */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 557 | iic_tpm_write(TPM_STS(chip->vendor.locality), &sts, 1); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 558 | debug("done\n"); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 559 | |
| 560 | return len; |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 561 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 562 | out_err: |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 563 | debug("%s: out_err\n", __func__); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 564 | tpm_tis_i2c_ready(chip); |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 565 | /* |
| 566 | * The TPM needs some time to clean up here, |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 567 | * so we sleep rather than keeping the bus busy |
| 568 | */ |
| 569 | udelay(2000); |
| 570 | release_locality(chip, chip->vendor.locality, 0); |
| 571 | |
| 572 | return rc; |
| 573 | } |
| 574 | |
| 575 | static struct tpm_vendor_specific tpm_tis_i2c = { |
| 576 | .status = tpm_tis_i2c_status, |
| 577 | .recv = tpm_tis_i2c_recv, |
| 578 | .send = tpm_tis_i2c_send, |
| 579 | .cancel = tpm_tis_i2c_ready, |
| 580 | .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, |
| 581 | .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, |
| 582 | .req_canceled = TPM_STS_COMMAND_READY, |
| 583 | }; |
| 584 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 585 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 586 | static enum i2c_chip_type tpm_vendor_chip_type(void) |
| 587 | { |
| 588 | #ifdef CONFIG_OF_CONTROL |
| 589 | const void *blob = gd->fdt_blob; |
| 590 | |
| 591 | if (fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9645_TPM) >= 0) |
| 592 | return SLB9645; |
| 593 | |
| 594 | if (fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9635_TPM) >= 0) |
| 595 | return SLB9635; |
| 596 | #endif |
| 597 | return UNKNOWN; |
| 598 | } |
| 599 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 600 | static int tpm_vendor_init_common(void) |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 601 | { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 602 | struct tpm_chip *chip; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 603 | u32 vendor; |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 604 | u32 expected_did_vid; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 605 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 606 | tpm_dev.chip_type = tpm_vendor_chip_type(); |
| 607 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 608 | chip = tpm_register_hardware(&tpm_tis_i2c); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 609 | if (chip < 0) |
| 610 | return -ENODEV; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 611 | |
| 612 | /* Disable interrupts (not supported) */ |
| 613 | chip->vendor.irq = 0; |
| 614 | |
| 615 | /* Default timeouts */ |
| 616 | chip->vendor.timeout_a = TIS_SHORT_TIMEOUT; |
| 617 | chip->vendor.timeout_b = TIS_LONG_TIMEOUT; |
| 618 | chip->vendor.timeout_c = TIS_SHORT_TIMEOUT; |
| 619 | chip->vendor.timeout_d = TIS_SHORT_TIMEOUT; |
| 620 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 621 | if (request_locality(chip, 0) < 0) |
| 622 | return -ENODEV; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 623 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 624 | /* Read four bytes from DID_VID register */ |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 625 | if (iic_tpm_read(TPM_DID_VID(0), (uchar *)&vendor, 4) < 0) { |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 626 | release_locality(chip, 0, 1); |
| 627 | return -EIO; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 630 | if (tpm_dev.chip_type == SLB9635) { |
| 631 | vendor = be32_to_cpu(vendor); |
| 632 | expected_did_vid = TPM_TIS_I2C_DID_VID_9635; |
| 633 | } else { |
| 634 | /* device id and byte order has changed for newer i2c tpms */ |
| 635 | expected_did_vid = TPM_TIS_I2C_DID_VID_9645; |
| 636 | } |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 637 | |
Vincent Palatin | ec34fa5 | 2013-04-12 11:04:36 +0000 | [diff] [blame] | 638 | if (tpm_dev.chip_type != UNKNOWN && vendor != expected_did_vid) { |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 639 | error("Vendor id did not match! ID was %08x\n", vendor); |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 640 | return -ENODEV; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Tom Wai-Hong Tam | 1b393db | 2013-04-12 11:04:37 +0000 | [diff] [blame] | 643 | debug("1.2 TPM (chip type %s device-id 0x%X)\n", |
| 644 | chip_name[tpm_dev.chip_type], vendor >> 16); |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * A timeout query to TPM can be placed here. |
| 648 | * Standard timeout values are used so far |
| 649 | */ |
| 650 | |
| 651 | return 0; |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 652 | } |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 653 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 654 | #ifdef CONFIG_DM_I2C |
| 655 | /* Initialisation of i2c tpm */ |
| 656 | int tpm_vendor_init_dev(struct udevice *dev) |
| 657 | { |
| 658 | tpm_dev.dev = dev; |
| 659 | return tpm_vendor_init_common(); |
| 660 | } |
| 661 | #else |
| 662 | /* Initialisation of i2c tpm */ |
| 663 | int tpm_vendor_init(uint32_t dev_addr) |
| 664 | { |
| 665 | uint old_addr; |
| 666 | int rc = 0; |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 667 | |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 668 | old_addr = tpm_dev.addr; |
| 669 | if (dev_addr != 0) |
| 670 | tpm_dev.addr = dev_addr; |
| 671 | |
| 672 | rc = tpm_vendor_init_common(); |
| 673 | if (rc) |
| 674 | tpm_dev.addr = old_addr; |
| 675 | |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 676 | return rc; |
| 677 | } |
Simon Glass | f90acf1 | 2015-05-04 11:30:59 -0600 | [diff] [blame] | 678 | #endif |
Rong Chang | f626799 | 2013-04-12 10:44:57 +0000 | [diff] [blame] | 679 | |
| 680 | void tpm_vendor_cleanup(struct tpm_chip *chip) |
| 681 | { |
| 682 | release_locality(chip, chip->vendor.locality, 1); |
| 683 | } |