[PATCH 2/2] HID: macally: Add support for Macally QKEY keyboard

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This enables the brightness-down and brightness-up keys on the Macally
QKEY keyboard. Similar workarounds are probably needed for quite a few
Macally keyboard models.

Based on the key translation code in the Apple keyboard driver.

Signed-off-by: Alex Henrie <alexhenrie24@xxxxxxxxx>
---
 drivers/hid/Kconfig       |  1 +
 drivers/hid/hid-ids.h     |  3 +++
 drivers/hid/hid-macally.c | 57 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index aef4a2a690e1..082900477df5 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -239,6 +239,7 @@ config HID_MACALLY
 
 	supported devices:
 	- Macally ikey keyboard
+	- Macally QKEY keyboard
 
 config HID_PRODIKEYS
 	tristate "Prodikeys PC-MIDI Keyboard support"
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index aacc7534b076..5afc3b7fe8ca 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -776,6 +776,9 @@
 #define USB_DEVICE_ID_CRYSTALTOUCH	0x0006
 #define USB_DEVICE_ID_CRYSTALTOUCH_DUAL	0x0007
 
+#define USB_VENDOR_ID_MACALLY			0x2222
+#define USB_DEVICE_ID_MACALLY_QKEY_KEYBOARD	0x0039
+
 #define USB_VENDOR_ID_MADCATZ		0x0738
 #define USB_DEVICE_ID_MADCATZ_BEATPAD	0x4540
 #define USB_DEVICE_ID_MADCATZ_RAT5	0x1705
diff --git a/drivers/hid/hid-macally.c b/drivers/hid/hid-macally.c
index 6f62f059b795..2567babe8200 100644
--- a/drivers/hid/hid-macally.c
+++ b/drivers/hid/hid-macally.c
@@ -31,9 +31,64 @@ static __u8 *macally_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 	return rdesc;
 }
 
+struct macally_key_translation
+{
+	u16 from;
+	u16 to;
+};
+
+static const struct macally_key_translation qkey_brightness_keys[] =
+{
+	{ KEY_SCROLLLOCK, KEY_BRIGHTNESSDOWN },
+	{ KEY_PAUSE, KEY_BRIGHTNESSUP },
+	{ }
+};
+
+static int macally_event(struct hid_device *hdev, struct hid_field *field,
+		struct hid_usage *usage, __s32 value)
+{
+	const struct macally_key_translation *trans;
+
+	switch (hdev->product) {
+		case USB_DEVICE_ID_MACALLY_QKEY_KEYBOARD:
+			trans = qkey_brightness_keys;
+			break;
+		default:
+			trans = NULL;
+	}
+
+	if (trans) {
+		while (trans->from) {
+			if (trans->from == usage->code) {
+				input_event(field->hidinput->input, usage->type,
+					trans->to, value);
+				return 1;
+			}
+			trans++;
+		}
+	}
+
+	return 0;
+}
+
+static int macally_input_mapping(struct hid_device *hdev, struct hid_input *hi,
+		struct hid_field *field, struct hid_usage *usage,
+		unsigned long **bit, int *max)
+{
+	const struct macally_key_translation *trans;
+
+	/* Enable all needed keys */
+	for (trans = qkey_brightness_keys; trans->from; trans++)
+		set_bit(trans->to, hi->input->keybit);
+
+	return 0;
+}
+
 static struct hid_device_id macally_id_table[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR,
 			 USB_DEVICE_ID_MACALLY_IKEY_KEYBOARD) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_MACALLY,
+			 USB_DEVICE_ID_MACALLY_QKEY_KEYBOARD) },
 	{ }
 };
 MODULE_DEVICE_TABLE(hid, macally_id_table);
@@ -42,6 +97,8 @@ static struct hid_driver macally_driver = {
 	.name			= "macally",
 	.id_table		= macally_id_table,
 	.report_fixup		= macally_report_fixup,
+	.event			= macally_event,
+	.input_mapping		= macally_input_mapping,
 };
 
 module_hid_driver(macally_driver);
-- 
2.21.0




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux