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))
78 static LIST_HEAD(tis_chips);
79 static DEFINE_MUTEX(tis_lock);
81 #if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
82 static int is_itpm(struct pnp_dev *dev)
84 struct acpi_device *acpi = pnp_acpi_device(dev);
85 struct acpi_hardware_id *id;
90 list_for_each_entry(id, &acpi->pnp.ids, list) {
91 if (!strcmp("INTC0102", id->id))
98 static inline int is_itpm(struct pnp_dev *dev)
104 /* Before we attempt to access the TPM we must see that the valid bit is set.
105 * The specification says that this bit is 0 at reset and remains 0 until the
106 * 'TPM has gone through its self test and initialization and has established
107 * correct values in the other bits.' */
108 static int wait_startup(struct tpm_chip *chip, int l)
110 unsigned long stop = jiffies + chip->vendor.timeout_a;
112 if (ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
116 } while (time_before(jiffies, stop));
120 static int check_locality(struct tpm_chip *chip, int l)
122 if ((ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
123 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
124 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
125 return chip->vendor.locality = l;
130 static void release_locality(struct tpm_chip *chip, int l, int force)
132 if (force || (ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
133 (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) ==
134 (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID))
135 iowrite8(TPM_ACCESS_ACTIVE_LOCALITY,
136 chip->vendor.iobase + TPM_ACCESS(l));
139 static int request_locality(struct tpm_chip *chip, int l)
141 unsigned long stop, timeout;
144 if (check_locality(chip, l) >= 0)
147 iowrite8(TPM_ACCESS_REQUEST_USE,
148 chip->vendor.iobase + TPM_ACCESS(l));
150 stop = jiffies + chip->vendor.timeout_a;
152 if (chip->vendor.irq) {
154 timeout = stop - jiffies;
155 if ((long)timeout <= 0)
157 rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
163 if (rc == -ERESTARTSYS && freezing(current)) {
164 clear_thread_flag(TIF_SIGPENDING);
168 /* wait for burstcount */
170 if (check_locality(chip, l) >= 0)
174 while (time_before(jiffies, stop));
179 static u8 tpm_tis_status(struct tpm_chip *chip)
181 return ioread8(chip->vendor.iobase +
182 TPM_STS(chip->vendor.locality));
185 static void tpm_tis_ready(struct tpm_chip *chip)
187 /* this causes the current command to be aborted */
188 iowrite8(TPM_STS_COMMAND_READY,
189 chip->vendor.iobase + TPM_STS(chip->vendor.locality));
192 static int get_burstcount(struct tpm_chip *chip)
197 /* wait for burstcount */
198 /* which timeout value, spec has 2 answers (c & d) */
199 stop = jiffies + chip->vendor.timeout_d;
201 burstcnt = ioread8(chip->vendor.iobase +
202 TPM_STS(chip->vendor.locality) + 1);
203 burstcnt += ioread8(chip->vendor.iobase +
204 TPM_STS(chip->vendor.locality) +
209 } while (time_before(jiffies, stop));
213 static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
215 int size = 0, burstcnt;
216 while (size < count &&
217 wait_for_tpm_stat(chip,
218 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
219 chip->vendor.timeout_c,
220 &chip->vendor.read_queue, true)
222 burstcnt = get_burstcount(chip);
223 for (; burstcnt > 0 && size < count; burstcnt--)
224 buf[size++] = ioread8(chip->vendor.iobase +
225 TPM_DATA_FIFO(chip->vendor.
231 static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
234 int expected, status;
236 if (count < TPM_HEADER_SIZE) {
241 /* read first 10 bytes, including tag, paramsize, and result */
243 recv_data(chip, buf, TPM_HEADER_SIZE)) < TPM_HEADER_SIZE) {
244 dev_err(chip->dev, "Unable to read header\n");
248 expected = be32_to_cpu(*(__be32 *) (buf + 2));
249 if (expected > count) {
255 recv_data(chip, &buf[TPM_HEADER_SIZE],
256 expected - TPM_HEADER_SIZE)) < expected) {
257 dev_err(chip->dev, "Unable to read remainder of result\n");
262 wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
263 &chip->vendor.int_queue, false);
264 status = tpm_tis_status(chip);
265 if (status & TPM_STS_DATA_AVAIL) { /* retry? */
266 dev_err(chip->dev, "Error left over data\n");
273 release_locality(chip, chip->vendor.locality, 0);
278 module_param(itpm, bool, 0444);
279 MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
282 * If interrupts are used (signaled by an irq set in the vendor structure)
283 * tpm.c can skip polling for the data to be available as the interrupt is
286 static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
288 int rc, status, burstcnt;
291 if (request_locality(chip, 0) < 0)
294 status = tpm_tis_status(chip);
295 if ((status & TPM_STS_COMMAND_READY) == 0) {
297 if (wait_for_tpm_stat
298 (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
299 &chip->vendor.int_queue, false) < 0) {
305 while (count < len - 1) {
306 burstcnt = get_burstcount(chip);
307 for (; burstcnt > 0 && count < len - 1; burstcnt--) {
308 iowrite8(buf[count], chip->vendor.iobase +
309 TPM_DATA_FIFO(chip->vendor.locality));
313 wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
314 &chip->vendor.int_queue, false);
315 status = tpm_tis_status(chip);
316 if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
322 /* write last byte */
324 chip->vendor.iobase + TPM_DATA_FIFO(chip->vendor.locality));
325 wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
326 &chip->vendor.int_queue, false);
327 status = tpm_tis_status(chip);
328 if ((status & TPM_STS_DATA_EXPECT) != 0) {
337 release_locality(chip, chip->vendor.locality, 0);
342 * If interrupts are used (signaled by an irq set in the vendor structure)
343 * tpm.c can skip polling for the data to be available as the interrupt is
346 static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
351 rc = tpm_tis_send_data(chip, buf, len);
357 chip->vendor.iobase + TPM_STS(chip->vendor.locality));
359 if (chip->vendor.irq) {
360 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
361 if (wait_for_tpm_stat
362 (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
363 tpm_calc_ordinal_duration(chip, ordinal),
364 &chip->vendor.read_queue, false) < 0) {
372 release_locality(chip, chip->vendor.locality, 0);
377 * Early probing for iTPM with STS_DATA_EXPECT flaw.
378 * Try sending command without itpm flag set and if that
379 * fails, repeat with itpm flag set.
381 static int probe_itpm(struct tpm_chip *chip)
384 u8 cmd_getticks[] = {
385 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
386 0x00, 0x00, 0x00, 0xf1
388 size_t len = sizeof(cmd_getticks);
389 bool rem_itpm = itpm;
390 u16 vendor = ioread16(chip->vendor.iobase + TPM_DID_VID(0));
392 /* probe only iTPMS */
393 if (vendor != TPM_VID_INTEL)
398 rc = tpm_tis_send_data(chip, cmd_getticks, len);
403 release_locality(chip, chip->vendor.locality, 0);
407 rc = tpm_tis_send_data(chip, cmd_getticks, len);
409 dev_info(chip->dev, "Detected an iTPM.\n");
417 release_locality(chip, chip->vendor.locality, 0);
422 static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
424 switch (chip->vendor.manufacturer_id) {
425 case TPM_VID_WINBOND:
426 return ((status == TPM_STS_VALID) ||
427 (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
429 return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
431 return (status == TPM_STS_COMMAND_READY);
435 static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
436 static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
437 static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
438 static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL);
439 static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL);
440 static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated,
442 static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
443 static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
444 static DEVICE_ATTR(durations, S_IRUGO, tpm_show_durations, NULL);
445 static DEVICE_ATTR(timeouts, S_IRUGO, tpm_show_timeouts, NULL);
447 static struct attribute *tis_attrs[] = {
448 &dev_attr_pubek.attr,
450 &dev_attr_enabled.attr,
451 &dev_attr_active.attr,
452 &dev_attr_owned.attr,
453 &dev_attr_temp_deactivated.attr,
455 &dev_attr_cancel.attr,
456 &dev_attr_durations.attr,
457 &dev_attr_timeouts.attr, NULL,
460 static struct attribute_group tis_attr_grp = {
464 static struct tpm_vendor_specific tpm_tis = {
465 .status = tpm_tis_status,
466 .recv = tpm_tis_recv,
467 .send = tpm_tis_send,
468 .cancel = tpm_tis_ready,
469 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
470 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
471 .req_canceled = tpm_tis_req_canceled,
472 .attr_group = &tis_attr_grp,
475 static irqreturn_t tis_int_probe(int irq, void *dev_id)
477 struct tpm_chip *chip = dev_id;
480 interrupt = ioread32(chip->vendor.iobase +
481 TPM_INT_STATUS(chip->vendor.locality));
486 chip->vendor.probed_irq = irq;
488 /* Clear interrupts handled with TPM_EOI */
490 chip->vendor.iobase +
491 TPM_INT_STATUS(chip->vendor.locality));
495 static irqreturn_t tis_int_handler(int dummy, void *dev_id)
497 struct tpm_chip *chip = dev_id;
501 interrupt = ioread32(chip->vendor.iobase +
502 TPM_INT_STATUS(chip->vendor.locality));
507 if (interrupt & TPM_INTF_DATA_AVAIL_INT)
508 wake_up_interruptible(&chip->vendor.read_queue);
509 if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
510 for (i = 0; i < 5; i++)
511 if (check_locality(chip, i) >= 0)
514 (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
515 TPM_INTF_CMD_READY_INT))
516 wake_up_interruptible(&chip->vendor.int_queue);
518 /* Clear interrupts handled with TPM_EOI */
520 chip->vendor.iobase +
521 TPM_INT_STATUS(chip->vendor.locality));
522 ioread32(chip->vendor.iobase + TPM_INT_STATUS(chip->vendor.locality));
526 static bool interrupts = true;
527 module_param(interrupts, bool, 0444);
528 MODULE_PARM_DESC(interrupts, "Enable interrupts");
530 static int tpm_tis_init(struct device *dev, resource_size_t start,
531 resource_size_t len, unsigned int irq)
533 u32 vendor, intfcaps, intmask;
534 int rc, i, irq_s, irq_e, probe;
535 struct tpm_chip *chip;
537 if (!(chip = tpm_register_hardware(dev, &tpm_tis)))
540 chip->vendor.iobase = ioremap(start, len);
541 if (!chip->vendor.iobase) {
546 /* Default timeouts */
547 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
548 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
549 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
550 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
552 if (wait_startup(chip, 0) != 0) {
557 if (request_locality(chip, 0) != 0) {
562 vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
563 chip->vendor.manufacturer_id = vendor;
566 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
567 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
570 probe = probe_itpm(chip);
579 dev_info(dev, "Intel iTPM workaround enabled\n");
582 /* Figure out the capabilities */
584 ioread32(chip->vendor.iobase +
585 TPM_INTF_CAPS(chip->vendor.locality));
586 dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
588 if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
589 dev_dbg(dev, "\tBurst Count Static\n");
590 if (intfcaps & TPM_INTF_CMD_READY_INT)
591 dev_dbg(dev, "\tCommand Ready Int Support\n");
592 if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
593 dev_dbg(dev, "\tInterrupt Edge Falling\n");
594 if (intfcaps & TPM_INTF_INT_EDGE_RISING)
595 dev_dbg(dev, "\tInterrupt Edge Rising\n");
596 if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
597 dev_dbg(dev, "\tInterrupt Level Low\n");
598 if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
599 dev_dbg(dev, "\tInterrupt Level High\n");
600 if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
601 dev_dbg(dev, "\tLocality Change Int Support\n");
602 if (intfcaps & TPM_INTF_STS_VALID_INT)
603 dev_dbg(dev, "\tSts Valid Int Support\n");
604 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
605 dev_dbg(dev, "\tData Avail Int Support\n");
607 /* get the timeouts before testing for irqs */
608 if (tpm_get_timeouts(chip)) {
609 dev_err(dev, "Could not get TPM timeouts and durations\n");
614 if (tpm_do_selftest(chip)) {
615 dev_err(dev, "TPM self test failed\n");
620 /* INTERRUPT Setup */
621 init_waitqueue_head(&chip->vendor.read_queue);
622 init_waitqueue_head(&chip->vendor.int_queue);
625 ioread32(chip->vendor.iobase +
626 TPM_INT_ENABLE(chip->vendor.locality));
628 intmask |= TPM_INTF_CMD_READY_INT
629 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
630 | TPM_INTF_STS_VALID_INT;
633 chip->vendor.iobase +
634 TPM_INT_ENABLE(chip->vendor.locality));
636 chip->vendor.irq = irq;
637 if (interrupts && !chip->vendor.irq) {
639 ioread8(chip->vendor.iobase +
640 TPM_INT_VECTOR(chip->vendor.locality));
648 for (i = irq_s; i <= irq_e && chip->vendor.irq == 0; i++) {
649 iowrite8(i, chip->vendor.iobase +
650 TPM_INT_VECTOR(chip->vendor.locality));
652 (i, tis_int_probe, IRQF_SHARED,
653 chip->vendor.miscdev.name, chip) != 0) {
655 "Unable to request irq: %d for probe\n",
660 /* Clear all existing */
662 (chip->vendor.iobase +
663 TPM_INT_STATUS(chip->vendor.locality)),
664 chip->vendor.iobase +
665 TPM_INT_STATUS(chip->vendor.locality));
668 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
669 chip->vendor.iobase +
670 TPM_INT_ENABLE(chip->vendor.locality));
672 chip->vendor.probed_irq = 0;
674 /* Generate Interrupts */
675 tpm_gen_interrupt(chip);
677 chip->vendor.irq = chip->vendor.probed_irq;
679 /* free_irq will call into tis_int_probe;
680 clear all irqs we haven't seen while doing
683 (chip->vendor.iobase +
684 TPM_INT_STATUS(chip->vendor.locality)),
685 chip->vendor.iobase +
686 TPM_INT_STATUS(chip->vendor.locality));
690 chip->vendor.iobase +
691 TPM_INT_ENABLE(chip->vendor.locality));
695 if (chip->vendor.irq) {
696 iowrite8(chip->vendor.irq,
697 chip->vendor.iobase +
698 TPM_INT_VECTOR(chip->vendor.locality));
700 (chip->vendor.irq, tis_int_handler, IRQF_SHARED,
701 chip->vendor.miscdev.name, chip) != 0) {
703 "Unable to request irq: %d for use\n",
705 chip->vendor.irq = 0;
707 /* Clear all existing */
709 (chip->vendor.iobase +
710 TPM_INT_STATUS(chip->vendor.locality)),
711 chip->vendor.iobase +
712 TPM_INT_STATUS(chip->vendor.locality));
715 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
716 chip->vendor.iobase +
717 TPM_INT_ENABLE(chip->vendor.locality));
721 INIT_LIST_HEAD(&chip->vendor.list);
722 mutex_lock(&tis_lock);
723 list_add(&chip->vendor.list, &tis_chips);
724 mutex_unlock(&tis_lock);
729 if (chip->vendor.iobase)
730 iounmap(chip->vendor.iobase);
731 tpm_remove_hardware(chip->dev);
735 #if defined(CONFIG_PNP) || defined(CONFIG_PM_SLEEP)
736 static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
740 /* reenable interrupts that device may have lost or
741 BIOS/firmware may have disabled */
742 iowrite8(chip->vendor.irq, chip->vendor.iobase +
743 TPM_INT_VECTOR(chip->vendor.locality));
746 ioread32(chip->vendor.iobase +
747 TPM_INT_ENABLE(chip->vendor.locality));
749 intmask |= TPM_INTF_CMD_READY_INT
750 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
751 | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE;
754 chip->vendor.iobase + TPM_INT_ENABLE(chip->vendor.locality));
758 #ifdef CONFIG_PM_SLEEP
759 static int tpm_tis_resume(struct device *dev)
761 struct tpm_chip *chip = dev_get_drvdata(dev);
764 if (chip->vendor.irq)
765 tpm_tis_reenable_interrupts(chip);
767 ret = tpm_pm_resume(dev);
769 tpm_do_selftest(chip);
775 static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
778 static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
779 const struct pnp_device_id *pnp_id)
781 resource_size_t start, len;
782 unsigned int irq = 0;
784 start = pnp_mem_start(pnp_dev, 0);
785 len = pnp_mem_len(pnp_dev, 0);
787 if (pnp_irq_valid(pnp_dev, 0))
788 irq = pnp_irq(pnp_dev, 0);
792 if (is_itpm(pnp_dev))
795 return tpm_tis_init(&pnp_dev->dev, start, len, irq);
798 static struct pnp_device_id tpm_pnp_tbl[] = {
799 {"PNP0C31", 0}, /* TPM */
800 {"ATM1200", 0}, /* Atmel */
801 {"IFX0102", 0}, /* Infineon */
802 {"BCM0101", 0}, /* Broadcom */
803 {"BCM0102", 0}, /* Broadcom */
804 {"NSC1200", 0}, /* National */
805 {"ICO0102", 0}, /* Intel */
807 {"", 0}, /* User Specified */
808 {"", 0} /* Terminator */
810 MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
812 static void tpm_tis_pnp_remove(struct pnp_dev *dev)
814 struct tpm_chip *chip = pnp_get_drvdata(dev);
816 tpm_dev_vendor_release(chip);
822 static struct pnp_driver tis_pnp_driver = {
824 .id_table = tpm_pnp_tbl,
825 .probe = tpm_tis_pnp_init,
826 .remove = tpm_tis_pnp_remove,
827 #ifdef CONFIG_PM_SLEEP
834 #define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
835 module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
836 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
837 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
840 static struct platform_driver tis_drv = {
843 .owner = THIS_MODULE,
848 static struct platform_device *pdev;
851 module_param(force, bool, 0444);
852 MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
853 static int __init init_tis(void)
858 return pnp_register_driver(&tis_pnp_driver);
861 rc = platform_driver_register(&tis_drv);
864 pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0);
869 rc = tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0);
874 platform_device_unregister(pdev);
876 platform_driver_unregister(&tis_drv);
880 static void __exit cleanup_tis(void)
882 struct tpm_vendor_specific *i, *j;
883 struct tpm_chip *chip;
884 mutex_lock(&tis_lock);
885 list_for_each_entry_safe(i, j, &tis_chips, list) {
886 chip = to_tpm_chip(i);
887 tpm_remove_hardware(chip->dev);
888 iowrite32(~TPM_GLOBAL_INT_ENABLE &
889 ioread32(chip->vendor.iobase +
890 TPM_INT_ENABLE(chip->vendor.
892 chip->vendor.iobase +
893 TPM_INT_ENABLE(chip->vendor.locality));
894 release_locality(chip, chip->vendor.locality, 1);
895 if (chip->vendor.irq)
896 free_irq(chip->vendor.irq, chip);
900 mutex_unlock(&tis_lock);
903 pnp_unregister_driver(&tis_pnp_driver);
907 platform_device_unregister(pdev);
908 platform_driver_unregister(&tis_drv);
911 module_init(init_tis);
912 module_exit(cleanup_tis);
913 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
914 MODULE_DESCRIPTION("TPM Driver");
915 MODULE_VERSION("2.0");
916 MODULE_LICENSE("GPL");