st33zp24.c 17 KB

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