]> err.no Git - linux-2.6/blobdiff - drivers/char/tpm/tpm_nsc.c
Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband
[linux-2.6] / drivers / char / tpm / tpm_nsc.c
index 10202d0bc1c799beec98d423ff4b13856d551c5b..680a8e3318877b6c6bd7f09ae61d46abd5605871 100644 (file)
@@ -19,6 +19,7 @@
  * 
  */
 
+#include <linux/platform_device.h>
 #include "tpm.h"
 
 /* National definitions */
@@ -244,7 +245,7 @@ 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 };
@@ -261,55 +262,93 @@ static struct tpm_vendor_specific tpm_nsc = {
        .miscdev = { .fops = &nsc_ops, },
 };
 
-static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
-                                 const struct pci_device_id *pci_id)
+static struct platform_device *pdev = NULL;
+
+static void __devexit tpm_nsc_remove(struct device *dev)
+{
+       struct tpm_chip *chip = dev_get_drvdata(dev);
+       if ( chip ) {
+               release_region(chip->vendor->base, 2);
+               tpm_remove_hardware(chip->dev);
+       }
+}
+
+static struct device_driver nsc_drv = {
+       .name = "tpm_nsc",
+       .bus = &platform_bus_type,
+       .owner = THIS_MODULE,
+       .suspend = tpm_pm_suspend,
+       .resume = tpm_pm_resume,
+};
+
+static int __init init_nsc(void)
 {
        int rc = 0;
        int lo, hi;
        int nscAddrBase = TPM_ADDR;
 
 
-       if (pci_enable_device(pci_dev))
-               return -EIO;
-
-       /* select PM channel 1 */
-       tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12);
-
        /* verify that it is a National part (SID) */
        if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
                nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
                        (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
-               if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) {
-                       rc = -ENODEV;
-                       goto out_err;
-               }
+               if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
+                       return -ENODEV;
        }
 
+       driver_register(&nsc_drv);
+
        hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
        lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
        tpm_nsc.base = (hi<<8) | lo;
 
-       dev_dbg(&pci_dev->dev, "NSC TPM detected\n");
-       dev_dbg(&pci_dev->dev,
+       /* enable the DPM module */
+       tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
+
+       pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
+       if (!pdev) {
+               rc = -ENOMEM;
+               goto err_unreg_drv;
+       }
+
+       pdev->name = "tpm_nscl0";
+       pdev->id = -1;
+       pdev->num_resources = 0;
+       pdev->dev.release = tpm_nsc_remove;
+       pdev->dev.driver = &nsc_drv;
+
+       if ((rc = platform_device_register(pdev)) < 0)
+               goto err_free_dev;
+
+       if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) {
+               rc = -EBUSY;
+               goto err_unreg_dev;
+       }
+
+       if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0)
+               goto err_rel_reg;
+
+       dev_dbg(&pdev->dev, "NSC TPM detected\n");
+       dev_dbg(&pdev->dev,
                "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
                tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
                tpm_read_index(nscAddrBase,0x27));
-       dev_dbg(&pci_dev->dev,
+       dev_dbg(&pdev->dev,
                "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
                tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
                tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
-       dev_dbg(&pci_dev->dev, "NSC IO Base0 0x%x\n",
+       dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
                (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
-       dev_dbg(&pci_dev->dev, "NSC IO Base1 0x%x\n",
+       dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
                (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
-       dev_dbg(&pci_dev->dev, "NSC Interrupt number and wakeup 0x%x\n",
+       dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
                tpm_read_index(nscAddrBase,0x70));
-       dev_dbg(&pci_dev->dev, "NSC IRQ type select 0x%x\n",
+       dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
                tpm_read_index(nscAddrBase,0x71));
-       dev_dbg(&pci_dev->dev,
+       dev_dbg(&pdev->dev,
                "NSC DMA channel select0 0x%x, select1 0x%x\n",
                tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
-       dev_dbg(&pci_dev->dev,
+       dev_dbg(&pdev->dev,
                "NSC Config "
                "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
                tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
@@ -318,63 +357,33 @@ static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
                tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
                tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
 
-       dev_info(&pci_dev->dev,
+       dev_info(&pdev->dev,
                 "NSC TPM revision %d\n",
                 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
 
-       /* enable the DPM module */
-       tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
-
-       if ((rc = tpm_register_hardware(&pci_dev->dev, &tpm_nsc)) < 0)
-               goto out_err;
-
        return 0;
 
-out_err:
-       pci_disable_device(pci_dev);
+err_rel_reg:
+       release_region(tpm_nsc.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 __devexit tpm_nsc_remove(struct pci_dev *pci_dev)
-{
-       struct tpm_chip *chip = pci_get_drvdata(pci_dev);
-
-       if ( chip )
-               tpm_remove_hardware(chip->dev);
-}
-
-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_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)},
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)},
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0)},
-       {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
-       {0,}
-};
-
-MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
-
-static struct pci_driver nsc_pci_driver = {
-       .name = "tpm_nsc",
-       .id_table = tpm_pci_tbl,
-       .probe = tpm_nsc_init,
-       .remove = __devexit_p(tpm_nsc_remove),
-       .suspend = tpm_pm_suspend,
-       .resume = tpm_pm_resume,
-};
-
-static int __init init_nsc(void)
-{
-       return pci_register_driver(&nsc_pci_driver);
-}
-
 static void __exit cleanup_nsc(void)
 {
-       pci_unregister_driver(&nsc_pci_driver);
+       if (pdev) {
+               tpm_nsc_remove(&pdev->dev);
+               platform_device_unregister(pdev);
+               kfree(pdev);
+               pdev = NULL;
+       }
+
+       driver_unregister(&nsc_drv);
 }
 
 module_init(init_nsc);