]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/tpm/tpm_atmel.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / drivers / char / tpm / tpm_atmel.c
index 32e01450c4253bd4b5f9e3ddb1d3ce21d3f8752c..d0e7926eb4865d31b906fab70ef266c1dbf7bbdb 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      
  * 
  */
 
-#include <linux/platform_device.h>
 #include "tpm.h"
-
-/* Atmel definitions */
-enum tpm_atmel_addr {
-       TPM_ATMEL_BASE_ADDR_LO = 0x08,
-       TPM_ATMEL_BASE_ADDR_HI = 0x09
-};
+#include "tpm_atmel.h"
 
 /* write status bits */
 enum tpm_atmel_write_status {
@@ -53,13 +47,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
                return -EIO;
 
        for (i = 0; i < 6; i++) {
-               status = inb(chip->vendor->base + 1);
+               status = ioread8(chip->vendor.iobase + 1);
                if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
-                       dev_err(chip->dev,
-                               "error reading header\n");
+                       dev_err(chip->dev, "error reading header\n");
                        return -EIO;
                }
-               *buf++ = inb(chip->vendor->base);
+               *buf++ = ioread8(chip->vendor.iobase);
        }
 
        /* size of the data received */
@@ -70,10 +63,9 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
                dev_err(chip->dev,
                        "Recv size(%d) less than available space\n", size);
                for (; i < size; i++) { /* clear the waiting data anyway */
-                       status = inb(chip->vendor->base + 1);
+                       status = ioread8(chip->vendor.iobase + 1);
                        if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
-                               dev_err(chip->dev,
-                                       "error reading data\n");
+                               dev_err(chip->dev, "error reading data\n");
                                return -EIO;
                        }
                }
@@ -82,17 +74,17 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 
        /* read all the data available */
        for (; i < size; i++) {
-               status = inb(chip->vendor->base + 1);
+               status = ioread8(chip->vendor.iobase + 1);
                if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
-                       dev_err(chip->dev,
-                               "error reading data\n");
+                       dev_err(chip->dev, "error reading data\n");
                        return -EIO;
                }
-               *buf++ = inb(chip->vendor->base);
+               *buf++ = ioread8(chip->vendor.iobase);
        }
 
        /* make sure data available is gone */
