2 * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24
3 * Copyright (C) 2009, 2010 STMicroelectronics
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * STMicroelectronics version 1.2.0, Copyright (C) 2010
20 * STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
21 * This is free software, and you are welcome to redistribute it
22 * under certain conditions.
24 * @Author: Christophe RICARD tpmsupport@st.com
26 * @File: tpm_stm_st33_i2c.c
29 * 09/15/2010: First shot driver tpm_tis driver for
33 #include <linux/pci.h>
34 #include <linux/module.h>
35 #include <linux/platform_device.h>
36 #include <linux/i2c.h>
38 #include <linux/miscdevice.h>
39 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/delay.h>
42 #include <linux/init.h>
43 #include <linux/wait.h>
44 #include <linux/string.h>
45 #include <linux/interrupt.h>
46 #include <linux/spinlock.h>
47 #include <linux/sysfs.h>
48 #include <linux/gpio.h>
49 #include <linux/sched.h>
50 #include <linux/uaccess.h>
52 #include <linux/slab.h>
53 #include <linux/sched.h>
56 #include "tpm_i2c_stm_st33.h"
58 enum stm33zp24_access {
59 TPM_ACCESS_VALID = 0x80,
60 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
61 TPM_ACCESS_REQUEST_PENDING = 0x04,
62 TPM_ACCESS_REQUEST_USE = 0x02,
65 enum stm33zp24_status {
67 TPM_STS_COMMAND_READY = 0x40,
69 TPM_STS_DATA_AVAIL = 0x10,
70 TPM_STS_DATA_EXPECT = 0x08,
73 enum stm33zp24_int_flags {
74 TPM_GLOBAL_INT_ENABLE = 0x80,
75 TPM_INTF_CMD_READY_INT = 0x080,
76 TPM_INTF_FIFO_AVALAIBLE_INT = 0x040,
77 TPM_INTF_WAKE_UP_READY_INT = 0x020,
78 TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
79 TPM_INTF_STS_VALID_INT = 0x002,
80 TPM_INTF_DATA_AVAIL_INT = 0x001,
84 TIS_SHORT_TIMEOUT = 750,
85 TIS_LONG_TIMEOUT = 2000,
90 * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
91 * @param: tpm_register, the tpm tis register where the data should be written
92 * @param: tpm_data, the tpm_data to write inside the tpm_register
93 * @param: tpm_size, The length of the data
94 * @return: Returns negative errno, or else the number of bytes written.
96 static int write8_reg(struct i2c_client *client, u8 tpm_register,
97 u8 *tpm_data, u16 tpm_size)
100 struct st33zp24_platform_data *pin_infos;
102 pin_infos = client->dev.platform_data;
104 pin_infos->tpm_i2c_buffer[0][0] = tpm_register;
105 memcpy(&pin_infos->tpm_i2c_buffer[0][1], tpm_data, tpm_size);
106 value = i2c_master_send(client, pin_infos->tpm_i2c_buffer[0],
113 * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
114 * @param: tpm_register, the tpm tis register where the data should be read
115 * @param: tpm_data, the TPM response
116 * @param: tpm_size, tpm TPM response size to read.
117 * @return: number of byte read successfully: should be one if success.
119 static int read8_reg(struct i2c_client *client, u8 tpm_register,
120 u8 *tpm_data, int tpm_size)
125 data = TPM_DUMMY_BYTE;
126 status = write8_reg(client, tpm_register, &data, 1);
128 status = i2c_master_recv(client, tpm_data, tpm_size);
134 * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
135 * @param: client, the chip description
136 * @param: tpm_register, the tpm tis register where the data should be written
137 * @param: tpm_data, the tpm_data to write inside the tpm_register
138 * @param: tpm_size, The length of the data
139 * @return: number of byte written successfully: should be one if success.
141 #define I2C_WRITE_DATA(client, tpm_register, tpm_data, tpm_size) \
142 (write8_reg(client, tpm_register | \
143 TPM_WRITE_DIRECTION, tpm_data, tpm_size))
147 * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
148 * @param: tpm, the chip description
149 * @param: tpm_register, the tpm tis register where the data should be read
150 * @param: tpm_data, the TPM response
151 * @param: tpm_size, tpm TPM response size to read.
152 * @return: number of byte read successfully: should be one if success.
154 #define I2C_READ_DATA(client, tpm_register, tpm_data, tpm_size) \
155 (read8_reg(client, tpm_register, tpm_data, tpm_size))
159 * clear the TPM interrupt register.
160 * @param: tpm, the chip description
162 static void clear_interruption(struct i2c_client *client)
165 I2C_READ_DATA(client, TPM_INT_STATUS, &interrupt, 1);
166 I2C_WRITE_DATA(client, TPM_INT_STATUS, &interrupt, 1);
167 I2C_READ_DATA(client, TPM_INT_STATUS, &interrupt, 1);
168 } /* clear_interruption() */
171 * _wait_for_interrupt_serirq_timeout
172 * @param: tpm, the chip description
173 * @param: timeout, the timeout of the interrupt
174 * @return: the status of the interruption.
176 static long _wait_for_interrupt_serirq_timeout(struct tpm_chip *chip,
177 unsigned long timeout)
180 struct i2c_client *client;
181 struct st33zp24_platform_data *pin_infos;
183 client = (struct i2c_client *) TPM_VPRIV(chip);
184 pin_infos = client->dev.platform_data;
186 status = wait_for_completion_interruptible_timeout(
187 &pin_infos->irq_detection,
190 enable_irq(gpio_to_irq(pin_infos->io_serirq));
191 gpio_direction_input(pin_infos->io_serirq);
194 } /* wait_for_interrupt_serirq_timeout() */
196 static int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition,
197 unsigned long timeout)
200 struct i2c_client *client;
202 client = (struct i2c_client *) TPM_VPRIV(chip);
204 status = _wait_for_interrupt_serirq_timeout(chip, timeout);
208 clear_interruption(client);
216 * tpm_stm_i2c_cancel, cancel is not implemented.
217 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
219 static void tpm_stm_i2c_cancel(struct tpm_chip *chip)
221 struct i2c_client *client;
224 client = (struct i2c_client *) TPM_VPRIV(chip);
226 data = TPM_STS_COMMAND_READY;
227 I2C_WRITE_DATA(client, TPM_STS, &data, 1);
228 if (chip->vendor.irq)
229 wait_for_serirq_timeout(chip, 1, chip->vendor.timeout_a);
230 } /* tpm_stm_i2c_cancel() */
233 * tpm_stm_spi_status return the TPM_STS register
234 * @param: chip, the tpm chip description
235 * @return: the TPM_STS register value.
237 static u8 tpm_stm_i2c_status(struct tpm_chip *chip)
239 struct i2c_client *client;
241 client = (struct i2c_client *) TPM_VPRIV(chip);
243 I2C_READ_DATA(client, TPM_STS, &data, 1);
245 } /* tpm_stm_i2c_status() */
249 * check_locality if the locality is active
250 * @param: chip, the tpm chip description
251 * @return: the active locality or -EACCESS.
253 static int check_locality(struct tpm_chip *chip)
255 struct i2c_client *client;
259 client = (struct i2c_client *) TPM_VPRIV(chip);
261 status = I2C_READ_DATA(client, TPM_ACCESS, &data, 1);
262 if (status && (data &
263 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
264 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
265 return chip->vendor.locality;
269 } /* check_locality() */
272 * request_locality request the TPM locality
273 * @param: chip, the chip description
274 * @return: the active locality or EACCESS.
276 static int request_locality(struct tpm_chip *chip)
280 struct i2c_client *client;
283 client = (struct i2c_client *) TPM_VPRIV(chip);
285 if (check_locality(chip) == chip->vendor.locality)
286 return chip->vendor.locality;
288 data = TPM_ACCESS_REQUEST_USE;
289 rc = I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1);
293 if (chip->vendor.irq) {
294 rc = wait_for_serirq_timeout(chip, (check_locality
296 chip->vendor.timeout_a);
298 return chip->vendor.locality;
300 stop = jiffies + chip->vendor.timeout_a;
302 if (check_locality(chip) >= 0)
303 return chip->vendor.locality;
305 } while (time_before(jiffies, stop));
310 } /* request_locality() */
313 * release_locality release the active locality
314 * @param: chip, the tpm chip description.
316 static void release_locality(struct tpm_chip *chip)
318 struct i2c_client *client;
321 client = (struct i2c_client *) TPM_VPRIV(chip);
322 data = TPM_ACCESS_ACTIVE_LOCALITY;
324 I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1);
328 * get_burstcount return the burstcount address 0x19 0x1A
329 * @param: chip, the chip description
330 * return: the burstcount.
332 static int get_burstcount(struct tpm_chip *chip)
335 int burstcnt, status;
338 struct i2c_client *client = (struct i2c_client *) TPM_VPRIV(chip);
340 stop = jiffies + chip->vendor.timeout_d;
342 tpm_reg = TPM_STS + 1;
343 status = I2C_READ_DATA(client, tpm_reg, &temp, 1);
347 tpm_reg = tpm_reg + 1;
349 status = I2C_READ_DATA(client, tpm_reg, &temp, 1);
353 burstcnt |= temp << 8;
357 } while (time_before(jiffies, stop));
361 } /* get_burstcount() */
364 * wait_for_stat wait for a TPM_STS value
365 * @param: chip, the tpm chip description
366 * @param: mask, the value mask to wait
367 * @param: timeout, the timeout
368 * @param: queue, the wait queue.
369 * @return: the tpm status, 0 if success, -ETIME if timeout is reached.
371 static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
372 wait_queue_head_t *queue)
378 if (chip->vendor.irq) {
379 rc = wait_for_serirq_timeout(chip, ((tpm_stm_i2c_status
385 stop = jiffies + timeout;
388 status = tpm_stm_i2c_status(chip);
389 if ((status & mask) == mask)
391 } while (time_before(jiffies, stop));
394 } /* wait_for_stat() */
397 * recv_data receive data
398 * @param: chip, the tpm chip description
399 * @param: buf, the buffer where the data are received
400 * @param: count, the number of data to receive
401 * @return: the number of bytes read from TPM FIFO.
403 static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
405 int size = 0, burstcnt, len;
406 struct i2c_client *client;
408 client = (struct i2c_client *) TPM_VPRIV(chip);
410 while (size < count &&
412 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
413 chip->vendor.timeout_c,
414 &chip->vendor.read_queue)
416 burstcnt = get_burstcount(chip);
417 len = min_t(int, burstcnt, count - size);
418 I2C_READ_DATA(client, TPM_DATA_FIFO, buf + size, len);
425 * tpm_ioserirq_handler the serirq irq handler
426 * @param: irq, the tpm chip description
427 * @param: dev_id, the description of the chip
428 * @return: the status of the handler.
430 static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
432 struct tpm_chip *chip = dev_id;
433 struct i2c_client *client;
434 struct st33zp24_platform_data *pin_infos;
436 disable_irq_nosync(irq);
438 client = (struct i2c_client *) TPM_VPRIV(chip);
439 pin_infos = client->dev.platform_data;
441 complete(&pin_infos->irq_detection);
443 } /* tpm_ioserirq_handler() */
447 * tpm_stm_i2c_send send TPM commands through the I2C bus.
449 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
450 * @param: buf, the buffer to send.
451 * @param: count, the number of bytes to send.
452 * @return: In case of success the number of bytes sent.
453 * In other case, a < 0 value describing the issue.
455 static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
459 burstcnt = 0, i, size;
462 struct i2c_client *client;
466 if (len < TPM_HEADER_SIZE)
469 client = (struct i2c_client *)TPM_VPRIV(chip);
473 ret = request_locality(chip);
477 status = tpm_stm_i2c_status(chip);
478 if ((status & TPM_STS_COMMAND_READY) == 0) {
479 tpm_stm_i2c_cancel(chip);
481 (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
482 &chip->vendor.int_queue) < 0) {
488 for (i = 0 ; i < len - 1 ;) {
489 burstcnt = get_burstcount(chip);
490 size = min_t(int, len - i - 1, burstcnt);
491 ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf, size);
498 status = tpm_stm_i2c_status(chip);
499 if ((status & TPM_STS_DATA_EXPECT) == 0) {
504 ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf + len - 1, 1);
508 status = tpm_stm_i2c_status(chip);
509 if ((status & TPM_STS_DATA_EXPECT) != 0) {
515 I2C_WRITE_DATA(client, TPM_STS, &data, 1);
519 tpm_stm_i2c_cancel(chip);
520 release_locality(chip);
525 * tpm_stm_i2c_recv received TPM response through the I2C bus.
526 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
527 * @param: buf, the buffer to store datas.
528 * @param: count, the number of bytes to send.
529 * @return: In case of success the number of bytes received.
530 * In other case, a < 0 value describing the issue.
532 static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf,
541 if (count < TPM_HEADER_SIZE) {
546 size = recv_data(chip, buf, TPM_HEADER_SIZE);
547 if (size < TPM_HEADER_SIZE) {
548 dev_err(chip->dev, "Unable to read header\n");
552 expected = be32_to_cpu(*(__be32 *) (buf + 2));
553 if (expected > count) {
558 size += recv_data(chip, &buf[TPM_HEADER_SIZE],
559 expected - TPM_HEADER_SIZE);
560 if (size < expected) {
561 dev_err(chip->dev, "Unable to read remainder of result\n");
567 chip->vendor.cancel(chip);
568 release_locality(chip);
572 static bool tpm_st33_i2c_req_canceled(struct tpm_chip *chip, u8 status)
574 return (status == TPM_STS_COMMAND_READY);
577 static const struct file_operations tpm_st33_i2c_fops = {
578 .owner = THIS_MODULE,
583 .release = tpm_release,
586 static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
587 static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
588 static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
589 static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL);
590 static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL);
591 static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated, NULL);
592 static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps_1_2, NULL);
593 static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
595 static struct attribute *stm_tpm_attrs[] = {
596 &dev_attr_pubek.attr,
598 &dev_attr_enabled.attr,
599 &dev_attr_active.attr,
600 &dev_attr_owned.attr,
601 &dev_attr_temp_deactivated.attr,
603 &dev_attr_cancel.attr, NULL,
606 static struct attribute_group stm_tpm_attr_grp = {
607 .attrs = stm_tpm_attrs
610 static struct tpm_vendor_specific st_i2c_tpm = {
611 .send = tpm_stm_i2c_send,
612 .recv = tpm_stm_i2c_recv,
613 .cancel = tpm_stm_i2c_cancel,
614 .status = tpm_stm_i2c_status,
615 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
616 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
617 .req_canceled = tpm_st33_i2c_req_canceled,
618 .attr_group = &stm_tpm_attr_grp,
619 .miscdev = {.fops = &tpm_st33_i2c_fops,},
622 static int interrupts ;
623 module_param(interrupts, int, 0444);
624 MODULE_PARM_DESC(interrupts, "Enable interrupts");
626 static int power_mgt = 1;
627 module_param(power_mgt, int, 0444);
628 MODULE_PARM_DESC(power_mgt, "Power Management");
631 * tpm_st33_i2c_probe initialize the TPM device
632 * @param: client, the i2c_client drescription (TPM I2C description).
633 * @param: id, the i2c_device_id struct.
634 * @return: 0 in case of success.
638 tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
642 struct tpm_chip *chip;
643 struct st33zp24_platform_data *platform_data;
647 if (client == NULL) {
648 pr_info("%s: i2c client is NULL. Device not accessible.\n",
654 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
655 dev_info(&client->dev, "client not i2c capable\n");
660 chip = tpm_register_hardware(&client->dev, &st_i2c_tpm);
662 dev_info(&client->dev, "fail chip\n");
667 platform_data = client->dev.platform_data;
669 if (!platform_data) {
670 dev_info(&client->dev, "chip not available\n");
672 goto _tpm_clean_answer;
675 platform_data->tpm_i2c_buffer[0] =
676 kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
677 if (platform_data->tpm_i2c_buffer[0] == NULL) {
679 goto _tpm_clean_answer;
681 platform_data->tpm_i2c_buffer[1] =
682 kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
683 if (platform_data->tpm_i2c_buffer[1] == NULL) {
685 goto _tpm_clean_response1;
688 TPM_VPRIV(chip) = client;
690 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
691 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
692 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
693 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
695 chip->vendor.locality = LOCALITY0;
698 err = gpio_request(platform_data->io_lpcpd, "TPM IO_LPCPD");
701 gpio_set_value(platform_data->io_lpcpd, 1);
705 init_completion(&platform_data->irq_detection);
706 if (request_locality(chip) != LOCALITY0) {
708 goto _tpm_clean_response2;
710 err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ");
714 clear_interruption(client);
715 err = request_irq(gpio_to_irq(platform_data->io_serirq),
716 &tpm_ioserirq_handler,
718 "TPM SERIRQ management", chip);
720 dev_err(chip->dev , "TPM SERIRQ signals %d not available\n",
721 gpio_to_irq(platform_data->io_serirq));
725 err = I2C_READ_DATA(client, TPM_INT_ENABLE, &intmask, 1);
729 intmask |= TPM_INTF_CMD_READY_INT
730 | TPM_INTF_FIFO_AVALAIBLE_INT
731 | TPM_INTF_WAKE_UP_READY_INT
732 | TPM_INTF_LOCALITY_CHANGE_INT
733 | TPM_INTF_STS_VALID_INT
734 | TPM_INTF_DATA_AVAIL_INT;
736 err = I2C_WRITE_DATA(client, TPM_INT_ENABLE, &intmask, 1);
740 intmask = TPM_GLOBAL_INT_ENABLE;
741 err = I2C_WRITE_DATA(client, (TPM_INT_ENABLE + 3), &intmask, 1);
745 err = I2C_READ_DATA(client, TPM_INT_STATUS, &intmask, 1);
749 chip->vendor.irq = interrupts;
751 tpm_gen_interrupt(chip);
754 tpm_get_timeouts(chip);
756 i2c_set_clientdata(client, chip);
758 dev_info(chip->dev, "TPM I2C Initialized\n");
761 free_irq(gpio_to_irq(platform_data->io_serirq), (void *) chip);
764 gpio_free(platform_data->io_serirq);
767 gpio_free(platform_data->io_lpcpd);
768 _tpm_clean_response2:
769 kzfree(platform_data->tpm_i2c_buffer[1]);
770 platform_data->tpm_i2c_buffer[1] = NULL;
771 _tpm_clean_response1:
772 kzfree(platform_data->tpm_i2c_buffer[0]);
773 platform_data->tpm_i2c_buffer[0] = NULL;
775 tpm_remove_hardware(chip->dev);
777 pr_info("TPM I2C initialisation fail\n");
782 * tpm_st33_i2c_remove remove the TPM device
783 * @param: client, the i2c_client drescription (TPM I2C description).
784 clear_bit(0, &chip->is_open);
785 * @return: 0 in case of success.
787 static int tpm_st33_i2c_remove(struct i2c_client *client)
789 struct tpm_chip *chip = (struct tpm_chip *)i2c_get_clientdata(client);
790 struct st33zp24_platform_data *pin_infos =
791 ((struct i2c_client *) TPM_VPRIV(chip))->dev.platform_data;
793 if (pin_infos != NULL) {
794 free_irq(pin_infos->io_serirq, chip);
796 gpio_free(pin_infos->io_serirq);
797 gpio_free(pin_infos->io_lpcpd);
799 tpm_remove_hardware(chip->dev);
801 if (pin_infos->tpm_i2c_buffer[1] != NULL) {
802 kzfree(pin_infos->tpm_i2c_buffer[1]);
803 pin_infos->tpm_i2c_buffer[1] = NULL;
805 if (pin_infos->tpm_i2c_buffer[0] != NULL) {
806 kzfree(pin_infos->tpm_i2c_buffer[0]);
807 pin_infos->tpm_i2c_buffer[0] = NULL;
814 #ifdef CONFIG_PM_SLEEP
816 * tpm_st33_i2c_pm_suspend suspend the TPM device
817 * Added: Work around when suspend and no tpm application is running, suspend
818 * may fail because chip->data_buffer is not set (only set in tpm_open in Linux
820 * @param: client, the i2c_client drescription (TPM I2C description).
821 * @param: mesg, the power management message.
822 * @return: 0 in case of success.
824 static int tpm_st33_i2c_pm_suspend(struct device *dev)
826 struct tpm_chip *chip = dev_get_drvdata(dev);
827 struct st33zp24_platform_data *pin_infos = dev->platform_data;
831 gpio_set_value(pin_infos->io_lpcpd, 0);
833 if (chip->data_buffer == NULL)
834 chip->data_buffer = pin_infos->tpm_i2c_buffer[0];
835 ret = tpm_pm_suspend(dev);
838 } /* tpm_st33_i2c_suspend() */
841 * tpm_st33_i2c_pm_resume resume the TPM device
842 * @param: client, the i2c_client drescription (TPM I2C description).
843 * @return: 0 in case of success.
845 static int tpm_st33_i2c_pm_resume(struct device *dev)
847 struct tpm_chip *chip = dev_get_drvdata(dev);
848 struct st33zp24_platform_data *pin_infos = dev->platform_data;
853 gpio_set_value(pin_infos->io_lpcpd, 1);
854 ret = wait_for_serirq_timeout(chip,
855 (chip->vendor.status(chip) &
856 TPM_STS_VALID) == TPM_STS_VALID,
857 chip->vendor.timeout_b);
859 if (chip->data_buffer == NULL)
860 chip->data_buffer = pin_infos->tpm_i2c_buffer[0];
861 ret = tpm_pm_resume(dev);
863 tpm_do_selftest(chip);
866 } /* tpm_st33_i2c_pm_resume() */
869 static const struct i2c_device_id tpm_st33_i2c_id[] = {
873 MODULE_DEVICE_TABLE(i2c, tpm_st33_i2c_id);
874 static SIMPLE_DEV_PM_OPS(tpm_st33_i2c_ops, tpm_st33_i2c_pm_suspend, tpm_st33_i2c_pm_resume);
875 static struct i2c_driver tpm_st33_i2c_driver = {
877 .owner = THIS_MODULE,
878 .name = TPM_ST33_I2C,
879 .pm = &tpm_st33_i2c_ops,
881 .probe = tpm_st33_i2c_probe,
882 .remove = tpm_st33_i2c_remove,
883 .id_table = tpm_st33_i2c_id
886 module_i2c_driver(tpm_st33_i2c_driver);
888 MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)");
889 MODULE_DESCRIPTION("STM TPM I2C ST33 Driver");
890 MODULE_VERSION("1.2.0");
891 MODULE_LICENSE("GPL");