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 static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value);
36 /* Before we attempt to access the TPM we must see that the valid bit is set.
37 * The specification says that this bit is 0 at reset and remains 0 until the
38 * 'TPM has gone through its self test and initialization and has established
39 * correct values in the other bits.'
41 static int wait_startup(struct tpm_chip *chip, int l)
43 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
44 unsigned long stop = jiffies + chip->timeout_a;
50 rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
54 if (access & TPM_ACCESS_VALID)
56 tpm_msleep(TPM_TIMEOUT);
57 } while (time_before(jiffies, stop));
61 static bool check_locality(struct tpm_chip *chip, int l)
63 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
67 rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
71 if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID
72 | TPM_ACCESS_REQUEST_USE)) ==
73 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
81 static int release_locality(struct tpm_chip *chip, int l)
83 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
85 tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
90 static int request_locality(struct tpm_chip *chip, int l)
92 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
93 unsigned long stop, timeout;
96 if (check_locality(chip, l))
99 rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE);
103 stop = jiffies + chip->timeout_a;
105 if (chip->flags & TPM_CHIP_FLAG_IRQ) {
107 timeout = stop - jiffies;
108 if ((long)timeout <= 0)
110 rc = wait_event_interruptible_timeout(priv->int_queue,
116 if (rc == -ERESTARTSYS && freezing(current)) {
117 clear_thread_flag(TIF_SIGPENDING);
121 /* wait for burstcount */
123 if (check_locality(chip, l))
125 tpm_msleep(TPM_TIMEOUT);
126 } while (time_before(jiffies, stop));
131 static u8 tpm_tis_status(struct tpm_chip *chip)
133 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
137 rc = tpm_tis_read8(priv, TPM_STS(priv->locality), &status);
144 static void tpm_tis_ready(struct tpm_chip *chip)
146 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
148 /* this causes the current command to be aborted */
149 tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_COMMAND_READY);
152 static int get_burstcount(struct tpm_chip *chip)
154 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
159 /* wait for burstcount */
160 if (chip->flags & TPM_CHIP_FLAG_TPM2)
161 stop = jiffies + chip->timeout_a;
163 stop = jiffies + chip->timeout_d;
165 rc = tpm_tis_read32(priv, TPM_STS(priv->locality), &value);
169 burstcnt = (value >> 8) & 0xFFFF;
172 tpm_msleep(TPM_TIMEOUT);
173 } while (time_before(jiffies, stop));
177 static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
179 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
180 int size = 0, burstcnt, rc;
182 while (size < count) {
183 rc = wait_for_tpm_stat(chip,
184 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
186 &priv->read_queue, true);
189 burstcnt = get_burstcount(chip);
191 dev_err(&chip->dev, "Unable to read burstcount\n");
194 burstcnt = min_t(int, burstcnt, count - size);
196 rc = tpm_tis_read_bytes(priv, TPM_DATA_FIFO(priv->locality),
197 burstcnt, buf + size);
206 static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
208 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
214 if (count < TPM_HEADER_SIZE) {
219 size = recv_data(chip, buf, TPM_HEADER_SIZE);
220 /* read first 10 bytes, including tag, paramsize, and result */
221 if (size < TPM_HEADER_SIZE) {
222 dev_err(&chip->dev, "Unable to read header\n");
226 expected = be32_to_cpu(*(__be32 *) (buf + 2));
227 if (expected > count || expected < TPM_HEADER_SIZE) {
232 rc = recv_data(chip, &buf[TPM_HEADER_SIZE],
233 expected - TPM_HEADER_SIZE);
239 if (size < expected) {
240 dev_err(&chip->dev, "Unable to read remainder of result\n");
245 if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
246 &priv->int_queue, false) < 0) {
250 status = tpm_tis_status(chip);
251 if (status & TPM_STS_DATA_AVAIL) { /* retry? */
252 dev_err(&chip->dev, "Error left over data\n");
263 * If interrupts are used (signaled by an irq set in the vendor structure)
264 * tpm.c can skip polling for the data to be available as the interrupt is
267 static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
269 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
270 int rc, status, burstcnt;
272 bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
274 status = tpm_tis_status(chip);
275 if ((status & TPM_STS_COMMAND_READY) == 0) {
277 if (wait_for_tpm_stat
278 (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
279 &priv->int_queue, false) < 0) {
285 while (count < len - 1) {
286 burstcnt = get_burstcount(chip);
288 dev_err(&chip->dev, "Unable to read burstcount\n");
292 burstcnt = min_t(int, burstcnt, len - count - 1);
293 rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
294 burstcnt, buf + count);
300 if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
301 &priv->int_queue, false) < 0) {
305 status = tpm_tis_status(chip);
306 if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
312 /* write last byte */
313 rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
317 if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
318 &priv->int_queue, false) < 0) {
322 status = tpm_tis_status(chip);
323 if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
335 static void disable_interrupts(struct tpm_chip *chip)
337 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
344 rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
348 intmask &= ~TPM_GLOBAL_INT_ENABLE;
349 rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
351 devm_free_irq(chip->dev.parent, priv->irq, chip);
353 chip->flags &= ~TPM_CHIP_FLAG_IRQ;
357 * If interrupts are used (signaled by an irq set in the vendor structure)
358 * tpm.c can skip polling for the data to be available as the interrupt is
361 static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
363 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
369 for (try = 0; try < TPM_RETRY; try++) {
370 rc = tpm_tis_send_data(chip, buf, len);
372 /* Data transfer done successfully */
375 /* Data transfer failed, not recoverable */
380 rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
384 if (chip->flags & TPM_CHIP_FLAG_IRQ) {
385 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
387 if (chip->flags & TPM_CHIP_FLAG_TPM2)
388 dur = tpm2_calc_ordinal_duration(chip, ordinal);
390 dur = tpm_calc_ordinal_duration(chip, ordinal);
392 if (wait_for_tpm_stat
393 (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur,
394 &priv->read_queue, false) < 0) {
405 static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
408 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
410 if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested)
411 return tpm_tis_send_main(chip, buf, len);
413 /* Verify receipt of the expected IRQ */
416 chip->flags &= ~TPM_CHIP_FLAG_IRQ;
417 rc = tpm_tis_send_main(chip, buf, len);
419 chip->flags |= TPM_CHIP_FLAG_IRQ;
420 if (!priv->irq_tested)
422 if (!priv->irq_tested)
423 disable_interrupts(chip);
424 priv->irq_tested = true;
428 struct tis_vendor_timeout_override {
430 unsigned long timeout_us[4];
433 static const struct tis_vendor_timeout_override vendor_timeout_overrides[] = {
435 { 0x32041114, { (TIS_SHORT_TIMEOUT*1000), (TIS_LONG_TIMEOUT*1000),
436 (TIS_SHORT_TIMEOUT*1000), (TIS_SHORT_TIMEOUT*1000) } },
439 static bool tpm_tis_update_timeouts(struct tpm_chip *chip,
440 unsigned long *timeout_cap)
442 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
446 if (chip->ops->clk_enable != NULL)
447 chip->ops->clk_enable(chip, true);
449 rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
453 for (i = 0; i != ARRAY_SIZE(vendor_timeout_overrides); i++) {
454 if (vendor_timeout_overrides[i].did_vid != did_vid)
456 memcpy(timeout_cap, vendor_timeout_overrides[i].timeout_us,
457 sizeof(vendor_timeout_overrides[i].timeout_us));
464 if (chip->ops->clk_enable != NULL)
465 chip->ops->clk_enable(chip, false);
471 * Early probing for iTPM with STS_DATA_EXPECT flaw.
472 * Try sending command without itpm flag set and if that
473 * fails, repeat with itpm flag set.
475 static int probe_itpm(struct tpm_chip *chip)
477 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
479 u8 cmd_getticks[] = {
480 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
481 0x00, 0x00, 0x00, 0xf1
483 size_t len = sizeof(cmd_getticks);
486 if (priv->flags & TPM_TIS_ITPM_WORKAROUND)
489 rc = tpm_tis_read16(priv, TPM_DID_VID(0), &vendor);
493 /* probe only iTPMS */
494 if (vendor != TPM_VID_INTEL)
497 if (request_locality(chip, 0) != 0)
500 rc = tpm_tis_send_data(chip, cmd_getticks, len);
506 priv->flags |= TPM_TIS_ITPM_WORKAROUND;
508 rc = tpm_tis_send_data(chip, cmd_getticks, len);
510 dev_info(&chip->dev, "Detected an iTPM.\n");
512 priv->flags &= ~TPM_TIS_ITPM_WORKAROUND;
518 release_locality(chip, priv->locality);
523 static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
525 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
527 switch (priv->manufacturer_id) {
528 case TPM_VID_WINBOND:
529 return ((status == TPM_STS_VALID) ||
530 (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
532 return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
534 return (status == TPM_STS_COMMAND_READY);
538 static irqreturn_t tis_int_handler(int dummy, void *dev_id)
540 struct tpm_chip *chip = dev_id;
541 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
545 rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt);
552 priv->irq_tested = true;
553 if (interrupt & TPM_INTF_DATA_AVAIL_INT)
554 wake_up_interruptible(&priv->read_queue);
555 if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
556 for (i = 0; i < 5; i++)
557 if (check_locality(chip, i))
560 (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
561 TPM_INTF_CMD_READY_INT))
562 wake_up_interruptible(&priv->int_queue);
564 /* Clear interrupts handled with TPM_EOI */
565 rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt);
569 tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt);
573 static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
575 const char *desc = "attempting to generate an interrupt";
579 if (chip->flags & TPM_CHIP_FLAG_TPM2)
580 return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
582 return tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc,
586 /* Register the IRQ and issue a command that will cause an interrupt. If an
587 * irq is seen then leave the chip setup for IRQ operation, otherwise reverse
588 * everything and leave in polling mode. Returns 0 on success.
590 static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
593 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
598 if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags,
599 dev_name(&chip->dev), chip) != 0) {
600 dev_info(&chip->dev, "Unable to request irq: %d for probe\n",
606 rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality),
611 rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq);
615 rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status);
619 /* Clear all existing */
620 rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status);
625 rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality),
626 intmask | TPM_GLOBAL_INT_ENABLE);
630 priv->irq_tested = false;
632 /* Generate an interrupt by having the core call through to
635 rc = tpm_tis_gen_interrupt(chip);
639 /* tpm_tis_send will either confirm the interrupt is working or it
640 * will call disable_irq which undoes all of the above.
642 if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
643 rc = tpm_tis_write8(priv, original_int_vec,
644 TPM_INT_VECTOR(priv->locality));
654 /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that
655 * do not have ACPI/etc. We typically expect the interrupt to be declared if
658 static void tpm_tis_probe_irq(struct tpm_chip *chip, u32 intmask)
660 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
664 rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality),
669 if (!original_int_vec) {
670 if (IS_ENABLED(CONFIG_X86))
671 for (i = 3; i <= 15; i++)
672 if (!tpm_tis_probe_irq_single(chip, intmask, 0,
675 } else if (!tpm_tis_probe_irq_single(chip, intmask, 0,
680 void tpm_tis_remove(struct tpm_chip *chip)
682 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
683 u32 reg = TPM_INT_ENABLE(priv->locality);
687 tpm_tis_clkrun_enable(chip, true);
689 rc = tpm_tis_read32(priv, reg, &interrupt);
693 tpm_tis_write32(priv, reg, ~TPM_GLOBAL_INT_ENABLE & interrupt);
695 tpm_tis_clkrun_enable(chip, false);
697 if (priv->ilb_base_addr)
698 iounmap(priv->ilb_base_addr);
700 EXPORT_SYMBOL_GPL(tpm_tis_remove);
703 * tpm_tis_clkrun_enable() - Keep clkrun protocol disabled for entire duration
704 * of a single TPM command
705 * @chip: TPM chip to use
706 * @value: 1 - Disable CLKRUN protocol, so that clocks are free running
707 * 0 - Enable CLKRUN protocol
708 * Call this function directly in tpm_tis_remove() in error or driver removal
709 * path, since the chip->ops is set to NULL in tpm_chip_unregister().
711 static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
713 struct tpm_tis_data *data = dev_get_drvdata(&chip->dev);
716 if (!IS_ENABLED(CONFIG_X86) || !is_bsw() ||
717 !data->ilb_base_addr)
721 data->clkrun_enabled++;
722 if (data->clkrun_enabled > 1)
724 clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
726 /* Disable LPC CLKRUN# */
727 clkrun_val &= ~LPC_CLKRUN_EN;
728 iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
731 * Write any random value on port 0x80 which is on LPC, to make
732 * sure LPC clock is running before sending any TPM command.
736 data->clkrun_enabled--;
737 if (data->clkrun_enabled)
740 clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
742 /* Enable LPC CLKRUN# */
743 clkrun_val |= LPC_CLKRUN_EN;
744 iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
747 * Write any random value on port 0x80 which is on LPC, to make
748 * sure LPC clock is running before sending any TPM command.
754 static const struct tpm_class_ops tpm_tis = {
755 .flags = TPM_OPS_AUTO_STARTUP,
756 .status = tpm_tis_status,
757 .recv = tpm_tis_recv,
758 .send = tpm_tis_send,
759 .cancel = tpm_tis_ready,
760 .update_timeouts = tpm_tis_update_timeouts,
761 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
762 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
763 .req_canceled = tpm_tis_req_canceled,
764 .request_locality = request_locality,
765 .relinquish_locality = release_locality,
766 .clk_enable = tpm_tis_clkrun_enable,
769 int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
770 const struct tpm_tis_phy_ops *phy_ops,
771 acpi_handle acpi_dev_handle)
773 u32 vendor, intfcaps, intmask;
777 struct tpm_chip *chip;
779 chip = tpmm_chip_alloc(dev, &tpm_tis);
781 return PTR_ERR(chip);
784 chip->acpi_dev_handle = acpi_dev_handle;
787 /* Maximum timeouts */
788 chip->timeout_a = msecs_to_jiffies(TIS_TIMEOUT_A_MAX);
789 chip->timeout_b = msecs_to_jiffies(TIS_TIMEOUT_B_MAX);
790 chip->timeout_c = msecs_to_jiffies(TIS_TIMEOUT_C_MAX);
791 chip->timeout_d = msecs_to_jiffies(TIS_TIMEOUT_D_MAX);
792 priv->phy_ops = phy_ops;
793 dev_set_drvdata(&chip->dev, priv);
796 priv->ilb_base_addr = ioremap(INTEL_LEGACY_BLK_BASE_ADDR,
798 if (!priv->ilb_base_addr)
801 clkrun_val = ioread32(priv->ilb_base_addr + LPC_CNTRL_OFFSET);
802 /* Check if CLKRUN# is already not enabled in the LPC bus */
803 if (!(clkrun_val & LPC_CLKRUN_EN)) {
804 iounmap(priv->ilb_base_addr);
805 priv->ilb_base_addr = NULL;
809 if (chip->ops->clk_enable != NULL)
810 chip->ops->clk_enable(chip, true);
812 if (wait_startup(chip, 0) != 0) {
817 /* Take control of the TPM's interrupt hardware and shut it off */
818 rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
822 intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT |
823 TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT;
824 intmask &= ~TPM_GLOBAL_INT_ENABLE;
826 rc = request_locality(chip, 0);
832 tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
833 release_locality(chip, 0);
835 rc = tpm2_probe(chip);
839 rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor);
843 priv->manufacturer_id = vendor;
845 rc = tpm_tis_read8(priv, TPM_RID(0), &rid);
849 dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n",
850 (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2",
853 probe = probe_itpm(chip);
859 /* Figure out the capabilities */
860 rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps);
864 dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
866 if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
867 dev_dbg(dev, "\tBurst Count Static\n");
868 if (intfcaps & TPM_INTF_CMD_READY_INT)
869 dev_dbg(dev, "\tCommand Ready Int Support\n");
870 if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
871 dev_dbg(dev, "\tInterrupt Edge Falling\n");
872 if (intfcaps & TPM_INTF_INT_EDGE_RISING)
873 dev_dbg(dev, "\tInterrupt Edge Rising\n");
874 if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
875 dev_dbg(dev, "\tInterrupt Level Low\n");
876 if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
877 dev_dbg(dev, "\tInterrupt Level High\n");
878 if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
879 dev_dbg(dev, "\tLocality Change Int Support\n");
880 if (intfcaps & TPM_INTF_STS_VALID_INT)
881 dev_dbg(dev, "\tSts Valid Int Support\n");
882 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
883 dev_dbg(dev, "\tData Avail Int Support\n");
885 /* INTERRUPT Setup */
886 init_waitqueue_head(&priv->read_queue);
887 init_waitqueue_head(&priv->int_queue);
889 /* Before doing irq testing issue a command to the TPM in polling mode
890 * to make sure it works. May as well use that command to set the
891 * proper timeouts for the driver.
893 if (tpm_get_timeouts(chip)) {
894 dev_err(dev, "Could not get TPM timeouts and durations\n");
900 tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
902 if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
903 dev_err(&chip->dev, FW_BUG
904 "TPM interrupt not working, polling instead\n");
906 disable_interrupts(chip);
909 tpm_tis_probe_irq(chip, intmask);
913 rc = tpm_chip_register(chip);
917 if (chip->ops->clk_enable != NULL)
918 chip->ops->clk_enable(chip, false);
922 if (chip->ops->clk_enable != NULL)
923 chip->ops->clk_enable(chip, false);
925 tpm_tis_remove(chip);
929 EXPORT_SYMBOL_GPL(tpm_tis_core_init);
931 #ifdef CONFIG_PM_SLEEP
932 static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
934 struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
938 if (chip->ops->clk_enable != NULL)
939 chip->ops->clk_enable(chip, true);
941 /* reenable interrupts that device may have lost or
942 * BIOS/firmware may have disabled
944 rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), priv->irq);
948 rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
952 intmask |= TPM_INTF_CMD_READY_INT
953 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
954 | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE;
956 tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
959 if (chip->ops->clk_enable != NULL)
960 chip->ops->clk_enable(chip, false);
965 int tpm_tis_resume(struct device *dev)
967 struct tpm_chip *chip = dev_get_drvdata(dev);
970 if (chip->flags & TPM_CHIP_FLAG_IRQ)
971 tpm_tis_reenable_interrupts(chip);
973 ret = tpm_pm_resume(dev);
977 /* TPM 1.2 requires self-test on resume. This function actually returns
978 * an error code but for unknown reason it isn't handled.
980 if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
981 tpm_do_selftest(chip);
985 EXPORT_SYMBOL_GPL(tpm_tis_resume);
988 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
989 MODULE_DESCRIPTION("TPM Driver");
990 MODULE_VERSION("2.0");
991 MODULE_LICENSE("GPL");