blob: 640c9a427b59b1f788a6541e4d81e88e9f9f9f42 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2004 IBM Corporation
3 *
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>
9 *
Kent Yoder8e81cc12007-08-22 14:01:04 -070010 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * Device driver for TCG/TCPA TPM (trusted platform module).
13 * Specifications at www.trustedcomputinggroup.org
14 *
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.
19 *
20 */
21
Chris Wrightfaba2782005-10-31 23:44:28 -080022#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "tpm.h"
25
26/* National definitions */
Kylene Halle1a23c62005-06-23 22:02:06 -070027enum tpm_nsc_addr{
Kylene Halle1a23c62005-06-23 22:02:06 -070028 TPM_NSC_IRQ = 0x07,
29 TPM_NSC_BASE0_HI = 0x60,
30 TPM_NSC_BASE0_LO = 0x61,
31 TPM_NSC_BASE1_HI = 0x62,
32 TPM_NSC_BASE1_LO = 0x63
Kylene Hall3122a882005-06-23 22:01:48 -070033};
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Kylene Hall3122a882005-06-23 22:01:48 -070035enum tpm_nsc_index {
36 NSC_LDN_INDEX = 0x07,
37 NSC_SID_INDEX = 0x20,
38 NSC_LDC_INDEX = 0x30,
39 NSC_DIO_INDEX = 0x60,
40 NSC_CIO_INDEX = 0x62,
41 NSC_IRQ_INDEX = 0x70,
42 NSC_ITS_INDEX = 0x71
43};
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Kylene Hall3122a882005-06-23 22:01:48 -070045enum tpm_nsc_status_loc {
46 NSC_STATUS = 0x01,
47 NSC_COMMAND = 0x01,
48 NSC_DATA = 0x00
49};
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/* status bits */
Kylene Halle1a23c62005-06-23 22:02:06 -070052enum tpm_nsc_status {
Kylene Hall3122a882005-06-23 22:01:48 -070053 NSC_STATUS_OBF = 0x01, /* output buffer full */
54 NSC_STATUS_IBF = 0x02, /* input buffer full */
55 NSC_STATUS_F0 = 0x04, /* F0 */
56 NSC_STATUS_A2 = 0x08, /* A2 */
57 NSC_STATUS_RDY = 0x10, /* ready to receive command */
58 NSC_STATUS_IBR = 0x20 /* ready to receive data */
59};
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/* command bits */
Kylene Hall3122a882005-06-23 22:01:48 -070062enum tpm_nsc_cmd_mode {
63 NSC_COMMAND_NORMAL = 0x01, /* normal mode */
64 NSC_COMMAND_EOC = 0x03,
65 NSC_COMMAND_CANCEL = 0x22
66};
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/*
68 * Wait for a certain status to appear
69 */
70static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
71{
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070072 unsigned long stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 /* status immediately available check */
Kylene Jo Hall90dda522006-04-22 02:37:15 -070075 *data = inb(chip->vendor.base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 if ((*data & mask) == val)
77 return 0;
78
79 /* wait for status */
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070080 stop = jiffies + 10 * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 do {
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070082 msleep(TPM_TIMEOUT);
Kylene Jo Hall90dda522006-04-22 02:37:15 -070083 *data = inb(chip->vendor.base + 1);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070084 if ((*data & mask) == val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070087 while (time_before(jiffies, stop));
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 return -EBUSY;
90}
91
92static int nsc_wait_for_ready(struct tpm_chip *chip)
93{
94 int status;
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070095 unsigned long stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 /* status immediately available check */
Kylene Jo Hall90dda522006-04-22 02:37:15 -070098 status = inb(chip->vendor.base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (status & NSC_STATUS_OBF)
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700100 status = inb(chip->vendor.base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 if (status & NSC_STATUS_RDY)
102 return 0;
103
104 /* wait for status */
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700105 stop = jiffies + 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 do {
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700107 msleep(TPM_TIMEOUT);
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700108 status = inb(chip->vendor.base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (status & NSC_STATUS_OBF)
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700110 status = inb(chip->vendor.base + NSC_DATA);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700111 if (status & NSC_STATUS_RDY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700114 while (time_before(jiffies, stop));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800116 dev_info(chip->dev, "wait for ready failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return -EBUSY;
118}
119
120
121static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
122{
123 u8 *buffer = buf;
124 u8 data, *p;
125 u32 size;
126 __be32 *native_size;
127
128 if (count < 6)
129 return -EIO;
130
131 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800132 dev_err(chip->dev, "F0 timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return -EIO;
134 }
135 if ((data =
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700136 inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800137 dev_err(chip->dev, "not in normal mode (0x%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 data);
139 return -EIO;
140 }
141
142 /* read the whole packet */
143 for (p = buffer; p < &buffer[count]; p++) {
144 if (wait_for_stat
145 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800146 dev_err(chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 "OBF timeout (while reading data)\n");
148 return -EIO;
149 }
150 if (data & NSC_STATUS_F0)
151 break;
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700152 *p = inb(chip->vendor.base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700155 if ((data & NSC_STATUS_F0) == 0 &&
156 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800157 dev_err(chip->dev, "F0 not set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return -EIO;
159 }
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700160 if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800161 dev_err(chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 "expected end of command(0x%x)\n", data);
163 return -EIO;
164 }
165
166 native_size = (__force __be32 *) (buf + 2);
167 size = be32_to_cpu(*native_size);
168
169 if (count < size)
170 return -EIO;
171
172 return size;
173}
174
175static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
176{
177 u8 data;
178 int i;
179
180 /*
181 * If we hit the chip with back to back commands it locks up
182 * and never set IBF. Hitting it with this "hammer" seems to
183 * fix it. Not sure why this is needed, we followed the flow
184 * chart in the manual to the letter.
185 */
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700186 outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 if (nsc_wait_for_ready(chip) != 0)
189 return -EIO;
190
191 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800192 dev_err(chip->dev, "IBF timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return -EIO;
194 }
195
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700196 outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800198 dev_err(chip->dev, "IBR timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return -EIO;
200 }
201
202 for (i = 0; i < count; i++) {
203 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800204 dev_err(chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 "IBF timeout (while writing data)\n");
206 return -EIO;
207 }
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700208 outb(buf[i], chip->vendor.base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210
211 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800212 dev_err(chip->dev, "IBF timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return -EIO;
214 }
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700215 outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 return count;
218}
219
220static void tpm_nsc_cancel(struct tpm_chip *chip)
221{
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700222 outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800225static u8 tpm_nsc_status(struct tpm_chip *chip)
226{
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700227 return inb(chip->vendor.base + NSC_STATUS);
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800228}
229
Arjan van de Ven62322d22006-07-03 00:24:21 -0700230static const struct file_operations nsc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 .owner = THIS_MODULE,
232 .llseek = no_llseek,
233 .open = tpm_open,
234 .read = tpm_read,
235 .write = tpm_write,
236 .release = tpm_release,
237};
238
Kylene Hall6659ca22005-06-23 22:02:00 -0700239static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
240static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
241static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
242static DEVICE_ATTR(cancel, S_IWUSR|S_IWGRP, NULL, tpm_store_cancel);
243
244static struct attribute * nsc_attrs[] = {
245 &dev_attr_pubek.attr,
246 &dev_attr_pcrs.attr,
247 &dev_attr_caps.attr,
248 &dev_attr_cancel.attr,
Randy Dunlap874ec332005-10-30 15:03:29 -0800249 NULL,
Kylene Hall6659ca22005-06-23 22:02:00 -0700250};
251
252static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs };
253
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700254static const struct tpm_vendor_specific tpm_nsc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .recv = tpm_nsc_recv,
256 .send = tpm_nsc_send,
257 .cancel = tpm_nsc_cancel,
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800258 .status = tpm_nsc_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 .req_complete_mask = NSC_STATUS_OBF,
260 .req_complete_val = NSC_STATUS_OBF,
Kylene Halld9e5b6b2005-06-23 22:02:02 -0700261 .req_canceled = NSC_STATUS_RDY,
Kylene Hall6659ca22005-06-23 22:02:00 -0700262 .attr_group = &nsc_attr_grp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 .miscdev = { .fops = &nsc_ops, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264};
265
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800266static struct platform_device *pdev = NULL;
267
Sam Ravnborg4821cd12008-04-29 01:03:23 -0700268static void tpm_nsc_remove(struct device *dev)
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800269{
270 struct tpm_chip *chip = dev_get_drvdata(dev);
271 if ( chip ) {
Kylene Jo Hall90dda522006-04-22 02:37:15 -0700272 release_region(chip->vendor.base, 2);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800273 tpm_remove_hardware(chip->dev);
274 }
275}
276
Rafael J. Wysockica9a2052012-07-06 19:09:28 +0200277static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
David Smith09f50c92009-01-07 18:08:57 -0800278
279static struct platform_driver nsc_drv = {
David Smith09f50c92009-01-07 18:08:57 -0800280 .driver = {
281 .name = "tpm_nsc",
282 .owner = THIS_MODULE,
Rafael J. Wysockica9a2052012-07-06 19:09:28 +0200283 .pm = &tpm_nsc_pm,
David Smith09f50c92009-01-07 18:08:57 -0800284 },
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800285};
286
287static int __init init_nsc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 int rc = 0;
Jeff Garzikf33d9bd2006-10-11 01:21:51 -0700290 int lo, hi, err;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700291 int nscAddrBase = TPM_ADDR;
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700292 struct tpm_chip *chip;
293 unsigned long base;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /* verify that it is a National part (SID) */
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700296 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
297 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
298 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800299 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
300 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
302
David Smith09f50c92009-01-07 18:08:57 -0800303 err = platform_driver_register(&nsc_drv);
Jeff Garzikf33d9bd2006-10-11 01:21:51 -0700304 if (err)
305 return err;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800306
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700307 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
308 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700309 base = (hi<<8) | lo;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700310
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800311 /* enable the DPM module */
312 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
313
David Smith09f50c92009-01-07 18:08:57 -0800314 pdev = platform_device_alloc("tpm_nscl0", -1);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800315 if (!pdev) {
316 rc = -ENOMEM;
317 goto err_unreg_drv;
318 }
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800319
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800320 pdev->num_resources = 0;
David Smith09f50c92009-01-07 18:08:57 -0800321 pdev->dev.driver = &nsc_drv.driver;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800322 pdev->dev.release = tpm_nsc_remove;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800323
Stefan Berger29412f02011-07-22 17:39:20 -0400324 if ((rc = platform_device_add(pdev)) < 0)
325 goto err_put_dev;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800326
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700327 if (request_region(base, 2, "tpm_nsc0") == NULL ) {
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800328 rc = -EBUSY;
Stefan Berger29412f02011-07-22 17:39:20 -0400329 goto err_del_dev;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800330 }
331
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700332 if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_nsc))) {
333 rc = -ENODEV;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800334 goto err_rel_reg;
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700335 }
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800336
337 dev_dbg(&pdev->dev, "NSC TPM detected\n");
338 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700340 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
341 tpm_read_index(nscAddrBase,0x27));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800342 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700344 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
345 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800346 dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700347 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800348 dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700349 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800350 dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700351 tpm_read_index(nscAddrBase,0x70));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800352 dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700353 tpm_read_index(nscAddrBase,0x71));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800354 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 "NSC DMA channel select0 0x%x, select1 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700356 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800357 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 "NSC Config "
359 "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700360 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
361 tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3),
362 tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5),
363 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
364 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800366 dev_info(&pdev->dev,
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700367 "NSC TPM revision %d\n",
368 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700370 chip->vendor.base = base;
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return 0;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800373
374err_rel_reg:
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700375 release_region(base, 2);
Stefan Berger29412f02011-07-22 17:39:20 -0400376err_del_dev:
377 platform_device_del(pdev);
378err_put_dev:
379 platform_device_put(pdev);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800380err_unreg_drv:
David Smith09f50c92009-01-07 18:08:57 -0800381 platform_driver_unregister(&nsc_drv);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800382 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
385static void __exit cleanup_nsc(void)
386{
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800387 if (pdev) {
388 tpm_nsc_remove(&pdev->dev);
389 platform_device_unregister(pdev);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800390 }
391
David Smith09f50c92009-01-07 18:08:57 -0800392 platform_driver_unregister(&nsc_drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
395module_init(init_nsc);
396module_exit(cleanup_nsc);
397
398MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
399MODULE_DESCRIPTION("TPM Driver");
400MODULE_VERSION("2.0");
401MODULE_LICENSE("GPL");