xref: /linux/drivers/char/tpm/tpm_nsc.c (revision 6659ca2ab6730c3bbb9fa495f2327b95b955decd)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (C) 2004 IBM Corporation
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Authors:
51da177e4SLinus Torvalds  * Leendert van Doorn <leendert@watson.ibm.com>
61da177e4SLinus Torvalds  * Dave Safford <safford@watson.ibm.com>
71da177e4SLinus Torvalds  * Reiner Sailer <sailer@watson.ibm.com>
81da177e4SLinus Torvalds  * Kylene Hall <kjhall@us.ibm.com>
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * Maintained by: <tpmdd_devel@lists.sourceforge.net>
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * Device driver for TCG/TCPA TPM (trusted platform module).
131da177e4SLinus Torvalds  * Specifications at www.trustedcomputinggroup.org
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
161da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License as
171da177e4SLinus Torvalds  * published by the Free Software Foundation, version 2 of the
181da177e4SLinus Torvalds  * License.
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  */
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #include "tpm.h"
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds /* National definitions */
253122a88aSKylene Hall enum tpm_nsc_addr {
263122a88aSKylene Hall 	TPM_NSC_BASE = 0x360,
273122a88aSKylene Hall 	TPM_NSC_IRQ = 0x07
283122a88aSKylene Hall };
291da177e4SLinus Torvalds 
303122a88aSKylene Hall enum tpm_nsc_index {
313122a88aSKylene Hall 	NSC_LDN_INDEX = 0x07,
323122a88aSKylene Hall 	NSC_SID_INDEX = 0x20,
333122a88aSKylene Hall 	NSC_LDC_INDEX = 0x30,
343122a88aSKylene Hall 	NSC_DIO_INDEX = 0x60,
353122a88aSKylene Hall 	NSC_CIO_INDEX = 0x62,
363122a88aSKylene Hall 	NSC_IRQ_INDEX = 0x70,
373122a88aSKylene Hall 	NSC_ITS_INDEX = 0x71
383122a88aSKylene Hall };
391da177e4SLinus Torvalds 
403122a88aSKylene Hall enum tpm_nsc_status_loc {
413122a88aSKylene Hall 	NSC_STATUS = 0x01,
423122a88aSKylene Hall 	NSC_COMMAND = 0x01,
433122a88aSKylene Hall 	NSC_DATA = 0x00
443122a88aSKylene Hall };
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds /* status bits */
473122a88aSKylene Hall enum tpm_nsc_status{
483122a88aSKylene Hall 	NSC_STATUS_OBF = 0x01,	/* output buffer full */
493122a88aSKylene Hall 	NSC_STATUS_IBF = 0x02,	/* input buffer full */
503122a88aSKylene Hall 	NSC_STATUS_F0 = 0x04,	/* F0 */
513122a88aSKylene Hall 	NSC_STATUS_A2 = 0x08,	/* A2 */
523122a88aSKylene Hall 	NSC_STATUS_RDY = 0x10,	/* ready to receive command */
533122a88aSKylene Hall 	NSC_STATUS_IBR = 0x20	/* ready to receive data */
543122a88aSKylene Hall };
551da177e4SLinus Torvalds /* command bits */
563122a88aSKylene Hall enum tpm_nsc_cmd_mode {
573122a88aSKylene Hall 	NSC_COMMAND_NORMAL = 0x01,	/* normal mode */
583122a88aSKylene Hall 	NSC_COMMAND_EOC = 0x03,
593122a88aSKylene Hall 	NSC_COMMAND_CANCEL = 0x22
603122a88aSKylene Hall };
611da177e4SLinus Torvalds /*
621da177e4SLinus Torvalds  * Wait for a certain status to appear
631da177e4SLinus Torvalds  */
641da177e4SLinus Torvalds static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
651da177e4SLinus Torvalds {
66700d8bdcSNishanth Aravamudan 	unsigned long stop;
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds 	/* status immediately available check */
691da177e4SLinus Torvalds 	*data = inb(chip->vendor->base + NSC_STATUS);
701da177e4SLinus Torvalds 	if ((*data & mask) == val)
711da177e4SLinus Torvalds 		return 0;
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds 	/* wait for status */
74700d8bdcSNishanth Aravamudan 	stop = jiffies + 10 * HZ;
751da177e4SLinus Torvalds 	do {
76700d8bdcSNishanth Aravamudan 		msleep(TPM_TIMEOUT);
771da177e4SLinus Torvalds 		*data = inb(chip->vendor->base + 1);
78700d8bdcSNishanth Aravamudan 		if ((*data & mask) == val)
791da177e4SLinus Torvalds 			return 0;
801da177e4SLinus Torvalds 	}
81700d8bdcSNishanth Aravamudan 	while (time_before(jiffies, stop));
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 	return -EBUSY;
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds static int nsc_wait_for_ready(struct tpm_chip *chip)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds 	int status;
89700d8bdcSNishanth Aravamudan 	unsigned long stop;
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds 	/* status immediately available check */
921da177e4SLinus Torvalds 	status = inb(chip->vendor->base + NSC_STATUS);
931da177e4SLinus Torvalds 	if (status & NSC_STATUS_OBF)
941da177e4SLinus Torvalds 		status = inb(chip->vendor->base + NSC_DATA);
951da177e4SLinus Torvalds 	if (status & NSC_STATUS_RDY)
961da177e4SLinus Torvalds 		return 0;
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds 	/* wait for status */
99700d8bdcSNishanth Aravamudan 	stop = jiffies + 100;
1001da177e4SLinus Torvalds 	do {
101700d8bdcSNishanth Aravamudan 		msleep(TPM_TIMEOUT);
1021da177e4SLinus Torvalds 		status = inb(chip->vendor->base + NSC_STATUS);
1031da177e4SLinus Torvalds 		if (status & NSC_STATUS_OBF)
1041da177e4SLinus Torvalds 			status = inb(chip->vendor->base + NSC_DATA);
105700d8bdcSNishanth Aravamudan 		if (status & NSC_STATUS_RDY)
1061da177e4SLinus Torvalds 			return 0;
1071da177e4SLinus Torvalds 	}
108700d8bdcSNishanth Aravamudan 	while (time_before(jiffies, stop));
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 	dev_info(&chip->pci_dev->dev, "wait for ready failed\n");
1111da177e4SLinus Torvalds 	return -EBUSY;
1121da177e4SLinus Torvalds }
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds 
1151da177e4SLinus Torvalds static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
1161da177e4SLinus Torvalds {
1171da177e4SLinus Torvalds 	u8 *buffer = buf;
1181da177e4SLinus Torvalds 	u8 data, *p;
1191da177e4SLinus Torvalds 	u32 size;
1201da177e4SLinus Torvalds 	__be32 *native_size;
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds 	if (count < 6)
1231da177e4SLinus Torvalds 		return -EIO;
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds 	if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
1261da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev, "F0 timeout\n");
1271da177e4SLinus Torvalds 		return -EIO;
1281da177e4SLinus Torvalds 	}
1291da177e4SLinus Torvalds 	if ((data =
1301da177e4SLinus Torvalds 	     inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
1311da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev, "not in normal mode (0x%x)\n",
1321da177e4SLinus Torvalds 			data);
1331da177e4SLinus Torvalds 		return -EIO;
1341da177e4SLinus Torvalds 	}
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds 	/* read the whole packet */
1371da177e4SLinus Torvalds 	for (p = buffer; p < &buffer[count]; p++) {
1381da177e4SLinus Torvalds 		if (wait_for_stat
1391da177e4SLinus Torvalds 		    (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
1401da177e4SLinus Torvalds 			dev_err(&chip->pci_dev->dev,
1411da177e4SLinus Torvalds 				"OBF timeout (while reading data)\n");
1421da177e4SLinus Torvalds 			return -EIO;
1431da177e4SLinus Torvalds 		}
1441da177e4SLinus Torvalds 		if (data & NSC_STATUS_F0)
1451da177e4SLinus Torvalds 			break;
1461da177e4SLinus Torvalds 		*p = inb(chip->vendor->base + NSC_DATA);
1471da177e4SLinus Torvalds 	}
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds 	if ((data & NSC_STATUS_F0) == 0) {
1501da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev, "F0 not set\n");
1511da177e4SLinus Torvalds 		return -EIO;
1521da177e4SLinus Torvalds 	}
1531da177e4SLinus Torvalds 	if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) {
1541da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev,
1551da177e4SLinus Torvalds 			"expected end of command(0x%x)\n", data);
1561da177e4SLinus Torvalds 		return -EIO;
1571da177e4SLinus Torvalds 	}
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds 	native_size = (__force __be32 *) (buf + 2);
1601da177e4SLinus Torvalds 	size = be32_to_cpu(*native_size);
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds 	if (count < size)
1631da177e4SLinus Torvalds 		return -EIO;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	return size;
1661da177e4SLinus Torvalds }
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
1691da177e4SLinus Torvalds {
1701da177e4SLinus Torvalds 	u8 data;
1711da177e4SLinus Torvalds 	int i;
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds 	/*
1741da177e4SLinus Torvalds 	 * If we hit the chip with back to back commands it locks up
1751da177e4SLinus Torvalds 	 * and never set IBF. Hitting it with this "hammer" seems to
1761da177e4SLinus Torvalds 	 * fix it. Not sure why this is needed, we followed the flow
1771da177e4SLinus Torvalds 	 * chart in the manual to the letter.
1781da177e4SLinus Torvalds 	 */
1791da177e4SLinus Torvalds 	outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND);
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds 	if (nsc_wait_for_ready(chip) != 0)
1821da177e4SLinus Torvalds 		return -EIO;
1831da177e4SLinus Torvalds 
1841da177e4SLinus Torvalds 	if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
1851da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev, "IBF timeout\n");
1861da177e4SLinus Torvalds 		return -EIO;
1871da177e4SLinus Torvalds 	}
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds 	outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND);
1901da177e4SLinus Torvalds 	if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
1911da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev, "IBR timeout\n");
1921da177e4SLinus Torvalds 		return -EIO;
1931da177e4SLinus Torvalds 	}
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds 	for (i = 0; i < count; i++) {
1961da177e4SLinus Torvalds 		if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
1971da177e4SLinus Torvalds 			dev_err(&chip->pci_dev->dev,
1981da177e4SLinus Torvalds 				"IBF timeout (while writing data)\n");
1991da177e4SLinus Torvalds 			return -EIO;
2001da177e4SLinus Torvalds 		}
2011da177e4SLinus Torvalds 		outb(buf[i], chip->vendor->base + NSC_DATA);
2021da177e4SLinus Torvalds 	}
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds 	if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
2051da177e4SLinus Torvalds 		dev_err(&chip->pci_dev->dev, "IBF timeout\n");
2061da177e4SLinus Torvalds 		return -EIO;
2071da177e4SLinus Torvalds 	}
2081da177e4SLinus Torvalds 	outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND);
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 	return count;
2111da177e4SLinus Torvalds }
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds static void tpm_nsc_cancel(struct tpm_chip *chip)
2141da177e4SLinus Torvalds {
2151da177e4SLinus Torvalds 	outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND);
2161da177e4SLinus Torvalds }
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds static struct file_operations nsc_ops = {
2191da177e4SLinus Torvalds 	.owner = THIS_MODULE,
2201da177e4SLinus Torvalds 	.llseek = no_llseek,
2211da177e4SLinus Torvalds 	.open = tpm_open,
2221da177e4SLinus Torvalds 	.read = tpm_read,
2231da177e4SLinus Torvalds 	.write = tpm_write,
2241da177e4SLinus Torvalds 	.release = tpm_release,
2251da177e4SLinus Torvalds };
2261da177e4SLinus Torvalds 
227*6659ca2aSKylene Hall static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
228*6659ca2aSKylene Hall static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
229*6659ca2aSKylene Hall static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
230*6659ca2aSKylene Hall static DEVICE_ATTR(cancel, S_IWUSR|S_IWGRP, NULL, tpm_store_cancel);
231*6659ca2aSKylene Hall 
232*6659ca2aSKylene Hall static struct attribute * nsc_attrs[] = {
233*6659ca2aSKylene Hall 	&dev_attr_pubek.attr,
234*6659ca2aSKylene Hall 	&dev_attr_pcrs.attr,
235*6659ca2aSKylene Hall 	&dev_attr_caps.attr,
236*6659ca2aSKylene Hall 	&dev_attr_cancel.attr,
237*6659ca2aSKylene Hall 	0,
238*6659ca2aSKylene Hall };
239*6659ca2aSKylene Hall 
240*6659ca2aSKylene Hall static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs };
241*6659ca2aSKylene Hall 
2421da177e4SLinus Torvalds static struct tpm_vendor_specific tpm_nsc = {
2431da177e4SLinus Torvalds 	.recv = tpm_nsc_recv,
2441da177e4SLinus Torvalds 	.send = tpm_nsc_send,
2451da177e4SLinus Torvalds 	.cancel = tpm_nsc_cancel,
2461da177e4SLinus Torvalds 	.req_complete_mask = NSC_STATUS_OBF,
2471da177e4SLinus Torvalds 	.req_complete_val = NSC_STATUS_OBF,
2481da177e4SLinus Torvalds 	.base = TPM_NSC_BASE,
249*6659ca2aSKylene Hall 	.attr_group = &nsc_attr_grp,
2501da177e4SLinus Torvalds 	.miscdev = { .fops = &nsc_ops, },
2511da177e4SLinus Torvalds };
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
2541da177e4SLinus Torvalds 				  const struct pci_device_id *pci_id)
2551da177e4SLinus Torvalds {
2561da177e4SLinus Torvalds 	int rc = 0;
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds 	if (pci_enable_device(pci_dev))
2591da177e4SLinus Torvalds 		return -EIO;
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds 	if (tpm_lpc_bus_init(pci_dev, TPM_NSC_BASE)) {
2621da177e4SLinus Torvalds 		rc = -ENODEV;
2631da177e4SLinus Torvalds 		goto out_err;
2641da177e4SLinus Torvalds 	}
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds 	/* verify that it is a National part (SID) */
2671da177e4SLinus Torvalds 	if (tpm_read_index(NSC_SID_INDEX) != 0xEF) {
2681da177e4SLinus Torvalds 		rc = -ENODEV;
2691da177e4SLinus Torvalds 		goto out_err;
2701da177e4SLinus Torvalds 	}
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev, "NSC TPM detected\n");
2731da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev,
2741da177e4SLinus Torvalds 		"NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
2751da177e4SLinus Torvalds 		tpm_read_index(0x07), tpm_read_index(0x20),
2761da177e4SLinus Torvalds 		tpm_read_index(0x27));
2771da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev,
2781da177e4SLinus Torvalds 		"NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
2791da177e4SLinus Torvalds 		tpm_read_index(0x21), tpm_read_index(0x25),
2801da177e4SLinus Torvalds 		tpm_read_index(0x26), tpm_read_index(0x28));
2811da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev, "NSC IO Base0 0x%x\n",
2821da177e4SLinus Torvalds 		(tpm_read_index(0x60) << 8) | tpm_read_index(0x61));
2831da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev, "NSC IO Base1 0x%x\n",
2841da177e4SLinus Torvalds 		(tpm_read_index(0x62) << 8) | tpm_read_index(0x63));
2851da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev, "NSC Interrupt number and wakeup 0x%x\n",
2861da177e4SLinus Torvalds 		tpm_read_index(0x70));
2871da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev, "NSC IRQ type select 0x%x\n",
2881da177e4SLinus Torvalds 		tpm_read_index(0x71));
2891da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev,
2901da177e4SLinus Torvalds 		"NSC DMA channel select0 0x%x, select1 0x%x\n",
2911da177e4SLinus Torvalds 		tpm_read_index(0x74), tpm_read_index(0x75));
2921da177e4SLinus Torvalds 	dev_dbg(&pci_dev->dev,
2931da177e4SLinus Torvalds 		"NSC Config "
2941da177e4SLinus Torvalds 		"0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
2951da177e4SLinus Torvalds 		tpm_read_index(0xF0), tpm_read_index(0xF1),
2961da177e4SLinus Torvalds 		tpm_read_index(0xF2), tpm_read_index(0xF3),
2971da177e4SLinus Torvalds 		tpm_read_index(0xF4), tpm_read_index(0xF5),
2981da177e4SLinus Torvalds 		tpm_read_index(0xF6), tpm_read_index(0xF7),
2991da177e4SLinus Torvalds 		tpm_read_index(0xF8), tpm_read_index(0xF9));
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds 	dev_info(&pci_dev->dev,
3021da177e4SLinus Torvalds 		 "NSC PC21100 TPM revision %d\n",
3031da177e4SLinus Torvalds 		 tpm_read_index(0x27) & 0x1F);
3041da177e4SLinus Torvalds 
3051da177e4SLinus Torvalds 	if (tpm_read_index(NSC_LDC_INDEX) == 0)
3061da177e4SLinus Torvalds 		dev_info(&pci_dev->dev, ": NSC TPM not active\n");
3071da177e4SLinus Torvalds 
3081da177e4SLinus Torvalds 	/* select PM channel 1 */
3091da177e4SLinus Torvalds 	tpm_write_index(NSC_LDN_INDEX, 0x12);
3101da177e4SLinus Torvalds 	tpm_read_index(NSC_LDN_INDEX);
3111da177e4SLinus Torvalds 
3121da177e4SLinus Torvalds 	/* disable the DPM module */
3131da177e4SLinus Torvalds 	tpm_write_index(NSC_LDC_INDEX, 0);
3141da177e4SLinus Torvalds 	tpm_read_index(NSC_LDC_INDEX);
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds 	/* set the data register base addresses */
3171da177e4SLinus Torvalds 	tpm_write_index(NSC_DIO_INDEX, TPM_NSC_BASE >> 8);
3181da177e4SLinus Torvalds 	tpm_write_index(NSC_DIO_INDEX + 1, TPM_NSC_BASE);
3191da177e4SLinus Torvalds 	tpm_read_index(NSC_DIO_INDEX);
3201da177e4SLinus Torvalds 	tpm_read_index(NSC_DIO_INDEX + 1);
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds 	/* set the command register base addresses */
3231da177e4SLinus Torvalds 	tpm_write_index(NSC_CIO_INDEX, (TPM_NSC_BASE + 1) >> 8);
3241da177e4SLinus Torvalds 	tpm_write_index(NSC_CIO_INDEX + 1, (TPM_NSC_BASE + 1));
3251da177e4SLinus Torvalds 	tpm_read_index(NSC_DIO_INDEX);
3261da177e4SLinus Torvalds 	tpm_read_index(NSC_DIO_INDEX + 1);
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds 	/* set the interrupt number to be used for the host interface */
3291da177e4SLinus Torvalds 	tpm_write_index(NSC_IRQ_INDEX, TPM_NSC_IRQ);
3301da177e4SLinus Torvalds 	tpm_write_index(NSC_ITS_INDEX, 0x00);
3311da177e4SLinus Torvalds 	tpm_read_index(NSC_IRQ_INDEX);
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds 	/* enable the DPM module */
3341da177e4SLinus Torvalds 	tpm_write_index(NSC_LDC_INDEX, 0x01);
3351da177e4SLinus Torvalds 	tpm_read_index(NSC_LDC_INDEX);
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds 	if ((rc = tpm_register_hardware(pci_dev, &tpm_nsc)) < 0)
3381da177e4SLinus Torvalds 		goto out_err;
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds 	return 0;
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds out_err:
3431da177e4SLinus Torvalds 	pci_disable_device(pci_dev);
3441da177e4SLinus Torvalds 	return rc;
3451da177e4SLinus Torvalds }
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
3481da177e4SLinus Torvalds 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
3491da177e4SLinus Torvalds 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
3501da177e4SLinus Torvalds 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
3511da177e4SLinus Torvalds 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
3521da177e4SLinus Torvalds 	{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
3531da177e4SLinus Torvalds 	{PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
3541da177e4SLinus Torvalds 	{0,}
3551da177e4SLinus Torvalds };
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
3581da177e4SLinus Torvalds 
3591da177e4SLinus Torvalds static struct pci_driver nsc_pci_driver = {
3601da177e4SLinus Torvalds 	.name = "tpm_nsc",
3611da177e4SLinus Torvalds 	.id_table = tpm_pci_tbl,
3621da177e4SLinus Torvalds 	.probe = tpm_nsc_init,
3631da177e4SLinus Torvalds 	.remove = __devexit_p(tpm_remove),
3641da177e4SLinus Torvalds 	.suspend = tpm_pm_suspend,
3651da177e4SLinus Torvalds 	.resume = tpm_pm_resume,
3661da177e4SLinus Torvalds };
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds static int __init init_nsc(void)
3691da177e4SLinus Torvalds {
3701da177e4SLinus Torvalds 	return pci_register_driver(&nsc_pci_driver);
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds static void __exit cleanup_nsc(void)
3741da177e4SLinus Torvalds {
3751da177e4SLinus Torvalds 	pci_unregister_driver(&nsc_pci_driver);
3761da177e4SLinus Torvalds }
3771da177e4SLinus Torvalds 
3781da177e4SLinus Torvalds module_init(init_nsc);
3791da177e4SLinus Torvalds module_exit(cleanup_nsc);
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
3821da177e4SLinus Torvalds MODULE_DESCRIPTION("TPM Driver");
3831da177e4SLinus Torvalds MODULE_VERSION("2.0");
3841da177e4SLinus Torvalds MODULE_LICENSE("GPL");
385