linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hid: Add mapping for special keys on compaq ku 0133 keyboard
@ 2014-08-12 23:14 Hans de Goede
  2014-08-12 23:35 ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2014-08-12 23:14 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, Hans de Goede

The compaq ku 0133 keyboard has 8 special keys at the top:
http://lackof.org/taggart/hacking/keyboard/cpqwireless.jpg

3 of these use standard HID usage codes from the consumer page, the 5
others use part of the reserved 0x07 - 0x1f range.

This commit adds mapping for this keyboard for these reserved codes, making
the other 5 keys work.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/hid/Kconfig      |  8 ++++++
 drivers/hid/Makefile     |  1 +
 drivers/hid/hid-compaq.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-core.c   |  1 +
 drivers/hid/hid-ids.h    |  3 +++
 5 files changed, 81 insertions(+)
 create mode 100644 drivers/hid/hid-compaq.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 5e79c6a..fafd8d8 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -160,6 +160,14 @@ config HID_CHICONY
 	---help---
 	Support for Chicony Tactical pad.
 
+config HID_COMPAQ
+	tristate "Compaq non-fully HID-compliant devices" if EXPERT
+	depends on HID
+	default !EXPERT
+	---help---
+	Support for Compaq devices that are not fully compliant with
+	the HID standard.
+
 config HID_PRODIKEYS
 	tristate "Prodikeys PC-MIDI Keyboard support"
 	depends on HID && SND
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index a6fa6ba..560d2db 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_HID_AUREAL)        += hid-aureal.o
 obj-$(CONFIG_HID_BELKIN)	+= hid-belkin.o
 obj-$(CONFIG_HID_CHERRY)	+= hid-cherry.o
 obj-$(CONFIG_HID_CHICONY)	+= hid-chicony.o
+obj-$(CONFIG_HID_COMPAQ)	+= hid-compaq.o
 obj-$(CONFIG_HID_CP2112)	+= hid-cp2112.o
 obj-$(CONFIG_HID_CYPRESS)	+= hid-cypress.o
 obj-$(CONFIG_HID_DRAGONRISE)	+= hid-dr.o
