€•”žŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ+/translations/zh_CN/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/zh_TW/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/it_IT/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/ja_JP/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/ko_KR/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/pt_BR/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/sp_SP/input/input-programming”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒCreating an input device driver”h]”hŒCreating an input device driver”…””}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒE/var/lib/git/docbuild/linux/Documentation/input/input-programming.rst”h´Kubh¶)”}”(hhh]”(h»)”}”(hŒThe simplest example”h]”hŒThe simplest example”…””}”(hhÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhhËh²hh³hÊh´KubhŒ paragraph”“”)”}”(hŒÜHere comes a very simple example of an input device driver. The device has just one button and the button is accessible at i/o port BUTTON_PORT. When pressed or released a BUTTON_IRQ happens. The driver could look like::”h]”hŒÛHere comes a very simple example of an input device driver. The device has just one button and the button is accessible at i/o port BUTTON_PORT. When pressed or released a BUTTON_IRQ happens. The driver could look like:”…””}”(hhÞh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KhhËh²hubhŒ literal_block”“”)”}”(hXÀ#include #include #include #include #include static struct input_dev *button_dev; static irqreturn_t button_interrupt(int irq, void *dummy) { input_report_key(button_dev, BTN_0, inb(BUTTON_PORT) & 1); input_sync(button_dev); return IRQ_HANDLED; } static int __init button_init(void) { int error; if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) { printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq); return -EBUSY; } button_dev = input_allocate_device(); if (!button_dev) { printk(KERN_ERR "button.c: Not enough memory\n"); error = -ENOMEM; goto err_free_irq; } button_dev->evbit[0] = BIT_MASK(EV_KEY); button_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0); error = input_register_device(button_dev); if (error) { printk(KERN_ERR "button.c: Failed to register device\n"); goto err_free_dev; } return 0; err_free_dev: input_free_device(button_dev); err_free_irq: free_irq(BUTTON_IRQ, button_interrupt); return error; } static void __exit button_exit(void) { input_unregister_device(button_dev); free_irq(BUTTON_IRQ, button_interrupt); } module_init(button_init); module_exit(button_exit);”h]”hXÀ#include #include #include #include #include static struct input_dev *button_dev; static irqreturn_t button_interrupt(int irq, void *dummy) { input_report_key(button_dev, BTN_0, inb(BUTTON_PORT) & 1); input_sync(button_dev); return IRQ_HANDLED; } static int __init button_init(void) { int error; if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) { printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq); return -EBUSY; } button_dev = input_allocate_device(); if (!button_dev) { printk(KERN_ERR "button.c: Not enough memory\n"); error = -ENOMEM; goto err_free_irq; } button_dev->evbit[0] = BIT_MASK(EV_KEY); button_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0); error = input_register_device(button_dev); if (error) { printk(KERN_ERR "button.c: Failed to register device\n"); goto err_free_dev; } return 0; err_free_dev: input_free_device(button_dev); err_free_irq: free_irq(BUTTON_IRQ, button_interrupt); return error; } static void __exit button_exit(void) { input_unregister_device(button_dev); free_irq(BUTTON_IRQ, button_interrupt); } module_init(button_init); module_exit(button_exit);”…””}”hhîsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hìh³hÊh´K hhËh²hubeh}”(h]”Œthe-simplest-example”ah ]”h"]”Œthe simplest example”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒWhat the example does”h]”hŒWhat the example does”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´KHubhÝ)”}”(hŒ„First it has to include the file, which interfaces to the input subsystem. This provides all the definitions needed.”h]”hŒ„First it has to include the file, which interfaces to the input subsystem. This provides all the definitions needed.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KJhjh²hubhÝ)”}”(hŒ±In the _init function, which is called either upon module load or when booting the kernel, it grabs the required resources (it should also check for the presence of the device).”h]”hŒ±In the _init function, which is called either upon module load or when booting the kernel, it grabs the required resources (it should also check for the presence of the device).”…””}”(hj%h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KMhjh²hubhÝ)”}”(hXThen it allocates a new input device structure with input_allocate_device() and sets up input bitfields. This way the device driver tells the other parts of the input systems what it is - what events can be generated or accepted by this input device. Our example device can only generate EV_KEY type events, and from those only BTN_0 event code. Thus we only set these two bits. We could have used::”h]”hXŽThen it allocates a new input device structure with input_allocate_device() and sets up input bitfields. This way the device driver tells the other parts of the input systems what it is - what events can be generated or accepted by this input device. Our example device can only generate EV_KEY type events, and from those only BTN_0 event code. Thus we only set these two bits. We could have used:”…””}”(hj3h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KQhjh²hubhí)”}”(hŒGset_bit(EV_KEY, button_dev->evbit); set_bit(BTN_0, button_dev->keybit);”h]”hŒGset_bit(EV_KEY, button_dev->evbit); set_bit(BTN_0, button_dev->keybit);”…””}”hjAsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´KXhjh²hubhÝ)”}”(hŒOas well, but with more than single bits the first approach tends to be shorter.”h]”hŒOas well, but with more than single bits the first approach tends to be shorter.”…””}”(hjOh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K[hjh²hubhÝ)”}”(hŒIThen the example driver registers the input device structure by calling::”h]”hŒHThen the example driver registers the input device structure by calling:”…””}”(hj]h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K^hjh²hubhí)”}”(hŒ"input_register_device(button_dev);”h]”hŒ"input_register_device(button_dev);”…””}”hjksbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´K`hjh²hubhÝ)”}”(hXThis adds the button_dev structure to linked lists of the input driver and calls device handler modules _connect functions to tell them a new input device has appeared. input_register_device() may sleep and therefore must not be called from an interrupt or with a spinlock held.”h]”hXThis adds the button_dev structure to linked lists of the input driver and calls device handler modules _connect functions to tell them a new input device has appeared. input_register_device() may sleep and therefore must not be called from an interrupt or with a spinlock held.”…””}”(hjyh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kbhjh²hubhÝ)”}”(hŒ7While in use, the only used function of the driver is::”h]”hŒ6While in use, the only used function of the driver is:”…””}”(hj‡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kghjh²hubhí)”}”(hŒbutton_interrupt()”h]”hŒbutton_interrupt()”…””}”hj•sbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Kihjh²hubhÝ)”}”(hŒTwhich upon every interrupt from the button checks its state and reports it via the::”h]”hŒSwhich upon every interrupt from the button checks its state and reports it via the:”…””}”(hj£h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kkhjh²hubhí)”}”(hŒinput_report_key()”h]”hŒinput_report_key()”…””}”hj±sbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Knhjh²hubhÝ)”}”(hŒãcall to the input system. There is no need to check whether the interrupt routine isn't reporting two same value events (press, press for example) to the input system, because the input_report_* functions check that themselves.”h]”hŒåcall to the input system. There is no need to check whether the interrupt routine isn’t reporting two same value events (press, press for example) to the input system, because the input_report_* functions check that themselves.”…””}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kphjh²hubhÝ)”}”(hŒThen there is the::”h]”hŒThen there is the:”…””}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kuhjh²hubhí)”}”(hŒ input_sync()”h]”hŒ input_sync()”…””}”hjÛsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Kwhjh²hubhÝ)”}”(hX,call to tell those who receive the events that we've sent a complete report. This doesn't seem important in the one button case, but is quite important for example for mouse movement, where you don't want the X and Y values to be interpreted separately, because that'd result in a different movement.”h]”hX4call to tell those who receive the events that we’ve sent a complete report. This doesn’t seem important in the one button case, but is quite important for example for mouse movement, where you don’t want the X and Y values to be interpreted separately, because that’d result in a different movement.”…””}”(hjéh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Kyhjh²hubeh}”(h]”Œwhat-the-example-does”ah ]”h"]”Œwhat the example does”ah$]”h&]”uh1hµhh·h²hh³hÊh´KHubh¶)”}”(hhh]”(h»)”}”(hŒdev->open() and dev->close()”h]”hŒdev->open() and dev->close()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÿh²hh³hÊh´KubhÝ)”}”(hX³In case the driver has to repeatedly poll the device, because it doesn't have an interrupt coming from it and the polling is too expensive to be done all the time, or if the device uses a valuable resource (e.g. interrupt), it can use the open and close callback to know when it can stop polling or release the interrupt and when it must resume polling or grab the interrupt again. To do that, we would add this to our example driver::”h]”hX´In case the driver has to repeatedly poll the device, because it doesn’t have an interrupt coming from it and the polling is too expensive to be done all the time, or if the device uses a valuable resource (e.g. interrupt), it can use the open and close callback to know when it can stop polling or release the interrupt and when it must resume polling or grab the interrupt again. To do that, we would add this to our example driver:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Khjÿh²hubhí)”}”(hXstatic int button_open(struct input_dev *dev) { if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) { printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq); return -EBUSY; } return 0; } static void button_close(struct input_dev *dev) { free_irq(IRQ_AMIGA_VERTB, button_interrupt); } static int __init button_init(void) { ... button_dev->open = button_open; button_dev->close = button_close; ... }”h]”hXstatic int button_open(struct input_dev *dev) { if (request_irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL)) { printk(KERN_ERR "button.c: Can't allocate irq %d\n", button_irq); return -EBUSY; } return 0; } static void button_close(struct input_dev *dev) { free_irq(IRQ_AMIGA_VERTB, button_interrupt); } static int __init button_init(void) { ... button_dev->open = button_open; button_dev->close = button_close; ... }”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Kˆhjÿh²hubhÝ)”}”(hX Note that input core keeps track of number of users for the device and makes sure that dev->open() is called only when the first user connects to the device and that dev->close() is called when the very last user disconnects. Calls to both callbacks are serialized.”h]”hX Note that input core keeps track of number of users for the device and makes sure that dev->open() is called only when the first user connects to the device and that dev->close() is called when the very last user disconnects. Calls to both callbacks are serialized.”…””}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KŸhjÿh²hubhÝ)”}”(hŒœThe open() callback should return a 0 in case of success or any non-zero value in case of failure. The close() callback (which is void) must always succeed.”h]”hŒœThe open() callback should return a 0 in case of success or any non-zero value in case of failure. The close() callback (which is void) must always succeed.”…””}”(hj:h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K¤hjÿh²hubeh}”(h]”Œdev-open-and-dev-close”ah ]”h"]”Œdev->open() and dev->close()”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒInhibiting input devices”h]”hŒInhibiting input devices”…””}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjPh²hh³hÊh´K¨ubhÝ)”}”(hŒîInhibiting a device means ignoring input events from it. As such it is about maintaining relationships with input handlers - either already existing relationships, or relationships to be established while the device is in inhibited state.”h]”hŒîInhibiting a device means ignoring input events from it. As such it is about maintaining relationships with input handlers - either already existing relationships, or relationships to be established while the device is in inhibited state.”…””}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KªhjPh²hubhÝ)”}”(hŒGIf a device is inhibited, no input handler will receive events from it.”h]”hŒGIf a device is inhibited, no input handler will receive events from it.”…””}”(hjoh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K¯hjPh²hubhÝ)”}”(hX[The fact that nobody wants events from the device is exploited further, by calling device's close() (if there are users) and open() (if there are users) on inhibit and uninhibit operations, respectively. Indeed, the meaning of close() is to stop providing events to the input core and that of open() is to start providing events to the input core.”h]”hX]The fact that nobody wants events from the device is exploited further, by calling device’s close() (if there are users) and open() (if there are users) on inhibit and uninhibit operations, respectively. Indeed, the meaning of close() is to stop providing events to the input core and that of open() is to start providing events to the input core.”…””}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K±hjPh²hubhÝ)”}”(hŒïCalling the device's close() method on inhibit (if there are users) allows the driver to save power. Either by directly powering down the device or by releasing the runtime-PM reference it got in open() when the driver is using runtime-PM.”h]”hŒñCalling the device’s close() method on inhibit (if there are users) allows the driver to save power. Either by directly powering down the device or by releasing the runtime-PM reference it got in open() when the driver is using runtime-PM.”…””}”(hj‹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K·hjPh²hubhÝ)”}”(hŒÍInhibiting and uninhibiting are orthogonal to opening and closing the device by input handlers. Userspace might want to inhibit a device in anticipation before any handler is positively matched against it.”h]”hŒÍInhibiting and uninhibiting are orthogonal to opening and closing the device by input handlers. Userspace might want to inhibit a device in anticipation before any handler is positively matched against it.”…””}”(hj™h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´K¼hjPh²hubhÝ)”}”(hX-Inhibiting and uninhibiting are orthogonal to device's being a wakeup source, too. Being a wakeup source plays a role when the system is sleeping, not when the system is operating. How drivers should program their interaction between inhibiting, sleeping and being a wakeup source is driver-specific.”h]”hX/Inhibiting and uninhibiting are orthogonal to device’s being a wakeup source, too. Being a wakeup source plays a role when the system is sleeping, not when the system is operating. How drivers should program their interaction between inhibiting, sleeping and being a wakeup source is driver-specific.”…””}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÀhjPh²hubhÝ)”}”(hX‹Taking the analogy with the network devices - bringing a network interface down doesn't mean that it should be impossible be wake the system up on LAN through this interface. So, there may be input drivers which should be considered wakeup sources even when inhibited. Actually, in many I2C input devices their interrupt is declared a wakeup interrupt and its handling happens in driver's core, which is not aware of input-specific inhibit (nor should it be). Composite devices containing several interfaces can be inhibited on a per-interface basis and e.g. inhibiting one interface shouldn't affect the device's capability of being a wakeup source.”h]”hX“Taking the analogy with the network devices - bringing a network interface down doesn’t mean that it should be impossible be wake the system up on LAN through this interface. So, there may be input drivers which should be considered wakeup sources even when inhibited. Actually, in many I2C input devices their interrupt is declared a wakeup interrupt and its handling happens in driver’s core, which is not aware of input-specific inhibit (nor should it be). Composite devices containing several interfaces can be inhibited on a per-interface basis and e.g. inhibiting one interface shouldn’t affect the device’s capability of being a wakeup source.”…””}”(hjµh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÅhjPh²hubhÝ)”}”(hXdIf a device is to be considered a wakeup source while inhibited, special care must be taken when programming its suspend(), as it might need to call device's open(). Depending on what close() means for the device in question, not opening() it before going to sleep might make it impossible to provide any wakeup events. The device is going to sleep anyway.”h]”hXfIf a device is to be considered a wakeup source while inhibited, special care must be taken when programming its suspend(), as it might need to call device’s open(). Depending on what close() means for the device in question, not opening() it before going to sleep might make it impossible to provide any wakeup events. The device is going to sleep anyway.”…””}”(hjÃh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÏhjPh²hubeh}”(h]”Œinhibiting-input-devices”ah ]”h"]”Œinhibiting input devices”ah$]”h&]”uh1hµhh·h²hh³hÊh´K¨ubh¶)”}”(hhh]”(h»)”}”(hŒBasic event types”h]”hŒBasic event types”…””}”(hjÜh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÙh²hh³hÊh´KÖubhÝ)”}”(hŒqThe most simple event type is EV_KEY, which is used for keys and buttons. It's reported to the input system via::”h]”hŒrThe most simple event type is EV_KEY, which is used for keys and buttons. It’s reported to the input system via:”…””}”(hjêh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KØhjÙh²hubhí)”}”(hŒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KïhjÙh²hubhÝ)”}”(hŒæHowever EV_ABS requires a little special care. Before calling input_register_device, you have to fill additional fields in the input_dev struct for each absolute axis your device has. If our button device had also the ABS_X axis::”h]”hŒåHowever EV_ABS requires a little special care. Before calling input_register_device, you have to fill additional fields in the input_dev struct for each absolute axis your device has. If our button device had also the ABS_X axis:”…””}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KñhjÙh²hubhí)”}”(hŒ{button_dev.absmin[ABS_X] = 0; button_dev.absmax[ABS_X] = 255; button_dev.absfuzz[ABS_X] = 4; button_dev.absflat[ABS_X] = 8;”h]”hŒ{button_dev.absmin[ABS_X] = 0; button_dev.absmax[ABS_X] = 255; button_dev.absfuzz[ABS_X] = 4; button_dev.absflat[ABS_X] = 8;”…””}”hjZsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´KöhjÙh²hubhÝ)”}”(hŒOr, you can just say::”h]”hŒOr, you can just say:”…””}”(hjhh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KûhjÙh²hubhí)”}”(hŒ6input_set_abs_params(button_dev, ABS_X, 0, 255, 4, 8);”h]”hŒ6input_set_abs_params(button_dev, ABS_X, 0, 255, 4, 8);”…””}”hjvsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´KýhjÙh²hubhÝ)”}”(hX?This setting would be appropriate for a joystick X axis, with the minimum of 0, maximum of 255 (which the joystick *must* be able to reach, no problem if it sometimes reports more, but it must be able to always reach the min and max values), with noise in the data up to +- 4, and with a center flat position of size 8.”h]”(hŒsThis setting would be appropriate for a joystick X axis, with the minimum of 0, maximum of 255 (which the joystick ”…””}”(hj„h²hh³Nh´NubhŒemphasis”“”)”}”(hŒ*must*”h]”hŒmust”…””}”(hjŽh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jŒhj„ubhŒÆ be able to reach, no problem if it sometimes reports more, but it must be able to always reach the min and max values), with noise in the data up to +- 4, and with a center flat position of size 8.”…””}”(hj„h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´KÿhjÙh²hubhÝ)”}”(hŒ¨If you don't need absfuzz and absflat, you can set them to zero, which mean that the thing is precise and always returns to exactly the center position (if it has any).”h]”hŒªIf you don’t need absfuzz and absflat, you can set them to zero, which mean that the thing is precise and always returns to exactly the center position (if it has any).”…””}”(hj¦h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MhjÙh²hubeh}”(h]”Œbasic-event-types”ah ]”h"]”Œbasic event types”ah$]”h&]”uh1hµhh·h²hh³hÊh´KÖubh¶)”}”(hhh]”(h»)”}”(hŒ'BITS_TO_LONGS(), BIT_WORD(), BIT_MASK()”h]”hŒ'BITS_TO_LONGS(), BIT_WORD(), BIT_MASK()”…””}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¼h²hh³hÊh´M ubhÝ)”}”(hŒBThese three macros from bitops.h help some bitfield computations::”h]”hŒAThese three macros from bitops.h help some bitfield computations:”…””}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M hj¼h²hubhí)”}”(hŒÞBITS_TO_LONGS(x) - returns the length of a bitfield array in longs for x bits BIT_WORD(x) - returns the index in the array in longs for bit x BIT_MASK(x) - returns the index in a long for bit x”h]”hŒÞBITS_TO_LONGS(x) - returns the length of a bitfield array in longs for x bits BIT_WORD(x) - returns the index in the array in longs for bit x BIT_MASK(x) - returns the index in a long for bit x”…””}”hjÛsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Mhj¼h²hubeh}”(h]”Œbits-to-longs-bit-word-bit-mask”ah ]”h"]”Œ'bits_to_longs(), bit_word(), bit_mask()”ah$]”h&]”uh1hµhh·h²hh³hÊh´M ubh¶)”}”(hhh]”(h»)”}”(hŒThe id* and name fields”h]”hŒThe id* and name fields”…””}”(hjôh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjñh²hh³hÊh´MubhÝ)”}”(hŒµThe dev->name should be set before registering the input device by the input device driver. It's a string like 'Generic button device' containing a user friendly name of the device.”h]”hŒ»The dev->name should be set before registering the input device by the input device driver. It’s a string like ‘Generic button device’ containing a user friendly name of the device.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mhjñh²hubhÝ)”}”(hX#The id* fields contain the bus ID (PCI, USB, ...), vendor ID and device ID of the device. The bus IDs are defined in input.h. The vendor and device IDs are defined in pci_ids.h, usb_ids.h and similar include files. These fields should be set by the input device driver before registering it.”h]”hX#The id* fields contain the bus ID (PCI, USB, ...), vendor ID and device ID of the device. The bus IDs are defined in input.h. The vendor and device IDs are defined in pci_ids.h, usb_ids.h and similar include files. These fields should be set by the input device driver before registering it.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mhjñh²hubhÝ)”}”(hŒRThe idtype field can be used for specific information for the input device driver.”h]”hŒRThe idtype field can be used for specific information for the input device driver.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mhjñh²hubhÝ)”}”(hŒIThe id and name fields can be passed to userland via the evdev interface.”h]”hŒIThe id and name fields can be passed to userland via the evdev interface.”…””}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M"hjñh²hubeh}”(h]”Œthe-id-and-name-fields”ah ]”h"]”Œthe id* and name fields”ah$]”h&]”uh1hµhh·h²hh³hÊh´Mubh¶)”}”(hhh]”(h»)”}”(hŒ+The keycode, keycodemax, keycodesize fields”h]”hŒ+The keycode, keycodemax, keycodesize fields”…””}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjBh²hh³hÊh´M%ubhÝ)”}”(hXThese three fields should be used by input devices that have dense keymaps. The keycode is an array used to map from scancodes to input system keycodes. The keycode max should contain the size of the array and keycodesize the size of each entry in it (in bytes).”h]”hXThese three fields should be used by input devices that have dense keymaps. The keycode is an array used to map from scancodes to input system keycodes. The keycode max should contain the size of the array and keycodesize the size of each entry in it (in bytes).”…””}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M'hjBh²hubhÝ)”}”(hX+Userspace can query and alter current scancode to keycode mappings using EVIOCGKEYCODE and EVIOCSKEYCODE ioctls on corresponding evdev interface. When a device has all 3 aforementioned fields filled in, the driver may rely on kernel's default implementation of setting and querying keycode mappings.”h]”hX-Userspace can query and alter current scancode to keycode mappings using EVIOCGKEYCODE and EVIOCSKEYCODE ioctls on corresponding evdev interface. When a device has all 3 aforementioned fields filled in, the driver may rely on kernel’s default implementation of setting and querying keycode mappings.”…””}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M,hjBh²hubeh}”(h]”Œ)the-keycode-keycodemax-keycodesize-fields”ah ]”h"]”Œ+the keycode, keycodemax, keycodesize fields”ah$]”h&]”uh1hµhh·h²hh³hÊh´M%ubh¶)”}”(hhh]”(h»)”}”(hŒ'dev->getkeycode() and dev->setkeycode()”h]”hŒ'dev->getkeycode() and dev->setkeycode()”…””}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjwh²hh³hÊh´M3ubhÝ)”}”(hŒ´getkeycode() and setkeycode() callbacks allow drivers to override default keycode/keycodesize/keycodemax mapping mechanism provided by input core and implement sparse keycode maps.”h]”hŒ´getkeycode() and setkeycode() callbacks allow drivers to override default keycode/keycodesize/keycodemax mapping mechanism provided by input core and implement sparse keycode maps.”…””}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M5hjwh²hubeh}”(h]”Œ!dev-getkeycode-and-dev-setkeycode”ah ]”h"]”Œ'dev->getkeycode() and dev->setkeycode()”ah$]”h&]”uh1hµhh·h²hh³hÊh´M3ubh¶)”}”(hhh]”(h»)”}”(hŒKey autorepeat”h]”hŒKey autorepeat”…””}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjžh²hh³hÊh´M:ubhÝ)”}”(hXC... is simple. It is handled by the input.c module. Hardware autorepeat is not used, because it's not present in many devices and even where it is present, it is broken sometimes (at keyboards: Toshiba notebooks). To enable autorepeat for your device, just set EV_REP in dev->evbit. All will be handled by the input system.”h]”hXE... is simple. It is handled by the input.c module. Hardware autorepeat is not used, because it’s not present in many devices and even where it is present, it is broken sometimes (at keyboards: Toshiba notebooks). To enable autorepeat for your device, just set EV_REP in dev->evbit. All will be handled by the input system.”…””}”(hj¯h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M<hjžh²hubeh}”(h]”Œkey-autorepeat”ah ]”h"]”Œkey autorepeat”ah$]”h&]”uh1hµhh·h²hh³hÊh´M:ubh¶)”}”(hhh]”(h»)”}”(hŒ)Other event types, handling output events”h]”hŒ)Other event types, handling output events”…””}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÅh²hh³hÊh´MCubhÝ)”}”(hŒ$The other event types up to now are:”h]”hŒ$The other event types up to now are:”…””}”(hjÖh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MEhjÅh²hubhŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒ$EV_LED - used for the keyboard LEDs.”h]”hÝ)”}”(hjíh]”hŒ$EV_LED - used for the keyboard LEDs.”…””}”(hjïh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MGhjëubah}”(h]”h ]”h"]”h$]”h&]”uh1jéhjæh²hh³hÊh´Nubjê)”}”(hŒ"EV_SND - used for keyboard beeps. ”h]”hÝ)”}”(hŒ!EV_SND - used for keyboard beeps.”h]”hŒ!EV_SND - used for keyboard beeps.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MHhjubah}”(h]”h ]”h"]”h$]”h&]”uh1jéhjæh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jäh³hÊh´MGhjÅh²hubhÝ)”}”(hXThey are very similar to for example key events, but they go in the other direction - from the system to the input device driver. If your input device driver can handle these events, it has to set the respective bits in evbit, *and* also the callback routine::”h]”(hŒãThey are very similar to for example key events, but they go in the other direction - from the system to the input device driver. If your input device driver can handle these events, it has to set the respective bits in evbit, ”…””}”(hj"h²hh³Nh´Nubj)”}”(hŒ*and*”h]”hŒand”…””}”(hj*h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jŒhj"ubhŒ also the callback routine:”…””}”(hj"h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´MJhjÅh²hubhí)”}”(hX#button_dev->event = button_event; int button_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { if (type == EV_SND && code == SND_BELL) { outb(value, BUTTON_BELL); return 0; } return -1; }”h]”hX#button_dev->event = button_event; int button_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { if (type == EV_SND && code == SND_BELL) { outb(value, BUTTON_BELL); return 0; } return -1; }”…””}”hjBsbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´MOhjÅh²hubhÝ)”}”(hŒšThis callback routine can be called from an interrupt or a BH (although that isn't a rule), and thus must not sleep, and must not take too long to finish.”h]”hŒœThis callback routine can be called from an interrupt or a BH (although that isn’t a rule), and thus must not sleep, and must not take too long to finish.”…””}”(hjPh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´M[hjÅh²hubeh}”(h]”Œ(other-event-types-handling-output-events”ah ]”h"]”Œ)other event types, handling output events”ah$]”h&]”uh1hµhh·h²hh³hÊh´MCubh¶)”}”(hhh]”(h»)”}”(hŒPolled input devices”h]”hŒPolled input devices”…””}”(hjih²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjfh²hh³hÊh´M_ubhÝ)”}”(hŒZInput polling is set up by passing an input device struct and a callback to the function::”h]”hŒYInput polling is set up by passing an input device struct and a callback to the function:”…””}”(hjwh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mahjfh²hubhí)”}”(hŒZint input_setup_polling(struct input_dev *dev, void (*poll_fn)(struct input_dev *dev))”h]”hŒZint input_setup_polling(struct input_dev *dev, void (*poll_fn)(struct input_dev *dev))”…””}”hj…sbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Mdhjfh²hubhÝ)”}”(hŒxWithin the callback, devices should use the regular input_report_* functions and input_sync as is used by other devices.”h]”hŒxWithin the callback, devices should use the regular input_report_* functions and input_sync as is used by other devices.”…””}”(hj“h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mghjfh²hubhÝ)”}”(hŒThere is also the function::”h]”hŒThere is also the function:”…””}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mjhjfh²hubhí)”}”(hŒJvoid input_set_poll_interval(struct input_dev *dev, unsigned int interval)”h]”hŒJvoid input_set_poll_interval(struct input_dev *dev, unsigned int interval)”…””}”hj¯sbah}”(h]”h ]”h"]”h$]”h&]”hühýuh1hìh³hÊh´Mlhjfh²hubhÝ)”}”(hŒ\which is used to configure the interval, in milliseconds, that the device will be polled at.”h]”hŒ\which is used to configure the interval, in milliseconds, that the device will be polled at.”…””}”(hj½h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÜh³hÊh´Mnhjfh²hubeh}”(h]”Œpolled-input-devices”ah ]”h"]”Œpolled input devices”ah$]”h&]”uh1hµhh·h²hh³hÊh´M_ubeh}”(h]”Œcreating-an-input-device-driver”ah ]”h"]”Œcreating an input device driver”ah$]”h&]”uh1hµhhh²hh³hÊh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÊuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hºNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jþŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÊŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jØjÕjjjüjùjMjJjÖjÓj¹j¶jîjëj?j<jtjqj›j˜jÂj¿jcj`jÐjÍuŒ nametypes”}”(j؉j‰jü‰jM‰jÖ‰j¹‰jî‰j?‰jt‰j›‰j‰jc‰jЉuh}”(jÕh·jhËjùjjJjÿjÓjPj¶jÙjëj¼j<jñjqjBj˜jwj¿jžj`jÅjÍjfuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.