6552be
From 98f07385212073536f303c07ece455acdd4d267f Mon Sep 17 00:00:00 2001
6552be
From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=9A=D1=83?=
6552be
 =?UTF-8?q?=D0=B4=D1=80=D1=8F=D0=B2=D1=86=D0=B5=D0=B2?=
6552be
 <nkudriavtsev@gmail.com>
6552be
Date: Tue, 21 Jul 2015 13:31:52 +0300
6552be
Subject: [PATCH] HID: chicony: Add support for Acer Aspire Switch 12
6552be
6552be
Acer Aspire Switch 12 keyboard Chicony's controller reports too big usage
6552be
index on the 1st interface. The patch fixes the report. The work based on
6552be
solution from drivers/hid/hid-holtek-mouse.c
6552be
6552be
Bug report: https://bugzilla.kernel.org/show_bug.cgi?id=101721
6552be
6552be
Signed-off-by: Nicholas Kudriavtsev <nkudriavtsev@gmail.com>
6552be
Signed-off-by: Jiri Kosina <jkosina@suse.com>
6552be
---
6552be
 drivers/hid/hid-chicony.c | 26 ++++++++++++++++++++++++++
6552be
 drivers/hid/hid-core.c    |  1 +
6552be
 drivers/hid/hid-ids.h     |  1 +
6552be
 3 files changed, 28 insertions(+)
6552be
6552be
diff --git a/drivers/hid/hid-chicony.c b/drivers/hid/hid-chicony.c
6552be
index b613d5a79684..bc3cec199fee 100644
6552be
--- a/drivers/hid/hid-chicony.c
6552be
+++ b/drivers/hid/hid-chicony.c
6552be
@@ -20,6 +20,7 @@
6552be
 #include <linux/input.h>
6552be
 #include <linux/hid.h>
6552be
 #include <linux/module.h>
6552be
+#include <linux/usb.h>
6552be
 
6552be
 #include "hid-ids.h"
6552be
 
6552be
@@ -57,10 +58,34 @@ static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
6552be
 	return 1;
6552be
 }
6552be
 
6552be
+static __u8 *ch_switch12_report_fixup(struct hid_device *hdev, __u8 *rdesc,
6552be
+		unsigned int *rsize)
6552be
+{
6552be
+	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
6552be
+	
6552be
+	if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
6552be
+		/* Change usage maximum and logical maximum from 0x7fff to
6552be
+		 * 0x2fff, so they don't exceed HID_MAX_USAGES */
6552be
+		switch (hdev->product) {
6552be
+		case USB_DEVICE_ID_CHICONY_ACER_SWITCH12:
6552be
+			if (*rsize >= 128 && rdesc[64] == 0xff && rdesc[65] == 0x7f
6552be
+					&& rdesc[69] == 0xff && rdesc[70] == 0x7f) {
6552be
+				hid_info(hdev, "Fixing up report descriptor\n");
6552be
+				rdesc[65] = rdesc[70] = 0x2f;
6552be
+			}
6552be
+			break;
6552be
+		}
6552be
+
6552be
+	}
6552be
+	return rdesc;
6552be
+}
6552be
+
6552be
+
6552be
 static const struct hid_device_id ch_devices[] = {
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
6552be
+	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) },
6552be
 	{ }
6552be
 };
6552be
 MODULE_DEVICE_TABLE(hid, ch_devices);
6552be
@@ -68,6 +93,7 @@ MODULE_DEVICE_TABLE(hid, ch_devices);
6552be
 static struct hid_driver ch_driver = {
6552be
 	.name = "chicony",
6552be
 	.id_table = ch_devices,
6552be
+	.report_fixup = ch_switch12_report_fixup,
6552be
 	.input_mapping = ch_input_mapping,
6552be
 };
6552be
 module_hid_driver(ch_driver);
6552be
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
6552be
index e6fce23b121a..f90ca6574221 100644
6552be
--- a/drivers/hid/hid-core.c
6552be
+++ b/drivers/hid/hid-core.c
6552be
@@ -1807,6 +1807,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
6552be
+	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
6552be
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
6552be
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
6552be
index b3b225b75d0a..79210ca8eff1 100644
6552be
--- a/drivers/hid/hid-ids.h
6552be
+++ b/drivers/hid/hid-ids.h
6552be
@@ -233,6 +233,7 @@
6552be
 #define USB_DEVICE_ID_CHICONY_PIXART_USB_OPTICAL_MOUSE	0x1053
6552be
 #define USB_DEVICE_ID_CHICONY_WIRELESS2	0x1123
6552be
 #define USB_DEVICE_ID_CHICONY_AK1D	0x1125
6552be
+#define USB_DEVICE_ID_CHICONY_ACER_SWITCH12	0x1421
6552be
 
6552be
 #define USB_VENDOR_ID_CHUNGHWAT		0x2247
6552be
 #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH	0x0001
6552be
-- 
6552be
2.4.3
6552be