2015-08-05 16:28:53

by Andrew Lunn

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

On Wed, Aug 05, 2015 at 08:31:27PM +0530, raghu MG wrote:
> Hi Andrew,
>
> The issue I found was irq_alloc_descs is called twice
> 1st time inside mvebu_gpio_probe & 2nd time inside irq_domain_add_simple.

So i'm somewhat confused. I just tested on my Kirkwood and 370
platforms, and an Armada XP WRT1900AC using 4.2.0-rc5, all which use
the same gpio driver.

They boot fine, the gpio driver is loaded, and the interrupt for the
gpio connected to a button are listed in /proc/interrupts. The
gpio-key driver is also able to use the gpio and the input-events
program does show events when i press the button.

So what is different with your platform?

Andrew


2015-08-06 05:54:50

by raghu MG

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

Hi Andrew,

My platform/board is ATCA carrier card which is getting interface to I/O card.
The I/O card is hot-pluggable or Jack-in or Jack out.
Also I/O card consists of hot-plugable SFP interface.
These events are triggered using GPIO's

So the events the carrier card recieves are
1) If I/O card is either Jacked-in or Jacked-out ,respective GPIO
pin-x triggers an event
2) If SFP is pushed into I/O card the respective GPIO pin-y triggers an event.




Another observation about "irq: Cannot allocate irq_descs @ IRQ47/79/111".
This is warning & irq_descs are already allocated , the overall
initialization/probe function doesn't get effected.
mvebu_gpio_irq_handler is only called if I register a another handler
at irq=82/83/84/85/87/88/89/90/92. I am registering this handler using
minimal kernel module.
My understanding of Linux IRQ/interrupt mechanism is limited to
request_irq, but registering domain & then IRQ is bit not clear.

Regards
Raghu




On Wed, Aug 5, 2015 at 9:51 PM, Andrew Lunn <[email protected]> wrote:
> On Wed, Aug 05, 2015 at 08:31:27PM +0530, raghu MG wrote:
>> Hi Andrew,
>>
>> The issue I found was irq_alloc_descs is called twice
>> 1st time inside mvebu_gpio_probe & 2nd time inside irq_domain_add_simple.
>
> So i'm somewhat confused. I just tested on my Kirkwood and 370
> platforms, and an Armada XP WRT1900AC using 4.2.0-rc5, all which use
> the same gpio driver.
>
> They boot fine, the gpio driver is loaded, and the interrupt for the
> gpio connected to a button are listed in /proc/interrupts. The
> gpio-key driver is also able to use the gpio and the input-events
> program does show events when i press the button.
>
> So what is different with your platform?
>
> Andrew

2015-08-06 13:36:26

by Andrew Lunn

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

> mvebu_gpio_irq_handler is only called if I register a another handler
> at irq=82/83/84/85/87/88/89/90/92. I am registering this handler using
> minimal kernel module.

This is totally wrong. The gpio driver needs these interrupts, and
will register a chained interrupt handle for these. Don't mess around
with them. Here is the code in the driver:

/* Setup the interrupt handlers. Each chip can have up to 4
* interrupt handlers, with each handler dealing with 8 GPIO
* pins. */
for (i = 0; i < 4; i++) {
int irq = platform_get_irq(pdev, i);

if (irq < 0)
continue;
irq_set_handler_data(irq, mvchip);
irq_set_chained_handler(irq, mvebu_gpio_irq_handler);
}

Andrew

2015-08-06 16:58:15

by raghu MG

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

Ok,I think I need to understand more about this gpio driver.

As you said its registering chained handler,but why are they(IRQs) not
visible in cat /proc/interrupts.
What could be the reason.?

Do I need to further initialize marvell GPIO registers to trigger
these events. The driver is unmasking all interrupts in probe function
writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF);
writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF);


Do I need to change the polarity in polarity register to suit the
board requirements in probe function.

I will try this in the morning.


Regards
Raghu

