Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Linux Device Drivers

Similar presentations


Presentation on theme: "Introduction to Linux Device Drivers"— Presentation transcript:

1 Introduction to Linux Device Drivers
Class 4: Input Device Drivers with Linux Kernel Aug 7, 2014 Khem Raj

2 Introduction Driver Collection Supporting input devices Keyboards Mice
Touchscreens Wheels

3 Introduction Standardize handling of similar devices
E.g. mice can be USB, bluetooth, PS/2 Standard event system to interact with userspace applications Input core extract common bits e.g. serio Name one advantage of kernel’s input subsystem ?

4 Input Subsystem Input device driver Input event driver
Talks to the device Input event driver Talks to Applications

5 Input Subsystem XWin Qt GUI apps Input Devices /dev/input/*
Userspace Kernel Space h/w space XWin Qt GUI apps Input Devices /dev/input/* Input Core subsystem Input Device Drivers Input Event Handers Serio USB HID HIDP PS/2 Keyboard USB Mice Bluetooth Mice

6 Input Events Understood by different Graphical systems e.g. X11, QT etc. H/W Independent abstraction Evdev Generic Input Event Driver

7 Input Event Handlers /** * struct input_value - input value representation type of value (EV_KEY, EV_ABS, etc) the value code the value */ struct input_value { __u16 type; __u16 code; __s32 value; }; What is a Input Event Driver ?

8 Input Device Drivers Serio Used to access keyboard controllers
PS/2 mouse and keyboards, trakcpoints Serial port controllers Touch pads Using serio via callback serio_register_driver() sends cmds to controllers To Add new driver Define open, close, start, stop, etc. Use serio_register_port ()

9 Application/emulates mouse moves
Example Console/gpm server Application/emulates mouse moves /dev/input/event Dispatch coordinates through sysfs (/sys/device/..) evdev Virtual Mouse Driver Input core

10 Application Opens a sysfs node Generate random relative coordinates
open("/sys/devices/platform/vms/coordinates", O_RDWR) Generate random relative coordinates Write it down to device file descriptor Close the file descriptor

11 Mouse Driver Defines a struct input_dev – Input device
Defines platform_device – Device struct Initialization Register a platform device and allocate struct input_dev platform_device_register_simple and input_allocate_device Create a sysfs node to read simulated coordinates sysfs_create_group(..) Define what data it will generate ( coordinates ) Use set_bit () to set members in input_dev struct e.g. evbit set_bit(REL_X, …) set_bit(REL_Y, …) Register with the input subsystem input_register_device () Write Function Gets the buffer with coordinates Use input_report_rel () to generate events ( REL_X, REL_Y) input_sync () denotes completions of events

12 Mouse Driver Attach to sysfs write function
DEVICE_ATTR(<devicename>, 0644, NULL, <driver write function>); Define attribute group and descriptor Exit/Cleanup Unregister from input subsystem input_unregister_device () Clean sysfs node sysfs_remove_group () Unregister Driver platform_device_unregister () How does device driver write function gets registered with sysfs ?

13 Input Subsystem Creates evdev structure from events
Send it on /dev/input/eventX gpm receives event in input_event format gpm -m /dev/input/eventX -t evdev

14 Evdev Interface This driver uses generic evdev interface
Some devices define own Event drivers They populate input_handler struct Register input_register_handler(&mousedev_handler); Which structure is initialized to define event driver ?

15 Output Events Keyboard/mice LEDs and Sound beeps
Set by evbits and callback function See drivers/input/misc/pcspkr.c Callback - static int pcspkr_event () static int __devinit pcspkr_probe () Declared evbits pcspkr_dev->evbit[0] = BIT(EV_SND); pcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); /* The Callback routine */ pcspkr_dev->event = pcspkr_event;

16 Debugging Input Drivers
Use evbug module Dumps type, code and value (input_event struct) Output looks like /* Touchpad Movement */ evbug.c Event. Dev: isa0060/serio1/input0: Type: 3, Code: 28, Value: 0 How do you debug input drivers ?

17 Source Event handlers Device drivers reside close to subsystem code
drivers/input directory But keyboard driver is in drivers/char Device drivers reside close to subsystem code net/bluetooth Documentation/input describes some of input interfaces Most of interfaces in include/linux/input.h

18 Thanks Q & A


Download ppt "Introduction to Linux Device Drivers"

Similar presentations


Ads by Google