aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKylene Jo Hall <kjhall@us.ibm.com>2005-10-30 18:03:24 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-10-30 20:37:28 -0500
commite659a3fe2027b19ecd8abb7ad79253672763454b (patch)
treec9759f75695a19742693c9719e92253e2cd52b7e /drivers
parentb4ed3e3cbb312869929cf4528d71e52629a6cacb (diff)
[PATCH] tpm: remove pci dependency
Since the tpm does not have it's own pci id we have been consuming the lpc bus. This is not correct and causes problems to support non lpc bus chips. This patch removes the dependency on pci_dev from tpm.c The subsequent patches will stop the supported chips from registering as pci drivers. Signed-off-by: Kylene Hall <kjhall@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/tpm/tpm.c65
-rw-r--r--drivers/char/tpm/tpm.h6
-rw-r--r--drivers/char/tpm/tpm_atmel.c26
-rw-r--r--drivers/char/tpm/tpm_infineon.c34
-rw-r--r--drivers/char/tpm/tpm_nsc.c32
5 files changed, 91 insertions, 72 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 328f2a97916e..75f949b53177 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -64,7 +64,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
64 if (count == 0) 64 if (count == 0)
65 return -ENODATA; 65 return -ENODATA;
66 if (count > bufsiz) { 66 if (count > bufsiz) {
67 dev_err(&chip->pci_dev->dev, 67 dev_err(chip->dev,
68 "invalid count value %x %zx \n", count, bufsiz); 68 "invalid count value %x %zx \n", count, bufsiz);
69 return -E2BIG; 69 return -E2BIG;
70 } 70 }
@@ -72,7 +72,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
72 down(&chip->tpm_mutex); 72 down(&chip->tpm_mutex);
73 73
74 if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { 74 if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) {
75 dev_err(&chip->pci_dev->dev, 75 dev_err(chip->dev,
76 "tpm_transmit: tpm_send: error %zd\n", rc); 76 "tpm_transmit: tpm_send: error %zd\n", rc);
77 goto out; 77 goto out;
78 } 78 }
@@ -86,7 +86,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
86 } 86 }
87 87
88 if ((status == chip->vendor->req_canceled)) { 88 if ((status == chip->vendor->req_canceled)) {
89 dev_err(&chip->pci_dev->dev, "Operation Canceled\n"); 89 dev_err(chip->dev, "Operation Canceled\n");
90 rc = -ECANCELED; 90 rc = -ECANCELED;
91 goto out; 91 goto out;
92 } 92 }
@@ -97,14 +97,14 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
97 97
98 98
99 chip->vendor->cancel(chip); 99 chip->vendor->cancel(chip);
100 dev_err(&chip->pci_dev->dev, "Operation Timed out\n"); 100 dev_err(chip->dev, "Operation Timed out\n");
101 rc = -ETIME; 101 rc = -ETIME;
102 goto out; 102 goto out;
103 103
104out_recv: 104out_recv:
105 rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); 105 rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz);
106 if (rc < 0) 106 if (rc < 0)
107 dev_err(&chip->pci_dev->dev, 107 dev_err(chip->dev,
108 "tpm_transmit: tpm_recv: error %zd\n", rc); 108 "tpm_transmit: tpm_recv: error %zd\n", rc);
109out: 109out:
110 up(&chip->tpm_mutex); 110 up(&chip->tpm_mutex);
@@ -139,15 +139,14 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
139 __be32 index; 139 __be32 index;
140 char *str = buf; 140 char *str = buf;
141 141
142 struct tpm_chip *chip = 142 struct tpm_chip *chip = dev_get_drvdata(dev);
143 pci_get_drvdata(to_pci_dev(dev));
144 if (chip == NULL) 143 if (chip == NULL)
145 return -ENODEV; 144 return -ENODEV;
146 145
147 memcpy(data, cap_pcr, sizeof(cap_pcr)); 146 memcpy(data, cap_pcr, sizeof(cap_pcr));
148 if ((len = tpm_transmit(chip, data, sizeof(data))) 147 if ((len = tpm_transmit(chip, data, sizeof(data)))
149 < CAP_PCR_RESULT_SIZE) { 148 < CAP_PCR_RESULT_SIZE) {
150 dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred " 149 dev_dbg(chip->dev, "A TPM error (%d) occurred "
151 "attempting to determine the number of PCRS\n", 150 "attempting to determine the number of PCRS\n",
152 be32_to_cpu(*((__be32 *) (data + 6)))); 151 be32_to_cpu(*((__be32 *) (data + 6))));
153 return 0; 152 return 0;
@@ -161,7 +160,7 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
161 memcpy(data + 10, &index, 4); 160 memcpy(data + 10, &index, 4);
162 if ((len = tpm_transmit(chip, data, sizeof(data))) 161 if ((len = tpm_transmit(chip, data, sizeof(data)))
163 < READ_PCR_RESULT_SIZE){ 162 < READ_PCR_RESULT_SIZE){
164 dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred" 163 dev_dbg(chip->dev, "A TPM error (%d) occurred"
165 " attempting to read PCR %d of %d\n", 164 " attempting to read PCR %d of %d\n",
166 be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs); 165 be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs);
167 goto out; 166 goto out;
@@ -191,8 +190,7 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
191 int i, rc; 190 int i, rc;
192 char *str = buf; 191 char *str = buf;
193 192
194 struct tpm_chip *chip = 193 struct tpm_chip *chip = dev_get_drvdata(dev);
195 pci_get_drvdata(to_pci_dev(dev));
196 if (chip == NULL) 194 if (chip == NULL)
197 return -ENODEV; 195 return -ENODEV;
198 196
@@ -205,7 +203,7 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
205 203
206 if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) < 204 if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) <
207 READ_PUBEK_RESULT_SIZE) { 205 READ_PUBEK_RESULT_SIZE) {
208 dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred " 206 dev_dbg(chip->dev, "A TPM error (%d) occurred "
209 "attempting to read the PUBEK\n", 207 "attempting to read the PUBEK\n",
210 be32_to_cpu(*((__be32 *) (data + 6)))); 208 be32_to_cpu(*((__be32 *) (data + 6))));
211 rc = 0; 209 rc = 0;
@@ -274,8 +272,7 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
274 ssize_t len; 272 ssize_t len;
275 char *str = buf; 273 char *str = buf;
276 274
277 struct tpm_chip *chip = 275 struct tpm_chip *chip = dev_get_drvdata(dev);
278 pci_get_drvdata(to_pci_dev(dev));
279 if (chip == NULL) 276 if (chip == NULL)
280 return -ENODEV; 277 return -ENODEV;
281 278
@@ -339,21 +336,21 @@ int tpm_open(struct inode *inode, struct file *file)
339 } 336 }
340 337
341 if (chip->num_opens) { 338 if (chip->num_opens) {
342 dev_dbg(&chip->pci_dev->dev, 339 dev_dbg(chip->dev,
343 "Another process owns this TPM\n"); 340 "Another process owns this TPM\n");
344 rc = -EBUSY; 341 rc = -EBUSY;
345 goto err_out; 342 goto err_out;
346 } 343 }
347 344
348 chip->num_opens++; 345 chip->num_opens++;
349 pci_dev_get(chip->pci_dev); 346 get_device(chip->dev);
350 347
351 spin_unlock(&driver_lock); 348 spin_unlock(&driver_lock);
352 349
353 chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); 350 chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
354 if (chip->data_buffer == NULL) { 351 if (chip->data_buffer == NULL) {
355 chip->num_opens--; 352 chip->num_opens--;
356 pci_dev_put(chip->pci_dev); 353 put_device(chip->dev);
357 return -ENOMEM; 354 return -ENOMEM;
358 } 355 }
359 356
@@ -378,7 +375,7 @@ int tpm_release(struct inode *inode, struct file *file)
378 chip->num_opens--; 375 chip->num_opens--;
379 del_singleshot_timer_sync(&chip->user_read_timer); 376 del_singleshot_timer_sync(&chip->user_read_timer);
380 atomic_set(&chip->data_pending, 0); 377 atomic_set(&chip->data_pending, 0);
381 pci_dev_put(chip->pci_dev); 378 put_device(chip->dev);
382 kfree(chip->data_buffer); 379 kfree(chip->data_buffer);
383 spin_unlock(&driver_lock); 380 spin_unlock(&driver_lock);
384 return 0; 381 return 0;
@@ -447,12 +444,12 @@ ssize_t tpm_read(struct file * file, char __user * buf,
447 444
448EXPORT_SYMBOL_GPL(tpm_read); 445EXPORT_SYMBOL_GPL(tpm_read);
449 446
450void __devexit tpm_remove(struct pci_dev *pci_dev) 447void tpm_remove_hardware(struct device *dev)
451{ 448{
452 struct tpm_chip *chip = pci_get_drvdata(pci_dev); 449 struct tpm_chip *chip = dev_get_drvdata(dev);
453 450
454 if (chip == NULL) { 451 if (chip == NULL) {
455 dev_err(&pci_dev->dev, "No device data found\n"); 452 dev_err(dev, "No device data found\n");
456 return; 453 return;
457 } 454 }
458 455
@@ -462,22 +459,20 @@ void __devexit tpm_remove(struct pci_dev *pci_dev)
462 459
463 spin_unlock(&driver_lock); 460 spin_unlock(&driver_lock);
464 461
465 pci_set_drvdata(pci_dev, NULL); 462 dev_set_drvdata(dev, NULL);
466 misc_deregister(&chip->vendor->miscdev); 463 misc_deregister(&chip->vendor->miscdev);
467 kfree(chip->vendor->miscdev.name); 464 kfree(chip->vendor->miscdev.name);
468 465
469 sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group); 466 sysfs_remove_group(&dev->kobj, chip->vendor->attr_group);
470
471 pci_disable_device(pci_dev);
472 467
473 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); 468 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
474 469
475 kfree(chip); 470 kfree(chip);
476 471
477 pci_dev_put(pci_dev); 472 put_device(dev);
478} 473}
479 474
480EXPORT_SYMBOL_GPL(tpm_remove); 475EXPORT_SYMBOL_GPL(tpm_remove_hardware);
481 476
482static u8 savestate[] = { 477static u8 savestate[] = {
483 0, 193, /* TPM_TAG_RQU_COMMAND */ 478 0, 193, /* TPM_TAG_RQU_COMMAND */
@@ -524,7 +519,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
524 * upon errant exit from this function specific probe function should call 519 * upon errant exit from this function specific probe function should call
525 * pci_disable_device 520 * pci_disable_device
526 */ 521 */
527int tpm_register_hardware(struct pci_dev *pci_dev, 522int tpm_register_hardware(struct device *dev,
528 struct tpm_vendor_specific *entry) 523 struct tpm_vendor_specific *entry)
529{ 524{
530#define DEVNAME_SIZE 7 525#define DEVNAME_SIZE 7
@@ -563,7 +558,7 @@ int tpm_register_hardware(struct pci_dev *pci_dev,
563 558
564dev_num_search_complete: 559dev_num_search_complete:
565 if (chip->dev_num < 0) { 560 if (chip->dev_num < 0) {
566 dev_err(&pci_dev->dev, 561 dev_err(dev,
567 "No available tpm device numbers\n"); 562 "No available tpm device numbers\n");
568 kfree(chip); 563 kfree(chip);
569 return -ENODEV; 564 return -ENODEV;
@@ -576,15 +571,15 @@ dev_num_search_complete:
576 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); 571 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
577 chip->vendor->miscdev.name = devname; 572 chip->vendor->miscdev.name = devname;
578 573
579 chip->vendor->miscdev.dev = &(pci_dev->dev); 574 chip->vendor->miscdev.dev = dev;
580 chip->pci_dev = pci_dev_get(pci_dev); 575 chip->dev = get_device(dev);
581 576
582 if (misc_register(&chip->vendor->miscdev)) { 577 if (misc_register(&chip->vendor->miscdev)) {
583 dev_err(&chip->pci_dev->dev, 578 dev_err(chip->dev,
584 "unable to misc_register %s, minor %d\n", 579 "unable to misc_register %s, minor %d\n",
585 chip->vendor->miscdev.name, 580 chip->vendor->miscdev.name,
586 chip->vendor->miscdev.minor); 581 chip->vendor->miscdev.minor);
587 pci_dev_put(pci_dev); 582 put_device(dev);
588 kfree(chip); 583 kfree(chip);
589 dev_mask[i] &= !(1 << j); 584 dev_mask[i] &= !(1 << j);
590 return -ENODEV; 585 return -ENODEV;
@@ -592,13 +587,13 @@ dev_num_search_complete:
592 587
593 spin_lock(&driver_lock); 588 spin_lock(&driver_lock);
594 589
595 pci_set_drvdata(pci_dev, chip); 590 dev_set_drvdata(dev, chip);
596 591
597 list_add(&chip->list, &tpm_chip_list); 592 list_add(&chip->list, &tpm_chip_list);
598 593
599 spin_unlock(&driver_lock); 594 spin_unlock(&driver_lock);
600 595
601 sysfs_create_group(&pci_dev->dev.kobj, chip->vendor->attr_group); 596 sysfs_create_group(&dev->kobj, chip->vendor->attr_group);
602 597
603 return 0; 598 return 0;
604} 599}
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index ba70bf519fc9..27bc8ccb931a 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -61,7 +61,7 @@ struct tpm_vendor_specific {
61}; 61};
62 62
63struct tpm_chip { 63struct tpm_chip {
64 struct pci_dev *pci_dev; /* PCI device stuff */ 64 struct device *dev; /* Device stuff */
65 65
66 int dev_num; /* /dev/tpm# */ 66 int dev_num; /* /dev/tpm# */
67 int num_opens; /* only one allowed */ 67 int num_opens; /* only one allowed */
@@ -92,13 +92,13 @@ static inline void tpm_write_index(int base, int index, int value)
92 outb(value & 0xFF, base+1); 92 outb(value & 0xFF, base+1);
93} 93}
94 94
95extern int tpm_register_hardware(struct pci_dev *, 95extern int tpm_register_hardware(struct device *,
96 struct tpm_vendor_specific *); 96 struct tpm_vendor_specific *);
97extern int tpm_open(struct inode *, struct file *); 97extern int tpm_open(struct inode *, struct file *);
98extern int tpm_release(struct inode *, struct file *); 98extern int tpm_release(struct inode *, struct file *);
99extern ssize_t tpm_write(struct file *, const char __user *, size_t, 99extern ssize_t tpm_write(struct file *, const char __user *, size_t,
100 loff_t *); 100 loff_t *);
101extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *); 101extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
102extern void __devexit tpm_remove(struct pci_dev *); 102extern void tpm_remove_hardware(struct device *);
103extern int tpm_pm_suspend(struct pci_dev *, pm_message_t); 103extern int tpm_pm_suspend(struct pci_dev *, pm_message_t);
104extern int tpm_pm_resume(struct pci_dev *); 104extern int tpm_pm_resume(struct pci_dev *);
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index 96ab9003047c..44b08ba6fc9d 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -54,7 +54,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
54 for (i = 0; i < 6; i++) { 54 for (i = 0; i < 6; i++) {
55 status = inb(chip->vendor->base + 1); 55 status = inb(chip->vendor->base + 1);
56 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 56 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
57 dev_err(&chip->pci_dev->dev, 57 dev_err(chip->dev,
58 "error reading header\n"); 58 "error reading header\n");
59 return -EIO; 59 return -EIO;
60 } 60 }
@@ -66,12 +66,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
66 size = be32_to_cpu(*native_size); 66 size = be32_to_cpu(*native_size);
67 67
68 if (count < size) { 68 if (count < size) {
69 dev_err(&chip->pci_dev->dev, 69 dev_err(chip->dev,
70 "Recv size(%d) less than available space\n", size); 70 "Recv size(%d) less than available space\n", size);
71 for (; i < size; i++) { /* clear the waiting data anyway */ 71 for (; i < size; i++) { /* clear the waiting data anyway */
72 status = inb(chip->vendor->base + 1); 72 status = inb(chip->vendor->base + 1);
73 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 73 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
74 dev_err(&chip->pci_dev->dev, 74 dev_err(chip->dev,
75 "error reading data\n"); 75 "error reading data\n");
76 return -EIO; 76 return -EIO;
77 } 77 }
@@ -83,7 +83,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
83 for (; i < size; i++) { 83 for (; i < size; i++) {
84 status = inb(chip->vendor->base + 1); 84 status = inb(chip->vendor->base + 1);
85 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 85 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
86 dev_err(&chip->pci_dev->dev, 86 dev_err(chip->dev,
87 "error reading data\n"); 87 "error reading data\n");
88 return -EIO; 88 return -EIO;
89 } 89 }
@@ -93,7 +93,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
93 /* make sure data available is gone */ 93 /* make sure data available is gone */
94 status = inb(chip->vendor->base + 1); 94 status = inb(chip->vendor->base + 1);
95 if (status & ATML_STATUS_DATA_AVAIL) { 95 if (status & ATML_STATUS_DATA_AVAIL) {
96 dev_err(&chip->pci_dev->dev, "data available is stuck\n"); 96 dev_err(chip->dev, "data available is stuck\n");
97 return -EIO; 97 return -EIO;
98 } 98 }
99 99
@@ -104,9 +104,9 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 * buf, size_t count)
104{ 104{
105 int i; 105 int i;
106 106
107 dev_dbg(&chip->pci_dev->dev, "tpm_atml_send: "); 107 dev_dbg(chip->dev, "tpm_atml_send:\n");
108 for (i = 0; i < count; i++) { 108 for (i = 0; i < count; i++) {
109 dev_dbg(&chip->pci_dev->dev, "0x%x(%d) ", buf[i], buf[i]); 109 dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
110 outb(buf[i], chip->vendor->base); 110 outb(buf[i], chip->vendor->base);
111 } 111 }
112 112
@@ -193,7 +193,7 @@ static int __devinit tpm_atml_init(struct pci_dev *pci_dev,
193 goto out_err; 193 goto out_err;
194 } 194 }
195 195
196 if ((rc = tpm_register_hardware(pci_dev, &tpm_atmel)) < 0) 196 if ((rc = tpm_register_hardware(&pci_dev->dev, &tpm_atmel)) < 0)
197 goto out_err; 197 goto out_err;
198 198
199 dev_info(&pci_dev->dev, 199 dev_info(&pci_dev->dev,
@@ -206,6 +206,14 @@ out_err:
206 return rc; 206 return rc;
207} 207}
208 208
209static void __devexit tpm_atml_remove(struct pci_dev *pci_dev)
210{
211 struct tpm_chip *chip = pci_get_drvdata(pci_dev);
212
213 if ( chip )
214 tpm_remove_hardware(chip->dev);
215}
216
209static struct pci_device_id tpm_pci_tbl[] __devinitdata = { 217static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
210 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, 218 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
211 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, 219 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
@@ -226,7 +234,7 @@ static struct pci_driver atmel_pci_driver = {
226 .name = "tpm_atmel", 234 .name = "tpm_atmel",
227 .id_table = tpm_pci_tbl, 235 .id_table = tpm_pci_tbl,
228 .probe = tpm_atml_init, 236 .probe = tpm_atml_init,
229 .remove = __devexit_p(tpm_remove), 237 .remove = __devexit_p(tpm_atml_remove),
230 .suspend = tpm_pm_suspend, 238 .suspend = tpm_pm_suspend,
231 .resume = tpm_pm_resume, 239 .resume = tpm_pm_resume,
232}; 240};
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index 5b2ed539c26f..5c3aeaffaf88 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -143,10 +143,10 @@ static int wait(struct tpm_chip *chip, int wait_for_bit)
143 } 143 }
144 if (i == TPM_MAX_TRIES) { /* timeout occurs */ 144 if (i == TPM_MAX_TRIES) { /* timeout occurs */
145 if (wait_for_bit == STAT_XFE) 145 if (wait_for_bit == STAT_XFE)
146 dev_err(&chip->pci_dev->dev, 146 dev_err(chip->dev,
147 "Timeout in wait(STAT_XFE)\n"); 147 "Timeout in wait(STAT_XFE)\n");
148 if (wait_for_bit == STAT_RDA) 148 if (wait_for_bit == STAT_RDA)
149 dev_err(&chip->pci_dev->dev, 149 dev_err(chip->dev,
150 "Timeout in wait(STAT_RDA)\n"); 150 "Timeout in wait(STAT_RDA)\n");
151 return -EIO; 151 return -EIO;
152 } 152 }
@@ -170,7 +170,7 @@ static void wait_and_send(struct tpm_chip *chip, u8 sendbyte)
170static void tpm_wtx(struct tpm_chip *chip) 170static void tpm_wtx(struct tpm_chip *chip)
171{ 171{
172 number_of_wtx++; 172 number_of_wtx++;
173 dev_info(&chip->pci_dev->dev, "Granting WTX (%02d / %02d)\n", 173 dev_info(chip->dev, "Granting WTX (%02d / %02d)\n",
174 number_of_wtx, TPM_MAX_WTX_PACKAGES); 174 number_of_wtx, TPM_MAX_WTX_PACKAGES);
175 wait_and_send(chip, TPM_VL_VER); 175 wait_and_send(chip, TPM_VL_VER);
176 wait_and_send(chip, TPM_CTRL_WTX); 176 wait_and_send(chip, TPM_CTRL_WTX);
@@ -181,7 +181,7 @@ static void tpm_wtx(struct tpm_chip *chip)
181 181
182static void tpm_wtx_abort(struct tpm_chip *chip) 182static void tpm_wtx_abort(struct tpm_chip *chip)
183{ 183{
184 dev_info(&chip->pci_dev->dev, "Aborting WTX\n"); 184 dev_info(chip->dev, "Aborting WTX\n");
185 wait_and_send(chip, TPM_VL_VER); 185 wait_and_send(chip, TPM_VL_VER);
186 wait_and_send(chip, TPM_CTRL_WTX_ABORT); 186 wait_and_send(chip, TPM_CTRL_WTX_ABORT);
187 wait_and_send(chip, 0x00); 187 wait_and_send(chip, 0x00);
@@ -206,7 +206,7 @@ recv_begin:
206 } 206 }
207 207
208 if (buf[0] != TPM_VL_VER) { 208 if (buf[0] != TPM_VL_VER) {
209 dev_err(&chip->pci_dev->dev, 209 dev_err(chip->dev,
210 "Wrong transport protocol implementation!\n"); 210 "Wrong transport protocol implementation!\n");
211 return -EIO; 211 return -EIO;
212 } 212 }
@@ -221,7 +221,7 @@ recv_begin:
221 } 221 }
222 222
223 if ((size == 0x6D00) && (buf[1] == 0x80)) { 223 if ((size == 0x6D00) && (buf[1] == 0x80)) {
224 dev_err(&chip->pci_dev->dev, 224 dev_err(chip->dev,
225 "Error handling on vendor layer!\n"); 225 "Error handling on vendor layer!\n");
226 return -EIO; 226 return -EIO;
227 } 227 }
@@ -234,7 +234,7 @@ recv_begin:
234 } 234 }
235 235
236 if (buf[1] == TPM_CTRL_WTX) { 236 if (buf[1] == TPM_CTRL_WTX) {
237 dev_info(&chip->pci_dev->dev, "WTX-package received\n"); 237 dev_info(chip->dev, "WTX-package received\n");
238 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) { 238 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) {
239 tpm_wtx(chip); 239 tpm_wtx(chip);
240 goto recv_begin; 240 goto recv_begin;
@@ -245,14 +245,14 @@ recv_begin:
245 } 245 }
246 246
247 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) { 247 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) {
248 dev_info(&chip->pci_dev->dev, "WTX-abort acknowledged\n"); 248 dev_info(chip->dev, "WTX-abort acknowledged\n");
249 return size; 249 return size;
250 } 250 }
251 251
252 if (buf[1] == TPM_CTRL_ERROR) { 252 if (buf[1] == TPM_CTRL_ERROR) {
253 dev_err(&chip->pci_dev->dev, "ERROR-package received:\n"); 253 dev_err(chip->dev, "ERROR-package received:\n");
254 if (buf[4] == TPM_INF_NAK) 254 if (buf[4] == TPM_INF_NAK)
255 dev_err(&chip->pci_dev->dev, 255 dev_err(chip->dev,
256 "-> Negative acknowledgement" 256 "-> Negative acknowledgement"
257 " - retransmit command!\n"); 257 " - retransmit command!\n");
258 return -EIO; 258 return -EIO;
@@ -271,7 +271,7 @@ static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)
271 271
272 ret = empty_fifo(chip, 1); 272 ret = empty_fifo(chip, 1);
273 if (ret) { 273 if (ret) {
274 dev_err(&chip->pci_dev->dev, "Timeout while clearing FIFO\n"); 274 dev_err(chip->dev, "Timeout while clearing FIFO\n");
275 return -EIO; 275 return -EIO;
276 } 276 }
277 277
@@ -494,7 +494,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
494 vendorid[0], vendorid[1], 494 vendorid[0], vendorid[1],
495 productid[0], productid[1], chipname); 495 productid[0], productid[1], chipname);
496 496
497 rc = tpm_register_hardware(pci_dev, &tpm_inf); 497 rc = tpm_register_hardware(&pci_dev->dev, &tpm_inf);
498 if (rc < 0) 498 if (rc < 0)
499 goto error; 499 goto error;
500 return 0; 500 return 0;
@@ -509,6 +509,14 @@ error2:
509 } 509 }
510} 510}
511 511
512static __devexit void tpm_inf_remove(struct pci_dev* pci_dev)
513{
514 struct tpm_chip* chip = pci_get_drvdata(pci_dev);
515
516 if( chip )
517 tpm_remove_hardware(chip->dev);
518}
519
512static struct pci_device_id tpm_pci_tbl[] __devinitdata = { 520static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
513 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, 521 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
514 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, 522 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
@@ -527,7 +535,7 @@ static struct pci_driver inf_pci_driver = {
527 .name = "tpm_inf", 535 .name = "tpm_inf",
528 .id_table = tpm_pci_tbl, 536 .id_table = tpm_pci_tbl,
529 .probe = tpm_inf_probe, 537 .probe = tpm_inf_probe,
530 .remove = __devexit_p(tpm_remove), 538 .remove = __devexit_p(tpm_inf_remove),
531 .suspend = tpm_pm_suspend, 539 .suspend = tpm_pm_suspend,
532 .resume = tpm_pm_resume, 540 .resume = tpm_pm_resume,
533}; 541};
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index bf3e774c4dce..10202d0bc1c7 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -111,7 +111,7 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
111 } 111 }
112 while (time_before(jiffies, stop)); 112 while (time_before(jiffies, stop));
113 113
114 dev_info(&chip->pci_dev->dev, "wait for ready failed\n"); 114 dev_info(chip->dev, "wait for ready failed\n");
115 return -EBUSY; 115 return -EBUSY;
116} 116}
117 117
@@ -127,12 +127,12 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
127 return -EIO; 127 return -EIO;
128 128
129 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) { 129 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
130 dev_err(&chip->pci_dev->dev, "F0 timeout\n"); 130 dev_err(chip->dev, "F0 timeout\n");
131 return -EIO; 131 return -EIO;
132 } 132 }
133 if ((data = 133 if ((data =
134 inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) { 134 inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
135 dev_err(&chip->pci_dev->dev, "not in normal mode (0x%x)\n", 135 dev_err(chip->dev, "not in normal mode (0x%x)\n",
136 data); 136 data);
137 return -EIO; 137 return -EIO;
138 } 138 }
@@ -141,7 +141,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
141 for (p = buffer; p < &buffer[count]; p++) { 141 for (p = buffer; p < &buffer[count]; p++) {
142 if (wait_for_stat 142 if (wait_for_stat
143 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) { 143 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
144 dev_err(&chip->pci_dev->dev, 144 dev_err(chip->dev,
145 "OBF timeout (while reading data)\n"); 145 "OBF timeout (while reading data)\n");
146 return -EIO; 146 return -EIO;
147 } 147 }
@@ -152,11 +152,11 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
152 152
153 if ((data & NSC_STATUS_F0) == 0 && 153 if ((data & NSC_STATUS_F0) == 0 &&
154 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) { 154 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
155 dev_err(&chip->pci_dev->dev, "F0 not set\n"); 155 dev_err(chip->dev, "F0 not set\n");
156 return -EIO; 156 return -EIO;
157 } 157 }
158 if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) { 158 if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) {
159 dev_err(&chip->pci_dev->dev, 159 dev_err(chip->dev,
160 "expected end of command(0x%x)\n", data); 160 "expected end of command(0x%x)\n", data);
161 return -EIO; 161 return -EIO;
162 } 162 }
@@ -187,19 +187,19 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
187 return -EIO; 187 return -EIO;
188 188
189 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 189 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
190 dev_err(&chip->pci_dev->dev, "IBF timeout\n"); 190 dev_err(chip->dev, "IBF timeout\n");
191 return -EIO; 191 return -EIO;
192 } 192 }
193 193
194 outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND); 194 outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND);
195 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { 195 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
196 dev_err(&chip->pci_dev->dev, "IBR timeout\n"); 196 dev_err(chip->dev, "IBR timeout\n");
197 return -EIO; 197 return -EIO;
198 } 198 }
199 199
200 for (i = 0; i < count; i++) { 200 for (i = 0; i < count; i++) {
201 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 201 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
202 dev_err(&chip->pci_dev->dev, 202 dev_err(chip->dev,
203 "IBF timeout (while writing data)\n"); 203 "IBF timeout (while writing data)\n");
204 return -EIO; 204 return -EIO;
205 } 205 }
@@ -207,7 +207,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
207 } 207 }
208 208
209 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 209 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
210 dev_err(&chip->pci_dev->dev, "IBF timeout\n"); 210 dev_err(chip->dev, "IBF timeout\n");
211 return -EIO; 211 return -EIO;
212 } 212 }
213 outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND); 213 outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND);
@@ -325,7 +325,7 @@ static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
325 /* enable the DPM module */ 325 /* enable the DPM module */
326 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); 326 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
327 327
328 if ((rc = tpm_register_hardware(pci_dev, &tpm_nsc)) < 0) 328 if ((rc = tpm_register_hardware(&pci_dev->dev, &tpm_nsc)) < 0)
329 goto out_err; 329 goto out_err;
330 330
331 return 0; 331 return 0;
@@ -335,6 +335,14 @@ out_err:
335 return rc; 335 return rc;
336} 336}
337 337
338static void __devexit tpm_nsc_remove(struct pci_dev *pci_dev)
339{
340 struct tpm_chip *chip = pci_get_drvdata(pci_dev);
341
342 if ( chip )
343 tpm_remove_hardware(chip->dev);
344}
345
338static struct pci_device_id tpm_pci_tbl[] __devinitdata = { 346static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
339 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, 347 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
340 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, 348 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
@@ -354,7 +362,7 @@ static struct pci_driver nsc_pci_driver = {
354 .name = "tpm_nsc", 362 .name = "tpm_nsc",
355 .id_table = tpm_pci_tbl, 363 .id_table = tpm_pci_tbl,
356 .probe = tpm_nsc_init, 364 .probe = tpm_nsc_init,
357 .remove = __devexit_p(tpm_remove), 365 .remove = __devexit_p(tpm_nsc_remove),
358 .suspend = tpm_pm_suspend, 366 .suspend = tpm_pm_suspend,
359 .resume = tpm_pm_resume, 367 .resume = tpm_pm_resume,
360}; 368};