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 | * |
| 10 | * Maintained by: <tpmdd_devel@lists.sourceforge.net> |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "tpm.h" |
| 24 | |
| 25 | /* National definitions */ |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 26 | enum tpm_nsc_addr{ |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 27 | TPM_NSC_IRQ = 0x07, |
| 28 | TPM_NSC_BASE0_HI = 0x60, |
| 29 | TPM_NSC_BASE0_LO = 0x61, |
| 30 | TPM_NSC_BASE1_HI = 0x62, |
| 31 | TPM_NSC_BASE1_LO = 0x63 |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 32 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 34 | enum tpm_nsc_index { |
| 35 | NSC_LDN_INDEX = 0x07, |
| 36 | NSC_SID_INDEX = 0x20, |
| 37 | NSC_LDC_INDEX = 0x30, |
| 38 | NSC_DIO_INDEX = 0x60, |
| 39 | NSC_CIO_INDEX = 0x62, |
| 40 | NSC_IRQ_INDEX = 0x70, |
| 41 | NSC_ITS_INDEX = 0x71 |
| 42 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 44 | enum tpm_nsc_status_loc { |
| 45 | NSC_STATUS = 0x01, |
| 46 | NSC_COMMAND = 0x01, |
| 47 | NSC_DATA = 0x00 |
| 48 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | /* status bits */ |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 51 | enum tpm_nsc_status { |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 52 | NSC_STATUS_OBF = 0x01, /* output buffer full */ |
| 53 | NSC_STATUS_IBF = 0x02, /* input buffer full */ |
| 54 | NSC_STATUS_F0 = 0x04, /* F0 */ |
| 55 | NSC_STATUS_A2 = 0x08, /* A2 */ |
| 56 | NSC_STATUS_RDY = 0x10, /* ready to receive command */ |
| 57 | NSC_STATUS_IBR = 0x20 /* ready to receive data */ |
| 58 | }; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* command bits */ |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 61 | enum tpm_nsc_cmd_mode { |
| 62 | NSC_COMMAND_NORMAL = 0x01, /* normal mode */ |
| 63 | NSC_COMMAND_EOC = 0x03, |
| 64 | NSC_COMMAND_CANCEL = 0x22 |
| 65 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Wait for a certain status to appear |
| 68 | */ |
| 69 | static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) |
| 70 | { |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 71 | unsigned long stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* status immediately available check */ |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 74 | *data = inb(chip->vendor.base + NSC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if ((*data & mask) == val) |
| 76 | return 0; |
| 77 | |
| 78 | /* wait for status */ |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 79 | stop = jiffies + 10 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | do { |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 81 | msleep(TPM_TIMEOUT); |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 82 | *data = inb(chip->vendor.base + 1); |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 83 | if ((*data & mask) == val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 86 | while (time_before(jiffies, stop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | return -EBUSY; |
| 89 | } |
| 90 | |
| 91 | static int nsc_wait_for_ready(struct tpm_chip *chip) |
| 92 | { |
| 93 | int status; |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 94 | unsigned long stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* status immediately available check */ |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 97 | status = inb(chip->vendor.base + NSC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (status & NSC_STATUS_OBF) |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 99 | status = inb(chip->vendor.base + NSC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (status & NSC_STATUS_RDY) |
| 101 | return 0; |
| 102 | |
| 103 | /* wait for status */ |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 104 | stop = jiffies + 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | do { |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 106 | msleep(TPM_TIMEOUT); |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 107 | status = inb(chip->vendor.base + NSC_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | if (status & NSC_STATUS_OBF) |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 109 | status = inb(chip->vendor.base + NSC_DATA); |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 110 | if (status & NSC_STATUS_RDY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 113 | while (time_before(jiffies, stop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 115 | dev_info(chip->dev, "wait for ready failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return -EBUSY; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) |
| 121 | { |
| 122 | u8 *buffer = buf; |
| 123 | u8 data, *p; |
| 124 | u32 size; |
| 125 | __be32 *native_size; |
| 126 | |
| 127 | if (count < 6) |
| 128 | return -EIO; |
| 129 | |
| 130 | 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] | 131 | dev_err(chip->dev, "F0 timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return -EIO; |
| 133 | } |
| 134 | if ((data = |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 135 | inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 136 | dev_err(chip->dev, "not in normal mode (0x%x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | data); |
| 138 | return -EIO; |
| 139 | } |
| 140 | |
| 141 | /* read the whole packet */ |
| 142 | for (p = buffer; p < &buffer[count]; p++) { |
| 143 | if (wait_for_stat |
| 144 | (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 145 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | "OBF timeout (while reading data)\n"); |
| 147 | return -EIO; |
| 148 | } |
| 149 | if (data & NSC_STATUS_F0) |
| 150 | break; |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 151 | *p = inb(chip->vendor.base + NSC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 154 | if ((data & NSC_STATUS_F0) == 0 && |
| 155 | (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] | 156 | dev_err(chip->dev, "F0 not set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return -EIO; |
| 158 | } |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 159 | if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 160 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | "expected end of command(0x%x)\n", data); |
| 162 | return -EIO; |
| 163 | } |
| 164 | |
| 165 | native_size = (__force __be32 *) (buf + 2); |
| 166 | size = be32_to_cpu(*native_size); |
| 167 | |
| 168 | if (count < size) |
| 169 | return -EIO; |
| 170 | |
| 171 | return size; |
| 172 | } |
| 173 | |
| 174 | static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) |
| 175 | { |
| 176 | u8 data; |
| 177 | int i; |
| 178 | |
| 179 | /* |
| 180 | * If we hit the chip with back to back commands it locks up |
| 181 | * and never set IBF. Hitting it with this "hammer" seems to |
| 182 | * fix it. Not sure why this is needed, we followed the flow |
| 183 | * chart in the manual to the letter. |
| 184 | */ |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 185 | outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | if (nsc_wait_for_ready(chip) != 0) |
| 188 | return -EIO; |
| 189 | |
| 190 | if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 191 | dev_err(chip->dev, "IBF timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return -EIO; |
| 193 | } |
| 194 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 195 | outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | 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] | 197 | dev_err(chip->dev, "IBR timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | return -EIO; |
| 199 | } |
| 200 | |
| 201 | for (i = 0; i < count; i++) { |
| 202 | if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 203 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | "IBF timeout (while writing data)\n"); |
| 205 | return -EIO; |
| 206 | } |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 207 | outb(buf[i], chip->vendor.base + NSC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 211 | dev_err(chip->dev, "IBF timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return -EIO; |
| 213 | } |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 214 | outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | return count; |
| 217 | } |
| 218 | |
| 219 | static void tpm_nsc_cancel(struct tpm_chip *chip) |
| 220 | { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 221 | outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 224 | static u8 tpm_nsc_status(struct tpm_chip *chip) |
| 225 | { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 226 | return inb(chip->vendor.base + NSC_STATUS); |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 229 | static const struct file_operations nsc_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | .owner = THIS_MODULE, |
| 231 | .llseek = no_llseek, |
| 232 | .open = tpm_open, |
| 233 | .read = tpm_read, |
| 234 | .write = tpm_write, |
| 235 | .release = tpm_release, |
| 236 | }; |
| 237 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 238 | static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); |
| 239 | static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); |
| 240 | static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL); |
| 241 | static DEVICE_ATTR(cancel, S_IWUSR|S_IWGRP, NULL, tpm_store_cancel); |
| 242 | |
| 243 | static struct attribute * nsc_attrs[] = { |
| 244 | &dev_attr_pubek.attr, |
| 245 | &dev_attr_pcrs.attr, |
| 246 | &dev_attr_caps.attr, |
| 247 | &dev_attr_cancel.attr, |
Randy Dunlap | 874ec33 | 2005-10-30 15:03:29 -0800 | [diff] [blame] | 248 | NULL, |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs }; |
| 252 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 253 | static const struct tpm_vendor_specific tpm_nsc = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | .recv = tpm_nsc_recv, |
| 255 | .send = tpm_nsc_send, |
| 256 | .cancel = tpm_nsc_cancel, |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 257 | .status = tpm_nsc_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | .req_complete_mask = NSC_STATUS_OBF, |
| 259 | .req_complete_val = NSC_STATUS_OBF, |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 260 | .req_canceled = NSC_STATUS_RDY, |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 261 | .attr_group = &nsc_attr_grp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | .miscdev = { .fops = &nsc_ops, }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 265 | static struct platform_device *pdev = NULL; |
| 266 | |
| 267 | static void __devexit tpm_nsc_remove(struct device *dev) |
| 268 | { |
| 269 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 270 | if ( chip ) { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 271 | release_region(chip->vendor.base, 2); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 272 | tpm_remove_hardware(chip->dev); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | static struct device_driver nsc_drv = { |
| 277 | .name = "tpm_nsc", |
| 278 | .bus = &platform_bus_type, |
| 279 | .owner = THIS_MODULE, |
| 280 | .suspend = tpm_pm_suspend, |
| 281 | .resume = tpm_pm_resume, |
| 282 | }; |
| 283 | |
| 284 | static int __init init_nsc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
| 286 | int rc = 0; |
Kylene Hall | e1a23c6 | 2005-06-23 22:02:06 -0700 | [diff] [blame] | 287 | int lo, hi; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 288 | int nscAddrBase = TPM_ADDR; |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 289 | struct tpm_chip *chip; |
| 290 | unsigned long base; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /* verify that it is a National part (SID) */ |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 293 | if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { |
| 294 | nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)| |
| 295 | (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 296 | if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) |
| 297 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 300 | driver_register(&nsc_drv); |
| 301 | |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 302 | hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); |
| 303 | lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 304 | base = (hi<<8) | lo; |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 305 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 306 | /* enable the DPM module */ |
| 307 | tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); |
| 308 | |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 309 | pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL); |
| 310 | if (!pdev) { |
| 311 | rc = -ENOMEM; |
| 312 | goto err_unreg_drv; |
| 313 | } |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 314 | |
| 315 | pdev->name = "tpm_nscl0"; |
| 316 | pdev->id = -1; |
| 317 | pdev->num_resources = 0; |
| 318 | pdev->dev.release = tpm_nsc_remove; |
| 319 | pdev->dev.driver = &nsc_drv; |
| 320 | |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 321 | if ((rc = platform_device_register(pdev)) < 0) |
| 322 | goto err_free_dev; |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 323 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 324 | if (request_region(base, 2, "tpm_nsc0") == NULL ) { |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 325 | rc = -EBUSY; |
| 326 | goto err_unreg_dev; |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 329 | if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_nsc))) { |
| 330 | rc = -ENODEV; |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 331 | goto err_rel_reg; |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 332 | } |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 333 | |
| 334 | dev_dbg(&pdev->dev, "NSC TPM detected\n"); |
| 335 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 337 | tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20), |
| 338 | tpm_read_index(nscAddrBase,0x27)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 339 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | "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] | 341 | tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25), |
| 342 | tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 343 | dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 344 | (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 345 | dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 346 | (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 347 | 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] | 348 | tpm_read_index(nscAddrBase,0x70)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 349 | dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 350 | tpm_read_index(nscAddrBase,0x71)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 351 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | "NSC DMA channel select0 0x%x, select1 0x%x\n", |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 353 | tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75)); |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 354 | dev_dbg(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | "NSC Config " |
| 356 | "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] | 357 | tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1), |
| 358 | tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3), |
| 359 | tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5), |
| 360 | tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7), |
| 361 | tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 363 | dev_info(&pdev->dev, |
Kylene Jo Hall | daacdfa | 2005-06-25 14:55:39 -0700 | [diff] [blame] | 364 | "NSC TPM revision %d\n", |
| 365 | tpm_read_index(nscAddrBase, 0x27) & 0x1F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 367 | chip->vendor.base = base; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return 0; |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 370 | |
| 371 | err_rel_reg: |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 372 | release_region(base, 2); |
Kylene Jo Hall | e2a8f7a | 2005-11-07 00:59:25 -0800 | [diff] [blame] | 373 | err_unreg_dev: |
| 374 | platform_device_unregister(pdev); |
| 375 | err_free_dev: |
| 376 | kfree(pdev); |
| 377 | err_unreg_drv: |
| 378 | driver_unregister(&nsc_drv); |
| 379 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static void __exit cleanup_nsc(void) |
| 383 | { |
Kylene Jo Hall | 570302a | 2005-10-30 15:03:26 -0800 | [diff] [blame] | 384 | if (pdev) { |
| 385 | tpm_nsc_remove(&pdev->dev); |
| 386 | platform_device_unregister(pdev); |
| 387 | kfree(pdev); |
| 388 | pdev = NULL; |
| 389 | } |
| 390 | |
| 391 | driver_unregister(&nsc_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | module_init(init_nsc); |
| 395 | module_exit(cleanup_nsc); |
| 396 | |
| 397 | MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); |
| 398 | MODULE_DESCRIPTION("TPM Driver"); |
| 399 | MODULE_VERSION("2.0"); |
| 400 | MODULE_LICENSE("GPL"); |