€•xŒ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Œ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”…””}”(hhõhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hhòhž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 KJhhòhž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).”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h KMhhòhž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:”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h KQhhòhž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);”…””}”hj-sbah}”(h]”h ]”h"]”h$]”h&]”hèhéuh1hØhŸh¶h KXhhòhž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.”…””}”(hj;hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h K[hhòhž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:”…””}”(hjIhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h K^hhòhžhubhÙ)”}”(hŒ"input_register_device(button_dev);”h]”hŒ"input_register_device(button_dev);”…””}”hjWsbah}”(h]”h ]”h"]”h$]”h&]”hèhéuh1hØhŸh¶h K`hhòhž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.”…””}”(hjehžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Kbhhòhž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:”…””}”(hjshžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h KghhòhžhubhÙ)”}”(hŒbutton_interrupt()”h]”hŒbutton_interrupt()”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hèhéuh1hØhŸh¶h Kihhòhž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:”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h KkhhòhžhubhÙ)”}”(hŒinput_report_key()”h]”hŒinput_report_key()”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hèhéuh1hØhŸh¶h Knhhòhž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 Kphhòhž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 KuhhòhžhubhÙ)”}”(hŒ input_sync()”h]”hŒ input_sync()”…””}”hjÇsbah}”(h]”h ]”h"]”h$]”h&]”hèhéuh1hØhŸh¶h Kwhhòhž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 Kyhhòhž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()”…””}”(hjîhž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:”…””}”(hjühž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; ... }”…””}”hj sbah}”(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.”…””}”(hjhž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”…””}”(hj?hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj<hž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.”…””}”(hjMhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Kªhj<hž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.”…””}”(hj[hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h K¯hj<hž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.”…””}”(hjihžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h K±hj<hž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.”…””}”(hjwhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h K·hj<hž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¼hj<hž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Àhj<hž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Åhj<hž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Ïhj<hž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Œ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.”…””}”(hjîhž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.”…””}”(hjühž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.”…””}”(hj hž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.”…””}”(hjhž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”…””}”(hj1hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj.hž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).”…””}”(hj?hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h M'hj.hž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.”…””}”(hjMhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h M,hj.hž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()”…””}”(hjfhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjchž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.”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h M5hjchž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”…””}”(hjhž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.”…””}”(hjòhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h MHhjîubah}”(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, ”…””}”(hjhžhhŸNh Nubjy)”}”(hŒ*and*”h]”hŒand”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jxhjubhŒ also the callback routine:”…””}”(hjhž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; }”…””}”hj.sbah}”(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.”…””}”(hj<hž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”…””}”(hjUhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjRhž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:”…””}”(hjchžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h MahjRhž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))”…””}”hjqsbah}”(h]”h ]”h"]”h$]”h&]”hèhéuh1hØhŸh¶h MdhjRhž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.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h MghjRhžhubhÉ)”}”(hŒThere is also the function::”h]”hŒThere is also the function:”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h MjhjRhž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 MlhjRhž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 MnhjRhž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Áhïhìjèjåj9j6jÂj¿j¥j¢jÚj×j+j(j`j]j‡j„j®j«jOjLj¼j¹uŒ nametypes”}”(jĉhï‰jè‰j9‰j‰j¥‰jÚ‰j+‰j`‰j‡‰j®‰jO‰j¼‰uh}”(jÁh£hìh·jåhòj6jëj¿j<j¢jÅj×j¨j(jÝj]j.j„jcj«jŠjLj±j¹jRuŒ 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.