GPIO and IRQs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPIO and IRQs

5,369 Views
GabrielSartori
Contributor II

Hi,

  I have two buttons plugged in my board.

  I would like to create a input driver for them. I am trying to use the gpio-keys driver.

  In the file ../arch/arm/mach-mx28/device.c I have added the above code.

  #if defined(CONFIG_KEYBOARD_GPIO)

#define MXS_KEY_BTN_0   MXS_PIN_TO_GPIO(PINID_SAIF0_SDATA0)
#define MXS_KEY_BTN_1   MXS_PIN_TO_GPIO(PINID_SAIF1_SDATA0)

#define KEY_BTN_0       0
#define KEY_BTN_1       1

static struct gpio_keys_button mxs_buttons[] = {

{
.code = KEY_BTN_0,
.gpio = MXS_KEY_BTN_0,
.desc = "User button 0",
.active_low = 0,
},

{
.code = KEY_BTN_1,
.gpio = MXS_KEY_BTN_1,
.desc = "User button 1",
.active_low = 0,
}
};

static struct gpio_keys_platform_data mxs_button_data = {
.buttons = mxs_buttons,
.nbuttons = ARRAY_SIZE(mxs_buttons),
};

static struct platform_device mxs_gpio_buttons = {
.name = "gpio-keys",
.id = -1,
.dev = {
.platform_data = &mxs_button_data,
},
};

static void __init mx28_init_btn(void)
{
        platform_device_register(&mxs_gpio_buttons);
}
#else
static void mx28_init_btn(void)
{
}
#endif

And then I added the mx28_init_btn in the mx28_device_init.

I did not get any compiling messages but in the boot it gives me a message telling that I failed to request_irq 247.

How can I tell kernel to request the IRQ_GPIO0 for the GPIO 247, for example?

I hope I was clear enough.

Thanks in advance.

Gabriel Sartori

Labels (1)
9 Replies

1,905 Views
peteewg
Contributor III

Okay, time for a dumb idiot newbie post.

I've only been at this for a couple of weeks (This is my first time building linux, using yocto/bitbake and developing for imx)

when you say...

../arch/arm/mach-mx28/device.c


where exactly do you mean?


I'm using yocto with the default settings and the closet I can find is :

build/tmp/sysroots/imx28evk/usr/src/kernel/arch/arm/mach-mx28

but I don't see any ".c" files I only have the header file "device.h"

Also on my imx28evk image the  usr/src file is empty, I'm obviously missing something but I don't know what.

My first simple tasks I've set myself are to get the Heartbeat working on LED3 instead of LED2 (imx28evk),

And to read LRADC values with different buttons pressed.

TBH I'm a bit lost as to where to start, what to include, whether I should be modifying code in tmp/sysroots.... or somehow getting bitbake to pick alternatives.

Any tips?

0 Kudos

1,905 Views
fabio_estevam
NXP Employee
NXP Employee

If you use a recent kernel, such as 3.10, then you can use device tree, which makes this task much easier.

You can see how other boards implement this at arch/arm/boot/dts.

For example, for mx6qsabresd:

gpio-keys {
   compatible = "gpio-keys";

   volume-up {
   label = "Volume Up";
   gpios = <&gpio1 4 0>;
   gpio-key,wakeup;
   linux,code = <115>; /* KEY_VOLUMEUP */
   };

   volume-down {
   label = "Volume Down";
   gpios = <&gpio1 5 0>;
   gpio-key,wakeup;
   linux,code = <114>; /* KEY_VOLUMEDOWN */
   };

    };

0 Kudos

1,905 Views
Conrad1z
Contributor II

irq 247 is the "virtual" irq number associated with PINID_SAIF0_SDATA0. The call to request_irq come from the driver gpio_keys.c. The error was probably due to the pin SAIF0_SDATA0 was already requested. You need to disable CONFIG_SND_MXS_SOC_DAI (see mx28evk_fixed_pins in mx28evk_pins.c)

However, even if irq 247 can successfully be requested, the key function still won't work. It is because the driver (gpio_keys.c) uses both IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING which is not supported by i.MX28 :-(

1,905 Views
CraigMcQueen
Contributor III

Conrad Conrad wrote:

However, even if irq 247 can successfully be requested, the key function still won't work. It is because the driver (gpio_keys.c) uses both IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING which is not supported by i.MX28

That is true, however it is possible to modify the driver so it only uses one trigger. Then in the interrupt handler, change it to the other trigger setting, depending on the current state of the GPIO input (and take care to handle race conditions). I could probably provide a patch file if anyone is interested.

(I initially tried to do this with IRQF_TRIGGER_HIGH and IRQF_TRIGGER_LOW, because that would be more robust in principle, but I had trouble using these trigger types (it would lock up).)

1,905 Views
whitewool
Contributor I

Hi,

I have exactly the same problem with the new HW version of an imx233 based device, 4 GPIO buttons, and I need absolutely to handle both edges because the user interface is pressure duration sensitive.

Using gpio_keys.c should be the clean way, so I also would like to see the patched gpio_keys.c.

Could you help me please?

Thanks

Alberto

0 Kudos

1,905 Views
whitewool
Contributor I

Ok, this version is a bit dirty but works with trigger level driver.

Alberto

gpio_keys.c

0 Kudos

1,905 Views
sujathap_m_
Contributor I

Hello,

Even I'm also facing same problem, couldn't request the irq193 successfully.

I have used your patch,still same problem.

Following messages are found during booting:

setting trigger mode 3 for irq 193 failed (mxs_gpio_set_irq_type+0x0/0x5c)

gpio-keys: Unable to claim irq 193; error -6

Regards,

Sujatha

0 Kudos

1,905 Views
UnisvrTim
Contributor III

I would like to see the patch. I am working on an i.MX280 board, need to learn how to convert the GPIO settings from imx28evk to our customized board. Thank you in advance.

0 Kudos

1,905 Views
CraigMcQueen
Contributor III

I know it's been a while, sorry. Here is a patch that I've used.

0 Kudos