Driver examples

You can summarize things in the two following drivers. The first one is a polled input device, based on a GPIO not mapped to IRQ. The polled input core will poll the GPIO to sense any changes. This driver is configured to send a 0 keycode. Each GPIO state corresponds to either a key press or a key release:

#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/of.h> /* For DT*/ #include <linux/platform_device.h> /* For platform devices */ #include <linux/gpio/consumer.h> /* For GPIO Descriptor interface */ #include <linux/input.h> #include <linux/input-polldev.h> struct poll_btn_data { struct gpio_desc *btn_gpiod; struct input_polled_dev *poll_dev; }; static void polled_btn_open(struct ...

Get Linux Device Drivers Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.