diff --git a/drivers/hid/hid-compaq.c b/drivers/hid/hid-compaq.c
new file mode 100644
index 0000000..db14ca9
--- /dev/null
+++ b/drivers/hid/hid-compaq.c
@@ -0,0 +1,68 @@
+/*
+ *  HID driver for some compaq "special" devices
+ *
+ *  Copyright (c) 2014 Hans de Goede <hdegoede@redhat.com>
+ *
+ *  Based on hid-microsoft.c which is:
+ *
+ *  Copyright (c) 1999 Andreas Gal
+ *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
+ *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
+ *  Copyright (c) 2006-2007 Jiri Kosina
+ *  Copyright (c) 2008 Jiri Slaby
+ */
+
+/*
+ * 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 <linux/device.h>
+#include <linux/input.h>
+#include <linux/hid.h>
+#include <linux/module.h>
+
+#include "hid-ids.h"
+
+#define compaq_map_key_clear(c)	hid_map_usage_clear(hi, usage, bit, max, \
+					EV_KEY, (c))
+
+static int compaq_input_mapping(struct hid_device *hdev, struct hid_input *hi,
+		struct hid_field *field, struct hid_usage *usage,
+		unsigned long **bit, int *max)
+{
+	pr_err("compaq input map called, page %04x usage %04x\n",
+		(usage->hid & HID_USAGE_PAGE), (usage->hid & HID_USAGE));
+
+	if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
+		return 0;
+
+
+	switch (usage->hid & HID_USAGE) {
+	case 0x0011: compaq_map_key_clear(KEY_PRESENTATION);	break;
+	case 0x0012: compaq_map_key_clear(KEY_ADDRESSBOOK);	break;
+	case 0x0013: compaq_map_key_clear(KEY_INFO);		break;
+	case 0x0014: compaq_map_key_clear(KEY_PROG1);		break;
+	case 0x0015: compaq_map_key_clear(KEY_MESSENGER);	break;
+	default:
+		return 0;
+	}
+	return 1;
+}
+
+static const struct hid_device_id compaq_devices[] = {
+	{ HID_USB_DEVICE(USB_VENDOR_ID_COMPAQ, USB_DEVICE_ID_KU_0133_KBD) },
+	{ }
+};
+MODULE_DEVICE_TABLE(hid, compaq_devices);
+
+static struct hid_driver compaq_driver = {
+	.name = "compaq",
+	.id_table = compaq_devices,
+	.input_mapping = compaq_input_mapping,
+};
+module_hid_driver(compaq_driver);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 8ed66fd..3bbd87c 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1754,6 +1754,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_COMPAQ, USB_DEVICE_ID_KU_0133_KBD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 48b66bb..9bf2c6d 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -236,6 +236,9 @@
 #define USB_DEVICE_ID_CODEMERCS_IOW_FIRST	0x1500
 #define USB_DEVICE_ID_CODEMERCS_IOW_LAST	0x15ff
 
+#define USB_VENDOR_ID_COMPAQ		0x049f
+#define USB_DEVICE_ID_KU_0133_KBD	0x0051
+
 #define USB_VENDOR_ID_CREATIVELABS	0x041e
 #define USB_DEVICE_ID_PRODIKEYS_PCMIDI	0x2801
 
-- 
2.0.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hid: Add mapping for special keys on compaq ku 0133 keyboard
  2014-08-12 23:14 [PATCH] hid: Add mapping for special keys on compaq ku 0133 keyboard Hans de Goede
@ 2014-08-12 23:35 ` Dmitry Torokhov
  2014-08-13  8:38   ` Hans de Goede
  2014-10-21 20:45   ` Hans de Goede
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2014-08-12 23:35 UTC (permalink / raw)
  To: Hans de Goede; +Cc: linux-input

On Wed, Aug 13, 2014 at 01:14:50AM +0200, Hans de Goede wrote:
> The compaq ku 0133 keyboard has 8 special keys at the top:
> http://lackof.org/taggart/hacking/keyboard/cpqwireless.jpg
> 
> 3 of these use standard HID usage codes from the consumer page, the 5
> others use part of the reserved 0x07 - 0x1f range.
> 
> This commit adds mapping for this keyboard for these reserved codes, making
> the other 5 keys work.

Can't we just load the proper keymap through udev without writing yet another
kernel driver?

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hid: Add mapping for special keys on compaq ku 0133 keyboard
  2014-08-12 23:35 ` Dmitry Torokhov
@ 2014-08-13  8:38   ` Hans de Goede
  2014-10-21 20:45   ` Hans de Goede
  1 sibling, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2014-08-13  8:38 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input

Hi,

On 08/13/2014 01:35 AM, Dmitry Torokhov wrote:
> On Wed, Aug 13, 2014 at 01:14:50AM +0200, Hans de Goede wrote:
>> The compaq ku 0133 keyboard has 8 special keys at the top:
>> http://lackof.org/taggart/hacking/keyboard/cpqwireless.jpg
>>
>> 3 of these use standard HID usage codes from the consumer page, the 5
>> others use part of the reserved 0x07 - 0x1f range.
>>
>> This commit adds mapping for this keyboard for these reserved codes, making
>> the other 5 keys work.
> 
> Can't we just load the proper keymap through udev without writing yet another
> kernel driver?

Hmm, in this case I don't see any reason why not. ATM I don't have access
to the keyboard in question. I'll try writing a udev hwdb entry for it, assuming
that works I'll send that upstream to the u-boot guys. If it does not work for
some reason, then I'll send a v2 of this patch.

Regards,

Hans

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hid: Add mapping for special keys on compaq ku 0133 keyboard
  2014-08-12 23:35 ` Dmitry Torokhov
  2014-08-13  8:38   ` Hans de Goede
@ 2014-10-21 20:45   ` Hans de Goede
  1 sibling, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2014-10-21 20:45 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input

Hi,

On 08/13/2014 01:35 AM, Dmitry Torokhov wrote:
> On Wed, Aug 13, 2014 at 01:14:50AM +0200, Hans de Goede wrote:
>> The compaq ku 0133 keyboard has 8 special keys at the top:
>> http://lackof.org/taggart/hacking/keyboard/cpqwireless.jpg
>>
>> 3 of these use standard HID usage codes from the consumer page, the 5
>> others use part of the reserved 0x07 - 0x1f range.
>>
>> This commit adds mapping for this keyboard for these reserved codes, making
>> the other 5 keys work.
>
> Can't we just load the proper keymap through udev without writing yet another
> kernel driver?

A valid question, and I agree that in this case where no special handling is
necessary, that would be better. So I've just tried this, but this does not
work, because hid-input.c chooses to ignore unknown usage codes in the
consumer page, rather then map them to KEY_UNKNOWN, making it impossible
to remap them through udev/hwdb later.

I've written a patch to fix this +  a hwdb patch, which seems like a better
way to deal with this then my original patch introducing a compaq usb hid kernel
driver esp. for this.

Regards,

Hans

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-21 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-12 23:14 [PATCH] hid: Add mapping for special keys on compaq ku 0133 keyboard Hans de Goede
2014-08-12 23:35 ` Dmitry Torokhov
2014-08-13  8:38   ` Hans de Goede
2014-10-21 20:45   ` Hans de Goede

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).