st33zp24.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * STMicroelectronics TPM Linux driver for TPM ST33ZP24
  3. * Copyright (C) 2009 - 2016 STMicroelectronics
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/fs.h>
  20. #include <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <linux/wait.h>
  23. #include <linux/freezer.h>
  24. #include <linux/string.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/gpio.h>
  27. #include <linux/sched.h>
  28. #include <linux/uaccess.h>
  29. #include <linux/io.h>
  30. #include <linux/slab.h>
  31. #include "../tpm.h"
  32. #include "st33zp24.h"
  33. #define TPM_ACCESS 0x0
  34. #define TPM_STS 0x18
  35. #define TPM_DATA_FIFO 0x24
  36. #define TPM_INTF_CAPABILITY 0x14
  37. #define TPM_INT_STATUS 0x10
  38. #define TPM_INT_ENABLE 0x08
  39. #define LOCALITY0 0
  40. enum st33zp24_access {
  41. TPM_ACCESS_VALID = 0x80,
  42. TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
  43. TPM_ACCESS_REQUEST_PENDING = 0x04,
  44. TPM_ACCESS_REQUEST_USE = 0x02,
  45. };
  46. enum st33zp24_status {
  47. TPM_STS_VALID = 0x80,
  48. TPM_STS_COMMAND_READY = 0x40,
  49. TPM_STS_GO = 0x20,
  50. TPM_STS_DATA_AVAIL = 0x10,
  51. TPM_STS_DATA_EXPECT = 0x08,
  52. };
  53. enum st33zp24_int_flags {
  54. TPM_GLOBAL_INT_ENABLE = 0x80,
  55. TPM_INTF_CMD_READY_INT = 0x080,
  56. TPM_INTF_FIFO_AVALAIBLE_INT = 0x040,
  57. TPM_INTF_WAKE_UP_READY_INT = 0x020,
  58. TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
  59. TPM_INTF_STS_VALID_INT = 0x002,
  60. TPM_INTF_DATA_AVAIL_INT = 0x001,
  61. };
  62. enum tis_defaults {
  63. TIS_SHORT_TIMEOUT = 750,
  64. TIS_LONG_TIMEOUT = 2000,
  65. };
  66. /*
  67. * clear_interruption clear the pending interrupt.
  68. * @param: tpm_dev, the tpm device device.
  69. * @return: the interrupt status value.
  70. */
  71. static u8 clear_interruption(struct st33zp24_dev *tpm_dev)
  72. {
  73. u8 interrupt;
  74. tpm_dev->ops->recv(tpm_dev->phy_id, TPM_INT_STATUS, &interrupt, 1);
  75. tpm_dev->ops->send(tpm_dev->phy_id, TPM_INT_STATUS, &interrupt, 1);
  76. return interrupt;
  77. } /* clear_interruption() */
  78. /*
  79. * st33zp24_cancel, cancel the current command execution or
  80. * set STS to COMMAND READY.
  81. * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
  82. */
  83. static void st33zp24_cancel(struct tpm_chip *chip)
  84. {
  85. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  86. u8 data;
  87. data = TPM_STS_COMMAND_READY;
  88. tpm_dev->ops->send(tpm_dev->phy_id, TPM_STS, &data, 1);
  89. } /* st33zp24_cancel() */
  90. /*
  91. * st33zp24_status return the TPM_STS register
  92. * @param: chip, the tpm chip description
  93. * @return: the TPM_STS register value.
  94. */
  95. static u8 st33zp24_status(struct tpm_chip *chip)
  96. {
  97. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  98. u8 data;
  99. tpm_dev->ops->recv(tpm_dev->phy_id, TPM_STS, &data, 1);
  100. return data;
  101. } /* st33zp24_status() */
  102. /*
  103. * check_locality if the locality is active
  104. * @param: chip, the tpm chip description
  105. * @return: true if LOCALITY0 is active, otherwise false
  106. */
  107. static bool check_locality(struct tpm_chip *chip)
  108. {
  109. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  110. u8 data;
  111. u8 status;
  112. status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
  113. if (status && (data &
  114. (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
  115. (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
  116. return true;
  117. return false;
  118. } /* check_locality() */
  119. /*
  120. * request_locality request the TPM locality
  121. * @param: chip, the chip description
  122. * @return: the active locality or negative value.
  123. */
  124. static int request_locality(struct tpm_chip *chip)
  125. {
  126. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  127. unsigned long stop;
  128. long ret;
  129. u8 data;
  130. if (check_locality(chip))
  131. return tpm_dev->locality;
  132. data = TPM_ACCESS_REQUEST_USE;
  133. ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
  134. if (ret < 0)
  135. return ret;
  136. stop = jiffies + chip->timeout_a;
  137. /* Request locality is usually effective after the request */
  138. do {
  139. if (check_locality(chip))
  140. return tpm_dev->locality;
  141. msleep(TPM_TIMEOUT);
  142. } while (time_before(jiffies, stop));
  143. /* could not get locality */
  144. return -EACCES;
  145. } /* request_locality() */
  146. /*
  147. * release_locality release the active locality
  148. * @param: chip, the tpm chip description.
  149. */
  150. static void release_locality(struct tpm_chip *chip)
  151. {
  152. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  153. u8 data;
  154. data = TPM_ACCESS_ACTIVE_LOCALITY;
  155. tpm_dev->ops->send(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
  156. }
  157. /*
  158. * get_burstcount return the burstcount value
  159. * @param: chip, the chip description
  160. * return: the burstcount or negative value.
  161. */
  162. static int get_burstcount(struct tpm_chip *chip)
  163. {
  164. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  165. unsigned long stop;
  166. int burstcnt, status;
  167. u8 temp;
  168. stop = jiffies + chip->timeout_d;
  169. do {
  170. status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_STS + 1,
  171. &temp, 1);
  172. if (status < 0)
  173. return -EBUSY;
  174. burstcnt = temp;
  175. status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_STS + 2,
  176. &temp, 1);
  177. if (status < 0)
  178. return -EBUSY;
  179. burstcnt |= temp << 8;
  180. if (burstcnt)
  181. return burstcnt;
  182. msleep(TPM_TIMEOUT);
  183. } while (time_before(jiffies, stop));
  184. return -EBUSY;
  185. } /* get_burstcount() */
  186. /*
  187. * wait_for_tpm_stat_cond
  188. * @param: chip, chip description
  189. * @param: mask, expected mask value
  190. * @param: check_cancel, does the command expected to be canceled ?
  191. * @param: canceled, did we received a cancel request ?
  192. * @return: true if status == mask or if the command is canceled.
  193. * false in other cases.
  194. */
  195. static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
  196. bool check_cancel, bool *canceled)
  197. {
  198. u8 status = chip->ops->status(chip);
  199. *canceled = false;
  200. if ((status & mask) == mask)
  201. return true;
  202. if (check_cancel && chip->ops->req_canceled(chip, status)) {
  203. *canceled = true;
  204. return true;
  205. }
  206. return false;
  207. }
  208. /*
  209. * wait_for_stat wait for a TPM_STS value
  210. * @param: chip, the tpm chip description
  211. * @param: mask, the value mask to wait
  212. * @param: timeout, the timeout
  213. * @param: queue, the wait queue.
  214. * @param: check_cancel, does the command can be cancelled ?
  215. * @return: the tpm status, 0 if success, -ETIME if timeout is reached.
  216. */
  217. static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
  218. wait_queue_head_t *queue, bool check_cancel)
  219. {
  220. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  221. unsigned long stop;
  222. int ret = 0;
  223. bool canceled = false;
  224. bool condition;
  225. u32 cur_intrs;
  226. u8 status;
  227. /* check current status */
  228. status = st33zp24_status(chip);
  229. if ((status & mask) == mask)
  230. return 0;
  231. stop = jiffies + timeout;
  232. if (chip->flags & TPM_CHIP_FLAG_IRQ) {
  233. cur_intrs = tpm_dev->intrs;
  234. clear_interruption(tpm_dev);
  235. enable_irq(tpm_dev->irq);
  236. do {
  237. if (ret == -ERESTARTSYS && freezing(current))
  238. clear_thread_flag(TIF_SIGPENDING);
  239. timeout = stop - jiffies;
  240. if ((long) timeout <= 0)
  241. return -1;
  242. ret = wait_event_interruptible_timeout(*queue,
  243. cur_intrs != tpm_dev->intrs,
  244. timeout);
  245. clear_interruption(tpm_dev);
  246. condition = wait_for_tpm_stat_cond(chip, mask,
  247. check_cancel, &canceled);
  248. if (ret >= 0 && condition) {
  249. if (canceled)
  250. return -ECANCELED;
  251. return 0;
  252. }
  253. } while (ret == -ERESTARTSYS && freezing(current));
  254. disable_irq_nosync(tpm_dev->irq);
  255. } else {
  256. do {
  257. msleep(TPM_TIMEOUT);
  258. status = chip->ops->status(chip);
  259. if ((status & mask) == mask)
  260. return 0;
  261. } while (time_before(jiffies, stop));
  262. }
  263. return -ETIME;
  264. } /* wait_for_stat() */
  265. /*
  266. * recv_data receive data
  267. * @param: chip, the tpm chip description
  268. * @param: buf, the buffer where the data are received
  269. * @param: count, the number of data to receive
  270. * @return: the number of bytes read from TPM FIFO.
  271. */
  272. static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
  273. {
  274. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  275. int size = 0, burstcnt, len, ret;
  276. while (size < count &&
  277. wait_for_stat(chip,
  278. TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  279. chip->timeout_c,
  280. &tpm_dev->read_queue, true) == 0) {
  281. burstcnt = get_burstcount(chip);
  282. if (burstcnt < 0)
  283. return burstcnt;
  284. len = min_t(int, burstcnt, count - size);
  285. ret = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_DATA_FIFO,
  286. buf + size, len);
  287. if (ret < 0)
  288. return ret;
  289. size += len;
  290. }
  291. return size;
  292. }
  293. /*
  294. * tpm_ioserirq_handler the serirq irq handler
  295. * @param: irq, the tpm chip description
  296. * @param: dev_id, the description of the chip
  297. * @return: the status of the handler.
  298. */
  299. static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
  300. {
  301. struct tpm_chip *chip = dev_id;
  302. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  303. tpm_dev->intrs++;
  304. wake_up_interruptible(&tpm_dev->read_queue);
  305. disable_irq_nosync(tpm_dev->irq);
  306. return IRQ_HANDLED;
  307. } /* tpm_ioserirq_handler() */
  308. /*
  309. * st33zp24_send send TPM commands through the I2C bus.
  310. *
  311. * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
  312. * @param: buf, the buffer to send.
  313. * @param: count, the number of bytes to send.
  314. * @return: In case of success the number of bytes sent.
  315. * In other case, a < 0 value describing the issue.
  316. */
  317. static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
  318. size_t len)
  319. {
  320. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  321. u32 status, i, size, ordinal;
  322. int burstcnt = 0;
  323. int ret;
  324. u8 data;
  325. if (len < TPM_HEADER_SIZE)
  326. return -EBUSY;
  327. ret = request_locality(chip);
  328. if (ret < 0)
  329. return ret;
  330. status = st33zp24_status(chip);
  331. if ((status & TPM_STS_COMMAND_READY) == 0) {
  332. st33zp24_cancel(chip);
  333. if (wait_for_stat
  334. (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
  335. &tpm_dev->read_queue, false) < 0) {
  336. ret = -ETIME;
  337. goto out_err;
  338. }
  339. }
  340. for (i = 0; i < len - 1;) {
  341. burstcnt = get_burstcount(chip);
  342. if (burstcnt < 0)
  343. return burstcnt;
  344. size = min_t(int, len - i - 1, burstcnt);
  345. ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_DATA_FIFO,
  346. buf + i, size);
  347. if (ret < 0)
  348. goto out_err;
  349. i += size;
  350. }
  351. status = st33zp24_status(chip);
  352. if ((status & TPM_STS_DATA_EXPECT) == 0) {
  353. ret = -EIO;
  354. goto out_err;
  355. }
  356. ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_DATA_FIFO,
  357. buf + len - 1, 1);
  358. if (ret < 0)
  359. goto out_err;
  360. status = st33zp24_status(chip);
  361. if ((status & TPM_STS_DATA_EXPECT) != 0) {
  362. ret = -EIO;
  363. goto out_err;
  364. }
  365. data = TPM_STS_GO;
  366. ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_STS, &data, 1);
  367. if (ret < 0)
  368. goto out_err;
  369. if (chip->flags & TPM_CHIP_FLAG_IRQ) {
  370. ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
  371. ret = wait_for_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  372. tpm_calc_ordinal_duration(chip, ordinal),
  373. &tpm_dev->read_queue, false);
  374. if (ret < 0)
  375. goto out_err;
  376. }
  377. return 0;
  378. out_err:
  379. st33zp24_cancel(chip);
  380. release_locality(chip);
  381. return ret;
  382. }
  383. /*
  384. * st33zp24_recv received TPM response through TPM phy.
  385. * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
  386. * @param: buf, the buffer to store datas.
  387. * @param: count, the number of bytes to send.
  388. * @return: In case of success the number of bytes received.
  389. * In other case, a < 0 value describing the issue.
  390. */
  391. static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf,
  392. size_t count)
  393. {
  394. int size = 0;
  395. u32 expected;
  396. if (!chip)
  397. return -EBUSY;
  398. if (count < TPM_HEADER_SIZE) {
  399. size = -EIO;
  400. goto out;
  401. }
  402. size = recv_data(chip, buf, TPM_HEADER_SIZE);
  403. if (size < TPM_HEADER_SIZE) {
  404. dev_err(&chip->dev, "Unable to read header\n");
  405. goto out;
  406. }
  407. expected = be32_to_cpu(*(__be32 *)(buf + 2));
  408. if (expected > count || expected < TPM_HEADER_SIZE) {
  409. size = -EIO;
  410. goto out;
  411. }
  412. size += recv_data(chip, &buf[TPM_HEADER_SIZE],
  413. expected - TPM_HEADER_SIZE);
  414. if (size < expected) {
  415. dev_err(&chip->dev, "Unable to read remainder of result\n");
  416. size = -ETIME;
  417. }
  418. out:
  419. st33zp24_cancel(chip);
  420. release_locality(chip);
  421. return size;
  422. }
  423. /*
  424. * st33zp24_req_canceled
  425. * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
  426. * @param: status, the TPM status.
  427. * @return: Does TPM ready to compute a new command ? true.
  428. */
  429. static bool st33zp24_req_canceled(struct tpm_chip *chip, u8 status)
  430. {
  431. return (status == TPM_STS_COMMAND_READY);
  432. }
  433. static const struct tpm_class_ops st33zp24_tpm = {
  434. .flags = TPM_OPS_AUTO_STARTUP,
  435. .send = st33zp24_send,
  436. .recv = st33zp24_recv,
  437. .cancel = st33zp24_cancel,
  438. .status = st33zp24_status,
  439. .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  440. .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  441. .req_canceled = st33zp24_req_canceled,
  442. };
  443. /*
  444. * st33zp24_probe initialize the TPM device
  445. * @param: client, the i2c_client drescription (TPM I2C description).
  446. * @param: id, the i2c_device_id struct.
  447. * @return: 0 in case of success.
  448. * -1 in other case.
  449. */
  450. int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
  451. struct device *dev, int irq, int io_lpcpd)
  452. {
  453. int ret;
  454. u8 intmask = 0;
  455. struct tpm_chip *chip;
  456. struct st33zp24_dev *tpm_dev;
  457. chip = tpmm_chip_alloc(dev, &st33zp24_tpm);
  458. if (IS_ERR(chip))
  459. return PTR_ERR(chip);
  460. tpm_dev = devm_kzalloc(dev, sizeof(struct st33zp24_dev),
  461. GFP_KERNEL);
  462. if (!tpm_dev)
  463. return -ENOMEM;
  464. tpm_dev->phy_id = phy_id;
  465. tpm_dev->ops = ops;
  466. dev_set_drvdata(&chip->dev, tpm_dev);
  467. chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
  468. chip->timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
  469. chip->timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
  470. chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
  471. tpm_dev->locality = LOCALITY0;
  472. if (irq) {
  473. /* INTERRUPT Setup */
  474. init_waitqueue_head(&tpm_dev->read_queue);
  475. tpm_dev->intrs = 0;
  476. if (request_locality(chip) != LOCALITY0) {
  477. ret = -ENODEV;
  478. goto _tpm_clean_answer;
  479. }
  480. clear_interruption(tpm_dev);
  481. ret = devm_request_irq(dev, irq, tpm_ioserirq_handler,
  482. IRQF_TRIGGER_HIGH, "TPM SERIRQ management",
  483. chip);
  484. if (ret < 0) {
  485. dev_err(&chip->dev, "TPM SERIRQ signals %d not available\n",
  486. irq);
  487. goto _tpm_clean_answer;
  488. }
  489. intmask |= TPM_INTF_CMD_READY_INT
  490. | TPM_INTF_STS_VALID_INT
  491. | TPM_INTF_DATA_AVAIL_INT;
  492. ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_INT_ENABLE,
  493. &intmask, 1);
  494. if (ret < 0)
  495. goto _tpm_clean_answer;
  496. intmask = TPM_GLOBAL_INT_ENABLE;
  497. ret = tpm_dev->ops->send(tpm_dev->phy_id, (TPM_INT_ENABLE + 3),
  498. &intmask, 1);
  499. if (ret < 0)
  500. goto _tpm_clean_answer;
  501. tpm_dev->irq = irq;
  502. chip->flags |= TPM_CHIP_FLAG_IRQ;
  503. disable_irq_nosync(tpm_dev->irq);
  504. }
  505. return tpm_chip_register(chip);
  506. _tpm_clean_answer:
  507. dev_info(&chip->dev, "TPM initialization fail\n");
  508. return ret;
  509. }
  510. EXPORT_SYMBOL(st33zp24_probe);
  511. /*
  512. * st33zp24_remove remove the TPM device
  513. * @param: tpm_data, the tpm phy.
  514. * @return: 0 in case of success.
  515. */
  516. int st33zp24_remove(struct tpm_chip *chip)
  517. {
  518. tpm_chip_unregister(chip);
  519. return 0;
  520. }
  521. EXPORT_SYMBOL(st33zp24_remove);
  522. #ifdef CONFIG_PM_SLEEP
  523. /*
  524. * st33zp24_pm_suspend suspend the TPM device
  525. * @param: tpm_data, the tpm phy.
  526. * @param: mesg, the power management message.
  527. * @return: 0 in case of success.
  528. */
  529. int st33zp24_pm_suspend(struct device *dev)
  530. {
  531. struct tpm_chip *chip = dev_get_drvdata(dev);
  532. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  533. int ret = 0;
  534. if (gpio_is_valid(tpm_dev->io_lpcpd))
  535. gpio_set_value(tpm_dev->io_lpcpd, 0);
  536. else
  537. ret = tpm_pm_suspend(dev);
  538. return ret;
  539. } /* st33zp24_pm_suspend() */
  540. EXPORT_SYMBOL(st33zp24_pm_suspend);
  541. /*
  542. * st33zp24_pm_resume resume the TPM device
  543. * @param: tpm_data, the tpm phy.
  544. * @return: 0 in case of success.
  545. */
  546. int st33zp24_pm_resume(struct device *dev)
  547. {
  548. struct tpm_chip *chip = dev_get_drvdata(dev);
  549. struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
  550. int ret = 0;
  551. if (gpio_is_valid(tpm_dev->io_lpcpd)) {
  552. gpio_set_value(tpm_dev->io_lpcpd, 1);
  553. ret = wait_for_stat(chip,
  554. TPM_STS_VALID, chip->timeout_b,
  555. &tpm_dev->read_queue, false);
  556. } else {
  557. ret = tpm_pm_resume(dev);
  558. if (!ret)
  559. tpm_do_selftest(chip);
  560. }
  561. return ret;
  562. } /* st33zp24_pm_resume() */
  563. EXPORT_SYMBOL(st33zp24_pm_resume);
  564. #endif
  565. MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)");
  566. MODULE_DESCRIPTION("ST33ZP24 TPM 1.2 driver");
  567. MODULE_VERSION("1.3.0");
  568. MODULE_LICENSE("GPL");