devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] TPM: Provide a tpm_tis OF driver
@ 2012-10-02 21:04 Jason Gunthorpe
  2012-10-10 16:24 ` Kent Yoder
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2012-10-02 21:04 UTC (permalink / raw)
  To: Kent Yoder; +Cc: linux-kernel, tpmdd-devel, devicetree-discuss

This provides an open firwmare driver binding for tpm_tis. OF
is useful on arches where PNP is not used.

Allow the tpm_tis driver to be selected if OF is compiled in.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
---
 drivers/char/tpm/Kconfig   |    2 +-
 drivers/char/tpm/tpm_tis.c |   79 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 65 insertions(+), 16 deletions(-)

v2 changes:
 - Add irq_autoprobe to tpm_tis_init to simplify the logic around
   the autoprobe function
 - Use platform functions in tis_of_probe_one
 - Rename tis_drv to tis_driver to silence MODPOST warnings
 - checkpatch cleanups
 - Do not attempt to auto-probe the TPM on OF configurations

diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index a048199..a346714 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -26,7 +26,7 @@ if TCG_TPM
 
 config TCG_TIS
 	tristate "TPM Interface Specification 1.2 Interface"
-	depends on X86
+	depends on X86 || OF
 	---help---
 	  If you have a TPM security chip that is compliant with the
 	  TCG TIS 1.2 TPM specification say Yes and it will be accessible
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index c4be351..23c6562 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -27,6 +27,7 @@
 #include <linux/wait.h>
 #include <linux/acpi.h>
 #include <linux/freezer.h>
+#include <linux/of_device.h>
 #include "tpm.h"
 
 enum tis_access {
@@ -507,7 +508,7 @@ module_param(interrupts, bool, 0444);
 MODULE_PARM_DESC(interrupts, "Enable interrupts");
 
 static int tpm_tis_init(struct device *dev, resource_size_t start,
-			resource_size_t len, unsigned int irq)
+			resource_size_t len, int irq, int irq_autoprobe)
 {
 	u32 vendor, intfcaps, intmask;
 	int rc, i, irq_s, irq_e, probe;
@@ -605,9 +606,12 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	iowrite32(intmask,
 		  chip->vendor.iobase +
 		  TPM_INT_ENABLE(chip->vendor.locality));
-	if (interrupts)
-		chip->vendor.irq = irq;
-	if (interrupts && !chip->vendor.irq) {
+	if (!interrupts) {
+		irq = 0;
+		irq_autoprobe = 0;
+	}
+	chip->vendor.irq = irq;
+	if (irq == 0 && irq_autoprobe) {
 		irq_s =
 		    ioread8(chip->vendor.iobase +
 			    TPM_INT_VECTOR(chip->vendor.locality));
@@ -739,13 +743,11 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
 
 	if (pnp_irq_valid(pnp_dev, 0))
 		irq = pnp_irq(pnp_dev, 0);
-	else
-		interrupts = 0;
 
 	if (is_itpm(pnp_dev))
 		itpm = 1;
 
-	return tpm_tis_init(&pnp_dev->dev, start, len, irq);
+	return tpm_tis_init(&pnp_dev->dev, start, len, irq, 0);
 }
 
 static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg)
@@ -768,7 +770,7 @@ static int tpm_tis_pnp_resume(struct pnp_dev *dev)
 	return ret;
 }
 
-static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
+static const struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
 	{"PNP0C31", 0},		/* TPM */
 	{"ATM1200", 0},		/* Atmel */
 	{"IFX0102", 0},		/* Infineon */
@@ -792,7 +794,7 @@ static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev)
 }
 
 
-static struct pnp_driver tis_pnp_driver = {
+static const struct pnp_driver tis_pnp_driver = {
 	.name = "tpm_tis",
 	.id_table = tpm_pnp_tbl,
 	.probe = tpm_tis_pnp_init,
@@ -821,12 +823,52 @@ static int tpm_tis_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
 
-static struct platform_driver tis_drv = {
+#ifdef CONFIG_OF
+static const struct of_device_id tis_of_platform_match[] __devinitdata = {
+	{.compatible = "tcg,tpm_tis"},
+	{},
+};
+MODULE_DEVICE_TABLE(of, tis_of_platform_match);
+
+static int __devinit tis_of_probe_one(struct platform_device *pdev)
+{
+	const struct resource *res;
+	int irq;
+
+	if (!pdev->dev.of_node)
+		return -ENODEV;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENODEV;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		irq = 0;
+	return tpm_tis_init(&pdev->dev, res->start, res->end - res->start + 1,
+			    irq, 0);
+}
+
+static int __devexit tis_of_remove_one(struct platform_device *odev)
+{
+	struct tpm_chip *chip = dev_get_drvdata(&odev->dev);
+	tpm_dev_vendor_release(chip);
+	kfree(chip);
+	return 0;
+}
+#endif
+
+static struct platform_driver tis_driver = {
 	.driver = {
 		.name = "tpm_tis",
 		.owner		= THIS_MODULE,
 		.pm		= &tpm_tis_pm,
+		.of_match_table = of_match_ptr(tis_of_platform_match),
 	},
+#ifdef CONFIG_OF
+	.probe = tis_of_probe_one,
+	.remove = __devexit_p(tis_of_remove_one)
+#endif
 };
 
 static struct platform_device *pdev;
@@ -842,15 +884,22 @@ static int __init init_tis(void)
 		return pnp_register_driver(&tis_pnp_driver);
 #endif
 
-	rc = platform_driver_register(&tis_drv);
+	rc = platform_driver_register(&tis_driver);
 	if (rc < 0)
 		return rc;
-	if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
+	/* TIS_MEM_BASE is only going to work on x86.. */
+#ifndef CONFIG_OF
+	pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0);
+	if (IS_ERR(pdev)) {
+		platform_driver_unregister(&tis_driver);
 		return PTR_ERR(pdev);
-	if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
+	}
+	rc = tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0, 1);
+	if (rc != 0) {
 		platform_device_unregister(pdev);
-		platform_driver_unregister(&tis_drv);
+		platform_driver_unregister(&tis_driver);
 	}
+#endif
 	return rc;
 }
 
@@ -882,7 +931,7 @@ static void __exit cleanup_tis(void)
 	}
 #endif
 	platform_device_unregister(pdev);
-	platform_driver_unregister(&tis_drv);
+	platform_driver_unregister(&tis_driver);
 }
 
 module_init(init_tis);
-- 
1.7.5.4

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

* Re: [PATCH v2] TPM: Provide a tpm_tis OF driver
  2012-10-02 21:04 [PATCH v2] TPM: Provide a tpm_tis OF driver Jason Gunthorpe
@ 2012-10-10 16:24 ` Kent Yoder
  2012-10-12 20:20   ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Kent Yoder @ 2012-10-10 16:24 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: linux-kernel, tpmdd-devel, devicetree-discuss

