按键驱动流程分析

设备树相关的配置:

gpio_keys {
		compatible = "gpio-keys";
                label = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&gpio_key_active>;
		goog_key {
			label = "google_key";
			gpios = <&tlmm 90 0x1>;
			linux,input-type = <1>;
			linux,code = <236>;
			debounce-interval = <15>;
			gpio-key,wakeup;
			linux,can-disable;      
		};
		vol_up {
			label = "volume_up";
			gpios = <&tlmm 91 0x1>;
			linux,input-type = <1>;
			linux,code = <115>;
			debounce-interval = <15>;
			linux,can-disable;
			gpio-key,wakeup;
		};
};

相关结构体成员:

相关结构体成员:
struct gpio_keys_platform_data {
	struct gpio_keys_button *buttons;
	int nbuttons;
	unsigned int poll_interval;
	unsigned int rep:1;
	int (*enable)(struct device *dev);
	void (*disable)(struct device *dev);
	const char *name;
};

struct gpio_keys_button {
	unsigned int code;
	int gpio;
	int active_low;
	const char *desc;
	unsigned int type;
	int wakeup;
	int debounce_interval;
	bool can_disable;
	int value;
	unsigned int irq;
	struct gpio_desc *gpiod;
};

struct gpio_keys_drvdata {
	const struct gpio_keys_platform_data *pdata;
	struct input_dev *input;
	struct mutex disable_lock;
	struct gpio_button_data data[0];
};

struct gpio_button_data {
	const struct gpio_keys_button *button;
	struct input_dev *input;
	struct gpio_desc *gpiod;

	struct timer_list release_timer;
	unsigned int release_delay;	/* in msecs, for IRQ-only buttons */

	struct delayed_work work;
	unsigned int software_debounce;	/* in msecs, for GPIO-driven buttons */

	unsigned int irq;
	spinlock_t lock;
	bool disabled;
	bool key_pressed;
};

代码流程:

gpio_keys_init
        |
	    |    (设置这个结构体gpio_keys_device_driver       
	    |--- platform_driver_register                    |--- gpio_keys_get_devtree_pdata(struct device *dev)  解析设备树
                              |                          |
                              |                          |
                              |--- gpio_keys_probe    ---|--- devm_input_allocate_device  分配一个输入设备
                                                         |
                                                         |
                                                         |--- gpio_keys_setup_key  申请GPIO、申请中断,设置gpio_keys_gpio_work_func工作队列函数、gpio_keys_gpio_isr中断函数
                                                                       |
                                                                       |
                                                                       |--- gpio_keys_gpio_isr   按下音量下键触发中断
                                                                                      |
                                                                                      |
                                                                                      |--- gpio_keys_gpio_work_func  
                                                                                                     |
                                                                                                     |
                                                                                                     |--- gpio_keys_gpio_report_event  上报键值

 

你可能感兴趣的:(【Linux底层】)