world leader in high performance signal processing
Trace: » gpio-keys

GENERAL DESCRIPTION

This page not only contains specific information regarding gpio-keys, but also general information, notably a keysyms list. You may have been referred to this page from a specific IC-based or matrix-peripheral-device page as well.

This sample device driver utilizes the Linux Input Device subsystem. In Particular evdev, which is a generic input event interface. It passes the events generated in the kernel straight to the program, with timestamps. The event codes are the same on all architectures and are hardware independent.

When own keys should be available to a console or read as key codes by an application program (regardless presence of a display), these events must be mapped as simple character 'sources' on tty-devices, details are outlined in fbcon (virtual terminal).

The devices are in /dev/input:

crw-r--r--   1 root     root      13,  64 Apr  1 10:49 event0
crw-r--r--   1 root     root      13,  65 Apr  1 10:50 event1
crw-r--r--   1 root     root      13,  66 Apr  1 10:50 event2
crw-r--r--   1 root     root      13,  67 Apr  1 10:50 event3
...

The Event interface can use blocking and non-blocking reads, also poll() and select()system calls on the /dev/input/eventX devices, and you'll always get a whole number of input events on a read. Their layout is:

struct input_event {
	struct timeval time;
	unsigned short type;
	unsigned short code;
	unsigned int value;
};

time is the timestamp, it returns the time at which the event happened. Type is for example EV_REL for relative moment, REL_KEY for a key-press or release. More types are defined in include/linux/input.h.

code is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input.h.

value is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks …), or 0 for EV_KEY for release, 1 for key-press and 2 for auto-repeat.

For more information please read:

  1. linux-2.6.x/Documentation/input/input.txt
  2. linux-2.6.x/Documentation/input/input-programming.txt

Kernel Configuration for GPIO Input Device Support (gpio-keys)

Setting up Input Device Support

Device Drivers

Input device support

 <*> Generic input layer (needed for keyboard, mouse, ...)
 ---   Userland interfaces
 < >   Mouse interface
 < >   Joystick interface (NEW)
 < >   Touchscreen interface (NEW)
 <*>   Event interface
 < >   Event debugging (NEW)
 ---   Input Device Drivers
 [*]   Keyboards  --->
 [ ]   Mouse  --->
 [ ]   Joysticks (NEW)  --->
 [ ]   Touchscreens (NEW)  --->
 [ ]   Miscellaneous devices  --->
     Hardware I/O ports  --->

Keyboards

 --- Keyboards
 <*>   GPIO Buttons

Warning Messages when Kernel Booting

You will get warning messages(for example on BF527-ezkit),

bfin-gpio: GPIO 16 is already reserved by gpio-keys: BTN0, and you are configuring it as IRQ!
bfin-gpio: GPIO 29 is already reserved by gpio-keys: BTN1, and you are configuring it as IRQ!

It's because gpio-keys requests pin GPIO-16 as a gpio resource,

gpio_keys_probe() -> gpio_request() -> bfin_gpio_request() 

then requests the same pin as irq pin,

gpio_keys_probe() -> request_irq() -> ... -> bfin_gpio_irq_request() 

Both the bfin_gpio_request() and bfin_gpio_irq_request() will check resource conflict. Now we permit a pin be requested both as GPIO and IRQ, but you will see the warning messages.

You can ignore these messages if all the drivers that use GPIO pins work well.

Otherwise, you may really have resource conflict. You can find resource conflict through checking /proc/gpio and /proc/interruts.

Blackfin test programs

[*] Input event device test

event_test application

The example test program shown below listens on the /dev/input/event0 file descriptor,
trying to read any events.

root:~> event_test /dev/input/event0
Input driver version is 1.0.0
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-keys"
Supported events:
  Event type 0 (Reset)
    Event code 0 (Reset)
    Event code 1 (Key)
  Event type 1 (Key)
    Event code 74 (KPMinus)
    Event code 78 (KPPlus)
Testing ... (interrupt to exit)
Event: time 4935.127416, type 1 (Key), code 78 (KPPlus), value 1
Event: time 4935.127431, type 0 (Reset), code 0 (Reset), value 0
Event: time 4935.251759, type 1 (Key), code 78 (KPPlus), value 0
Event: time 4935.251770, type 0 (Reset), code 0 (Reset), value 0
Event: time 4935.487180, type 1 (Key), code 78 (KPPlus), value 1
Event: time 4935.487192, type 0 (Reset), code 0 (Reset), value 0
Event: time 4935.571668, type 1 (Key), code 78 (KPPlus), value 0
Event: time 4935.571675, type 0 (Reset), code 0 (Reset), value 0
Event: time 4936.248747, type 1 (Key), code 78 (KPPlus), value 1
Event: time 4936.248760, type 0 (Reset), code 0 (Reset), value 0
Event: time 4936.367608, type 1 (Key), code 78 (KPPlus), value 0
Event: time 4936.367619, type 0 (Reset), code 0 (Reset), value 0
Event: time 4936.572710, type 1 (Key), code 78 (KPPlus), value 1
Event: time 4936.572722, type 0 (Reset), code 0 (Reset), value 0
Event: time 4936.661097, type 1 (Key), code 78 (KPPlus), value 0
Event: time 4936.661104, type 0 (Reset), code 0 (Reset), value 0

You get one event per key press and another per key release.

Customizing the gpio-keys driver

customizing_for_your_board

In your Board Resource file add follwoing:

file: arch/blackfin/mach-bf537/boards/stamp.c

scm failed with exit code 1:
file does not exist in git

Also make sure that the &bfin_device_gpiokeys is added to your your board's platform data.

file: arch/blackfin/mach-bf537/boards/stamp.c

scm failed with exit code 1:
file does not exist in git

Be aware that this driver has no debouncing as a default property. Moreover, debouncing must be specified for each input individually, if desired. A reasonable value is 20 (milliseconds). This can be added by changing the definition to something like:

{KEY_A, GPIO_PF4, 1, "gpio-keys: A", EV_KEY, 0, 20},

Above example registers 4 keys

GPIO KeyCode
GPIO_PF2BTN_0
GPIO_PF3BTN_1
GPIO_PF4KEY_A
GPIO_PF5KEY_B

file: include/linux/gpio_keys.h

scm failed with exit code 1:
file does not exist in git

For a full list of EVENTS and KEYCODES see here:

file: include/linux/input.h

scm failed with exit code 1:
file does not exist in git