2 * Copyright (C) 2004 IBM Corporation
5 * Leendert van Doorn <leendert@watson.ibm.com>
6 * Dave Safford <safford@watson.ibm.com>
7 * Reiner Sailer <sailer@watson.ibm.com>
8 * Kylene Hall <kjhall@us.ibm.com>
10 * Maintained by: <tpmdd_devel@lists.sourceforge.net>
12 * Device driver for TCG/TCPA TPM (trusted platform module).
13 * Specifications at www.trustedcomputinggroup.org
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation, version 2 of the
24 /* Atmel definitions */
29 /* write status bits */
30 enum tpm_atmel_write_status {
31 ATML_STATUS_ABORT = 0x01,
32 ATML_STATUS_LASTBYTE = 0x04
34 /* read status bits */
35 enum tpm_atmel_read_status {
36 ATML_STATUS_BUSY = 0x01,
37 ATML_STATUS_DATA_AVAIL = 0x02,
38 ATML_STATUS_REWRITE = 0x04,
39 ATML_STATUS_READY = 0x08
42 static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
44 u8 status, *hdr = buf;
49 /* start reading header */
53 for (i = 0; i < 6; i++) {
54 status = inb(chip->vendor->base + 1);
55 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
56 dev_err(&chip->pci_dev->dev,
57 "error reading header\n");
60 *buf++ = inb(chip->vendor->base);
63 /* size of the data received */
64 native_size = (__force __be32 *) (hdr + 2);
65 size = be32_to_cpu(*native_size);
68 dev_err(&chip->pci_dev->dev,
69 "Recv size(%d) less than available space\n", size);
70 for (; i < size; i++) { /* clear the waiting data anyway */
71 status = inb(chip->vendor->base + 1);
72 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
73 dev_err(&chip->pci_dev->dev,
74 "error reading data\n");
81 /* read all the data available */
82 for (; i < size; i++) {
83 status = inb(chip->vendor->base + 1);
84 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
85 dev_err(&chip->pci_dev->dev,
86 "error reading data\n");
89 *buf++ = inb(chip->vendor->base);
92 /* make sure data available is gone */
93 status = inb(chip->vendor->base + 1);
94 if (status & ATML_STATUS_DATA_AVAIL) {
95 dev_err(&chip->pci_dev->dev, "data available is stuck\n");
102 static int tpm_atml_send(struct tpm_chip *chip, u8 * buf, size_t count)
106 dev_dbg(&chip->pci_dev->dev, "tpm_atml_send: ");
107 for (i = 0; i < count; i++) {
108 dev_dbg(&chip->pci_dev->dev, "0x%x(%d) ", buf[i], buf[i]);
109 outb(buf[i], chip->vendor->base);
115 static void tpm_atml_cancel(struct tpm_chip *chip)
117 outb(ATML_STATUS_ABORT, chip->vendor->base + 1);
120 static struct file_operations atmel_ops = {
121 .owner = THIS_MODULE,
126 .release = tpm_release,
129 static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
130 static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
131 static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
132 static DEVICE_ATTR(cancel, S_IWUSR |S_IWGRP, NULL, tpm_store_cancel);
134 static struct attribute* atmel_attrs[] = {
135 &dev_attr_pubek.attr,
138 &dev_attr_cancel.attr,
142 static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
144 static struct tpm_vendor_specific tpm_atmel = {
145 .recv = tpm_atml_recv,
146 .send = tpm_atml_send,
147 .cancel = tpm_atml_cancel,
148 .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
149 .req_complete_val = ATML_STATUS_DATA_AVAIL,
150 .req_canceled = ATML_STATUS_READY,
151 .base = TPM_ATML_BASE,
152 .attr_group = &atmel_attr_grp,
153 .miscdev = { .fops = &atmel_ops, },
156 static int __devinit tpm_atml_init(struct pci_dev *pci_dev,
157 const struct pci_device_id *pci_id)
162 if (pci_enable_device(pci_dev))
165 if (tpm_lpc_bus_init(pci_dev, TPM_ATML_BASE)) {
170 /* verify that it is an Atmel part */
171 if (tpm_read_index(4) != 'A' || tpm_read_index(5) != 'T'
172 || tpm_read_index(6) != 'M' || tpm_read_index(7) != 'L') {
177 /* query chip for its version number */
178 if ((version[0] = tpm_read_index(0x00)) != 0xFF) {
179 version[1] = tpm_read_index(0x01);
180 version[2] = tpm_read_index(0x02);
181 version[3] = tpm_read_index(0x03);
183 dev_info(&pci_dev->dev, "version query failed\n");
188 if ((rc = tpm_register_hardware(pci_dev, &tpm_atmel)) < 0)
191 dev_info(&pci_dev->dev,
192 "Atmel TPM version %d.%d.%d.%d\n", version[0], version[1],
193 version[2], version[3]);
197 pci_disable_device(pci_dev);
201 static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
202 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
203 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
204 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
205 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
206 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
207 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
211 MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
213 static struct pci_driver atmel_pci_driver = {
215 .id_table = tpm_pci_tbl,
216 .probe = tpm_atml_init,
217 .remove = __devexit_p(tpm_remove),
218 .suspend = tpm_pm_suspend,
219 .resume = tpm_pm_resume,
222 static int __init init_atmel(void)
224 return pci_register_driver(&atmel_pci_driver);
227 static void __exit cleanup_atmel(void)
229 pci_unregister_driver(&atmel_pci_driver);
232 module_init(init_atmel);
233 module_exit(cleanup_atmel);
235 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
236 MODULE_DESCRIPTION("TPM Driver");
237 MODULE_VERSION("2.0");
238 MODULE_LICENSE("GPL");