aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-02-20 20:16:43 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-20 20:16:43 -0500
commit27a67e0f983567574ef659520d930f82cf65125a (patch)
tree67d1874c281ba37f68d15d65db97c5abbdee5826
parent59da2a0630b8db5fa71fa5ca0052fd3fe3766d94 (diff)
parent53f724b2432a9f97a941251772f2b0d195e2d282 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
Pull HID updates from Jiri Kosina: - a lot of Wacom driver updates; most notably second generation Intuos Pro is now supported, code from Aaron Armstrong Skomra and Jason Gerecke - Surface 3 and 4 Type Cover Pro support from Daniel Keller, Dennis Chen and Yuta Kobayashi - hid-rmi is now generic transport driver, used by synaptics-rmi4; Support the Lenovo Thinkpad X1 Tablet dock follows on top, from Andrew Duggan - a few misc bugfixes and improvements here and there * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: (29 commits) HID: intel-ish-hid: constify device_type structure HID: wacom: Bluetooth IRQ for Intuos Pro should handle prox/range HID: intel-ish-hid: ipc: check FW status to distinguish ISH resume paths HID: multitouch: fix LG Melfas touchscreen HID: wacom: don't apply generic settings to old devices HID: wacom: generic: support LEDs HID: wacom: generic: support generic touch switch HID: wacom: generic: add vendor defined touch HID: wacom: generic: add support for touchring HID: wacom: generic: remove input_event_flag HID: wacom: Support 2nd-gen Intuos Pro's Bluetooth classic interface HID: wacom: Move WAC_CMD_* into wacom_wac.h HID: wacom: Enable HID_GENERIC codepath for Bluetooth devices HID: wacom: do not attempt to switch mode while in probe HID: wacom: remove warning while disconnecting devices HID: wacom: release the resources before leaving despite devm HID: whitespace cleanup HID: multitouch: enable Surface 3 Type Cover Pro to report multitouch data HID: rmi: Support the Lenovo Thinkpad X1 Tablet dock using hid-rmi HID: rmi: Handle all Synaptics touchpads using hid-rmi ...
-rw-r--r--drivers/hid/Kconfig5
-rw-r--r--drivers/hid/hid-core.c27
-rw-r--r--drivers/hid/hid-ids.h11
-rw-r--r--drivers/hid/hid-mf.c19
-rw-r--r--drivers/hid/hid-microsoft.c12
-rw-r--r--drivers/hid/hid-multitouch.c44
-rw-r--r--drivers/hid/hid-rmi.c975
-rw-r--r--drivers/hid/intel-ish-hid/ipc/hw-ish-regs.h8
-rw-r--r--drivers/hid/intel-ish-hid/ipc/hw-ish.h12
-rw-r--r--drivers/hid/intel-ish-hid/ipc/pci-ish.c38
-rw-r--r--drivers/hid/intel-ish-hid/ishtp-hid.c2
-rw-r--r--drivers/hid/intel-ish-hid/ishtp/bus.c2
-rw-r--r--drivers/hid/intel-ish-hid/ishtp/hbm.c1
-rw-r--r--drivers/hid/intel-ish-hid/ishtp/init.c1
-rw-r--r--drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h3
-rw-r--r--drivers/hid/usbhid/hid-core.c3
-rw-r--r--drivers/hid/usbhid/hid-quirks.c12
-rw-r--r--drivers/hid/usbhid/usbkbd.c3
-rw-r--r--drivers/hid/usbhid/usbmouse.c3
-rw-r--r--drivers/hid/wacom.h5
-rw-r--r--drivers/hid/wacom_sys.c147
-rw-r--r--drivers/hid/wacom_wac.c289
-rw-r--r--drivers/hid/wacom_wac.h37
23 files changed, 698 insertions, 961 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 4070b7386e9d..1aeb80e52424 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -785,6 +785,11 @@ config HID_SUNPLUS
785config HID_RMI 785config HID_RMI
786 tristate "Synaptics RMI4 device support" 786 tristate "Synaptics RMI4 device support"
787 depends on HID 787 depends on HID
788 select RMI4_CORE
789 select RMI4_F03
790 select RMI4_F11
791 select RMI4_F12
792 select RMI4_F30
788 ---help--- 793 ---help---
789 Support for Synaptics RMI4 touchpads. 794 Support for Synaptics RMI4 touchpads.
790 Say Y here if you have a Synaptics RMI4 touchpads over i2c-hid or usbhid 795 Say Y here if you have a Synaptics RMI4 touchpads over i2c-hid or usbhid
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index ea36b557d5ee..538ff697a4cf 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -43,7 +43,6 @@
43 */ 43 */
44 44
45#define DRIVER_DESC "HID core driver" 45#define DRIVER_DESC "HID core driver"
46#define DRIVER_LICENSE "GPL"
47 46
48int hid_debug = 0; 47int hid_debug = 0;
49module_param_named(debug, hid_debug, int, 0600); 48module_param_named(debug, hid_debug, int, 0600);
@@ -724,13 +723,7 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
724 hid->group = HID_GROUP_SENSOR_HUB; 723 hid->group = HID_GROUP_SENSOR_HUB;
725 724
726 if (hid->vendor == USB_VENDOR_ID_MICROSOFT && 725 if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
727 (hid->product == USB_DEVICE_ID_MS_TYPE_COVER_PRO_3 || 726 hid->product == USB_DEVICE_ID_MS_POWER_COVER &&
728 hid->product == USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2 ||
729 hid->product == USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP ||
730 hid->product == USB_DEVICE_ID_MS_TYPE_COVER_PRO_4 ||
731 hid->product == USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_2 ||
732 hid->product == USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_JP ||
733 hid->product == USB_DEVICE_ID_MS_POWER_COVER) &&
734 hid->group == HID_GROUP_MULTITOUCH) 727 hid->group == HID_GROUP_MULTITOUCH)
735 hid->group = HID_GROUP_GENERIC; 728 hid->group = HID_GROUP_GENERIC;
736 729
@@ -826,7 +819,8 @@ static int hid_scan_report(struct hid_device *hid)
826 hid->group = HID_GROUP_WACOM; 819 hid->group = HID_GROUP_WACOM;
827 break; 820 break;
828 case USB_VENDOR_ID_SYNAPTICS: 821 case USB_VENDOR_ID_SYNAPTICS:
829 if (hid->group == HID_GROUP_GENERIC) 822 if (hid->group == HID_GROUP_GENERIC ||
823 hid->group == HID_GROUP_MULTITOUCH_WIN_8)
830 if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC) 824 if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
831 && (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER)) 825 && (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER))
832 /* 826 /*
@@ -1887,6 +1881,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
1887 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) }, 1881 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
1888#if IS_ENABLED(CONFIG_HID_MAYFLASH) 1882#if IS_ENABLED(CONFIG_HID_MAYFLASH)
1889 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3) }, 1883 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3) },
1884 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR) },
1885 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE1) },
1886 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE2) },
1890#endif 1887#endif
1891 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_WN) }, 1888 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_WN) },
1892 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_FA) }, 1889 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_FA) },
@@ -1933,6 +1930,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1933 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) }, 1930 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) },
1934 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) }, 1931 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) },
1935#endif 1932#endif
1933 { HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MELFAS_MT) },
1936 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, 1934 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1937 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, 1935 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1938 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, 1936 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
@@ -1985,12 +1983,6 @@ static const struct hid_device_id hid_have_special_driver[] = {
1985 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) }, 1983 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
1986 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 1984 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1987 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) }, 1985 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
1988 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3) },
1989 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2) },
1990 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP) },
1991 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4) },
1992 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_2) },
1993 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_JP) },
1994 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K) }, 1986 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K) },
1995 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600) }, 1987 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600) },
1996 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1) }, 1988 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1) },
@@ -2126,6 +2118,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
2126 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) }, 2118 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
2127 { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) }, 2119 { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) },
2128 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) }, 2120 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
2121 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
2129 { } 2122 { }
2130}; 2123};
2131 2124
@@ -2314,7 +2307,7 @@ __ATTRIBUTE_GROUPS(hid_dev);
2314 2307
2315static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) 2308static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
2316{ 2309{
2317 struct hid_device *hdev = to_hid_device(dev); 2310 struct hid_device *hdev = to_hid_device(dev);
2318 2311
2319 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", 2312 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
2320 hdev->bus, hdev->vendor, hdev->product)) 2313 hdev->bus, hdev->vendor, hdev->product))
@@ -2867,5 +2860,5 @@ module_exit(hid_exit);
2867MODULE_AUTHOR("Andreas Gal"); 2860MODULE_AUTHOR("Andreas Gal");
2868MODULE_AUTHOR("Vojtech Pavlik"); 2861MODULE_AUTHOR("Vojtech Pavlik");
2869MODULE_AUTHOR("Jiri Kosina"); 2862MODULE_AUTHOR("Jiri Kosina");
2870MODULE_LICENSE(DRIVER_LICENSE); 2863MODULE_LICENSE("GPL");
2871 2864
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 350accfee8e8..86c95d30ac80 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -323,7 +323,8 @@
323#define USB_DEVICE_ID_DRAGONRISE_WIIU 0x1800 323#define USB_DEVICE_ID_DRAGONRISE_WIIU 0x1800
324#define USB_DEVICE_ID_DRAGONRISE_PS3 0x1801 324#define USB_DEVICE_ID_DRAGONRISE_PS3 0x1801
325#define USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR 0x1803 325#define USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR 0x1803
326#define USB_DEVICE_ID_DRAGONRISE_GAMECUBE 0x1843 326#define USB_DEVICE_ID_DRAGONRISE_GAMECUBE1 0x1843
327#define USB_DEVICE_ID_DRAGONRISE_GAMECUBE2 0x1844
327 328
328#define USB_VENDOR_ID_DWAV 0x0eef 329#define USB_VENDOR_ID_DWAV 0x0eef
329#define USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER 0x0001 330#define USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER 0x0001
@@ -630,9 +631,11 @@
630#define USB_DEVICE_ID_LENOVO_CUSBKBD 0x6047 631#define USB_DEVICE_ID_LENOVO_CUSBKBD 0x6047
631#define USB_DEVICE_ID_LENOVO_CBTKBD 0x6048 632#define USB_DEVICE_ID_LENOVO_CBTKBD 0x6048
632#define USB_DEVICE_ID_LENOVO_TPPRODOCK 0x6067 633#define USB_DEVICE_ID_LENOVO_TPPRODOCK 0x6067
634#define USB_DEVICE_ID_LENOVO_X1_COVER 0x6085
633 635
634#define USB_VENDOR_ID_LG 0x1fd2 636#define USB_VENDOR_ID_LG 0x1fd2
635#define USB_DEVICE_ID_LG_MULTITOUCH 0x0064 637#define USB_DEVICE_ID_LG_MULTITOUCH 0x0064
638#define USB_DEVICE_ID_LG_MELFAS_MT 0x6007
636 639
637#define USB_VENDOR_ID_LOGITECH 0x046d 640#define USB_VENDOR_ID_LOGITECH 0x046d
638#define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e 641#define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e
@@ -725,12 +728,6 @@
725#define USB_DEVICE_ID_MS_SURFACE_PRO_2 0x0799 728#define USB_DEVICE_ID_MS_SURFACE_PRO_2 0x0799
726#define USB_DEVICE_ID_MS_TOUCH_COVER_2 0x07a7 729#define USB_DEVICE_ID_MS_TOUCH_COVER_2 0x07a7
727#define USB_DEVICE_ID_MS_TYPE_COVER_2 0x07a9 730#define USB_DEVICE_ID_MS_TYPE_COVER_2 0x07a9
728#define USB_DEVICE_ID_MS_TYPE_COVER_PRO_3 0x07dc
729#define USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2 0x07e2
730#define USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP 0x07dd
731#define USB_DEVICE_ID_MS_TYPE_COVER_PRO_4 0x07e4
732#define USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_2 0x07e8
733#define USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_JP 0x07e9
734#define USB_DEVICE_ID_MS_POWER_COVER 0x07da 731#define USB_DEVICE_ID_MS_POWER_COVER 0x07da
735 732
736#define USB_VENDOR_ID_MOJO 0x8282 733#define USB_VENDOR_ID_MOJO 0x8282
diff --git a/drivers/hid/hid-mf.c b/drivers/hid/hid-mf.c
index d9090765a6e5..03f10516131d 100644
--- a/drivers/hid/hid-mf.c
+++ b/drivers/hid/hid-mf.c
@@ -6,12 +6,14 @@
6 * 6 *
7 * Tested with: 7 * Tested with:
8 * 0079:1801 "DragonRise Inc. Mayflash PS3 Game Controller Adapter" 8 * 0079:1801 "DragonRise Inc. Mayflash PS3 Game Controller Adapter"
9 * 0079:1803 "DragonRise Inc. Mayflash Wireless Sensor DolphinBar"
10 * 0079:1843 "DragonRise Inc. Mayflash GameCube Game Controller Adapter"
11 * 0079:1844 "DragonRise Inc. Mayflash GameCube Game Controller Adapter (v04)"
9 * 12 *
10 * The following adapters probably work too, but need to be tested: 13 * The following adapters probably work too, but need to be tested:
11 * 0079:1800 "DragonRise Inc. Mayflash WIIU Game Controller Adapter" 14 * 0079:1800 "DragonRise Inc. Mayflash WIIU Game Controller Adapter"
12 * 0079:1843 "DragonRise Inc. Mayflash GameCube Game Controller Adapter"
13 * 15 *
14 * Copyright (c) 2016 Marcel Hasler <mahasler@gmail.com> 16 * Copyright (c) 2016-2017 Marcel Hasler <mahasler@gmail.com>
15 */ 17 */
16 18
17/* 19/*
@@ -125,8 +127,8 @@ static int mf_probe(struct hid_device *hid, const struct hid_device_id *id)
125 127
126 dev_dbg(&hid->dev, "Mayflash HID hardware probe...\n"); 128 dev_dbg(&hid->dev, "Mayflash HID hardware probe...\n");
127 129
128 /* Split device into four inputs */ 130 /* Apply quirks as needed */
129 hid->quirks |= HID_QUIRK_MULTI_INPUT; 131 hid->quirks |= id->driver_data;
130 132
131 error = hid_parse(hid); 133 error = hid_parse(hid);
132 if (error) { 134 if (error) {
@@ -151,7 +153,14 @@ static int mf_probe(struct hid_device *hid, const struct hid_device_id *id)
151} 153}
152 154
153static const struct hid_device_id mf_devices[] = { 155static const struct hid_device_id mf_devices[] = {
154 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3), }, 156 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3),
157 .driver_data = HID_QUIRK_MULTI_INPUT },
158 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR),
159 .driver_data = HID_QUIRK_MULTI_INPUT },
160 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE1),
161 .driver_data = HID_QUIRK_MULTI_INPUT },
162 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE2),
163 .driver_data = 0 }, /* No quirk required */
155 { } 164 { }
156}; 165};
157MODULE_DEVICE_TABLE(hid, mf_devices); 166MODULE_DEVICE_TABLE(hid, mf_devices);
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 74b7b84a0420..96e7d3231d2f 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -274,18 +274,6 @@ static const struct hid_device_id ms_devices[] = {
274 .driver_data = MS_NOGET }, 274 .driver_data = MS_NOGET },
275 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500), 275 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
276 .driver_data = MS_DUPLICATE_USAGES }, 276 .driver_data = MS_DUPLICATE_USAGES },
277 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3),
278 .driver_data = MS_HIDINPUT },
279 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2),
280 .driver_data = MS_HIDINPUT },
281 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP),
282 .driver_data = MS_HIDINPUT },
283 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4),
284 .driver_data = MS_HIDINPUT },
285 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_2),
286 .driver_data = MS_HIDINPUT },
287 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_JP),
288 .driver_data = MS_HIDINPUT },
289 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER), 277 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER),
290 .driver_data = MS_HIDINPUT }, 278 .driver_data = MS_HIDINPUT },
291 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD), 279 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD),
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 6dca66806844..692647485a53 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -68,6 +68,7 @@ MODULE_LICENSE("GPL");
68#define MT_QUIRK_HOVERING (1 << 11) 68#define MT_QUIRK_HOVERING (1 << 11)
69#define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12) 69#define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12)
70#define MT_QUIRK_FORCE_GET_FEATURE (1 << 13) 70#define MT_QUIRK_FORCE_GET_FEATURE (1 << 13)
71#define MT_QUIRK_FIX_CONST_CONTACT_ID (1 << 14)
71 72
72#define MT_INPUTMODE_TOUCHSCREEN 0x02 73#define MT_INPUTMODE_TOUCHSCREEN 0x02
73#define MT_INPUTMODE_TOUCHPAD 0x03 74#define MT_INPUTMODE_TOUCHPAD 0x03
@@ -157,6 +158,7 @@ static void mt_post_parse(struct mt_device *td);
157#define MT_CLS_FLATFROG 0x0107 158#define MT_CLS_FLATFROG 0x0107
158#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108 159#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
159#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109 160#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
161#define MT_CLS_LG 0x010a
160#define MT_CLS_VTL 0x0110 162#define MT_CLS_VTL 0x0110
161 163
162#define MT_DEFAULT_MAXCONTACT 10 164#define MT_DEFAULT_MAXCONTACT 10
@@ -263,6 +265,12 @@ static struct mt_class mt_classes[] = {
263 .sn_move = 2048, 265 .sn_move = 2048,
264 .maxcontacts = 40, 266 .maxcontacts = 40,
265 }, 267 },
268 { .name = MT_CLS_LG,
269 .quirks = MT_QUIRK_ALWAYS_VALID |
270 MT_QUIRK_FIX_CONST_CONTACT_ID |
271 MT_QUIRK_IGNORE_DUPLICATES |
272 MT_QUIRK_HOVERING |
273 MT_QUIRK_CONTACT_CNT_ACCURATE },
266 { .name = MT_CLS_VTL, 274 { .name = MT_CLS_VTL,
267 .quirks = MT_QUIRK_ALWAYS_VALID | 275 .quirks = MT_QUIRK_ALWAYS_VALID |
268 MT_QUIRK_CONTACT_CNT_ACCURATE | 276 MT_QUIRK_CONTACT_CNT_ACCURATE |
@@ -1078,6 +1086,34 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
1078 return 0; 1086 return 0;
1079} 1087}
1080 1088
1089static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1090{
1091 if (field->usage[0].hid != usage ||
1092 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1093 return;
1094
1095 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1096 field->flags |= HID_MAIN_ITEM_VARIABLE;
1097}
1098
1099static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1100{
1101 struct hid_report *report;
1102 int i;
1103
1104 list_for_each_entry(report,
1105 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1106 list) {
1107
1108 if (!report->maxfield)
1109 continue;
1110
1111 for (i = 0; i < report->maxfield; i++)
1112 if (report->field[i]->maxusage >= 1)
1113 mt_fix_const_field(report->field[i], usage);
1114 }
1115}
1116
1081static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) 1117static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1082{ 1118{
1083 int ret, i; 1119 int ret, i;
@@ -1151,6 +1187,9 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1151 if (ret != 0) 1187 if (ret != 0)
1152 return ret; 1188 return ret;
1153 1189
1190 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1191 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1192
1154 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 1193 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1155 if (ret) 1194 if (ret)
1156 return ret; 1195 return ret;
@@ -1398,6 +1437,11 @@ static const struct hid_device_id mt_devices[] = {
1398 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK, 1437 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
1399 USB_DEVICE_ID_ILITEK_MULTITOUCH) }, 1438 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1400 1439
1440 /* LG Melfas panel */
1441 { .driver_data = MT_CLS_LG,
1442 HID_USB_DEVICE(USB_VENDOR_ID_LG,
1443 USB_DEVICE_ID_LG_MELFAS_MT) },
1444
1401 /* MosArt panels */ 1445 /* MosArt panels */
1402 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, 1446 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1403 MT_USB_DEVICE(USB_VENDOR_ID_ASUS, 1447 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index be89bcbf6a71..5b40c2614599 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -14,11 +14,14 @@
14#include <linux/hid.h> 14#include <linux/hid.h>
15#include <linux/input.h> 15#include <linux/input.h>
16#include <linux/input/mt.h> 16#include <linux/input/mt.h>
17#include <linux/irq.h>
18#include <linux/irqdomain.h>
17#include <linux/module.h> 19#include <linux/module.h>
18#include <linux/pm.h> 20#include <linux/pm.h>
19#include <linux/slab.h> 21#include <linux/slab.h>
20#include <linux/wait.h> 22#include <linux/wait.h>
21#include <linux/sched.h> 23#include <linux/sched.h>
24#include <linux/rmi.h>
22#include "hid-ids.h" 25#include "hid-ids.h"
23 26
24#define RMI_MOUSE_REPORT_ID 0x01 /* Mouse emulation Report */ 27#define RMI_MOUSE_REPORT_ID 0x01 /* Mouse emulation Report */
@@ -33,9 +36,6 @@
33#define RMI_READ_DATA_PENDING 1 36#define RMI_READ_DATA_PENDING 1
34#define RMI_STARTED 2 37#define RMI_STARTED 2
35 38
36#define RMI_SLEEP_NORMAL 0x0
37#define RMI_SLEEP_DEEP_SLEEP 0x1
38
39/* device flags */ 39/* device flags */
40#define RMI_DEVICE BIT(0) 40#define RMI_DEVICE BIT(0)
41#define RMI_DEVICE_HAS_PHYS_BUTTONS BIT(1) 41#define RMI_DEVICE_HAS_PHYS_BUTTONS BIT(1)
@@ -54,25 +54,12 @@ enum rmi_mode_type {
54 RMI_MODE_NO_PACKED_ATTN_REPORTS = 2, 54 RMI_MODE_NO_PACKED_ATTN_REPORTS = 2,
55}; 55};
56 56
57struct rmi_function {
58 unsigned page; /* page of the function */
59 u16 query_base_addr; /* base address for queries */
60 u16 command_base_addr; /* base address for commands */
61 u16 control_base_addr; /* base address for controls */
62 u16 data_base_addr; /* base address for datas */
63 unsigned int interrupt_base; /* cross-function interrupt number
64 * (uniq in the device)*/
65 unsigned int interrupt_count; /* number of interrupts */
66 unsigned int report_size; /* size of a report */
67 unsigned long irq_mask; /* mask of the interrupts
68 * (to be applied against ATTN IRQ) */
69};
70
71/** 57/**
72 * struct rmi_data - stores information for hid communication 58 * struct rmi_data - stores information for hid communication
73 * 59 *
74 * @page_mutex: Locks current page to avoid changing pages in unexpected ways. 60 * @page_mutex: Locks current page to avoid changing pages in unexpected ways.
75 * @page: Keeps track of the current virtual page 61 * @page: Keeps track of the current virtual page
62 * @xport: transport device to be registered with the RMI4 core.
76 * 63 *
77 * @wait: Used for waiting for read data 64 * @wait: Used for waiting for read data
78 * 65 *
@@ -84,26 +71,18 @@ struct rmi_function {
84 * 71 *
85 * @flags: flags for the current device (started, reading, etc...) 72 * @flags: flags for the current device (started, reading, etc...)
86 * 73 *
87 * @f11: placeholder of internal RMI function F11 description
88 * @f30: placeholder of internal RMI function F30 description
89 *
90 * @max_fingers: maximum finger count reported by the device
91 * @max_x: maximum x value reported by the device
92 * @max_y: maximum y value reported by the device
93 *
94 * @gpio_led_count: count of GPIOs + LEDs reported by F30
95 * @button_count: actual physical buttons count
96 * @button_mask: button mask used to decode GPIO ATTN reports
97 * @button_state_mask: pull state of the buttons
98 *
99 * @input: pointer to the kernel input device
100 *
101 * @reset_work: worker which will be called in case of a mouse report 74 * @reset_work: worker which will be called in case of a mouse report
102 * @hdev: pointer to the struct hid_device 75 * @hdev: pointer to the struct hid_device
76 *
77 * @device_flags: flags which describe the device
78 *
79 * @domain: the IRQ domain allocated for this RMI4 device
80 * @rmi_irq: the irq that will be used to generate events to rmi-core
103 */ 81 */
104struct rmi_data { 82struct rmi_data {
105 struct mutex page_mutex; 83 struct mutex page_mutex;
106 int page; 84 int page;
85 struct rmi_transport_dev xport;
107 86
108 wait_queue_head_t wait; 87 wait_queue_head_t wait;
109 88
@@ -115,34 +94,13 @@ struct rmi_data {
115 94
116 unsigned long flags; 95 unsigned long flags;
117 96
118 struct rmi_function f01;
119 struct rmi_function f11;
120 struct rmi_function f30;
121
122 unsigned int max_fingers;
123 unsigned int max_x;
124 unsigned int max_y;
125 unsigned int x_size_mm;
126 unsigned int y_size_mm;
127 bool read_f11_ctrl_regs;
128 u8 f11_ctrl_regs[RMI_F11_CTRL_REG_COUNT];
129
130 unsigned int gpio_led_count;
131 unsigned int button_count;
132 unsigned long button_mask;
133 unsigned long button_state_mask;
134
135 struct input_dev *input;
136
137 struct work_struct reset_work; 97 struct work_struct reset_work;
138 struct hid_device *hdev; 98 struct hid_device *hdev;
139 99
140 unsigned long device_flags; 100 unsigned long device_flags;
141 unsigned long firmware_id;
142 101
143 u8 f01_ctrl0; 102 struct irq_domain *domain;
144 u8 interrupt_enable_mask; 103 int rmi_irq;
145 bool restore_interrupt_mask;
146}; 104};
147 105
148#define RMI_PAGE(addr) (((addr) >> 8) & 0xff) 106#define RMI_PAGE(addr) (((addr) >> 8) & 0xff)
@@ -220,10 +178,11 @@ static int rmi_write_report(struct hid_device *hdev, u8 *report, int len)
220 return ret; 178 return ret;
221} 179}
222 180
223static int rmi_read_block(struct hid_device *hdev, u16 addr, void *buf, 181static int rmi_hid_read_block(struct rmi_transport_dev *xport, u16 addr,
224 const int len) 182 void *buf, size_t len)
225{ 183{
226 struct rmi_data *data = hid_get_drvdata(hdev); 184 struct rmi_data *data = container_of(xport, struct rmi_data, xport);
185 struct hid_device *hdev = data->hdev;
227 int ret; 186 int ret;
228 int bytes_read; 187 int bytes_read;
229 int bytes_needed; 188 int bytes_needed;
@@ -292,15 +251,11 @@ exit:
292 return ret; 251 return ret;
293} 252}
294 253
295static inline int rmi_read(struct hid_device *hdev, u16 addr, void *buf) 254static int rmi_hid_write_block(struct rmi_transport_dev *xport, u16 addr,
296{ 255 const void *buf, size_t len)
297 return rmi_read_block(hdev, addr, buf, 1);
298}
299
300static int rmi_write_block(struct hid_device *hdev, u16 addr, void *buf,
301 const int len)
302{ 256{
303 struct rmi_data *data = hid_get_drvdata(hdev); 257 struct rmi_data *data = container_of(xport, struct rmi_data, xport);
258 struct hid_device *hdev = data->hdev;
304 int ret; 259 int ret;
305 260
306 mutex_lock(&data->page_mutex); 261 mutex_lock(&data->page_mutex);
@@ -332,62 +287,20 @@ exit:
332 return ret; 287 return ret;
333} 288}
334 289
335static inline int rmi_write(struct hid_device *hdev, u16 addr, void *buf)
336{
337 return rmi_write_block(hdev, addr, buf, 1);
338}
339
340static void rmi_f11_process_touch(struct rmi_data *hdata, int slot,
341 u8 finger_state, u8 *touch_data)
342{
343 int x, y, wx, wy;
344 int wide, major, minor;
345 int z;
346
347 input_mt_slot(hdata->input, slot);
348 input_mt_report_slot_state(hdata->input, MT_TOOL_FINGER,
349 finger_state == 0x01);
350 if (finger_state == 0x01) {
351 x = (touch_data[0] << 4) | (touch_data[2] & 0x0F);
352 y = (touch_data[1] << 4) | (touch_data[2] >> 4);
353 wx = touch_data[3] & 0x0F;
354 wy = touch_data[3] >> 4;
355 wide = (wx > wy);
356 major = max(wx, wy);
357 minor = min(wx, wy);
358 z = touch_data[4];
359
360 /* y is inverted */
361 y = hdata->max_y - y;
362
363 input_event(hdata->input, EV_ABS, ABS_MT_POSITION_X, x);
364 input_event(hdata->input, EV_ABS, ABS_MT_POSITION_Y, y);
365 input_event(hdata->input, EV_ABS, ABS_MT_ORIENTATION, wide);
366 input_event(hdata->input, EV_ABS, ABS_MT_PRESSURE, z);
367 input_event(hdata->input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
368 input_event(hdata->input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
369 }
370}
371
372static int rmi_reset_attn_mode(struct hid_device *hdev) 290static int rmi_reset_attn_mode(struct hid_device *hdev)
373{ 291{
374 struct rmi_data *data = hid_get_drvdata(hdev); 292 struct rmi_data *data = hid_get_drvdata(hdev);
293 struct rmi_device *rmi_dev = data->xport.rmi_dev;
375 int ret; 294 int ret;
376 295
377 ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS); 296 ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS);
378 if (ret) 297 if (ret)
379 return ret; 298 return ret;
380 299
381 if (data->restore_interrupt_mask) { 300 if (test_bit(RMI_STARTED, &data->flags))
382 ret = rmi_write(hdev, data->f01.control_base_addr + 1, 301 ret = rmi_dev->driver->reset_handler(rmi_dev);
383 &data->interrupt_enable_mask);
384 if (ret) {
385 hid_err(hdev, "can not write F01 control register\n");
386 return ret;
387 }
388 }
389 302
390 return 0; 303 return ret;
391} 304}
392 305
393static void rmi_reset_work(struct work_struct *work) 306static void rmi_reset_work(struct work_struct *work)
@@ -399,102 +312,22 @@ static void rmi_reset_work(struct work_struct *work)
399 rmi_reset_attn_mode(hdata->hdev); 312 rmi_reset_attn_mode(hdata->hdev);
400} 313}
401 314
402static inline int rmi_schedule_reset(struct hid_device *hdev) 315static int rmi_input_event(struct hid_device *hdev, u8 *data, int size)
403{
404 struct rmi_data *hdata = hid_get_drvdata(hdev);
405 return schedule_work(&hdata->reset_work);
406}
407
408static int rmi_f11_input_event(struct hid_device *hdev, u8 irq, u8 *data,
409 int size)
410{
411 struct rmi_data *hdata = hid_get_drvdata(hdev);
412 int offset;
413 int i;
414
415 if (!(irq & hdata->f11.irq_mask) || size <= 0)
416 return 0;
417
418 offset = (hdata->max_fingers >> 2) + 1;
419 for (i = 0; i < hdata->max_fingers; i++) {
420 int fs_byte_position = i >> 2;
421 int fs_bit_position = (i & 0x3) << 1;
422 int finger_state = (data[fs_byte_position] >> fs_bit_position) &
423 0x03;
424 int position = offset + 5 * i;
425
426 if (position + 5 > size) {
427 /* partial report, go on with what we received */
428 printk_once(KERN_WARNING
429 "%s %s: Detected incomplete finger report. Finger reports may occasionally get dropped on this platform.\n",
430 dev_driver_string(&hdev->dev),
431 dev_name(&hdev->dev));
432 hid_dbg(hdev, "Incomplete finger report\n");
433 break;
434 }
435
436 rmi_f11_process_touch(hdata, i, finger_state, &data[position]);
437 }
438 input_mt_sync_frame(hdata->input);
439 input_sync(hdata->input);
440 return hdata->f11.report_size;
441}
442
443static int rmi_f30_input_event(struct hid_device *hdev, u8 irq, u8 *data,
444 int size)
445{ 316{
446 struct rmi_data *hdata = hid_get_drvdata(hdev); 317 struct rmi_data *hdata = hid_get_drvdata(hdev);
447 int i; 318 struct rmi_device *rmi_dev = hdata->xport.rmi_dev;
448 int button = 0; 319 unsigned long flags;
449 bool value;
450 320
451 if (!(irq & hdata->f30.irq_mask)) 321 if (!(test_bit(RMI_STARTED, &hdata->flags)))
452 return 0; 322 return 0;
453 323
454 if (size < (int)hdata->f30.report_size) { 324 local_irq_save(flags);
455 hid_warn(hdev, "Click Button pressed, but the click data is missing\n");
456 return 0;
457 }
458 325
459 for (i = 0; i < hdata->gpio_led_count; i++) { 326 rmi_set_attn_data(rmi_dev, data[1], &data[2], size - 2);
460 if (test_bit(i, &hdata->button_mask)) {
461 value = (data[i / 8] >> (i & 0x07)) & BIT(0);
462 if (test_bit(i, &hdata->button_state_mask))
463 value = !value;
464 input_event(hdata->input, EV_KEY, BTN_LEFT + button++,
465 value);
466 }
467 }
468 return hdata->f30.report_size;
469}
470
471static int rmi_input_event(struct hid_device *hdev, u8 *data, int size)
472{
473 struct rmi_data *hdata = hid_get_drvdata(hdev);
474 unsigned long irq_mask = 0;
475 unsigned index = 2;
476 327
477 if (!(test_bit(RMI_STARTED, &hdata->flags))) 328 generic_handle_irq(hdata->rmi_irq);
478 return 0;
479 329
480 irq_mask |= hdata->f11.irq_mask; 330 local_irq_restore(flags);
481 irq_mask |= hdata->f30.irq_mask;
482
483 if (data[1] & ~irq_mask)
484 hid_dbg(hdev, "unknown intr source:%02lx %s:%d\n",
485 data[1] & ~irq_mask, __FILE__, __LINE__);
486
487 if (hdata->f11.interrupt_base < hdata->f30.interrupt_base) {
488 index += rmi_f11_input_event(hdev, data[1], &data[index],
489 size - index);
490 index += rmi_f30_input_event(hdev, data[1], &data[index],
491 size - index);
492 } else {
493 index += rmi_f30_input_event(hdev, data[1], &data[index],
494 size - index);
495 index += rmi_f11_input_event(hdev, data[1], &data[index],
496 size - index);
497 }
498 331
499 return 1; 332 return 1;
500} 333}
@@ -568,7 +401,7 @@ static int rmi_event(struct hid_device *hdev, struct hid_field *field,
568 return 1; 401 return 1;
569 } 402 }
570 403
571 rmi_schedule_reset(hdev); 404 schedule_work(&data->reset_work);
572 return 1; 405 return 1;
573 } 406 }
574 407
@@ -576,637 +409,71 @@ static int rmi_event(struct hid_device *hdev, struct hid_field *field,
576} 409}
577 410
578#ifdef CONFIG_PM 411#ifdef CONFIG_PM
579static int rmi_set_sleep_mode(struct hid_device *hdev, int sleep_mode)
580{
581 struct rmi_data *data = hid_get_drvdata(hdev);
582 int ret;
583 u8 f01_ctrl0;
584
585 f01_ctrl0 = (data->f01_ctrl0 & ~0x3) | sleep_mode;
586
587 ret = rmi_write(hdev, data->f01.control_base_addr,
588 &f01_ctrl0);
589 if (ret) {
590 hid_err(hdev, "can not write sleep mode\n");
591 return ret;
592 }
593
594 return 0;
595}
596
597static int rmi_suspend(struct hid_device *hdev, pm_message_t message) 412static int rmi_suspend(struct hid_device *hdev, pm_message_t message)
598{ 413{
599 struct rmi_data *data = hid_get_drvdata(hdev); 414 struct rmi_data *data = hid_get_drvdata(hdev);
600 int ret; 415 struct rmi_device *rmi_dev = data->xport.rmi_dev;
601 u8 buf[RMI_F11_CTRL_REG_COUNT];
602
603 if (!(data->device_flags & RMI_DEVICE))
604 return 0;
605
606 ret = rmi_read_block(hdev, data->f11.control_base_addr, buf,
607 RMI_F11_CTRL_REG_COUNT);
608 if (ret)
609 hid_warn(hdev, "can not read F11 control registers\n");
610 else
611 memcpy(data->f11_ctrl_regs, buf, RMI_F11_CTRL_REG_COUNT);
612
613
614 if (!device_may_wakeup(hdev->dev.parent))
615 return rmi_set_sleep_mode(hdev, RMI_SLEEP_DEEP_SLEEP);
616
617 return 0;
618}
619
620static int rmi_post_reset(struct hid_device *hdev)
621{
622 struct rmi_data *data = hid_get_drvdata(hdev);
623 int ret; 416 int ret;
624 417
625 if (!(data->device_flags & RMI_DEVICE)) 418 if (!(data->device_flags & RMI_DEVICE))
626 return 0; 419 return 0;
627 420
628 ret = rmi_reset_attn_mode(hdev); 421 ret = rmi_driver_suspend(rmi_dev, false);
629 if (ret) { 422 if (ret) {
630 hid_err(hdev, "can not set rmi mode\n"); 423 hid_warn(hdev, "Failed to suspend device: %d\n", ret);
631 return ret; 424 return ret;
632 } 425 }
633 426
634 if (data->read_f11_ctrl_regs) { 427 return 0;
635 ret = rmi_write_block(hdev, data->f11.control_base_addr,
636 data->f11_ctrl_regs, RMI_F11_CTRL_REG_COUNT);
637 if (ret)
638 hid_warn(hdev,
639 "can not write F11 control registers after reset\n");
640 }
641
642 if (!device_may_wakeup(hdev->dev.parent)) {
643 ret = rmi_set_sleep_mode(hdev, RMI_SLEEP_NORMAL);
644 if (ret) {
645 hid_err(hdev, "can not write sleep mode\n");
646 return ret;
647 }
648 }
649
650 return ret;
651} 428}
652 429
653static int rmi_post_resume(struct hid_device *hdev) 430static int rmi_post_resume(struct hid_device *hdev)
654{ 431{
655 struct rmi_data *data = hid_get_drvdata(hdev); 432 struct rmi_data *data = hid_get_drvdata(hdev);
433 struct rmi_device *rmi_dev = data->xport.rmi_dev;
434 int ret;
656 435
657 if (!(data->device_flags & RMI_DEVICE)) 436 if (!(data->device_flags & RMI_DEVICE))
658 return 0; 437 return 0;
659 438
660 return rmi_reset_attn_mode(hdev); 439 ret = rmi_reset_attn_mode(hdev);
661} 440 if (ret)
662#endif /* CONFIG_PM */
663
664#define RMI4_MAX_PAGE 0xff
665#define RMI4_PAGE_SIZE 0x0100
666
667#define PDT_START_SCAN_LOCATION 0x00e9
668#define PDT_END_SCAN_LOCATION 0x0005
669#define RMI4_END_OF_PDT(id) ((id) == 0x00 || (id) == 0xff)
670
671struct pdt_entry {
672 u8 query_base_addr:8;
673 u8 command_base_addr:8;
674 u8 control_base_addr:8;
675 u8 data_base_addr:8;
676 u8 interrupt_source_count:3;
677 u8 bits3and4:2;
678 u8 function_version:2;
679 u8 bit7:1;
680 u8 function_number:8;
681} __attribute__((__packed__));
682
683static inline unsigned long rmi_gen_mask(unsigned irq_base, unsigned irq_count)
684{
685 return GENMASK(irq_count + irq_base - 1, irq_base);
686}
687
688static void rmi_register_function(struct rmi_data *data,
689 struct pdt_entry *pdt_entry, int page, unsigned interrupt_count)
690{
691 struct rmi_function *f = NULL;
692 u16 page_base = page << 8;
693
694 switch (pdt_entry->function_number) {
695 case 0x01:
696 f = &data->f01;
697 break;
698 case 0x11:
699 f = &data->f11;
700 break;
701 case 0x30:
702 f = &data->f30;
703 break;
704 }
705
706 if (f) {
707 f->page = page;
708 f->query_base_addr = page_base | pdt_entry->query_base_addr;
709 f->command_base_addr = page_base | pdt_entry->command_base_addr;
710 f->control_base_addr = page_base | pdt_entry->control_base_addr;
711 f->data_base_addr = page_base | pdt_entry->data_base_addr;
712 f->interrupt_base = interrupt_count;
713 f->interrupt_count = pdt_entry->interrupt_source_count;
714 f->irq_mask = rmi_gen_mask(f->interrupt_base,
715 f->interrupt_count);
716 data->interrupt_enable_mask |= f->irq_mask;
717 }
718}
719
720static int rmi_scan_pdt(struct hid_device *hdev)
721{
722 struct rmi_data *data = hid_get_drvdata(hdev);
723 struct pdt_entry entry;
724 int page;
725 bool page_has_function;
726 int i;
727 int retval;
728 int interrupt = 0;
729 u16 page_start, pdt_start , pdt_end;
730
731 hid_info(hdev, "Scanning PDT...\n");
732
733 for (page = 0; (page <= RMI4_MAX_PAGE); page++) {
734 page_start = RMI4_PAGE_SIZE * page;
735 pdt_start = page_start + PDT_START_SCAN_LOCATION;
736 pdt_end = page_start + PDT_END_SCAN_LOCATION;
737
738 page_has_function = false;
739 for (i = pdt_start; i >= pdt_end; i -= sizeof(entry)) {
740 retval = rmi_read_block(hdev, i, &entry, sizeof(entry));
741 if (retval) {
742 hid_err(hdev,
743 "Read of PDT entry at %#06x failed.\n",
744 i);
745 goto error_exit;
746 }
747
748 if (RMI4_END_OF_PDT(entry.function_number))
749 break;
750
751 page_has_function = true;
752
753 hid_info(hdev, "Found F%02X on page %#04x\n",
754 entry.function_number, page);
755
756 rmi_register_function(data, &entry, page, interrupt);
757 interrupt += entry.interrupt_source_count;
758 }
759
760 if (!page_has_function)
761 break;
762 }
763
764 hid_info(hdev, "%s: Done with PDT scan.\n", __func__);
765 retval = 0;
766
767error_exit:
768 return retval;
769}
770
771#define RMI_DEVICE_F01_BASIC_QUERY_LEN 11
772
773static int rmi_populate_f01(struct hid_device *hdev)
774{
775 struct rmi_data *data = hid_get_drvdata(hdev);
776 u8 basic_queries[RMI_DEVICE_F01_BASIC_QUERY_LEN];
777 u8 info[3];
778 int ret;
779 bool has_query42;
780 bool has_lts;
781 bool has_sensor_id;
782 bool has_ds4_queries = false;
783 bool has_build_id_query = false;
784 bool has_package_id_query = false;
785 u16 query_offset = data->f01.query_base_addr;
786 u16 prod_info_addr;
787 u8 ds4_query_len;
788
789 ret = rmi_read_block(hdev, query_offset, basic_queries,
790 RMI_DEVICE_F01_BASIC_QUERY_LEN);
791 if (ret) {
792 hid_err(hdev, "Can not read basic queries from Function 0x1.\n");
793 return ret;
794 }
795
796 has_lts = !!(basic_queries[0] & BIT(2));
797 has_sensor_id = !!(basic_queries[1] & BIT(3));
798 has_query42 = !!(basic_queries[1] & BIT(7));
799
800 query_offset += 11;
801 prod_info_addr = query_offset + 6;
802 query_offset += 10;
803
804 if (has_lts)
805 query_offset += 20;
806
807 if (has_sensor_id)
808 query_offset++;
809
810 if (has_query42) {
811 ret = rmi_read(hdev, query_offset, info);
812 if (ret) {
813 hid_err(hdev, "Can not read query42.\n");
814 return ret;
815 }
816 has_ds4_queries = !!(info[0] & BIT(0));
817 query_offset++;
818 }
819
820 if (has_ds4_queries) {
821 ret = rmi_read(hdev, query_offset, &ds4_query_len);
822 if (ret) {
823 hid_err(hdev, "Can not read DS4 Query length.\n");
824 return ret;
825 }
826 query_offset++;
827
828 if (ds4_query_len > 0) {
829 ret = rmi_read(hdev, query_offset, info);
830 if (ret) {
831 hid_err(hdev, "Can not read DS4 query.\n");
832 return ret;
833 }
834
835 has_package_id_query = !!(info[0] & BIT(0));
836 has_build_id_query = !!(info[0] & BIT(1));
837 }
838 }
839
840 if (has_package_id_query)
841 prod_info_addr++;
842
843 if (has_build_id_query) {
844 ret = rmi_read_block(hdev, prod_info_addr, info, 3);
845 if (ret) {
846 hid_err(hdev, "Can not read product info.\n");
847 return ret;
848 }
849
850 data->firmware_id = info[1] << 8 | info[0];
851 data->firmware_id += info[2] * 65536;
852 }
853
854 ret = rmi_read_block(hdev, data->f01.control_base_addr, info,
855 2);
856
857 if (ret) {
858 hid_err(hdev, "can not read f01 ctrl registers\n");
859 return ret;
860 }
861
862 data->f01_ctrl0 = info[0];
863
864 if (!info[1]) {
865 /*
866 * Do to a firmware bug in some touchpads the F01 interrupt
867 * enable control register will be cleared on reset.
868 * This will stop the touchpad from reporting data, so
869 * if F01 CTRL1 is 0 then we need to explicitly enable
870 * interrupts for the functions we want data for.
871 */
872 data->restore_interrupt_mask = true;
873
874 ret = rmi_write(hdev, data->f01.control_base_addr + 1,
875 &data->interrupt_enable_mask);
876 if (ret) {
877 hid_err(hdev, "can not write to control reg 1: %d.\n",
878 ret);
879 return ret;
880 }
881 }
882
883 return 0;
884}
885
886static int rmi_populate_f11(struct hid_device *hdev)
887{
888 struct rmi_data *data = hid_get_drvdata(hdev);
889 u8 buf[20];
890 int ret;
891 bool has_query9;
892 bool has_query10 = false;
893 bool has_query11;
894 bool has_query12;
895 bool has_query27;
896 bool has_query28;
897 bool has_query36 = false;
898 bool has_physical_props;
899 bool has_gestures;
900 bool has_rel;
901 bool has_data40 = false;
902 bool has_dribble = false;
903 bool has_palm_detect = false;
904 unsigned x_size, y_size;
905 u16 query_offset;
906
907 if (!data->f11.query_base_addr) {
908 hid_err(hdev, "No 2D sensor found, giving up.\n");
909 return -ENODEV;
910 }
911
912 /* query 0 contains some useful information */
913 ret = rmi_read(hdev, data->f11.query_base_addr, buf);
914 if (ret) {
915 hid_err(hdev, "can not get query 0: %d.\n", ret);
916 return ret;
917 }
918 has_query9 = !!(buf[0] & BIT(3));
919 has_query11 = !!(buf[0] & BIT(4));
920 has_query12 = !!(buf[0] & BIT(5));
921 has_query27 = !!(buf[0] & BIT(6));
922 has_query28 = !!(buf[0] & BIT(7));
923
924 /* query 1 to get the max number of fingers */
925 ret = rmi_read(hdev, data->f11.query_base_addr + 1, buf);
926 if (ret) {
927 hid_err(hdev, "can not get NumberOfFingers: %d.\n", ret);
928 return ret;
929 }
930 data->max_fingers = (buf[0] & 0x07) + 1;
931 if (data->max_fingers > 5)
932 data->max_fingers = 10;
933
934 data->f11.report_size = data->max_fingers * 5 +
935 DIV_ROUND_UP(data->max_fingers, 4);
936
937 if (!(buf[0] & BIT(4))) {
938 hid_err(hdev, "No absolute events, giving up.\n");
939 return -ENODEV;
940 }
941
942 has_rel = !!(buf[0] & BIT(3));
943 has_gestures = !!(buf[0] & BIT(5));
944
945 ret = rmi_read(hdev, data->f11.query_base_addr + 5, buf);
946 if (ret) {
947 hid_err(hdev, "can not get absolute data sources: %d.\n", ret);
948 return ret; 441 return ret;
949 }
950
951 has_dribble = !!(buf[0] & BIT(4));
952
953 /*
954 * At least 4 queries are guaranteed to be present in F11
955 * +1 for query 5 which is present since absolute events are
956 * reported and +1 for query 12.
957 */
958 query_offset = 6;
959
960 if (has_rel)
961 ++query_offset; /* query 6 is present */
962
963 if (has_gestures) {
964 /* query 8 to find out if query 10 exists */
965 ret = rmi_read(hdev,
966 data->f11.query_base_addr + query_offset + 1, buf);
967 if (ret) {
968 hid_err(hdev, "can not read gesture information: %d.\n",
969 ret);
970 return ret;
971 }
972 has_palm_detect = !!(buf[0] & BIT(0));
973 has_query10 = !!(buf[0] & BIT(2));
974
975 query_offset += 2; /* query 7 and 8 are present */
976 }
977
978 if (has_query9)
979 ++query_offset;
980
981 if (has_query10)
982 ++query_offset;
983
984 if (has_query11)
985 ++query_offset;
986
987 /* query 12 to know if the physical properties are reported */
988 if (has_query12) {
989 ret = rmi_read(hdev, data->f11.query_base_addr
990 + query_offset, buf);
991 if (ret) {
992 hid_err(hdev, "can not get query 12: %d.\n", ret);
993 return ret;
994 }
995 has_physical_props = !!(buf[0] & BIT(5));
996
997 if (has_physical_props) {
998 query_offset += 1;
999 ret = rmi_read_block(hdev,
1000 data->f11.query_base_addr
1001 + query_offset, buf, 4);
1002 if (ret) {
1003 hid_err(hdev, "can not read query 15-18: %d.\n",
1004 ret);
1005 return ret;
1006 }
1007
1008 x_size = buf[0] | (buf[1] << 8);
1009 y_size = buf[2] | (buf[3] << 8);
1010
1011 data->x_size_mm = DIV_ROUND_CLOSEST(x_size, 10);
1012 data->y_size_mm = DIV_ROUND_CLOSEST(y_size, 10);
1013
1014 hid_info(hdev, "%s: size in mm: %d x %d\n",
1015 __func__, data->x_size_mm, data->y_size_mm);
1016
1017 /*
1018 * query 15 - 18 contain the size of the sensor
1019 * and query 19 - 26 contain bezel dimensions
1020 */
1021 query_offset += 12;
1022 }
1023 }
1024
1025 if (has_query27)
1026 ++query_offset;
1027 442
1028 if (has_query28) { 443 ret = rmi_driver_resume(rmi_dev, false);
1029 ret = rmi_read(hdev, data->f11.query_base_addr
1030 + query_offset, buf);
1031 if (ret) {
1032 hid_err(hdev, "can not get query 28: %d.\n", ret);
1033 return ret;
1034 }
1035
1036 has_query36 = !!(buf[0] & BIT(6));
1037 }
1038
1039 if (has_query36) {
1040 query_offset += 2;
1041 ret = rmi_read(hdev, data->f11.query_base_addr
1042 + query_offset, buf);
1043 if (ret) {
1044 hid_err(hdev, "can not get query 36: %d.\n", ret);
1045 return ret;
1046 }
1047
1048 has_data40 = !!(buf[0] & BIT(5));
1049 }
1050
1051
1052 if (has_data40)
1053 data->f11.report_size += data->max_fingers * 2;
1054
1055 ret = rmi_read_block(hdev, data->f11.control_base_addr,
1056 data->f11_ctrl_regs, RMI_F11_CTRL_REG_COUNT);
1057 if (ret) { 444 if (ret) {
1058 hid_err(hdev, "can not read ctrl block of size 11: %d.\n", ret); 445 hid_warn(hdev, "Failed to resume device: %d\n", ret);
1059 return ret; 446 return ret;
1060 } 447 }
1061 448
1062 /* data->f11_ctrl_regs now contains valid register data */
1063 data->read_f11_ctrl_regs = true;
1064
1065 data->max_x = data->f11_ctrl_regs[6] | (data->f11_ctrl_regs[7] << 8);
1066 data->max_y = data->f11_ctrl_regs[8] | (data->f11_ctrl_regs[9] << 8);
1067
1068 if (has_dribble) {
1069 data->f11_ctrl_regs[0] = data->f11_ctrl_regs[0] & ~BIT(6);
1070 ret = rmi_write(hdev, data->f11.control_base_addr,
1071 data->f11_ctrl_regs);
1072 if (ret) {
1073 hid_err(hdev, "can not write to control reg 0: %d.\n",
1074 ret);
1075 return ret;
1076 }
1077 }
1078
1079 if (has_palm_detect) {
1080 data->f11_ctrl_regs[11] = data->f11_ctrl_regs[11] & ~BIT(0);
1081 ret = rmi_write(hdev, data->f11.control_base_addr + 11,
1082 &data->f11_ctrl_regs[11]);
1083 if (ret) {
1084 hid_err(hdev, "can not write to control reg 11: %d.\n",
1085 ret);
1086 return ret;
1087 }
1088 }
1089
1090 return 0;
1091}
1092
1093static int rmi_populate_f30(struct hid_device *hdev)
1094{
1095 struct rmi_data *data = hid_get_drvdata(hdev);
1096 u8 buf[20];
1097 int ret;
1098 bool has_gpio, has_led;
1099 unsigned bytes_per_ctrl;
1100 u8 ctrl2_addr;
1101 int ctrl2_3_length;
1102 int i;
1103
1104 /* function F30 is for physical buttons */
1105 if (!data->f30.query_base_addr) {
1106 hid_err(hdev, "No GPIO/LEDs found, giving up.\n");
1107 return -ENODEV;
1108 }
1109
1110 ret = rmi_read_block(hdev, data->f30.query_base_addr, buf, 2);
1111 if (ret) {
1112 hid_err(hdev, "can not get F30 query registers: %d.\n", ret);
1113 return ret;
1114 }
1115
1116 has_gpio = !!(buf[0] & BIT(3));
1117 has_led = !!(buf[0] & BIT(2));
1118 data->gpio_led_count = buf[1] & 0x1f;
1119
1120 /* retrieve ctrl 2 & 3 registers */
1121 bytes_per_ctrl = (data->gpio_led_count + 7) / 8;
1122 /* Ctrl0 is present only if both has_gpio and has_led are set*/
1123 ctrl2_addr = (has_gpio && has_led) ? bytes_per_ctrl : 0;
1124 /* Ctrl1 is always be present */
1125 ctrl2_addr += bytes_per_ctrl;
1126 ctrl2_3_length = 2 * bytes_per_ctrl;
1127
1128 data->f30.report_size = bytes_per_ctrl;
1129
1130 ret = rmi_read_block(hdev, data->f30.control_base_addr + ctrl2_addr,
1131 buf, ctrl2_3_length);
1132 if (ret) {
1133 hid_err(hdev, "can not read ctrl 2&3 block of size %d: %d.\n",
1134 ctrl2_3_length, ret);
1135 return ret;
1136 }
1137
1138 for (i = 0; i < data->gpio_led_count; i++) {
1139 int byte_position = i >> 3;
1140 int bit_position = i & 0x07;
1141 u8 dir_byte = buf[byte_position];
1142 u8 data_byte = buf[byte_position + bytes_per_ctrl];
1143 bool dir = (dir_byte >> bit_position) & BIT(0);
1144 bool dat = (data_byte >> bit_position) & BIT(0);
1145
1146 if (dir == 0) {
1147 /* input mode */
1148 if (dat) {
1149 /* actual buttons have pull up resistor */
1150 data->button_count++;
1151 set_bit(i, &data->button_mask);
1152 set_bit(i, &data->button_state_mask);
1153 }
1154 }
1155
1156 }
1157
1158 return 0; 449 return 0;
1159} 450}
451#endif /* CONFIG_PM */
1160 452
1161static int rmi_populate(struct hid_device *hdev) 453static int rmi_hid_reset(struct rmi_transport_dev *xport, u16 reset_addr)
1162{ 454{
1163 struct rmi_data *data = hid_get_drvdata(hdev); 455 struct rmi_data *data = container_of(xport, struct rmi_data, xport);
1164 int ret; 456 struct hid_device *hdev = data->hdev;
1165
1166 ret = rmi_scan_pdt(hdev);
1167 if (ret) {
1168 hid_err(hdev, "PDT scan failed with code %d.\n", ret);
1169 return ret;
1170 }
1171
1172 ret = rmi_populate_f01(hdev);
1173 if (ret) {
1174 hid_err(hdev, "Error while initializing F01 (%d).\n", ret);
1175 return ret;
1176 }
1177
1178 ret = rmi_populate_f11(hdev);
1179 if (ret) {
1180 hid_err(hdev, "Error while initializing F11 (%d).\n", ret);
1181 return ret;
1182 }
1183
1184 if (!(data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)) {
1185 ret = rmi_populate_f30(hdev);
1186 if (ret)
1187 hid_warn(hdev, "Error while initializing F30 (%d).\n", ret);
1188 }
1189 457
1190 return 0; 458 return rmi_reset_attn_mode(hdev);
1191} 459}
1192 460
1193static int rmi_input_configured(struct hid_device *hdev, struct hid_input *hi) 461static int rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
1194{ 462{
1195 struct rmi_data *data = hid_get_drvdata(hdev); 463 struct rmi_data *data = hid_get_drvdata(hdev);
1196 struct input_dev *input = hi->input; 464 struct input_dev *input = hi->input;
1197 int ret; 465 int ret = 0;
1198 int res_x, res_y, i; 466
467 if (!(data->device_flags & RMI_DEVICE))
468 return 0;
1199 469
1200 data->input = input; 470 data->xport.input = input;
1201 471
1202 hid_dbg(hdev, "Opening low level driver\n"); 472 hid_dbg(hdev, "Opening low level driver\n");
1203 ret = hid_hw_open(hdev); 473 ret = hid_hw_open(hdev);
1204 if (ret) 474 if (ret)
1205 return ret; 475 return ret;
1206 476
1207 if (!(data->device_flags & RMI_DEVICE))
1208 return 0;
1209
1210 /* Allow incoming hid reports */ 477 /* Allow incoming hid reports */
1211 hid_device_io_start(hdev); 478 hid_device_io_start(hdev);
1212 479
@@ -1222,40 +489,10 @@ static int rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
1222 goto exit; 489 goto exit;
1223 } 490 }
1224 491
1225 ret = rmi_populate(hdev); 492 ret = rmi_register_transport_device(&data->xport);
1226 if (ret) 493 if (ret < 0) {
1227 goto exit; 494 dev_err(&hdev->dev, "failed to register transport driver\n");
1228
1229 hid_info(hdev, "firmware id: %ld\n", data->firmware_id);
1230
1231 __set_bit(EV_ABS, input->evbit);
1232 input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->max_x, 0, 0);
1233 input_set_abs_params(input, ABS_MT_POSITION_Y, 1, data->max_y, 0, 0);
1234
1235 if (data->x_size_mm && data->y_size_mm) {
1236 res_x = (data->max_x - 1) / data->x_size_mm;
1237 res_y = (data->max_y - 1) / data->y_size_mm;
1238
1239 input_abs_set_res(input, ABS_MT_POSITION_X, res_x);
1240 input_abs_set_res(input, ABS_MT_POSITION_Y, res_y);
1241 }
1242
1243 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
1244 input_set_abs_params(input, ABS_MT_PRESSURE, 0, 0xff, 0, 0);
1245 input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 0x0f, 0, 0);
1246 input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 0x0f, 0, 0);
1247
1248 ret = input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER);
1249 if (ret < 0)
1250 goto exit; 495 goto exit;
1251
1252 if (data->button_count) {
1253 __set_bit(EV_KEY, input->evbit);
1254 for (i = 0; i < data->button_count; i++)
1255 __set_bit(BTN_LEFT + i, input->keybit);
1256
1257 if (data->button_count == 1)
1258 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1259 } 496 }
1260 497
1261 set_bit(RMI_STARTED, &data->flags); 498 set_bit(RMI_STARTED, &data->flags);
@@ -1304,6 +541,71 @@ static int rmi_check_valid_report_id(struct hid_device *hdev, unsigned type,
1304 return 0; 541 return 0;
1305} 542}
1306 543
544static struct rmi_device_platform_data rmi_hid_pdata = {
545 .sensor_pdata = {
546 .sensor_type = rmi_sensor_touchpad,
547 .axis_align.flip_y = true,
548 .dribble = RMI_REG_STATE_ON,
549 .palm_detect = RMI_REG_STATE_OFF,
550 },
551};
552
553static const struct rmi_transport_ops hid_rmi_ops = {
554 .write_block = rmi_hid_write_block,
555 .read_block = rmi_hid_read_block,
556 .reset = rmi_hid_reset,
557};
558
559static void rmi_irq_teardown(void *data)
560{
561 struct rmi_data *hdata = data;
562 struct irq_domain *domain = hdata->domain;
563
564 if (!domain)
565 return;
566
567 irq_dispose_mapping(irq_find_mapping(domain, 0));
568
569 irq_domain_remove(domain);
570 hdata->domain = NULL;
571 hdata->rmi_irq = 0;
572}
573
574static int rmi_irq_map(struct irq_domain *h, unsigned int virq,
575 irq_hw_number_t hw_irq_num)
576{
577 irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
578
579 return 0;
580}
581
582static const struct irq_domain_ops rmi_irq_ops = {
583 .map = rmi_irq_map,
584};
585
586static int rmi_setup_irq_domain(struct hid_device *hdev)
587{
588 struct rmi_data *hdata = hid_get_drvdata(hdev);
589 int ret;
590
591 hdata->domain = irq_domain_create_linear(hdev->dev.fwnode, 1,
592 &rmi_irq_ops, hdata);
593 if (!hdata->domain)
594 return -ENOMEM;
595
596 ret = devm_add_action_or_reset(&hdev->dev, &rmi_irq_teardown, hdata);
597 if (ret)
598 return ret;
599
600 hdata->rmi_irq = irq_create_mapping(hdata->domain, 0);
601 if (hdata->rmi_irq <= 0) {
602 hid_err(hdev, "Can't allocate an IRQ\n");
603 return hdata->rmi_irq < 0 ? hdata->rmi_irq : -ENXIO;
604 }
605
606 return 0;
607}
608
1307static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id) 609static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
1308{ 610{
1309 struct rmi_data *data = NULL; 611 struct rmi_data *data = NULL;
@@ -1365,8 +667,8 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
1365 667
1366 data->writeReport = devm_kzalloc(&hdev->dev, alloc_size, GFP_KERNEL); 668 data->writeReport = devm_kzalloc(&hdev->dev, alloc_size, GFP_KERNEL);
1367 if (!data->writeReport) { 669 if (!data->writeReport) {
1368 ret = -ENOMEM; 670 hid_err(hdev, "failed to allocate buffer for HID reports\n");
1369 return ret; 671 return -ENOMEM;
1370 } 672 }
1371 673
1372 data->readReport = data->writeReport + data->output_report_size; 674 data->readReport = data->writeReport + data->output_report_size;
@@ -1375,6 +677,21 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
1375 677
1376 mutex_init(&data->page_mutex); 678 mutex_init(&data->page_mutex);
1377 679
680 ret = rmi_setup_irq_domain(hdev);
681 if (ret) {
682 hid_err(hdev, "failed to allocate IRQ domain\n");
683 return ret;
684 }
685
686 if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)
687 rmi_hid_pdata.f30_data.disable = true;
688
689 data->xport.dev = hdev->dev.parent;
690 data->xport.pdata = rmi_hid_pdata;
691 data->xport.pdata.irq = data->rmi_irq;
692 data->xport.proto_name = "hid";
693 data->xport.ops = &hid_rmi_ops;
694
1378start: 695start:
1379 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 696 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1380 if (ret) { 697 if (ret) {
@@ -1382,17 +699,6 @@ start:
1382 return ret; 699 return ret;
1383 } 700 }
1384 701
1385 if ((data->device_flags & RMI_DEVICE) &&
1386 !test_bit(RMI_STARTED, &data->flags))
1387 /*
1388 * The device maybe in the bootloader if rmi_input_configured
1389 * failed to find F11 in the PDT. Print an error, but don't
1390 * return an error from rmi_probe so that hidraw will be
1391 * accessible from userspace. That way a userspace tool
1392 * can be used to reload working firmware on the touchpad.
1393 */
1394 hid_err(hdev, "Device failed to be properly configured\n");
1395
1396 return 0; 702 return 0;
1397} 703}
1398 704
@@ -1401,6 +707,8 @@ static void rmi_remove(struct hid_device *hdev)
1401 struct rmi_data *hdata = hid_get_drvdata(hdev); 707 struct rmi_data *hdata = hid_get_drvdata(hdev);
1402 708
1403 clear_bit(RMI_STARTED, &hdata->flags); 709 clear_bit(RMI_STARTED, &hdata->flags);
710 cancel_work_sync(&hdata->reset_work);
711 rmi_unregister_transport_device(&hdata->xport);
1404 712
1405 hid_hw_stop(hdev); 713 hid_hw_stop(hdev);
1406} 714}
@@ -1408,6 +716,7 @@ static void rmi_remove(struct hid_device *hdev)
1408static const struct hid_device_id rmi_id[] = { 716static const struct hid_device_id rmi_id[] = {
1409 { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14), 717 { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14),
1410 .driver_data = RMI_DEVICE_HAS_PHYS_BUTTONS }, 718 .driver_data = RMI_DEVICE_HAS_PHYS_BUTTONS },
719 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
1411 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_RMI, HID_ANY_ID, HID_ANY_ID) }, 720 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_RMI, HID_ANY_ID, HID_ANY_ID) },
1412 { } 721 { }
1413}; 722};
@@ -1425,7 +734,7 @@ static struct hid_driver rmi_driver = {
1425#ifdef CONFIG_PM 734#ifdef CONFIG_PM
1426 .suspend = rmi_suspend, 735 .suspend = rmi_suspend,
1427 .resume = rmi_post_resume, 736 .resume = rmi_post_resume,
1428 .reset_resume = rmi_post_reset, 737 .reset_resume = rmi_post_resume,
1429#endif 738#endif
1430}; 739};
1431 740
diff --git a/drivers/hid/intel-ish-hid/ipc/hw-ish-regs.h b/drivers/hid/intel-ish-hid/ipc/hw-ish-regs.h
index ab68afcba2a2..a5897b9c0956 100644
--- a/drivers/hid/intel-ish-hid/ipc/hw-ish-regs.h
+++ b/drivers/hid/intel-ish-hid/ipc/hw-ish-regs.h
@@ -111,6 +111,14 @@
111#define IPC_ILUP_BIT (1<<IPC_ILUP_OFFS) 111#define IPC_ILUP_BIT (1<<IPC_ILUP_OFFS)
112 112
113/* 113/*
114 * ISH FW status bits in ISH FW Status Register
115 */
116#define IPC_ISH_FWSTS_SHIFT 12
117#define IPC_ISH_FWSTS_MASK GENMASK(15, 12)
118#define IPC_GET_ISH_FWSTS(status) \
119 (((status) & IPC_ISH_FWSTS_MASK) >> IPC_ISH_FWSTS_SHIFT)
120
121/*
114 * FW status bits (relevant) 122 * FW status bits (relevant)
115 */ 123 */
116#define IPC_FWSTS_ILUP 0x1 124#define IPC_FWSTS_ILUP 0x1
diff --git a/drivers/hid/intel-ish-hid/ipc/hw-ish.h b/drivers/hid/intel-ish-hid/ipc/hw-ish.h
index 46615a03e78f..fd34307a7a70 100644
--- a/drivers/hid/intel-ish-hid/ipc/hw-ish.h
+++ b/drivers/hid/intel-ish-hid/ipc/hw-ish.h
@@ -61,6 +61,18 @@ struct ish_hw {
61 void __iomem *mem_addr; 61 void __iomem *mem_addr;
62}; 62};
63 63
64/*
65 * ISH FW status type
66 */
67enum {
68 FWSTS_AFTER_RESET = 0,
69 FWSTS_WAIT_FOR_HOST = 4,
70 FWSTS_START_KERNEL_DMA = 5,
71 FWSTS_FW_IS_RUNNING = 7,
72 FWSTS_SENSOR_APP_LOADED = 8,
73 FWSTS_SENSOR_APP_RUNNING = 15
74};
75
64#define to_ish_hw(dev) (struct ish_hw *)((dev)->hw) 76#define to_ish_hw(dev) (struct ish_hw *)((dev)->hw)
65 77
66irqreturn_t ish_irq_handler(int irq, void *dev_id); 78irqreturn_t ish_irq_handler(int irq, void *dev_id);
diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
index 20d647d2dd2c..8df81dc84529 100644
--- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
+++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
@@ -24,7 +24,6 @@
24#include <linux/sched.h> 24#include <linux/sched.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/workqueue.h> 26#include <linux/workqueue.h>
27#include <linux/miscdevice.h>
28#define CREATE_TRACE_POINTS 27#define CREATE_TRACE_POINTS
29#include <trace/events/intel_ish.h> 28#include <trace/events/intel_ish.h>
30#include "ishtp-dev.h" 29#include "ishtp-dev.h"
@@ -47,7 +46,8 @@ MODULE_DEVICE_TABLE(pci, ish_pci_tbl);
47 * 46 *
48 * Callback to direct log messages to Linux trace buffers 47 * Callback to direct log messages to Linux trace buffers
49 */ 48 */
50static void ish_event_tracer(struct ishtp_device *dev, char *format, ...) 49static __printf(2, 3)
50void ish_event_tracer(struct ishtp_device *dev, const char *format, ...)
51{ 51{
52 if (trace_ishtp_dump_enabled()) { 52 if (trace_ishtp_dump_enabled()) {
53 va_list args; 53 va_list args;
@@ -205,12 +205,15 @@ static void ish_remove(struct pci_dev *pdev)
205#ifdef CONFIG_PM 205#ifdef CONFIG_PM
206static struct device *ish_resume_device; 206static struct device *ish_resume_device;
207 207
208/* 50ms to get resume response */
209#define WAIT_FOR_RESUME_ACK_MS 50
210
208/** 211/**
209 * ish_resume_handler() - Work function to complete resume 212 * ish_resume_handler() - Work function to complete resume
210 * @work: work struct 213 * @work: work struct
211 * 214 *
212 * The resume work function to complete resume function asynchronously. 215 * The resume work function to complete resume function asynchronously.
213 * There are two types of platforms, one where ISH is not powered off, 216 * There are two resume paths, one where ISH is not powered off,
214 * in that case a simple resume message is enough, others we need 217 * in that case a simple resume message is enough, others we need
215 * a reset sequence. 218 * a reset sequence.
216 */ 219 */
@@ -218,20 +221,31 @@ static void ish_resume_handler(struct work_struct *work)
218{ 221{
219 struct pci_dev *pdev = to_pci_dev(ish_resume_device); 222 struct pci_dev *pdev = to_pci_dev(ish_resume_device);
220 struct ishtp_device *dev = pci_get_drvdata(pdev); 223 struct ishtp_device *dev = pci_get_drvdata(pdev);
224 uint32_t fwsts;
221 int ret; 225 int ret;
222 226
223 ishtp_send_resume(dev); 227 /* Get ISH FW status */
228 fwsts = IPC_GET_ISH_FWSTS(dev->ops->get_fw_status(dev));
224 229
225 /* 50 ms to get resume response */ 230 /*
226 if (dev->resume_flag) 231 * If currently, in ISH FW, sensor app is loaded or beyond that,
227 ret = wait_event_interruptible_timeout(dev->resume_wait, 232 * it means ISH isn't powered off, in this case, send a resume message.
228 !dev->resume_flag, 233 */
229 msecs_to_jiffies(50)); 234 if (fwsts >= FWSTS_SENSOR_APP_LOADED) {
235 ishtp_send_resume(dev);
236
237 /* Waiting to get resume response */
238 if (dev->resume_flag)
239 ret = wait_event_interruptible_timeout(dev->resume_wait,
240 !dev->resume_flag,
241 msecs_to_jiffies(WAIT_FOR_RESUME_ACK_MS));
242 }
230 243
231 /* 244 /*
232 * If no resume response. This platform is not S0ix compatible 245 * If in ISH FW, sensor app isn't loaded yet, or no resume response.
233 * So on resume full reboot of ISH processor will happen, so 246 * That means this platform is not S0ix compatible, or something is
234 * need to go through init sequence again 247 * wrong with ISH FW. So on resume, full reboot of ISH processor will
248 * happen, so need to go through init sequence again.
235 */ 249 */
236 if (dev->resume_flag) 250 if (dev->resume_flag)
237 ish_init(dev); 251 ish_init(dev);
diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.c b/drivers/hid/intel-ish-hid/ishtp-hid.c
index 277983aa1d90..cd23903ddcf1 100644
--- a/drivers/hid/intel-ish-hid/ishtp-hid.c
+++ b/drivers/hid/intel-ish-hid/ishtp-hid.c
@@ -208,7 +208,7 @@ int ishtp_hid_probe(unsigned int cur_hid_dev,
208 hid->version = le16_to_cpu(ISH_HID_VERSION); 208 hid->version = le16_to_cpu(ISH_HID_VERSION);
209 hid->vendor = le16_to_cpu(ISH_HID_VENDOR); 209 hid->vendor = le16_to_cpu(ISH_HID_VENDOR);
210 hid->product = le16_to_cpu(ISH_HID_PRODUCT); 210 hid->product = le16_to_cpu(ISH_HID_PRODUCT);
211 snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX", "hid-ishtp", 211 snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-ishtp",
212 hid->vendor, hid->product); 212 hid->vendor, hid->product);
213 213
214 rv = hid_add_device(hid); 214 rv = hid_add_device(hid);
diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c
index f4cbc744e657..5f382fedc2ab 100644
--- a/drivers/hid/intel-ish-hid/ishtp/bus.c
+++ b/drivers/hid/intel-ish-hid/ishtp/bus.c
@@ -358,7 +358,7 @@ static void ishtp_cl_dev_release(struct device *dev)
358 kfree(to_ishtp_cl_device(dev)); 358 kfree(to_ishtp_cl_device(dev));
359} 359}
360 360
361static struct device_type ishtp_cl_device_type = { 361static const struct device_type ishtp_cl_device_type = {
362 .release = ishtp_cl_dev_release, 362 .release = ishtp_cl_dev_release,
363}; 363};
364 364
diff --git a/drivers/hid/intel-ish-hid/ishtp/hbm.c b/drivers/hid/intel-ish-hid/ishtp/hbm.c
index 59460b66e689..b7213608ce43 100644
--- a/drivers/hid/intel-ish-hid/ishtp/hbm.c
+++ b/drivers/hid/intel-ish-hid/ishtp/hbm.c
@@ -19,7 +19,6 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/wait.h> 20#include <linux/wait.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/miscdevice.h>
23#include "ishtp-dev.h" 22#include "ishtp-dev.h"
24#include "hbm.h" 23#include "hbm.h"
25#include "client.h" 24#include "client.h"
diff --git a/drivers/hid/intel-ish-hid/ishtp/init.c b/drivers/hid/intel-ish-hid/ishtp/init.c
index ac364418e17c..d27e03526acd 100644
--- a/drivers/hid/intel-ish-hid/ishtp/init.c
+++ b/drivers/hid/intel-ish-hid/ishtp/init.c
@@ -16,7 +16,6 @@
16#include <linux/export.h> 16#include <linux/export.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/miscdevice.h>
20#include "ishtp-dev.h" 19#include "ishtp-dev.h"
21#include "hbm.h" 20#include "hbm.h"
22#include "client.h" 21#include "client.h"
diff --git a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h
index a94f9a8a96a0..6a6d927b78b0 100644
--- a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h
+++ b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h
@@ -238,7 +238,8 @@ struct ishtp_device {
238 uint64_t ishtp_host_dma_rx_buf_phys; 238 uint64_t ishtp_host_dma_rx_buf_phys;
239 239
240 /* Dump to trace buffers if enabled*/ 240 /* Dump to trace buffers if enabled*/
241 void (*print_log)(struct ishtp_device *dev, char *format, ...); 241 __printf(2, 3) void (*print_log)(struct ishtp_device *dev,
242 const char *format, ...);
242 243
243 /* Debug stats */ 244 /* Debug stats */
244 unsigned int ipc_rx_cnt; 245 unsigned int ipc_rx_cnt;
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 333108ef18cf..961bc6fdd2d9 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -43,7 +43,6 @@
43 */ 43 */
44 44
45#define DRIVER_DESC "USB HID core driver" 45#define DRIVER_DESC "USB HID core driver"
46#define DRIVER_LICENSE "GPL"
47 46
48/* 47/*
49 * Module parameters. 48 * Module parameters.
@@ -1660,4 +1659,4 @@ MODULE_AUTHOR("Andreas Gal");
1660MODULE_AUTHOR("Vojtech Pavlik"); 1659MODULE_AUTHOR("Vojtech Pavlik");
1661MODULE_AUTHOR("Jiri Kosina"); 1660MODULE_AUTHOR("Jiri Kosina");
1662MODULE_DESCRIPTION(DRIVER_DESC); 1661MODULE_DESCRIPTION(DRIVER_DESC);
1663MODULE_LICENSE(DRIVER_LICENSE); 1662MODULE_LICENSE("GPL");
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 30a2977e2645..d6847a664446 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -85,7 +85,7 @@ static const struct hid_blacklist {
85 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_WIIU, HID_QUIRK_MULTI_INPUT }, 85 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_WIIU, HID_QUIRK_MULTI_INPUT },
86 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3, HID_QUIRK_MULTI_INPUT }, 86 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3, HID_QUIRK_MULTI_INPUT },
87 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR, HID_QUIRK_MULTI_INPUT }, 87 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR, HID_QUIRK_MULTI_INPUT },
88 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE, HID_QUIRK_MULTI_INPUT }, 88 { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE1, HID_QUIRK_MULTI_INPUT },
89 { USB_VENDOR_ID_ELAN, HID_ANY_ID, HID_QUIRK_ALWAYS_POLL }, 89 { USB_VENDOR_ID_ELAN, HID_ANY_ID, HID_QUIRK_ALWAYS_POLL },
90 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 90 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
91 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS }, 91 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS },
@@ -103,12 +103,6 @@ static const struct hid_blacklist {
103 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_SURFACE_PRO_2, HID_QUIRK_NO_INIT_REPORTS }, 103 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_SURFACE_PRO_2, HID_QUIRK_NO_INIT_REPORTS },
104 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_2, HID_QUIRK_NO_INIT_REPORTS }, 104 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_2, HID_QUIRK_NO_INIT_REPORTS },
105 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TOUCH_COVER_2, HID_QUIRK_NO_INIT_REPORTS }, 105 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TOUCH_COVER_2, HID_QUIRK_NO_INIT_REPORTS },
106 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3, HID_QUIRK_NO_INIT_REPORTS },
107 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2, HID_QUIRK_NO_INIT_REPORTS },
108 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP, HID_QUIRK_NO_INIT_REPORTS },
109 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4, HID_QUIRK_NO_INIT_REPORTS },
110 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_2, HID_QUIRK_NO_INIT_REPORTS },
111 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_JP, HID_QUIRK_NO_INIT_REPORTS },
112 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER, HID_QUIRK_NO_INIT_REPORTS }, 106 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER, HID_QUIRK_NO_INIT_REPORTS },
113 { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS }, 107 { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS },
114 { USB_VENDOR_ID_NEXIO, USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750, HID_QUIRK_NO_INIT_REPORTS }, 108 { USB_VENDOR_ID_NEXIO, USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750, HID_QUIRK_NO_INIT_REPORTS },
@@ -297,7 +291,7 @@ static void usbhid_remove_all_dquirks(void)
297 291
298} 292}
299 293
300/** 294/**
301 * usbhid_quirks_init: apply USB HID quirks specified at module load time 295 * usbhid_quirks_init: apply USB HID quirks specified at module load time
302 */ 296 */
303int usbhid_quirks_init(char **quirks_param) 297int usbhid_quirks_init(char **quirks_param)
@@ -361,7 +355,7 @@ static const struct hid_blacklist *usbhid_exists_squirk(const u16 idVendor,
361 355
362 if (bl_entry != NULL) 356 if (bl_entry != NULL)
363 dbg_hid("Found squirk 0x%x for USB HID vendor 0x%hx prod 0x%hx\n", 357 dbg_hid("Found squirk 0x%x for USB HID vendor 0x%hx prod 0x%hx\n",
364 bl_entry->quirks, bl_entry->idVendor, 358 bl_entry->quirks, bl_entry->idVendor,
365 bl_entry->idProduct); 359 bl_entry->idProduct);
366 return bl_entry; 360 return bl_entry;
367} 361}
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
index 9a332e683db7..7fb2d1e4f5dd 100644
--- a/drivers/hid/usbhid/usbkbd.c
+++ b/drivers/hid/usbhid/usbkbd.c
@@ -39,11 +39,10 @@
39#define DRIVER_VERSION "" 39#define DRIVER_VERSION ""
40#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" 40#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
41#define DRIVER_DESC "USB HID Boot Protocol keyboard driver" 41#define DRIVER_DESC "USB HID Boot Protocol keyboard driver"
42#define DRIVER_LICENSE "GPL"
43 42
44MODULE_AUTHOR(DRIVER_AUTHOR); 43MODULE_AUTHOR(DRIVER_AUTHOR);
45MODULE_DESCRIPTION(DRIVER_DESC); 44MODULE_DESCRIPTION(DRIVER_DESC);
46MODULE_LICENSE(DRIVER_LICENSE); 45MODULE_LICENSE("GPL");
47 46
48static const unsigned char usb_kbd_keycode[256] = { 47static const unsigned char usb_kbd_keycode[256] = {
49 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 48 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
diff --git a/drivers/hid/usbhid/usbmouse.c b/drivers/hid/usbhid/usbmouse.c
index bf16d72dc370..dd911c5241d8 100644
--- a/drivers/hid/usbhid/usbmouse.c
+++ b/drivers/hid/usbhid/usbmouse.c
@@ -42,11 +42,10 @@
42#define DRIVER_VERSION "v1.6" 42#define DRIVER_VERSION "v1.6"
43#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" 43#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
44#define DRIVER_DESC "USB HID Boot Protocol mouse driver" 44#define DRIVER_DESC "USB HID Boot Protocol mouse driver"
45#define DRIVER_LICENSE "GPL"
46 45
47MODULE_AUTHOR(DRIVER_AUTHOR); 46MODULE_AUTHOR(DRIVER_AUTHOR);
48MODULE_DESCRIPTION(DRIVER_DESC); 47MODULE_DESCRIPTION(DRIVER_DESC);
49MODULE_LICENSE(DRIVER_LICENSE); 48MODULE_LICENSE("GPL");
50 49
51struct usb_mouse { 50struct usb_mouse {
52 char name[128]; 51 char name[128];
diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h
index d303e413306d..38ee2125412f 100644
--- a/drivers/hid/wacom.h
+++ b/drivers/hid/wacom.h
@@ -102,7 +102,6 @@
102#define DRIVER_VERSION "v2.00" 102#define DRIVER_VERSION "v2.00"
103#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" 103#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
104#define DRIVER_DESC "USB Wacom tablet driver" 104#define DRIVER_DESC "USB Wacom tablet driver"
105#define DRIVER_LICENSE "GPL"
106 105
107#define USB_VENDOR_ID_WACOM 0x056a 106#define USB_VENDOR_ID_WACOM 0x056a
108#define USB_VENDOR_ID_LENOVO 0x17ef 107#define USB_VENDOR_ID_LENOVO 0x17ef
@@ -166,7 +165,9 @@ struct wacom {
166 struct work_struct wireless_work; 165 struct work_struct wireless_work;
167 struct work_struct battery_work; 166 struct work_struct battery_work;
168 struct work_struct remote_work; 167 struct work_struct remote_work;
168 struct delayed_work init_work;
169 struct wacom_remote *remote; 169 struct wacom_remote *remote;
170 bool generic_has_leds;
170 struct wacom_leds { 171 struct wacom_leds {
171 struct wacom_group_leds *groups; 172 struct wacom_group_leds *groups;
172 unsigned int count; 173 unsigned int count;
@@ -218,4 +219,6 @@ enum led_brightness wacom_leds_brightness_get(struct wacom_led *led);
218struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group, 219struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group,
219 unsigned int id); 220 unsigned int id);
220struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur); 221struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur);
222int wacom_equivalent_usage(int usage);
223int wacom_initialize_leds(struct wacom *wacom);
221#endif 224#endif
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 8aeca038cc73..be8f7e2a026f 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -16,15 +16,7 @@
16#include <linux/input/mt.h> 16#include <linux/input/mt.h>
17 17
18#define WAC_MSG_RETRIES 5 18#define WAC_MSG_RETRIES 5
19
20#define WAC_CMD_WL_LED_CONTROL 0x03
21#define WAC_CMD_LED_CONTROL 0x20
22#define WAC_CMD_ICON_START 0x21
23#define WAC_CMD_ICON_XFER 0x23
24#define WAC_CMD_ICON_BT_XFER 0x26
25#define WAC_CMD_RETRIES 10 19#define WAC_CMD_RETRIES 10
26#define WAC_CMD_DELETE_PAIRING 0x20
27#define WAC_CMD_UNPAIR_ALL 0xFF
28 20
29#define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) 21#define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
30#define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) 22#define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
@@ -120,11 +112,12 @@ static void wacom_feature_mapping(struct hid_device *hdev,
120 struct wacom *wacom = hid_get_drvdata(hdev); 112 struct wacom *wacom = hid_get_drvdata(hdev);
121 struct wacom_features *features = &wacom->wacom_wac.features; 113 struct wacom_features *features = &wacom->wacom_wac.features;
122 struct hid_data *hid_data = &wacom->wacom_wac.hid_data; 114 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
115 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
123 u8 *data; 116 u8 *data;
124 int ret; 117 int ret;
125 int n; 118 int n;
126 119
127 switch (usage->hid) { 120 switch (equivalent_usage) {
128 case HID_DG_CONTACTMAX: 121 case HID_DG_CONTACTMAX:
129 /* leave touch_max as is if predefined */ 122 /* leave touch_max as is if predefined */
130 if (!features->touch_max) { 123 if (!features->touch_max) {
@@ -333,8 +326,14 @@ static void wacom_post_parse_hid(struct hid_device *hdev,
333 if (features->type == HID_GENERIC) { 326 if (features->type == HID_GENERIC) {
334 /* Any last-minute generic device setup */ 327 /* Any last-minute generic device setup */
335 if (features->touch_max > 1) { 328 if (features->touch_max > 1) {
336 input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max, 329 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
337 INPUT_MT_DIRECT); 330 input_mt_init_slots(wacom_wac->touch_input,
331 wacom_wac->features.touch_max,
332 INPUT_MT_DIRECT);
333 else
334 input_mt_init_slots(wacom_wac->touch_input,
335 wacom_wac->features.touch_max,
336 INPUT_MT_POINTER);
338 } 337 }
339 } 338 }
340} 339}
@@ -497,11 +496,11 @@ static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
497 * from the tablet, it is necessary to switch the tablet out of this 496 * from the tablet, it is necessary to switch the tablet out of this
498 * mode and into one which sends the full range of tablet data. 497 * mode and into one which sends the full range of tablet data.
499 */ 498 */
500static int wacom_query_tablet_data(struct hid_device *hdev, 499static int _wacom_query_tablet_data(struct wacom *wacom)
501 struct wacom_features *features)
502{ 500{
503 struct wacom *wacom = hid_get_drvdata(hdev); 501 struct hid_device *hdev = wacom->hdev;
504 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 502 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
503 struct wacom_features *features = &wacom_wac->features;
505 504
506 if (hdev->bus == BUS_BLUETOOTH) 505 if (hdev->bus == BUS_BLUETOOTH)
507 return wacom_bt_query_tablet_data(hdev, 1, features); 506 return wacom_bt_query_tablet_data(hdev, 1, features);
@@ -757,9 +756,6 @@ static int wacom_led_control(struct wacom *wacom)
757 unsigned char report_id = WAC_CMD_LED_CONTROL; 756 unsigned char report_id = WAC_CMD_LED_CONTROL;
758 int buf_size = 9; 757 int buf_size = 9;
759 758
760 if (!hid_get_drvdata(wacom->hdev))
761 return -ENODEV;
762
763 if (!wacom->led.groups) 759 if (!wacom->led.groups)
764 return -ENOTSUPP; 760 return -ENOTSUPP;
765 761
@@ -767,12 +763,21 @@ static int wacom_led_control(struct wacom *wacom)
767 report_id = WAC_CMD_WL_LED_CONTROL; 763 report_id = WAC_CMD_WL_LED_CONTROL;
768 buf_size = 13; 764 buf_size = 13;
769 } 765 }
766 else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
767 report_id = WAC_CMD_WL_INTUOSP2;
768 buf_size = 51;
769 }
770 buf = kzalloc(buf_size, GFP_KERNEL); 770 buf = kzalloc(buf_size, GFP_KERNEL);
771 if (!buf) 771 if (!buf)
772 return -ENOMEM; 772 return -ENOMEM;
773 773
774 if (wacom->wacom_wac.features.type >= INTUOS5S && 774 if (wacom->wacom_wac.features.type == HID_GENERIC) {
775 wacom->wacom_wac.features.type <= INTUOSPL) { 775 buf[0] = WAC_CMD_LED_CONTROL_GENERIC;
776 buf[1] = wacom->led.llv;
777 buf[2] = wacom->led.groups[0].select & 0x03;
778
779 } else if ((wacom->wacom_wac.features.type >= INTUOS5S &&
780 wacom->wacom_wac.features.type <= INTUOSPL)) {
776 /* 781 /*
777 * Touch Ring and crop mark LED luminance may take on 782 * Touch Ring and crop mark LED luminance may take on
778 * one of four values: 783 * one of four values:
@@ -792,6 +797,16 @@ static int wacom_led_control(struct wacom *wacom)
792 } else 797 } else
793 buf[1] = led_bits; 798 buf[1] = led_bits;
794 } 799 }
800 else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
801 buf[0] = report_id;
802 buf[4] = 100; // Power Connection LED (ORANGE)
803 buf[5] = 100; // BT Connection LED (BLUE)
804 buf[6] = 100; // Paper Mode (RED?)
805 buf[7] = 100; // Paper Mode (GREEN?)
806 buf[8] = 100; // Paper Mode (BLUE?)
807 buf[9] = wacom->led.llv;
808 buf[10] = wacom->led.groups[0].select & 0x03;
809 }
795 else { 810 else {
796 int led = wacom->led.groups[0].select | 0x4; 811 int led = wacom->led.groups[0].select | 0x4;
797 812
@@ -1032,6 +1047,17 @@ static struct attribute_group intuos5_led_attr_group = {
1032 .attrs = intuos5_led_attrs, 1047 .attrs = intuos5_led_attrs,
1033}; 1048};
1034 1049
1050static struct attribute *generic_led_attrs[] = {
1051 &dev_attr_status0_luminance.attr,
1052 &dev_attr_status_led0_select.attr,
1053 NULL
1054};
1055
1056static struct attribute_group generic_led_attr_group = {
1057 .name = "wacom_led",
1058 .attrs = generic_led_attrs,
1059};
1060
1035struct wacom_sysfs_group_devres { 1061struct wacom_sysfs_group_devres {
1036 struct attribute_group *group; 1062 struct attribute_group *group;
1037 struct kobject *root; 1063 struct kobject *root;
@@ -1353,7 +1379,7 @@ static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count,
1353 return 0; 1379 return 0;
1354} 1380}
1355 1381
1356static int wacom_initialize_leds(struct wacom *wacom) 1382int wacom_initialize_leds(struct wacom *wacom)
1357{ 1383{
1358 int error; 1384 int error;
1359 1385
@@ -1362,6 +1388,23 @@ static int wacom_initialize_leds(struct wacom *wacom)
1362 1388
1363 /* Initialize default values */ 1389 /* Initialize default values */
1364 switch (wacom->wacom_wac.features.type) { 1390 switch (wacom->wacom_wac.features.type) {
1391 case HID_GENERIC:
1392 if (!wacom->generic_has_leds)
1393 return 0;
1394 wacom->led.llv = 100;
1395 wacom->led.max_llv = 100;
1396
1397 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1398 if (error) {
1399 hid_err(wacom->hdev,
1400 "cannot create leds err: %d\n", error);
1401 return error;
1402 }
1403
1404 error = wacom_devm_sysfs_create_group(wacom,
1405 &generic_led_attr_group);
1406 break;
1407
1365 case INTUOS4S: 1408 case INTUOS4S:
1366 case INTUOS4: 1409 case INTUOS4:
1367 case INTUOS4WL: 1410 case INTUOS4WL:
@@ -1420,6 +1463,17 @@ static int wacom_initialize_leds(struct wacom *wacom)
1420 &intuos5_led_attr_group); 1463 &intuos5_led_attr_group);
1421 break; 1464 break;
1422 1465
1466 case INTUOSP2_BT:
1467 wacom->led.llv = 50;
1468 wacom->led.max_llv = 100;
1469 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1470 if (error) {
1471 hid_err(wacom->hdev,
1472 "cannot create leds err: %d\n", error);
1473 return error;
1474 }
1475 return 0;
1476
1423 case REMOTE: 1477 case REMOTE:
1424 wacom->led.llv = 255; 1478 wacom->led.llv = 255;
1425 wacom->led.max_llv = 255; 1479 wacom->led.max_llv = 255;
@@ -1440,11 +1494,23 @@ static int wacom_initialize_leds(struct wacom *wacom)
1440 "cannot create sysfs group err: %d\n", error); 1494 "cannot create sysfs group err: %d\n", error);
1441 return error; 1495 return error;
1442 } 1496 }
1443 wacom_led_control(wacom);
1444 1497
1445 return 0; 1498 return 0;
1446} 1499}
1447 1500
1501static void wacom_init_work(struct work_struct *work)
1502{
1503 struct wacom *wacom = container_of(work, struct wacom, init_work.work);
1504
1505 _wacom_query_tablet_data(wacom);
1506 wacom_led_control(wacom);
1507}
1508
1509static void wacom_query_tablet_data(struct wacom *wacom)
1510{
1511 schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000));
1512}
1513
1448static enum power_supply_property wacom_battery_props[] = { 1514static enum power_supply_property wacom_battery_props[] = {
1449 POWER_SUPPLY_PROP_MODEL_NAME, 1515 POWER_SUPPLY_PROP_MODEL_NAME,
1450 POWER_SUPPLY_PROP_PRESENT, 1516 POWER_SUPPLY_PROP_PRESENT,
@@ -2020,6 +2086,24 @@ static void wacom_release_resources(struct wacom *wacom)
2020 wacom->wacom_wac.pad_input = NULL; 2086 wacom->wacom_wac.pad_input = NULL;
2021} 2087}
2022 2088
2089static void wacom_set_shared_values(struct wacom_wac *wacom_wac)
2090{
2091 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) {
2092 wacom_wac->shared->type = wacom_wac->features.type;
2093 wacom_wac->shared->touch_input = wacom_wac->touch_input;
2094 }
2095
2096 if (wacom_wac->has_mute_touch_switch)
2097 wacom_wac->shared->has_mute_touch_switch = true;
2098
2099 if (wacom_wac->shared->has_mute_touch_switch &&
2100 wacom_wac->shared->touch_input) {
2101 set_bit(EV_SW, wacom_wac->shared->touch_input->evbit);
2102 input_set_capability(wacom_wac->shared->touch_input, EV_SW,
2103 SW_MUTE_DEVICE);
2104 }
2105}
2106
2023static int wacom_parse_and_register(struct wacom *wacom, bool wireless) 2107static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
2024{ 2108{
2025 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 2109 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
@@ -2118,7 +2202,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
2118 2202
2119 if (!wireless) { 2203 if (!wireless) {
2120 /* Note that if query fails it is not a hard failure */ 2204 /* Note that if query fails it is not a hard failure */
2121 wacom_query_tablet_data(hdev, features); 2205 wacom_query_tablet_data(wacom);
2122 } 2206 }
2123 2207
2124 /* touch only Bamboo doesn't support pen */ 2208 /* touch only Bamboo doesn't support pen */
@@ -2139,13 +2223,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
2139 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) 2223 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
2140 error = hid_hw_open(hdev); 2224 error = hid_hw_open(hdev);
2141 2225
2142 if ((wacom_wac->features.type == INTUOSHT || 2226 wacom_set_shared_values(wacom_wac);
2143 wacom_wac->features.type == INTUOSHT2) &&
2144 (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) {
2145 wacom_wac->shared->type = wacom_wac->features.type;
2146 wacom_wac->shared->touch_input = wacom_wac->touch_input;
2147 }
2148
2149 devres_close_group(&hdev->dev, wacom); 2227 devres_close_group(&hdev->dev, wacom);
2150 2228
2151 return 0; 2229 return 0;
@@ -2450,6 +2528,7 @@ static int wacom_probe(struct hid_device *hdev,
2450 wacom->usbdev = dev; 2528 wacom->usbdev = dev;
2451 wacom->intf = intf; 2529 wacom->intf = intf;
2452 mutex_init(&wacom->lock); 2530 mutex_init(&wacom->lock);
2531 INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work);
2453 INIT_WORK(&wacom->wireless_work, wacom_wireless_work); 2532 INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
2454 INIT_WORK(&wacom->battery_work, wacom_battery_work); 2533 INIT_WORK(&wacom->battery_work, wacom_battery_work);
2455 INIT_WORK(&wacom->remote_work, wacom_remote_work); 2534 INIT_WORK(&wacom->remote_work, wacom_remote_work);
@@ -2491,12 +2570,17 @@ static void wacom_remove(struct hid_device *hdev)
2491 2570
2492 hid_hw_stop(hdev); 2571 hid_hw_stop(hdev);
2493 2572
2573 cancel_delayed_work_sync(&wacom->init_work);
2494 cancel_work_sync(&wacom->wireless_work); 2574 cancel_work_sync(&wacom->wireless_work);
2495 cancel_work_sync(&wacom->battery_work); 2575 cancel_work_sync(&wacom->battery_work);
2496 cancel_work_sync(&wacom->remote_work); 2576 cancel_work_sync(&wacom->remote_work);
2497 if (hdev->bus == BUS_BLUETOOTH) 2577 if (hdev->bus == BUS_BLUETOOTH)
2498 device_remove_file(&hdev->dev, &dev_attr_speed); 2578 device_remove_file(&hdev->dev, &dev_attr_speed);
2499 2579
2580 /* make sure we don't trigger the LEDs */
2581 wacom_led_groups_release(wacom);
2582 wacom_release_resources(wacom);
2583
2500 hid_set_drvdata(hdev, NULL); 2584 hid_set_drvdata(hdev, NULL);
2501} 2585}
2502 2586
@@ -2504,12 +2588,11 @@ static void wacom_remove(struct hid_device *hdev)
2504static int wacom_resume(struct hid_device *hdev) 2588static int wacom_resume(struct hid_device *hdev)
2505{ 2589{
2506 struct wacom *wacom = hid_get_drvdata(hdev); 2590 struct wacom *wacom = hid_get_drvdata(hdev);
2507 struct wacom_features *features = &wacom->wacom_wac.features;
2508 2591
2509 mutex_lock(&wacom->lock); 2592 mutex_lock(&wacom->lock);
2510 2593
2511 /* switch to wacom mode first */ 2594 /* switch to wacom mode first */
2512 wacom_query_tablet_data(hdev, features); 2595 _wacom_query_tablet_data(wacom);
2513 wacom_led_control(wacom); 2596 wacom_led_control(wacom);
2514 2597
2515 mutex_unlock(&wacom->lock); 2598 mutex_unlock(&wacom->lock);
@@ -2540,4 +2623,4 @@ module_hid_driver(wacom_driver);
2540MODULE_VERSION(DRIVER_VERSION); 2623MODULE_VERSION(DRIVER_VERSION);
2541MODULE_AUTHOR(DRIVER_AUTHOR); 2624MODULE_AUTHOR(DRIVER_AUTHOR);
2542MODULE_DESCRIPTION(DRIVER_DESC); 2625MODULE_DESCRIPTION(DRIVER_DESC);
2543MODULE_LICENSE(DRIVER_LICENSE); 2626MODULE_LICENSE("GPL");
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 672145b0d8f5..4aa3de9f1163 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -43,6 +43,8 @@ static void wacom_report_numbered_buttons(struct input_dev *input_dev,
43 43
44static int wacom_numbered_button_to_key(int n); 44static int wacom_numbered_button_to_key(int n);
45 45
46static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
47 int group);
46/* 48/*
47 * Percent of battery capacity for Graphire. 49 * Percent of battery capacity for Graphire.
48 * 8th value means AC online and show 100% capacity. 50 * 8th value means AC online and show 100% capacity.
@@ -1192,6 +1194,166 @@ static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1192 return count; 1194 return count;
1193} 1195}
1194 1196
1197static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1198{
1199 const int pen_frame_len = 14;
1200 const int pen_frames = 7;
1201
1202 struct input_dev *pen_input = wacom->pen_input;
1203 unsigned char *data = wacom->data;
1204 int i;
1205
1206 wacom->serial[0] = get_unaligned_le64(&data[99]);
1207 wacom->id[0] = get_unaligned_le16(&data[107]);
1208 if (wacom->serial[0] >> 52 == 1) {
1209 /* Add back in missing bits of ID for non-USI pens */
1210 wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
1211 }
1212 wacom->tool[0] = wacom_intuos_get_tool_type(wacom_intuos_id_mangle(wacom->id[0]));
1213
1214 for (i = 0; i < pen_frames; i++) {
1215 unsigned char *frame = &data[i*pen_frame_len + 1];
1216 bool valid = frame[0] & 0x80;
1217 bool prox = frame[0] & 0x40;
1218 bool range = frame[0] & 0x20;
1219
1220 if (!valid)
1221 continue;
1222
1223 if (range) {
1224 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
1225 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
1226 input_report_abs(pen_input, ABS_TILT_X, frame[7]);
1227 input_report_abs(pen_input, ABS_TILT_Y, frame[8]);
1228 input_report_abs(pen_input, ABS_Z, get_unaligned_le16(&frame[9]));
1229 input_report_abs(pen_input, ABS_WHEEL, get_unaligned_le16(&frame[11]));
1230 }
1231 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
1232 input_report_abs(pen_input, ABS_DISTANCE, range ? frame[13] : wacom->features.distance_max);
1233
1234 input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x01);
1235 input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02);
1236 input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04);
1237
1238 input_report_key(pen_input, wacom->tool[0], prox);
1239 input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]);
1240 input_report_abs(pen_input, ABS_MISC,
1241 wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */
1242
1243 wacom->shared->stylus_in_proximity = prox;
1244
1245 input_sync(pen_input);
1246 }
1247}
1248
1249static void wacom_intuos_pro2_bt_touch(struct wacom_wac *wacom)
1250{
1251 const int finger_touch_len = 8;
1252 const int finger_frames = 4;
1253 const int finger_frame_len = 43;
1254
1255 struct input_dev *touch_input = wacom->touch_input;
1256 unsigned char *data = wacom->data;
1257 int num_contacts_left = 5;
1258 int i, j;
1259
1260 for (i = 0; i < finger_frames; i++) {
1261 unsigned char *frame = &data[i*finger_frame_len + 109];
1262 int current_num_contacts = frame[0] & 0x7F;
1263 int contacts_to_send;
1264
1265 if (!(frame[0] & 0x80))
1266 continue;
1267
1268 /*
1269 * First packet resets the counter since only the first
1270 * packet in series will have non-zero current_num_contacts.
1271 */
1272 if (current_num_contacts)
1273 wacom->num_contacts_left = current_num_contacts;
1274
1275 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1276
1277 for (j = 0; j < contacts_to_send; j++) {
1278 unsigned char *touch = &frame[j*finger_touch_len + 1];
1279 int slot = input_mt_get_slot_by_key(touch_input, touch[0]);
1280 int x = get_unaligned_le16(&touch[2]);
1281 int y = get_unaligned_le16(&touch[4]);
1282 int w = touch[6] * input_abs_get_res(touch_input, ABS_MT_POSITION_X);
1283 int h = touch[7] * input_abs_get_res(touch_input, ABS_MT_POSITION_Y);
1284
1285 if (slot < 0)
1286 continue;
1287
1288 input_mt_slot(touch_input, slot);
1289 input_mt_report_slot_state(touch_input, MT_TOOL_FINGER, touch[1] & 0x01);
1290 input_report_abs(touch_input, ABS_MT_POSITION_X, x);
1291 input_report_abs(touch_input, ABS_MT_POSITION_Y, y);
1292 input_report_abs(touch_input, ABS_MT_TOUCH_MAJOR, max(w, h));
1293 input_report_abs(touch_input, ABS_MT_TOUCH_MINOR, min(w, h));
1294 input_report_abs(touch_input, ABS_MT_ORIENTATION, w > h);
1295 }
1296
1297 input_mt_sync_frame(touch_input);
1298
1299 wacom->num_contacts_left -= contacts_to_send;
1300 if (wacom->num_contacts_left <= 0) {
1301 wacom->num_contacts_left = 0;
1302 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1303 }
1304 }
1305
1306 input_report_switch(touch_input, SW_MUTE_DEVICE, !(data[281] >> 7));
1307 input_sync(touch_input);
1308}
1309
1310static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
1311{
1312 struct input_dev *pad_input = wacom->pad_input;
1313 unsigned char *data = wacom->data;
1314
1315 int buttons = (data[282] << 1) | ((data[281] >> 6) & 0x01);
1316 int ring = data[285];
1317 int prox = buttons | (ring & 0x80);
1318
1319 wacom_report_numbered_buttons(pad_input, 9, buttons);
1320
1321 input_report_abs(pad_input, ABS_WHEEL, (ring & 0x80) ? (ring & 0x7f) : 0);
1322
1323 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
1324 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
1325 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1326
1327 input_sync(pad_input);
1328}
1329
1330static void wacom_intuos_pro2_bt_battery(struct wacom_wac *wacom)
1331{
1332 unsigned char *data = wacom->data;
1333
1334 bool chg = data[284] & 0x80;
1335 int battery_status = data[284] & 0x7F;
1336
1337 wacom_notify_battery(wacom, battery_status, chg, 1, chg);
1338}
1339
1340static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
1341{
1342 unsigned char *data = wacom->data;
1343
1344 if (data[0] != 0x80) {
1345 dev_dbg(wacom->pen_input->dev.parent,
1346 "%s: received unknown report #%d\n", __func__, data[0]);
1347 return 0;
1348 }
1349
1350 wacom_intuos_pro2_bt_pen(wacom);
1351 wacom_intuos_pro2_bt_touch(wacom);
1352 wacom_intuos_pro2_bt_pad(wacom);
1353 wacom_intuos_pro2_bt_battery(wacom);
1354 return 0;
1355}
1356
1195static int wacom_24hdt_irq(struct wacom_wac *wacom) 1357static int wacom_24hdt_irq(struct wacom_wac *wacom)
1196{ 1358{
1197 struct input_dev *input = wacom->touch_input; 1359 struct input_dev *input = wacom->touch_input;
@@ -1446,7 +1608,7 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1446 return 0; 1608 return 0;
1447} 1609}
1448 1610
1449static int wacom_equivalent_usage(int usage) 1611int wacom_equivalent_usage(int usage)
1450{ 1612{
1451 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) { 1613 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1452 int subpage = (usage & 0xFF00) << 8; 1614 int subpage = (usage & 0xFF00) << 8;
@@ -1473,6 +1635,16 @@ static int wacom_equivalent_usage(int usage)
1473 return subpage | subusage; 1635 return subpage | subusage;
1474 } 1636 }
1475 1637
1638 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMTOUCH) {
1639 int subpage = (usage & 0xFF00) << 8;
1640 int subusage = (usage & 0xFF);
1641
1642 if (subpage == HID_UP_UNDEFINED)
1643 subpage = WACOM_HID_SP_DIGITIZER;
1644
1645 return subpage | subusage;
1646 }
1647
1476 return usage; 1648 return usage;
1477} 1649}
1478 1650
@@ -1552,12 +1724,14 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1552 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0); 1724 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1553 features->device_type |= WACOM_DEVICETYPE_PAD; 1725 features->device_type |= WACOM_DEVICETYPE_PAD;
1554 break; 1726 break;
1727 case WACOM_HID_WD_BUTTONCENTER:
1728 wacom->generic_has_leds = true;
1729 /* fall through */
1555 case WACOM_HID_WD_BUTTONHOME: 1730 case WACOM_HID_WD_BUTTONHOME:
1556 case WACOM_HID_WD_BUTTONUP: 1731 case WACOM_HID_WD_BUTTONUP:
1557 case WACOM_HID_WD_BUTTONDOWN: 1732 case WACOM_HID_WD_BUTTONDOWN:
1558 case WACOM_HID_WD_BUTTONLEFT: 1733 case WACOM_HID_WD_BUTTONLEFT:
1559 case WACOM_HID_WD_BUTTONRIGHT: 1734 case WACOM_HID_WD_BUTTONRIGHT:
1560 case WACOM_HID_WD_BUTTONCENTER:
1561 wacom_map_usage(input, usage, field, EV_KEY, 1735 wacom_map_usage(input, usage, field, EV_KEY,
1562 wacom_numbered_button_to_key(features->numbered_buttons), 1736 wacom_numbered_button_to_key(features->numbered_buttons),
1563 0); 1737 0);
@@ -1565,7 +1739,17 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1565 features->device_type |= WACOM_DEVICETYPE_PAD; 1739 features->device_type |= WACOM_DEVICETYPE_PAD;
1566 break; 1740 break;
1567 case WACOM_HID_WD_TOUCHONOFF: 1741 case WACOM_HID_WD_TOUCHONOFF:
1568 wacom_map_usage(input, usage, field, EV_SW, SW_MUTE_DEVICE, 0); 1742 /*
1743 * This usage, which is used to mute touch events, comes
1744 * from the pad packet, but is reported on the touch
1745 * interface. Because the touch interface may not have
1746 * been created yet, we cannot call wacom_map_usage(). In
1747 * order to process this usage when we receive it, we set
1748 * the usage type and code directly.
1749 */
1750 wacom_wac->has_mute_touch_switch = true;
1751 usage->type = EV_SW;
1752 usage->code = SW_MUTE_DEVICE;
1569 features->device_type |= WACOM_DEVICETYPE_PAD; 1753 features->device_type |= WACOM_DEVICETYPE_PAD;
1570 break; 1754 break;
1571 case WACOM_HID_WD_TOUCHSTRIP: 1755 case WACOM_HID_WD_TOUCHSTRIP:
@@ -1580,6 +1764,10 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1580 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0); 1764 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1581 features->device_type |= WACOM_DEVICETYPE_PAD; 1765 features->device_type |= WACOM_DEVICETYPE_PAD;
1582 break; 1766 break;
1767 case WACOM_HID_WD_TOUCHRINGSTATUS:
1768 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1769 features->device_type |= WACOM_DEVICETYPE_PAD;
1770 break;
1583 } 1771 }
1584 1772
1585 switch (equivalent_usage & 0xfffffff0) { 1773 switch (equivalent_usage & 0xfffffff0) {
@@ -1622,17 +1810,40 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
1622 struct input_dev *input = wacom_wac->pad_input; 1810 struct input_dev *input = wacom_wac->pad_input;
1623 struct wacom_features *features = &wacom_wac->features; 1811 struct wacom_features *features = &wacom_wac->features;
1624 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); 1812 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1813 int i;
1814
1815 /*
1816 * Avoid reporting this event and setting inrange_state if this usage
1817 * hasn't been mapped.
1818 */
1819 if (!usage->type)
1820 return;
1625 1821
1626 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) { 1822 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
1627 wacom_wac->hid_data.inrange_state |= value; 1823 if (usage->hid != WACOM_HID_WD_TOUCHRING)
1824 wacom_wac->hid_data.inrange_state |= value;
1628 } 1825 }
1629 1826
1630 switch (equivalent_usage) { 1827 switch (equivalent_usage) {
1631 case WACOM_HID_WD_TOUCHRINGSTATUS: 1828 case WACOM_HID_WD_TOUCHRINGSTATUS:
1829 if (!value)
1830 input_event(input, usage->type, usage->code, 0);
1632 break; 1831 break;
1633 1832
1833 case WACOM_HID_WD_TOUCHONOFF:
1834 if (wacom_wac->shared->touch_input) {
1835 input_report_switch(wacom_wac->shared->touch_input,
1836 SW_MUTE_DEVICE, !value);
1837 input_sync(wacom_wac->shared->touch_input);
1838 }
1839 break;
1840
1841 case WACOM_HID_WD_BUTTONCENTER:
1842 for (i = 0; i < wacom->led.count; i++)
1843 wacom_update_led(wacom, features->numbered_buttons,
1844 value, i);
1845 /* fall through*/
1634 default: 1846 default:
1635 features->input_event_flag = true;
1636 input_event(input, usage->type, usage->code, value); 1847 input_event(input, usage->type, usage->code, value);
1637 break; 1848 break;
1638 } 1849 }
@@ -1670,20 +1881,15 @@ static void wacom_wac_pad_report(struct hid_device *hdev,
1670{ 1881{
1671 struct wacom *wacom = hid_get_drvdata(hdev); 1882 struct wacom *wacom = hid_get_drvdata(hdev);
1672 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 1883 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1673 struct wacom_features *features = &wacom_wac->features;
1674 struct input_dev *input = wacom_wac->pad_input; 1884 struct input_dev *input = wacom_wac->pad_input;
1675 bool active = wacom_wac->hid_data.inrange_state != 0; 1885 bool active = wacom_wac->hid_data.inrange_state != 0;
1676 1886
1677 /* report prox for expresskey events */ 1887 /* report prox for expresskey events */
1678 if (wacom_equivalent_usage(report->field[0]->physical) == HID_DG_TABLETFUNCTIONKEY) { 1888 if (wacom_equivalent_usage(report->field[0]->physical) == HID_DG_TABLETFUNCTIONKEY) {
1679 features->input_event_flag = true;
1680 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0); 1889 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
1681 }
1682
1683 if (features->input_event_flag) {
1684 features->input_event_flag = false;
1685 input_sync(input); 1890 input_sync(input);
1686 } 1891 }
1892
1687} 1893}
1688 1894
1689static void wacom_wac_pen_usage_mapping(struct hid_device *hdev, 1895static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
@@ -2058,8 +2264,10 @@ static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2058 2264
2059 for (j = 0; j < field->maxusage; j++) { 2265 for (j = 0; j < field->maxusage; j++) {
2060 struct hid_usage *usage = &field->usage[j]; 2266 struct hid_usage *usage = &field->usage[j];
2267 unsigned int equivalent_usage =
2268 wacom_equivalent_usage(usage->hid);
2061 2269
2062 switch (usage->hid) { 2270 switch (equivalent_usage) {
2063 case HID_GD_X: 2271 case HID_GD_X:
2064 case HID_GD_Y: 2272 case HID_GD_Y:
2065 case HID_DG_WIDTH: 2273 case HID_DG_WIDTH:
@@ -2068,7 +2276,7 @@ static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2068 case HID_DG_INRANGE: 2276 case HID_DG_INRANGE:
2069 case HID_DG_INVERT: 2277 case HID_DG_INVERT:
2070 case HID_DG_TIPSWITCH: 2278 case HID_DG_TIPSWITCH:
2071 hid_data->last_slot_field = usage->hid; 2279 hid_data->last_slot_field = equivalent_usage;
2072 break; 2280 break;
2073 case HID_DG_CONTACTCOUNT: 2281 case HID_DG_CONTACTCOUNT:
2074 hid_data->cc_report = report->id; 2282 hid_data->cc_report = report->id;
@@ -2123,8 +2331,8 @@ void wacom_wac_usage_mapping(struct hid_device *hdev,
2123 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 2331 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2124 struct wacom_features *features = &wacom_wac->features; 2332 struct wacom_features *features = &wacom_wac->features;
2125 2333
2126 /* currently, only direct devices have proper hid report descriptors */ 2334 if (WACOM_DIRECT_DEVICE(field))
2127 features->device_type |= WACOM_DEVICETYPE_DIRECT; 2335 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2128 2336
2129 if (WACOM_PAD_FIELD(field)) 2337 if (WACOM_PAD_FIELD(field))
2130 wacom_wac_pad_usage_mapping(hdev, field, usage); 2338 wacom_wac_pad_usage_mapping(hdev, field, usage);
@@ -2142,6 +2350,9 @@ void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
2142 if (wacom->wacom_wac.features.type != HID_GENERIC) 2350 if (wacom->wacom_wac.features.type != HID_GENERIC)
2143 return; 2351 return;
2144 2352
2353 if (value > field->logical_maximum || value < field->logical_minimum)
2354 return;
2355
2145 if (WACOM_PAD_FIELD(field)) { 2356 if (WACOM_PAD_FIELD(field)) {
2146 wacom_wac_pad_battery_event(hdev, field, usage, value); 2357 wacom_wac_pad_battery_event(hdev, field, usage, value);
2147 if (wacom->wacom_wac.pad_input) 2358 if (wacom->wacom_wac.pad_input)
@@ -2669,6 +2880,10 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
2669 sync = wacom_intuos_irq(wacom_wac); 2880 sync = wacom_intuos_irq(wacom_wac);
2670 break; 2881 break;
2671 2882
2883 case INTUOSP2_BT:
2884 sync = wacom_intuos_pro2_bt_irq(wacom_wac, len);
2885 break;
2886
2672 case TABLETPC: 2887 case TABLETPC:
2673 case TABLETPCE: 2888 case TABLETPCE:
2674 case TABLETPC2FG: 2889 case TABLETPC2FG:
@@ -2779,8 +2994,6 @@ void wacom_setup_device_quirks(struct wacom *wacom)
2779 struct wacom_features *features = &wacom->wacom_wac.features; 2994 struct wacom_features *features = &wacom->wacom_wac.features;
2780 2995
2781 /* The pen and pad share the same interface on most devices */ 2996 /* The pen and pad share the same interface on most devices */
2782 if (features->numbered_buttons > 0)
2783 features->device_type |= WACOM_DEVICETYPE_PAD;
2784 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 || 2997 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
2785 features->type == DTUS || 2998 features->type == DTUS ||
2786 (features->type >= INTUOS3S && features->type <= WACOM_MO)) { 2999 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
@@ -2840,6 +3053,13 @@ void wacom_setup_device_quirks(struct wacom *wacom)
2840 if (features->type == REMOTE) 3053 if (features->type == REMOTE)
2841 features->device_type = WACOM_DEVICETYPE_PAD; 3054 features->device_type = WACOM_DEVICETYPE_PAD;
2842 3055
3056 if (features->type == INTUOSP2_BT) {
3057 features->device_type |= WACOM_DEVICETYPE_PEN |
3058 WACOM_DEVICETYPE_PAD |
3059 WACOM_DEVICETYPE_TOUCH;
3060 features->quirks |= WACOM_QUIRK_BATTERY;
3061 }
3062
2843 switch (features->type) { 3063 switch (features->type) {
2844 case PL: 3064 case PL:
2845 case DTU: 3065 case DTU:
@@ -2986,6 +3206,7 @@ int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
2986 case INTUOSPL: 3206 case INTUOSPL:
2987 case INTUOS5S: 3207 case INTUOS5S:
2988 case INTUOSPS: 3208 case INTUOSPS:
3209 case INTUOSP2_BT:
2989 input_set_abs_params(input_dev, ABS_DISTANCE, 0, 3210 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2990 features->distance_max, 3211 features->distance_max,
2991 features->distance_fuzz, 0); 3212 features->distance_fuzz, 0);
@@ -3094,6 +3315,27 @@ int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3094 } 3315 }
3095 3316
3096 switch (features->type) { 3317 switch (features->type) {
3318 case INTUOSP2_BT:
3319 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3320 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3321
3322 if (wacom_wac->shared->touch->product == 0x361) {
3323 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3324 0, 12440, 4, 0);
3325 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3326 0, 8640, 4, 0);
3327 }
3328 else if (wacom_wac->shared->touch->product == 0x360) {
3329 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3330 0, 8960, 4, 0);
3331 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3332 0, 5920, 4, 0);
3333 }
3334 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
3335 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
3336
3337 /* fall through */
3338
3097 case INTUOS5: 3339 case INTUOS5:
3098 case INTUOS5L: 3340 case INTUOS5L:
3099 case INTUOSPM: 3341 case INTUOSPM:
@@ -3290,6 +3532,9 @@ int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3290{ 3532{
3291 struct wacom_features *features = &wacom_wac->features; 3533 struct wacom_features *features = &wacom_wac->features;
3292 3534
3535 if ((features->type == HID_GENERIC) && features->numbered_buttons > 0)
3536 features->device_type |= WACOM_DEVICETYPE_PAD;
3537
3293 if (!(features->device_type & WACOM_DEVICETYPE_PAD)) 3538 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
3294 return -ENODEV; 3539 return -ENODEV;
3295 3540
@@ -3391,6 +3636,7 @@ int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3391 case INTUOSPL: 3636 case INTUOSPL:
3392 case INTUOS5S: 3637 case INTUOS5S:
3393 case INTUOSPS: 3638 case INTUOSPS:
3639 case INTUOSP2_BT:
3394 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0); 3640 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3395 break; 3641 break;
3396 3642
@@ -3949,6 +4195,12 @@ static const struct wacom_features wacom_features_0x343 =
3949 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4, 4195 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3950 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET, 4196 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3951 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET }; 4197 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
4198static const struct wacom_features wacom_features_0x360 =
4199 { "Wacom Intuos Pro M", 44800, 29600, 8191, 63,
4200 INTUOSP2_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 9, .touch_max = 10 };
4201static const struct wacom_features wacom_features_0x361 =
4202 { "Wacom Intuos Pro L", 62200, 43200, 8191, 63,
4203 INTUOSP2_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 9, .touch_max = 10 };
3952 4204
3953static const struct wacom_features wacom_features_HID_ANY_ID = 4205static const struct wacom_features wacom_features_HID_ANY_ID =
3954 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID }; 4206 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
@@ -4115,6 +4367,8 @@ const struct hid_device_id wacom_ids[] = {
4115 { USB_DEVICE_WACOM(0x33D) }, 4367 { USB_DEVICE_WACOM(0x33D) },
4116 { USB_DEVICE_WACOM(0x33E) }, 4368 { USB_DEVICE_WACOM(0x33E) },
4117 { USB_DEVICE_WACOM(0x343) }, 4369 { USB_DEVICE_WACOM(0x343) },
4370 { BT_DEVICE_WACOM(0x360) },
4371 { BT_DEVICE_WACOM(0x361) },
4118 { USB_DEVICE_WACOM(0x4001) }, 4372 { USB_DEVICE_WACOM(0x4001) },
4119 { USB_DEVICE_WACOM(0x4004) }, 4373 { USB_DEVICE_WACOM(0x4004) },
4120 { USB_DEVICE_WACOM(0x5000) }, 4374 { USB_DEVICE_WACOM(0x5000) },
@@ -4123,6 +4377,7 @@ const struct hid_device_id wacom_ids[] = {
4123 4377
4124 { USB_DEVICE_WACOM(HID_ANY_ID) }, 4378 { USB_DEVICE_WACOM(HID_ANY_ID) },
4125 { I2C_DEVICE_WACOM(HID_ANY_ID) }, 4379 { I2C_DEVICE_WACOM(HID_ANY_ID) },
4380 { BT_DEVICE_WACOM(HID_ANY_ID) },
4126 { } 4381 { }
4127}; 4382};
4128MODULE_DEVICE_TABLE(hid, wacom_ids); 4383MODULE_DEVICE_TABLE(hid, wacom_ids);
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index fb0e50acb10d..857ccee16f38 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -12,8 +12,8 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/hid.h> 13#include <linux/hid.h>
14 14
15/* maximum packet length for USB devices */ 15/* maximum packet length for USB/BT devices */
16#define WACOM_PKGLEN_MAX 192 16#define WACOM_PKGLEN_MAX 361
17 17
18#define WACOM_NAME_MAX 64 18#define WACOM_NAME_MAX 64
19#define WACOM_MAX_REMOTES 5 19#define WACOM_MAX_REMOTES 5
@@ -72,6 +72,17 @@
72#define WACOM_REPORT_REMOTE 17 72#define WACOM_REPORT_REMOTE 17
73#define WACOM_REPORT_INTUOSHT2_ID 8 73#define WACOM_REPORT_INTUOSHT2_ID 8
74 74
75/* wacom command report ids */
76#define WAC_CMD_WL_LED_CONTROL 0x03
77#define WAC_CMD_LED_CONTROL 0x20
78#define WAC_CMD_ICON_START 0x21
79#define WAC_CMD_ICON_XFER 0x23
80#define WAC_CMD_ICON_BT_XFER 0x26
81#define WAC_CMD_DELETE_PAIRING 0x20
82#define WAC_CMD_LED_CONTROL_GENERIC 0x32
83#define WAC_CMD_UNPAIR_ALL 0xFF
84#define WAC_CMD_WL_INTUOSP2 0x82
85
75/* device quirks */ 86/* device quirks */
76#define WACOM_QUIRK_BBTOUCH_LOWRES 0x0001 87#define WACOM_QUIRK_BBTOUCH_LOWRES 0x0001
77#define WACOM_QUIRK_SENSE 0x0002 88#define WACOM_QUIRK_SENSE 0x0002
@@ -91,6 +102,7 @@
91#define WACOM_HID_SP_DIGITIZER 0x000d0000 102#define WACOM_HID_SP_DIGITIZER 0x000d0000
92#define WACOM_HID_SP_DIGITIZERINFO 0x00100000 103#define WACOM_HID_SP_DIGITIZERINFO 0x00100000
93#define WACOM_HID_WD_DIGITIZER (WACOM_HID_UP_WACOMDIGITIZER | 0x01) 104#define WACOM_HID_WD_DIGITIZER (WACOM_HID_UP_WACOMDIGITIZER | 0x01)
105#define WACOM_HID_WD_PEN (WACOM_HID_UP_WACOMDIGITIZER | 0x02)
94#define WACOM_HID_WD_SENSE (WACOM_HID_UP_WACOMDIGITIZER | 0x36) 106#define WACOM_HID_WD_SENSE (WACOM_HID_UP_WACOMDIGITIZER | 0x36)
95#define WACOM_HID_WD_DIGITIZERFNKEYS (WACOM_HID_UP_WACOMDIGITIZER | 0x39) 107#define WACOM_HID_WD_DIGITIZERFNKEYS (WACOM_HID_UP_WACOMDIGITIZER | 0x39)
96#define WACOM_HID_WD_SERIALHI (WACOM_HID_UP_WACOMDIGITIZER | 0x5c) 108#define WACOM_HID_WD_SERIALHI (WACOM_HID_UP_WACOMDIGITIZER | 0x5c)
@@ -104,6 +116,7 @@
104#define WACOM_HID_WD_ACCELEROMETER_Y (WACOM_HID_UP_WACOMDIGITIZER | 0x0402) 116#define WACOM_HID_WD_ACCELEROMETER_Y (WACOM_HID_UP_WACOMDIGITIZER | 0x0402)
105#define WACOM_HID_WD_ACCELEROMETER_Z (WACOM_HID_UP_WACOMDIGITIZER | 0x0403) 117#define WACOM_HID_WD_ACCELEROMETER_Z (WACOM_HID_UP_WACOMDIGITIZER | 0x0403)
106#define WACOM_HID_WD_BATTERY_CHARGING (WACOM_HID_UP_WACOMDIGITIZER | 0x0404) 118#define WACOM_HID_WD_BATTERY_CHARGING (WACOM_HID_UP_WACOMDIGITIZER | 0x0404)
119#define WACOM_HID_WD_TOUCHONOFF (WACOM_HID_UP_WACOMDIGITIZER | 0x0454)
107#define WACOM_HID_WD_BATTERY_LEVEL (WACOM_HID_UP_WACOMDIGITIZER | 0x043b) 120#define WACOM_HID_WD_BATTERY_LEVEL (WACOM_HID_UP_WACOMDIGITIZER | 0x043b)
108#define WACOM_HID_WD_EXPRESSKEY00 (WACOM_HID_UP_WACOMDIGITIZER | 0x0910) 121#define WACOM_HID_WD_EXPRESSKEY00 (WACOM_HID_UP_WACOMDIGITIZER | 0x0910)
109#define WACOM_HID_WD_EXPRESSKEYCAP00 (WACOM_HID_UP_WACOMDIGITIZER | 0x0950) 122#define WACOM_HID_WD_EXPRESSKEYCAP00 (WACOM_HID_UP_WACOMDIGITIZER | 0x0950)
@@ -113,7 +126,6 @@
113#define WACOM_HID_WD_BUTTONLEFT (WACOM_HID_UP_WACOMDIGITIZER | 0x0993) 126#define WACOM_HID_WD_BUTTONLEFT (WACOM_HID_UP_WACOMDIGITIZER | 0x0993)
114#define WACOM_HID_WD_BUTTONRIGHT (WACOM_HID_UP_WACOMDIGITIZER | 0x0994) 127#define WACOM_HID_WD_BUTTONRIGHT (WACOM_HID_UP_WACOMDIGITIZER | 0x0994)
115#define WACOM_HID_WD_BUTTONCENTER (WACOM_HID_UP_WACOMDIGITIZER | 0x0995) 128#define WACOM_HID_WD_BUTTONCENTER (WACOM_HID_UP_WACOMDIGITIZER | 0x0995)
116#define WACOM_HID_WD_TOUCHONOFF (WACOM_HID_UP_WACOMDIGITIZER | 0x0996)
117#define WACOM_HID_WD_FINGERWHEEL (WACOM_HID_UP_WACOMDIGITIZER | 0x0d03) 129#define WACOM_HID_WD_FINGERWHEEL (WACOM_HID_UP_WACOMDIGITIZER | 0x0d03)
118#define WACOM_HID_WD_OFFSETLEFT (WACOM_HID_UP_WACOMDIGITIZER | 0x0d30) 130#define WACOM_HID_WD_OFFSETLEFT (WACOM_HID_UP_WACOMDIGITIZER | 0x0d30)
119#define WACOM_HID_WD_OFFSETTOP (WACOM_HID_UP_WACOMDIGITIZER | 0x0d31) 131#define WACOM_HID_WD_OFFSETTOP (WACOM_HID_UP_WACOMDIGITIZER | 0x0d31)
@@ -127,6 +139,12 @@
127#define WACOM_HID_UP_G11 0xff110000 139#define WACOM_HID_UP_G11 0xff110000
128#define WACOM_HID_G11_PEN (WACOM_HID_UP_G11 | 0x02) 140#define WACOM_HID_G11_PEN (WACOM_HID_UP_G11 | 0x02)
129#define WACOM_HID_G11_TOUCHSCREEN (WACOM_HID_UP_G11 | 0x11) 141#define WACOM_HID_G11_TOUCHSCREEN (WACOM_HID_UP_G11 | 0x11)
142#define WACOM_HID_UP_WACOMTOUCH 0xff000000
143#define WACOM_HID_WT_TOUCHSCREEN (WACOM_HID_UP_WACOMTOUCH | 0x04)
144#define WACOM_HID_WT_TOUCHPAD (WACOM_HID_UP_WACOMTOUCH | 0x05)
145#define WACOM_HID_WT_CONTACTMAX (WACOM_HID_UP_WACOMTOUCH | 0x55)
146#define WACOM_HID_WT_X (WACOM_HID_UP_WACOMTOUCH | 0x130)
147#define WACOM_HID_WT_Y (WACOM_HID_UP_WACOMTOUCH | 0x131)
130 148
131#define WACOM_PAD_FIELD(f) (((f)->physical == HID_DG_TABLETFUNCTIONKEY) || \ 149#define WACOM_PAD_FIELD(f) (((f)->physical == HID_DG_TABLETFUNCTIONKEY) || \
132 ((f)->physical == WACOM_HID_WD_DIGITIZERFNKEYS) || \ 150 ((f)->physical == WACOM_HID_WD_DIGITIZERFNKEYS) || \
@@ -144,7 +162,14 @@
144 ((f)->physical == HID_DG_FINGER) || \ 162 ((f)->physical == HID_DG_FINGER) || \
145 ((f)->application == HID_DG_TOUCHSCREEN) || \ 163 ((f)->application == HID_DG_TOUCHSCREEN) || \
146 ((f)->application == WACOM_HID_G9_TOUCHSCREEN) || \ 164 ((f)->application == WACOM_HID_G9_TOUCHSCREEN) || \
147 ((f)->application == WACOM_HID_G11_TOUCHSCREEN)) 165 ((f)->application == WACOM_HID_G11_TOUCHSCREEN) || \
166 ((f)->application == WACOM_HID_WT_TOUCHPAD) || \
167 ((f)->application == HID_DG_TOUCHPAD))
168
169#define WACOM_DIRECT_DEVICE(f) (((f)->application == HID_DG_TOUCHSCREEN) || \
170 ((f)->application == WACOM_HID_WT_TOUCHSCREEN) || \
171 ((f)->application == HID_DG_PEN) || \
172 ((f)->application == WACOM_HID_WD_PEN))
148 173
149enum { 174enum {
150 PENPARTNER = 0, 175 PENPARTNER = 0,
@@ -170,6 +195,7 @@ enum {
170 INTUOSPS, 195 INTUOSPS,
171 INTUOSPM, 196 INTUOSPM,
172 INTUOSPL, 197 INTUOSPL,
198 INTUOSP2_BT,
173 WACOM_21UX2, 199 WACOM_21UX2,
174 WACOM_22HD, 200 WACOM_22HD,
175 DTK, 201 DTK,
@@ -232,7 +258,6 @@ struct wacom_features {
232 int pktlen; 258 int pktlen;
233 bool check_for_hid_type; 259 bool check_for_hid_type;
234 int hid_type; 260 int hid_type;
235 bool input_event_flag;
236}; 261};
237 262
238struct wacom_shared { 263struct wacom_shared {
@@ -244,6 +269,7 @@ struct wacom_shared {
244 struct input_dev *touch_input; 269 struct input_dev *touch_input;
245 struct hid_device *pen; 270 struct hid_device *pen;
246 struct hid_device *touch; 271 struct hid_device *touch;
272 bool has_mute_touch_switch;
247}; 273};
248 274
249struct hid_data { 275struct hid_data {
@@ -300,6 +326,7 @@ struct wacom_wac {
300 int mode_report; 326 int mode_report;
301 int mode_value; 327 int mode_value;
302 struct hid_data hid_data; 328 struct hid_data hid_data;
329 bool has_mute_touch_switch;
303}; 330};
304 331
305#endif 332#endif