[PATCH] mutex subsystem, more debugging code
[safe/jmp/linux-2.6] / drivers / char / tpm / tpm_atmel.c
index 61fe14a..ff36549 100644 (file)
  */
 
 #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 {
@@ -40,7 +35,7 @@ enum tpm_atmel_read_status {
        ATML_STATUS_READY = 0x08
 };
 
-static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
+static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 {
        u8 status, *hdr = buf;
        u32 size;
@@ -52,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->pci_dev->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 */
@@ -66,13 +60,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
        size = be32_to_cpu(*native_size);
 
        if (count < size) {
-               dev_err(&chip->pci_dev->dev,
+               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->pci_dev->dev,
-                                       "error reading data\n");
+                               dev_err(chip->dev, "error reading data\n");
                                return -EIO;
                        }
                }
@@ -81,33 +74,33 @@ 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->pci_dev->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->pci_dev->dev, "data available is stuck\n");
+               dev_err(chip->dev, "data available is stuck\n");
                return -EIO;
        }
 
        return size;
 }
 
-static int tpm_atml_send(struct tpm_chip *chip, u8 * buf, size_t count)
+static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
 {
        int i;
 
-       dev_dbg(&chip->pci_dev->dev, "tpm_atml_send: ");
+       dev_dbg(chip->dev, "tpm_atml_send:\n");
        for (i = 0; i < count; i++) {
-               dev_dbg(&chip->pci_dev->dev, "0x%x(%d) ", buf[i], buf[i]);
-               outb(buf[i], chip->vendor->base);
+               dev_dbg(chip->dev, "%d 0x%x(%d)\n",  i, buf[i], buf[i]);
+               iowrite8(buf[i], chip->vendor->iobase);
        }
 
        return count;
@@ -115,7 +108,12 @@ 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 ioread8(chip->vendor->iobase + 1);
 }
 
 static struct file_operations atmel_ops = {
@@ -137,7 +135,7 @@ static struct attribute* atmel_attrs[] = {
        &dev_attr_pcrs.attr,
        &dev_attr_caps.attr,
        &dev_attr_cancel.attr,
-       0,
+       NULL,
 };
 
 static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
@@ -146,6 +144,7 @@ static struct tpm_vendor_specific tpm_atmel = {
        .recv = tpm_atml_recv,
        .send = tpm_atml_send,
        .cancel = tpm_atml_cancel,
+       .status = tpm_atml_status,
        .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
        .req_complete_val = ATML_STATUS_DATA_AVAIL,
        .req_canceled = ATML_STATUS_READY,
@@ -153,83 +152,73 @@ static struct tpm_vendor_specific tpm_atmel = {
        .miscdev = { .fops = &atmel_ops, },
 };
 
-static int __devinit tpm_atml_init(struct pci_dev *pci_dev,
-                                  const struct pci_device_id *pci_id)
-{
-       u8 version[4];
-       int rc = 0;
-       int lo, hi;
+static struct platform_device *pdev;
 
-       if (pci_enable_device(pci_dev))
-               return -EIO;
+static void atml_plat_remove(void)
+{
+       struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
+
+       if (chip) {
+               if (chip->vendor->have_region)
+                       atmel_release_region(chip->vendor->base,
+                                            chip->vendor->region_size);
+               atmel_put_base_addr(chip->vendor);
+               tpm_remove_hardware(chip->dev);
+               platform_device_unregister(pdev);
+       }
+}
 
-       lo = tpm_read_index( TPM_ATMEL_BASE_ADDR_LO );
-       hi = tpm_read_index( TPM_ATMEL_BASE_ADDR_HI );
+static struct device_driver atml_drv = {
+       .name = "tpm_atmel",
+       .bus = &platform_bus_type,
+       .owner = THIS_MODULE,
+       .suspend = tpm_pm_suspend,
+       .resume = tpm_pm_resume,
+};
 
-       tpm_atmel.base = (hi<<8)|lo;
-       dev_dbg( &pci_dev->dev, "Operating with base: 0x%x\n", tpm_atmel.base);
+static int __init init_atmel(void)
+{
+       int rc = 0;
 
-       /* verify that it is an Atmel part */
-       if (tpm_read_index(4) != 'A' || tpm_read_index(5) != 'T'
-           || tpm_read_index(6) != 'M' || tpm_read_index(7) != 'L') {
-               rc = -ENODEV;
-               goto out_err;
-       }
+       driver_register(&atml_drv);
 
-       /* query chip for its version number */
-       if ((version[0] = tpm_read_index(0x00)) != 0xFF) {
-               version[1] = tpm_read_index(0x01);
-               version[2] = tpm_read_index(0x02);
-               version[3] = tpm_read_index(0x03);
-       } else {
-               dev_info(&pci_dev->dev, "version query failed\n");
+       if ((tpm_atmel.iobase = atmel_get_base_addr(&tpm_atmel)) == NULL) {
                rc = -ENODEV;
-               goto out_err;
+               goto err_unreg_drv;
        }
 
-       if ((rc = tpm_register_hardware(pci_dev, &tpm_atmel)) < 0)
-               goto out_err;
+       tpm_atmel.have_region =
+           (atmel_request_region
+            (tpm_atmel.base, tpm_atmel.region_size,
+             "tpm_atmel0") == NULL) ? 0 : 1;
 
-       dev_info(&pci_dev->dev,
-                "Atmel TPM version %d.%d.%d.%d\n", version[0], version[1],
-                version[2], version[3]);
+       if (IS_ERR
+           (pdev =
+            platform_device_register_simple("tpm_atmel", -1, NULL, 0))) {
+               rc = PTR_ERR(pdev);
+               goto err_rel_reg;
+       }
 
+       if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0)
+               goto err_unreg_dev;
        return 0;
-out_err:
-       pci_disable_device(pci_dev);
-       return rc;
-}
-
-static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
-       {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
-       {PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6LPC)},
-       {0,}
-};
 
-MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
-
-static struct pci_driver atmel_pci_driver = {
-       .name = "tpm_atmel",
-       .id_table = tpm_pci_tbl,
-       .probe = tpm_atml_init,
-       .remove = __devexit_p(tpm_remove),
-       .suspend = tpm_pm_suspend,
-       .resume = tpm_pm_resume,
-};
-
-static int __init init_atmel(void)
-{
-       return pci_register_driver(&atmel_pci_driver);
+err_unreg_dev:
+       platform_device_unregister(pdev);
+err_rel_reg:
+       atmel_put_base_addr(&tpm_atmel);
+       if (tpm_atmel.have_region)
+               atmel_release_region(tpm_atmel.base,
+                                    tpm_atmel.region_size);
+err_unreg_drv:
+       driver_unregister(&atml_drv);
+       return rc;
 }
 
 static void __exit cleanup_atmel(void)
 {
-       pci_unregister_driver(&atmel_pci_driver);
+       driver_unregister(&atml_drv);
+       atml_plat_remove();
 }
 
 module_init(init_atmel);