Re: [PATCH 2/2] HID: redragon Add additional verification to rdesc modification quirk

2018-08-03 Thread Robert Munteanu
On Sat, 2018-07-28 at 15:53 -0400, John S Gruber wrote:
> There are many devices using the vendor_id 0c45 and device_id of 760b
> combination. Also the two bytes 0x81 0x00 aren't rare for a report
> description. For these reasons the report description being altered
> by the quirk should be verified more completely
> 
> If I'm understanding this correctly, I believe for an array field the
> report_size should be greater or equal to
> ceil(log2(usage_maximum - usage_minimum + 1)). That's 3 bits for
> these 8
> shift keys, 0xe0-0xe7. Therefore the incorrect report description
> can't
> be valid for any device.
> 
> Check the actual count of the rdesc and compare the entire field
> description to reduce the chance of patching the wrong thing by
> inadvertence.
> 
> Signed-off-by: John S Gruber 

I tested this on 4.17.11 with 85455dd906d5 and cbe7e3ad0eab from Jiri's
for-4.19/upstream tree and it works just fine.

Feel free to add

  Acked-By: Robert Munteanu 

Thanks for looking into this.

Robert



Re: [PATCH 2/2] HID: redragon Add additional verification to rdesc modification quirk

2018-08-03 Thread Robert Munteanu
On Sat, 2018-07-28 at 15:53 -0400, John S Gruber wrote:
> There are many devices using the vendor_id 0c45 and device_id of 760b
> combination. Also the two bytes 0x81 0x00 aren't rare for a report
> description. For these reasons the report description being altered
> by the quirk should be verified more completely
> 
> If I'm understanding this correctly, I believe for an array field the
> report_size should be greater or equal to
> ceil(log2(usage_maximum - usage_minimum + 1)). That's 3 bits for
> these 8
> shift keys, 0xe0-0xe7. Therefore the incorrect report description
> can't
> be valid for any device.
> 
> Check the actual count of the rdesc and compare the entire field
> description to reduce the chance of patching the wrong thing by
> inadvertence.
> 
> Signed-off-by: John S Gruber 

I tested this on 4.17.11 with 85455dd906d5 and cbe7e3ad0eab from Jiri's
for-4.19/upstream tree and it works just fine.

Feel free to add

  Acked-By: Robert Munteanu 

Thanks for looking into this.

Robert



Re: [PATCH 1/2] HID: redragon: Fix regression in non-Redragon keyboard due to this new driver

2018-07-30 Thread Robert Munteanu
Hi John,

