All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] GPIO irq handler on powerpc.
@ 2012-06-07 21:16 Chris Stone
  2012-06-08  7:15 ` Gilles Chanteperdrix
  2012-06-08  7:31 ` Philippe Gerum
  0 siblings, 2 replies; 8+ messages in thread
From: Chris Stone @ 2012-06-07 21:16 UTC (permalink / raw)
  To: xenomai@xenomai.org

I am using Xenomai 2.6.0 on kernel 3.0.13, with adeos-ipipe-3.0.13-powerpc-2.13-06 applied. My target CPU 
is Freescale MPC8378.

On a powerpc, GPIO's are mapped to virtual irqs. Thus, in order to install an irq handler for a gpio 
interrupt, one must do the following in the kernel:

	err = gpio_request(HYPHY_IRQ_GPIO, NULL);
	if (err<0) {
		printk(KERN_ERR "%s: could not request gpio %d, rc %d\n", __func__, HYPHY_IRQ_GPIO, err);
		return err;
	}
	err = gpio_direction_input(HYPHY_IRQ_GPIO);
	if (err<0) {
		printk(KERN_ERR "%s: could not set gpio %d to input, rc %d\n", __func__, HYPHY_IRQ_GPIO, err);
		return err;
	}

	virq = __gpio_to_irq(HYPHY_IRQ_GPIO);
	if (virq < 0) {
		printk(KERN_ERR "%s: could not map gpio %d to virq \n", __func__, HYPHY_IRQ_GPIO);
		return virq;
	}
      err = request_irq(virq, hyphy20G_irq, 0, hyphy20G_dev.name, &hyphy20G_dev);

In other words, you install the irq handler on the virtual irq number returned from __gpio_to_irq. The above 
code works in my system, i.e., the hyphy20G_irq handler is called on an interrupt.

However, if I use:

err = rt_intr_create(intrObj, "HyPhyIRQ", virq, hyphy20G_irq, NULL, 0);
rt_intr_enable(intrObj);

then the hyphy20G_irq handler is not called on an interrupt. I realize that interrupt handlers are 
recommended to be implemented in user space, but a user space implementation does not work either, 
so I moved into the kernel to see if I could get something to work.

Is it possible to install an Xenomai ISR on a powerpc virtual irq? 

I have attached the full driver code.

Chris Stone
Embedded Linux Architect
Optelian
1 Brewer Hunt Way
Ottawa, Ontario K2K 2B5

Phone: 613-287-2000 x2106

www.optelian.com

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: hyphypcie.c
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20120607/b899a195/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: hyphypcie.h
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20120607/b899a195/attachment.h>

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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-07 21:16 [Xenomai] GPIO irq handler on powerpc Chris Stone
@ 2012-06-08  7:15 ` Gilles Chanteperdrix
  2012-06-08 14:50   ` Chris Stone
  2012-06-08 15:00   ` Chris Stone
  2012-06-08  7:31 ` Philippe Gerum
  1 sibling, 2 replies; 8+ messages in thread
From: Gilles Chanteperdrix @ 2012-06-08  7:15 UTC (permalink / raw)
  To: Chris Stone; +Cc: xenomai@xenomai.org

On 06/07/2012 11:16 PM, Chris Stone wrote:
> I am using Xenomai 2.6.0 on kernel 3.0.13, with adeos-ipipe-3.0.13-powerpc-2.13-06 applied. My target CPU 
> is Freescale MPC8378.
> 
> On a powerpc, GPIO's are mapped to virtual irqs. Thus, in order to install an irq handler for a gpio 
> interrupt, one must do the following in the kernel:
> 
> 	err = gpio_request(HYPHY_IRQ_GPIO, NULL);
> 	if (err<0) {
> 		printk(KERN_ERR "%s: could not request gpio %d, rc %d\n", __func__, HYPHY_IRQ_GPIO, err);
> 		return err;
> 	}
> 	err = gpio_direction_input(HYPHY_IRQ_GPIO);
> 	if (err<0) {
> 		printk(KERN_ERR "%s: could not set gpio %d to input, rc %d\n", __func__, HYPHY_IRQ_GPIO, err);
> 		return err;
> 	}
> 
> 	virq = __gpio_to_irq(HYPHY_IRQ_GPIO);
> 	if (virq < 0) {
> 		printk(KERN_ERR "%s: could not map gpio %d to virq \n", __func__, HYPHY_IRQ_GPIO);
> 		return virq;
> 	}
>       err = request_irq(virq, hyphy20G_irq, 0, hyphy20G_dev.name, &hyphy20G_dev);
> 
> In other words, you install the irq handler on the virtual irq number returned from __gpio_to_irq. The above 
> code works in my system, i.e., the hyphy20G_irq handler is called on an interrupt.
> 
> However, if I use:
> 
> err = rt_intr_create(intrObj, "HyPhyIRQ", virq, hyphy20G_irq, NULL, 0);
> rt_intr_enable(intrObj);
> 
> then the hyphy20G_irq handler is not called on an interrupt. 

