tpm_tis_i2c.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. #include <common.h>
  39. #include <dm.h>
  40. #include <fdtdec.h>
  41. #include <linux/compiler.h>
  42. #include <i2c.h>
  43. #include <tpm.h>
  44. #include <asm-generic/errno.h>
  45. #include <linux/types.h>
  46. #include <linux/unaligned/be_byteshift.h>
  47. #include "tpm_private.h"
  48. DECLARE_GLOBAL_DATA_PTR;
  49. /* Address of the TPM on the I2C bus */
  50. #define TPM_I2C_ADDR 0x20
  51. /* Max buffer size supported by our tpm */
  52. #define TPM_DEV_BUFSIZE 1260
  53. /* Max number of iterations after i2c NAK */
  54. #define MAX_COUNT 3
  55. /*
  56. * Max number of iterations after i2c NAK for 'long' commands
  57. *
  58. * We need this especially for sending TPM_READY, since the cleanup after the
  59. * transtion to the ready state may take some time, but it is unpredictable
  60. * how long it will take.
  61. */
  62. #define MAX_COUNT_LONG 50
  63. #define SLEEP_DURATION 60 /* in usec */
  64. #define SLEEP_DURATION_LONG 210 /* in usec */
  65. #define TPM_HEADER_SIZE 10
  66. /*
  67. * Expected value for DIDVID register
  68. *
  69. * The only device the system knows about at this moment is Infineon slb9635.
  70. */
  71. #define TPM_TIS_I2C_DID_VID 0x000b15d1L
  72. enum tis_access {
  73. TPM_ACCESS_VALID = 0x80,
  74. TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
  75. TPM_ACCESS_REQUEST_PENDING = 0x04,
  76. TPM_ACCESS_REQUEST_USE = 0x02,
  77. };
  78. enum tis_status {
  79. TPM_STS_VALID = 0x80,
  80. TPM_STS_COMMAND_READY = 0x40,
  81. TPM_STS_GO = 0x20,
  82. TPM_STS_DATA_AVAIL = 0x10,
  83. TPM_STS_DATA_EXPECT = 0x08,
  84. };
  85. enum tis_defaults {
  86. TIS_SHORT_TIMEOUT = 750, /* ms */
  87. TIS_LONG_TIMEOUT = 2000, /* ms */
  88. };
  89. /* expected value for DIDVID register */
  90. #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
  91. #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
  92. enum i2c_chip_type {
  93. SLB9635,
  94. SLB9645,
  95. UNKNOWN,
  96. };
  97. static const char * const chip_name[] = {
  98. [SLB9635] = "slb9635tt",
  99. [SLB9645] = "slb9645tt",
  100. [UNKNOWN] = "unknown/fallback to slb9635",
  101. };
  102. #define TPM_ACCESS(l) (0x0000 | ((l) << 4))
  103. #define TPM_STS(l) (0x0001 | ((l) << 4))
  104. #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
  105. #define TPM_DID_VID(l) (0x0006 | ((l) << 4))
  106. /* Structure to store I2C TPM specific stuff */
  107. struct tpm_dev {
  108. #ifdef CONFIG_DM_I2C
  109. struct udevice *dev;
  110. #else
  111. uint addr;
  112. #endif
  113. u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
  114. enum i2c_chip_type chip_type;
  115. };
  116. static struct tpm_dev tpm_dev = {
  117. #ifndef CONFIG_DM_I2C
  118. .addr = TPM_I2C_ADDR
  119. #endif
  120. };
  121. static struct tpm_dev tpm_dev;
  122. /*
  123. * iic_tpm_read() - read from TPM register
  124. * @addr: register address to read from
  125. * @buffer: provided by caller
  126. * @len: number of bytes to read
  127. *
  128. * Read len bytes from TPM register and put them into
  129. * buffer (little-endian format, i.e. first byte is put into buffer[0]).
  130. *
  131. * NOTE: TPM is big-endian for multi-byte values. Multi-byte
  132. * values have to be swapped.
  133. *
  134. * Return -EIO on error, 0 on success.
  135. */
  136. static int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
  137. {
  138. int rc;
  139. int count;
  140. uint32_t addrbuf = addr;
  141. if ((tpm_dev.chip_type == SLB9635) || (tpm_dev.chip_type == UNKNOWN)) {
  142. /* slb9635 protocol should work in both cases */
  143. for (count = 0; count < MAX_COUNT; count++) {
  144. #ifdef CONFIG_DM_I2C
  145. rc = dm_i2c_write(tpm_dev.dev, 0, (uchar *)&addrbuf, 1);
  146. #else
  147. rc = i2c_write(tpm_dev.addr, 0, 0,
  148. (uchar *)&addrbuf, 1);
  149. #endif
  150. if (rc == 0)
  151. break; /* Success, break to skip sleep */
  152. udelay(SLEEP_DURATION);
  153. }
  154. if (rc)
  155. return -rc;
  156. /* After the TPM has successfully received the register address
  157. * it needs some time, thus we're sleeping here again, before
  158. * retrieving the data
  159. */
  160. for (count = 0; count < MAX_COUNT; count++) {
  161. udelay(SLEEP_DURATION);
  162. #ifdef CONFIG_DM_I2C
  163. rc = dm_i2c_read(tpm_dev.dev, 0, buffer, len);
  164. #else
  165. rc = i2c_read(tpm_dev.addr, 0, 0, buffer, len);
  166. #endif
  167. if (rc == 0)
  168. break; /* success, break to skip sleep */
  169. }
  170. } else {
  171. /*
  172. * Use a combined read for newer chips.
  173. * Unfortunately the smbus functions are not suitable due to
  174. * the 32 byte limit of the smbus.
  175. * Retries should usually not be needed, but are kept just to
  176. * be safe on the safe side.
  177. */
  178. for (count = 0; count < MAX_COUNT; count++) {
  179. #ifdef CONFIG_DM_I2C
  180. rc = dm_i2c_read(tpm_dev.dev, addr, buffer, len);
  181. #else
  182. rc = i2c_read(tpm_dev.addr, addr, 1, buffer, len);
  183. #endif
  184. if (rc == 0)
  185. break; /* break here to skip sleep */
  186. udelay(SLEEP_DURATION);
  187. }
  188. }
  189. /* Take care of 'guard time' */
  190. udelay(SLEEP_DURATION);
  191. if (rc)
  192. return -rc;
  193. return 0;
  194. }
  195. static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
  196. unsigned int sleep_time, u8 max_count)
  197. {
  198. int rc = 0;
  199. int count;
  200. /* Prepare send buffer */
  201. #ifndef CONFIG_DM_I2C
  202. tpm_dev.buf[0] = addr;
  203. memcpy(&(tpm_dev.buf[1]), buffer, len);
  204. buffer = tpm_dev.buf;
  205. len++;
  206. #endif
  207. for (count = 0; count < max_count; count++) {
  208. #ifdef CONFIG_DM_I2C
  209. rc = dm_i2c_write(tpm_dev.dev, addr, buffer, len);
  210. #else
  211. rc = i2c_write(tpm_dev.addr, 0, 0, buffer, len);
  212. #endif
  213. if (rc == 0)
  214. break; /* Success, break to skip sleep */
  215. udelay(sleep_time);
  216. }
  217. /* take care of 'guard time' */
  218. udelay(sleep_time);
  219. if (rc)
  220. return -rc;
  221. return 0;
  222. }
  223. /*
  224. * iic_tpm_write() - write to TPM register
  225. * @addr: register address to write to
  226. * @buffer: containing data to be written
  227. * @len: number of bytes to write
  228. *
  229. * Write len bytes from provided buffer to TPM register (little
  230. * endian format, i.e. buffer[0] is written as first byte).
  231. *
  232. * NOTE: TPM is big-endian for multi-byte values. Multi-byte
  233. * values have to be swapped.
  234. *
  235. * NOTE: use this function instead of the iic_tpm_write_generic function.
  236. *
  237. * Return -EIO on error, 0 on success
  238. */
  239. static int iic_tpm_write(u8 addr, u8 *buffer, size_t len)
  240. {
  241. return iic_tpm_write_generic(addr, buffer, len, SLEEP_DURATION,
  242. MAX_COUNT);
  243. }
  244. /*
  245. * This function is needed especially for the cleanup situation after
  246. * sending TPM_READY
  247. */
  248. static int iic_tpm_write_long(u8 addr, u8 *buffer, size_t len)
  249. {
  250. return iic_tpm_write_generic(addr, buffer, len, SLEEP_DURATION_LONG,
  251. MAX_COUNT_LONG);
  252. }
  253. static int check_locality(struct tpm_chip *chip, int loc)
  254. {
  255. const u8 mask = TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID;
  256. u8 buf;
  257. int rc;
  258. rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1);
  259. if (rc < 0)
  260. return rc;
  261. if ((buf & mask) == mask) {
  262. chip->vendor.locality = loc;
  263. return loc;
  264. }
  265. return -1;
  266. }
  267. static void release_locality(struct tpm_chip *chip, int loc, int force)
  268. {
  269. const u8 mask = TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID;
  270. u8 buf;
  271. if (iic_tpm_read(TPM_ACCESS(loc), &buf, 1) < 0)
  272. return;
  273. if (force || (buf & mask) == mask) {
  274. buf = TPM_ACCESS_ACTIVE_LOCALITY;
  275. iic_tpm_write(TPM_ACCESS(loc), &buf, 1);
  276. }
  277. }
  278. static int request_locality(struct tpm_chip *chip, int loc)
  279. {
  280. unsigned long start, stop;
  281. u8 buf = TPM_ACCESS_REQUEST_USE;
  282. int rc;
  283. if (check_locality(chip, loc) >= 0)
  284. return loc; /* We already have the locality */
  285. rc = iic_tpm_write(TPM_ACCESS(loc), &buf, 1);
  286. if (rc)
  287. return rc;
  288. /* Wait for burstcount */
  289. start = get_timer(0);
  290. stop = chip->vendor.timeout_a;
  291. do {
  292. if (check_locality(chip, loc) >= 0)
  293. return loc;
  294. udelay(TPM_TIMEOUT * 1000);
  295. } while (get_timer(start) < stop);
  296. return -1;
  297. }
  298. static u8 tpm_tis_i2c_status(struct tpm_chip *chip)
  299. {
  300. /* NOTE: Since i2c read may fail, return 0 in this case --> time-out */
  301. u8 buf;
  302. if (iic_tpm_read(TPM_STS(chip->vendor.locality), &buf, 1) < 0)
  303. return 0;
  304. else
  305. return buf;
  306. }
  307. static void tpm_tis_i2c_ready(struct tpm_chip *chip)
  308. {
  309. int rc;
  310. /* This causes the current command to be aborted */
  311. u8 buf = TPM_STS_COMMAND_READY;
  312. debug("%s\n", __func__);
  313. rc = iic_tpm_write_long(TPM_STS(chip->vendor.locality), &buf, 1);
  314. if (rc)
  315. debug("%s: rc=%d\n", __func__, rc);
  316. }
  317. static ssize_t get_burstcount(struct tpm_chip *chip)
  318. {
  319. unsigned long start, stop;
  320. ssize_t burstcnt;
  321. u8 addr, buf[3];
  322. /* Wait for burstcount */
  323. /* XXX: Which timeout value? Spec has 2 answers (c & d) */
  324. start = get_timer(0);
  325. stop = chip->vendor.timeout_d;
  326. do {
  327. /* Note: STS is little endian */
  328. addr = TPM_STS(chip->vendor.locality) + 1;
  329. if (iic_tpm_read(addr, buf, 3) < 0)
  330. burstcnt = 0;
  331. else
  332. burstcnt = (buf[2] << 16) + (buf[1] << 8) + buf[0];
  333. if (burstcnt)
  334. return burstcnt;
  335. udelay(TPM_TIMEOUT * 1000);
  336. } while (get_timer(start) < stop);
  337. return -EBUSY;
  338. }
  339. static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
  340. int *status)
  341. {
  342. unsigned long start, stop;
  343. /* Check current status */
  344. *status = tpm_tis_i2c_status(chip);
  345. if ((*status & mask) == mask)
  346. return 0;
  347. start = get_timer(0);
  348. stop = timeout;
  349. do {
  350. udelay(TPM_TIMEOUT * 1000);
  351. *status = tpm_tis_i2c_status(chip);
  352. if ((*status & mask) == mask)
  353. return 0;
  354. } while (get_timer(start) < stop);
  355. return -ETIME;
  356. }
  357. static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
  358. {
  359. size_t size = 0;
  360. ssize_t burstcnt;
  361. int rc;
  362. while (size < count) {
  363. burstcnt = get_burstcount(chip);
  364. /* burstcount < 0 -> tpm is busy */
  365. if (burstcnt < 0)
  366. return burstcnt;
  367. /* Limit received data to max left */
  368. if (burstcnt > (count - size))
  369. burstcnt = count - size;
  370. rc = iic_tpm_read(TPM_DATA_FIFO(chip->vendor.locality),
  371. &(buf[size]), burstcnt);
  372. if (rc == 0)
  373. size += burstcnt;
  374. }
  375. return size;
  376. }
  377. static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
  378. {
  379. int size = 0;
  380. int expected, status;
  381. if (count < TPM_HEADER_SIZE) {
  382. size = -EIO;
  383. goto out;
  384. }
  385. /* Read first 10 bytes, including tag, paramsize, and result */
  386. size = recv_data(chip, buf, TPM_HEADER_SIZE);
  387. if (size < TPM_HEADER_SIZE) {
  388. error("Unable to read header\n");
  389. goto out;
  390. }
  391. expected = get_unaligned_be32(buf + TPM_RSP_SIZE_BYTE);
  392. if ((size_t)expected > count) {
  393. error("Error size=%x, expected=%x, count=%x\n", size, expected,
  394. count);
  395. size = -EIO;
  396. goto out;
  397. }
  398. size += recv_data(chip, &buf[TPM_HEADER_SIZE],
  399. expected - TPM_HEADER_SIZE);
  400. if (size < expected) {
  401. error("Unable to read remainder of result\n");
  402. size = -ETIME;
  403. goto out;
  404. }
  405. wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status);
  406. if (status & TPM_STS_DATA_AVAIL) { /* Retry? */
  407. error("Error left over data\n");
  408. size = -EIO;
  409. goto out;
  410. }
  411. out:
  412. tpm_tis_i2c_ready(chip);
  413. /*
  414. * The TPM needs some time to clean up here,
  415. * so we sleep rather than keeping the bus busy
  416. */
  417. udelay(2000);
  418. release_locality(chip, chip->vendor.locality, 0);
  419. return size;
  420. }
  421. static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
  422. {
  423. int rc, status;
  424. size_t burstcnt;
  425. size_t count = 0;
  426. int retry = 0;
  427. u8 sts = TPM_STS_GO;
  428. debug("%s: len=%d\n", __func__, len);
  429. if (len > TPM_DEV_BUFSIZE)
  430. return -E2BIG; /* Command is too long for our tpm, sorry */
  431. if (request_locality(chip, 0) < 0)
  432. return -EBUSY;
  433. status = tpm_tis_i2c_status(chip);
  434. if ((status & TPM_STS_COMMAND_READY) == 0) {
  435. tpm_tis_i2c_ready(chip);
  436. if (wait_for_stat(chip, TPM_STS_COMMAND_READY,
  437. chip->vendor.timeout_b, &status) < 0) {
  438. rc = -ETIME;
  439. goto out_err;
  440. }
  441. }
  442. burstcnt = get_burstcount(chip);
  443. /* burstcount < 0 -> tpm is busy */
  444. if (burstcnt < 0)
  445. return burstcnt;
  446. while (count < len) {
  447. udelay(300);
  448. if (burstcnt > len - count)
  449. burstcnt = len - count;
  450. #ifdef CONFIG_TPM_TIS_I2C_BURST_LIMITATION
  451. if (retry && burstcnt > CONFIG_TPM_TIS_I2C_BURST_LIMITATION)
  452. burstcnt = CONFIG_TPM_TIS_I2C_BURST_LIMITATION;
  453. #endif /* CONFIG_TPM_TIS_I2C_BURST_LIMITATION */
  454. rc = iic_tpm_write(TPM_DATA_FIFO(chip->vendor.locality),
  455. &(buf[count]), burstcnt);
  456. if (rc == 0)
  457. count += burstcnt;
  458. else {
  459. debug("%s: error\n", __func__);
  460. if (retry++ > 10) {
  461. rc = -EIO;
  462. goto out_err;
  463. }
  464. rc = wait_for_stat(chip, TPM_STS_VALID,
  465. chip->vendor.timeout_c, &status);
  466. if (rc)
  467. goto out_err;
  468. if ((status & TPM_STS_DATA_EXPECT) == 0) {
  469. rc = -EIO;
  470. goto out_err;
  471. }
  472. }
  473. }
  474. /* Go and do it */
  475. iic_tpm_write(TPM_STS(chip->vendor.locality), &sts, 1);
  476. debug("done\n");
  477. return len;
  478. out_err:
  479. debug("%s: out_err\n", __func__);
  480. tpm_tis_i2c_ready(chip);
  481. /*
  482. * The TPM needs some time to clean up here,
  483. * so we sleep rather than keeping the bus busy
  484. */
  485. udelay(2000);
  486. release_locality(chip, chip->vendor.locality, 0);
  487. return rc;
  488. }
  489. static struct tpm_vendor_specific tpm_tis_i2c = {
  490. .status = tpm_tis_i2c_status,
  491. .recv = tpm_tis_i2c_recv,
  492. .send = tpm_tis_i2c_send,
  493. .cancel = tpm_tis_i2c_ready,
  494. .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  495. .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  496. .req_canceled = TPM_STS_COMMAND_READY,
  497. };
  498. static enum i2c_chip_type tpm_vendor_chip_type(void)
  499. {
  500. #ifdef CONFIG_OF_CONTROL
  501. const void *blob = gd->fdt_blob;
  502. if (fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9645_TPM) >= 0)
  503. return SLB9645;
  504. if (fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9635_TPM) >= 0)
  505. return SLB9635;
  506. #endif
  507. return UNKNOWN;
  508. }
  509. static int tpm_vendor_init_common(void)
  510. {
  511. struct tpm_chip *chip;
  512. u32 vendor;
  513. u32 expected_did_vid;
  514. tpm_dev.chip_type = tpm_vendor_chip_type();
  515. chip = tpm_register_hardware(&tpm_tis_i2c);
  516. if (chip < 0)
  517. return -ENODEV;
  518. /* Disable interrupts (not supported) */
  519. chip->vendor.irq = 0;
  520. /* Default timeouts */
  521. chip->vendor.timeout_a = TIS_SHORT_TIMEOUT;
  522. chip->vendor.timeout_b = TIS_LONG_TIMEOUT;
  523. chip->vendor.timeout_c = TIS_SHORT_TIMEOUT;
  524. chip->vendor.timeout_d = TIS_SHORT_TIMEOUT;
  525. if (request_locality(chip, 0) < 0)
  526. return -ENODEV;
  527. /* Read four bytes from DID_VID register */
  528. if (iic_tpm_read(TPM_DID_VID(0), (uchar *)&vendor, 4) < 0) {
  529. release_locality(chip, 0, 1);
  530. return -EIO;
  531. }
  532. if (tpm_dev.chip_type == SLB9635) {
  533. vendor = be32_to_cpu(vendor);
  534. expected_did_vid = TPM_TIS_I2C_DID_VID_9635;
  535. } else {
  536. /* device id and byte order has changed for newer i2c tpms */
  537. expected_did_vid = TPM_TIS_I2C_DID_VID_9645;
  538. }
  539. if (tpm_dev.chip_type != UNKNOWN && vendor != expected_did_vid) {
  540. error("Vendor id did not match! ID was %08x\n", vendor);
  541. return -ENODEV;
  542. }
  543. debug("1.2 TPM (chip type %s device-id 0x%X)\n",
  544. chip_name[tpm_dev.chip_type], vendor >> 16);
  545. /*
  546. * A timeout query to TPM can be placed here.
  547. * Standard timeout values are used so far
  548. */
  549. return 0;
  550. }
  551. #ifdef CONFIG_DM_I2C
  552. /* Initialisation of i2c tpm */
  553. int tpm_vendor_init_dev(struct udevice *dev)
  554. {
  555. tpm_dev.dev = dev;
  556. return tpm_vendor_init_common();
  557. }
  558. #else
  559. /* Initialisation of i2c tpm */
  560. int tpm_vendor_init(uint32_t dev_addr)
  561. {
  562. uint old_addr;
  563. int rc = 0;
  564. old_addr = tpm_dev.addr;
  565. if (dev_addr != 0)
  566. tpm_dev.addr = dev_addr;
  567. rc = tpm_vendor_init_common();
  568. if (rc)
  569. tpm_dev.addr = old_addr;
  570. return rc;
  571. }
  572. #endif
  573. void tpm_vendor_cleanup(struct tpm_chip *chip)
  574. {
  575. release_locality(chip, chip->vendor.locality, 1);
  576. }