Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Yoder | 8e81cc1 | 2007-08-22 14:01:04 -0700 | [diff] [blame] | 10 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 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 Wright | faba278 | 2005-10-31 23:44:28 -0800 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "tpm.h" |
| 25 | |
| 26 | /* National definitions */ |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 27 | enum tpm_nsc_addr{ |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 28 | 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 Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 33 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 35 | enum 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 45 | enum tpm_nsc_status_loc { |
| 46 | NSC_STATUS = 0x01, |
| 47 | NSC_COMMAND = 0x01, |
| 48 | NSC_DATA = 0x00 |
| 49 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* status bits */ |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 52 | enum tpm_nsc_status { |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 53 | 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 Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* command bits */ |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 62 | enum tpm_nsc_cmd_mode { |
| 63 | NSC_COMMAND_NORMAL = 0x01, /* normal mode */ |
| 64 | NSC_COMMAND_EOC = 0x03, |
| 65 | NSC_COMMAND_CANCEL = 0x22 |
| 66 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Wait for a certain status to appear |
| 69 | */ |
| 70 | static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) |
| 71 | { |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 72 | unsigned long stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | /* status immediately available check */ |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 75 | *data = inb(chip->vendor.base + NSC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if ((*data & mask) == val) |
| 77 | return 0; |
| 78 | |
| 79 | /* wait for status */ |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 80 | stop = jiffies + 10 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | do { |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 82 | msleep(TPM_TIMEOUT); |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 83 | *data = inb(chip->vendor.base + 1); |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 84 | if ((*data & mask) == val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 87 | while (time_before(jiffies, stop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | return -EBUSY; |
| 90 | } |
| 91 | |
| 92 | static int nsc_wait_for_ready(struct tpm_chip *chip) |
| 93 | { |
| 94 | int status; |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 95 | unsigned long stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | /* status immediately available check */ |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 98 | status = inb(chip->vendor.base + NSC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (status & NSC_STATUS_OBF) |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 100 | status = inb(chip->vendor.base + NSC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | if (status & NSC_STATUS_RDY) |
| 102 | return 0; |
| 103 | |
| 104 | /* wait for status */ |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 105 | stop = jiffies + 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | do { |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 107 | msleep(TPM_TIMEOUT); |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 108 | status = inb(chip->vendor.base + NSC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (status & NSC_STATUS_OBF) |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 110 | status = inb(chip->vendor.base + NSC_DATA); |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 111 | if (status & NSC_STATUS_RDY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 114 | while (time_before(jiffies, stop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 116 | dev_info(chip->dev, "wait for ready failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return -EBUSY; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | static 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 Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 132 | dev_err(chip->dev, "F0 timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return -EIO; |
| 134 | } |
| 135 | if ((data = |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 136 | inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 137 | dev_err(chip->dev, "not in normal mode (0x%x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | 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 Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 146 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | "OBF timeout (while reading data)\n"); |
| 148 | return -EIO; |
| 149 | } |
| 150 | if (data & NSC_STATUS_F0) |
| 151 | break; |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 152 | *p = inb(chip->vendor.base + NSC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 155 | if ((data & NSC_STATUS_F0) == 0 && |
| 156 | (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 157 | dev_err(chip->dev, "F0 not set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return -EIO; |
| 159 | } |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 160 | if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 161 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | "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 | |
| 175 | static 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 Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 186 | outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 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 Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 192 | dev_err(chip->dev, "IBF timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return -EIO; |
| 194 | } |
| 195 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 196 | outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 198 | dev_err(chip->dev, "IBR timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | 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 Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 204 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | "IBF timeout (while writing data)\n"); |
| 206 | return -EIO; |
| 207 | } |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 208 | outb(buf[i], chip->vendor.base + NSC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 212 | dev_err(chip->dev, "IBF timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | return -EIO; |
| 214 | } |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 215 | outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | return count; |
| 218 | } |
| 219 | |
| 220 | static void tpm_nsc_cancel(struct tpm_chip *chip) |
| 221 | { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 222 | outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 225 | static u8 tpm_nsc_status(struct tpm_chip *chip) |
| 226 | { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 227 | return inb(chip->vendor.base + NSC_STATUS); |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Stefan Berger | 1f86605 | 2013-01-22 13:52:35 -0600 | [diff] [blame] | 230 | static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status) |
| 231 | { |
| 232 | return (status == NSC_STATUS_RDY); |
| 233 | } |
| 234 | |
Jason Gunthorpe | 01ad1fa | 2013-11-26 13:30:43 -0700 | [diff] [blame] | 235 | static const struct tpm_class_ops tpm_nsc = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | .recv = tpm_nsc_recv, |
| 237 | .send = tpm_nsc_send, |
| 238 | .cancel = tpm_nsc_cancel, |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 239 | .status = tpm_nsc_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | .req_complete_mask = NSC_STATUS_OBF, |
| 241 | .req_complete_val = NSC_STATUS_OBF, |
Stefan Berger | 1f86605 | 2013-01-22 13:52:35 -0600 | [diff] [blame] | 242 | .req_canceled = tpm_nsc_req_canceled, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 245 | static struct platform_device *pdev = NULL; |
| 246 | |
Sam Ravnborg | 4821cd1 | 2008-04-29 01:03:23 -0700 | [diff] [blame] | 247 | static void tpm_nsc_remove(struct device *dev) |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 248 | { |
| 249 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 250 | if ( chip ) { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 251 | release_region(chip->vendor.base, 2); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 252 | tpm_remove_hardware(chip->dev); |
| 253 | } |
| 254 | } |
| 255 | |
Rafael J. Wysocki | ca9a205 | 2012-07-06 19:09:28 +0200 | [diff] [blame] | 256 | static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume); |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 257 | |
| 258 | static struct platform_driver nsc_drv = { |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 259 | .driver = { |
| 260 | .name = "tpm_nsc", |
| 261 | .owner = THIS_MODULE, |
Rafael J. Wysocki | ca9a205 | 2012-07-06 19:09:28 +0200 | [diff] [blame] | 262 | .pm = &tpm_nsc_pm, |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 263 | }, |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | static int __init init_nsc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
| 268 | int rc = 0; |
Jeff Garzik | f33d9bd | 2006-10-11 01:21:51 -0700 | [diff] [blame] | 269 | int lo, hi, err; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 270 | int nscAddrBase = TPM_ADDR; |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 271 | struct tpm_chip *chip; |
| 272 | unsigned long base; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | /* verify that it is a National part (SID) */ |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 275 | if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { |
| 276 | nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)| |
| 277 | (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 278 | if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) |
| 279 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 282 | err = platform_driver_register(&nsc_drv); |
Jeff Garzik | f33d9bd | 2006-10-11 01:21:51 -0700 | [diff] [blame] | 283 | if (err) |
| 284 | return err; |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 285 | |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 286 | hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); |
| 287 | lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 288 | base = (hi<<8) | lo; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 289 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 290 | /* enable the DPM module */ |
| 291 | tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); |
| 292 | |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 293 | pdev = platform_device_alloc("tpm_nscl0", -1); |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 294 | if (!pdev) { |
| 295 | rc = -ENOMEM; |
| 296 | goto err_unreg_drv; |
| 297 | } |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 298 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 299 | pdev->num_resources = 0; |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 300 | pdev->dev.driver = &nsc_drv.driver; |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 301 | pdev->dev.release = tpm_nsc_remove; |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 302 | |
Stefan Berger | 29412f0 | 2011-07-22 17:39:20 -0400 | [diff] [blame] | 303 | if ((rc = platform_device_add(pdev)) < 0) |
| 304 | goto err_put_dev; |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 305 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 306 | if (request_region(base, 2, "tpm_nsc0") == NULL ) { |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 307 | rc = -EBUSY; |
Stefan Berger | 29412f0 | 2011-07-22 17:39:20 -0400 | [diff] [blame] | 308 | goto err_del_dev; |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 311 | if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_nsc))) { |
| 312 | rc = -ENODEV; |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 313 | goto err_rel_reg; |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 314 | } |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 315 | |
| 316 | dev_dbg(&pdev->dev, "NSC TPM detected\n"); |
| 317 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 319 | tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20), |
| 320 | tpm_read_index(nscAddrBase,0x27)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 321 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 323 | tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25), |
| 324 | tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 325 | dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 326 | (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 327 | dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 328 | (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 329 | dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 330 | tpm_read_index(nscAddrBase,0x70)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 331 | dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 332 | tpm_read_index(nscAddrBase,0x71)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 333 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | "NSC DMA channel select0 0x%x, select1 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 335 | tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 336 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | "NSC Config " |
| 338 | "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 339 | tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1), |
| 340 | tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3), |
| 341 | tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5), |
| 342 | tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7), |
| 343 | tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 345 | dev_info(&pdev->dev, |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 346 | "NSC TPM revision %d\n", |
| 347 | tpm_read_index(nscAddrBase, 0x27) & 0x1F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 349 | chip->vendor.base = base; |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return 0; |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 352 | |
| 353 | err_rel_reg: |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 354 | release_region(base, 2); |
Stefan Berger | 29412f0 | 2011-07-22 17:39:20 -0400 | [diff] [blame] | 355 | err_del_dev: |
| 356 | platform_device_del(pdev); |
| 357 | err_put_dev: |
| 358 | platform_device_put(pdev); |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 359 | err_unreg_drv: |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 360 | platform_driver_unregister(&nsc_drv); |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 361 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static void __exit cleanup_nsc(void) |
| 365 | { |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 366 | if (pdev) { |
| 367 | tpm_nsc_remove(&pdev->dev); |
| 368 | platform_device_unregister(pdev); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 369 | } |
| 370 | |
David Smith | 09f50c9 | 2009-01-07 18:08:57 -0800 | [diff] [blame] | 371 | platform_driver_unregister(&nsc_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | module_init(init_nsc); |
| 375 | module_exit(cleanup_nsc); |
| 376 | |
| 377 | MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); |
| 378 | MODULE_DESCRIPTION("TPM Driver"); |
| 379 | MODULE_VERSION("2.0"); |
| 380 | MODULE_LICENSE("GPL"); |