Dmitry Torokhov | b08c118 | 2017-04-06 18:08:42 -0700 | [diff] [blame] | 1 | =============================== |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 2 | Creating an input device driver |
| 3 | =============================== |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 5 | The simplest example |
| 6 | ~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
| 8 | Here comes a very simple example of an input device driver. The device has |
| 9 | just one button and the button is accessible at i/o port BUTTON_PORT. When |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 10 | pressed or released a BUTTON_IRQ happens. The driver could look like:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 12 | #include <linux/input.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 16 | #include <asm/irq.h> |
| 17 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 19 | static struct input_dev *button_dev; |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 20 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 21 | static irqreturn_t button_interrupt(int irq, void *dummy) |
| 22 | { |
| 23 | input_report_key(button_dev, BTN_0, inb(BUTTON_PORT) & 1); |
| 24 | input_sync(button_dev); |
| 25 | return IRQ_HANDLED; |
| 26 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 28 | static int __init button_init(void) |
| 29 | { |
| 30 | int error; |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 32 | if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) { |
| 33 | printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq); |
| 34 | return -EBUSY; |
| 35 | } |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 36 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 37 | button_dev = input_allocate_device(); |
| 38 | if (!button_dev) { |
| 39 | printk(KERN_ERR "button.c: Not enough memory\n"); |
| 40 | error = -ENOMEM; |
| 41 | goto err_free_irq; |
| 42 | } |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 43 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 44 | button_dev->evbit[0] = BIT_MASK(EV_KEY); |
| 45 | button_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0); |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 46 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 47 | error = input_register_device(button_dev); |
| 48 | if (error) { |
| 49 | printk(KERN_ERR "button.c: Failed to register device\n"); |
| 50 | goto err_free_dev; |
| 51 | } |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 52 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 53 | return 0; |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 54 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 55 | err_free_dev: |
| 56 | input_free_device(button_dev); |
| 57 | err_free_irq: |
| 58 | free_irq(BUTTON_IRQ, button_interrupt); |
| 59 | return error; |
| 60 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 62 | static void __exit button_exit(void) |
| 63 | { |
| 64 | input_unregister_device(button_dev); |
| 65 | free_irq(BUTTON_IRQ, button_interrupt); |
| 66 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 68 | module_init(button_init); |
| 69 | module_exit(button_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 71 | What the example does |
| 72 | ~~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | First it has to include the <linux/input.h> file, which interfaces to the |
| 75 | input subsystem. This provides all the definitions needed. |
| 76 | |
| 77 | In the _init function, which is called either upon module load or when |
| 78 | booting the kernel, it grabs the required resources (it should also check |
| 79 | for the presence of the device). |
| 80 | |
Matt LaPlante | 01dd2fb | 2007-10-20 01:34:40 +0200 | [diff] [blame] | 81 | Then it allocates a new input device structure with input_allocate_device() |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 82 | and sets up input bitfields. This way the device driver tells the other |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | parts of the input systems what it is - what events can be generated or |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 84 | accepted by this input device. Our example device can only generate EV_KEY |
| 85 | type events, and from those only BTN_0 event code. Thus we only set these |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 86 | two bits. We could have used:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | set_bit(EV_KEY, button_dev.evbit); |
| 89 | set_bit(BTN_0, button_dev.keybit); |
| 90 | |
| 91 | as well, but with more than single bits the first approach tends to be |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 92 | shorter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 94 | Then the example driver registers the input device structure by calling:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | input_register_device(&button_dev); |
| 97 | |
| 98 | This adds the button_dev structure to linked lists of the input driver and |
| 99 | calls device handler modules _connect functions to tell them a new input |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 100 | device has appeared. input_register_device() may sleep and therefore must |
| 101 | not be called from an interrupt or with a spinlock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 103 | While in use, the only used function of the driver is:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | button_interrupt() |
| 106 | |
| 107 | which upon every interrupt from the button checks its state and reports it |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 108 | via the:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | input_report_key() |
| 111 | |
| 112 | call to the input system. There is no need to check whether the interrupt |
| 113 | routine isn't reporting two same value events (press, press for example) to |
| 114 | the input system, because the input_report_* functions check that |
| 115 | themselves. |
| 116 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 117 | Then there is the:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | input_sync() |
| 120 | |
| 121 | call to tell those who receive the events that we've sent a complete report. |
| 122 | This doesn't seem important in the one button case, but is quite important |
| 123 | for for example mouse movement, where you don't want the X and Y values |
| 124 | to be interpreted separately, because that'd result in a different movement. |
| 125 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 126 | dev->open() and dev->close() |
| 127 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | In case the driver has to repeatedly poll the device, because it doesn't |
| 130 | have an interrupt coming from it and the polling is too expensive to be done |
| 131 | all the time, or if the device uses a valuable resource (eg. interrupt), it |
| 132 | can use the open and close callback to know when it can stop polling or |
| 133 | release the interrupt and when it must resume polling or grab the interrupt |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 134 | again. To do that, we would add this to our example driver:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 136 | static int button_open(struct input_dev *dev) |
| 137 | { |
| 138 | if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) { |
| 139 | printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq); |
| 140 | return -EBUSY; |
| 141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 146 | static void button_close(struct input_dev *dev) |
| 147 | { |
| 148 | free_irq(IRQ_AMIGA_VERTB, button_interrupt); |
| 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 151 | static int __init button_init(void) |
| 152 | { |
| 153 | ... |
| 154 | button_dev->open = button_open; |
| 155 | button_dev->close = button_close; |
| 156 | ... |
| 157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 159 | Note that input core keeps track of number of users for the device and |
| 160 | makes sure that dev->open() is called only when the first user connects |
| 161 | to the device and that dev->close() is called when the very last user |
| 162 | disconnects. Calls to both callbacks are serialized. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | The open() callback should return a 0 in case of success or any nonzero value |
| 165 | in case of failure. The close() callback (which is void) must always succeed. |
| 166 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 167 | Basic event types |
| 168 | ~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | The most simple event type is EV_KEY, which is used for keys and buttons. |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 171 | It's reported to the input system via:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | input_report_key(struct input_dev *dev, int code, int value) |
| 174 | |
Martin Kepplinger | 28a5c96 | 2017-03-12 12:54:22 +0100 | [diff] [blame] | 175 | See uapi/linux/input-event-codes.h for the allowable values of code (from 0 to |
| 176 | KEY_MAX). Value is interpreted as a truth value, ie any nonzero value means key |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | pressed, zero value means key released. The input code generates events only |
| 178 | in case the value is different from before. |
| 179 | |
| 180 | In addition to EV_KEY, there are two more basic event types: EV_REL and |
| 181 | EV_ABS. They are used for relative and absolute values supplied by the |
| 182 | device. A relative value may be for example a mouse movement in the X axis. |
| 183 | The mouse reports it as a relative difference from the last position, |
| 184 | because it doesn't have any absolute coordinate system to work in. Absolute |
| 185 | events are namely for joysticks and digitizers - devices that do work in an |
| 186 | absolute coordinate systems. |
| 187 | |
| 188 | Having the device report EV_REL buttons is as simple as with EV_KEY, simply |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 189 | set the corresponding bits and call the:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | input_report_rel(struct input_dev *dev, int code, int value) |
| 192 | |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 193 | function. Events are generated only for nonzero value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | However EV_ABS requires a little special care. Before calling |
| 196 | input_register_device, you have to fill additional fields in the input_dev |
| 197 | struct for each absolute axis your device has. If our button device had also |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 198 | the ABS_X axis:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | button_dev.absmin[ABS_X] = 0; |
| 201 | button_dev.absmax[ABS_X] = 255; |
| 202 | button_dev.absfuzz[ABS_X] = 4; |
| 203 | button_dev.absflat[ABS_X] = 8; |
| 204 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 205 | Or, you can just say:: |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 206 | |
| 207 | input_set_abs_params(button_dev, ABS_X, 0, 255, 4, 8); |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | This setting would be appropriate for a joystick X axis, with the minimum of |
| 210 | 0, maximum of 255 (which the joystick *must* be able to reach, no problem if |
| 211 | it sometimes reports more, but it must be able to always reach the min and |
| 212 | max values), with noise in the data up to +- 4, and with a center flat |
| 213 | position of size 8. |
| 214 | |
| 215 | If you don't need absfuzz and absflat, you can set them to zero, which mean |
| 216 | that the thing is precise and always returns to exactly the center position |
| 217 | (if it has any). |
| 218 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 219 | BITS_TO_LONGS(), BIT_WORD(), BIT_MASK() |
| 220 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 222 | These three macros from bitops.h help some bitfield computations:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 224 | BITS_TO_LONGS(x) - returns the length of a bitfield array in longs for |
| 225 | x bits |
| 226 | BIT_WORD(x) - returns the index in the array in longs for bit x |
| 227 | BIT_MASK(x) - returns the index in a long for bit x |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 229 | The id* and name fields |
| 230 | ~~~~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | The dev->name should be set before registering the input device by the input |
| 233 | device driver. It's a string like 'Generic button device' containing a |
| 234 | user friendly name of the device. |
| 235 | |
| 236 | The id* fields contain the bus ID (PCI, USB, ...), vendor ID and device ID |
| 237 | of the device. The bus IDs are defined in input.h. The vendor and device ids |
| 238 | are defined in pci_ids.h, usb_ids.h and similar include files. These fields |
| 239 | should be set by the input device driver before registering it. |
| 240 | |
| 241 | The idtype field can be used for specific information for the input device |
| 242 | driver. |
| 243 | |
| 244 | The id and name fields can be passed to userland via the evdev interface. |
| 245 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 246 | The keycode, keycodemax, keycodesize fields |
| 247 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 249 | These three fields should be used by input devices that have dense keymaps. |
| 250 | The keycode is an array used to map from scancodes to input system keycodes. |
| 251 | The keycode max should contain the size of the array and keycodesize the |
| 252 | size of each entry in it (in bytes). |
| 253 | |
| 254 | Userspace can query and alter current scancode to keycode mappings using |
| 255 | EVIOCGKEYCODE and EVIOCSKEYCODE ioctls on corresponding evdev interface. |
| 256 | When a device has all 3 aforementioned fields filled in, the driver may |
| 257 | rely on kernel's default implementation of setting and querying keycode |
| 258 | mappings. |
| 259 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 260 | dev->getkeycode() and dev->setkeycode() |
| 261 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 262 | |
Dmitry Torokhov | 85796e7 | 2007-04-29 23:42:08 -0400 | [diff] [blame] | 263 | getkeycode() and setkeycode() callbacks allow drivers to override default |
| 264 | keycode/keycodesize/keycodemax mapping mechanism provided by input core |
| 265 | and implement sparse keycode maps. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 267 | Key autorepeat |
| 268 | ~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | ... is simple. It is handled by the input.c module. Hardware autorepeat is |
| 271 | not used, because it's not present in many devices and even where it is |
| 272 | present, it is broken sometimes (at keyboards: Toshiba notebooks). To enable |
| 273 | autorepeat for your device, just set EV_REP in dev->evbit. All will be |
| 274 | handled by the input system. |
| 275 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 276 | Other event types, handling output events |
| 277 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | The other event types up to now are: |
| 280 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 281 | - EV_LED - used for the keyboard LEDs. |
| 282 | - EV_SND - used for keyboard beeps. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | They are very similar to for example key events, but they go in the other |
| 285 | direction - from the system to the input device driver. If your input device |
| 286 | driver can handle these events, it has to set the respective bits in evbit, |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 287 | *and* also the callback routine:: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 289 | button_dev->event = button_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Mauro Carvalho Chehab | 1c4ada6 | 2017-04-04 17:44:04 -0700 | [diff] [blame] | 291 | int button_event(struct input_dev *dev, unsigned int type, |
| 292 | unsigned int code, int value) |
| 293 | { |
| 294 | if (type == EV_SND && code == SND_BELL) { |
| 295 | outb(value, BUTTON_BELL); |
| 296 | return 0; |
| 297 | } |
| 298 | return -1; |
| 299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | This callback routine can be called from an interrupt or a BH (although that |
| 302 | isn't a rule), and thus must not sleep, and must not take too long to finish. |