This is a bug.

> I realize that interrupt handlers are 
> recommended to be implemented in user space, but a user space implementation does not work either, 

Definitely not. Interrupts handlers in user-space are not recommended.
At all.

> so I moved into the kernel to see if I could get something to work.
> 
> Is it possible to install an Xenomai ISR on a powerpc virtual irq? 

Normally it should be. If the GPIO interrupts are multiplexed (several
GPIOs on the same parent irq), you should look for the parent irq
handler and see that:
- its code is safe to be called from xenomai domain
- it calls ipipe_handle_chained_irq for the individual demultiplexed
gpio interrupts instead of generic_handle_irq

Note that a bug in multiplexed GPIO interrupts has been fixed very
recently. You may want to upgrade to the I-pipe core for linux 3.2,
currently only available as a git repository:

git://git.denx.de/ipipe.git branch core-3.2

Which also requires xenomai sources from the git repository:

git://git.xenomai.org/xenomai-2.6.git branch master

-- 
                                                                Gilles.


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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-07 21:16 [Xenomai] GPIO irq handler on powerpc Chris Stone
  2012-06-08  7:15 ` Gilles Chanteperdrix
@ 2012-06-08  7:31 ` Philippe Gerum
  1 sibling, 0 replies; 8+ messages in thread
From: Philippe Gerum @ 2012-06-08  7:31 UTC (permalink / raw)
  To: Chris Stone; +Cc: xenomai@xenomai.org

On 06/07/2012 11:16 PM, Chris Stone wrote:
> I am using Xenomai 2.6.0 on kernel 3.0.13, with adeos-ipipe-3.0.13-powerpc-2.13-06 applied. My target CPU
> is Freescale MPC8378.
>
> On a powerpc, GPIO's are mapped to virtual irqs. Thus, in order to install an irq handler for a gpio
> interrupt, one must do the following in the kernel:
>
> 	err = gpio_request(HYPHY_IRQ_GPIO, NULL);
> 	if (err<0) {
> 		printk(KERN_ERR "%s: could not request gpio %d, rc %d\n", __func__, HYPHY_IRQ_GPIO, err);
> 		return err;
> 	}
> 	err = gpio_direction_input(HYPHY_IRQ_GPIO);
> 	if (err<0) {
> 		printk(KERN_ERR "%s: could not set gpio %d to input, rc %d\n", __func__, HYPHY_IRQ_GPIO, err);
> 		return err;
> 	}
>
> 	virq = __gpio_to_irq(HYPHY_IRQ_GPIO);
> 	if (virq<  0) {
> 		printk(KERN_ERR "%s: could not map gpio %d to virq \n", __func__, HYPHY_IRQ_GPIO);
> 		return virq;
> 	}
>        err = request_irq(virq, hyphy20G_irq, 0, hyphy20G_dev.name,&hyphy20G_dev);
>
> In other words, you install the irq handler on the virtual irq number returned from __gpio_to_irq. The above
> code works in my system, i.e., the hyphy20G_irq handler is called on an interrupt.
>
> However, if I use:
>
> err = rt_intr_create(intrObj, "HyPhyIRQ", virq, hyphy20G_irq, NULL, 0);
> rt_intr_enable(intrObj);
>
> then the hyphy20G_irq handler is not called on an interrupt. I realize that interrupt handlers are
> recommended to be implemented in user space, but a user space implementation does not work either,

I believe this is a typo, but just for the record: the rt_intr* API is 
deprecated, and interrupt handlers in user-space over Xenomai are NOT 
recommended.

> so I moved into the kernel to see if I could get something to work.
>
> Is it possible to install an Xenomai ISR on a powerpc virtual irq?

Xenomai, and more specifically the I-pipe does interface with irq 
numbers defined in the kernel namespace, so yes, virqs is what we always 
use internally for powerpc.

You may want to check whether that GPIO is actually chained from a 
multiplex parent IRQ.

-- 
Philippe.


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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-08  7:15 ` Gilles Chanteperdrix
@ 2012-06-08 14:50   ` Chris Stone
  2012-06-08 15:14     ` Philippe Gerum
  2012-06-08 15:00   ` Chris Stone
  1 sibling, 1 reply; 8+ messages in thread
From: Chris Stone @ 2012-06-08 14:50 UTC (permalink / raw)
  To: xenomai@xenomai.org

