[PATCH 4/6] Input: winbond-cir - switch to using new keycode interface

2010-09-08 Thread Dmitry Torokhov
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 d...@mail.ru
---

 drivers/input/misc/winbond-cir.c |  248 +-
 1 files changed, 163 insertions(+), 85 deletions(-)

diff --git a/drivers/input/misc/winbond-cir.c b/drivers/input/misc/winbond-cir.c
index 64f1de7..6a69067 100644
--- a/drivers/input/misc/winbond-cir.c
+++ b/drivers/input/misc/winbond-cir.c
@@ -172,7 +172,6 @@ enum wbcir_protocol {
 #define WBCIR_MAX_IDLE_BYTES   10
 
 static DEFINE_SPINLOCK(wbcir_lock);
-static DEFINE_RWLOCK(keytable_lock);
 
 struct wbcir_key {
u32 scancode;
@@ -184,7 +183,7 @@ struct wbcir_keyentry {
struct list_head list;
 };
 
-static struct wbcir_key rc6_def_keymap[] = {
+static const struct wbcir_key rc6_def_keymap[] = {
{ 0x800F0400, KEY_NUMERIC_0 },
{ 0x800F0401, KEY_NUMERIC_1 },
{ 0x800F0402, KEY_NUMERIC_2 },
@@ -365,88 +364,152 @@ wbcir_to_rc6cells(u8 val)
  *
  */
 
-static unsigned int
-wbcir_do_getkeycode(struct wbcir_data *data, u32 scancode)
+static struct wbcir_keyentry *
+wbcir_keyentry_by_scancode(struct wbcir_data *data, u32 scancode)
 {
struct wbcir_keyentry *keyentry;
-   unsigned int keycode = KEY_RESERVED;
-   unsigned long flags;
 
-   read_lock_irqsave(keytable_lock, flags);
+   list_for_each_entry(keyentry, data-keytable, list)
+   if (keyentry-key.scancode == scancode)
+   return keyentry;
+
+   return NULL;
+}
+
+static struct wbcir_keyentry *
+wbcir_keyentry_by_index(struct wbcir_data *data, unsigned int index)
+{
+   struct wbcir_keyentry *keyentry;
+   unsigned int cur_idx = 0;
+
+   list_for_each_entry(keyentry, data-keytable, list)
+   if (cur_idx++ == index)
+   return keyentry;
+
+   return NULL;
+}
+
+static struct wbcir_keyentry *
+wbcir_lookup_keyentry(struct wbcir_data *data,
+ const struct input_keymap_entry *ke)
+{
+   struct wbcir_keyentry *keyentry;
+   unsigned int scancode;
+
+   if (ke-flags  INPUT_KEYMAP_BY_INDEX)
+   keyentry = wbcir_keyentry_by_index(data, ke-index);
+   else if (input_scancode_to_scalar(ke, scancode) == 0)
+   keyentry = wbcir_keyentry_by_scancode(data, scancode);
+   else
+   keyentry = NULL;
+
+   return keyentry;
+
+}
+
+static unsigned int
+wbcir_keyentry_get_index(struct wbcir_data *data,
+const struct wbcir_keyentry *keyentry)
+{
+   struct wbcir_keyentry *k;
+   int idx = 0;
 
-   list_for_each_entry(keyentry, data-keytable, list) {
-   if (keyentry-key.scancode == scancode) {
-   keycode = keyentry-key.keycode;
+   list_for_each_entry(k, data-keytable, list) {
+   if (k == keyentry)
break;
-   }
+   idx++;
}
 
-   read_unlock_irqrestore(keytable_lock, flags);
-   return keycode;
+   return idx;
 }
 
 static int
-wbcir_getkeycode(struct input_dev *dev,
-unsigned int scancode, unsigned int *keycode)
+wbcir_getkeycode(struct input_dev *dev, struct input_keymap_entry *ke)
 {
struct wbcir_data *data = input_get_drvdata(dev);
+   const struct wbcir_keyentry *keyentry;
+
+   keyentry = wbcir_lookup_keyentry(data, ke);
+   if (keyentry) {
+   ke-keycode = keyentry-key.keycode;
+   if (!(ke-flags  INPUT_KEYMAP_BY_INDEX))
+   ke-index = wbcir_keyentry_get_index(data, keyentry);
+   ke-len = sizeof(keyentry-key.scancode);
+   memcpy(ke-scancode, keyentry-key.scancode,
+   sizeof(keyentry-key.scancode));
+
+   return 0;
+   }
 
-   *keycode = wbcir_do_getkeycode(data, scancode);
-   return 0;
+   return -EINVAL;
 }
 
 static int
 wbcir_setkeycode(struct input_dev *dev,
-unsigned int scancode, unsigned int keycode)
+const struct input_keymap_entry *ke,
+unsigned int *old_keycode)
 {
struct wbcir_data *data = input_get_drvdata(dev);
struct wbcir_keyentry *keyentry;
-   struct wbcir_keyentry *new_keyentry;
-   unsigned long flags;
-   unsigned int old_keycode = KEY_RESERVED;
-
-   new_keyentry = kmalloc(sizeof(*new_keyentry), GFP_KERNEL);
-   if (!new_keyentry)
-   return -ENOMEM;
+   unsigned int scancode;
 
-   write_lock_irqsave(keytable_lock, flags);
+   *old_keycode = KEY_RESERVED;
 
-   list_for_each_entry(keyentry, data-keytable, list) {
-   if (keyentry-key.scancode != scancode)
-   continue;
+   if 

Re: [PATCH 4/6] Input: winbond-cir - switch to using new keycode interface

2010-09-08 Thread David Härdeman
On Wed, Sep 08, 2010 at 12:42:00AM -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 d...@mail.ru
 ---
 
  drivers/input/misc/winbond-cir.c |  248 
 +-
  1 files changed, 163 insertions(+), 85 deletions(-)

Thanks for doing the conversion for me, but I think you can skip this 
patch. The driver will (if I understood your patchset correctly) still 
work with the old get/setkeycode ioctls and I have a patch lined up that 
converts winbond-cir.c to use ir-core which means all of the input 
related code is removed.


-- 
David Härdeman
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] Input: winbond-cir - switch to using new keycode interface

2010-09-08 Thread Dmitry Torokhov
On Wed, Sep 08, 2010 at 11:16:17PM +0200, David Härdeman wrote:
 On Wed, Sep 08, 2010 at 12:42:00AM -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 d...@mail.ru
  ---
  
   drivers/input/misc/winbond-cir.c |  248 
  +-
   1 files changed, 163 insertions(+), 85 deletions(-)
 
 Thanks for doing the conversion for me, but I think you can skip this 
 patch. The driver will (if I understood your patchset correctly) still 
 work with the old get/setkeycode ioctls and I have a patch lined up that 
 converts winbond-cir.c to use ir-core which means all of the input 
 related code is removed.
 

Yes, it should still work with old get/setkeycode. What are the plans
for your patch? .37 or later?

-- 
Dmitry
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] Input: winbond-cir - switch to using new keycode interface

2010-09-08 Thread David Härdeman
On Wed, Sep 08, 2010 at 04:00:04PM -0700, Dmitry Torokhov wrote:
 On Wed, Sep 08, 2010 at 11:16:17PM +0200, David Härdeman wrote:
  On Wed, Sep 08, 2010 at 12:42:00AM -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 d...@mail.ru
   ---
   
drivers/input/misc/winbond-cir.c |  248 
   +-
1 files changed, 163 insertions(+), 85 deletions(-)
  
  Thanks for doing the conversion for me, but I think you can skip this 
  patch. The driver will (if I understood your patchset correctly) still 
  work with the old get/setkeycode ioctls and I have a patch lined up that 
  converts winbond-cir.c to use ir-core which means all of the input 
  related code is removed.
  
 
 Yes, it should still work with old get/setkeycode. What are the plans
 for your patch? .37 or later?

Up to Mauro but I believe it's .37 (sometime after your input patches 
land).

-- 
David Härdeman
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] Input: winbond-cir - switch to using new keycode interface

2010-09-08 Thread Mauro Carvalho Chehab
Em 08-09-2010 20:09, David Härdeman escreveu:
 On Wed, Sep 08, 2010 at 04:00:04PM -0700, Dmitry Torokhov wrote:
 On Wed, Sep 08, 2010 at 11:16:17PM +0200, David Härdeman wrote:
 On Wed, Sep 08, 2010 at 12:42:00AM -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 d...@mail.ru
 ---

  drivers/input/misc/winbond-cir.c |  248 
 +-
  1 files changed, 163 insertions(+), 85 deletions(-)

 Thanks for doing the conversion for me, but I think you can skip this 
 patch. The driver will (if I understood your patchset correctly) still 
 work with the old get/setkeycode ioctls and I have a patch lined up that 
 converts winbond-cir.c to use ir-core which means all of the input 
 related code is removed.


 Yes, it should still work with old get/setkeycode. What are the plans
 for your patch? .37 or later?
 
 Up to Mauro but I believe it's .37 (sometime after your input patches 
 land).

.37 seems feasible, if you submit your patch in time for review.

Maybe I should create a temporary staging tree for .37 with the input patches
applied there, to allow people to better review and test the rc patches with
everything applied.

Cheers,
Mauro.

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html