接前一篇文章:Linux设备驱动之gpio-keys(1)
本文内容参考:
Linux设备驱动之gpio-keys_linux gpio-keys-CSDN博客
GPIO-KEY的实现原理及使用方法_gpio-keys-CSDN博客
linux gpio key 实现方式_llinux gpio key 长按-CSDN博客
特此致谢!
上一回讲到了设备树(DTS)配置,给出了Linux内核代码中Documentation/devicetree/bindings/gpio/gpio-keys.txt文件,本回开始解析其具体内容。
二、详细解析
1. 设备树配置(DTS)
为了便于理解和回顾,再次贴出<Linux内核源码根目录>/Documentation/devicetree/bindings/gpio/gpio-keys.txt内容,如下:
bash
Device-Tree bindings for input/keyboard/gpio_keys.c keyboard driver
Required properties:
- compatible = "gpio-keys";
Optional properties:
- autorepeat: Boolean, Enable auto repeat feature of Linux input
subsystem.
- label: String, name of the input device.
Each button (key) is represented as a sub-node of "gpio-keys":
Subnode properties:
- gpios: OF device-tree gpio specification.
- interrupts: the interrupt line for that input.
- label: Descriptive name of the key.
- linux,code: Keycode to emit.
Note that either "interrupts" or "gpios" properties can be omitted, but not
both at the same time. Specifying both properties is allowed.
Optional subnode-properties:
- linux,input-type: Specify event type this button/key generates.
If not specified defaults to <1> == EV_KEY.
- debounce-interval: Debouncing interval time in milliseconds.
If not specified defaults to 5.
- wakeup-source: Boolean, button can wake-up the system.
(Legacy property supported: "gpio-key,wakeup")
- wakeup-event-action: Specifies whether the key should wake the
system when asserted, when deasserted, or both. This property is
only valid for keys that wake up the system (e.g., when the
"wakeup-source" property is also provided).
Supported values are defined in linux-event-codes.h:
EV_ACT_ASSERTED - asserted
EV_ACT_DEASSERTED - deasserted
EV_ACT_ANY - both asserted and deasserted
- linux,can-disable: Boolean, indicates that button is connected
to dedicated (not shared) interrupt which can be disabled to
suppress events from the button.
Example nodes:
gpio-keys {
compatible = "gpio-keys";
autorepeat;
up {
label = "GPIO Key UP";
linux,code = <103>;
gpios = <&gpio1 0 1>;
};
down {
label = "GPIO Key DOWN";
linux,code = <108>;
interrupts = <1 IRQ_TYPE_LEVEL_HIGH 7>;
};
...
Required properties
-
- compatible = "gpio-keys";
该属性定义了设备的兼容性。
Optional properties
-
- autorepeat
布尔类型,启用input子系统的auto repeat特性。
-
- label
字符串类型,输入设备(如按键key)的名称。
Subnode properties
每一个按钮(button)/按键(key)都对应为"gpio-keys"的一个子节点,子节点的属性包括:
-
- gpios
开放固件设备树GPIO规范。
-
- interrupts
输入的中断线。
-
- label
按键的描述性名称。
-
- linux,code
input子系统所定义的按键代码。参见:include/dt-bindings/input/input.h关于keys和buttons的code定义。
注意:"interrupts"或"gpios"属性都可以省略,但不能同时省略。允许同时指定这两个属性。
Optional subnode-properties
-
- linux,input-type
定义该key/button的event type(input子系统定义)。如果未指定,默认为1(EV_KEY)。
-
- debounce-interval
定义该key/button的去抖间隔。如果未指定,默认为5ms。
- -gpio-key,wakeup
布尔类型。标识该key可以唤醒系统,例如,Android系统的power-key。
-
- wakeup-event-action
指定按键在断言(有效)、取消断言(失效)或两者时,都应唤醒系统。
此属性仅对能唤醒系统的按键有效(例如,当同时提供"wakeup-source"属性时)。
支持的值在linux-event-codes.h中定义:
EV_ACT_ASSERTED - asserted
EV_ACT_DEASSERTED - deasserted
EV_ACT_ANY - both asserted and deasserted
-
- linux,can-disable:
布尔类型。表明某按钮连接到专用(非共享)中断,可以禁用该中断以抑制按钮的事件。
示例(结点):
bash
gpio-keys {
compatible = "gpio-keys";
autorepeat;
up {
label = "GPIO Key UP";
linux,code = <103>;
gpios = <&gpio1 0 1>;
};
down {
label = "GPIO Key DOWN";
linux,code = <108>;
interrupts = <1 IRQ_TYPE_LEVEL_HIGH 7>;
};
...
这样,Documentation/devicetree/bindings/gpio/gpio-keys.txt的内容就解析完了。更多内容请看下回。