mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	srajiv@linux.vnet.ibm.com
Subject: [RESEND PATCH] TPM: Make tpm_tis always create a platform driver
Date: Mon, 2 Nov 2009 17:37:36 -0700	[thread overview]
Message-ID: <20091103003736.GM7768@obsidianresearch.com> (raw)
In-Reply-To: <20090915171816.GJ25981@obsidianresearch.com>

Any chance of getting some interest in this? :)

Thanks,
Jason

On Tue, Sep 15, 2009 at 11:18:16AM -0600, Jason Gunthorpe wrote:
> 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
> +++ 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);
>  }
>  

      reply	other threads:[~2009-11-03  0:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-15 17:18 [PATCH] " Jason Gunthorpe
2009-11-03  0:37 ` Jason Gunthorpe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091103003736.GM7768@obsidianresearch.com \
    --to=jgunthorpe@obsidianresearch.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srajiv@linux.vnet.ibm.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®