From b4ed3e3cbb312869929cf4528d71e52629a6cacb Mon Sep 17 00:00:00 2001 From: Kylene Jo Hall Date: Sun, 30 Oct 2005 15:03:23 -0800 Subject: [PATCH] tpm: add status function to allow non-lpc bus chips This patch is in preparation of supporting chips that are not necessarily on the lpc bus and thus are not accessed with inb's and outb's. The patch replaces the call to get the chip's status in the tpm.c file with a vendor specific status function. The patch also defines the function for each of the current supported devices. Signed-off-by: Kylene Hall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_nsc.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/char/tpm/tpm_nsc.c') diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index b412734..bf3e774 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -220,6 +220,11 @@ static void tpm_nsc_cancel(struct tpm_chip *chip) 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); +} + static struct file_operations nsc_ops = { .owner = THIS_MODULE, .llseek = no_llseek, @@ -248,6 +253,7 @@ static struct tpm_vendor_specific tpm_nsc = { .recv = tpm_nsc_recv, .send = tpm_nsc_send, .cancel = tpm_nsc_cancel, + .status = tpm_nsc_status, .req_complete_mask = NSC_STATUS_OBF, .req_complete_val = NSC_STATUS_OBF, .req_canceled = NSC_STATUS_RDY, -- cgit v1.1 From e659a3fe2027b19ecd8abb7ad79253672763454b Mon Sep 17 00:00:00 2001 From: Kylene Jo Hall Date: Sun, 30 Oct 2005 15:03:24 -0800 Subject: [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 Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_nsc.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'drivers/char/tpm/tpm_nsc.c') diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index bf3e774..10202d0 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) } while (time_before(jiffies, stop)); - dev_info(&chip->pci_dev->dev, "wait for ready failed\n"); + dev_info(chip->dev, "wait for ready failed\n"); return -EBUSY; } @@ -127,12 +127,12 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) return -EIO; if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) { - dev_err(&chip->pci_dev->dev, "F0 timeout\n"); + dev_err(chip->dev, "F0 timeout\n"); return -EIO; } if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) { - dev_err(&chip->pci_dev->dev, "not in normal mode (0x%x)\n", + dev_err(chip->dev, "not in normal mode (0x%x)\n", data); return -EIO; } @@ -141,7 +141,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) for (p = buffer; p < &buffer[count]; p++) { if (wait_for_stat (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) { - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "OBF timeout (while reading data)\n"); return -EIO; } @@ -152,11 +152,11 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) if ((data & NSC_STATUS_F0) == 0 && (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) { - dev_err(&chip->pci_dev->dev, "F0 not set\n"); + dev_err(chip->dev, "F0 not set\n"); return -EIO; } if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) { - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "expected end of command(0x%x)\n", data); return -EIO; } @@ -187,19 +187,19 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) return -EIO; if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { - dev_err(&chip->pci_dev->dev, "IBF timeout\n"); + dev_err(chip->dev, "IBF timeout\n"); return -EIO; } 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->pci_dev->dev, "IBR timeout\n"); + dev_err(chip->dev, "IBR timeout\n"); return -EIO; } for (i = 0; i < count; i++) { if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "IBF timeout (while writing data)\n"); return -EIO; } @@ -207,7 +207,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) } if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { - dev_err(&chip->pci_dev->dev, "IBF timeout\n"); + dev_err(chip->dev, "IBF timeout\n"); return -EIO; } outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND); @@ -325,7 +325,7 @@ static int __devinit tpm_nsc_init(struct pci_dev *pci_dev, /* enable the DPM module */ tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); - if ((rc = tpm_register_hardware(pci_dev, &tpm_nsc)) < 0) + if ((rc = tpm_register_hardware(&pci_dev->dev, &tpm_nsc)) < 0) goto out_err; return 0; @@ -335,6 +335,14 @@ out_err: 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)}, @@ -354,7 +362,7 @@ static struct pci_driver nsc_pci_driver = { .name = "tpm_nsc", .id_table = tpm_pci_tbl, .probe = tpm_nsc_init, - .remove = __devexit_p(tpm_remove), + .remove = __devexit_p(tpm_nsc_remove), .suspend = tpm_pm_suspend, .resume = tpm_pm_resume, }; -- cgit v1.1 From 570302a31149083b0ac8b2f08c195e9211c2c0c6 Mon Sep 17 00:00:00 2001 From: Kylene Jo Hall Date: Sun, 30 Oct 2005 15:03:26 -0800 Subject: [PATCH] tpm: move nsc driver off pci_dev This patch changes the nsc driver from a pci driver to a platform driver. Signed-off-by: Kylene Hall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_nsc.c | 144 ++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 67 deletions(-) (limited to 'drivers/char/tpm/tpm_nsc.c') diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 10202d0..6adfc07 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -261,16 +261,32 @@ 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; + driver_register(&nsc_drv); /* select PM channel 1 */ tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12); @@ -279,37 +295,71 @@ static int __devinit tpm_nsc_init(struct pci_dev *pci_dev, 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; } 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 = kmalloc(sizeof(struct platform_device), GFP_KERNEL); + if ( !pdev ) + return -ENOMEM; + + memset(pdev, 0, sizeof(struct platform_device)); + + 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) { + kfree(pdev); + pdev = NULL; + return rc; + } + + if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) { + platform_device_unregister(pdev); + kfree(pdev); + pdev = NULL; + return -EBUSY; + } + + 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; + } + + 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 +368,23 @@ 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); - 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); -- cgit v1.1 From 874ec33ff9ccf3651590697a2c2923b911bf31d0 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sun, 30 Oct 2005 15:03:29 -0800 Subject: [PATCH] sparse cleanups: NULL pointers, C99 struct init. Convert most of the remaining "Using plain integer as NULL pointer" sparse warnings to use NULL. (Not duplicating patches that are already in -mm, -bird, or -kj.) Convert isdn driver struct initializer to use C99 syntax. Signed-off-by: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_nsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char/tpm/tpm_nsc.c') diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 6adfc07..253871b 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -244,7 +244,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 }; -- cgit v1.1