On Thu, Aug 6, 2015 at 6:59 PM, Andrew Lunn <[email protected]> wrote:
>> mvebu_gpio_irq_handler is only called if I register a another handler
>> at irq=82/83/84/85/87/88/89/90/92. I am registering this handler using
>> minimal kernel module.
>
> This is totally wrong. The gpio driver needs these interrupts, and
> will register a chained interrupt handle for these. Don't mess around
> with them. Here is the code in the driver:
>
> /* Setup the interrupt handlers. Each chip can have up to 4
> * interrupt handlers, with each handler dealing with 8 GPIO
> * pins. */
> for (i = 0; i < 4; i++) {
> int irq = platform_get_irq(pdev, i);
>
> if (irq < 0)
> continue;
> irq_set_handler_data(irq, mvchip);
> irq_set_chained_handler(irq, mvebu_gpio_irq_handler);
> }
>
> Andrew

2015-08-06 17:20:22

by Andrew Lunn

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

On Thu, Aug 06, 2015 at 10:28:12PM +0530, raghu MG wrote:
> Ok,I think I need to understand more about this gpio driver.
>
> As you said its registering chained handler,but why are they(IRQs) not
> visible in cat /proc/interrupts.

chained interrupts are never visible there. All you see are leaf
interrupts, i.e. the device interrupts. Here is my Armada XP based
WRT1900AC:

$ cat /proc/interrupts
CPU0 CPU1
16: 8959833 12783597 armada_370_xp_irq 5 Level armada_370_xp_per_cpu_tick
19: 0 0 armada_370_xp_irq 31 Level mv64xxx_i2c
20: 1453 0 armada_370_xp_irq 41 Level serial
26: 0 0 armada_370_xp_irq 45 Level ehci_hcd:usb3
27: 9682 0 armada_370_xp_irq 8 Level mvneta
28: 4 0 armada_370_xp_irq 10 Level mvneta
29: 35078 0 armada_370_xp_irq 55 Level f10a0000.sata
30: 3839 0 armada_370_xp_irq 113 Level f10d0000.nand
70: 0 0 f1018140.gpio 0 Edge WPS
71: 20 0 f1018140.gpio 1 Edge Factory Reset Button
90: 2 0 armada_370_xp_irq 51 Level f1060900.xor
91: 2 0 armada_370_xp_irq 52 Level f1060900.xor
92: 2 0 armada_370_xp_irq 94 Level f10f0900.xor
93: 2 0 armada_370_xp_irq 95 Level f10f0900.xor
94: 0 0 armada_370_xp_msi_irq 0 Edge xhci_hcd

Notice the two f1018140.gpio, which are the buttons.

> Do I need to further initialize marvell GPIO registers to trigger
> these events.

Nope, just the normal gpio API and all will work, as demonstrated by
the two buttons on my board.

> Do I need to change the polarity in polarity register to suit the
> board requirements in probe function.

Nope, you put that in the DT file:

gpio_keys {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-0 = <&keys_pin>;
pinctrl-names = "default";

button@1 {
label = "WPS";
linux,code = <KEY_WPS_BUTTON>;
gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>;
};

button@2 {
label = "Factory Reset Button";
linux,code = <KEY_RESTART>;
gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>;
};
};

You can change GPIO_ACTIVE_HIGH to GPIO_ACTIVE_LOW if that is what you
need.

Andrew

2015-08-06 18:18:35

by raghu MG

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

Ok...
my bad never realised DT entries are necessary.
will try this & post the results.

Regards
Raghu

