2 * Copyright (C) 2005, 2006 IBM Corporation
5 * Leendert van Doorn <leendert@watson.ibm.com>
6 * Kylene Hall <kjhall@us.ibm.com>
8 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
10 * Device driver for TCG/TCPA TPM (trusted platform module).
11 * Specifications at www.trustedcomputinggroup.org
13 * This device driver implements the TPM interface as defined in
14 * the TCG TPM Interface Spec version 1.2, revision 1.0.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation, version 2 of the
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/pnp.h>
25 #include <linux/slab.h>
26 #include <linux/interrupt.h>
27 #include <linux/wait.h>
28 #include <linux/acpi.h>
29 #include <linux/freezer.h>
33 TPM_ACCESS_VALID
= 0x80,
34 TPM_ACCESS_ACTIVE_LOCALITY
= 0x20,
35 TPM_ACCESS_REQUEST_PENDING
= 0x04,
36 TPM_ACCESS_REQUEST_USE
= 0x02,
41 TPM_STS_COMMAND_READY
= 0x40,
43 TPM_STS_DATA_AVAIL
= 0x10,
44 TPM_STS_DATA_EXPECT
= 0x08,
48 TPM_GLOBAL_INT_ENABLE
= 0x80000000,
49 TPM_INTF_BURST_COUNT_STATIC
= 0x100,
50 TPM_INTF_CMD_READY_INT
= 0x080,
51 TPM_INTF_INT_EDGE_FALLING
= 0x040,
52 TPM_INTF_INT_EDGE_RISING
= 0x020,
53 TPM_INTF_INT_LEVEL_LOW
= 0x010,
54 TPM_INTF_INT_LEVEL_HIGH
= 0x008,
55 TPM_INTF_LOCALITY_CHANGE_INT
= 0x004,
56 TPM_INTF_STS_VALID_INT
= 0x002,
57 TPM_INTF_DATA_AVAIL_INT
= 0x001,
61 TIS_MEM_BASE
= 0xFED40000,
63 TIS_SHORT_TIMEOUT
= 750, /* ms */
64 TIS_LONG_TIMEOUT
= 2000, /* 2 sec */
67 #define TPM_ACCESS(l) (0x0000 | ((l) << 12))
68 #define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
69 #define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
70 #define TPM_INT_STATUS(l) (0x0010 | ((l) << 12))
71 #define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
72 #define TPM_STS(l) (0x0018 | ((l) << 12))
73 #define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
75 #define TPM_DID_VID(l) (0x0F00 | ((l) << 12))
76 #define TPM_RID(l) (0x0F04 | ((l) << 12))
82 #if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
83 static int is_itpm(struct pnp_dev
*dev
)
85 struct acpi_device
*acpi
= pnp_acpi_device(dev
);
86 struct acpi_hardware_id
*id
;
91 list_for_each_entry(id
, &acpi
->pnp
.ids
, list
) {
92 if (!strcmp("INTC0102", id
->id
))
99 static inline int is_itpm(struct pnp_dev
*dev
)
105 /* Before we attempt to access the TPM we must see that the valid bit is set.
106 * The specification says that this bit is 0 at reset and remains 0 until the
107 * 'TPM has gone through its self test and initialization and has established
108 * correct values in the other bits.' */
109 static int wait_startup(struct tpm_chip
*chip
, int l
)
111 unsigned long stop
= jiffies
+ chip
->vendor
.timeout_a
;
113 if (ioread8(chip
->vendor
.iobase
+ TPM_ACCESS(l
)) &
117 } while (time_before(jiffies
, stop
));
121 static int check_locality(struct tpm_chip
*chip
, int l
)
123 if ((ioread8(chip
->vendor
.iobase
+ TPM_ACCESS(l
)) &
124 (TPM_ACCESS_ACTIVE_LOCALITY
| TPM_ACCESS_VALID
)) ==
125 (TPM_ACCESS_ACTIVE_LOCALITY
| TPM_ACCESS_VALID
))
126 return chip
->vendor
.locality
= l
;
131 static void release_locality(struct tpm_chip
*chip
, int l
, int force
)
133 if (force
|| (ioread8(chip
->vendor
.iobase
+ TPM_ACCESS(l
)) &
134 (TPM_ACCESS_REQUEST_PENDING
| TPM_ACCESS_VALID
)) ==
135 (TPM_ACCESS_REQUEST_PENDING
| TPM_ACCESS_VALID
))
136 iowrite8(TPM_ACCESS_ACTIVE_LOCALITY
,
137 chip
->vendor
.iobase
+ TPM_ACCESS(l
));
140 static int request_locality(struct tpm_chip
*chip
, int l
)
142 unsigned long stop
, timeout
;
145 if (check_locality(chip
, l
) >= 0)
148 iowrite8(TPM_ACCESS_REQUEST_USE
,
149 chip
->vendor
.iobase
+ TPM_ACCESS(l
));
151 stop
= jiffies
+ chip
->vendor
.timeout_a
;
153 if (chip
->vendor
.irq
) {
155 timeout
= stop
- jiffies
;
156 if ((long)timeout
<= 0)
158 rc
= wait_event_interruptible_timeout(chip
->vendor
.int_queue
,
164 if (rc
== -ERESTARTSYS
&& freezing(current
)) {
165 clear_thread_flag(TIF_SIGPENDING
);
169 /* wait for burstcount */
171 if (check_locality(chip
, l
) >= 0)
175 while (time_before(jiffies
, stop
));
180 static u8
tpm_tis_status(struct tpm_chip
*chip
)
182 return ioread8(chip
->vendor
.iobase
+
183 TPM_STS(chip
->vendor
.locality
));
186 static void tpm_tis_ready(struct tpm_chip
*chip
)
188 /* this causes the current command to be aborted */
189 iowrite8(TPM_STS_COMMAND_READY
,
190 chip
->vendor
.iobase
+ TPM_STS(chip
->vendor
.locality
));
193 static int get_burstcount(struct tpm_chip
*chip
)
198 /* wait for burstcount */
199 /* which timeout value, spec has 2 answers (c & d) */
200 stop
= jiffies
+ chip
->vendor
.timeout_d
;
202 burstcnt
= ioread8(chip
->vendor
.iobase
+
203 TPM_STS(chip
->vendor
.locality
) + 1);
204 burstcnt
+= ioread8(chip
->vendor
.iobase
+
205 TPM_STS(chip
->vendor
.locality
) +
210 } while (time_before(jiffies
, stop
));
214 static int recv_data(struct tpm_chip
*chip
, u8
*buf
, size_t count
)
216 int size
= 0, burstcnt
;
217 while (size
< count
&&
218 wait_for_tpm_stat(chip
,
219 TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
220 chip
->vendor
.timeout_c
,
221 &chip
->vendor
.read_queue
, true)
223 burstcnt
= get_burstcount(chip
);
224 for (; burstcnt
> 0 && size
< count
; burstcnt
--)
225 buf
[size
++] = ioread8(chip
->vendor
.iobase
+
226 TPM_DATA_FIFO(chip
->vendor
.
232 static int tpm_tis_recv(struct tpm_chip
*chip
, u8
*buf
, size_t count
)
235 int expected
, status
;
237 if (count
< TPM_HEADER_SIZE
) {
242 /* read first 10 bytes, including tag, paramsize, and result */
244 recv_data(chip
, buf
, TPM_HEADER_SIZE
)) < TPM_HEADER_SIZE
) {
245 dev_err(chip
->pdev
, "Unable to read header\n");
249 expected
= be32_to_cpu(*(__be32
*) (buf
+ 2));
250 if (expected
> count
) {
256 recv_data(chip
, &buf
[TPM_HEADER_SIZE
],
257 expected
- TPM_HEADER_SIZE
)) < expected
) {
258 dev_err(chip
->pdev
, "Unable to read remainder of result\n");
263 wait_for_tpm_stat(chip
, TPM_STS_VALID
, chip
->vendor
.timeout_c
,
264 &chip
->vendor
.int_queue
, false);
265 status
= tpm_tis_status(chip
);
266 if (status
& TPM_STS_DATA_AVAIL
) { /* retry? */
267 dev_err(chip
->pdev
, "Error left over data\n");
274 release_locality(chip
, chip
->vendor
.locality
, 0);
279 module_param(itpm
, bool, 0444);
280 MODULE_PARM_DESC(itpm
, "Force iTPM workarounds (found on some Lenovo laptops)");
283 * If interrupts are used (signaled by an irq set in the vendor structure)
284 * tpm.c can skip polling for the data to be available as the interrupt is
287 static int tpm_tis_send_data(struct tpm_chip
*chip
, u8
*buf
, size_t len
)
289 int rc
, status
, burstcnt
;
292 if (request_locality(chip
, 0) < 0)
295 status
= tpm_tis_status(chip
);
296 if ((status
& TPM_STS_COMMAND_READY
) == 0) {
298 if (wait_for_tpm_stat
299 (chip
, TPM_STS_COMMAND_READY
, chip
->vendor
.timeout_b
,
300 &chip
->vendor
.int_queue
, false) < 0) {
306 while (count
< len
- 1) {
307 burstcnt
= get_burstcount(chip
);
308 for (; burstcnt
> 0 && count
< len
- 1; burstcnt
--) {
309 iowrite8(buf
[count
], chip
->vendor
.iobase
+
310 TPM_DATA_FIFO(chip
->vendor
.locality
));
314 wait_for_tpm_stat(chip
, TPM_STS_VALID
, chip
->vendor
.timeout_c
,
315 &chip
->vendor
.int_queue
, false);
316 status
= tpm_tis_status(chip
);
317 if (!itpm
&& (status
& TPM_STS_DATA_EXPECT
) == 0) {
323 /* write last byte */
325 chip
->vendor
.iobase
+ TPM_DATA_FIFO(chip
->vendor
.locality
));
326 wait_for_tpm_stat(chip
, TPM_STS_VALID
, chip
->vendor
.timeout_c
,
327 &chip
->vendor
.int_queue
, false);
328 status
= tpm_tis_status(chip
);
329 if ((status
& TPM_STS_DATA_EXPECT
) != 0) {
338 release_locality(chip
, chip
->vendor
.locality
, 0);
342 static void disable_interrupts(struct tpm_chip
*chip
)
347 ioread32(chip
->vendor
.iobase
+
348 TPM_INT_ENABLE(chip
->vendor
.locality
));
349 intmask
&= ~TPM_GLOBAL_INT_ENABLE
;
351 chip
->vendor
.iobase
+
352 TPM_INT_ENABLE(chip
->vendor
.locality
));
353 free_irq(chip
->vendor
.irq
, chip
);
354 chip
->vendor
.irq
= 0;
358 * If interrupts are used (signaled by an irq set in the vendor structure)
359 * tpm.c can skip polling for the data to be available as the interrupt is
362 static int tpm_tis_send_main(struct tpm_chip
*chip
, u8
*buf
, size_t len
)
367 rc
= tpm_tis_send_data(chip
, buf
, len
);
373 chip
->vendor
.iobase
+ TPM_STS(chip
->vendor
.locality
));
375 if (chip
->vendor
.irq
) {
376 ordinal
= be32_to_cpu(*((__be32
*) (buf
+ 6)));
377 if (wait_for_tpm_stat
378 (chip
, TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
379 tpm_calc_ordinal_duration(chip
, ordinal
),
380 &chip
->vendor
.read_queue
, false) < 0) {
388 release_locality(chip
, chip
->vendor
.locality
, 0);
392 static int tpm_tis_send(struct tpm_chip
*chip
, u8
*buf
, size_t len
)
395 struct priv_data
*priv
= chip
->vendor
.priv
;
397 if (!chip
->vendor
.irq
|| priv
->irq_tested
)
398 return tpm_tis_send_main(chip
, buf
, len
);
400 /* Verify receipt of the expected IRQ */
401 irq
= chip
->vendor
.irq
;
402 chip
->vendor
.irq
= 0;
403 rc
= tpm_tis_send_main(chip
, buf
, len
);
404 chip
->vendor
.irq
= irq
;
405 if (!priv
->irq_tested
)
407 if (!priv
->irq_tested
) {
408 disable_interrupts(chip
);
410 FW_BUG
"TPM interrupt not working, polling instead\n");
412 priv
->irq_tested
= true;
416 struct tis_vendor_timeout_override
{
418 unsigned long timeout_us
[4];
421 static const struct tis_vendor_timeout_override vendor_timeout_overrides
[] = {
423 { 0x32041114, { (TIS_SHORT_TIMEOUT
*1000), (TIS_LONG_TIMEOUT
*1000),
424 (TIS_SHORT_TIMEOUT
*1000), (TIS_SHORT_TIMEOUT
*1000) } },
427 static bool tpm_tis_update_timeouts(struct tpm_chip
*chip
,
428 unsigned long *timeout_cap
)
433 did_vid
= ioread32(chip
->vendor
.iobase
+ TPM_DID_VID(0));
435 for (i
= 0; i
!= ARRAY_SIZE(vendor_timeout_overrides
); i
++) {
436 if (vendor_timeout_overrides
[i
].did_vid
!= did_vid
)
438 memcpy(timeout_cap
, vendor_timeout_overrides
[i
].timeout_us
,
439 sizeof(vendor_timeout_overrides
[i
].timeout_us
));
447 * Early probing for iTPM with STS_DATA_EXPECT flaw.
448 * Try sending command without itpm flag set and if that
449 * fails, repeat with itpm flag set.
451 static int probe_itpm(struct tpm_chip
*chip
)
454 u8 cmd_getticks
[] = {
455 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
456 0x00, 0x00, 0x00, 0xf1
458 size_t len
= sizeof(cmd_getticks
);
459 bool rem_itpm
= itpm
;
460 u16 vendor
= ioread16(chip
->vendor
.iobase
+ TPM_DID_VID(0));
462 /* probe only iTPMS */
463 if (vendor
!= TPM_VID_INTEL
)
468 rc
= tpm_tis_send_data(chip
, cmd_getticks
, len
);
473 release_locality(chip
, chip
->vendor
.locality
, 0);
477 rc
= tpm_tis_send_data(chip
, cmd_getticks
, len
);
479 dev_info(chip
->pdev
, "Detected an iTPM.\n");
487 release_locality(chip
, chip
->vendor
.locality
, 0);
492 static bool tpm_tis_req_canceled(struct tpm_chip
*chip
, u8 status
)
494 switch (chip
->vendor
.manufacturer_id
) {
495 case TPM_VID_WINBOND
:
496 return ((status
== TPM_STS_VALID
) ||
497 (status
== (TPM_STS_VALID
| TPM_STS_COMMAND_READY
)));
499 return (status
== (TPM_STS_VALID
| TPM_STS_COMMAND_READY
));
501 return (status
== TPM_STS_COMMAND_READY
);
505 static const struct tpm_class_ops tpm_tis
= {
506 .status
= tpm_tis_status
,
507 .recv
= tpm_tis_recv
,
508 .send
= tpm_tis_send
,
509 .cancel
= tpm_tis_ready
,
510 .update_timeouts
= tpm_tis_update_timeouts
,
511 .req_complete_mask
= TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
512 .req_complete_val
= TPM_STS_DATA_AVAIL
| TPM_STS_VALID
,
513 .req_canceled
= tpm_tis_req_canceled
,
516 static irqreturn_t
tis_int_probe(int irq
, void *dev_id
)
518 struct tpm_chip
*chip
= dev_id
;
521 interrupt
= ioread32(chip
->vendor
.iobase
+
522 TPM_INT_STATUS(chip
->vendor
.locality
));
527 chip
->vendor
.probed_irq
= irq
;
529 /* Clear interrupts handled with TPM_EOI */
531 chip
->vendor
.iobase
+
532 TPM_INT_STATUS(chip
->vendor
.locality
));
536 static irqreturn_t
tis_int_handler(int dummy
, void *dev_id
)
538 struct tpm_chip
*chip
= dev_id
;
542 interrupt
= ioread32(chip
->vendor
.iobase
+
543 TPM_INT_STATUS(chip
->vendor
.locality
));
548 ((struct priv_data
*)chip
->vendor
.priv
)->irq_tested
= true;
549 if (interrupt
& TPM_INTF_DATA_AVAIL_INT
)
550 wake_up_interruptible(&chip
->vendor
.read_queue
);
551 if (interrupt
& TPM_INTF_LOCALITY_CHANGE_INT
)
552 for (i
= 0; i
< 5; i
++)
553 if (check_locality(chip
, i
) >= 0)
556 (TPM_INTF_LOCALITY_CHANGE_INT
| TPM_INTF_STS_VALID_INT
|
557 TPM_INTF_CMD_READY_INT
))
558 wake_up_interruptible(&chip
->vendor
.int_queue
);
560 /* Clear interrupts handled with TPM_EOI */
562 chip
->vendor
.iobase
+
563 TPM_INT_STATUS(chip
->vendor
.locality
));
564 ioread32(chip
->vendor
.iobase
+ TPM_INT_STATUS(chip
->vendor
.locality
));
568 static bool interrupts
= true;
569 module_param(interrupts
, bool, 0444);
570 MODULE_PARM_DESC(interrupts
, "Enable interrupts");
572 static void tpm_tis_remove(struct tpm_chip
*chip
)
574 iowrite32(~TPM_GLOBAL_INT_ENABLE
&
575 ioread32(chip
->vendor
.iobase
+
576 TPM_INT_ENABLE(chip
->vendor
.
578 chip
->vendor
.iobase
+
579 TPM_INT_ENABLE(chip
->vendor
.locality
));
580 release_locality(chip
, chip
->vendor
.locality
, 1);
583 static int tpm_tis_init(struct device
*dev
, acpi_handle acpi_dev_handle
,
584 resource_size_t start
, resource_size_t len
,
587 u32 vendor
, intfcaps
, intmask
;
588 int rc
, i
, irq_s
, irq_e
, probe
;
589 struct tpm_chip
*chip
;
590 struct priv_data
*priv
;
592 priv
= devm_kzalloc(dev
, sizeof(struct priv_data
), GFP_KERNEL
);
596 chip
= tpmm_chip_alloc(dev
, &tpm_tis
);
598 return PTR_ERR(chip
);
600 chip
->vendor
.priv
= priv
;
601 chip
->acpi_dev_handle
= acpi_dev_handle
;
603 chip
->vendor
.iobase
= devm_ioremap(dev
, start
, len
);
604 if (!chip
->vendor
.iobase
)
607 /* Default timeouts */
608 chip
->vendor
.timeout_a
= msecs_to_jiffies(TIS_SHORT_TIMEOUT
);
609 chip
->vendor
.timeout_b
= msecs_to_jiffies(TIS_LONG_TIMEOUT
);
610 chip
->vendor
.timeout_c
= msecs_to_jiffies(TIS_SHORT_TIMEOUT
);
611 chip
->vendor
.timeout_d
= msecs_to_jiffies(TIS_SHORT_TIMEOUT
);
613 if (wait_startup(chip
, 0) != 0) {
618 if (request_locality(chip
, 0) != 0) {
623 vendor
= ioread32(chip
->vendor
.iobase
+ TPM_DID_VID(0));
624 chip
->vendor
.manufacturer_id
= vendor
;
627 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
628 vendor
>> 16, ioread8(chip
->vendor
.iobase
+ TPM_RID(0)));
631 probe
= probe_itpm(chip
);
640 dev_info(dev
, "Intel iTPM workaround enabled\n");
643 /* Figure out the capabilities */
645 ioread32(chip
->vendor
.iobase
+
646 TPM_INTF_CAPS(chip
->vendor
.locality
));
647 dev_dbg(dev
, "TPM interface capabilities (0x%x):\n",
649 if (intfcaps
& TPM_INTF_BURST_COUNT_STATIC
)
650 dev_dbg(dev
, "\tBurst Count Static\n");
651 if (intfcaps
& TPM_INTF_CMD_READY_INT
)
652 dev_dbg(dev
, "\tCommand Ready Int Support\n");
653 if (intfcaps
& TPM_INTF_INT_EDGE_FALLING
)
654 dev_dbg(dev
, "\tInterrupt Edge Falling\n");
655 if (intfcaps
& TPM_INTF_INT_EDGE_RISING
)
656 dev_dbg(dev
, "\tInterrupt Edge Rising\n");
657 if (intfcaps
& TPM_INTF_INT_LEVEL_LOW
)
658 dev_dbg(dev
, "\tInterrupt Level Low\n");
659 if (intfcaps
& TPM_INTF_INT_LEVEL_HIGH
)
660 dev_dbg(dev
, "\tInterrupt Level High\n");
661 if (intfcaps
& TPM_INTF_LOCALITY_CHANGE_INT
)
662 dev_dbg(dev
, "\tLocality Change Int Support\n");
663 if (intfcaps
& TPM_INTF_STS_VALID_INT
)
664 dev_dbg(dev
, "\tSts Valid Int Support\n");
665 if (intfcaps
& TPM_INTF_DATA_AVAIL_INT
)
666 dev_dbg(dev
, "\tData Avail Int Support\n");
668 /* INTERRUPT Setup */
669 init_waitqueue_head(&chip
->vendor
.read_queue
);
670 init_waitqueue_head(&chip
->vendor
.int_queue
);
673 ioread32(chip
->vendor
.iobase
+
674 TPM_INT_ENABLE(chip
->vendor
.locality
));
676 intmask
|= TPM_INTF_CMD_READY_INT
677 | TPM_INTF_LOCALITY_CHANGE_INT
| TPM_INTF_DATA_AVAIL_INT
678 | TPM_INTF_STS_VALID_INT
;
681 chip
->vendor
.iobase
+
682 TPM_INT_ENABLE(chip
->vendor
.locality
));
684 chip
->vendor
.irq
= irq
;
685 if (interrupts
&& !chip
->vendor
.irq
) {
687 ioread8(chip
->vendor
.iobase
+
688 TPM_INT_VECTOR(chip
->vendor
.locality
));
696 for (i
= irq_s
; i
<= irq_e
&& chip
->vendor
.irq
== 0; i
++) {
697 iowrite8(i
, chip
->vendor
.iobase
+
698 TPM_INT_VECTOR(chip
->vendor
.locality
));
700 (dev
, i
, tis_int_probe
, IRQF_SHARED
,
701 chip
->devname
, chip
) != 0) {
703 "Unable to request irq: %d for probe\n",
708 /* Clear all existing */
710 (chip
->vendor
.iobase
+
711 TPM_INT_STATUS(chip
->vendor
.locality
)),
712 chip
->vendor
.iobase
+
713 TPM_INT_STATUS(chip
->vendor
.locality
));
716 iowrite32(intmask
| TPM_GLOBAL_INT_ENABLE
,
717 chip
->vendor
.iobase
+
718 TPM_INT_ENABLE(chip
->vendor
.locality
));
720 chip
->vendor
.probed_irq
= 0;
722 /* Generate Interrupts */
723 tpm_gen_interrupt(chip
);
725 chip
->vendor
.irq
= chip
->vendor
.probed_irq
;
727 /* free_irq will call into tis_int_probe;
728 clear all irqs we haven't seen while doing
731 (chip
->vendor
.iobase
+
732 TPM_INT_STATUS(chip
->vendor
.locality
)),
733 chip
->vendor
.iobase
+
734 TPM_INT_STATUS(chip
->vendor
.locality
));
738 chip
->vendor
.iobase
+
739 TPM_INT_ENABLE(chip
->vendor
.locality
));
742 if (chip
->vendor
.irq
) {
743 iowrite8(chip
->vendor
.irq
,
744 chip
->vendor
.iobase
+
745 TPM_INT_VECTOR(chip
->vendor
.locality
));
747 (dev
, chip
->vendor
.irq
, tis_int_handler
, IRQF_SHARED
,
748 chip
->devname
, chip
) != 0) {
750 "Unable to request irq: %d for use\n",
752 chip
->vendor
.irq
= 0;
754 /* Clear all existing */
756 (chip
->vendor
.iobase
+
757 TPM_INT_STATUS(chip
->vendor
.locality
)),
758 chip
->vendor
.iobase
+
759 TPM_INT_STATUS(chip
->vendor
.locality
));
762 iowrite32(intmask
| TPM_GLOBAL_INT_ENABLE
,
763 chip
->vendor
.iobase
+
764 TPM_INT_ENABLE(chip
->vendor
.locality
));
768 if (tpm_get_timeouts(chip
)) {
769 dev_err(dev
, "Could not get TPM timeouts and durations\n");
774 if (tpm_do_selftest(chip
)) {
775 dev_err(dev
, "TPM self test failed\n");
780 return tpm_chip_register(chip
);
782 tpm_tis_remove(chip
);
786 #ifdef CONFIG_PM_SLEEP
787 static void tpm_tis_reenable_interrupts(struct tpm_chip
*chip
)
791 /* reenable interrupts that device may have lost or
792 BIOS/firmware may have disabled */
793 iowrite8(chip
->vendor
.irq
, chip
->vendor
.iobase
+
794 TPM_INT_VECTOR(chip
->vendor
.locality
));
797 ioread32(chip
->vendor
.iobase
+
798 TPM_INT_ENABLE(chip
->vendor
.locality
));
800 intmask
|= TPM_INTF_CMD_READY_INT
801 | TPM_INTF_LOCALITY_CHANGE_INT
| TPM_INTF_DATA_AVAIL_INT
802 | TPM_INTF_STS_VALID_INT
| TPM_GLOBAL_INT_ENABLE
;
805 chip
->vendor
.iobase
+ TPM_INT_ENABLE(chip
->vendor
.locality
));
808 static int tpm_tis_resume(struct device
*dev
)
810 struct tpm_chip
*chip
= dev_get_drvdata(dev
);
813 if (chip
->vendor
.irq
)
814 tpm_tis_reenable_interrupts(chip
);
816 ret
= tpm_pm_resume(dev
);
818 tpm_do_selftest(chip
);
824 static SIMPLE_DEV_PM_OPS(tpm_tis_pm
, tpm_pm_suspend
, tpm_tis_resume
);
827 static int tpm_tis_pnp_init(struct pnp_dev
*pnp_dev
,
828 const struct pnp_device_id
*pnp_id
)
830 resource_size_t start
, len
;
831 unsigned int irq
= 0;
832 acpi_handle acpi_dev_handle
= NULL
;
834 start
= pnp_mem_start(pnp_dev
, 0);
835 len
= pnp_mem_len(pnp_dev
, 0);
837 if (pnp_irq_valid(pnp_dev
, 0))
838 irq
= pnp_irq(pnp_dev
, 0);
842 if (is_itpm(pnp_dev
))
845 if (pnp_acpi_device(pnp_dev
))
846 acpi_dev_handle
= pnp_acpi_device(pnp_dev
)->handle
;
848 return tpm_tis_init(&pnp_dev
->dev
, acpi_dev_handle
, start
, len
, irq
);
851 static struct pnp_device_id tpm_pnp_tbl
[] = {
852 {"PNP0C31", 0}, /* TPM */
853 {"ATM1200", 0}, /* Atmel */
854 {"IFX0102", 0}, /* Infineon */
855 {"BCM0101", 0}, /* Broadcom */
856 {"BCM0102", 0}, /* Broadcom */
857 {"NSC1200", 0}, /* National */
858 {"ICO0102", 0}, /* Intel */
860 {"", 0}, /* User Specified */
861 {"", 0} /* Terminator */
863 MODULE_DEVICE_TABLE(pnp
, tpm_pnp_tbl
);
865 static void tpm_tis_pnp_remove(struct pnp_dev
*dev
)
867 struct tpm_chip
*chip
= pnp_get_drvdata(dev
);
868 tpm_chip_unregister(chip
);
869 tpm_tis_remove(chip
);
872 static struct pnp_driver tis_pnp_driver
= {
874 .id_table
= tpm_pnp_tbl
,
875 .probe
= tpm_tis_pnp_init
,
876 .remove
= tpm_tis_pnp_remove
,
882 #define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
883 module_param_string(hid
, tpm_pnp_tbl
[TIS_HID_USR_IDX
].id
,
884 sizeof(tpm_pnp_tbl
[TIS_HID_USR_IDX
].id
), 0444);
885 MODULE_PARM_DESC(hid
, "Set additional specific HID for this driver to probe");
888 static struct platform_driver tis_drv
= {
895 static struct platform_device
*pdev
;
898 module_param(force
, bool, 0444);
899 MODULE_PARM_DESC(force
, "Force device probe rather than using ACPI entry");
900 static int __init
init_tis(void)
905 return pnp_register_driver(&tis_pnp_driver
);
908 rc
= platform_driver_register(&tis_drv
);
911 pdev
= platform_device_register_simple("tpm_tis", -1, NULL
, 0);
916 rc
= tpm_tis_init(&pdev
->dev
, NULL
, TIS_MEM_BASE
, TIS_MEM_LEN
, 0);
921 platform_device_unregister(pdev
);
923 platform_driver_unregister(&tis_drv
);
927 static void __exit
cleanup_tis(void)
929 struct tpm_chip
*chip
;
932 pnp_unregister_driver(&tis_pnp_driver
);
936 chip
= dev_get_drvdata(&pdev
->dev
);
937 tpm_chip_unregister(chip
);
938 tpm_tis_remove(chip
);
939 platform_device_unregister(pdev
);
940 platform_driver_unregister(&tis_drv
);
943 module_init(init_tis
);
944 module_exit(cleanup_tis
);
945 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
946 MODULE_DESCRIPTION("TPM Driver");
947 MODULE_VERSION("2.0");
948 MODULE_LICENSE("GPL");