[PATCH] aic7xxx_osm build fix
[cris-mirror.git] / drivers / char / tpm / tpm_atmel.c
blobf9333e729b623308618606222f673ba0b8897074
1 /*
2 * Copyright (C) 2004 IBM Corporation
4 * Authors:
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
18 * License.
22 #include "tpm.h"
24 /* Atmel definitions */
25 #define TPM_ATML_BASE 0x400
27 /* write status bits */
28 #define ATML_STATUS_ABORT 0x01
29 #define ATML_STATUS_LASTBYTE 0x04
31 /* read status bits */
32 #define ATML_STATUS_BUSY 0x01
33 #define ATML_STATUS_DATA_AVAIL 0x02
34 #define ATML_STATUS_REWRITE 0x04
37 static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
39 u8 status, *hdr = buf;
40 u32 size;
41 int i;
42 __be32 *native_size;
44 /* start reading header */
45 if (count < 6)
46 return -EIO;
48 for (i = 0; i < 6; i++) {
49 status = inb(chip->vendor->base + 1);
50 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
51 dev_err(&chip->pci_dev->dev,
52 "error reading header\n");
53 return -EIO;
55 *buf++ = inb(chip->vendor->base);
58 /* size of the data received */
59 native_size = (__force __be32 *) (hdr + 2);
60 size = be32_to_cpu(*native_size);
62 if (count < size) {
63 dev_err(&chip->pci_dev->dev,
64 "Recv size(%d) less than available space\n", size);
65 for (; i < size; i++) { /* clear the waiting data anyway */
66 status = inb(chip->vendor->base + 1);
67 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
68 dev_err(&chip->pci_dev->dev,
69 "error reading data\n");
70 return -EIO;
73 return -EIO;
76 /* read all the data available */
77 for (; i < size; i++) {
78 status = inb(chip->vendor->base + 1);
79 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
80 dev_err(&chip->pci_dev->dev,
81 "error reading data\n");
82 return -EIO;
84 *buf++ = inb(chip->vendor->base);
87 /* make sure data available is gone */
88 status = inb(chip->vendor->base + 1);
89 if (status & ATML_STATUS_DATA_AVAIL) {
90 dev_err(&chip->pci_dev->dev, "data available is stuck\n");
91 return -EIO;
94 return size;
97 static int tpm_atml_send(struct tpm_chip *chip, u8 * buf, size_t count)
99 int i;
101 dev_dbg(&chip->pci_dev->dev, "tpm_atml_send: ");
102 for (i = 0; i < count; i++) {
103 dev_dbg(&chip->pci_dev->dev, "0x%x(%d) ", buf[i], buf[i]);
104 outb(buf[i], chip->vendor->base);
107 return count;
110 static void tpm_atml_cancel(struct tpm_chip *chip)
112 outb(ATML_STATUS_ABORT, chip->vendor->base + 1);
115 static struct file_operations atmel_ops = {
116 .owner = THIS_MODULE,
117 .llseek = no_llseek,
118 .open = tpm_open,
119 .read = tpm_read,
120 .write = tpm_write,
121 .release = tpm_release,
124 static struct tpm_vendor_specific tpm_atmel = {
125 .recv = tpm_atml_recv,
126 .send = tpm_atml_send,
127 .cancel = tpm_atml_cancel,
128 .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
129 .req_complete_val = ATML_STATUS_DATA_AVAIL,
130 .base = TPM_ATML_BASE,
131 .miscdev = { .fops = &atmel_ops, },
134 static int __devinit tpm_atml_init(struct pci_dev *pci_dev,
135 const struct pci_device_id *pci_id)
137 u8 version[4];
138 int rc = 0;
140 if (pci_enable_device(pci_dev))
141 return -EIO;
143 if (tpm_lpc_bus_init(pci_dev, TPM_ATML_BASE)) {
144 rc = -ENODEV;
145 goto out_err;
148 /* verify that it is an Atmel part */
149 if (tpm_read_index(4) != 'A' || tpm_read_index(5) != 'T'
150 || tpm_read_index(6) != 'M' || tpm_read_index(7) != 'L') {
151 rc = -ENODEV;
152 goto out_err;
155 /* query chip for its version number */
156 if ((version[0] = tpm_read_index(0x00)) != 0xFF) {
157 version[1] = tpm_read_index(0x01);
158 version[2] = tpm_read_index(0x02);
159 version[3] = tpm_read_index(0x03);
160 } else {
161 dev_info(&pci_dev->dev, "version query failed\n");
162 rc = -ENODEV;
163 goto out_err;
166 if ((rc = tpm_register_hardware(pci_dev, &tpm_atmel)) < 0)
167 goto out_err;
169 dev_info(&pci_dev->dev,
170 "Atmel TPM version %d.%d.%d.%d\n", version[0], version[1],
171 version[2], version[3]);
173 return 0;
174 out_err:
175 pci_disable_device(pci_dev);
176 return rc;
179 static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
180 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
181 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
182 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
183 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
184 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
185 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
186 {0,}
189 MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
191 static struct pci_driver atmel_pci_driver = {
192 .name = "tpm_atmel",
193 .id_table = tpm_pci_tbl,
194 .probe = tpm_atml_init,
195 .remove = __devexit_p(tpm_remove),
196 .suspend = tpm_pm_suspend,
197 .resume = tpm_pm_resume,
200 static int __init init_atmel(void)
202 return pci_register_driver(&atmel_pci_driver);
205 static void __exit cleanup_atmel(void)
207 pci_unregister_driver(&atmel_pci_driver);
210 module_init(init_atmel);
211 module_exit(cleanup_atmel);
213 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
214 MODULE_DESCRIPTION("TPM Driver");
215 MODULE_VERSION("2.0");
216 MODULE_LICENSE("GPL");