-       status = inb(chip->vendor->base + 1);
+       status = ioread8(chip->vendor.iobase + 1);
+
        if (status & ATML_STATUS_DATA_AVAIL) {
                dev_err(chip->dev, "data available is stuck\n");
                return -EIO;
@@ -108,7 +100,7 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
        dev_dbg(chip->dev, "tpm_atml_send:\n");
        for (i = 0; i < count; i++) {
                dev_dbg(chip->dev, "%d 0x%x(%d)\n",  i, buf[i], buf[i]);
-               outb(buf[i], chip->vendor->base);
+               iowrite8(buf[i], chip->vendor.iobase);
        }
 
        return count;
@@ -116,15 +108,15 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
 
 static void tpm_atml_cancel(struct tpm_chip *chip)
 {
-       outb(ATML_STATUS_ABORT, chip->vendor->base + 1);
+       iowrite8(ATML_STATUS_ABORT, chip->vendor.iobase + 1);
 }
 
 static u8 tpm_atml_status(struct tpm_chip *chip)
 {
-       return inb(chip->vendor->base + 1);
+       return ioread8(chip->vendor.iobase + 1);
 }
 
-static struct file_operations atmel_ops = {
+static const struct file_operations atmel_ops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .open = tpm_open,
@@ -148,7 +140,7 @@ static struct attribute* atmel_attrs[] = {
 
 static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
 
-static struct tpm_vendor_specific tpm_atmel = {
+static const struct tpm_vendor_specific tpm_atmel = {
        .recv = tpm_atml_recv,
        .send = tpm_atml_send,
        .cancel = tpm_atml_cancel,
@@ -162,12 +154,17 @@ static struct tpm_vendor_specific tpm_atmel = {
 
 static struct platform_device *pdev;
 
-static void __devexit tpm_atml_remove(struct device *dev)
+static void atml_plat_remove(void)
 {
-       struct tpm_chip *chip = dev_get_drvdata(dev);
+       struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
+
        if (chip) {
-               release_region(chip->vendor->base, 2);
+               if (chip->vendor.have_region)
+                       atmel_release_region(chip->vendor.base,
+                                            chip->vendor.region_size);
+               atmel_put_base_addr(chip->vendor.iobase);
                tpm_remove_hardware(chip->dev);
+               platform_device_unregister(pdev);
        }
 }
 
@@ -182,72 +179,58 @@ static struct device_driver atml_drv = {
 static int __init init_atmel(void)
 {
        int rc = 0;
-       int lo, hi;
+       void __iomem *iobase = NULL;
+       int have_region, region_size;
+       unsigned long base;
+       struct  tpm_chip *chip;
 
-       driver_register(&atml_drv);
-
-       lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
-       hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
-
-       tpm_atmel.base = (hi<<8)|lo;
+       rc = driver_register(&atml_drv);
+       if (rc)
+               return rc;
 
-       /* verify that it is an Atmel part */
-       if (tpm_read_index(TPM_ADDR, 4) != 'A' || tpm_read_index(TPM_ADDR, 5) != 'T'
-           || tpm_read_index(TPM_ADDR, 6) != 'M' || tpm_read_index(TPM_ADDR, 7) != 'L') {
-               return -ENODEV;
+       if ((iobase = atmel_get_base_addr(&base, &region_size)) == NULL) {
+               rc = -ENODEV;
+               goto err_unreg_drv;
        }
 
-       /* verify chip version number is 1.1 */
-       if (    (tpm_read_index(TPM_ADDR, 0x00) != 0x01) ||
-               (tpm_read_index(TPM_ADDR, 0x01) != 0x01 ))
-               return -ENODEV;
-
-       pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
-       if ( !pdev )
-               return -ENOMEM;
-
-       pdev->name = "tpm_atmel0";
-       pdev->id = -1;
-       pdev->num_resources = 0;
-       pdev->dev.release = tpm_atml_remove;
-       pdev->dev.driver = &atml_drv;
+       have_region =
+           (atmel_request_region
+            (tpm_atmel.base, region_size, "tpm_atmel0") == NULL) ? 0 : 1;
 
-       if ((rc = platform_device_register(pdev)) < 0) {
-               kfree(pdev);
-               pdev = NULL;
-               return rc;
+       pdev = platform_device_register_simple("tpm_atmel", -1, NULL, 0);
+       if (IS_ERR(pdev)) {
+               rc = PTR_ERR(pdev);
+               goto err_rel_reg;
        }
 
-       if (request_region(tpm_atmel.base, 2, "tpm_atmel0") == NULL ) {
-               platform_device_unregister(pdev);
-               kfree(pdev);
-               pdev = NULL;
-               return -EBUSY;
+       if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_atmel))) {
+               rc = -ENODEV;
+               goto err_unreg_dev;
        }
 
-       if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0) {
-               release_region(tpm_atmel.base, 2);
-               platform_device_unregister(pdev);
-               kfree(pdev);
-               pdev = NULL;
-               return rc;
-       }
+       chip->vendor.iobase = iobase;
+       chip->vendor.base = base;
+       chip->vendor.have_region = have_region;
+       chip->vendor.region_size = region_size;
 
-       dev_info(&pdev->dev, "Atmel TPM 1.1, Base Address: 0x%x\n",
-                       tpm_atmel.base);
        return 0;
+
+err_unreg_dev:
+       platform_device_unregister(pdev);
+err_rel_reg:
+       atmel_put_base_addr(iobase);
+       if (have_region)
+               atmel_release_region(base,
+                                    region_size);
+err_unreg_drv:
+       driver_unregister(&atml_drv);
+       return rc;
 }
 
 static void __exit cleanup_atmel(void)
 {
-       if (pdev) {
-               tpm_atml_remove(&pdev->dev);
-               platform_device_unregister(pdev);
-               kfree(pdev);
-               pdev = NULL;
-       }
-
        driver_unregister(&atml_drv);
+       atml_plat_remove();
 }
 
 module_init(init_atmel);