On Sat, 2018-07-28 at 15:53 -0400, John S Gruber wrote:
> The Redragon keyboard uses the second device being presented, but
> other
> devices with the same vendor_id/device_id pair (0x0c45:760b) use the
> first.
> Don't cause its deletion. Problem introduced in commit 85455dd906d5
> ("HID: redragon: Fix modifier keys for Redragon Asura Keyboard")
> 
> Fixes: 85455dd906d5
> Signed-off-by: John S Gruber 
> ---
>  drivers/hid/hid-redragon.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
> index daf5957..85a5fbb 100644
> --- a/drivers/hid/hid-redragon.c
> +++ b/drivers/hid/hid-redragon.c
> @@ -55,10 +55,6 @@ static int redragon_probe(struct hid_device *dev,
>   return ret;
>   }
> 
> - /* do not register unused input device */
> - if (dev->maxapplication == 1)
> - return 0;
> -
>   ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
>   if (ret) {
>   hid_err(dev, "hw start failed\n");

As I mentioned, this is already fixed by
dc9b8e85ed95cbe7e3ad0eabb5b48d617bbc365e, scheduled for 4.19, and I
suggest that we instead add that one to 4.18.

The explanation is that the block you deleted was the whole reason for
adding the redragon_probe function, so the changes are largely
equivalent.

Thanks,

Robert



Re: [PATCH 1/2] HID: redragon: Fix regression in non-Redragon keyboard due to this new driver

2018-07-30 Thread Robert Munteanu
Hi John,

On Sat, 2018-07-28 at 15:53 -0400, John S Gruber wrote:
> The Redragon keyboard uses the second device being presented, but
> other
> devices with the same vendor_id/device_id pair (0x0c45:760b) use the
> first.
> Don't cause its deletion. Problem introduced in commit 85455dd906d5
> ("HID: redragon: Fix modifier keys for Redragon Asura Keyboard")
> 
> Fixes: 85455dd906d5
> Signed-off-by: John S Gruber 
> ---
>  drivers/hid/hid-redragon.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
> index daf5957..85a5fbb 100644
> --- a/drivers/hid/hid-redragon.c
> +++ b/drivers/hid/hid-redragon.c
> @@ -55,10 +55,6 @@ static int redragon_probe(struct hid_device *dev,
>   return ret;
>   }
> 
> - /* do not register unused input device */
> - if (dev->maxapplication == 1)
> - return 0;
> -
>   ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
>   if (ret) {
>   hid_err(dev, "hw start failed\n");

As I mentioned, this is already fixed by
dc9b8e85ed95cbe7e3ad0eabb5b48d617bbc365e, scheduled for 4.19, and I
suggest that we instead add that one to 4.18.

The explanation is that the block you deleted was the whole reason for
adding the redragon_probe function, so the changes are largely
equivalent.

Thanks,

Robert



[PATCH v6] Fix modifier keys for Redragon Asura Keyboard

2018-04-16 Thread Robert Munteanu
This adds a new driver for the Redragon Asura keyboard. The Asura
keyboard contains an error in the HID descriptor which causes all
modifier keys to be mapped to left shift. Additionally, we suppress
the creation of a second, not working, keyboard device.

Signed-off-by: Robert Munteanu <romb...@apache.org>
---
 drivers/hid/Kconfig|  7 
 drivers/hid/Makefile   |  1 +
 drivers/hid/hid-ids.h  |  1 +
 drivers/hid/hid-redragon.c | 86 ++
 4 files changed, 95 insertions(+)
 create mode 100644 drivers/hid/hid-redragon.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 19c499f5623d..1125e4813716 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -560,6 +560,13 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_REDRAGON
+   tristate "Redragon keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Redragon keyboards that need fix-ups to work properly.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index eb13b9e92d85..a36f3f40ba63 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -84,6 +84,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)+= 
hid-picolcd_debugfs.o
 
 obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
 obj-$(CONFIG_HID_PRIMAX)   += hid-primax.o
+obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
 obj-$(CONFIG_HID_RETRODE)  += hid-retrode.o
 obj-$(CONFIG_HID_ROCCAT)   += hid-roccat.o hid-roccat-common.o \
hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9454ac134ce2..41a64d0e91f9 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -599,6 +599,7 @@
 #define USB_VENDOR_ID_JESS 0x0c45
 #define USB_DEVICE_ID_JESS_YUREX   0x1010
 #define USB_DEVICE_ID_ASUS_MD_5112 0x5112
+#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
 
 #define USB_VENDOR_ID_JESS20x0f30
 #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
new file mode 100644
index ..daf59578bf93
--- /dev/null
+++ b/drivers/hid/hid-redragon.c
@@ -0,0 +1,86 @@
+/*
+ *  HID driver for Redragon keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ *  SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+/*
+ * The Redragon Asura keyboard sends an incorrect HID descriptor.
+ * At byte 100 it contains
+ *
+ *   0x81, 0x00
+ *
+ * which is Input (Data, Arr, Abs), but it should be
+ *
+ *   0x81, 0x02
+ *
+ * which is Input (Data, Var, Abs), which is consistent with the way
+ * key codes are generated.
+ */
+
+static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+   unsigned int *rsize)
+{
+   if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
+   dev_info(>dev, "Fixing Redragon ASURA report 
descriptor.\n");
+   rdesc[101] = 0x02;
+   }
+
+   return rdesc;
+}
+
+static int redragon_probe(struct hid_device *dev,
+   const struct hid_device_id *id)
+{
+   int ret;
+
+   ret = hid_parse(dev);
+   if (ret) {
+   hid_err(dev, "parse failed\n");
+   return ret;
+   }
+
+   /* do not register unused input device */
+   if (dev->maxapplication == 1)
+   return 0;
+
+   ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
+   if (ret) {
+   hid_err(dev, "hw start failed\n");
+   return ret;
+   }
+
+   return 0;
+}
+static const struct hid_device_id redragon_devices[] = {
+   {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
+   {}
+};
+
+MODULE_DEVICE_TABLE(hid, redragon_devices);
+
+static struct hid_driver redragon_driver = {
+   .name = "redragon",
+   .id_table = redragon_devices,
+   .report_fixup = redragon_report_fixup,
+   .probe = redragon_probe
+};
+
+module_hid_driver(redragon_driver);
+
+MODULE_LICENSE("GPL");
-- 
2.16.3



[PATCH v6] Fix modifier keys for Redragon Asura Keyboard

2018-04-16 Thread Robert Munteanu
This adds a new driver for the Redragon Asura keyboard. The Asura
keyboard contains an error in the HID descriptor which causes all
modifier keys to be mapped to left shift. Additionally, we suppress
the creation of a second, not working, keyboard device.

Signed-off-by: Robert Munteanu 
---
 drivers/hid/Kconfig|  7 
 drivers/hid/Makefile   |  1 +
 drivers/hid/hid-ids.h  |  1 +
 drivers/hid/hid-redragon.c | 86 ++
 4 files changed, 95 insertions(+)
 create mode 100644 drivers/hid/hid-redragon.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 19c499f5623d..1125e4813716 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -560,6 +560,13 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_REDRAGON
+   tristate "Redragon keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Redragon keyboards that need fix-ups to work properly.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index eb13b9e92d85..a36f3f40ba63 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -84,6 +84,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)+= 
hid-picolcd_debugfs.o
 
 obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
 obj-$(CONFIG_HID_PRIMAX)   += hid-primax.o
+obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
 obj-$(CONFIG_HID_RETRODE)  += hid-retrode.o
 obj-$(CONFIG_HID_ROCCAT)   += hid-roccat.o hid-roccat-common.o \
hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9454ac134ce2..41a64d0e91f9 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -599,6 +599,7 @@
 #define USB_VENDOR_ID_JESS 0x0c45
 #define USB_DEVICE_ID_JESS_YUREX   0x1010
 #define USB_DEVICE_ID_ASUS_MD_5112 0x5112
+#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
 
 #define USB_VENDOR_ID_JESS20x0f30
 #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
new file mode 100644
index ..daf59578bf93
--- /dev/null
+++ b/drivers/hid/hid-redragon.c
@@ -0,0 +1,86 @@
+/*
+ *  HID driver for Redragon keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ *  SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+/*
+ * The Redragon Asura keyboard sends an incorrect HID descriptor.
+ * At byte 100 it contains
+ *
+ *   0x81, 0x00
+ *
+ * which is Input (Data, Arr, Abs), but it should be
+ *
+ *   0x81, 0x02
+ *
+ * which is Input (Data, Var, Abs), which is consistent with the way
+ * key codes are generated.
+ */
+
+static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+   unsigned int *rsize)
+{
+   if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
+   dev_info(>dev, "Fixing Redragon ASURA report 
descriptor.\n");
+   rdesc[101] = 0x02;
+   }
+
+   return rdesc;
+}
+
+static int redragon_probe(struct hid_device *dev,
+   const struct hid_device_id *id)
+{
+   int ret;
+
+   ret = hid_parse(dev);
+   if (ret) {
+   hid_err(dev, "parse failed\n");
+   return ret;
+   }
+
+   /* do not register unused input device */
+   if (dev->maxapplication == 1)
+   return 0;
+
+   ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
+   if (ret) {
+   hid_err(dev, "hw start failed\n");
+   return ret;
+   }
+
+   return 0;
+}
+static const struct hid_device_id redragon_devices[] = {
+   {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
+   {}
+};
+
+MODULE_DEVICE_TABLE(hid, redragon_devices);
+
+static struct hid_driver redragon_driver = {
+   .name = "redragon",
+   .id_table = redragon_devices,
+   .report_fixup = redragon_report_fixup,
+   .probe = redragon_probe
+};
+
+module_hid_driver(redragon_driver);
+
+MODULE_LICENSE("GPL");
-- 
2.16.3



Re: [PATCH v5] Fix modifier keys for Redragon Asura Keyboard

2018-04-16 Thread Robert Munteanu
On Mon, 2018-04-16 at 15:36 +0200, Benjamin Tissoires wrote:
> > > > +MODULE_LICENSE("GPL");
> > > 
> > > The SPDX header says GPL-v2. And IIRC if there is the SPDX header
> > > you
> > > can drop the MODULE_LICENSE (not entirely sure though).
> > 
> > Ack, will adjust and re-test.
> 
> Actually, you might be correct. I just read Mauro's blog:
> https://blogs.s-osg.org/linux-kernel-license-practices-revisited-spdx
> /
> and it says "Types of licenses for MODULE_LICENSE() macro -> 'GPL' ->
> GNU Public License v2 or later" (in the second table).

Currently the header says 'SPDX-License-Identifier: GPL-2.0', which is
'GNU General Public License v2.0 only' according to 

  https://spdx.org/licenses/

So we can't use that with MODULE_LICENSE("GPL") which means 'GNU
General Public License v2.0 or later' . I don't have a strong
preference for either, but I'll go with the 'or later' part since that
seems to be more in favour ( shorter argument for the MODULE_LICENSE
macro ).

Robert


Re: [PATCH v5] Fix modifier keys for Redragon Asura Keyboard

2018-04-16 Thread Robert Munteanu
On Mon, 2018-04-16 at 15:36 +0200, Benjamin Tissoires wrote:
> > > > +MODULE_LICENSE("GPL");
> > > 
> > > The SPDX header says GPL-v2. And IIRC if there is the SPDX header
> > > you
> > > can drop the MODULE_LICENSE (not entirely sure though).
> > 
> > Ack, will adjust and re-test.
> 
> Actually, you might be correct. I just read Mauro's blog:
> https://blogs.s-osg.org/linux-kernel-license-practices-revisited-spdx
> /
> and it says "Types of licenses for MODULE_LICENSE() macro -> 'GPL' ->
> GNU Public License v2 or later" (in the second table).

Currently the header says 'SPDX-License-Identifier: GPL-2.0', which is
'GNU General Public License v2.0 only' according to 

  https://spdx.org/licenses/

So we can't use that with MODULE_LICENSE("GPL") which means 'GNU
General Public License v2.0 or later' . I don't have a strong
preference for either, but I'll go with the 'or later' part since that
seems to be more in favour ( shorter argument for the MODULE_LICENSE
macro ).

Robert


Re: [PATCH v5] Fix modifier keys for Redragon Asura Keyboard

2018-04-16 Thread Robert Munteanu
Hi Benjamin and Jiri,

On Mon, 2018-04-16 at 12:02 +0200, Benjamin Tissoires wrote:
> Hi Robert,
> 
> On Wed, Apr 11, 2018 at 11:49 AM, Robert Munteanu <romb...@apache.org
> > wrote:
> > Changelog:
> > 
> > - v2: modifier keys work, some combinations are still troublesome
> > - v3: style cleanup, rebase on top of 4.14
> > - v4: remove most debugging calls, make init info useful for user,
> >   rebased on top of 4.15
> > - v5: fix the HID descriptor as suggested by Benjamin Tissoires,
> >   use existing USB vendor id, update comment style, add SPDX
> >   license identifier, rename to hid-redragon, stop registering
> >   two input devices, rebased on top of 4.16
> 
> As Jiri said, please provide a correct commit message.

Will do.

> 
> I have a few nitpicks in the driver, v6 should be fine:
> 
> > 
> > Signed-off-by: Robert Munteanu <romb...@apache.org>
> > ---
> >  drivers/hid/Kconfig|  7 
> >  drivers/hid/Makefile   |  1 +
> >  drivers/hid/hid-ids.h  |  1 +
> >  drivers/hid/hid-quirks.c   |  3 ++
> >  drivers/hid/hid-redragon.c | 89
> > ++
> >  5 files changed, 101 insertions(+)
> >  create mode 100644 drivers/hid/hid-redragon.c
> > 
> > diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> > index 19c499f5623d..1125e4813716 100644
> > --- a/drivers/hid/Kconfig
> > +++ b/drivers/hid/Kconfig
> > @@ -560,6 +560,13 @@ config HID_MAYFLASH
> > Say Y here if you have HJZ Mayflash PS3 game controller
> > adapters
> > and want to enable force feedback support.
> > 
> > +config HID_REDRAGON
> > +   tristate "Redragon keyboards"
> > +   depends on HID
> > +   default !EXPERT
> > +   ---help---
> > +Support for Redragon keyboards that need fix-ups to work
> > properly.
> > +
> >  config HID_MICROSOFT
> > tristate "Microsoft non-fully HID-compliant devices"
> > depends on HID
> > diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
> > index eb13b9e92d85..a36f3f40ba63 100644
> > --- a/drivers/hid/Makefile
> > +++ b/drivers/hid/Makefile
> > @@ -84,6 +84,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)+=
> > hid-picolcd_debugfs.o
> > 
> >  obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
> >  obj-$(CONFIG_HID_PRIMAX)   += hid-primax.o
> > +obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
> >  obj-$(CONFIG_HID_RETRODE)  += hid-retrode.o
> >  obj-$(CONFIG_HID_ROCCAT)   += hid-roccat.o hid-roccat-common.o 
> > \
> > hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 9454ac134ce2..41a64d0e91f9 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -599,6 +599,7 @@
> >  #define USB_VENDOR_ID_JESS 0x0c45
> >  #define USB_DEVICE_ID_JESS_YUREX   0x1010
> >  #define USB_DEVICE_ID_ASUS_MD_5112 0x5112
> > +#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
> > 
> >  #define USB_VENDOR_ID_JESS20x0f30
> >  #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
> > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
> > index e92b77fa574a..5f1253f1739a 100644
> > --- a/drivers/hid/hid-quirks.c
> > +++ b/drivers/hid/hid-quirks.c
> > @@ -557,6 +557,9 @@ static const struct hid_device_id
> > hid_have_special_driver[] = {
> >  #if IS_ENABLED(CONFIG_HID_PRODIKEYS)
> > { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS,
> > USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
> >  #endif
> > +#if IS_ENABLED(CONFIG_HID_REDRAGON)
> > +   {
> > HID_USB_DEVICE(USB_VENDOR_ID_JESS,  USB_DEVICE_ID_REDRAGON_ASURA)
> > },
> > +#endif
> 
> Please drop this hunk. v4.16 should work without changing
> hid_have_special_driver. This way, you will be sure that an initramfs
> that doesn't include hid-redragon.ko will allo people to type their
> LUKS password.

I recall testing without this change resulted in the driver not being
picked up. I will retest ( running 4.16.0 here, can update to 4.16.1
soon ). In case the driver is not picked up, where should I start
looking?

> 
> >  #if IS_ENABLED(CONFIG_HID_RETRODE)
> > { HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY,
> > USB_DEVICE_ID_RETRODE2) },
> >  #endif
> > diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-
> > redragon.c
> > new file mode 100644
> > index ..ff98a5dbb8e2
> > --- /dev

Re: [PATCH v5] Fix modifier keys for Redragon Asura Keyboard

2018-04-16 Thread Robert Munteanu
Hi Benjamin and Jiri,

On Mon, 2018-04-16 at 12:02 +0200, Benjamin Tissoires wrote:
> Hi Robert,
> 
> On Wed, Apr 11, 2018 at 11:49 AM, Robert Munteanu  > wrote:
> > Changelog:
> > 
> > - v2: modifier keys work, some combinations are still troublesome
> > - v3: style cleanup, rebase on top of 4.14
> > - v4: remove most debugging calls, make init info useful for user,
> >   rebased on top of 4.15
> > - v5: fix the HID descriptor as suggested by Benjamin Tissoires,
> >   use existing USB vendor id, update comment style, add SPDX
> >   license identifier, rename to hid-redragon, stop registering
> >   two input devices, rebased on top of 4.16
> 
> As Jiri said, please provide a correct commit message.

Will do.

> 
> I have a few nitpicks in the driver, v6 should be fine:
> 
> > 
> > Signed-off-by: Robert Munteanu 
> > ---
> >  drivers/hid/Kconfig|  7 
> >  drivers/hid/Makefile   |  1 +
> >  drivers/hid/hid-ids.h  |  1 +
> >  drivers/hid/hid-quirks.c   |  3 ++
> >  drivers/hid/hid-redragon.c | 89
> > ++
> >  5 files changed, 101 insertions(+)
> >  create mode 100644 drivers/hid/hid-redragon.c
> > 
> > diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> > index 19c499f5623d..1125e4813716 100644
> > --- a/drivers/hid/Kconfig
> > +++ b/drivers/hid/Kconfig
> > @@ -560,6 +560,13 @@ config HID_MAYFLASH
> > Say Y here if you have HJZ Mayflash PS3 game controller
> > adapters
> > and want to enable force feedback support.
> > 
> > +config HID_REDRAGON
> > +   tristate "Redragon keyboards"
> > +   depends on HID
> > +   default !EXPERT
> > +   ---help---
> > +Support for Redragon keyboards that need fix-ups to work
> > properly.
> > +
> >  config HID_MICROSOFT
> > tristate "Microsoft non-fully HID-compliant devices"
> > depends on HID
> > diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
> > index eb13b9e92d85..a36f3f40ba63 100644
> > --- a/drivers/hid/Makefile
> > +++ b/drivers/hid/Makefile
> > @@ -84,6 +84,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)+=
> > hid-picolcd_debugfs.o
> > 
> >  obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
> >  obj-$(CONFIG_HID_PRIMAX)   += hid-primax.o
> > +obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
> >  obj-$(CONFIG_HID_RETRODE)  += hid-retrode.o
> >  obj-$(CONFIG_HID_ROCCAT)   += hid-roccat.o hid-roccat-common.o 
> > \
> > hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 9454ac134ce2..41a64d0e91f9 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -599,6 +599,7 @@
> >  #define USB_VENDOR_ID_JESS 0x0c45
> >  #define USB_DEVICE_ID_JESS_YUREX   0x1010
> >  #define USB_DEVICE_ID_ASUS_MD_5112 0x5112
> > +#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
> > 
> >  #define USB_VENDOR_ID_JESS20x0f30
> >  #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
> > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
> > index e92b77fa574a..5f1253f1739a 100644
> > --- a/drivers/hid/hid-quirks.c
> > +++ b/drivers/hid/hid-quirks.c
> > @@ -557,6 +557,9 @@ static const struct hid_device_id
> > hid_have_special_driver[] = {
> >  #if IS_ENABLED(CONFIG_HID_PRODIKEYS)
> > { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS,
> > USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
> >  #endif
> > +#if IS_ENABLED(CONFIG_HID_REDRAGON)
> > +   {
> > HID_USB_DEVICE(USB_VENDOR_ID_JESS,  USB_DEVICE_ID_REDRAGON_ASURA)
> > },
> > +#endif
> 
> Please drop this hunk. v4.16 should work without changing
> hid_have_special_driver. This way, you will be sure that an initramfs
> that doesn't include hid-redragon.ko will allo people to type their
> LUKS password.

I recall testing without this change resulted in the driver not being
picked up. I will retest ( running 4.16.0 here, can update to 4.16.1
soon ). In case the driver is not picked up, where should I start
looking?

> 
> >  #if IS_ENABLED(CONFIG_HID_RETRODE)
> > { HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY,
> > USB_DEVICE_ID_RETRODE2) },
> >  #endif
> > diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-
> > redragon.c
> > new file mode 100644
> > index ..ff98a5dbb8e2
> > --- /dev/null
> > +++ b/drivers/hid/hid-redragon.c
> &

[PATCH v5] Fix modifier keys for Redragon Asura Keyboard

2018-04-11 Thread Robert Munteanu
Changelog:

- v2: modifier keys work, some combinations are still troublesome
- v3: style cleanup, rebase on top of 4.14
- v4: remove most debugging calls, make init info useful for user,
  rebased on top of 4.15
- v5: fix the HID descriptor as suggested by Benjamin Tissoires,
  use existing USB vendor id, update comment style, add SPDX
  license identifier, rename to hid-redragon, stop registering
  two input devices, rebased on top of 4.16

Signed-off-by: Robert Munteanu <romb...@apache.org>
---
 drivers/hid/Kconfig|  7 
 drivers/hid/Makefile   |  1 +
 drivers/hid/hid-ids.h  |  1 +
 drivers/hid/hid-quirks.c   |  3 ++
 drivers/hid/hid-redragon.c | 89 ++
 5 files changed, 101 insertions(+)
 create mode 100644 drivers/hid/hid-redragon.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 19c499f5623d..1125e4813716 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -560,6 +560,13 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_REDRAGON
+   tristate "Redragon keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Redragon keyboards that need fix-ups to work properly.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index eb13b9e92d85..a36f3f40ba63 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -84,6 +84,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)+= 
hid-picolcd_debugfs.o
 
 obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
 obj-$(CONFIG_HID_PRIMAX)   += hid-primax.o
+obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
 obj-$(CONFIG_HID_RETRODE)  += hid-retrode.o
 obj-$(CONFIG_HID_ROCCAT)   += hid-roccat.o hid-roccat-common.o \
hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9454ac134ce2..41a64d0e91f9 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -599,6 +599,7 @@
 #define USB_VENDOR_ID_JESS 0x0c45
 #define USB_DEVICE_ID_JESS_YUREX   0x1010
 #define USB_DEVICE_ID_ASUS_MD_5112 0x5112
+#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
 
 #define USB_VENDOR_ID_JESS20x0f30
 #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index e92b77fa574a..5f1253f1739a 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -557,6 +557,9 @@ static const struct hid_device_id hid_have_special_driver[] 
= {
 #if IS_ENABLED(CONFIG_HID_PRODIKEYS)
{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, 
USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
 #endif
+#if IS_ENABLED(CONFIG_HID_REDRAGON)
+   { HID_USB_DEVICE(USB_VENDOR_ID_JESS,  USB_DEVICE_ID_REDRAGON_ASURA) },
+#endif
 #if IS_ENABLED(CONFIG_HID_RETRODE)
{ HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY, 
USB_DEVICE_ID_RETRODE2) },
 #endif
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
new file mode 100644
index ..ff98a5dbb8e2
--- /dev/null
+++ b/drivers/hid/hid-redragon.c
@@ -0,0 +1,89 @@
+/*
+ *  HID driver for Redragon keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ *  SPDX-License-Identifier: GPL-2.0
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+/*
+ * The Redragon Asura keyboard sends an incorrect HID descriptor.
+ * At byte 100 it contains
+ *
+ *   0x81, 0x00
+ *
+ * which is Input (Data, Arr, Abs), but it should be
+ *
+ *   0x81, 0x02
+ *
+ * which is Input (Data, Var, Abs), which is consistent with the way
+ * key codes are generated.
+ */
+
+static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+   unsigned int *rsize)
+{
+   if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
+   dev_info(>dev, "Fixing Redragon ASURA report 
descriptor.\n");
+   rdesc[101] = 0x02;
+   }
+
+   return rdesc;
+}
+
+static int redragon_probe(struct hid_device *dev,
+   const struct hid_device_id *id)
+{
+   int ret;
+
+   ret = hid_parse(dev);
+   if (ret) {
+   hid_err(dev, "parse failed\n");
+   return ret;
+   }
+
+   /* do not register unused input device */
+   if (dev->maxapplication == 1)
+   return 0;
+
+   ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
+   if (ret) {
+   hid_err(dev, "hw start 

[PATCH v5] Fix modifier keys for Redragon Asura Keyboard

2018-04-11 Thread Robert Munteanu
Changelog:

- v2: modifier keys work, some combinations are still troublesome
- v3: style cleanup, rebase on top of 4.14
- v4: remove most debugging calls, make init info useful for user,
  rebased on top of 4.15
- v5: fix the HID descriptor as suggested by Benjamin Tissoires,
  use existing USB vendor id, update comment style, add SPDX
  license identifier, rename to hid-redragon, stop registering
  two input devices, rebased on top of 4.16

Signed-off-by: Robert Munteanu 
---
 drivers/hid/Kconfig|  7 
 drivers/hid/Makefile   |  1 +
 drivers/hid/hid-ids.h  |  1 +
 drivers/hid/hid-quirks.c   |  3 ++
 drivers/hid/hid-redragon.c | 89 ++
 5 files changed, 101 insertions(+)
 create mode 100644 drivers/hid/hid-redragon.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 19c499f5623d..1125e4813716 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -560,6 +560,13 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_REDRAGON
+   tristate "Redragon keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Redragon keyboards that need fix-ups to work properly.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index eb13b9e92d85..a36f3f40ba63 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -84,6 +84,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS)+= 
hid-picolcd_debugfs.o
 
 obj-$(CONFIG_HID_PLANTRONICS)  += hid-plantronics.o
 obj-$(CONFIG_HID_PRIMAX)   += hid-primax.o
+obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
 obj-$(CONFIG_HID_RETRODE)  += hid-retrode.o
 obj-$(CONFIG_HID_ROCCAT)   += hid-roccat.o hid-roccat-common.o \
hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9454ac134ce2..41a64d0e91f9 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -599,6 +599,7 @@
 #define USB_VENDOR_ID_JESS 0x0c45
 #define USB_DEVICE_ID_JESS_YUREX   0x1010
 #define USB_DEVICE_ID_ASUS_MD_5112 0x5112
+#define USB_DEVICE_ID_REDRAGON_ASURA   0x760b
 
 #define USB_VENDOR_ID_JESS20x0f30
 #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index e92b77fa574a..5f1253f1739a 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -557,6 +557,9 @@ static const struct hid_device_id hid_have_special_driver[] 
= {
 #if IS_ENABLED(CONFIG_HID_PRODIKEYS)
{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, 
USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
 #endif
+#if IS_ENABLED(CONFIG_HID_REDRAGON)
+   { HID_USB_DEVICE(USB_VENDOR_ID_JESS,  USB_DEVICE_ID_REDRAGON_ASURA) },
+#endif
 #if IS_ENABLED(CONFIG_HID_RETRODE)
{ HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY, 
USB_DEVICE_ID_RETRODE2) },
 #endif
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c
new file mode 100644
index ..ff98a5dbb8e2
--- /dev/null
+++ b/drivers/hid/hid-redragon.c
@@ -0,0 +1,89 @@
+/*
+ *  HID driver for Redragon keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ *  SPDX-License-Identifier: GPL-2.0
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+/*
+ * The Redragon Asura keyboard sends an incorrect HID descriptor.
+ * At byte 100 it contains
+ *
+ *   0x81, 0x00
+ *
+ * which is Input (Data, Arr, Abs), but it should be
+ *
+ *   0x81, 0x02
+ *
+ * which is Input (Data, Var, Abs), which is consistent with the way
+ * key codes are generated.
+ */
+
+static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+   unsigned int *rsize)
+{
+   if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
+   dev_info(>dev, "Fixing Redragon ASURA report 
descriptor.\n");
+   rdesc[101] = 0x02;
+   }
+
+   return rdesc;
+}
+
+static int redragon_probe(struct hid_device *dev,
+   const struct hid_device_id *id)
+{
+   int ret;
+
+   ret = hid_parse(dev);
+   if (ret) {
+   hid_err(dev, "parse failed\n");
+   return ret;
+   }
+
+   /* do not register unused input device */
+   if (dev->maxapplication == 1)
+   return 0;
+
+   ret = hid_hw_start(dev, HID_CONNECT_DEFAULT);
+   if (ret) {
+   hid_err(dev, "hw start failed\n"

Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-22 Thread Robert Munteanu
On Thu, 2018-03-22 at 09:17 +0100, Robert Munteanu wrote:
> On Wed, 2018-03-21 at 17:51 +0100, Ondrej Zary wrote:
> > On Wednesday 21 March 2018 11:43:31 Robert Munteanu wrote:
> > > +#define USB_VENDOR_ID_MICRODIA  0x0c45
> > > +#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
> > 
> > Microdia is most probably an incorrect name. The 0c45 id probably
> > belongs 
> > to "Sonix Technology Co., Ltd."
> 
> Right, I was unsure about that. I'll remove the microdia references
> and
> use sonix.

I see the following in hid-ids.h

  define USB_VENDOR_ID_JESS0x0c45

which I guess I should use since it's already defined in there.

Robert


Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-22 Thread Robert Munteanu
On Thu, 2018-03-22 at 09:17 +0100, Robert Munteanu wrote:
> On Wed, 2018-03-21 at 17:51 +0100, Ondrej Zary wrote:
> > On Wednesday 21 March 2018 11:43:31 Robert Munteanu wrote:
> > > +#define USB_VENDOR_ID_MICRODIA  0x0c45
> > > +#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
> > 
> > Microdia is most probably an incorrect name. The 0c45 id probably
> > belongs 
> > to "Sonix Technology Co., Ltd."
> 
> Right, I was unsure about that. I'll remove the microdia references
> and
> use sonix.

I see the following in hid-ids.h

  define USB_VENDOR_ID_JESS0x0c45

which I guess I should use since it's already defined in there.

Robert


Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-22 Thread Robert Munteanu
On Thu, 2018-03-22 at 09:33 +0100, Benjamin Tissoires wrote:
> On Wed, Mar 21, 2018 at 5:33 PM, Robert Munteanu <romb...@apache.org>
> wrote:
> > Hi Benjamin,
> > 
> > On Wed, 2018-03-21 at 17:12 +0100, Benjamin Tissoires wrote:
> > > Hi Robert,
> > > 
> > > First, apologies for not answering to the RFC. I missed it and it
> > > fell
> > > down in my INBOX.
> > > 
> > > On Wed, Mar 21, 2018 at 11:43 AM, Robert Munteanu <rombert@apache
> > > .org
> > > > wrote:
> > > > The microdia family of keyboards uses a non-standard way of
> > > > sending
> > > > modifier keys.
> > > > 
> > > > The down event always sets the first bit to 0x04 and the second
> > > > keycode
> > > 
> > > Pretty sure you are talking about bytes here, not bits.
> > > And in the HID world, the first byte is usually a report ID.
> > 
> > Right, thanks for spotting that.
> > 
> > > 
> > > > to a custom value For instance, left shift sends the following
> > > > bits
> > > > 
> > > >   04 02 00 00 00 00 00 00
> > > > 
> > > > while left control sends
> > > > 
> > > >   04 01 00 00 00 00 00 00
> > > 
> > > This sounds like bit(0) is mapped to LEFT_SHIFT and bit(1) mapped
> > > to
> > > LEFT_CONTROL in the second byte.
> > > Fortunately, LeftControl is designed in HID as 0xe0 in the
> > > keyboard
> > > HID usage table, and LeftShift is 0xe1. So that would match the
> > > behavior you are seeing.
> > > If you have 04 04 00 00 00 00 00 00 when pressing LeftAlt, then
> > > definitively you are just facing a bitmask, which is fairly
> > > common.
> > > 
> > > > 
> > > > As a result all modifier keys are mapped to left shift and the
> > > > keyboard is
> > > > non-functional in that respect. To solve the problem, we
> > > > capture
> > > > the
> > > > raw data in raw_event and manually generate the correct input
> > > > events.
> > > 
> > > I'd like to see the hid-recorder events from these keypresses.
> > > The
> > > device might be buggy, but I have a gut feeling your solution is
> > > not
> > > the simplest one.
> > > Please grab hid-recorder from http://bentiss.github.io/hid-replay
> > > -
> > > docs/
> > 
> > See below, I recorded the output for pressing left ctrl, left alt,
> > left
> > shift, right ctrl, right alt, right shift, meta.
> > 
> > D: 0
> > R: 169 05 0c 09 01 a1 01 85 01 19 00 2a 80 03 15 00 26 80 03 95 01
> > 75
> > 10 81 00 c0 05 01 09 80 a1 01 85 02 19 81 29 83 15 00 25 01 75 01
> > 95 03
> > 81 02 95 05 81 01 c0 06 00 ff 09 01 a1 01 85 03 1a f1 00 2a f8 00
> > 15 00
> > 25 01 75 01 95 08 81 02 c0 05 01 09 06 a1 01 85 04 05 07 19 e0 29
> > e7 15
> > 00 25 01 75 01 95 08 81 00 95 30 75 01 15 00 25 01 05 07 19 00 29
> > 2f 81
> > 02 c0 05 01 09 06 a1 01 85 05 95 38 75 01 15 00 25 01 05 07 19 30
> > 29 67
> > 81 02 c0 05 01 09 06 a1 01 85 06 95 38 75 01 15 00 25 01 05 07 19
> > 68 29
> > 9f 81 02 c0
> > N: USB Keyboard
> > P: usb-:00:14.0-6/input1
> > I: 3 0c45 760b
> > D: 0
> > E: 0.00 8 04 01 00 00 00 00 00 00
> > E: 0.039920 8 04 00 00 00 00 00 00 00
> > E: 0.751952 8 04 04 00 00 00 00 00 00
> > E: 0.823977 8 04 00 00 00 00 00 00 00
> > E: 2.639887 8 04 02 00 00 00 00 00 00
> > E: 2.711896 8 04 00 00 00 00 00 00 00
> > E: 3.583932 8 04 10 00 00 00 00 00 00
> > E: 3.663919 8 04 00 00 00 00 00 00 00
> > E: 4.871886 8 04 40 00 00 00 00 00 00
> > E: 4.935906 8 04 00 00 00 00 00 00 00
> > E: 6.503872 8 04 20 00 00 00 00 00 00
> > E: 6.575850 8 04 00 00 00 00 00 00 00
> > E: 7.383844 8 04 08 00 00 00 00 00 00
> > E: 7.455861 8 04 00 00 00 00 00 00 00
> 
> Thanks. So it's indeed an issue with the report descriptor. Not sure
> how this can also work under Windows.
> FYI, the Report ID 4 translates to:
> 
> 0x05, 0x01,// Usage Page (Generic
> Desktop)78
> 0x09, 0x06,// Usage
> (Keyboard)80
> 0xa1, 0x01,// Collection
> (Application)82
> 0x85, 0x04,//  Report ID
> (4)  84
> 0x05, 0x07,//  Usage Page
> (Keyboard)  86
> 0x19, 0xe0,// 

Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-22 Thread Robert Munteanu
On Thu, 2018-03-22 at 09:33 +0100, Benjamin Tissoires wrote:
> On Wed, Mar 21, 2018 at 5:33 PM, Robert Munteanu 
> wrote:
> > Hi Benjamin,
> > 
> > On Wed, 2018-03-21 at 17:12 +0100, Benjamin Tissoires wrote:
> > > Hi Robert,
> > > 
> > > First, apologies for not answering to the RFC. I missed it and it
> > > fell
> > > down in my INBOX.
> > > 
> > > On Wed, Mar 21, 2018 at 11:43 AM, Robert Munteanu  > > .org
> > > > wrote:
> > > > The microdia family of keyboards uses a non-standard way of
> > > > sending
> > > > modifier keys.
> > > > 
> > > > The down event always sets the first bit to 0x04 and the second
> > > > keycode
> > > 
> > > Pretty sure you are talking about bytes here, not bits.
> > > And in the HID world, the first byte is usually a report ID.
> > 
> > Right, thanks for spotting that.
> > 
> > > 
> > > > to a custom value For instance, left shift sends the following
> > > > bits
> > > > 
> > > >   04 02 00 00 00 00 00 00
> > > > 
> > > > while left control sends
> > > > 
> > > >   04 01 00 00 00 00 00 00
> > > 
> > > This sounds like bit(0) is mapped to LEFT_SHIFT and bit(1) mapped
> > > to
> > > LEFT_CONTROL in the second byte.
> > > Fortunately, LeftControl is designed in HID as 0xe0 in the
> > > keyboard
> > > HID usage table, and LeftShift is 0xe1. So that would match the
> > > behavior you are seeing.
> > > If you have 04 04 00 00 00 00 00 00 when pressing LeftAlt, then
> > > definitively you are just facing a bitmask, which is fairly
> > > common.
> > > 
> > > > 
> > > > As a result all modifier keys are mapped to left shift and the
> > > > keyboard is
> > > > non-functional in that respect. To solve the problem, we
> > > > capture
> > > > the
> > > > raw data in raw_event and manually generate the correct input
> > > > events.
> > > 
> > > I'd like to see the hid-recorder events from these keypresses.
> > > The
> > > device might be buggy, but I have a gut feeling your solution is
> > > not
> > > the simplest one.
> > > Please grab hid-recorder from http://bentiss.github.io/hid-replay
> > > -
> > > docs/
> > 
> > See below, I recorded the output for pressing left ctrl, left alt,
> > left
> > shift, right ctrl, right alt, right shift, meta.
> > 
> > D: 0
> > R: 169 05 0c 09 01 a1 01 85 01 19 00 2a 80 03 15 00 26 80 03 95 01
> > 75
> > 10 81 00 c0 05 01 09 80 a1 01 85 02 19 81 29 83 15 00 25 01 75 01
> > 95 03
> > 81 02 95 05 81 01 c0 06 00 ff 09 01 a1 01 85 03 1a f1 00 2a f8 00
> > 15 00
> > 25 01 75 01 95 08 81 02 c0 05 01 09 06 a1 01 85 04 05 07 19 e0 29
> > e7 15
> > 00 25 01 75 01 95 08 81 00 95 30 75 01 15 00 25 01 05 07 19 00 29
> > 2f 81
> > 02 c0 05 01 09 06 a1 01 85 05 95 38 75 01 15 00 25 01 05 07 19 30
> > 29 67
> > 81 02 c0 05 01 09 06 a1 01 85 06 95 38 75 01 15 00 25 01 05 07 19
> > 68 29
> > 9f 81 02 c0
> > N: USB Keyboard
> > P: usb-:00:14.0-6/input1
> > I: 3 0c45 760b
> > D: 0
> > E: 0.00 8 04 01 00 00 00 00 00 00
> > E: 0.039920 8 04 00 00 00 00 00 00 00
> > E: 0.751952 8 04 04 00 00 00 00 00 00
> > E: 0.823977 8 04 00 00 00 00 00 00 00
> > E: 2.639887 8 04 02 00 00 00 00 00 00
> > E: 2.711896 8 04 00 00 00 00 00 00 00
> > E: 3.583932 8 04 10 00 00 00 00 00 00
> > E: 3.663919 8 04 00 00 00 00 00 00 00
> > E: 4.871886 8 04 40 00 00 00 00 00 00
> > E: 4.935906 8 04 00 00 00 00 00 00 00
> > E: 6.503872 8 04 20 00 00 00 00 00 00
> > E: 6.575850 8 04 00 00 00 00 00 00 00
> > E: 7.383844 8 04 08 00 00 00 00 00 00
> > E: 7.455861 8 04 00 00 00 00 00 00 00
> 
> Thanks. So it's indeed an issue with the report descriptor. Not sure
> how this can also work under Windows.
> FYI, the Report ID 4 translates to:
> 
> 0x05, 0x01,// Usage Page (Generic
> Desktop)78
> 0x09, 0x06,// Usage
> (Keyboard)80
> 0xa1, 0x01,// Collection
> (Application)82
> 0x85, 0x04,//  Report ID
> (4)  84
> 0x05, 0x07,//  Usage Page
> (Keyboard)  86
> 0x19, 0xe0,//  Usage Minimum
> (224)88
> 0x29, 

Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-22 Thread Robert Munteanu
On Wed, 2018-03-21 at 17:51 +0100, Ondrej Zary wrote:
> On Wednesday 21 March 2018 11:43:31 Robert Munteanu wrote:
> > +#define USB_VENDOR_ID_MICRODIA  0x0c45
> > +#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
> 
> Microdia is most probably an incorrect name. The 0c45 id probably
> belongs 
> to "Sonix Technology Co., Ltd."

Right, I was unsure about that. I'll remove the microdia references and
use sonix.

Robert


Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-22 Thread Robert Munteanu
On Wed, 2018-03-21 at 17:51 +0100, Ondrej Zary wrote:
> On Wednesday 21 March 2018 11:43:31 Robert Munteanu wrote:
> > +#define USB_VENDOR_ID_MICRODIA  0x0c45
> > +#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
> 
> Microdia is most probably an incorrect name. The 0c45 id probably
> belongs 
> to "Sonix Technology Co., Ltd."

Right, I was unsure about that. I'll remove the microdia references and
use sonix.

Robert


Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-21 Thread Robert Munteanu
Hi Benjamin,

On Wed, 2018-03-21 at 17:12 +0100, Benjamin Tissoires wrote:
> Hi Robert,
> 
> First, apologies for not answering to the RFC. I missed it and it
> fell
> down in my INBOX.
> 
> On Wed, Mar 21, 2018 at 11:43 AM, Robert Munteanu <romb...@apache.org
> > wrote:
> > The microdia family of keyboards uses a non-standard way of sending
> > modifier keys.
> > 
> > The down event always sets the first bit to 0x04 and the second
> > keycode
> 
> Pretty sure you are talking about bytes here, not bits.
> And in the HID world, the first byte is usually a report ID.

Right, thanks for spotting that.

> 
> > to a custom value For instance, left shift sends the following bits
> > 
> >   04 02 00 00 00 00 00 00
> > 
> > while left control sends
> > 
> >   04 01 00 00 00 00 00 00
> 
> This sounds like bit(0) is mapped to LEFT_SHIFT and bit(1) mapped to
> LEFT_CONTROL in the second byte.
> Fortunately, LeftControl is designed in HID as 0xe0 in the keyboard
> HID usage table, and LeftShift is 0xe1. So that would match the
> behavior you are seeing.
> If you have 04 04 00 00 00 00 00 00 when pressing LeftAlt, then
> definitively you are just facing a bitmask, which is fairly common.
> 
> > 
> > As a result all modifier keys are mapped to left shift and the
> > keyboard is
> > non-functional in that respect. To solve the problem, we capture
> > the
> > raw data in raw_event and manually generate the correct input
> > events.
> 
> I'd like to see the hid-recorder events from these keypresses. The
> device might be buggy, but I have a gut feeling your solution is not
> the simplest one.
> Please grab hid-recorder from http://bentiss.github.io/hid-replay-
> docs/

See below, I recorded the output for pressing left ctrl, left alt, left
shift, right ctrl, right alt, right shift, meta.

D: 0
R: 169 05 0c 09 01 a1 01 85 01 19 00 2a 80 03 15 00 26 80 03 95 01 75
10 81 00 c0 05 01 09 80 a1 01 85 02 19 81 29 83 15 00 25 01 75 01 95 03
81 02 95 05 81 01 c0 06 00 ff 09 01 a1 01 85 03 1a f1 00 2a f8 00 15 00
25 01 75 01 95 08 81 02 c0 05 01 09 06 a1 01 85 04 05 07 19 e0 29 e7 15
00 25 01 75 01 95 08 81 00 95 30 75 01 15 00 25 01 05 07 19 00 29 2f 81
02 c0 05 01 09 06 a1 01 85 05 95 38 75 01 15 00 25 01 05 07 19 30 29 67
81 02 c0 05 01 09 06 a1 01 85 06 95 38 75 01 15 00 25 01 05 07 19 68 29
9f 81 02 c0
N: USB Keyboard
P: usb-:00:14.0-6/input1
I: 3 0c45 760b
D: 0
E: 0.00 8 04 01 00 00 00 00 00 00
E: 0.039920 8 04 00 00 00 00 00 00 00
E: 0.751952 8 04 04 00 00 00 00 00 00
E: 0.823977 8 04 00 00 00 00 00 00 00
E: 2.639887 8 04 02 00 00 00 00 00 00
E: 2.711896 8 04 00 00 00 00 00 00 00
E: 3.583932 8 04 10 00 00 00 00 00 00
E: 3.663919 8 04 00 00 00 00 00 00 00
E: 4.871886 8 04 40 00 00 00 00 00 00
E: 4.935906 8 04 00 00 00 00 00 00 00
E: 6.503872 8 04 20 00 00 00 00 00 00
E: 6.575850 8 04 00 00 00 00 00 00 00
E: 7.383844 8 04 08 00 00 00 00 00 00
E: 7.455861 8 04 00 00 00 00 00 00 00

> 
> > 
> > The keyboard functions mostly as expected now, with only a few
> > minor
> > issues:
> > 
> > - two USB devices are detected instead of 1
> 
> Well, that should be easy enough to solve

I think so, but I could not find a way how to do that.

> 
> > - some key combinations are not triggered - e.g.
> >   left shift + left ctrl + p. However, the same combination is
> > recognized
> >   with the right shift key.
> 
> Could you add this combination in the hid-recorder output too?

This is what Left Ctrl + Shift + U produces:

E: 24.575686 8 04 01 00 00 00 00 00 00
E: 24.951689 8 04 03 00 00 00 00 00 00
E: 26.719615 8 04 01 00 00 00 00 00 00
E: 26.727611 8 04 00 00 00 00 00 00 00

On the other hand, Right Ctrl + Shift + U produces:

E: 55.911268 8 04 10 00 00 00 00 00 00
E: 56.119280 8 04 30 00 00 00 00 00 00
E: 56.599319 8 04 30 00 00 00 01 00 00
E: 56.703282 8 04 30 00 00 00 00 00 00
E: 56.815278 8 04 20 00 00 00 00 00 00
E: 56.823255 8 04 00 00 00 00 00 00 00

It looks suspicious that the keypress is not registered. Do I need to
boot a kernel without my patch applied?

> more comments inlined:
> 
> > 
> > Changelog:
> > 
> > - v2: modifier keys work, some combinations are still troublesome
> > - v3: style cleanup, rebase on top of 4.14
> > - v4: remove most debugging calls, make init info useful for user,
> >   rebased on top of 4.15
> > 
> > Signed-off-by: Robert Munteanu <romb...@apache.org>
> > ---
> >  drivers/hid/Kconfig|   9 +++
> >  drivers/hid/Makefile   |   2 +-
> >  drivers/hid/hid-core.c |   3 +
> >  drivers/hid/hid-ids.h  |   3 +
> >  drivers/hid/hid-microdia.c | 148
> > +

Re: [PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-21 Thread Robert Munteanu
Hi Benjamin,

On Wed, 2018-03-21 at 17:12 +0100, Benjamin Tissoires wrote:
> Hi Robert,
> 
> First, apologies for not answering to the RFC. I missed it and it
> fell
> down in my INBOX.
> 
> On Wed, Mar 21, 2018 at 11:43 AM, Robert Munteanu  > wrote:
> > The microdia family of keyboards uses a non-standard way of sending
> > modifier keys.
> > 
> > The down event always sets the first bit to 0x04 and the second
> > keycode
> 
> Pretty sure you are talking about bytes here, not bits.
> And in the HID world, the first byte is usually a report ID.

Right, thanks for spotting that.

> 
> > to a custom value For instance, left shift sends the following bits
> > 
> >   04 02 00 00 00 00 00 00
> > 
> > while left control sends
> > 
> >   04 01 00 00 00 00 00 00
> 
> This sounds like bit(0) is mapped to LEFT_SHIFT and bit(1) mapped to
> LEFT_CONTROL in the second byte.
> Fortunately, LeftControl is designed in HID as 0xe0 in the keyboard
> HID usage table, and LeftShift is 0xe1. So that would match the
> behavior you are seeing.
> If you have 04 04 00 00 00 00 00 00 when pressing LeftAlt, then
> definitively you are just facing a bitmask, which is fairly common.
> 
> > 
> > As a result all modifier keys are mapped to left shift and the
> > keyboard is
> > non-functional in that respect. To solve the problem, we capture
> > the
> > raw data in raw_event and manually generate the correct input
> > events.
> 
> I'd like to see the hid-recorder events from these keypresses. The
> device might be buggy, but I have a gut feeling your solution is not
> the simplest one.
> Please grab hid-recorder from http://bentiss.github.io/hid-replay-
> docs/

See below, I recorded the output for pressing left ctrl, left alt, left
shift, right ctrl, right alt, right shift, meta.

D: 0
R: 169 05 0c 09 01 a1 01 85 01 19 00 2a 80 03 15 00 26 80 03 95 01 75
10 81 00 c0 05 01 09 80 a1 01 85 02 19 81 29 83 15 00 25 01 75 01 95 03
81 02 95 05 81 01 c0 06 00 ff 09 01 a1 01 85 03 1a f1 00 2a f8 00 15 00
25 01 75 01 95 08 81 02 c0 05 01 09 06 a1 01 85 04 05 07 19 e0 29 e7 15
00 25 01 75 01 95 08 81 00 95 30 75 01 15 00 25 01 05 07 19 00 29 2f 81
02 c0 05 01 09 06 a1 01 85 05 95 38 75 01 15 00 25 01 05 07 19 30 29 67
81 02 c0 05 01 09 06 a1 01 85 06 95 38 75 01 15 00 25 01 05 07 19 68 29
9f 81 02 c0
N: USB Keyboard
P: usb-:00:14.0-6/input1
I: 3 0c45 760b
D: 0
E: 0.00 8 04 01 00 00 00 00 00 00
E: 0.039920 8 04 00 00 00 00 00 00 00
E: 0.751952 8 04 04 00 00 00 00 00 00
E: 0.823977 8 04 00 00 00 00 00 00 00
E: 2.639887 8 04 02 00 00 00 00 00 00
E: 2.711896 8 04 00 00 00 00 00 00 00
E: 3.583932 8 04 10 00 00 00 00 00 00
E: 3.663919 8 04 00 00 00 00 00 00 00
E: 4.871886 8 04 40 00 00 00 00 00 00
E: 4.935906 8 04 00 00 00 00 00 00 00
E: 6.503872 8 04 20 00 00 00 00 00 00
E: 6.575850 8 04 00 00 00 00 00 00 00
E: 7.383844 8 04 08 00 00 00 00 00 00
E: 7.455861 8 04 00 00 00 00 00 00 00

> 
> > 
> > The keyboard functions mostly as expected now, with only a few
> > minor
> > issues:
> > 
> > - two USB devices are detected instead of 1
> 
> Well, that should be easy enough to solve

I think so, but I could not find a way how to do that.

> 
> > - some key combinations are not triggered - e.g.
> >   left shift + left ctrl + p. However, the same combination is
> > recognized
> >   with the right shift key.
> 
> Could you add this combination in the hid-recorder output too?

This is what Left Ctrl + Shift + U produces:

E: 24.575686 8 04 01 00 00 00 00 00 00
E: 24.951689 8 04 03 00 00 00 00 00 00
E: 26.719615 8 04 01 00 00 00 00 00 00
E: 26.727611 8 04 00 00 00 00 00 00 00

On the other hand, Right Ctrl + Shift + U produces:

E: 55.911268 8 04 10 00 00 00 00 00 00
E: 56.119280 8 04 30 00 00 00 00 00 00
E: 56.599319 8 04 30 00 00 00 01 00 00
E: 56.703282 8 04 30 00 00 00 00 00 00
E: 56.815278 8 04 20 00 00 00 00 00 00
E: 56.823255 8 04 00 00 00 00 00 00 00

It looks suspicious that the keypress is not registered. Do I need to
boot a kernel without my patch applied?

> more comments inlined:
> 
> > 
> > Changelog:
> > 
> > - v2: modifier keys work, some combinations are still troublesome
> > - v3: style cleanup, rebase on top of 4.14
> > - v4: remove most debugging calls, make init info useful for user,
> >   rebased on top of 4.15
> > 
> > Signed-off-by: Robert Munteanu 
> > ---
> >  drivers/hid/Kconfig|   9 +++
> >  drivers/hid/Makefile   |   2 +-
> >  drivers/hid/hid-core.c |   3 +
> >  drivers/hid/hid-ids.h  |   3 +
> >  drivers/hid/hid-microdia.c | 148
> > +
> >  5 files changed, 164 insertions(+), 1 deleti

[PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-21 Thread Robert Munteanu
The microdia family of keyboards uses a non-standard way of sending
modifier keys.

The down event always sets the first bit to 0x04 and the second keycode
to a custom value For instance, left shift sends the following bits

  04 02 00 00 00 00 00 00

while left control sends

  04 01 00 00 00 00 00 00

As a result all modifier keys are mapped to left shift and the keyboard is
non-functional in that respect. To solve the problem, we capture the
raw data in raw_event and manually generate the correct input events.

The keyboard functions mostly as expected now, with only a few minor
issues:

- two USB devices are detected instead of 1
- some key combinations are not triggered - e.g.
  left shift + left ctrl + p. However, the same combination is recognized
  with the right shift key.

Changelog:

- v2: modifier keys work, some combinations are still troublesome
- v3: style cleanup, rebase on top of 4.14
- v4: remove most debugging calls, make init info useful for user,
  rebased on top of 4.15

Signed-off-by: Robert Munteanu <romb...@apache.org>
---
 drivers/hid/Kconfig|   9 +++
 drivers/hid/Makefile   |   2 +-
 drivers/hid/hid-core.c |   3 +
 drivers/hid/hid-ids.h  |   3 +
 drivers/hid/hid-microdia.c | 148 +
 5 files changed, 164 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hid/hid-microdia.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 779c5ae47f36..c3350f2ec4ea 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -548,6 +548,15 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_MICRODIA
+   tristate "Microdia based keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Microdia devices that are not compliant with the HID standard.
+
+One known example if the Redragon Asura Keyboard.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 235bd2a7b333..e66a305876c5 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o
 obj-$(CONFIG_HID_LOGITECH_HIDPP)   += hid-logitech-hidpp.o
 obj-$(CONFIG_HID_MAGICMOUSE)   += hid-magicmouse.o
 obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o
+obj-$(CONFIG_HID_MICRODIA)  += hid-microdia.o
 obj-$(CONFIG_HID_MICROSOFT)+= hid-microsoft.o
 obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
 obj-$(CONFIG_HID_MULTITOUCH)   += hid-multitouch.o
@@ -121,4 +122,3 @@ obj-$(CONFIG_USB_KBD)   += usbhid/
 
 obj-$(CONFIG_I2C_HID)  += i2c-hid/
 
-obj-$(CONFIG_INTEL_ISH_HID)+= intel-ish-hid/
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 0c3f608131cf..b36c2df4b755 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2393,6 +2393,9 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
 #endif
 #if IS_ENABLED(CONFIG_HID_ZYDACRON)
{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, 
USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
+#endif
+#if IS_ENABLED(CONFIG_HID_MICRODIA)
+   { HID_USB_DEVICE(USB_VENDOR_ID_MICRODIA,  USB_DEVICE_ID_REDRAGON_ASURA) 
},
 #endif
{ }
 };
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5da3d6256d25..146869e55c5a 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -1171,4 +1171,7 @@
 #define USB_VENDOR_ID_UGTIZER  0x2179
 #define USB_DEVICE_ID_UGTIZER_TABLET_GP06100x0053
 
+#define USB_VENDOR_ID_MICRODIA  0x0c45
+#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
+
 #endif
diff --git a/drivers/hid/hid-microdia.c b/drivers/hid/hid-microdia.c
new file mode 100644
index ..f9d8de18a989
--- /dev/null
+++ b/drivers/hid/hid-microdia.c
@@ -0,0 +1,148 @@
+/*
+ *  HID driver for Microdia-based keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+// The microdia family of keyboards uses a non-standard way of sending
+// modifier keys
+//
+// The down event always sets the first bit to 0x04 and the second keycode
+// to a custom value. For instance, left shift sends the following bits
+//
+//   04 02 00 00 00 00 00 00
+//
+// while left control sends
+//
+//   04 01 00 00 00 00 00 00
+//
+// Unfortunately these are all mapped to left shift and the keyboard is
+// non-functional in that respect. To solve the problem, we capture the
+// raw data in raw_event and manually generate the correct

[PATCH v3] Fix modifier keys for Redragon Asura Keyboard

2018-03-21 Thread Robert Munteanu
The microdia family of keyboards uses a non-standard way of sending
modifier keys.

The down event always sets the first bit to 0x04 and the second keycode
to a custom value For instance, left shift sends the following bits

  04 02 00 00 00 00 00 00

while left control sends

  04 01 00 00 00 00 00 00

As a result all modifier keys are mapped to left shift and the keyboard is
non-functional in that respect. To solve the problem, we capture the
raw data in raw_event and manually generate the correct input events.

The keyboard functions mostly as expected now, with only a few minor
issues:

- two USB devices are detected instead of 1
- some key combinations are not triggered - e.g.
  left shift + left ctrl + p. However, the same combination is recognized
  with the right shift key.

Changelog:

- v2: modifier keys work, some combinations are still troublesome
- v3: style cleanup, rebase on top of 4.14
- v4: remove most debugging calls, make init info useful for user,
  rebased on top of 4.15

Signed-off-by: Robert Munteanu 
---
 drivers/hid/Kconfig|   9 +++
 drivers/hid/Makefile   |   2 +-
 drivers/hid/hid-core.c |   3 +
 drivers/hid/hid-ids.h  |   3 +
 drivers/hid/hid-microdia.c | 148 +
 5 files changed, 164 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hid/hid-microdia.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 779c5ae47f36..c3350f2ec4ea 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -548,6 +548,15 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_MICRODIA
+   tristate "Microdia based keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Microdia devices that are not compliant with the HID standard.
+
+One known example if the Redragon Asura Keyboard.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 235bd2a7b333..e66a305876c5 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o
 obj-$(CONFIG_HID_LOGITECH_HIDPP)   += hid-logitech-hidpp.o
 obj-$(CONFIG_HID_MAGICMOUSE)   += hid-magicmouse.o
 obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o
+obj-$(CONFIG_HID_MICRODIA)  += hid-microdia.o
 obj-$(CONFIG_HID_MICROSOFT)+= hid-microsoft.o
 obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
 obj-$(CONFIG_HID_MULTITOUCH)   += hid-multitouch.o
@@ -121,4 +122,3 @@ obj-$(CONFIG_USB_KBD)   += usbhid/
 
 obj-$(CONFIG_I2C_HID)  += i2c-hid/
 
-obj-$(CONFIG_INTEL_ISH_HID)+= intel-ish-hid/
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 0c3f608131cf..b36c2df4b755 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2393,6 +2393,9 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
 #endif
 #if IS_ENABLED(CONFIG_HID_ZYDACRON)
{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, 
USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
+#endif
+#if IS_ENABLED(CONFIG_HID_MICRODIA)
+   { HID_USB_DEVICE(USB_VENDOR_ID_MICRODIA,  USB_DEVICE_ID_REDRAGON_ASURA) 
},
 #endif
{ }
 };
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5da3d6256d25..146869e55c5a 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -1171,4 +1171,7 @@
 #define USB_VENDOR_ID_UGTIZER  0x2179
 #define USB_DEVICE_ID_UGTIZER_TABLET_GP06100x0053
 
+#define USB_VENDOR_ID_MICRODIA  0x0c45
+#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
+
 #endif
diff --git a/drivers/hid/hid-microdia.c b/drivers/hid/hid-microdia.c
new file mode 100644
index ..f9d8de18a989
--- /dev/null
+++ b/drivers/hid/hid-microdia.c
@@ -0,0 +1,148 @@
+/*
+ *  HID driver for Microdia-based keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+// The microdia family of keyboards uses a non-standard way of sending
+// modifier keys
+//
+// The down event always sets the first bit to 0x04 and the second keycode
+// to a custom value. For instance, left shift sends the following bits
+//
+//   04 02 00 00 00 00 00 00
+//
+// while left control sends
+//
+//   04 01 00 00 00 00 00 00
+//
+// Unfortunately these are all mapped to left shift and the keyboard is
+// non-functional in that respect. To solve the problem, we capture the
+// raw data in raw_event and manually generate the correct input events
+//
+// TODO

[RFC PATCH] Fix modifier keys for Redragon Asura Keyboard

2018-01-10 Thread Robert Munteanu
The microdia family of keyboards uses a non-standard way of sending
modifier keys.

The down event always sets the first bit to 0x04 and the second keycode
to a custom value For instance, left shift sends the following bits

  04 02 00 00 00 00 00 00

while left control sends

  04 01 00 00 00 00 00 00

As a result all modifier keys are mapped to left shift and the keyboard is
non-functional in that respect. To solve the problem, we capture the
raw data in raw_event and manually generate the correct input events.

The keyboard functions mostly as expected now, with only a few minor
issues:

- two USB devices are detected instead of 1
- some key combinations are not triggered - e.g.
  left shift + left ctrl + p. However, the same combination is recognized
  with the right shift key.

Tested on Kernel 4.14.12

Changelog:

- v2: modifier keys work, some combinations are still troublesome
- v3: style cleanup, rebase on top of 4.14

Signed-off-by: Robert Munteanu <romb...@apache.org>
---
 drivers/hid/Kconfig|   9 +++
 drivers/hid/Makefile   |   2 +-
 drivers/hid/hid-core.c |   3 +
 drivers/hid/hid-ids.h  |   3 +
 drivers/hid/hid-microdia.c | 178 +
 5 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hid/hid-microdia.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 374301fcbc86..0033a81f0ad4 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -548,6 +548,15 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_MICRODIA
+   tristate "Microdia based keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Microdia devices that are not compliant with the HID standard.
+
+One known example if the Redragon Asura Keyboard.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 235bd2a7b333..e66a305876c5 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o
 obj-$(CONFIG_HID_LOGITECH_HIDPP)   += hid-logitech-hidpp.o
 obj-$(CONFIG_HID_MAGICMOUSE)   += hid-magicmouse.o
 obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o
+obj-$(CONFIG_HID_MICRODIA)  += hid-microdia.o
 obj-$(CONFIG_HID_MICROSOFT)+= hid-microsoft.o
 obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
 obj-$(CONFIG_HID_MULTITOUCH)   += hid-multitouch.o
@@ -121,4 +122,3 @@ obj-$(CONFIG_USB_KBD)   += usbhid/
 
 obj-$(CONFIG_I2C_HID)  += i2c-hid/
 
-obj-$(CONFIG_INTEL_ISH_HID)+= intel-ish-hid/
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 330ca983828b..eeb325e3ff0d 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2388,6 +2388,9 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
 #endif
 #if IS_ENABLED(CONFIG_HID_ZYDACRON)
{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, 
USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
+#endif
+#if IS_ENABLED(CONFIG_HID_MICRODIA)
+   { HID_USB_DEVICE(USB_VENDOR_ID_MICRODIA,  USB_DEVICE_ID_REDRAGON_ASURA) 
},
 #endif
{ }
 };
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index be2e005c3c51..2edbf01361f1 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -1161,4 +1161,7 @@
 #define USB_VENDOR_ID_UGTIZER  0x2179
 #define USB_DEVICE_ID_UGTIZER_TABLET_GP06100x0053
 
+#define USB_VENDOR_ID_MICRODIA  0x0c45
+#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
+
 #endif
diff --git a/drivers/hid/hid-microdia.c b/drivers/hid/hid-microdia.c
new file mode 100644
index ..a6119786859d
--- /dev/null
+++ b/drivers/hid/hid-microdia.c
@@ -0,0 +1,178 @@
+/*
+ *  HID driver for Microdia-based keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+// The microdia family of keyboards uses a non-standard way of sending
+// modifier keys
+//
+// The down event always sets the first bit to 0x04 and the second keycode
+// to a custom value. For instance, left shift sends the following bits
+//
+//   04 02 00 00 00 00 00 00
+//
+// while left control sends
+//
+//   04 01 00 00 00 00 00 00
+//
+// Unfortunately these are all mapped to left shift and the keyboard is
+// non-functional in that respect. To solve the problem, we capture the
+// raw data in raw_event and manually generate the correct input events
+//
+// TODO
+//
+// 1. Some modifiers keys

[RFC PATCH] Fix modifier keys for Redragon Asura Keyboard

2018-01-10 Thread Robert Munteanu
The microdia family of keyboards uses a non-standard way of sending
modifier keys.

The down event always sets the first bit to 0x04 and the second keycode
to a custom value For instance, left shift sends the following bits

  04 02 00 00 00 00 00 00

while left control sends

  04 01 00 00 00 00 00 00

As a result all modifier keys are mapped to left shift and the keyboard is
non-functional in that respect. To solve the problem, we capture the
raw data in raw_event and manually generate the correct input events.

The keyboard functions mostly as expected now, with only a few minor
issues:

- two USB devices are detected instead of 1
- some key combinations are not triggered - e.g.
  left shift + left ctrl + p. However, the same combination is recognized
  with the right shift key.

Tested on Kernel 4.14.12

Changelog:

- v2: modifier keys work, some combinations are still troublesome
- v3: style cleanup, rebase on top of 4.14

Signed-off-by: Robert Munteanu 
---
 drivers/hid/Kconfig|   9 +++
 drivers/hid/Makefile   |   2 +-
 drivers/hid/hid-core.c |   3 +
 drivers/hid/hid-ids.h  |   3 +
 drivers/hid/hid-microdia.c | 178 +
 5 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hid/hid-microdia.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 374301fcbc86..0033a81f0ad4 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -548,6 +548,15 @@ config HID_MAYFLASH
Say Y here if you have HJZ Mayflash PS3 game controller adapters
and want to enable force feedback support.
 
+config HID_MICRODIA
+   tristate "Microdia based keyboards"
+   depends on HID
+   default !EXPERT
+   ---help---
+Support for Microdia devices that are not compliant with the HID standard.
+
+One known example if the Redragon Asura Keyboard.
+
 config HID_MICROSOFT
tristate "Microsoft non-fully HID-compliant devices"
depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 235bd2a7b333..e66a305876c5 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o
 obj-$(CONFIG_HID_LOGITECH_HIDPP)   += hid-logitech-hidpp.o
 obj-$(CONFIG_HID_MAGICMOUSE)   += hid-magicmouse.o
 obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o
+obj-$(CONFIG_HID_MICRODIA)  += hid-microdia.o
 obj-$(CONFIG_HID_MICROSOFT)+= hid-microsoft.o
 obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
 obj-$(CONFIG_HID_MULTITOUCH)   += hid-multitouch.o
@@ -121,4 +122,3 @@ obj-$(CONFIG_USB_KBD)   += usbhid/
 
 obj-$(CONFIG_I2C_HID)  += i2c-hid/
 
-obj-$(CONFIG_INTEL_ISH_HID)+= intel-ish-hid/
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 330ca983828b..eeb325e3ff0d 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2388,6 +2388,9 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
 #endif
 #if IS_ENABLED(CONFIG_HID_ZYDACRON)
{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, 
USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
+#endif
+#if IS_ENABLED(CONFIG_HID_MICRODIA)
+   { HID_USB_DEVICE(USB_VENDOR_ID_MICRODIA,  USB_DEVICE_ID_REDRAGON_ASURA) 
},
 #endif
{ }
 };
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index be2e005c3c51..2edbf01361f1 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -1161,4 +1161,7 @@
 #define USB_VENDOR_ID_UGTIZER  0x2179
 #define USB_DEVICE_ID_UGTIZER_TABLET_GP06100x0053
 
+#define USB_VENDOR_ID_MICRODIA  0x0c45
+#define USB_DEVICE_ID_REDRAGON_ASURA0x760b
+
 #endif
diff --git a/drivers/hid/hid-microdia.c b/drivers/hid/hid-microdia.c
new file mode 100644
index ..a6119786859d
--- /dev/null
+++ b/drivers/hid/hid-microdia.c
@@ -0,0 +1,178 @@
+/*
+ *  HID driver for Microdia-based keyboards
+ *
+ *  Copyright (c) 2017 Robert Munteanu
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hid-ids.h"
+
+
+// The microdia family of keyboards uses a non-standard way of sending
+// modifier keys
+//
+// The down event always sets the first bit to 0x04 and the second keycode
+// to a custom value. For instance, left shift sends the following bits
+//
+//   04 02 00 00 00 00 00 00
+//
+// while left control sends
+//
+//   04 01 00 00 00 00 00 00
+//
+// Unfortunately these are all mapped to left shift and the keyboard is
+// non-functional in that respect. To solve the problem, we capture the
+// raw data in raw_event and manually generate the correct input events
+//
+// TODO
+//
+// 1. Some modifiers keys still don't work, e.g. Ctrl-Shift

Redragon Asura Keyboard - All Shift, Ctrl, Alt, Win keys function as left shift

2017-06-12 Thread Robert Munteanu
Hi,

I am trying to use the keyboard I mentioned. Most of the keys work
fine, except for Shift/Alt/Ctrl/Win. All of them are mapped a left
shift. Some notes:

1. dmesg output when plugging in the keyboard

[185765.848957] input: USB Keyboard as
/devices/pci:00/:00:14.0/usb1/1-3/1-3:1.0/0003:0C45:760B.0022/input/input50
[185765.905395] hid-generic 0003:0C45:760B.0022: input,hidraw3: USB
HID v1.11 Keyboard [USB Keyboard] on usb-:00:14.0-3/input0
[185765.949342] input: USB Keyboard as
/devices/pci:00/:00:14.0/usb1/1-3/1-3:1.1/0003:0C45:760B.0023/input/input51
[185766.009474] hid-generic 0003:0C45:760B.0023:
input,hiddev0,hidraw4: USB HID v1.11 Keyboard [USB Keyboard] on
usb-:00:14.0-3/input1

The first input device sends absolutely no input, the second one sends
all the input.

2. Tests done using evtest

With evtest, all the mentioned keys have the following output:

Event: time 1497272760.897616, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e1
Event: time 1497272760.897616, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1

3. Information from debugs

In sys/kernel/debug/hid I have two entries:

- 0003:0C45:760B.0037
- 0003:0C45:760B.0038

I've pasted the rdesc output at

- https://pastebin.com/4VwDKRvU
- https://pastebin.com/CrBVRFBj

4. Hexdump output

I've taken the hexdump output when pressing the affected keys. The
keypresses, in order, were:

- Left Shift
- Left Ctrl
- Win
- Left Alt
- Right Alt
- Right Ctrl
- Right Shift

  04 00 00 00 00 00 00 00  04 02 00 00 00 00 00 00  ||
0010  04 00 00 00 00 00 00 00  04 01 00 00 00 00 00 00  ||
0020  04 00 00 00 00 00 00 00  04 08 00 00 00 00 00 00  ||
0030  04 00 00 00 00 00 00 00  04 04 00 00 00 00 00 00  ||
0040  04 00 00 00 00 00 00 00  04 40 00 00 00 00 00 00  |.@..|
0050  04 00 00 00 00 00 00 00  04 10 00 00 00 00 00 00  ||
0060  04 00 00 00 00 00 00 00  04 20 00 00 00 00 00 00  |. ..|

If you need more information to qualify whether this is a bug or not,
let me know. I'd be glad to test any potential fixes.

I am running kernel 4.11.2 ( openSUSE Tumbleweed x86_64 ).

Thanks,

Robert

For reference, this was initiated as a question at
https://unix.stackexchange.com/questions/370612/redragon-asura-usb-keyboard-maps-all-ctrl-alt-win-keys-to-shift-l



-- 
http://robert.muntea.nu/


Redragon Asura Keyboard - All Shift, Ctrl, Alt, Win keys function as left shift

2017-06-12 Thread Robert Munteanu
Hi,

I am trying to use the keyboard I mentioned. Most of the keys work
fine, except for Shift/Alt/Ctrl/Win. All of them are mapped a left
shift. Some notes:

1. dmesg output when plugging in the keyboard

[185765.848957] input: USB Keyboard as
/devices/pci:00/:00:14.0/usb1/1-3/1-3:1.0/0003:0C45:760B.0022/input/input50
[185765.905395] hid-generic 0003:0C45:760B.0022: input,hidraw3: USB
HID v1.11 Keyboard [USB Keyboard] on usb-:00:14.0-3/input0
[185765.949342] input: USB Keyboard as
/devices/pci:00/:00:14.0/usb1/1-3/1-3:1.1/0003:0C45:760B.0023/input/input51
[185766.009474] hid-generic 0003:0C45:760B.0023:
input,hiddev0,hidraw4: USB HID v1.11 Keyboard [USB Keyboard] on
usb-:00:14.0-3/input1

The first input device sends absolutely no input, the second one sends
all the input.

2. Tests done using evtest

With evtest, all the mentioned keys have the following output:

Event: time 1497272760.897616, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e1
Event: time 1497272760.897616, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1

3. Information from debugs

In sys/kernel/debug/hid I have two entries:

- 0003:0C45:760B.0037
- 0003:0C45:760B.0038

I've pasted the rdesc output at

- https://pastebin.com/4VwDKRvU
- https://pastebin.com/CrBVRFBj

4. Hexdump output

I've taken the hexdump output when pressing the affected keys. The
keypresses, in order, were:

- Left Shift
- Left Ctrl
- Win
- Left Alt
- Right Alt
- Right Ctrl
- Right Shift

  04 00 00 00 00 00 00 00  04 02 00 00 00 00 00 00  ||
0010  04 00 00 00 00 00 00 00  04 01 00 00 00 00 00 00  ||
0020  04 00 00 00 00 00 00 00  04 08 00 00 00 00 00 00  ||
0030  04 00 00 00 00 00 00 00  04 04 00 00 00 00 00 00  ||
0040  04 00 00 00 00 00 00 00  04 40 00 00 00 00 00 00  |.@..|
0050  04 00 00 00 00 00 00 00  04 10 00 00 00 00 00 00  ||
0060  04 00 00 00 00 00 00 00  04 20 00 00 00 00 00 00  |. ..|

If you need more information to qualify whether this is a bug or not,
let me know. I'd be glad to test any potential fixes.

I am running kernel 4.11.2 ( openSUSE Tumbleweed x86_64 ).

Thanks,

Robert

For reference, this was initiated as a question at
https://unix.stackexchange.com/questions/370612/redragon-asura-usb-keyboard-maps-all-ctrl-alt-win-keys-to-shift-l



-- 
http://robert.muntea.nu/