> 
> > I realize that interrupt handlers are recommended to be implemented
> in
> > user space, but a user space implementation does not work either,
> 
> Definitely not. Interrupts handlers in user-space are not recommended.
> At all.

Oops, good to know. I could have sworn I read that somewhere, but thanks
for setting me straight. I gather from Phillipe's response that I should
be using the RTDM API, so I will switch to that. 

> 
> > so I moved into the kernel to see if I could get something to work.
> >
> > Is it possible to install an Xenomai ISR on a powerpc virtual irq?
> 
> Normally it should be. If the GPIO interrupts are multiplexed (several
> GPIOs on the same parent irq), you should look for the parent irq
> handler and see that:
> - its code is safe to be called from xenomai domain
> - it calls ipipe_handle_chained_irq for the individual demultiplexed
> gpio interrupts instead of generic_handle_irq
> 
> Note that a bug in multiplexed GPIO interrupts has been fixed very
> recently. You may want to upgrade to the I-pipe core for linux 3.2,
> currently only available as a git repository:
> 
> git://git.denx.de/ipipe.git branch core-3.2
> 
> Which also requires xenomai sources from the git repository:
> 
> git://git.xenomai.org/xenomai-2.6.git branch master
> 

There was a call to generic_handle_irq that should have been calling 
ipipe_handle_chained_irq so I have a fix for the problem. Here is a
diff:

diff -r 0f7a4ec77dc0 arch/powerpc/sysdev/mpc8xxx_gpio.c
--- a/arch/powerpc/sysdev/mpc8xxx_gpio.c        Mon Jun 04 11:04:14 2012 -0400
+++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c        Fri Jun 08 10:39:40 2012 -0400
@@ -151,7 +151,7 @@
 
        mask = in_be32(mm->regs + GPIO_IER) & in_be32(mm->regs + GPIO_IMR);
        if (mask)
-               generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
+               ipipe_handle_chained_irq(irq_linear_revmap(mpc8xxx_gc->irq,
                                                     32 - ffs(mask)));
 }

I did not see this in the core-3.2 branch of the ipipe git, so you may need to
merge this in. Let me know if I should be providing this fix in another form.

Cheers,
   Chris.

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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-08  7:15 ` Gilles Chanteperdrix
  2012-06-08 14:50   ` Chris Stone
@ 2012-06-08 15:00   ` Chris Stone
  1 sibling, 0 replies; 8+ messages in thread
From: Chris Stone @ 2012-06-08 15:00 UTC (permalink / raw)
  To: xenomai@xenomai.org

I shouldn't be embedding diffs into email, especially when we use Outlook. So,
attached is a patch for the change I made. Hopefully, that is more useful.

Cheers,
   Chris.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipipe-mpc8xxx-gpio.patch
Type: application/octet-stream
Size: 459 bytes
Desc: ipipe-mpc8xxx-gpio.patch
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20120608/b437389f/attachment.obj>

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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-08 14:50   ` Chris Stone
@ 2012-06-08 15:14     ` Philippe Gerum
  2012-06-08 15:18       ` Chris Stone
  0 siblings, 1 reply; 8+ messages in thread
From: Philippe Gerum @ 2012-06-08 15:14 UTC (permalink / raw)
  To: Chris Stone; +Cc: xenomai@xenomai.org

On 06/08/2012 04:50 PM, Chris Stone wrote:

> There was a call to generic_handle_irq that should have been calling
> ipipe_handle_chained_irq so I have a fix for the problem. Here is a
> diff:
>
> diff -r 0f7a4ec77dc0 arch/powerpc/sysdev/mpc8xxx_gpio.c
> --- a/arch/powerpc/sysdev/mpc8xxx_gpio.c        Mon Jun 04 11:04:14 2012 -0400
> +++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c        Fri Jun 08 10:39:40 2012 -0400
> @@ -151,7 +151,7 @@
>
>          mask = in_be32(mm->regs + GPIO_IER)&  in_be32(mm->regs + GPIO_IMR);
>          if (mask)
> -               generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
> +               ipipe_handle_chained_irq(irq_linear_revmap(mpc8xxx_gc->irq,
>                                                       32 - ffs(mask)));
>   }
>
> I did not see this in the core-3.2 branch of the ipipe git, so you may need to
> merge this in. Let me know if I should be providing this fix in another form.
>

This won't apply to a mainline 3.2.x kernel. Are these bits part of a 
vendor-specific tree?

