kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* How is gpio_keys.ko supposed to work?
@ 2013-03-28 16:13 Sven Geggus
  2013-03-29 17:46 ` Jerry Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Geggus @ 2013-03-28 16:13 UTC (permalink / raw)
  To: kernelnewbies

Hello,

I have a userland application on Raspberry Pi which uses select to read
input from a button connected to gpio like this:

GPIO --+---- BUTTON ----- GND
       |
       +--- RESISTOR 2k -- VCC (3.3V)

The sysfs "file" I use select at is /sys/class/gpio/gpioX/value with the
method found in Documentation/gpio.txt.

However, this same file also states the following:
Note that standard kernel drivers exist for common "LEDs and Buttons"
GPIO tasks:  "leds-gpio" and "gpio_keys", respectively.  Use those
instead of talking directly to the GPIOs; they integrate with kernel
frameworks better than your userspace code could.

So how can I make this "standard kernel drivers" work?

I would like to get rid of using /sys/class/gpio/gpioX/value and use
/dev/input/eventX instead, because the first method will require debouncing
in userland and is not portable to other keyboard types.

I tried to compile a kernel with CONFIG_KEYBOARD_GPIO enabled and load
gpio_keys.ko. However this did neither create a new device in /dev/input/
nor /sys/devices/platform/gpio-keys.

Kconfig states the following:
...
Your board-specific setup logic must also provide a platform device,
with configuration data saying which GPIOs are used.
...

So looks like my "board-specific setup logic" (whatever this might be) does
not "provide a platform device with configuration data saying which GPIOs
are used".

So my question is twofold:
1. Where can I find the "board-specific setup logic" (for Rapberry Pi in my
case
2. How would this "board-specific setup logic" (if unavailable) look like to
make gpio_keys.ko work?

Sven

P.S.: The kernel in use is the one from
git://github.com/raspberrypi/linux.git which is basically a vanilla 3.6.11
with Raspberry Pi specific patches.

-- 
Threading is a performance hack.
(The Art of Unix Programming by Eric S. Raymond)

/me is giggls at ircnet, http://sven.gegg.us/ on the Web

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

* How is gpio_keys.ko supposed to work?
  2013-03-28 16:13 How is gpio_keys.ko supposed to work? Sven Geggus
@ 2013-03-29 17:46 ` Jerry Zhang
  2013-03-30 18:41   ` Sven Geggus
  0 siblings, 1 reply; 3+ messages in thread
From: Jerry Zhang @ 2013-03-29 17:46 UTC (permalink / raw)
  To: kernelnewbies

2013/3/29 Sven Geggus <lists@fuchsschwanzdomain.de>

> Hello,
>
> I have a userland application on Raspberry Pi which uses select to read
> input from a button connected to gpio like this:
>
> GPIO --+---- BUTTON ----- GND
>        |
>        +--- RESISTOR 2k -- VCC (3.3V)
>
> The sysfs "file" I use select at is /sys/class/gpio/gpioX/value with the
> method found in Documentation/gpio.txt.
>
> However, this same file also states the following:
> Note that standard kernel drivers exist for common "LEDs and Buttons"
> GPIO tasks:  "leds-gpio" and "gpio_keys", respectively.  Use those
> instead of talking directly to the GPIOs; they integrate with kernel
> frameworks better than your userspace code could.
>
> So how can I make this "standard kernel drivers" work?
>
> I would like to get rid of using /sys/class/gpio/gpioX/value and use
> /dev/input/eventX instead, because the first method will require debouncing
> in userland and is not portable to other keyboard types.
>
> I tried to compile a kernel with CONFIG_KEYBOARD_GPIO enabled and load
> gpio_keys.ko. However this did neither create a new device in /dev/input/
> nor /sys/devices/platform/gpio-keys.
>

The entry will only be created after the "Driver" probes the "Device"
successfully. In your case, you need to be sure the corresponding
platform_device is claimed in your board setup code. The setup logic vary
from Arch/mach to Arch/mach. Here is one example from sh.

http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c

 199 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L199>static
struct gpio_keys_platform_data
<http://lxr.linux.no/linux+v3.4.11/+code=gpio_keys_platform_data>
baseboard_buttons_data
<http://lxr.linux.no/linux+v3.4.11/+code=baseboard_buttons_data> = {
200 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L200>
       .buttons <http://lxr.linux.no/linux+v3.4.11/+code=buttons>
  = baseboard_buttons
<http://lxr.linux.no/linux+v3.4.11/+code=baseboard_buttons>, 201
<http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L201>
       .nbuttons <http://lxr.linux.no/linux+v3.4.11/+code=nbuttons>
   = ARRAY_SIZE
<http://lxr.linux.no/linux+v3.4.11/+code=ARRAY_SIZE>(baseboard_buttons
<http://lxr.linux.no/linux+v3.4.11/+code=baseboard_buttons>), 202
<http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L202>};
203 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L203>
204 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L204>static
struct platform_device
<http://lxr.linux.no/linux+v3.4.11/+code=platform_device>
baseboard_buttons_device
<http://lxr.linux.no/linux+v3.4.11/+code=baseboard_buttons_device> = {
205 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L205>
       .name <http://lxr.linux.no/linux+v3.4.11/+code=name>
= "gpio-keys", 206
<http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L206>
       .id <http://lxr.linux.no/linux+v3.4.11/+code=id>             =
-1, 207 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L207>
       .dev <http://lxr.linux.no/linux+v3.4.11/+code=dev>            =
{ 208 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L208>
               .platform_data
<http://lxr.linux.no/linux+v3.4.11/+code=platform_data>  =
&baseboard_buttons_data
<http://lxr.linux.no/linux+v3.4.11/+code=baseboard_buttons_data>, 209
<http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L209>
       }, 210 <http://lxr.linux.no/linux+v3.4.11/arch/sh/boards/mach-x3proto/setup.c#L210>};





>
> Kconfig states the following:
> ...
> Your board-specific setup logic must also provide a platform device,
> with configuration data saying which GPIOs are used.
> ...
>
> So looks like my "board-specific setup logic" (whatever this might be) does
> not "provide a platform device with configuration data saying which GPIOs
> are used".
>
> So my question is twofold:
> 1. Where can I find the "board-specific setup logic" (for Rapberry Pi in my
> case
> 2. How would this "board-specific setup logic" (if unavailable) look like
> to
> make gpio_keys.ko work?
>
> Sven
>
> P.S.: The kernel in use is the one from
> git://github.com/raspberrypi/linux.git which is basically a vanilla 3.6.11
> with Raspberry Pi specific patches.
>
> --
> Threading is a performance hack.
> (The Art of Unix Programming by Eric S. Raymond)
>
> /me is giggls at ircnet, http://sven.gegg.us/ on the Web
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130330/1e6a22b3/attachment.html 

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

* How is gpio_keys.ko supposed to work?
  2013-03-29 17:46 ` Jerry Zhang
@ 2013-03-30 18:41   ` Sven Geggus
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Geggus @ 2013-03-30 18:41 UTC (permalink / raw)
  To: kernelnewbies

Jerry Zhang <jerry.scofield@gmail.com> wrote:

> The entry will only be created after the "Driver" probes the "Device"
> successfully. In your case, you need to be sure the corresponding
> platform_device is claimed in your board setup code.

What does claiming the device actually mean? Do I really need to
hardcode the GPIOs where buttons are connected at compile time?

This would not be a very good idea for a User configurable board like
Raspberry Pi.

I actually thought that I could configure the gpios where buttons are
connected at runtime using sysfs, depending on the actual hardware
setup in use.

Sven

-- 
"Das Einzige wovor wir Angst haben m?ssen ist die Angst selbst"
						(Franklin D. Roosevelt)

/me is giggls at ircnet, http://sven.gegg.us/ on the Web

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

end of thread, other threads:[~2013-03-30 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-28 16:13 How is gpio_keys.ko supposed to work? Sven Geggus
2013-03-29 17:46 ` Jerry Zhang
2013-03-30 18:41   ` Sven Geggus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).