Linux设备驱动之gpio-keys(2)

接前一篇文章:Linux设备驱动之gpio-keys(1)

本文内容参考:

Linux设备驱动之gpio-keys_linux gpio-keys-CSDN博客

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的内容就解析完了。更多内容请看下回。

相关推荐
BlueBirdssh14 天前
时钟相位差
linux驱动
ton_tom3 个月前
设备驱动程序编程-Linux2.6.10-kdb安装
linux驱动
淮北也生橘123 个月前
Linux驱动知识点:容器嵌入机制(Container Embedding)
linux驱动·嵌入式linux
yan123688 个月前
Linux 驱动之设备树
android·linux·驱动开发·linux驱动
liuluyang5309 个月前
linux sysfs的使用
linux驱动·sysfs
m0_747124531 年前
基于 IMX6ULL 的环境监测自主调控系统
linux驱动
m0_747124531 年前
Linux 驱动入门(5)—— DHT11(温湿度传感器)驱动
linux·linux驱动
御风_211 年前
Linux——字符设备驱动控制LED
linux·ubuntu·linux驱动
臻一1 年前
Rockchip-linux驱动 --- IIC
iic·linux驱动