-- 
Philippe.


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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-08 15:14     ` Philippe Gerum
@ 2012-06-08 15:18       ` Chris Stone
  2012-06-08 15:22         ` Philippe Gerum
  0 siblings, 1 reply; 8+ messages in thread
From: Chris Stone @ 2012-06-08 15:18 UTC (permalink / raw)
  To: Philippe Gerum; +Cc: xenomai@xenomai.org

I am not using a 3.2.x kernel. It was not a vendor specific tree, but
a mainline 3.0.13 kernel. 

Cheers,
    Chris.

> -----Original Message-----
> From: Philippe Gerum [mailto:rpm@xenomai.org]
> Sent: Friday, June 08, 2012 11:14 AM
> To: Chris Stone
> Cc: xenomai@xenomai.org
> Subject: Re: [Xenomai] GPIO irq handler on powerpc.
> 
> On 06/08/2012 04:50 PM, Chris Stone wrote:
> 
> > There was a call to generic_handle_irq that should have been calling
> > ipipe_handle_chained_irq so I have a fix for the problem. Here is a
> > diff:
> >
> > diff -r 0f7a4ec77dc0 arch/powerpc/sysdev/mpc8xxx_gpio.c
> > --- a/arch/powerpc/sysdev/mpc8xxx_gpio.c        Mon Jun 04 11:04:14
> 2012 -0400
> > +++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c        Fri Jun 08 10:39:40
> 2012 -0400
> > @@ -151,7 +151,7 @@
> >
> >          mask = in_be32(mm->regs + GPIO_IER)&  in_be32(mm->regs +
> GPIO_IMR);
> >          if (mask)
> > -               generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
> > +
> > + ipipe_handle_chained_irq(irq_linear_revmap(mpc8xxx_gc->irq,
> >                                                       32 -
> ffs(mask)));
> >   }
> >
> > I did not see this in the core-3.2 branch of the ipipe git, so you
> may
> > need to merge this in. Let me know if I should be providing this fix
> in another form.
> >
> 
> This won't apply to a mainline 3.2.x kernel. Are these bits part of a
> vendor-specific tree?
> 
> --
> Philippe.


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

* Re: [Xenomai] GPIO irq handler on powerpc.
  2012-06-08 15:18       ` Chris Stone
@ 2012-06-08 15:22         ` Philippe Gerum
  0 siblings, 0 replies; 8+ messages in thread
From: Philippe Gerum @ 2012-06-08 15:22 UTC (permalink / raw)
  To: Chris Stone; +Cc: xenomai@xenomai.org

On 06/08/2012 05:18 PM, Chris Stone wrote:
> I am not using a 3.2.x kernel. It was not a vendor specific tree, but
> a mainline 3.0.13 kernel.

Ok, so this moved to drivers/gpio. Patch queued, thanks.

>
> Cheers,
>      Chris.
>
>> -----Original Message-----
>> From: Philippe Gerum [mailto:rpm@xenomai.org]
>> Sent: Friday, June 08, 2012 11:14 AM
>> To: Chris Stone
>> Cc: xenomai@xenomai.org
>> Subject: Re: [Xenomai] GPIO irq handler on powerpc.
>>
>> On 06/08/2012 04:50 PM, Chris Stone wrote:
>>
>>> There was a call to generic_handle_irq that should have been calling
>>> ipipe_handle_chained_irq so I have a fix for the problem. Here is a
>>> diff:
>>>
>>> diff -r 0f7a4ec77dc0 arch/powerpc/sysdev/mpc8xxx_gpio.c
>>> --- a/arch/powerpc/sysdev/mpc8xxx_gpio.c        Mon Jun 04 11:04:14
>> 2012 -0400
>>> +++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c        Fri Jun 08 10:39:40
>> 2012 -0400
>>> @@ -151,7 +151,7 @@
>>>
>>>           mask = in_be32(mm->regs + GPIO_IER)&   in_be32(mm->regs +
>> GPIO_IMR);
>>>           if (mask)
>>> -               generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
>>> +
>>> + ipipe_handle_chained_irq(irq_linear_revmap(mpc8xxx_gc->irq,
>>>                                                        32 -
>> ffs(mask)));
>>>    }
>>>
>>> I did not see this in the core-3.2 branch of the ipipe git, so you
>> may
>>> need to merge this in. Let me know if I should be providing this fix
>> in another form.
>>>
>>
>> This won't apply to a mainline 3.2.x kernel. Are these bits part of a
>> vendor-specific tree?
>>
>> --
>> Philippe.
>


-- 
Philippe.


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

end of thread, other threads:[~2012-06-08 15:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-07 21:16 [Xenomai] GPIO irq handler on powerpc Chris Stone
2012-06-08  7:15 ` Gilles Chanteperdrix
2012-06-08 14:50   ` Chris Stone
2012-06-08 15:14     ` Philippe Gerum
2012-06-08 15:18       ` Chris Stone
2012-06-08 15:22         ` Philippe Gerum
2012-06-08 15:00   ` Chris Stone
2012-06-08  7:31 ` Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.