How is gpio_keys.ko supposed to work?
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 fromgit://github.com/raspberrypi/linux.git which is basically a vanilla 3.6.11 with Raspberry Pi specific patches.
Signature · 4 lines
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
2013/3/29 Sven Geggus <[email protected]>
Quoted 20 lines
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/valuewith the method found inDocumentation/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?
Quoted 8 lines
I would like to get rid of using
/sys/class/gpio/gpioX/valueand use/dev/input/eventXinstead, 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_GPIOenabled 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>};
Quoted 28 lines
Kconfigstates 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 fromgit://github.com/raspberrypi/linux.gitwhich 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)
Quoted 7 lines
/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
Quoted 3 lines · Jerry Zhang
The entry will only be created after the "Driver" probes the "Device" successfully. In your case, you need to be sure the corresponding
platform_deviceis 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
Signature · 4 lines
"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