Hi Jason,

On Tue, Oct 02, 2012 at 03:04:53PM -0600, Jason Gunthorpe wrote:
> This provides an open firwmare driver binding for tpm_tis. OF
> is useful on arches where PNP is not used.
> 
> Allow the tpm_tis driver to be selected if OF is compiled in.
> 
> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> ---
>  drivers/char/tpm/Kconfig   |    2 +-
>  drivers/char/tpm/tpm_tis.c |   79 +++++++++++++++++++++++++++++++++++--------
>  2 files changed, 65 insertions(+), 16 deletions(-)
> 
> v2 changes:
>  - Add irq_autoprobe to tpm_tis_init to simplify the logic around
>    the autoprobe function
>  - Use platform functions in tis_of_probe_one
>  - Rename tis_drv to tis_driver to silence MODPOST warnings
>  - checkpatch cleanups
>  - Do not attempt to auto-probe the TPM on OF configurations
> 
[cut]
> @@ -768,7 +770,7 @@ static int tpm_tis_pnp_resume(struct pnp_dev *dev)
>  	return ret;
>  }
> 
> -static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
> +static const struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
>  	{"PNP0C31", 0},		/* TPM */
>  	{"ATM1200", 0},		/* Atmel */
>  	{"IFX0102", 0},		/* Infineon */
> @@ -792,7 +794,7 @@ static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev)
>  }
> 
> 
> -static struct pnp_driver tis_pnp_driver = {
> +static const struct pnp_driver tis_pnp_driver = {
>  	.name = "tpm_tis",
>  	.id_table = tpm_pnp_tbl,
>  	.probe = tpm_tis_pnp_init,

  Why change the structs to const here? This generates warnings for me:

drivers/char/tpm/tpm_tis.c: In function ‘init_tis’:
drivers/char/tpm/tpm_tis.c:885:3: warning: passing argument 1 of
‘pnp_register_driver’ discards ‘const’ qualifier from pointer target
type [enabled by default]
In file included from drivers/char/tpm/tpm_tis.c:24:0:
include/linux/pnp.h:469:5: note: expected ‘struct pnp_driver *’ but
argument is of type ‘const struct pnp_driver *’
drivers/char/tpm/tpm_tis.c: In function ‘cleanup_tis’:
drivers/char/tpm/tpm_tis.c:930:3: warning: passing argument 1 of
‘pnp_unregister_driver’ discards ‘const’ qualifier from pointer target
type [enabled by default]
In file included from drivers/char/tpm/tpm_tis.c:24:0:
include/linux/pnp.h:470:6: note: expected ‘struct pnp_driver *’ but
argument is of type ‘const struct pnp_driver *’

> @@ -821,12 +823,52 @@ static int tpm_tis_resume(struct device *dev)
> 
>  static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
> 
> -static struct platform_driver tis_drv = {
> +#ifdef CONFIG_OF
> +static const struct of_device_id tis_of_platform_match[] __devinitdata = {
> +	{.compatible = "tcg,tpm_tis"},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, tis_of_platform_match);
> +
> +static int __devinit tis_of_probe_one(struct platform_device *pdev)
> +{
> +	const struct resource *res;
> +	int irq;
> +
> +	if (!pdev->dev.of_node)
> +		return -ENODEV;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -ENODEV;
> +
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0)
> +		irq = 0;
> +	return tpm_tis_init(&pdev->dev, res->start, res->end - res->start + 1,
> +			    irq, 0);
> +}
> +
> +static int __devexit tis_of_remove_one(struct platform_device *odev)
> +{
> +	struct tpm_chip *chip = dev_get_drvdata(&odev->dev);
> +	tpm_dev_vendor_release(chip);
> +	kfree(chip);
> +	return 0;
> +}
> +#endif
> +
> +static struct platform_driver tis_driver = {
>  	.driver = {
>  		.name = "tpm_tis",
>  		.owner		= THIS_MODULE,
>  		.pm		= &tpm_tis_pm,
> +		.of_match_table = of_match_ptr(tis_of_platform_match),
>  	},

  Patch v2 removes the ifdef around of_match_table, which now generates
an error:

drivers/char/tpm/tpm_tis.c:867:3: error: implicit declaration of
function ‘of_match_ptr’ [-Werror=implicit-function-declaration]
drivers/char/tpm/tpm_tis.c:867:34: error: ‘tis_of_platform_match’
undeclared here (not in a function)

Kent

> +#ifdef CONFIG_OF
> +	.probe = tis_of_probe_one,
> +	.remove = __devexit_p(tis_of_remove_one)
> +#endif
>  };
> 
>  static struct platform_device *pdev;
> @@ -842,15 +884,22 @@ static int __init init_tis(void)
>  		return pnp_register_driver(&tis_pnp_driver);
>  #endif
> 
> -	rc = platform_driver_register(&tis_drv);
> +	rc = platform_driver_register(&tis_driver);
>  	if (rc < 0)
>  		return rc;
> -	if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
> +	/* TIS_MEM_BASE is only going to work on x86.. */
> +#ifndef CONFIG_OF
> +	pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0);
> +	if (IS_ERR(pdev)) {
> +		platform_driver_unregister(&tis_driver);
>  		return PTR_ERR(pdev);
> -	if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
> +	}
> +	rc = tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0, 1);
> +	if (rc != 0) {
>  		platform_device_unregister(pdev);
> -		platform_driver_unregister(&tis_drv);
> +		platform_driver_unregister(&tis_driver);
>  	}
> +#endif
>  	return rc;
>  }
> 
> @@ -882,7 +931,7 @@ static void __exit cleanup_tis(void)
>  	}
>  #endif
>  	platform_device_unregister(pdev);
> -	platform_driver_unregister(&tis_drv);
> +	platform_driver_unregister(&tis_driver);
>  }
> 
>  module_init(init_tis);
> -- 
> 1.7.5.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

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

