blob: 07163a429fdf907f085ff2792176d7b6583e3ff3 [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
72static inline struct tpm_nsc_priv *nsc_get_priv(struct tpm_chip *chip)
73{
74 return chip->vendor.priv;
75}
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/*
78 * Wait for a certain status to appear
79 */
80static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
81{
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070082 unsigned long stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 /* status immediately available check */
Jarkko Sakkinenee177982016-03-23 08:16:09 +020085 *data = inb(nsc_get_priv(chip)->base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if ((*data & mask) == val)
87 return 0;
88
89 /* wait for status */
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070090 stop = jiffies + 10 * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 do {
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070092 msleep(TPM_TIMEOUT);
Jarkko Sakkinenee177982016-03-23 08:16:09 +020093 *data = inb(nsc_get_priv(chip)->base + 1);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070094 if ((*data & mask) == val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -070097 while (time_before(jiffies, stop));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 return -EBUSY;
100}
101
102static int nsc_wait_for_ready(struct tpm_chip *chip)
103{
104 int status;
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700105 unsigned long stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 /* status immediately available check */
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200108 status = inb(nsc_get_priv(chip)->base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (status & NSC_STATUS_OBF)
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200110 status = inb(nsc_get_priv(chip)->base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (status & NSC_STATUS_RDY)
112 return 0;
113
114 /* wait for status */
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700115 stop = jiffies + 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 do {
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700117 msleep(TPM_TIMEOUT);
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200118 status = inb(nsc_get_priv(chip)->base + NSC_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (status & NSC_STATUS_OBF)
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200120 status = inb(nsc_get_priv(chip)->base + NSC_DATA);
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700121 if (status & NSC_STATUS_RDY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
Nishanth Aravamudan700d8bd2005-06-23 22:01:47 -0700124 while (time_before(jiffies, stop));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500126 dev_info(&chip->dev, "wait for ready failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return -EBUSY;
128}
129
130
131static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
132{
133 u8 *buffer = buf;
134 u8 data, *p;
135 u32 size;
136 __be32 *native_size;
137
138 if (count < 6)
139 return -EIO;
140
141 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500142 dev_err(&chip->dev, "F0 timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return -EIO;
144 }
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200145
146 data = inb(nsc_get_priv(chip)->base + NSC_DATA);
147 if (data != NSC_COMMAND_NORMAL) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500148 dev_err(&chip->dev, "not in normal mode (0x%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 data);
150 return -EIO;
151 }
152
153 /* read the whole packet */
154 for (p = buffer; p < &buffer[count]; p++) {
155 if (wait_for_stat
156 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500157 dev_err(&chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 "OBF timeout (while reading data)\n");
159 return -EIO;
160 }
161 if (data & NSC_STATUS_F0)
162 break;
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200163 *p = inb(nsc_get_priv(chip)->base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700166 if ((data & NSC_STATUS_F0) == 0 &&
167 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500168 dev_err(&chip->dev, "F0 not set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return -EIO;
170 }
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200171
172 data = inb(nsc_get_priv(chip)->base + NSC_DATA);
173 if (data != NSC_COMMAND_EOC) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500174 dev_err(&chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 "expected end of command(0x%x)\n", data);
176 return -EIO;
177 }
178
179 native_size = (__force __be32 *) (buf + 2);
180 size = be32_to_cpu(*native_size);
181
182 if (count < size)
183 return -EIO;
184
185 return size;
186}
187
188static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
189{
190 u8 data;
191 int i;
192
193 /*
194 * If we hit the chip with back to back commands it locks up
195 * and never set IBF. Hitting it with this "hammer" seems to
196 * fix it. Not sure why this is needed, we followed the flow
197 * chart in the manual to the letter.
198 */
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200199 outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 if (nsc_wait_for_ready(chip) != 0)
202 return -EIO;
203
204 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500205 dev_err(&chip->dev, "IBF timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return -EIO;
207 }
208
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200209 outb(NSC_COMMAND_NORMAL, nsc_get_priv(chip)->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500211 dev_err(&chip->dev, "IBR timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 return -EIO;
213 }
214
215 for (i = 0; i < count; i++) {
216 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500217 dev_err(&chip->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 "IBF timeout (while writing data)\n");
219 return -EIO;
220 }
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200221 outb(buf[i], nsc_get_priv(chip)->base + NSC_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
224 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
Jason Gunthorpe8cfffc92016-02-29 12:29:47 -0500225 dev_err(&chip->dev, "IBF timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 return -EIO;
227 }
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200228 outb(NSC_COMMAND_EOC, nsc_get_priv(chip)->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 return count;
231}
232
233static void tpm_nsc_cancel(struct tpm_chip *chip)
234{
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200235 outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800238static u8 tpm_nsc_status(struct tpm_chip *chip)
239{
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200240 return inb(nsc_get_priv(chip)->base + NSC_STATUS);
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800241}
242
Stefan Berger1f866052013-01-22 13:52:35 -0600243static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
244{
245 return (status == NSC_STATUS_RDY);
246}
247
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -0700248static const struct tpm_class_ops tpm_nsc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 .recv = tpm_nsc_recv,
250 .send = tpm_nsc_send,
251 .cancel = tpm_nsc_cancel,
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -0800252 .status = tpm_nsc_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 .req_complete_mask = NSC_STATUS_OBF,
254 .req_complete_val = NSC_STATUS_OBF,
Stefan Berger1f866052013-01-22 13:52:35 -0600255 .req_canceled = tpm_nsc_req_canceled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800258static struct platform_device *pdev = NULL;
259
Sam Ravnborg4821cd12008-04-29 01:03:23 -0700260static void tpm_nsc_remove(struct device *dev)
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800261{
262 struct tpm_chip *chip = dev_get_drvdata(dev);
Jarkko Sakkinenafb5abc2014-12-12 11:46:34 -0800263
264 tpm_chip_unregister(chip);
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200265 release_region(nsc_get_priv(chip)->base, 2);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800266}
267
Rafael J. Wysockica9a2052012-07-06 19:09:28 +0200268static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
David Smith09f50c92009-01-07 18:08:57 -0800269
270static struct platform_driver nsc_drv = {
David Smith09f50c92009-01-07 18:08:57 -0800271 .driver = {
272 .name = "tpm_nsc",
Rafael J. Wysockica9a2052012-07-06 19:09:28 +0200273 .pm = &tpm_nsc_pm,
David Smith09f50c92009-01-07 18:08:57 -0800274 },
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800275};
276
277static int __init init_nsc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 int rc = 0;
Jeff Garzikf33d9bd2006-10-11 01:21:51 -0700280 int lo, hi, err;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700281 int nscAddrBase = TPM_ADDR;
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700282 struct tpm_chip *chip;
283 unsigned long base;
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200284 struct tpm_nsc_priv *priv;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* verify that it is a National part (SID) */
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700287 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
288 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
289 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800290 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
291 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293
David Smith09f50c92009-01-07 18:08:57 -0800294 err = platform_driver_register(&nsc_drv);
Jeff Garzikf33d9bd2006-10-11 01:21:51 -0700295 if (err)
296 return err;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800297
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700298 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
299 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700300 base = (hi<<8) | lo;
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700301
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800302 /* enable the DPM module */
303 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
304
David Smith09f50c92009-01-07 18:08:57 -0800305 pdev = platform_device_alloc("tpm_nscl0", -1);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800306 if (!pdev) {
307 rc = -ENOMEM;
308 goto err_unreg_drv;
309 }
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800310
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800311 pdev->num_resources = 0;
David Smith09f50c92009-01-07 18:08:57 -0800312 pdev->dev.driver = &nsc_drv.driver;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800313 pdev->dev.release = tpm_nsc_remove;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800314
Stefan Berger29412f02011-07-22 17:39:20 -0400315 if ((rc = platform_device_add(pdev)) < 0)
316 goto err_put_dev;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800317
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200318 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
319 if (!priv) {
320 rc = -ENOMEM;
321 goto err_del_dev;
322 }
323
324 priv->base = base;
325
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700326 if (request_region(base, 2, "tpm_nsc0") == NULL ) {
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800327 rc = -EBUSY;
Stefan Berger29412f02011-07-22 17:39:20 -0400328 goto err_del_dev;
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800329 }
330
Jarkko Sakkinenafb5abc2014-12-12 11:46:34 -0800331 chip = tpmm_chip_alloc(&pdev->dev, &tpm_nsc);
332 if (IS_ERR(chip)) {
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700333 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
Jarkko Sakkinenee177982016-03-23 08:16:09 +0200337 chip->vendor.priv = priv;
338
Jarkko Sakkinenafb5abc2014-12-12 11:46:34 -0800339 rc = tpm_chip_register(chip);
340 if (rc)
341 goto err_rel_reg;
342
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800343 dev_dbg(&pdev->dev, "NSC TPM detected\n");
344 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700346 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
347 tpm_read_index(nscAddrBase,0x27));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800348 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700350 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
351 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800352 dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700353 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800354 dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700355 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800356 dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700357 tpm_read_index(nscAddrBase,0x70));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800358 dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700359 tpm_read_index(nscAddrBase,0x71));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800360 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 "NSC DMA channel select0 0x%x, select1 0x%x\n",
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700362 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800363 dev_dbg(&pdev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 "NSC Config "
365 "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 -0700366 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
367 tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3),
368 tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5),
369 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
370 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800372 dev_info(&pdev->dev,
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -0700373 "NSC TPM revision %d\n",
374 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return 0;
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800377
378err_rel_reg:
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700379 release_region(base, 2);
Stefan Berger29412f02011-07-22 17:39:20 -0400380err_del_dev:
381 platform_device_del(pdev);
382err_put_dev:
383 platform_device_put(pdev);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800384err_unreg_drv:
David Smith09f50c92009-01-07 18:08:57 -0800385 platform_driver_unregister(&nsc_drv);
Kylene Jo Halle2a8f7a2005-11-07 00:59:25 -0800386 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
389static void __exit cleanup_nsc(void)
390{
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800391 if (pdev) {
392 tpm_nsc_remove(&pdev->dev);
393 platform_device_unregister(pdev);
Kylene Jo Hall570302a2005-10-30 15:03:26 -0800394 }
395
David Smith09f50c92009-01-07 18:08:57 -0800396 platform_driver_unregister(&nsc_drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
399module_init(init_nsc);
400module_exit(cleanup_nsc);
401
402MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
403MODULE_DESCRIPTION("TPM Driver");
404MODULE_VERSION("2.0");
405MODULE_LICENSE("GPL");