On Thu, Aug 6, 2015 at 10:43 PM, Andrew Lunn <[email protected]> wrote:
> On Thu, Aug 06, 2015 at 10:28:12PM +0530, raghu MG wrote:
>> Ok,I think I need to understand more about this gpio driver.
>>
>> As you said its registering chained handler,but why are they(IRQs) not
>> visible in cat /proc/interrupts.
>
> chained interrupts are never visible there. All you see are leaf
> interrupts, i.e. the device interrupts. Here is my Armada XP based
> WRT1900AC:
>
> $ cat /proc/interrupts
> CPU0 CPU1
> 16: 8959833 12783597 armada_370_xp_irq 5 Level armada_370_xp_per_cpu_tick
> 19: 0 0 armada_370_xp_irq 31 Level mv64xxx_i2c
> 20: 1453 0 armada_370_xp_irq 41 Level serial
> 26: 0 0 armada_370_xp_irq 45 Level ehci_hcd:usb3
> 27: 9682 0 armada_370_xp_irq 8 Level mvneta
> 28: 4 0 armada_370_xp_irq 10 Level mvneta
> 29: 35078 0 armada_370_xp_irq 55 Level f10a0000.sata
> 30: 3839 0 armada_370_xp_irq 113 Level f10d0000.nand
> 70: 0 0 f1018140.gpio 0 Edge WPS
> 71: 20 0 f1018140.gpio 1 Edge Factory Reset Button
> 90: 2 0 armada_370_xp_irq 51 Level f1060900.xor
> 91: 2 0 armada_370_xp_irq 52 Level f1060900.xor
> 92: 2 0 armada_370_xp_irq 94 Level f10f0900.xor
> 93: 2 0 armada_370_xp_irq 95 Level f10f0900.xor
> 94: 0 0 armada_370_xp_msi_irq 0 Edge xhci_hcd
>
> Notice the two f1018140.gpio, which are the buttons.
>
>> Do I need to further initialize marvell GPIO registers to trigger
>> these events.
>
> Nope, just the normal gpio API and all will work, as demonstrated by
> the two buttons on my board.
>
>> Do I need to change the polarity in polarity register to suit the
>> board requirements in probe function.
>
> Nope, you put that in the DT file:
>
> gpio_keys {
> compatible = "gpio-keys";
> #address-cells = <1>;
> #size-cells = <0>;
> pinctrl-0 = <&keys_pin>;
> pinctrl-names = "default";
>
> button@1 {
> label = "WPS";
> linux,code = <KEY_WPS_BUTTON>;
> gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>;
> };
>
> button@2 {
> label = "Factory Reset Button";
> linux,code = <KEY_RESTART>;
> gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>;
> };
> };
>
> You can change GPIO_ACTIVE_HIGH to GPIO_ACTIVE_LOW if that is what you
> need.
>
> Andrew
>

2015-08-07 20:54:12

by raghu MG

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

Hi Andrew,
I added these entries into armada-xp-gp.dtb
gpio_rtm {
compatible = "gpio-rtm";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-0 = <&keys_pin>;
pinctrl-names = "default";

rtm@57 {
label = "RTM JACKINOUT";
gpios = <&gpio1 26 GPIO_ACTIVE_LOW>; /* GPIO 57 */
};
};

So I understand the leaf nodes are specific purpose of
GPIOs(input:keyboard,mouse,touchpad etc).
1)For the board I am working needs different implementation for GPIO
57 unlike input devices drivers driving GPIOs.
2)To implement the functionality I need to write driver specific to my
board which will implement event specific to requirements.
I hope I am going right here, can you name a simple driver(kernel
source) where it would make my driver development easy.

Thanks & Regards
Raghu

2015-08-07 22:17:55

by Andrew Lunn

[permalink] [raw]
Subject: Re: Armadaxp GPIO interrupts

On Sat, Aug 08, 2015 at 02:24:04AM +0530, raghu MG wrote:
> Hi Andrew,
> I added these entries into armada-xp-gp.dtb
> gpio_rtm {
> compatible = "gpio-rtm";
> #address-cells = <1>;
> #size-cells = <0>;
> pinctrl-0 = <&keys_pin>;
> pinctrl-names = "default";
>
> rtm@57 {
> label = "RTM JACKINOUT";
> gpios = <&gpio1 26 GPIO_ACTIVE_LOW>; /* GPIO 57 */
> };
> };
>
> So I understand the leaf nodes are specific purpose of
> GPIOs(input:keyboard,mouse,touchpad etc).
> 1)For the board I am working needs different implementation for GPIO
> 57 unlike input devices drivers driving GPIOs.
> 2)To implement the functionality I need to write driver specific to my
> board which will implement event specific to requirements.
> I hope I am going right here, can you name a simple driver(kernel
> source) where it would make my driver development easy.

Given the name "RTM JACKINOUT", how about

sound/soc/soc-jack.c

Andrew