]> err.no Git - linux-2.6/blobdiff - drivers/char/tpm/tpm_nsc.c
Merge branch 'for-2.6.26' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer...
[linux-2.6] / drivers / char / tpm / tpm_nsc.c
index 6adfc07d0fd6d5b87fe36276abc572cda76088a9..ab18c1e7b115fd098ef56599241560d67fb19597 100644 (file)
@@ -7,7 +7,7 @@
  * Reiner Sailer <sailer@watson.ibm.com>
  * Kylene Hall <kjhall@us.ibm.com>
  *
- * Maintained by: <tpmdd_devel@lists.sourceforge.net>
+ * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  *
  * Device driver for TCG/TCPA TPM (trusted platform module).
  * Specifications at www.trustedcomputinggroup.org      
@@ -19,6 +19,7 @@
  * 
  */
 
+#include <linux/platform_device.h>
 #include "tpm.h"
 
 /* National definitions */
@@ -70,7 +71,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
        unsigned long stop;
 
        /* status immediately available check */
-       *data = inb(chip->vendor->base + NSC_STATUS);
+       *data = inb(chip->vendor.base + NSC_STATUS);
        if ((*data & mask) == val)
                return 0;
 
@@ -78,7 +79,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
        stop = jiffies + 10 * HZ;
        do {
                msleep(TPM_TIMEOUT);
-               *data = inb(chip->vendor->base + 1);
+               *data = inb(chip->vendor.base + 1);
                if ((*data & mask) == val)
                        return 0;
        }
@@ -93,9 +94,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
        unsigned long stop;
 
        /* status immediately available check */
-       status = inb(chip->vendor->base + NSC_STATUS);
+       status = inb(chip->vendor.base + NSC_STATUS);
        if (status & NSC_STATUS_OBF)
-               status = inb(chip->vendor->base + NSC_DATA);
+               status = inb(chip->vendor.base + NSC_DATA);
        if (status & NSC_STATUS_RDY)
                return 0;
 
@@ -103,9 +104,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
        stop = jiffies + 100;
        do {
                msleep(TPM_TIMEOUT);
-               status = inb(chip->vendor->base + NSC_STATUS);
+               status = inb(chip->vendor.base + NSC_STATUS);
                if (status & NSC_STATUS_OBF)
-                       status = inb(chip->vendor->base + NSC_DATA);
+                       status = inb(chip->vendor.base + NSC_DATA);
                if (status & NSC_STATUS_RDY)
                        return 0;
        }
@@ -131,7 +132,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
                return -EIO;
        }
        if ((data =
-            inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
+            inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
                dev_err(chip->dev, "not in normal mode (0x%x)\n",
                        data);
                return -EIO;
@@ -147,7 +148,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
                }
                if (data & NSC_STATUS_F0)
                        break;
-               *p = inb(chip->vendor->base + NSC_DATA);
+               *p = inb(chip->vendor.base + NSC_DATA);
        }
 
        if ((data & NSC_STATUS_F0) == 0 &&
@@ -155,7 +156,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
                dev_err(chip->dev, "F0 not set\n");
                return -EIO;
        }
-       if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) {
+       if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
                dev_err(chip->dev,
                        "expected end of command(0x%x)\n", data);
                return -EIO;
@@ -181,7 +182,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
         * fix it. Not sure why this is needed, we followed the flow
         * chart in the manual to the letter.
         */
-       outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND);
+       outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
 
        if (nsc_wait_for_ready(chip) != 0)
                return -EIO;
@@ -191,7 +192,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
                return -EIO;
        }
 
-       outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND);
+       outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND);
        if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
                dev_err(chip->dev, "IBR timeout\n");
                return -EIO;
@@ -203,29 +204,29 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
                                "IBF timeout (while writing data)\n");
                        return -EIO;
                }
-               outb(buf[i], chip->vendor->base + NSC_DATA);
+               outb(buf[i], chip->vendor.base + NSC_DATA);
        }
 
        if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
                dev_err(chip->dev, "IBF timeout\n");
                return -EIO;
        }
