Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: improve autorepeat initialization

Add new function input_enable_softrepeat() that allows drivers to
initialize their own values for input_dev->rep[REP_DELAY] and
input_dev->rep[REP_PERIOD], but also use the software autorepeat
functionality from input.c.

For example, a HID driver could do:

static void xyz_input_configured(struct hid_device *hid,
struct hid_input *hidinput)
{
input_enable_softrepeat(hidinput->input, 400, 100);
}

static struct hid_driver xyz_driver = {
.input_configured = xyz_input_configured,
}

Signed-off-by: Petri Gynther <pgynther@google.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Petri Gynther and committed by
Dmitry Torokhov
027c71bb aba54876

+21 -6
+19 -6
drivers/input/input.c
··· 2045 2045 } 2046 2046 2047 2047 /** 2048 + * input_enable_softrepeat - enable software autorepeat 2049 + * @dev: input device 2050 + * @delay: repeat delay 2051 + * @period: repeat period 2052 + * 2053 + * Enable software autorepeat on the input device. 2054 + */ 2055 + void input_enable_softrepeat(struct input_dev *dev, int delay, int period) 2056 + { 2057 + dev->timer.data = (unsigned long) dev; 2058 + dev->timer.function = input_repeat_key; 2059 + dev->rep[REP_DELAY] = delay; 2060 + dev->rep[REP_PERIOD] = period; 2061 + } 2062 + EXPORT_SYMBOL(input_enable_softrepeat); 2063 + 2064 + /** 2048 2065 * input_register_device - register device with input core 2049 2066 * @dev: device to be registered 2050 2067 * ··· 2125 2108 * If delay and period are pre-set by the driver, then autorepeating 2126 2109 * is handled by the driver itself and we don't do it in input.c. 2127 2110 */ 2128 - if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { 2129 - dev->timer.data = (long) dev; 2130 - dev->timer.function = input_repeat_key; 2131 - dev->rep[REP_DELAY] = 250; 2132 - dev->rep[REP_PERIOD] = 33; 2133 - } 2111 + if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) 2112 + input_enable_softrepeat(dev, 250, 33); 2134 2113 2135 2114 if (!dev->getkeycode) 2136 2115 dev->getkeycode = input_default_getkeycode;
+2
include/linux/input.h
··· 469 469 int input_set_keycode(struct input_dev *dev, 470 470 const struct input_keymap_entry *ke); 471 471 472 + void input_enable_softrepeat(struct input_dev *dev, int delay, int period); 473 + 472 474 extern struct class input_class; 473 475 474 476 /**