2 * Copyright (C) 2005, 2006 IBM Corporation
3 * Copyright (C) 2014, 2015 Intel Corporation
6 * Leendert van Doorn <leendert@watson.ibm.com>
7 * Kylene Hall <kjhall@us.ibm.com>
9 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
11 * Device driver for TCG/TCPA TPM (trusted platform module).
12 * Specifications at www.trustedcomputinggroup.org
14 * This device driver implements the TPM interface as defined in
15 * the TCG TPM Interface Spec version 1.2, revision 1.0.
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation, version 2 of the
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/pnp.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
28 #include <linux/wait.h>
29 #include <linux/acpi.h>
30 #include <linux/freezer.h>
32 #include "tpm_tis_core.h"
34 /* Before we attempt to access the TPM we must see that the valid bit is set.
35 * The specification says that this bit is 0 at reset and remains 0 until the
36 * 'TPM has gone through its self test and initialization and has established
37 * correct values in the other bits.'
39 static int wait_startup(struct tpm_chip
*chip
, int l
)
41 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
42 unsigned long stop
= jiffies
+ chip
->timeout_a
;
48 rc
= tpm_tis_read8(priv
, TPM_ACCESS(l
), &access
);
52 if (access
& TPM_ACCESS_VALID
)
55 } while (time_before(jiffies
, stop
));
59 static int check_locality(struct tpm_chip
*chip
, int l
)
61 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
65 rc
= tpm_tis_read8(priv
, TPM_ACCESS(l
), &access
);
69 if ((access
& (TPM_ACCESS_ACTIVE_LOCALITY
| TPM_ACCESS_VALID
)) ==
70 (TPM_ACCESS_ACTIVE_LOCALITY
| TPM_ACCESS_VALID
))
71 return priv
->locality
= l
;
76 static void release_locality(struct tpm_chip
*chip
, int l
, int force
)
78 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
82 rc
= tpm_tis_read8(priv
, TPM_ACCESS(l
), &access
);
86 if (force
|| (access
&
87 (TPM_ACCESS_REQUEST_PENDING
| TPM_ACCESS_VALID
)) ==
88 (TPM_ACCESS_REQUEST_PENDING
| TPM_ACCESS_VALID
))
89 tpm_tis_write8(priv
, TPM_ACCESS(l
), TPM_ACCESS_ACTIVE_LOCALITY
);
93 static int request_locality(struct tpm_chip
*chip
, int l
)
95 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
96 unsigned long stop
, timeout
;
99 if (check_locality(chip
, l
) >= 0)
102 rc
= tpm_tis_write8(priv
, TPM_ACCESS(l
), TPM_ACCESS_REQUEST_USE
);
106 stop
= jiffies
+ chip
->timeout_a
;
108 if (chip
->flags
& TPM_CHIP_FLAG_IRQ
) {
110 timeout
= stop
- jiffies
;
111 if ((long)timeout
<= 0)
113 rc
= wait_event_interruptible_timeout(priv
->int_queue
,
119 if (rc
== -ERESTARTSYS
&& freezing(current
)) {
120 clear_thread_flag(TIF_SIGPENDING
);
124 /* wait for burstcount */
126 if (check_locality(chip
, l
) >= 0)
129 } while (time_before(jiffies
, stop
));
134 static u8
tpm_tis_status(struct tpm_chip
*chip
)
136 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
140 rc
= tpm_tis_read8(priv
, TPM_STS(priv
->locality
), &status
);
147 static void tpm_tis_ready(struct tpm_chip
*chip
)
149 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
151 /* this causes the current command to be aborted */
152 tpm_tis_write8(priv
, TPM_STS(priv
->locality
), TPM_STS_COMMAND_READY
);
155 static int get_burstcount(struct tpm_chip
*chip
)
157 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
162 /* wait for burstcount */
163 /* which timeout value, spec has 2 answers (c & d) */
164 stop
= jiffies
+ chip
->timeout_d
;
166 rc
= tpm_tis_read32(priv
, TPM_STS(priv
->locality
), &value
);
170 burstcnt
= (value
>> 8) & 0xFFFF;
174 } while (time_before(jiffies
, stop
));
178 static int recv_data(struct tpm_chip
*chip
, u8
*buf
, size_t count
)
180 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
181 int size
= 0, burstcnt
, rc
;
183 while (size
< count
) {
184 rc
= wait_for_tpm_stat(chip
,
185 TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
187 &priv
->read_queue
, true);
190 burstcnt
= get_burstcount(chip
);
192 dev_err(&chip
->dev
, "Unable to read burstcount\n");
195 burstcnt
= min_t(int, burstcnt
, count
- size
);
197 rc
= tpm_tis_read_bytes(priv
, TPM_DATA_FIFO(priv
->locality
),
198 burstcnt
, buf
+ size
);
207 static int tpm_tis_recv(struct tpm_chip
*chip
, u8
*buf
, size_t count
)
209 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
211 int expected
, status
;
213 if (count
< TPM_HEADER_SIZE
) {
218 size
= recv_data(chip
, buf
, TPM_HEADER_SIZE
);
219 /* read first 10 bytes, including tag, paramsize, and result */
220 if (size
< TPM_HEADER_SIZE
) {
221 dev_err(&chip
->dev
, "Unable to read header\n");
225 expected
= be32_to_cpu(*(__be32
*) (buf
+ 2));
226 if (expected
> count
) {
231 size
+= recv_data(chip
, &buf
[TPM_HEADER_SIZE
],
232 expected
- TPM_HEADER_SIZE
);
233 if (size
< expected
) {
234 dev_err(&chip
->dev
, "Unable to read remainder of result\n");
239 if (wait_for_tpm_stat(chip
, TPM_STS_VALID
, chip
->timeout_c
,
240 &priv
->int_queue
, false) < 0) {
244 status
= tpm_tis_status(chip
);
245 if (status
& TPM_STS_DATA_AVAIL
) { /* retry? */
246 dev_err(&chip
->dev
, "Error left over data\n");
253 release_locality(chip
, priv
->locality
, 0);
258 * If interrupts are used (signaled by an irq set in the vendor structure)
259 * tpm.c can skip polling for the data to be available as the interrupt is
262 static int tpm_tis_send_data(struct tpm_chip
*chip
, u8
*buf
, size_t len
)
264 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
265 int rc
, status
, burstcnt
;
267 bool itpm
= priv
->flags
& TPM_TIS_ITPM_WORKAROUND
;
269 if (request_locality(chip
, 0) < 0)
272 status
= tpm_tis_status(chip
);
273 if ((status
& TPM_STS_COMMAND_READY
) == 0) {
275 if (wait_for_tpm_stat
276 (chip
, TPM_STS_COMMAND_READY
, chip
->timeout_b
,
277 &priv
->int_queue
, false) < 0) {
283 while (count
< len
- 1) {
284 burstcnt
= get_burstcount(chip
);
286 dev_err(&chip
->dev
, "Unable to read burstcount\n");
290 burstcnt
= min_t(int, burstcnt
, len
- count
- 1);
291 rc
= tpm_tis_write_bytes(priv
, TPM_DATA_FIFO(priv
->locality
),
292 burstcnt
, buf
+ count
);
298 if (wait_for_tpm_stat(chip
, TPM_STS_VALID
, chip
->timeout_c
,
299 &priv
->int_queue
, false) < 0) {
303 status
= tpm_tis_status(chip
);
304 if (!itpm
&& (status
& TPM_STS_DATA_EXPECT
) == 0) {
310 /* write last byte */
311 rc
= tpm_tis_write8(priv
, TPM_DATA_FIFO(priv
->locality
), buf
[count
]);
315 if (wait_for_tpm_stat(chip
, TPM_STS_VALID
, chip
->timeout_c
,
316 &priv
->int_queue
, false) < 0) {
320 status
= tpm_tis_status(chip
);
321 if (!itpm
&& (status
& TPM_STS_DATA_EXPECT
) != 0) {
330 release_locality(chip
, priv
->locality
, 0);
334 static void disable_interrupts(struct tpm_chip
*chip
)
336 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
340 rc
= tpm_tis_read32(priv
, TPM_INT_ENABLE(priv
->locality
), &intmask
);
344 intmask
&= ~TPM_GLOBAL_INT_ENABLE
;
345 rc
= tpm_tis_write32(priv
, TPM_INT_ENABLE(priv
->locality
), intmask
);
347 devm_free_irq(chip
->dev
.parent
, priv
->irq
, chip
);
349 chip
->flags
&= ~TPM_CHIP_FLAG_IRQ
;
353 * If interrupts are used (signaled by an irq set in the vendor structure)
354 * tpm.c can skip polling for the data to be available as the interrupt is
357 static int tpm_tis_send_main(struct tpm_chip
*chip
, u8
*buf
, size_t len
)
359 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
364 rc
= tpm_tis_send_data(chip
, buf
, len
);
369 rc
= tpm_tis_write8(priv
, TPM_STS(priv
->locality
), TPM_STS_GO
);
373 if (chip
->flags
& TPM_CHIP_FLAG_IRQ
) {
374 ordinal
= be32_to_cpu(*((__be32
*) (buf
+ 6)));
376 if (chip
->flags
& TPM_CHIP_FLAG_TPM2
)
377 dur
= tpm2_calc_ordinal_duration(chip
, ordinal
);
379 dur
= tpm_calc_ordinal_duration(chip
, ordinal
);
381 if (wait_for_tpm_stat
382 (chip
, TPM_STS_DATA_AVAIL
| TPM_STS_VALID
, dur
,
383 &priv
->read_queue
, false) < 0) {
391 release_locality(chip
, priv
->locality
, 0);
395 static int tpm_tis_send(struct tpm_chip
*chip
, u8
*buf
, size_t len
)
398 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
400 if (!(chip
->flags
& TPM_CHIP_FLAG_IRQ
) || priv
->irq_tested
)
401 return tpm_tis_send_main(chip
, buf
, len
);
403 /* Verify receipt of the expected IRQ */
406 chip
->flags
&= ~TPM_CHIP_FLAG_IRQ
;
407 rc
= tpm_tis_send_main(chip
, buf
, len
);
409 chip
->flags
|= TPM_CHIP_FLAG_IRQ
;
410 if (!priv
->irq_tested
)
412 if (!priv
->irq_tested
)
413 disable_interrupts(chip
);
414 priv
->irq_tested
= true;
418 struct tis_vendor_timeout_override
{
420 unsigned long timeout_us
[4];
423 static const struct tis_vendor_timeout_override vendor_timeout_overrides
[] = {
425 { 0x32041114, { (TIS_SHORT_TIMEOUT
*1000), (TIS_LONG_TIMEOUT
*1000),
426 (TIS_SHORT_TIMEOUT
*1000), (TIS_SHORT_TIMEOUT
*1000) } },
429 static bool tpm_tis_update_timeouts(struct tpm_chip
*chip
,
430 unsigned long *timeout_cap
)
432 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
436 rc
= tpm_tis_read32(priv
, TPM_DID_VID(0), &did_vid
);
440 for (i
= 0; i
!= ARRAY_SIZE(vendor_timeout_overrides
); i
++) {
441 if (vendor_timeout_overrides
[i
].did_vid
!= did_vid
)
443 memcpy(timeout_cap
, vendor_timeout_overrides
[i
].timeout_us
,
444 sizeof(vendor_timeout_overrides
[i
].timeout_us
));
452 * Early probing for iTPM with STS_DATA_EXPECT flaw.
453 * Try sending command without itpm flag set and if that
454 * fails, repeat with itpm flag set.
456 static int probe_itpm(struct tpm_chip
*chip
)
458 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
460 u8 cmd_getticks
[] = {
461 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
462 0x00, 0x00, 0x00, 0xf1
464 size_t len
= sizeof(cmd_getticks
);
467 if (priv
->flags
& TPM_TIS_ITPM_WORKAROUND
)
470 rc
= tpm_tis_read16(priv
, TPM_DID_VID(0), &vendor
);
474 /* probe only iTPMS */
475 if (vendor
!= TPM_VID_INTEL
)
478 rc
= tpm_tis_send_data(chip
, cmd_getticks
, len
);
483 release_locality(chip
, priv
->locality
, 0);
485 priv
->flags
|= TPM_TIS_ITPM_WORKAROUND
;
487 rc
= tpm_tis_send_data(chip
, cmd_getticks
, len
);
489 dev_info(&chip
->dev
, "Detected an iTPM.\n");
491 priv
->flags
&= ~TPM_TIS_ITPM_WORKAROUND
;
497 release_locality(chip
, priv
->locality
, 0);
502 static bool tpm_tis_req_canceled(struct tpm_chip
*chip
, u8 status
)
504 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
506 switch (priv
->manufacturer_id
) {
507 case TPM_VID_WINBOND
:
508 return ((status
== TPM_STS_VALID
) ||
509 (status
== (TPM_STS_VALID
| TPM_STS_COMMAND_READY
)));
511 return (status
== (TPM_STS_VALID
| TPM_STS_COMMAND_READY
));
513 return (status
== TPM_STS_COMMAND_READY
);
517 static irqreturn_t
tis_int_handler(int dummy
, void *dev_id
)
519 struct tpm_chip
*chip
= dev_id
;
520 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
524 rc
= tpm_tis_read32(priv
, TPM_INT_STATUS(priv
->locality
), &interrupt
);
531 priv
->irq_tested
= true;
532 if (interrupt
& TPM_INTF_DATA_AVAIL_INT
)
533 wake_up_interruptible(&priv
->read_queue
);
534 if (interrupt
& TPM_INTF_LOCALITY_CHANGE_INT
)
535 for (i
= 0; i
< 5; i
++)
536 if (check_locality(chip
, i
) >= 0)
539 (TPM_INTF_LOCALITY_CHANGE_INT
| TPM_INTF_STS_VALID_INT
|
540 TPM_INTF_CMD_READY_INT
))
541 wake_up_interruptible(&priv
->int_queue
);
543 /* Clear interrupts handled with TPM_EOI */
544 rc
= tpm_tis_write32(priv
, TPM_INT_STATUS(priv
->locality
), interrupt
);
548 tpm_tis_read32(priv
, TPM_INT_STATUS(priv
->locality
), &interrupt
);
552 static int tpm_tis_gen_interrupt(struct tpm_chip
*chip
)
554 const char *desc
= "attempting to generate an interrupt";
558 if (chip
->flags
& TPM_CHIP_FLAG_TPM2
)
559 return tpm2_get_tpm_pt(chip
, 0x100, &cap2
, desc
);
561 return tpm_getcap(chip
, TPM_CAP_PROP_TIS_TIMEOUT
, &cap
, desc
,
565 /* Register the IRQ and issue a command that will cause an interrupt. If an
566 * irq is seen then leave the chip setup for IRQ operation, otherwise reverse
567 * everything and leave in polling mode. Returns 0 on success.
569 static int tpm_tis_probe_irq_single(struct tpm_chip
*chip
, u32 intmask
,
572 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
577 if (devm_request_irq(chip
->dev
.parent
, irq
, tis_int_handler
, flags
,
578 dev_name(&chip
->dev
), chip
) != 0) {
579 dev_info(&chip
->dev
, "Unable to request irq: %d for probe\n",
585 rc
= tpm_tis_read8(priv
, TPM_INT_VECTOR(priv
->locality
),
590 rc
= tpm_tis_write8(priv
, TPM_INT_VECTOR(priv
->locality
), irq
);
594 rc
= tpm_tis_read32(priv
, TPM_INT_STATUS(priv
->locality
), &int_status
);
598 /* Clear all existing */
599 rc
= tpm_tis_write32(priv
, TPM_INT_STATUS(priv
->locality
), int_status
);
604 rc
= tpm_tis_write32(priv
, TPM_INT_ENABLE(priv
->locality
),
605 intmask
| TPM_GLOBAL_INT_ENABLE
);
609 priv
->irq_tested
= false;
611 /* Generate an interrupt by having the core call through to
614 rc
= tpm_tis_gen_interrupt(chip
);
618 /* tpm_tis_send will either confirm the interrupt is working or it
619 * will call disable_irq which undoes all of the above.
621 if (!(chip
->flags
& TPM_CHIP_FLAG_IRQ
)) {
622 rc
= tpm_tis_write8(priv
, original_int_vec
,
623 TPM_INT_VECTOR(priv
->locality
));
633 /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that
634 * do not have ACPI/etc. We typically expect the interrupt to be declared if
637 static void tpm_tis_probe_irq(struct tpm_chip
*chip
, u32 intmask
)
639 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
643 rc
= tpm_tis_read8(priv
, TPM_INT_VECTOR(priv
->locality
),
648 if (!original_int_vec
) {
649 if (IS_ENABLED(CONFIG_X86
))
650 for (i
= 3; i
<= 15; i
++)
651 if (!tpm_tis_probe_irq_single(chip
, intmask
, 0,
654 } else if (!tpm_tis_probe_irq_single(chip
, intmask
, 0,
659 void tpm_tis_remove(struct tpm_chip
*chip
)
661 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
662 u32 reg
= TPM_INT_ENABLE(priv
->locality
);
666 rc
= tpm_tis_read32(priv
, reg
, &interrupt
);
670 tpm_tis_write32(priv
, reg
, ~TPM_GLOBAL_INT_ENABLE
& interrupt
);
671 release_locality(chip
, priv
->locality
, 1);
673 EXPORT_SYMBOL_GPL(tpm_tis_remove
);
675 static const struct tpm_class_ops tpm_tis
= {
676 .flags
= TPM_OPS_AUTO_STARTUP
,
677 .status
= tpm_tis_status
,
678 .recv
= tpm_tis_recv
,
679 .send
= tpm_tis_send
,
680 .cancel
= tpm_tis_ready
,
681 .update_timeouts
= tpm_tis_update_timeouts
,
682 .req_complete_mask
= TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
683 .req_complete_val
= TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
684 .req_canceled
= tpm_tis_req_canceled
,
687 int tpm_tis_core_init(struct device
*dev
, struct tpm_tis_data
*priv
, int irq
,
688 const struct tpm_tis_phy_ops
*phy_ops
,
689 acpi_handle acpi_dev_handle
)
691 u32 vendor
, intfcaps
, intmask
;
694 struct tpm_chip
*chip
;
696 chip
= tpmm_chip_alloc(dev
, &tpm_tis
);
698 return PTR_ERR(chip
);
701 chip
->acpi_dev_handle
= acpi_dev_handle
;
704 /* Maximum timeouts */
705 chip
->timeout_a
= msecs_to_jiffies(TIS_TIMEOUT_A_MAX
);
706 chip
->timeout_b
= msecs_to_jiffies(TIS_TIMEOUT_B_MAX
);
707 chip
->timeout_c
= msecs_to_jiffies(TIS_TIMEOUT_C_MAX
);
708 chip
->timeout_d
= msecs_to_jiffies(TIS_TIMEOUT_D_MAX
);
709 priv
->phy_ops
= phy_ops
;
710 dev_set_drvdata(&chip
->dev
, priv
);
712 if (wait_startup(chip
, 0) != 0) {
717 /* Take control of the TPM's interrupt hardware and shut it off */
718 rc
= tpm_tis_read32(priv
, TPM_INT_ENABLE(priv
->locality
), &intmask
);
722 intmask
|= TPM_INTF_CMD_READY_INT
| TPM_INTF_LOCALITY_CHANGE_INT
|
723 TPM_INTF_DATA_AVAIL_INT
| TPM_INTF_STS_VALID_INT
;
724 intmask
&= ~TPM_GLOBAL_INT_ENABLE
;
725 tpm_tis_write32(priv
, TPM_INT_ENABLE(priv
->locality
), intmask
);
727 if (request_locality(chip
, 0) != 0) {
732 rc
= tpm2_probe(chip
);
736 rc
= tpm_tis_read32(priv
, TPM_DID_VID(0), &vendor
);
740 priv
->manufacturer_id
= vendor
;
742 rc
= tpm_tis_read8(priv
, TPM_RID(0), &rid
);
746 dev_info(dev
, "%s TPM (device-id 0x%X, rev-id %d)\n",
747 (chip
->flags
& TPM_CHIP_FLAG_TPM2
) ? "2.0" : "1.2",
750 probe
= probe_itpm(chip
);
756 /* Figure out the capabilities */
757 rc
= tpm_tis_read32(priv
, TPM_INTF_CAPS(priv
->locality
), &intfcaps
);
761 dev_dbg(dev
, "TPM interface capabilities (0x%x):\n",
763 if (intfcaps
& TPM_INTF_BURST_COUNT_STATIC
)
764 dev_dbg(dev
, "\tBurst Count Static\n");
765 if (intfcaps
& TPM_INTF_CMD_READY_INT
)
766 dev_dbg(dev
, "\tCommand Ready Int Support\n");
767 if (intfcaps
& TPM_INTF_INT_EDGE_FALLING
)
768 dev_dbg(dev
, "\tInterrupt Edge Falling\n");
769 if (intfcaps
& TPM_INTF_INT_EDGE_RISING
)
770 dev_dbg(dev
, "\tInterrupt Edge Rising\n");
771 if (intfcaps
& TPM_INTF_INT_LEVEL_LOW
)
772 dev_dbg(dev
, "\tInterrupt Level Low\n");
773 if (intfcaps
& TPM_INTF_INT_LEVEL_HIGH
)
774 dev_dbg(dev
, "\tInterrupt Level High\n");
775 if (intfcaps
& TPM_INTF_LOCALITY_CHANGE_INT
)
776 dev_dbg(dev
, "\tLocality Change Int Support\n");
777 if (intfcaps
& TPM_INTF_STS_VALID_INT
)
778 dev_dbg(dev
, "\tSts Valid Int Support\n");
779 if (intfcaps
& TPM_INTF_DATA_AVAIL_INT
)
780 dev_dbg(dev
, "\tData Avail Int Support\n");
782 /* INTERRUPT Setup */
783 init_waitqueue_head(&priv
->read_queue
);
784 init_waitqueue_head(&priv
->int_queue
);
786 /* Before doing irq testing issue a command to the TPM in polling mode
787 * to make sure it works. May as well use that command to set the
788 * proper timeouts for the driver.
790 if (tpm_get_timeouts(chip
)) {
791 dev_err(dev
, "Could not get TPM timeouts and durations\n");
797 tpm_tis_probe_irq_single(chip
, intmask
, IRQF_SHARED
,
799 if (!(chip
->flags
& TPM_CHIP_FLAG_IRQ
))
800 dev_err(&chip
->dev
, FW_BUG
801 "TPM interrupt not working, polling instead\n");
803 tpm_tis_probe_irq(chip
, intmask
);
807 return tpm_chip_register(chip
);
809 tpm_tis_remove(chip
);
812 EXPORT_SYMBOL_GPL(tpm_tis_core_init
);
814 #ifdef CONFIG_PM_SLEEP
815 static void tpm_tis_reenable_interrupts(struct tpm_chip
*chip
)
817 struct tpm_tis_data
*priv
= dev_get_drvdata(&chip
->dev
);
821 /* reenable interrupts that device may have lost or
822 * BIOS/firmware may have disabled
824 rc
= tpm_tis_write8(priv
, TPM_INT_VECTOR(priv
->locality
), priv
->irq
);
828 rc
= tpm_tis_read32(priv
, TPM_INT_ENABLE(priv
->locality
), &intmask
);
832 intmask
|= TPM_INTF_CMD_READY_INT
833 | TPM_INTF_LOCALITY_CHANGE_INT
| TPM_INTF_DATA_AVAIL_INT
834 | TPM_INTF_STS_VALID_INT
| TPM_GLOBAL_INT_ENABLE
;
836 tpm_tis_write32(priv
, TPM_INT_ENABLE(priv
->locality
), intmask
);
839 int tpm_tis_resume(struct device
*dev
)
841 struct tpm_chip
*chip
= dev_get_drvdata(dev
);
844 if (chip
->flags
& TPM_CHIP_FLAG_IRQ
)
845 tpm_tis_reenable_interrupts(chip
);
847 ret
= tpm_pm_resume(dev
);
851 /* TPM 1.2 requires self-test on resume. This function actually returns
852 * an error code but for unknown reason it isn't handled.
854 if (!(chip
->flags
& TPM_CHIP_FLAG_TPM2
))
855 tpm_do_selftest(chip
);
859 EXPORT_SYMBOL_GPL(tpm_tis_resume
);
862 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
863 MODULE_DESCRIPTION("TPM Driver");
864 MODULE_VERSION("2.0");
865 MODULE_LICENSE("GPL");