Skip to contentSkip to conversation

83xx: requesting external interrupts

DISCUSSION Alex Zeffertt 5 participants 10 messages May 10, 2007 – Jun 30, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi list,

I'm trying to port a driver from 2.6.11 to 2.6.21 and I'm stuck on the following line:

	request_irq(MPC83xx_IRQ_EXT5, mpc832xemds_phy_interrupt, SA_SHIRQ, "pm5384", dev);

The first problem is that MPC83xx_IRQ_EXT5 is no longer defined. If I hard code this to what I think is the right value (i.e. 21) then request_irq fails on insmod.

I obviously need to do something different now that ARCH=powerpc, but I can't find any examples of code which requests 83xx external interrupts. Can anybody help?

TIA,

Alex

#1 lore raw

Alex,

Follow this thread...
http://marc.info/?l=linuxppc-embedded&m=116849062702002&w=2

Quoted 19 lines · Alex Zeffertt

Hi list,

I'm trying to port a driver from 2.6.11 to 2.6.21 and I'm stuck on the following line:

	request_irq(MPC83xx_IRQ_EXT5, mpc832xemds_phy_interrupt, SA_SHIRQ, "pm5384", dev);

The first problem is that MPC83xx_IRQ_EXT5 is no longer defined. If I hard code this to what I think is the right value (i.e. 21) then request_irq fails on insmod.

I obviously need to do something different now that ARCH=powerpc, but I can't find any examples of code which requests 83xx external interrupts. Can anybody help?

TIA,

Alex
_______________________________________________
Linuxppc-embedded mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-embedded

#3 lore raw
In reply to a message not in the archive

Alex,

Quoted 16 lines · Alex Zeffertt

Hi,

Thanks for your reply Ben, but I think my problem is slightly different. It is not that the sense (high/low/rising/falling) of the interrupt is wrong, but that the kernel will not allow me to register the handler.

I've changed my code to:

     struct device_node *np = of_find_node_by_type(NULL, "ipic");
     struct irq_host *host = irq_find_host(np);
     int rc;

     unsigned int virq = irq_find_mapping(host, 5);
     set_irq_type(virq, IRQ_TYPE_EDGE_FALLING);
     rc = request_irq(virq, mpc832xemds_phy_interrupt, IRQF_SHARED, "pm5384", dev);
Quoted 5 lines

but the last line still returns a non-zero error code.

Is there a new way of requesting to install a handler for external interrupts? I can't find any powerpc examples in the kernel tree....

Sorry, I missed a bit of the implementation. You need to register the IRQs before attempting to attach an ISR. Here's some sample code that works for me. You'll probably need different IRQs, based on what your board does:

/* All external IRQs + Generic timer IRQs must be initialized by BSP */ const int bsp_irqs[] = {48, 17, 18, 19, 20, 21, 22, 23, 90, 78, 84, 72};

Add this to your BSP IRQ init code (void __init xxx_init_IRQs())

	for (i=0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)
		virq = irq_create_mapping(NULL, bsp_irqs[i]);

That should do it.

regards,
Ben

#4 lore raw
Quoted 30 lines · Ben Warren

Alex,

Quoted 15 lines · Alex Zeffertt

Hi,

Thanks for your reply Ben, but I think my problem is slightly different. It is not that the sense (high/low/rising/falling) of the interrupt is wrong, but that the kernel will not allow me to register the handler.

I've changed my code to:

     struct device_node *np = of_find_node_by_type(NULL, "ipic");
     struct irq_host *host = irq_find_host(np);
     int rc;

     unsigned int virq = irq_find_mapping(host, 5);
     set_irq_type(virq, IRQ_TYPE_EDGE_FALLING);
     rc = request_irq(virq, mpc832xemds_phy_interrupt,  
Quoted 7 lines

IRQF_SHARED, "pm5384", dev);

but the last line still returns a non-zero error code.

Is there a new way of requesting to install a handler for external interrupts? I can't find any powerpc examples in the kernel tree....

Sorry, I missed a bit of the implementation. You need to register the IRQs before attempting to attach an ISR. Here's some sample code that works for me. You'll probably need different IRQs, based on what your board does:

Quoted 8 lines

/* All external IRQs + Generic timer IRQs must be initialized by BSP */ const int bsp_irqs[] = {48, 17, 18, 19, 20, 21, 22, 23, 90, 78, 84, 72};

Add this to your BSP IRQ init code (void __init xxx_init_IRQs())

	for (i=0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)
		virq = irq_create_mapping(NULL, bsp_irqs[i]);

I assume you're code doesn't look exactly like this. You'll need to use the virq in the request_irq()... its most likely just random luck if things are working and you aren't using the virq returned from irq_create_mapping()