* Re: [PATCH v2] TPM: Provide a tpm_tis OF driver
  2012-10-10 16:24 ` Kent Yoder
@ 2012-10-12 20:20   ` Jason Gunthorpe
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2012-10-12 20:20 UTC (permalink / raw)
  To: Kent Yoder; +Cc: linux-kernel, tpmdd-devel, devicetree-discuss

On Wed, Oct 10, 2012 at 11:24:28AM -0500, Kent Yoder wrote:

>   Why change the structs to const here? This generates warnings for me:

I should have dropped this, I was added when I added the __devinitdata
annotations..

> > +
> > +static struct platform_driver tis_driver = {
> >  	.driver = {
> >  		.name = "tpm_tis",
> >  		.owner		= THIS_MODULE,
> >  		.pm		= &tpm_tis_pm,
> > +		.of_match_table = of_match_ptr(tis_of_platform_match),
> >  	},
> 
>   Patch v2 removes the ifdef around of_match_table, which now generates
> an error:

Yes, this update was following the style of other drivers. Obviously I
never thought to try this on x86 (only PPC), so I will try to setup a
compile for that as well and send v3.

I suspect this is simply a missing #include.

Regards,
Jason

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

end of thread, other threads:[~2012-10-12 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-02 21:04 [PATCH v2] TPM: Provide a tpm_tis OF driver Jason Gunthorpe
2012-10-10 16:24 ` Kent Yoder
2012-10-12 20:20   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).