From: "Ville Syrjälä" <syrjala@sci.fi>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>,
Linux Input <linux-input@vger.kernel.org>,
linux-media@vger.kernel.org, Jarod Wilson <jarod@redhat.com>,
Maxim Levitsky <maximlevitsky@gmail.com>,
David Hardeman <david@hardeman.nu>, Jiri Kosina <jkosina@suse.cz>
Subject: Re: [PATCH 5/6] Input: ati-remote2 - switch to using new keycode interface
Date: Thu, 9 Sep 2010 15:40:04 +0300 [thread overview]
Message-ID: <20100909124003.GT10135@sci.fi> (raw)
In-Reply-To: <20100908074205.32365.68835.stgit@hammer.corenet.prv>
On Wed, Sep 08, 2010 at 12:42:05AM -0700, Dmitry Torokhov wrote:
> Switch the code to use new style of getkeycode and setkeycode
> methods to allow retrieving and setting keycodes not only by
> their scancodes but also by index.
>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
>
> drivers/input/misc/ati_remote2.c | 93 +++++++++++++++++++++++++++-----------
> 1 files changed, 65 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
> index 2325765..b2e0d82 100644
> --- a/drivers/input/misc/ati_remote2.c
> +++ b/drivers/input/misc/ati_remote2.c
> @@ -483,51 +483,88 @@ static void ati_remote2_complete_key(struct urb *urb)
> }
>
> static int ati_remote2_getkeycode(struct input_dev *idev,
> - unsigned int scancode, unsigned int *keycode)
> + struct input_keymap_entry *ke)
> {
> struct ati_remote2 *ar2 = input_get_drvdata(idev);
> unsigned int mode;
> - int index;
> + int offset;
> + unsigned int index;
> + unsigned int scancode;
> +
> + if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
> + index = ke->index;
> + if (index >= (ATI_REMOTE2_MODES - 1) *
^^^^
That -1 looks wrong. Same in setkeycode().
> + ARRAY_SIZE(ati_remote2_key_table))
> + return -EINVAL;
> +
> + mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
> + offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
> + scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
> + } else {
> + if (input_scancode_to_scalar(ke, &scancode))
> + return -EINVAL;
> +
> + mode = scancode >> 8;
> + if (mode > ATI_REMOTE2_PC)
> + return -EINVAL;
> +
> + offset = ati_remote2_lookup(scancode & 0xff);
> + if (offset < 0)
> + return -EINVAL;
> +
> + index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
> + }
>
> - mode = scancode >> 8;
> - if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask))
> - return -EINVAL;
You're removing the mode_mask check here, but I think that's fine. I
don't see why the keymap shouldn't be allowed to be queried/modified for
the unused modes.
> + ke->keycode = ar2->keycode[mode][offset];
> + ke->len = sizeof(scancode);
> + memcpy(&ke->scancode, &scancode, sizeof(scancode));
The scancodes fit into two bytes each. Does it matter that you're
using 4 bytes here?
> + ke->index = index;
>
> - index = ati_remote2_lookup(scancode & 0xFF);
> - if (index < 0)
> - return -EINVAL;
> -
> - *keycode = ar2->keycode[mode][index];
> return 0;
> }
>
> static int ati_remote2_setkeycode(struct input_dev *idev,
> - unsigned int scancode, unsigned int keycode)
> + const struct input_keymap_entry *ke,
> + unsigned int *old_keycode)
> {
> struct ati_remote2 *ar2 = input_get_drvdata(idev);
> - unsigned int mode, old_keycode;
> - int index;
> -
> - mode = scancode >> 8;
> - if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask))
> - return -EINVAL;
> -
> - index = ati_remote2_lookup(scancode & 0xFF);
> - if (index < 0)
> - return -EINVAL;
> + unsigned int mode;
> + int offset;
> + unsigned int index;
> + unsigned int scancode;
> +
> + if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
> + if (ke->index >= (ATI_REMOTE2_MODES - 1) *
> + ARRAY_SIZE(ati_remote2_key_table))
> + return -EINVAL;
> +
> + mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
> + offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
> + } else {
> + if (input_scancode_to_scalar(ke, &scancode))
> + return -EINVAL;
> +
> + mode = scancode >> 8;
> + if (mode > ATI_REMOTE2_PC)
> + return -EINVAL;
> +
> + offset = ati_remote2_lookup(scancode & 0xff);
> + if (offset < 0)
> + return -EINVAL;
> + }
>
> - old_keycode = ar2->keycode[mode][index];
> - ar2->keycode[mode][index] = keycode;
> - __set_bit(keycode, idev->keybit);
> + *old_keycode = ar2->keycode[mode][offset];
> + ar2->keycode[mode][offset] = ke->keycode;
> + __set_bit(ke->keycode, idev->keybit);
>
> for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
> for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
> - if (ar2->keycode[mode][index] == old_keycode)
> + if (ar2->keycode[mode][index] == *old_keycode)
> return 0;
> }
> }
>
> - __clear_bit(old_keycode, idev->keybit);
> + __clear_bit(*old_keycode, idev->keybit);
>
> return 0;
> }
> @@ -575,8 +612,8 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
> idev->open = ati_remote2_open;
> idev->close = ati_remote2_close;
>
> - idev->getkeycode = ati_remote2_getkeycode;
> - idev->setkeycode = ati_remote2_setkeycode;
> + idev->getkeycode_new = ati_remote2_getkeycode;
> + idev->setkeycode_new = ati_remote2_setkeycode;
>
> idev->name = ar2->name;
> idev->phys = ar2->phys;
>
--
Ville Syrjälä
syrjala@sci.fi
http://www.sci.fi/~syrjala/
next prev parent reply other threads:[~2010-09-09 12:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-08 7:41 [PATCH 0/6] Large scancode handling Dmitry Torokhov
2010-09-08 7:41 ` [PATCH 1/6] Input: add support for large scancodes Dmitry Torokhov
2010-10-29 21:36 ` James Hogan
2010-10-29 22:34 ` James Hogan
2010-09-08 7:41 ` [PATCH 2/6] Input: sparse-keymap - switch to using new keycode interface Dmitry Torokhov
2010-09-08 7:41 ` [PATCH 3/6] Input: hid-input " Dmitry Torokhov
2010-09-08 7:42 ` [PATCH 4/6] Input: winbond-cir " Dmitry Torokhov
2010-09-08 21:16 ` David Härdeman
2010-09-08 23:00 ` Dmitry Torokhov
2010-09-08 23:09 ` David Härdeman
2010-09-08 23:14 ` Mauro Carvalho Chehab
2010-09-08 7:42 ` [PATCH 5/6] Input: ati-remote2 " Dmitry Torokhov
2010-09-09 12:40 ` Ville Syrjälä [this message]
2010-09-13 16:28 ` Dmitry Torokhov
2010-09-15 21:04 ` Ville Syrjälä
2010-09-15 21:13 ` Dmitry Torokhov
2010-09-08 7:42 ` [PATCH 6/6] Input: media/IR " Dmitry Torokhov
2010-09-08 9:48 ` [PATCH 0/6] Large scancode handling Jiri Kosina
2010-09-08 14:24 ` Jarod Wilson
2010-09-08 15:15 ` Mauro Carvalho Chehab
2010-09-08 15:22 ` Jarod Wilson
2010-09-08 15:25 ` Jiri Kosina
2010-09-08 15:36 ` Dmitry Torokhov
2010-09-08 16:09 ` Jarod Wilson
2010-09-08 16:56 ` Dmitry Torokhov
2010-09-08 17:29 ` Jarod Wilson
2010-09-13 15:00 ` Jiri Kosina
2010-09-08 15:36 ` Dmitry Torokhov
2010-09-08 14:31 ` Jarod Wilson
2010-09-08 15:34 ` Dmitry Torokhov
2010-09-13 17:48 ` Jarod Wilson
2010-09-14 1:26 ` Dmitry Torokhov
2010-09-08 15:23 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100909124003.GT10135@sci.fi \
--to=syrjala@sci.fi \
--cc=david@hardeman.nu \
--cc=dmitry.torokhov@gmail.com \
--cc=jarod@redhat.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maximlevitsky@gmail.com \
--cc=mchehab@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).