(Well its more than random luck, its because most 83xx systems only have one PIC and this hw_irq # == virq)

- k

#5 lore raw
Quoted 10 lines · Kumar Gala

I assume you're code doesn't look exactly like this. You'll need to use the virq in the request_irq()... its most likely just random luck if things are working and you aren't using the virq returned from irq_create_mapping()

(Well its more than random luck, its because most 83xx systems only have one PIC and this hw_irq # == virq)

- k

In the code that registers the ISR I do this:

virq = irq_find_mapping(NULL, MY_IRQ);
request_irq(virq ...)

Since I only have one interrupt controller, host is NULL, right?

regards,
Ben

#6 lore raw
Quoted 11 lines · Ben Warren
Quoted 9 lines · Kumar Gala

I assume you're code doesn't look exactly like this. You'll need to use the virq in the request_irq()... its most likely just random luck if things are working and you aren't using the virq returned from irq_create_mapping()

(Well its more than random luck, its because most 83xx systems only have one PIC and this hw_irq # == virq)

Quoted 8 lines
Quoted 1 line

- k

In the code that registers the ISR I do this:

virq = irq_find_mapping(NULL, MY_IRQ);
request_irq(virq ...)

Since I only have one interrupt controller, host is NULL, right?

Should be ok. I've been doing the irq_create_mapping() in _init_IRQ() and saving off the return.

- k

#7 lore raw
In reply to Ben Warren
Quoted 6 lines · Ben Warren

Alex,
=20

Quoted 3 lines · Alex Zeffertt

Hi,
=20
Thanks for your reply Ben, but I think my problem is slightly =

different. It is not

Quoted 1 line
Quoted 1 line

that the sense (high/low/rising/falling) of the interrupt is wrong, =

but that the

Quoted 11 lines
Quoted 11 lines

kernel will not allow me to register the handler.
=20
I've changed my code to:
=20

     struct device_node *np =3D of_find_node_by_type(NULL, "ipic");
     struct irq_host *host =3D irq_find_host(np);
     int rc;
=20
     unsigned int virq =3D irq_find_mapping(host, 5);
     set_irq_type(virq, IRQ_TYPE_EDGE_FALLING);
     rc =3D request_irq(virq, mpc832xemds_phy_interrupt, =

IRQF_SHARED, "pm5384", dev);

Quoted 4 lines
Quoted 4 lines

=20
but the last line still returns a non-zero error code. =20
Is there a new way of requesting to install a handler for external =

interrupts? I

Quoted 8 lines
Quoted 2 lines

can't find any powerpc examples in the kernel tree.... =20

Sorry, I missed a bit of the implementation. You need to register the IRQs before attempting to attach an ISR. Here's some sample code that works for me. You'll probably need different IRQs, based on what your board does:
=20
/* All external IRQs + Generic timer IRQs must be initialized by BSP =

*/

Quoted 1 line

const int bsp_irqs[] =3D {48, 17, 18, 19, 20, 21, 22, 23, 90, 78, 84, =

72};

Quoted 11 lines

=20
Add this to your BSP IRQ init code (void __init xxx_init_IRQs()) =20
=20

	for (i=3D0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)
		virq =3D irq_create_mapping(NULL, bsp_irqs[i]);

=20
That should do it.
=20
regards,
Ben

Hi Ben

I too am adding such a IRQ for my PHY connected to external IRQ2. The PHY is connetced to UCC2.
I have this in my DTS for the PHY:

	mdio@2320 {
			#address-cells =3D <1>;
			#size-cells =3D <0>;
			reg =3D <2320 18>;
			device_type =3D "mdio";
			compatible =3D "ucc_geth_phy";

			phy1: ethernet-phy@0 {
				interrupt-parent =3D <&ipic>;
				interrupts =3D <12 2>; //EXT IRQ2
				reg =3D <0>; // 0
				device_type =3D "ethernet-phy";
				interface =3D <3>; //ENET_100_MII
			};

Now the things is that the IRQ works with and without the
/* All external IRQs + Generic timer IRQs must be initialized by BSP */ const int bsp_irqs[] =3D {48, 17, 18, 19, 20, 21, 22, 23, 90, 78, 84, =
72};
for (i=3D0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)

	virq =3D irq_create_mapping(NULL, bsp_irqs[i]);
code in my bsp. There is one difference though.
Printing the irq num in phy_interrupt:
static irqreturn_t phy_interrupt(int irq, void *dev_id)
{
	struct net_device *dev =3D (struct net_device *)dev_id;
	struct ucc_geth_private *ugeth =3D netdev_priv(dev);

	ugeth_vdbg("%s: IN", __FUNCTION__);
	printk(KERN_ERR "PHY IRQ:%d \n", irq);

Shows a difference:
with the bsp code added it prints:
PHY IRQ:18
and when I remove the bsp code it prints:
PHY IRQ:19

So what is correct, should I add the bsp code or not?

Jocke

#8 lore raw

Hi Jocke,

On Fri, 2007-06-29 at 13:34 +0200, Joakim Tjernlund wrote:
<snip>

Quoted 39 lines

I too am adding such a IRQ for my PHY connected to external IRQ2. The PHY is connetced to UCC2.
I have this in my DTS for the PHY:

	mdio@2320 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2320 18>;
			device_type = "mdio";
			compatible = "ucc_geth_phy";

			phy1: ethernet-phy@0 {
				interrupt-parent = <&ipic>;
				interrupts = <12 2>; //EXT IRQ2
				reg = <0>; // 0
				device_type = "ethernet-phy";
				interface = <3>; //ENET_100_MII
			};

Now the things is that the IRQ works with and without the
/* All external IRQs + Generic timer IRQs must be initialized by BSP */ const int bsp_irqs[] = {48, 17, 18, 19, 20, 21, 22, 23, 90, 78, 84, 72}; for (i=0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)

	virq = irq_create_mapping(NULL, bsp_irqs[i]);
code in my bsp. There is one difference though.
Printing the irq num in phy_interrupt:
static irqreturn_t phy_interrupt(int irq, void *dev_id)
{
	struct net_device *dev = (struct net_device *)dev_id;
	struct ucc_geth_private *ugeth = netdev_priv(dev);

	ugeth_vdbg("%s: IN", __FUNCTION__);
	printk(KERN_ERR "PHY IRQ:%d \n", irq);

Shows a difference:
with the bsp code added it prints:
PHY IRQ:18
and when I remove the bsp code it prints:
PHY IRQ:19

Quoted 3 lines

So what is correct, should I add the bsp code or not?

Jocke

I had to add this board initialization code because on my CPU (8349), certain interrupts weren't automatically mapped by built-in kernel code. Interrupts simply weren't firing, because they hadn't been enabled in the IPIC. Your case is different, because the MDIO device tree entry is parsed by common code (arch/powerpc/sysdev/something).

You probably don't need to explicitly map IRQs unless they're being used by custom device drivers. I don't know why you'd get a different virtual mapping, though. I guess you're effectively mapping the same IRQ twice, and I don't know what that does. Part of me wants to say "if it works properly, who cares", but that's how we get into trouble...

Somebody like Kumar Gala could probably provide a real answer.

regards,
Ben

#9 lore raw
In reply to Joakim Tjernlund
Quoted 15 lines · Joakim Tjernlund
mdio@2320 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2320 18>;
			device_type = "mdio";
			compatible = "ucc_geth_phy";

			phy1: ethernet-phy@0 {
				interrupt-parent = <&ipic>;
				interrupts = <12 2>; //EXT IRQ2
				reg = <0>; // 0
				device_type = "ethernet-phy";
				interface = <3>; //ENET_100_MII
			};
Quoted 7 lines

Now the things is that the IRQ works with and without the
/* All external IRQs + Generic timer IRQs must be initialized by
BSP */
const int bsp_irqs[] = {48, 17, 18, 19, 20, 21, 22, 23, 90, 78,
84, 72};
for (i=0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)

	virq = irq_create_mapping(NULL, bsp_irqs[i]);

This isn't how to use the device tree. That is, you *aren't* using the device tree. You want to read the node of every device you want to set up, and create the mapping. Look at irq_of_parse_and_map(). Look in include/asm-powerpc/prom.h, at of_irq_to_resource(), which maps an irq in the device tree.

Andy

#10 lore raw
Quoted 35 lines

-----Original Message-----
From: Andy Fleming [mailto:[email protected]]
Sent: den 30 juni 2007 01:55
To: Joakim Tjernlund
Cc: [email protected]; [email protected]
Subject: Re: 83xx: requesting external interrupts

Quoted 15 lines · Joakim Tjernlund
mdio@2320 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2320 18>;
			device_type = "mdio";
			compatible = "ucc_geth_phy";

			phy1: ethernet-phy@0 {
				interrupt-parent = <&ipic>;
				interrupts = <12 2>; //EXT IRQ2
				reg = <0>; // 0
				device_type = "ethernet-phy";
				interface = <3>; //ENET_100_MII
			};
Quoted 7 lines

Now the things is that the IRQ works with and without the
/* All external IRQs + Generic timer IRQs must be initialized by
BSP */
const int bsp_irqs[] = {48, 17, 18, 19, 20, 21, 22, 23, 90, 78,
84, 72};
for (i=0;i<sizeof(bsp_irqs)/sizeof(bsp_irqs[0]);i++)

	virq = irq_create_mapping(NULL, bsp_irqs[i]);
Quoted 5 lines

This isn't how to use the device tree. That is, you *aren't* using the device tree. You want to read the node of every device you want to set up, and create the mapping. Look at irq_of_parse_and_map(). Look in include/asm-powerpc/prom.h, at of_irq_to_resource(), which maps an irq in the device tree.

I use both!
I see that ipic.c does all the work for me, so I should just drop the above code. It is strange though that the virq # changes if I keep the code.

hmm, maybe if I sort the bsp_irqs[] list numerically it will be the same? Am at home ATM so I can't verify.

Jocke