blob: 5d6cce74cd3fa3e7f71cf207454dd1e5e492e560 [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};
Jarkko Sakkinenee177982016-03-23 08:16:09 +020067
68struct tpm_nsc_priv {
69 unsigned long base;
70};
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/*
73 * Wait for a certain status to appear
74 */
75static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
76{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +020077 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070078 unsigned long stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 /* status immediately available check */
Christophe Ricard9e0d39d2016-03-31 22:57:00 +020081 *data = inb(priv->base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 if ((*data & mask) == val)
83 return 0;
84
85 /* wait for status */
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070086 stop = jiffies + 10 * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 do {
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070088 msleep(TPM_TIMEOUT);
Christophe Ricard9e0d39d2016-03-31 22:57:00 +020089 *data = inb(priv->base + 1);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070090 if ((*data & mask) == val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070093 while (time_before(jiffies, stop));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 return -EBUSY;
96}
97
98static int nsc_wait_for_ready(struct tpm_chip *chip)
99{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200100 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 int status;
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700102 unsigned long stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 /* status immediately available check */
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200105 status = inb(priv->base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if (status & NSC_STATUS_OBF)
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200107 status = inb(priv->base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (status & NSC_STATUS_RDY)
109 return 0;
110
111 /* wait for status */
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700112 stop = jiffies + 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 do {
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700114 msleep(TPM_TIMEOUT);
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200115 status = inb(priv->base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (status & NSC_STATUS_OBF)
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200117 status = inb(priv->base + NSC_DATA);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700118 if (status & NSC_STATUS_RDY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700121 while (time_before(jiffies, stop));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500123 dev_info(&chip->dev, "wait for ready failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return -EBUSY;
125}
126
127
128static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
129{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200130 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 u8 *buffer = buf;
132 u8 data, *p;
133 u32 size;
134 __be32 *native_size;
135
136 if (count < 6)
137 return -EIO;
138
139 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500140 dev_err(&chip->dev, "F0 timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return -EIO;
142 }
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200143
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200144 data = inb(priv->base + NSC_DATA);
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200145 if (data != NSC_COMMAND_NORMAL) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500146 dev_err(&chip->dev, "not in normal mode (0x%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 data);
148 return -EIO;
149 }
150
151 /* read the whole packet */
152 for (p = buffer; p < &buffer[count]; p++) {
153 if (wait_for_stat
154 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500155 dev_err(&chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 "OBF timeout (while reading data)\n");
157 return -EIO;
158 }
159 if (data & NSC_STATUS_F0)
160 break;
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200161 *p = inb(priv->base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700164 if ((data & NSC_STATUS_F0) == 0 &&
165 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500166 dev_err(&chip->dev, "F0 not set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return -EIO;
168 }
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200169
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200170 data = inb(priv->base + NSC_DATA);
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200171 if (data != NSC_COMMAND_EOC) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500172 dev_err(&chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 "expected end of command(0x%x)\n", data);
174 return -EIO;
175 }
176
177 native_size = (__force __be32 *) (buf + 2);
178 size = be32_to_cpu(*native_size);
179
180 if (count < size)
181 return -EIO;
182
183 return size;
184}
185
186static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
187{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200188 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 u8 data;
190 int i;
191
192 /*
193 * If we hit the chip with back to back commands it locks up
194 * and never set IBF. Hitting it with this "hammer" seems to
195 * fix it. Not sure why this is needed, we followed the flow
196 * chart in the manual to the letter.
197 */
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200198 outb(NSC_COMMAND_CANCEL, priv->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 if (nsc_wait_for_ready(chip) != 0)
201 return -EIO;
202
203 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500204 dev_err(&chip->dev, "IBF timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return -EIO;
206 }
207
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200208 outb(NSC_COMMAND_NORMAL, priv->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500210 dev_err(&chip->dev, "IBR timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return -EIO;
212 }
213
214 for (i = 0; i < count; i++) {
215 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500216 dev_err(&chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 "IBF timeout (while writing data)\n");
218 return -EIO;
219 }
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200220 outb(buf[i], priv->base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
222
223 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500224 dev_err(&chip->dev, "IBF timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return -EIO;
226 }
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200227 outb(NSC_COMMAND_EOC, priv->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 return count;
230}
231
232static void tpm_nsc_cancel(struct tpm_chip *chip)
233{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200234 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
235
236 outb(NSC_COMMAND_CANCEL, priv->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800239static u8 tpm_nsc_status(struct tpm_chip *chip)
240{
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200241 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
242
243 return inb(priv->base + NSC_STATUS);
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800244}
245
Stefan Berger1f866052013-01-22 13:52:35 -0600246static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
247{
248 return (status == NSC_STATUS_RDY);
249}
250
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -0700251static const struct tpm_class_ops tpm_nsc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .recv = tpm_nsc_recv,
253 .send = tpm_nsc_send,
254 .cancel = tpm_nsc_cancel,
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800255 .status = tpm_nsc_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .req_complete_mask = NSC_STATUS_OBF,
257 .req_complete_val = NSC_STATUS_OBF,
Stefan Berger1f866052013-01-22 13:52:35 -0600258 .req_canceled = tpm_nsc_req_canceled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259};
260
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800261static struct platform_device *pdev = NULL;
262
Sam Ravnborg4821cd12008-04-29 01:03:23 -0700263static void tpm_nsc_remove(struct device *dev)
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800264{
265 struct tpm_chip *chip = dev_get_drvdata(dev);
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200266 struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
Jarkko Sakkinenafb5abc2014-12-12 11:46:34 -0800267
268 tpm_chip_unregister(chip);
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200269 release_region(priv->base, 2);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800270}
271
Rafael J. Wysockica9a2052012-07-06 19:09:28 +0200272static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
David Smith09f50c92009-01-07 18:08:57 -0800273
274static struct platform_driver nsc_drv = {
David Smith09f50c92009-01-07 18:08:57 -0800275 .driver = {
276 .name = "tpm_nsc",
Rafael J. Wysockica9a2052012-07-06 19:09:28 +0200277 .pm = &tpm_nsc_pm,
David Smith09f50c92009-01-07 18:08:57 -0800278 },
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800279};
280
Jarkko Sakkinen1d191552017-01-25 16:47:39 +0200281static inline int tpm_read_index(int base, int index)
282{
283 outb(index, base);
284 return inb(base+1) & 0xFF;
285}
286
287static inline void tpm_write_index(int base, int index, int value)
288{
289 outb(index, base);
290 outb(value & 0xFF, base+1);
291}
292
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800293static int __init init_nsc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 int rc = 0;
Jeff Garzikf33d9bd2006-10-11 01:21:51 -0700296 int lo, hi, err;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700297 int nscAddrBase = TPM_ADDR;
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700298 struct tpm_chip *chip;
299 unsigned long base;
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200300 struct tpm_nsc_priv *priv;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 /* verify that it is a National part (SID) */
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700303 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
304 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
305 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800306 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
307 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309
David Smith09f50c92009-01-07 18:08:57 -0800310 err = platform_driver_register(&nsc_drv);
Jeff Garzikf33d9bd2006-10-11 01:21:51 -0700311 if (err)
312 return err;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800313
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700314 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
315 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700316 base = (hi<<8) | lo;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700317
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800318 /* enable the DPM module */
319 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
320
David Smith09f50c92009-01-07 18:08:57 -0800321 pdev = platform_device_alloc("tpm_nscl0", -1);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800322 if (!pdev) {
323 rc = -ENOMEM;
324 goto err_unreg_drv;
325 }
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800326
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800327 pdev->num_resources = 0;
David Smith09f50c92009-01-07 18:08:57 -0800328 pdev->dev.driver = &nsc_drv.driver;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800329 pdev->dev.release = tpm_nsc_remove;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800330
Stefan Berger29412f02011-07-22 17:39:20 -0400331 if ((rc = platform_device_add(pdev)) < 0)
332 goto err_put_dev;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800333
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200334 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
335 if (!priv) {
336 rc = -ENOMEM;
337 goto err_del_dev;
338 }
339
340 priv->base = base;
341
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700342 if (request_region(base, 2, "tpm_nsc0") == NULL ) {
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800343 rc = -EBUSY;
Stefan Berger29412f02011-07-22 17:39:20 -0400344 goto err_del_dev;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800345 }
346
Jarkko Sakkinenafb5abc2014-12-12 11:46:34 -0800347 chip = tpmm_chip_alloc(&pdev->dev, &tpm_nsc);
348 if (IS_ERR(chip)) {
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700349 rc = -ENODEV;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800350 goto err_rel_reg;
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700351 }
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800352
Christophe Ricard9e0d39d2016-03-31 22:57:00 +0200353 dev_set_drvdata(&chip->dev, priv);
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200354
Jarkko Sakkinenafb5abc2014-12-12 11:46:34 -0800355 rc = tpm_chip_register(chip);
356 if (rc)
357 goto err_rel_reg;
358
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800359 dev_dbg(&pdev->dev, "NSC TPM detected\n");
360 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700362 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
363 tpm_read_index(nscAddrBase,0x27));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800364 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700366 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
367 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800368 dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700369 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800370 dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700371 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800372 dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700373 tpm_read_index(nscAddrBase,0x70));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800374 dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700375 tpm_read_index(nscAddrBase,0x71));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800376 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 "NSC DMA channel select0 0x%x, select1 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700378 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800379 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 "NSC Config "
381 "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 -0700382 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
383 tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3),
384 tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5),
385 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
386 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800388 dev_info(&pdev->dev,
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700389 "NSC TPM revision %d\n",
390 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return 0;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800393
394err_rel_reg:
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700395 release_region(base, 2);
Stefan Berger29412f02011-07-22 17:39:20 -0400396err_del_dev:
397 platform_device_del(pdev);
398err_put_dev:
399 platform_device_put(pdev);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800400err_unreg_drv:
David Smith09f50c92009-01-07 18:08:57 -0800401 platform_driver_unregister(&nsc_drv);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800402 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
405static void __exit cleanup_nsc(void)
406{
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800407 if (pdev) {
408 tpm_nsc_remove(&pdev->dev);
409 platform_device_unregister(pdev);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800410 }
411
David Smith09f50c92009-01-07 18:08:57 -0800412 platform_driver_unregister(&nsc_drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415module_init(init_nsc);
416module_exit(cleanup_nsc);
417
418MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
419MODULE_DESCRIPTION("TPM Driver");
420MODULE_VERSION("2.0");
421MODULE_LICENSE("GPL");