mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] TPM: Make tpm_tis always create a platform driver
@ 2009-09-15 17:18 Jason Gunthorpe
  2009-11-03  0:37 ` [RESEND PATCH] " Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Gunthorpe @ 2009-09-15 17:18 UTC (permalink / raw)
  To: tpmdd-devel, linux-kernel, srajiv

This lets systems that don't use PNP to create a platform device and have the
tpm_tis driver bind to it. For embedded users.

Rework the force option to just create a platform device with the proper
resource information and use the usual binding mechanism to set it up.

Slightly rework the way interrupt auto detection happens to provide a -1 'do
not ever autodetect' input and use it to force off autodetection if PNP or
platform devices have no IRQ line.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
---
 drivers/char/tpm/tpm_tis.c |   73 +++++++++++++++++++++++++++++---------------
 1 files changed, 48 insertions(+), 25 deletions(-)

Unfortunately I can only test the platform device path here, I don't
have a PC system that uses this driver to test the force option.

diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 626dd4c..80db599 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -435,7 +435,7 @@ module_param(interrupts, bool, 0444);
 MODULE_PARM_DESC(interrupts, "Enable interrupts");
 
 static int tpm_tis_init(struct device *dev, u32 start,
-			u32 len, unsigned int irq)
+			u32 len, int irq)
 {
 	u32 vendor, intfcaps, intmask;
 	int rc, i;
@@ -507,9 +507,11 @@ static int tpm_tis_init(struct device *dev, u32 start,
 	iowrite32(intmask,
 		  chip->vendor.iobase +
 		  TPM_INT_ENABLE(chip->vendor.locality));
-	if (interrupts)
+	if (!interrupts)
+		irq = -1;
+	if (irq != -1)
 		chip->vendor.irq = irq;
-	if (interrupts && !chip->vendor.irq) {
+	if (irq == 0) {
 		chip->vendor.irq =
 		    ioread8(chip->vendor.iobase +
 			    TPM_INT_VECTOR(chip->vendor.locality));
@@ -594,15 +596,13 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
 				      const struct pnp_device_id *pnp_id)
 {
 	u32 start, len;
-	unsigned int irq = 0;
+	int irq = -1;
 
 	start = pnp_mem_start(pnp_dev, 0);
 	len = pnp_mem_len(pnp_dev, 0);
 
 	if (pnp_irq_valid(pnp_dev, 0))
 		irq = pnp_irq(pnp_dev, 0);
-	else
-		interrupts = 0;
 
 	return tpm_tis_init(&pnp_dev->dev, start, len, irq);
 }
@@ -654,6 +654,30 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
 		    sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
 
+static int force;
+module_param(force, bool, 0444);
+MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
+static struct platform_device *forced_pdev;
+static int __devinit tpm_tis_probe(struct platform_device *pdev)
+{
+	struct resource *mem;
+	struct resource *irqr;
+	int irq = -1;
+
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!mem)
+		return -EINVAL;
+
+	irqr = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (irqr)
+		irq = irqr->start;
+	else if (pdev == forced_pdev)
+		irq = 0;    /* Auto-detect interrupts. */
+
+	return tpm_tis_init(&pdev->dev, mem->start, (mem->end - mem->start+1),
+			    irq);
+}
+
 static int tpm_tis_suspend(struct platform_device *dev, pm_message_t msg)
 {
 	return tpm_pm_suspend(&dev->dev, msg);
@@ -668,30 +692,29 @@ static struct platform_driver tis_drv = {
 		.name = "tpm_tis",
 		.owner		= THIS_MODULE,
 	},
+	.probe = tpm_tis_probe,
 	.suspend = tpm_tis_suspend,
 	.resume = tpm_tis_resume,
 };
 
-static struct platform_device *pdev;
-
-static int force;
-module_param(force, bool, 0444);
-MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
 static int __init init_tis(void)
 {
 	int rc;
 
-	if (force) {
-		rc = platform_driver_register(&tis_drv);
-		if (rc < 0)
-			return rc;
-		if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
-			return PTR_ERR(pdev);
-		if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
-			platform_device_unregister(pdev);
-			platform_driver_unregister(&tis_drv);
-		}
+	rc = platform_driver_register(&tis_drv);
+	if (rc < 0)
 		return rc;
+
+	if (force) {
+		struct resource res[1] = {
+			{.start = TIS_MEM_BASE,
+			 .end = TIS_MEM_BASE + TIS_MEM_LEN - 1,
+			 .flags = IORESOURCE_MEM} };
+		forced_pdev = platform_device_register_simple("tpm_tis", -1,
+							      res, 1);
+		if (IS_ERR(forced_pdev))
+			return PTR_ERR(forced_pdev);
+		return 0;
 	}
 
 	return pnp_register_driver(&tis_pnp_driver);
@@ -719,10 +742,10 @@ static void __exit cleanup_tis(void)
 	}
 	spin_unlock(&tis_lock);
 
-	if (force) {
-		platform_device_unregister(pdev);
-		platform_driver_unregister(&tis_drv);
-	} else
+	if (forced_pdev)
+		platform_device_unregister(forced_pdev);
+	platform_driver_unregister(&tis_drv);
+	if (!force)
 		pnp_unregister_driver(&tis_pnp_driver);
 }
 
-- 
1.6.0.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-03  0:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-15 17:18 [PATCH] TPM: Make tpm_tis always create a platform driver Jason Gunthorpe
2009-11-03  0:37 ` [RESEND PATCH] " Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®