-       outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND);
+       outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND);
 
        return count;
 }
 
 static void tpm_nsc_cancel(struct tpm_chip *chip)
 {
-       outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND);
+       outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
 }
 
 static u8 tpm_nsc_status(struct tpm_chip *chip)
 {
-       return inb(chip->vendor->base + NSC_STATUS);
+       return inb(chip->vendor.base + NSC_STATUS);
 }
 
-static struct file_operations nsc_ops = {
+static const struct file_operations nsc_ops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .open = tpm_open,
@@ -244,12 +245,12 @@ static struct attribute * nsc_attrs[] = {
        &dev_attr_pcrs.attr,
        &dev_attr_caps.attr,
        &dev_attr_cancel.attr,
-       0,
+       NULL,
 };
 
 static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs };
 
-static struct tpm_vendor_specific tpm_nsc = {
+static const struct tpm_vendor_specific tpm_nsc = {
        .recv = tpm_nsc_recv,
        .send = tpm_nsc_send,
        .cancel = tpm_nsc_cancel,
@@ -263,11 +264,11 @@ static struct tpm_vendor_specific tpm_nsc = {
 
 static struct platform_device *pdev = NULL;
 
-static void __devexit tpm_nsc_remove(struct device *dev)
+static void tpm_nsc_remove(struct device *dev)
 {
        struct tpm_chip *chip = dev_get_drvdata(dev);
        if ( chip ) {
-               release_region(chip->vendor->base, 2);
+               release_region(chip->vendor.base, 2);
                tpm_remove_hardware(chip->dev);
        }
 }
@@ -283,13 +284,10 @@ static struct device_driver nsc_drv = {
 static int __init init_nsc(void)
 {
        int rc = 0;
-       int lo, hi;
+       int lo, hi, err;
        int nscAddrBase = TPM_ADDR;
-
-       driver_register(&nsc_drv);
-
-       /* select PM channel 1 */
-       tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12);
+       struct tpm_chip *chip;
+       unsigned long base;
 
        /* verify that it is a National part (SID) */
        if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
@@ -299,18 +297,22 @@ static int __init init_nsc(void)
                        return -ENODEV;
        }
 
+       err = driver_register(&nsc_drv);
+       if (err)
+               return err;
+
        hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
        lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
-       tpm_nsc.base = (hi<<8) | lo;
+       base = (hi<<8) | lo;
 
        /* enable the DPM module */
        tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
 
-       pdev = kmalloc(sizeof(struct platform_device), GFP_KERNEL);
-       if ( !pdev )
-               return -ENOMEM;
-
-       memset(pdev, 0, sizeof(struct platform_device));
+       pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
+       if (!pdev) {
+               rc = -ENOMEM;
+               goto err_unreg_drv;
+       }
 
        pdev->name = "tpm_nscl0";
        pdev->id = -1;
@@ -318,25 +320,17 @@ static int __init init_nsc(void)
        pdev->dev.release = tpm_nsc_remove;
        pdev->dev.driver = &nsc_drv;
 
-       if ((rc=platform_device_register(pdev)) < 0) {
-               kfree(pdev);
-               pdev = NULL;
-               return rc;
-       }
+       if ((rc = platform_device_register(pdev)) < 0)
+               goto err_free_dev;
 
-       if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) {
-               platform_device_unregister(pdev);
-               kfree(pdev);
-               pdev = NULL;
-               return -EBUSY;
+       if (request_region(base, 2, "tpm_nsc0") == NULL ) {
+               rc = -EBUSY;
+               goto err_unreg_dev;
        }
 
-       if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) {
-               release_region(tpm_nsc.base, 2);
-               platform_device_unregister(pdev);
-               kfree(pdev);
-               pdev = NULL;
-               return rc;
+       if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_nsc))) {
+               rc = -ENODEV;
+               goto err_rel_reg;
        }
 
        dev_dbg(&pdev->dev, "NSC TPM detected\n");
@@ -372,7 +366,19 @@ static int __init init_nsc(void)
                 "NSC TPM revision %d\n",
                 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
 
+       chip->vendor.base = base;
+
        return 0;
+
+err_rel_reg:
+       release_region(base, 2);
+err_unreg_dev:
+       platform_device_unregister(pdev);
+err_free_dev:
+       kfree(pdev);
+err_unreg_drv:
+       driver_unregister(&nsc_drv);
+       return rc;
 }
 
 static void __exit cleanup_nsc(void)