diff mbox

[v2] Input: improve autorepeat initialization

Message ID 1444676686-26900-1-git-send-email-pgynther@google.com (mailing list archive)
State Superseded
Headers show

Commit Message

Petri Gynther Oct. 12, 2015, 7:04 p.m. UTC
Allow driver to initialize its 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)
{
        hidinput->input->rep[REP_DELAY] = 400;
        hidinput->input->rep[REP_PERIOD] = 100;
        hidinput->input->softrepeat = true;
}

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

Signed-off-by: Petri Gynther <pgynther@google.com>
---
 drivers/input/input.c | 9 +++++++--
 include/linux/input.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

Comments

Petri Gynther Oct. 13, 2015, 11:05 p.m. UTC | #1
Hi Dmitry,

On Mon, Oct 12, 2015 at 12:04 PM, Petri Gynther <pgynther@google.com> wrote:
> Allow driver to initialize its 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)
> {
>         hidinput->input->rep[REP_DELAY] = 400;
>         hidinput->input->rep[REP_PERIOD] = 100;
>         hidinput->input->softrepeat = true;
> }
>
> static struct hid_driver xyz_driver = {
>         .input_configured = xyz_input_configured,
> }
>
> Signed-off-by: Petri Gynther <pgynther@google.com>
> ---
>  drivers/input/input.c | 9 +++++++--
>  include/linux/input.h | 1 +
>  2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 5391abd..a6f65c7 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -2106,13 +2106,18 @@ int input_register_device(struct input_dev *dev)
>
>         /*
>          * If delay and period are pre-set by the driver, then autorepeating
> -        * is handled by the driver itself and we don't do it in input.c.
> +        * is handled by the driver itself and we don't do it in input.c
> +        * unless the driver also requests softrepeat.
>          */
>         if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
> -               dev->timer.data = (long) dev;
> +               dev->softrepeat = true;
> +               dev->timer.data = (unsigned long) dev;
>                 dev->timer.function = input_repeat_key;
>                 dev->rep[REP_DELAY] = 250;
>                 dev->rep[REP_PERIOD] = 33;

Please ignore this patch v2.
Better solution is to move the code from if-statement to an exported
function and call it here and from drivers when desired.
Sending patch v3 shortly.

> +       } else if (dev->softrepeat) {
> +               dev->timer.data = (unsigned long) dev;
> +               dev->timer.function = input_repeat_key;
>         }
>
>         if (!dev->getkeycode)
> diff --git a/include/linux/input.h b/include/linux/input.h
> index 82ce323..2535948 100644
> --- a/include/linux/input.h
> +++ b/include/linux/input.h
> @@ -150,6 +150,7 @@ struct input_dev {
>
>         struct ff_device *ff;
>
> +       bool softrepeat;
>         unsigned int repeat_key;
>         struct timer_list timer;
>
> --
> 2.6.0.rc2.230.g3dd15c0
>
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 5391abd..a6f65c7 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -2106,13 +2106,18 @@  int input_register_device(struct input_dev *dev)
 
 	/*
 	 * If delay and period are pre-set by the driver, then autorepeating
-	 * is handled by the driver itself and we don't do it in input.c.
+	 * is handled by the driver itself and we don't do it in input.c
+	 * unless the driver also requests softrepeat.
 	 */
 	if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
-		dev->timer.data = (long) dev;
+		dev->softrepeat = true;
+		dev->timer.data = (unsigned long) dev;
 		dev->timer.function = input_repeat_key;
 		dev->rep[REP_DELAY] = 250;
 		dev->rep[REP_PERIOD] = 33;
+	} else if (dev->softrepeat) {
+		dev->timer.data = (unsigned long) dev;
+		dev->timer.function = input_repeat_key;
 	}
 
 	if (!dev->getkeycode)
diff --git a/include/linux/input.h b/include/linux/input.h
index 82ce323..2535948 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -150,6 +150,7 @@  struct input_dev {
 
 	struct ff_device *ff;
 
+	bool softrepeat;
 	unsigned int repeat_key;
 	struct timer_list timer;