blob: 4519cb332987bc1ac840f9d8ac26cac4be3b964b [file] [log] [blame]
Leendert van Doorn27084ef2006-04-22 02:38:03 -07001/*
2 * Copyright (C) 2005, 2006 IBM Corporation
3 *
4 * Authors:
5 * Leendert van Doorn <leendert@watson.ibm.com>
6 * Kylene Hall <kjhall@us.ibm.com>
7 *
Kent Yoder8e81cc12007-08-22 14:01:04 -07008 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
9 *
Leendert van Doorn27084ef2006-04-22 02:38:03 -070010 * Device driver for TCG/TCPA TPM (trusted platform module).
11 * Specifications at www.trustedcomputinggroup.org
12 *
13 * This device driver implements the TPM interface as defined in
14 * the TCG TPM Interface Spec version 1.2, revision 1.0.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation, version 2 of the
19 * License.
20 */
Kylene Jo Hall57135562006-04-22 02:39:44 -070021#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/moduleparam.h>
Leendert van Doorn27084ef2006-04-22 02:38:03 -070024#include <linux/pnp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Leendert van Doorn27084ef2006-04-22 02:38:03 -070026#include <linux/interrupt.h>
27#include <linux/wait.h>
Matthew Garrett3f0d3d02010-10-21 17:42:40 -040028#include <linux/acpi.h>
Stefan Berger20b87bb2011-03-30 12:13:31 -040029#include <linux/freezer.h>
Leendert van Doorn27084ef2006-04-22 02:38:03 -070030#include "tpm.h"
31
Leendert van Doorn27084ef2006-04-22 02:38:03 -070032enum tis_access {
33 TPM_ACCESS_VALID = 0x80,
34 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
35 TPM_ACCESS_REQUEST_PENDING = 0x04,
36 TPM_ACCESS_REQUEST_USE = 0x02,
37};
38
39enum tis_status {
40 TPM_STS_VALID = 0x80,
41 TPM_STS_COMMAND_READY = 0x40,
42 TPM_STS_GO = 0x20,
43 TPM_STS_DATA_AVAIL = 0x10,
44 TPM_STS_DATA_EXPECT = 0x08,
45};
46
47enum tis_int_flags {
48 TPM_GLOBAL_INT_ENABLE = 0x80000000,
49 TPM_INTF_BURST_COUNT_STATIC = 0x100,
50 TPM_INTF_CMD_READY_INT = 0x080,
51 TPM_INTF_INT_EDGE_FALLING = 0x040,
52 TPM_INTF_INT_EDGE_RISING = 0x020,
53 TPM_INTF_INT_LEVEL_LOW = 0x010,
54 TPM_INTF_INT_LEVEL_HIGH = 0x008,
55 TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
56 TPM_INTF_STS_VALID_INT = 0x002,
57 TPM_INTF_DATA_AVAIL_INT = 0x001,
58};
59
Kylene Jo Hall36b20022006-04-22 02:38:19 -070060enum tis_defaults {
Kylene Jo Hall2a7362f2006-05-15 09:44:25 -070061 TIS_MEM_BASE = 0xFED40000,
Kylene Jo Hallb09d5302006-04-22 02:38:55 -070062 TIS_MEM_LEN = 0x5000,
Kylene Jo Hallcb535422006-04-22 02:39:31 -070063 TIS_SHORT_TIMEOUT = 750, /* ms */
64 TIS_LONG_TIMEOUT = 2000, /* 2 sec */
Kylene Jo Hall36b20022006-04-22 02:38:19 -070065};
66
Leendert van Doorn27084ef2006-04-22 02:38:03 -070067#define TPM_ACCESS(l) (0x0000 | ((l) << 12))
68#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
69#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
70#define TPM_INT_STATUS(l) (0x0010 | ((l) << 12))
71#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
72#define TPM_STS(l) (0x0018 | ((l) << 12))
73#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
74
75#define TPM_DID_VID(l) (0x0F00 | ((l) << 12))
76#define TPM_RID(l) (0x0F04 | ((l) << 12))
77
78static LIST_HEAD(tis_chips);
Jiri Kosina4e70daa2012-02-29 10:29:23 +010079static DEFINE_MUTEX(tis_lock);
Leendert van Doorn27084ef2006-04-22 02:38:03 -070080
Randy Dunlap1560ffe62011-08-03 16:21:11 -070081#if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
Matthew Garrett3f0d3d02010-10-21 17:42:40 -040082static int is_itpm(struct pnp_dev *dev)
83{
84 struct acpi_device *acpi = pnp_acpi_device(dev);
85 struct acpi_hardware_id *id;
86
Kent Yoder6e38bfa2013-01-31 09:39:31 -060087 if (!acpi)
88 return 0;
89
Matthew Garrett3f0d3d02010-10-21 17:42:40 -040090 list_for_each_entry(id, &acpi->pnp.ids, list) {
91 if (!strcmp("INTC0102", id->id))
92 return 1;
93 }
94
95 return 0;
96}
Randy Dunlap1560ffe62011-08-03 16:21:11 -070097#else
98static inline int is_itpm(struct pnp_dev *dev)
99{
100 return 0;
101}
Matthew Garrett3f0d3d02010-10-21 17:42:40 -0400102#endif
103
Jason Gunthorpe7240b982012-12-06 15:44:54 -0700104/* Before we attempt to access the TPM we must see that the valid bit is set.
105 * The specification says that this bit is 0 at reset and remains 0 until the
106 * 'TPM has gone through its self test and initialization and has established
107 * correct values in the other bits.' */
108static int wait_startup(struct tpm_chip *chip, int l)
109{
110 unsigned long stop = jiffies + chip->vendor.timeout_a;
111 do {
112 if (ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
113 TPM_ACCESS_VALID)
114 return 0;
115 msleep(TPM_TIMEOUT);
116 } while (time_before(jiffies, stop));
117 return -1;
118}
119
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700120static int check_locality(struct tpm_chip *chip, int l)
121{
122 if ((ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
123 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
124 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
125 return chip->vendor.locality = l;
126
127 return -1;
128}
129
130static void release_locality(struct tpm_chip *chip, int l, int force)
131{
132 if (force || (ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
133 (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) ==
134 (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID))
135 iowrite8(TPM_ACCESS_ACTIVE_LOCALITY,
136 chip->vendor.iobase + TPM_ACCESS(l));
137}
138
139static int request_locality(struct tpm_chip *chip, int l)
140{
Stefan Berger20b87bb2011-03-30 12:13:31 -0400141 unsigned long stop, timeout;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700142 long rc;
143
144 if (check_locality(chip, l) >= 0)
145 return l;
146
147 iowrite8(TPM_ACCESS_REQUEST_USE,
148 chip->vendor.iobase + TPM_ACCESS(l));
149
Stefan Berger20b87bb2011-03-30 12:13:31 -0400150 stop = jiffies + chip->vendor.timeout_a;
151
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700152 if (chip->vendor.irq) {
Stefan Berger20b87bb2011-03-30 12:13:31 -0400153again:
154 timeout = stop - jiffies;
155 if ((long)timeout <= 0)
156 return -1;
Kylene Jo Hall36b20022006-04-22 02:38:19 -0700157 rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700158 (check_locality
159 (chip, l) >= 0),
Stefan Berger20b87bb2011-03-30 12:13:31 -0400160 timeout);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700161 if (rc > 0)
162 return l;
Stefan Berger20b87bb2011-03-30 12:13:31 -0400163 if (rc == -ERESTARTSYS && freezing(current)) {
164 clear_thread_flag(TIF_SIGPENDING);
165 goto again;
166 }
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700167 } else {
168 /* wait for burstcount */
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700169 do {
170 if (check_locality(chip, l) >= 0)
171 return l;
172 msleep(TPM_TIMEOUT);
173 }
174 while (time_before(jiffies, stop));
175 }
176 return -1;
177}
178
179static u8 tpm_tis_status(struct tpm_chip *chip)
180{
181 return ioread8(chip->vendor.iobase +
182 TPM_STS(chip->vendor.locality));
183}
184
185static void tpm_tis_ready(struct tpm_chip *chip)
186{
187 /* this causes the current command to be aborted */
188 iowrite8(TPM_STS_COMMAND_READY,
189 chip->vendor.iobase + TPM_STS(chip->vendor.locality));
190}
191
192static int get_burstcount(struct tpm_chip *chip)
193{
194 unsigned long stop;
195 int burstcnt;
196
197 /* wait for burstcount */
198 /* which timeout value, spec has 2 answers (c & d) */
Kylene Jo Hall36b20022006-04-22 02:38:19 -0700199 stop = jiffies + chip->vendor.timeout_d;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700200 do {
201 burstcnt = ioread8(chip->vendor.iobase +
202 TPM_STS(chip->vendor.locality) + 1);
203 burstcnt += ioread8(chip->vendor.iobase +
204 TPM_STS(chip->vendor.locality) +
205 2) << 8;
206 if (burstcnt)
207 return burstcnt;
208 msleep(TPM_TIMEOUT);
209 } while (time_before(jiffies, stop));
210 return -EBUSY;
211}
212
Kylene Jo Hallcb535422006-04-22 02:39:31 -0700213static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700214{
215 int size = 0, burstcnt;
216 while (size < count &&
Rajiv Andradefd048862011-09-16 14:39:40 -0300217 wait_for_tpm_stat(chip,
218 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
219 chip->vendor.timeout_c,
Stefan Berger78f09cc2013-01-22 13:57:53 -0600220 &chip->vendor.read_queue, true)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700221 == 0) {
222 burstcnt = get_burstcount(chip);
223 for (; burstcnt > 0 && size < count; burstcnt--)
224 buf[size++] = ioread8(chip->vendor.iobase +
225 TPM_DATA_FIFO(chip->vendor.
226 locality));
227 }
228 return size;
229}
230
Kylene Jo Hallcb535422006-04-22 02:39:31 -0700231static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700232{
233 int size = 0;
234 int expected, status;
235
236 if (count < TPM_HEADER_SIZE) {
237 size = -EIO;
238 goto out;
239 }
240
241 /* read first 10 bytes, including tag, paramsize, and result */
242 if ((size =
243 recv_data(chip, buf, TPM_HEADER_SIZE)) < TPM_HEADER_SIZE) {
244 dev_err(chip->dev, "Unable to read header\n");
245 goto out;
246 }
247
248 expected = be32_to_cpu(*(__be32 *) (buf + 2));
249 if (expected > count) {
250 size = -EIO;
251 goto out;
252 }
253
254 if ((size +=
255 recv_data(chip, &buf[TPM_HEADER_SIZE],
256 expected - TPM_HEADER_SIZE)) < expected) {
257 dev_err(chip->dev, "Unable to read remainder of result\n");
258 size = -ETIME;
259 goto out;
260 }
261
Rajiv Andradefd048862011-09-16 14:39:40 -0300262 wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
Stefan Berger78f09cc2013-01-22 13:57:53 -0600263 &chip->vendor.int_queue, false);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700264 status = tpm_tis_status(chip);
265 if (status & TPM_STS_DATA_AVAIL) { /* retry? */
266 dev_err(chip->dev, "Error left over data\n");
267 size = -EIO;
268 goto out;
269 }
270
271out:
272 tpm_tis_ready(chip);
273 release_locality(chip, chip->vendor.locality, 0);
274 return size;
275}
276
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030277static bool itpm;
Rajiv Andrade3507d612009-09-10 17:09:35 -0300278module_param(itpm, bool, 0444);
279MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
280
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700281/*
282 * If interrupts are used (signaled by an irq set in the vendor structure)
283 * tpm.c can skip polling for the data to be available as the interrupt is
284 * waited for here
285 */
Stefan Berger9519de32011-03-30 12:13:33 -0400286static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700287{
288 int rc, status, burstcnt;
289 size_t count = 0;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700290
291 if (request_locality(chip, 0) < 0)
292 return -EBUSY;
293
294 status = tpm_tis_status(chip);
295 if ((status & TPM_STS_COMMAND_READY) == 0) {
296 tpm_tis_ready(chip);
Rajiv Andradefd048862011-09-16 14:39:40 -0300297 if (wait_for_tpm_stat
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700298 (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
Stefan Berger78f09cc2013-01-22 13:57:53 -0600299 &chip->vendor.int_queue, false) < 0) {
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700300 rc = -ETIME;
301 goto out_err;
302 }
303 }
304
305 while (count < len - 1) {
306 burstcnt = get_burstcount(chip);
307 for (; burstcnt > 0 && count < len - 1; burstcnt--) {
308 iowrite8(buf[count], chip->vendor.iobase +
309 TPM_DATA_FIFO(chip->vendor.locality));
310 count++;
311 }
312
Rajiv Andradefd048862011-09-16 14:39:40 -0300313 wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
Stefan Berger78f09cc2013-01-22 13:57:53 -0600314 &chip->vendor.int_queue, false);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700315 status = tpm_tis_status(chip);
Rajiv Andrade3507d612009-09-10 17:09:35 -0300316 if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700317 rc = -EIO;
318 goto out_err;
319 }
320 }
321
322 /* write last byte */
323 iowrite8(buf[count],
Stefan Berger9519de32011-03-30 12:13:33 -0400324 chip->vendor.iobase + TPM_DATA_FIFO(chip->vendor.locality));
Rajiv Andradefd048862011-09-16 14:39:40 -0300325 wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
Stefan Berger78f09cc2013-01-22 13:57:53 -0600326 &chip->vendor.int_queue, false);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700327 status = tpm_tis_status(chip);
328 if ((status & TPM_STS_DATA_EXPECT) != 0) {
329 rc = -EIO;
330 goto out_err;
331 }
332
Stefan Berger9519de32011-03-30 12:13:33 -0400333 return 0;
334
335out_err:
336 tpm_tis_ready(chip);
337 release_locality(chip, chip->vendor.locality, 0);
338 return rc;
339}
340
341/*
342 * If interrupts are used (signaled by an irq set in the vendor structure)
343 * tpm.c can skip polling for the data to be available as the interrupt is
344 * waited for here
345 */
346static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
347{
348 int rc;
349 u32 ordinal;
350
351 rc = tpm_tis_send_data(chip, buf, len);
352 if (rc < 0)
353 return rc;
354
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700355 /* go and do it */
356 iowrite8(TPM_STS_GO,
357 chip->vendor.iobase + TPM_STS(chip->vendor.locality));
358
359 if (chip->vendor.irq) {
360 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
Rajiv Andradefd048862011-09-16 14:39:40 -0300361 if (wait_for_tpm_stat
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700362 (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
363 tpm_calc_ordinal_duration(chip, ordinal),
Stefan Berger78f09cc2013-01-22 13:57:53 -0600364 &chip->vendor.read_queue, false) < 0) {
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700365 rc = -ETIME;
366 goto out_err;
367 }
368 }
369 return len;
370out_err:
371 tpm_tis_ready(chip);
372 release_locality(chip, chip->vendor.locality, 0);
373 return rc;
374}
375
Stefan Berger9519de32011-03-30 12:13:33 -0400376/*
377 * Early probing for iTPM with STS_DATA_EXPECT flaw.
378 * Try sending command without itpm flag set and if that
379 * fails, repeat with itpm flag set.
380 */
381static int probe_itpm(struct tpm_chip *chip)
382{
383 int rc = 0;
384 u8 cmd_getticks[] = {
385 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
386 0x00, 0x00, 0x00, 0xf1
387 };
388 size_t len = sizeof(cmd_getticks);
Stefan Berger968de8e2012-01-20 12:58:50 -0500389 bool rem_itpm = itpm;
Stefan Berger4e401fb2012-01-20 12:58:49 -0500390 u16 vendor = ioread16(chip->vendor.iobase + TPM_DID_VID(0));
391
392 /* probe only iTPMS */
393 if (vendor != TPM_VID_INTEL)
394 return 0;
Stefan Berger9519de32011-03-30 12:13:33 -0400395
Peter Huewe73249692012-11-29 22:08:41 +0100396 itpm = false;
Stefan Berger9519de32011-03-30 12:13:33 -0400397
398 rc = tpm_tis_send_data(chip, cmd_getticks, len);
399 if (rc == 0)
400 goto out;
401
402 tpm_tis_ready(chip);
403 release_locality(chip, chip->vendor.locality, 0);
404
Peter Huewe73249692012-11-29 22:08:41 +0100405 itpm = true;
Stefan Berger9519de32011-03-30 12:13:33 -0400406
407 rc = tpm_tis_send_data(chip, cmd_getticks, len);
408 if (rc == 0) {
409 dev_info(chip->dev, "Detected an iTPM.\n");
410 rc = 1;
411 } else
412 rc = -EFAULT;
413
414out:
415 itpm = rem_itpm;
416 tpm_tis_ready(chip);
417 release_locality(chip, chip->vendor.locality, 0);
418
419 return rc;
420}
421
Stefan Berger1f866052013-01-22 13:52:35 -0600422static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
423{
424 switch (chip->vendor.manufacturer_id) {
425 case TPM_VID_WINBOND:
426 return ((status == TPM_STS_VALID) ||
427 (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
428 case TPM_VID_STM:
429 return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
430 default:
431 return (status == TPM_STS_COMMAND_READY);
432 }
433}
434
Arjan van de Ven62322d22006-07-03 00:24:21 -0700435static const struct file_operations tis_ops = {
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700436 .owner = THIS_MODULE,
437 .llseek = no_llseek,
438 .open = tpm_open,
439 .read = tpm_read,
440 .write = tpm_write,
441 .release = tpm_release,
442};
443
444static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
445static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
446static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
447static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL);
448static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL);
449static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated,
450 NULL);
451static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps_1_2, NULL);
452static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
Stefan Berger04ab2292011-03-30 12:13:25 -0400453static DEVICE_ATTR(durations, S_IRUGO, tpm_show_durations, NULL);
Stefan Berger62592102011-03-30 12:13:28 -0400454static DEVICE_ATTR(timeouts, S_IRUGO, tpm_show_timeouts, NULL);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700455
456static struct attribute *tis_attrs[] = {
457 &dev_attr_pubek.attr,
458 &dev_attr_pcrs.attr,
459 &dev_attr_enabled.attr,
460 &dev_attr_active.attr,
461 &dev_attr_owned.attr,
462 &dev_attr_temp_deactivated.attr,
463 &dev_attr_caps.attr,
Stefan Berger04ab2292011-03-30 12:13:25 -0400464 &dev_attr_cancel.attr,
Stefan Berger62592102011-03-30 12:13:28 -0400465 &dev_attr_durations.attr,
466 &dev_attr_timeouts.attr, NULL,
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700467};
468
469static struct attribute_group tis_attr_grp = {
470 .attrs = tis_attrs
471};
472
473static struct tpm_vendor_specific tpm_tis = {
474 .status = tpm_tis_status,
475 .recv = tpm_tis_recv,
476 .send = tpm_tis_send,
477 .cancel = tpm_tis_ready,
478 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
479 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
Stefan Berger1f866052013-01-22 13:52:35 -0600480 .req_canceled = tpm_tis_req_canceled,
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700481 .attr_group = &tis_attr_grp,
482 .miscdev = {
483 .fops = &tis_ops,},
484};
485
David Howells7d12e782006-10-05 14:55:46 +0100486static irqreturn_t tis_int_probe(int irq, void *dev_id)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700487{
Jeff Garzik06efcad2007-10-19 03:10:11 -0400488 struct tpm_chip *chip = dev_id;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700489 u32 interrupt;
490
491 interrupt = ioread32(chip->vendor.iobase +
492 TPM_INT_STATUS(chip->vendor.locality));
493
494 if (interrupt == 0)
495 return IRQ_NONE;
496
Stefan Bergera7b66822011-03-30 12:13:32 -0400497 chip->vendor.probed_irq = irq;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700498
499 /* Clear interrupts handled with TPM_EOI */
500 iowrite32(interrupt,
501 chip->vendor.iobase +
502 TPM_INT_STATUS(chip->vendor.locality));
503 return IRQ_HANDLED;
504}
505
Jeff Garzika6f97b22007-10-31 05:20:49 -0400506static irqreturn_t tis_int_handler(int dummy, void *dev_id)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700507{
Jeff Garzik06efcad2007-10-19 03:10:11 -0400508 struct tpm_chip *chip = dev_id;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700509 u32 interrupt;
510 int i;
511
512 interrupt = ioread32(chip->vendor.iobase +
513 TPM_INT_STATUS(chip->vendor.locality));
514
515 if (interrupt == 0)
516 return IRQ_NONE;
517
518 if (interrupt & TPM_INTF_DATA_AVAIL_INT)
519 wake_up_interruptible(&chip->vendor.read_queue);
520 if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
521 for (i = 0; i < 5; i++)
522 if (check_locality(chip, i) >= 0)
523 break;
524 if (interrupt &
525 (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
526 TPM_INTF_CMD_READY_INT))
527 wake_up_interruptible(&chip->vendor.int_queue);
528
529 /* Clear interrupts handled with TPM_EOI */
530 iowrite32(interrupt,
531 chip->vendor.iobase +
532 TPM_INT_STATUS(chip->vendor.locality));
Kylene Jo Hallcab091e2006-07-14 00:24:30 -0700533 ioread32(chip->vendor.iobase + TPM_INT_STATUS(chip->vendor.locality));
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700534 return IRQ_HANDLED;
535}
536
Peter Huewe73249692012-11-29 22:08:41 +0100537static bool interrupts = true;
Kylene Jo Hall57135562006-04-22 02:39:44 -0700538module_param(interrupts, bool, 0444);
539MODULE_PARM_DESC(interrupts, "Enable interrupts");
540
Kylene Jo Hallc3c36aa2006-07-14 00:24:31 -0700541static int tpm_tis_init(struct device *dev, resource_size_t start,
Bjorn Helgaas7917ff92007-10-16 23:26:46 -0700542 resource_size_t len, unsigned int irq)
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700543{
544 u32 vendor, intfcaps, intmask;
Stefan Berger968de8e2012-01-20 12:58:50 -0500545 int rc, i, irq_s, irq_e, probe;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700546 struct tpm_chip *chip;
547
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700548 if (!(chip = tpm_register_hardware(dev, &tpm_tis)))
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700549 return -ENODEV;
550
551 chip->vendor.iobase = ioremap(start, len);
552 if (!chip->vendor.iobase) {
553 rc = -EIO;
554 goto out_err;
555 }
556
Jason Gunthorpeec579352009-09-09 17:22:18 -0600557 /* Default timeouts */
558 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
559 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
560 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
561 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
562
Jason Gunthorpe7240b982012-12-06 15:44:54 -0700563 if (wait_startup(chip, 0) != 0) {
564 rc = -ENODEV;
565 goto out_err;
566 }
567
Marcel Selhorst05a462a2007-11-28 16:21:27 -0800568 if (request_locality(chip, 0) != 0) {
569 rc = -ENODEV;
570 goto out_err;
571 }
572
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700573 vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
Stefan Berger3e3a5e92013-01-22 13:50:07 -0600574 chip->vendor.manufacturer_id = vendor;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700575
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700576 dev_info(dev,
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700577 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
578 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
579
Stefan Berger9519de32011-03-30 12:13:33 -0400580 if (!itpm) {
Stefan Berger968de8e2012-01-20 12:58:50 -0500581 probe = probe_itpm(chip);
582 if (probe < 0) {
Stefan Berger9519de32011-03-30 12:13:33 -0400583 rc = -ENODEV;
584 goto out_err;
585 }
Peter Huewe73249692012-11-29 22:08:41 +0100586 itpm = !!probe;
Stefan Berger9519de32011-03-30 12:13:33 -0400587 }
588
Rajiv Andrade3507d612009-09-10 17:09:35 -0300589 if (itpm)
590 dev_info(dev, "Intel iTPM workaround enabled\n");
591
592
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700593 /* Figure out the capabilities */
594 intfcaps =
595 ioread32(chip->vendor.iobase +
596 TPM_INTF_CAPS(chip->vendor.locality));
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700597 dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700598 intfcaps);
599 if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700600 dev_dbg(dev, "\tBurst Count Static\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700601 if (intfcaps & TPM_INTF_CMD_READY_INT)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700602 dev_dbg(dev, "\tCommand Ready Int Support\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700603 if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700604 dev_dbg(dev, "\tInterrupt Edge Falling\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700605 if (intfcaps & TPM_INTF_INT_EDGE_RISING)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700606 dev_dbg(dev, "\tInterrupt Edge Rising\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700607 if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700608 dev_dbg(dev, "\tInterrupt Level Low\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700609 if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700610 dev_dbg(dev, "\tInterrupt Level High\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700611 if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700612 dev_dbg(dev, "\tLocality Change Int Support\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700613 if (intfcaps & TPM_INTF_STS_VALID_INT)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700614 dev_dbg(dev, "\tSts Valid Int Support\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700615 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700616 dev_dbg(dev, "\tData Avail Int Support\n");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700617
Stefan Bergera7b66822011-03-30 12:13:32 -0400618 /* get the timeouts before testing for irqs */
Stefan Berger7f326ed2011-11-11 12:57:05 -0500619 if (tpm_get_timeouts(chip)) {
620 dev_err(dev, "Could not get TPM timeouts and durations\n");
621 rc = -ENODEV;
622 goto out_err;
623 }
Stefan Bergera7b66822011-03-30 12:13:32 -0400624
Stefan Berger68d6e672011-11-11 12:57:04 -0500625 if (tpm_do_selftest(chip)) {
626 dev_err(dev, "TPM self test failed\n");
627 rc = -ENODEV;
628 goto out_err;
629 }
630
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700631 /* INTERRUPT Setup */
632 init_waitqueue_head(&chip->vendor.read_queue);
633 init_waitqueue_head(&chip->vendor.int_queue);
634
635 intmask =
636 ioread32(chip->vendor.iobase +
637 TPM_INT_ENABLE(chip->vendor.locality));
638
639 intmask |= TPM_INTF_CMD_READY_INT
640 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
641 | TPM_INTF_STS_VALID_INT;
642
643 iowrite32(intmask,
644 chip->vendor.iobase +
645 TPM_INT_ENABLE(chip->vendor.locality));
Bjorn Helgaas7917ff92007-10-16 23:26:46 -0700646 if (interrupts)
647 chip->vendor.irq = irq;
648 if (interrupts && !chip->vendor.irq) {
Stefan Bergera7b66822011-03-30 12:13:32 -0400649 irq_s =
Kylene Jo Hall57135562006-04-22 02:39:44 -0700650 ioread8(chip->vendor.iobase +
651 TPM_INT_VECTOR(chip->vendor.locality));
Stefan Bergera7b66822011-03-30 12:13:32 -0400652 if (irq_s) {
653 irq_e = irq_s;
654 } else {
655 irq_s = 3;
656 irq_e = 15;
657 }
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700658
Stefan Bergera7b66822011-03-30 12:13:32 -0400659 for (i = irq_s; i <= irq_e && chip->vendor.irq == 0; i++) {
Kylene Jo Hall57135562006-04-22 02:39:44 -0700660 iowrite8(i, chip->vendor.iobase +
Stefan Bergera7b66822011-03-30 12:13:32 -0400661 TPM_INT_VECTOR(chip->vendor.locality));
Kylene Jo Hall57135562006-04-22 02:39:44 -0700662 if (request_irq
Thomas Gleixner0f2ed4c2006-07-01 19:29:33 -0700663 (i, tis_int_probe, IRQF_SHARED,
Kylene Jo Hall57135562006-04-22 02:39:44 -0700664 chip->vendor.miscdev.name, chip) != 0) {
665 dev_info(chip->dev,
666 "Unable to request irq: %d for probe\n",
667 i);
668 continue;
669 }
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700670
Kylene Jo Hall57135562006-04-22 02:39:44 -0700671 /* Clear all existing */
672 iowrite32(ioread32
673 (chip->vendor.iobase +
674 TPM_INT_STATUS(chip->vendor.locality)),
675 chip->vendor.iobase +
676 TPM_INT_STATUS(chip->vendor.locality));
677
678 /* Turn on */
679 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
680 chip->vendor.iobase +
681 TPM_INT_ENABLE(chip->vendor.locality));
682
Stefan Bergera7b66822011-03-30 12:13:32 -0400683 chip->vendor.probed_irq = 0;
684
Kylene Jo Hall57135562006-04-22 02:39:44 -0700685 /* Generate Interrupts */
686 tpm_gen_interrupt(chip);
687
Stefan Bergera7b66822011-03-30 12:13:32 -0400688 chip->vendor.irq = chip->vendor.probed_irq;
689
690 /* free_irq will call into tis_int_probe;
691 clear all irqs we haven't seen while doing
692 tpm_gen_interrupt */
693 iowrite32(ioread32
694 (chip->vendor.iobase +
695 TPM_INT_STATUS(chip->vendor.locality)),
696 chip->vendor.iobase +
697 TPM_INT_STATUS(chip->vendor.locality));
698
Kylene Jo Hall57135562006-04-22 02:39:44 -0700699 /* Turn off */
700 iowrite32(intmask,
701 chip->vendor.iobase +
702 TPM_INT_ENABLE(chip->vendor.locality));
703 free_irq(i, chip);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700704 }
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700705 }
706 if (chip->vendor.irq) {
707 iowrite8(chip->vendor.irq,
708 chip->vendor.iobase +
709 TPM_INT_VECTOR(chip->vendor.locality));
710 if (request_irq
Thomas Gleixner0f2ed4c2006-07-01 19:29:33 -0700711 (chip->vendor.irq, tis_int_handler, IRQF_SHARED,
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700712 chip->vendor.miscdev.name, chip) != 0) {
713 dev_info(chip->dev,
Kylene Jo Hall57135562006-04-22 02:39:44 -0700714 "Unable to request irq: %d for use\n",
715 chip->vendor.irq);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700716 chip->vendor.irq = 0;
717 } else {
718 /* Clear all existing */
719 iowrite32(ioread32
720 (chip->vendor.iobase +
721 TPM_INT_STATUS(chip->vendor.locality)),
722 chip->vendor.iobase +
723 TPM_INT_STATUS(chip->vendor.locality));
724
725 /* Turn on */
726 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
727 chip->vendor.iobase +
728 TPM_INT_ENABLE(chip->vendor.locality));
729 }
730 }
731
732 INIT_LIST_HEAD(&chip->vendor.list);
Jiri Kosina4e70daa2012-02-29 10:29:23 +0100733 mutex_lock(&tis_lock);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700734 list_add(&chip->vendor.list, &tis_chips);
Jiri Kosina4e70daa2012-02-29 10:29:23 +0100735 mutex_unlock(&tis_lock);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700736
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700737
738 return 0;
739out_err:
740 if (chip->vendor.iobase)
741 iounmap(chip->vendor.iobase);
742 tpm_remove_hardware(chip->dev);
743 return rc;
744}
Stefan Berger96854312011-07-17 01:04:24 -0400745
Kent Yoder7e72fe72012-08-09 09:20:15 -0500746#if defined(CONFIG_PNP) || defined(CONFIG_PM_SLEEP)
Stefan Berger96854312011-07-17 01:04:24 -0400747static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
748{
749 u32 intmask;
750
751 /* reenable interrupts that device may have lost or
752 BIOS/firmware may have disabled */
753 iowrite8(chip->vendor.irq, chip->vendor.iobase +
754 TPM_INT_VECTOR(chip->vendor.locality));
755
756 intmask =
757 ioread32(chip->vendor.iobase +
758 TPM_INT_ENABLE(chip->vendor.locality));
759
760 intmask |= TPM_INTF_CMD_READY_INT
761 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
762 | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE;
763
764 iowrite32(intmask,
765 chip->vendor.iobase + TPM_INT_ENABLE(chip->vendor.locality));
766}
Kent Yoder7e72fe72012-08-09 09:20:15 -0500767#endif
Stefan Berger96854312011-07-17 01:04:24 -0400768
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300769#ifdef CONFIG_PNP
Bill Pembertonafc6d362012-11-19 13:22:42 -0500770static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700771 const struct pnp_device_id *pnp_id)
772{
Kylene Jo Hallc3c36aa2006-07-14 00:24:31 -0700773 resource_size_t start, len;
Bjorn Helgaas7917ff92007-10-16 23:26:46 -0700774 unsigned int irq = 0;
775
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700776 start = pnp_mem_start(pnp_dev, 0);
777 len = pnp_mem_len(pnp_dev, 0);
778
Bjorn Helgaas7917ff92007-10-16 23:26:46 -0700779 if (pnp_irq_valid(pnp_dev, 0))
780 irq = pnp_irq(pnp_dev, 0);
781 else
Peter Huewe73249692012-11-29 22:08:41 +0100782 interrupts = false;
Bjorn Helgaas7917ff92007-10-16 23:26:46 -0700783
Olof Johanssone5cce6c2011-01-06 21:24:01 -0600784 if (is_itpm(pnp_dev))
Peter Huewe73249692012-11-29 22:08:41 +0100785 itpm = true;
Olof Johanssone5cce6c2011-01-06 21:24:01 -0600786
Bjorn Helgaas7917ff92007-10-16 23:26:46 -0700787 return tpm_tis_init(&pnp_dev->dev, start, len, irq);
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700788}
789
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700790static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg)
791{
Rafael J. Wysocki035e2ce2012-07-06 19:09:01 +0200792 return tpm_pm_suspend(&dev->dev);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700793}
794
795static int tpm_tis_pnp_resume(struct pnp_dev *dev)
796{
Rajiv Andrade59f6fbe2010-06-23 12:18:56 -0700797 struct tpm_chip *chip = pnp_get_drvdata(dev);
798 int ret;
799
Stefan Berger45baa1d2011-03-30 12:13:30 -0400800 if (chip->vendor.irq)
801 tpm_tis_reenable_interrupts(chip);
802
Rajiv Andrade59f6fbe2010-06-23 12:18:56 -0700803 ret = tpm_pm_resume(&dev->dev);
804 if (!ret)
Stefan Berger68d6e672011-11-11 12:57:04 -0500805 tpm_do_selftest(chip);
Rajiv Andrade59f6fbe2010-06-23 12:18:56 -0700806
807 return ret;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700808}
809
Bill Pemberton0bbed202012-11-19 13:24:36 -0500810static struct pnp_device_id tpm_pnp_tbl[] = {
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700811 {"PNP0C31", 0}, /* TPM */
Kylene Jo Hall93e1b7d2006-04-22 02:39:52 -0700812 {"ATM1200", 0}, /* Atmel */
813 {"IFX0102", 0}, /* Infineon */
814 {"BCM0101", 0}, /* Broadcom */
LE DISEZ Erwan061991e2008-07-25 19:44:56 -0700815 {"BCM0102", 0}, /* Broadcom */
Kylene Jo Hall93e1b7d2006-04-22 02:39:52 -0700816 {"NSC1200", 0}, /* National */
Marcin Obarafb0e7e12008-07-10 17:30:42 -0700817 {"ICO0102", 0}, /* Intel */
Kylene Jo Hall93e1b7d2006-04-22 02:39:52 -0700818 /* Add new here */
819 {"", 0}, /* User Specified */
820 {"", 0} /* Terminator */
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700821};
Matt Domsch31bde712009-11-03 12:05:50 +1100822MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700823
Bill Pemberton39af33f2012-11-19 13:26:26 -0500824static void tpm_tis_pnp_remove(struct pnp_dev *dev)
Rajiv Andrade253115b2008-10-11 09:04:39 +1100825{
826 struct tpm_chip *chip = pnp_get_drvdata(dev);
827
828 tpm_dev_vendor_release(chip);
829
830 kfree(chip);
831}
832
833
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700834static struct pnp_driver tis_pnp_driver = {
835 .name = "tpm_tis",
836 .id_table = tpm_pnp_tbl,
837 .probe = tpm_tis_pnp_init,
838 .suspend = tpm_tis_pnp_suspend,
839 .resume = tpm_tis_pnp_resume,
Rajiv Andrade253115b2008-10-11 09:04:39 +1100840 .remove = tpm_tis_pnp_remove,
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700841};
842
Kylene Jo Hall93e1b7d2006-04-22 02:39:52 -0700843#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
844module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
845 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
846MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300847#endif
Ming Lei7a192ec2009-02-06 23:40:12 +0800848
Rafael J. Wysocki07368d32012-08-09 23:00:35 +0200849#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockib633f052012-07-06 19:09:20 +0200850static int tpm_tis_resume(struct device *dev)
Ming Lei7a192ec2009-02-06 23:40:12 +0800851{
Rafael J. Wysockib633f052012-07-06 19:09:20 +0200852 struct tpm_chip *chip = dev_get_drvdata(dev);
Stefan Berger45baa1d2011-03-30 12:13:30 -0400853
854 if (chip->vendor.irq)
855 tpm_tis_reenable_interrupts(chip);
856
Rafael J. Wysockib633f052012-07-06 19:09:20 +0200857 return tpm_pm_resume(dev);
Ming Lei7a192ec2009-02-06 23:40:12 +0800858}
Rafael J. Wysocki07368d32012-08-09 23:00:35 +0200859#endif
Rafael J. Wysockib633f052012-07-06 19:09:20 +0200860
861static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
862
Ming Lei7a192ec2009-02-06 23:40:12 +0800863static struct platform_driver tis_drv = {
864 .driver = {
865 .name = "tpm_tis",
866 .owner = THIS_MODULE,
Rafael J. Wysockib633f052012-07-06 19:09:20 +0200867 .pm = &tpm_tis_pm,
Ming Lei7a192ec2009-02-06 23:40:12 +0800868 },
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700869};
870
871static struct platform_device *pdev;
872
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030873static bool force;
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700874module_param(force, bool, 0444);
875MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700876static int __init init_tis(void)
877{
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700878 int rc;
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300879#ifdef CONFIG_PNP
880 if (!force)
881 return pnp_register_driver(&tis_pnp_driver);
882#endif
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700883
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300884 rc = platform_driver_register(&tis_drv);
885 if (rc < 0)
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700886 return rc;
Wei Yongjun4fba3c32013-04-25 15:07:47 +0800887 pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0);
888 if (IS_ERR(pdev)) {
889 rc = PTR_ERR(pdev);
890 goto err_dev;
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700891 }
Wei Yongjun4fba3c32013-04-25 15:07:47 +0800892 rc = tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0);
893 if (rc)
894 goto err_init;
895 return 0;
896err_init:
897 platform_device_unregister(pdev);
898err_dev:
899 platform_driver_unregister(&tis_drv);
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300900 return rc;
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700901}
902
903static void __exit cleanup_tis(void)
904{
905 struct tpm_vendor_specific *i, *j;
906 struct tpm_chip *chip;
Jiri Kosina4e70daa2012-02-29 10:29:23 +0100907 mutex_lock(&tis_lock);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700908 list_for_each_entry_safe(i, j, &tis_chips, list) {
909 chip = to_tpm_chip(i);
Rajiv Andrade253115b2008-10-11 09:04:39 +1100910 tpm_remove_hardware(chip->dev);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700911 iowrite32(~TPM_GLOBAL_INT_ENABLE &
912 ioread32(chip->vendor.iobase +
913 TPM_INT_ENABLE(chip->vendor.
914 locality)),
915 chip->vendor.iobase +
916 TPM_INT_ENABLE(chip->vendor.locality));
917 release_locality(chip, chip->vendor.locality, 1);
918 if (chip->vendor.irq)
919 free_irq(chip->vendor.irq, chip);
920 iounmap(i->iobase);
921 list_del(&i->list);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700922 }
Jiri Kosina4e70daa2012-02-29 10:29:23 +0100923 mutex_unlock(&tis_lock);
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300924#ifdef CONFIG_PNP
925 if (!force) {
Kylene Jo Hall9e323d32006-07-14 00:24:31 -0700926 pnp_unregister_driver(&tis_pnp_driver);
Rajiv Andrade7f2ab002010-05-13 17:37:54 -0300927 return;
928 }
929#endif
930 platform_device_unregister(pdev);
931 platform_driver_unregister(&tis_drv);
Leendert van Doorn27084ef2006-04-22 02:38:03 -0700932}
933
934module_init(init_tis);
935module_exit(cleanup_tis);
936MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
937MODULE_DESCRIPTION("TPM Driver");
938MODULE_VERSION("2.0");
939MODULE_LICENSE("GPL");