blob: 5d419a95b6c25904ca833c06540bb19b73ea41ae [file] [log] [blame]
Jiri Slaby5f22a792008-05-16 11:49:19 +02001/*
2 * HID driver for some logitech "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
Jiri Slaby5f22a792008-05-16 11:49:19 +02008 * Copyright (c) 2008 Jiri Slaby
Hendrik Iben2c6118e2010-10-04 15:39:49 +02009 * Copyright (c) 2010 Hendrik Iben
Jiri Slaby5f22a792008-05-16 11:49:19 +020010 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
Simon Wood32c88cb2010-09-22 13:19:42 +020022#include <linux/random.h>
23#include <linux/sched.h>
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060024#include <linux/usb.h>
Simon Wood32c88cb2010-09-22 13:19:42 +020025#include <linux/wait.h>
Jiri Slaby5f22a792008-05-16 11:49:19 +020026
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060027#include "usbhid/usbhid.h"
Jiri Slaby5f22a792008-05-16 11:49:19 +020028#include "hid-ids.h"
Jiri Slaby606bd0a2008-07-04 23:06:45 +020029#include "hid-lg.h"
Michal Malýa54dc7792015-02-18 17:59:22 +010030#include "hid-lg4ff.h"
Jiri Slaby5f22a792008-05-16 11:49:19 +020031
32#define LG_RDESC 0x001
33#define LG_BAD_RELATIVE_KEYS 0x002
34#define LG_DUPLICATE_USAGES 0x004
Jiri Slaby5f22a792008-05-16 11:49:19 +020035#define LG_EXPANDED_KEYMAP 0x010
36#define LG_IGNORE_DOUBLED_WHEEL 0x020
37#define LG_WIRELESS 0x040
38#define LG_INVERT_HWHEEL 0x080
39#define LG_NOGET 0x100
Jiri Slaby606bd0a2008-07-04 23:06:45 +020040#define LG_FF 0x200
41#define LG_FF2 0x400
Jiri Kosina24985cf2009-11-13 10:45:53 +010042#define LG_RDESC_REL_ABS 0x800
Gary Stein74f292c2010-01-13 00:25:58 +010043#define LG_FF3 0x1000
Simon Wood32c88cb2010-09-22 13:19:42 +020044#define LG_FF4 0x2000
Jiri Slaby5f22a792008-05-16 11:49:19 +020045
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060046/* Size of the original descriptors of the Driving Force (and Pro) wheels */
47#define DF_RDESC_ORIG_SIZE 130
Michael Bauerdc0a4f02011-06-02 15:40:14 -070048#define DFP_RDESC_ORIG_SIZE 97
Simon Wood7f505472013-10-10 08:20:12 -060049#define FV_RDESC_ORIG_SIZE 130
Simon Wood270baef2013-02-19 20:25:10 -070050#define MOMO_RDESC_ORIG_SIZE 87
Simon Wood348cbaa2013-10-10 08:20:13 -060051#define MOMO2_RDESC_ORIG_SIZE 87
Simon Wood560bea32016-09-18 10:55:41 -060052#define FFG_RDESC_ORIG_SIZE 85
Jarrad Whitakere41b3cd2019-01-24 22:40:50 +110053#define FG_RDESC_ORIG_SIZE 82
Michael Bauerdc0a4f02011-06-02 15:40:14 -070054
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060055/* Fixed report descriptors for Logitech Driving Force (and Pro)
56 * wheel controllers
Michael Bauerdc0a4f02011-06-02 15:40:14 -070057 *
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060058 * The original descriptors hide the separate throttle and brake axes in
Michael Bauerdc0a4f02011-06-02 15:40:14 -070059 * a custom vendor usage page, providing only a combined value as
60 * GenericDesktop.Y.
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060061 * These descriptors remove the combined Y axis and instead report
Michael Bauerdc0a4f02011-06-02 15:40:14 -070062 * separate throttle (Y) and brake (RZ).
63 */
Paul Sbarra54bfe3f2013-02-17 11:53:13 -060064static __u8 df_rdesc_fixed[] = {
650x05, 0x01, /* Usage Page (Desktop), */
Antonio Ospitebfb61ab2016-02-09 13:55:04 +0100660x09, 0x04, /* Usage (Joystick), */
Paul Sbarra54bfe3f2013-02-17 11:53:13 -0600670xA1, 0x01, /* Collection (Application), */
680xA1, 0x02, /* Collection (Logical), */
690x95, 0x01, /* Report Count (1), */
700x75, 0x0A, /* Report Size (10), */
710x14, /* Logical Minimum (0), */
720x26, 0xFF, 0x03, /* Logical Maximum (1023), */
730x34, /* Physical Minimum (0), */
740x46, 0xFF, 0x03, /* Physical Maximum (1023), */
750x09, 0x30, /* Usage (X), */
760x81, 0x02, /* Input (Variable), */
770x95, 0x0C, /* Report Count (12), */
780x75, 0x01, /* Report Size (1), */
790x25, 0x01, /* Logical Maximum (1), */
800x45, 0x01, /* Physical Maximum (1), */
810x05, 0x09, /* Usage (Buttons), */
820x19, 0x01, /* Usage Minimum (1), */
830x29, 0x0c, /* Usage Maximum (12), */
840x81, 0x02, /* Input (Variable), */
850x95, 0x02, /* Report Count (2), */
860x06, 0x00, 0xFF, /* Usage Page (Vendor: 65280), */
870x09, 0x01, /* Usage (?: 1), */
880x81, 0x02, /* Input (Variable), */
890x05, 0x01, /* Usage Page (Desktop), */
Paul Sbarra54bfe3f2013-02-17 11:53:13 -0600900x26, 0xFF, 0x00, /* Logical Maximum (255), */
910x46, 0xFF, 0x00, /* Physical Maximum (255), */
920x95, 0x01, /* Report Count (1), */
930x75, 0x08, /* Report Size (8), */
940x81, 0x02, /* Input (Variable), */
950x25, 0x07, /* Logical Maximum (7), */
960x46, 0x3B, 0x01, /* Physical Maximum (315), */
970x75, 0x04, /* Report Size (4), */
980x65, 0x14, /* Unit (Degrees), */
990x09, 0x39, /* Usage (Hat Switch), */
1000x81, 0x42, /* Input (Variable, Null State), */
1010x75, 0x01, /* Report Size (1), */
1020x95, 0x04, /* Report Count (4), */
1030x65, 0x00, /* Unit (none), */
1040x06, 0x00, 0xFF, /* Usage Page (Vendor: 65280), */
1050x09, 0x01, /* Usage (?: 1), */
1060x25, 0x01, /* Logical Maximum (1), */
1070x45, 0x01, /* Physical Maximum (1), */
1080x81, 0x02, /* Input (Variable), */
Paul Sbarra5a9b571b2013-02-17 11:53:14 -06001090x05, 0x01, /* Usage Page (Desktop), */
1100x95, 0x01, /* Report Count (1), */
Paul Sbarra54bfe3f2013-02-17 11:53:13 -06001110x75, 0x08, /* Report Size (8), */
1120x26, 0xFF, 0x00, /* Logical Maximum (255), */
1130x46, 0xFF, 0x00, /* Physical Maximum (255), */
Paul Sbarra5a9b571b2013-02-17 11:53:14 -06001140x09, 0x31, /* Usage (Y), */
1150x81, 0x02, /* Input (Variable), */
1160x09, 0x35, /* Usage (Rz), */
Paul Sbarra54bfe3f2013-02-17 11:53:13 -06001170x81, 0x02, /* Input (Variable), */
1180xC0, /* End Collection, */
1190xA1, 0x02, /* Collection (Logical), */
1200x26, 0xFF, 0x00, /* Logical Maximum (255), */
1210x46, 0xFF, 0x00, /* Physical Maximum (255), */
1220x95, 0x07, /* Report Count (7), */
1230x75, 0x08, /* Report Size (8), */
1240x09, 0x03, /* Usage (?: 3), */
1250x91, 0x02, /* Output (Variable), */
1260xC0, /* End Collection, */
1270xC0 /* End Collection */
128};
129
Michael Bauerdc0a4f02011-06-02 15:40:14 -0700130static __u8 dfp_rdesc_fixed[] = {
1310x05, 0x01, /* Usage Page (Desktop), */
Antonio Ospitebfb61ab2016-02-09 13:55:04 +01001320x09, 0x04, /* Usage (Joystick), */
Michael Bauerdc0a4f02011-06-02 15:40:14 -07001330xA1, 0x01, /* Collection (Application), */
1340xA1, 0x02, /* Collection (Logical), */
1350x95, 0x01, /* Report Count (1), */
1360x75, 0x0E, /* Report Size (14), */
1370x14, /* Logical Minimum (0), */
1380x26, 0xFF, 0x3F, /* Logical Maximum (16383), */
1390x34, /* Physical Minimum (0), */
1400x46, 0xFF, 0x3F, /* Physical Maximum (16383), */
1410x09, 0x30, /* Usage (X), */
1420x81, 0x02, /* Input (Variable), */
1430x95, 0x0E, /* Report Count (14), */
1440x75, 0x01, /* Report Size (1), */
1450x25, 0x01, /* Logical Maximum (1), */
1460x45, 0x01, /* Physical Maximum (1), */
1470x05, 0x09, /* Usage Page (Button), */
1480x19, 0x01, /* Usage Minimum (01h), */
1490x29, 0x0E, /* Usage Maximum (0Eh), */
1500x81, 0x02, /* Input (Variable), */
1510x05, 0x01, /* Usage Page (Desktop), */
1520x95, 0x01, /* Report Count (1), */
1530x75, 0x04, /* Report Size (4), */
1540x25, 0x07, /* Logical Maximum (7), */
1550x46, 0x3B, 0x01, /* Physical Maximum (315), */
1560x65, 0x14, /* Unit (Degrees), */
1570x09, 0x39, /* Usage (Hat Switch), */
1580x81, 0x42, /* Input (Variable, Nullstate), */
1590x65, 0x00, /* Unit, */
1600x26, 0xFF, 0x00, /* Logical Maximum (255), */
1610x46, 0xFF, 0x00, /* Physical Maximum (255), */
1620x75, 0x08, /* Report Size (8), */
1630x81, 0x01, /* Input (Constant), */
1640x09, 0x31, /* Usage (Y), */
1650x81, 0x02, /* Input (Variable), */
1660x09, 0x35, /* Usage (Rz), */
1670x81, 0x02, /* Input (Variable), */
1680x81, 0x01, /* Input (Constant), */
1690xC0, /* End Collection, */
1700xA1, 0x02, /* Collection (Logical), */
1710x09, 0x02, /* Usage (02h), */
1720x95, 0x07, /* Report Count (7), */
1730x91, 0x02, /* Output (Variable), */
1740xC0, /* End Collection, */
1750xC0 /* End Collection */
176};
177
Simon Wood7f505472013-10-10 08:20:12 -0600178static __u8 fv_rdesc_fixed[] = {
1790x05, 0x01, /* Usage Page (Desktop), */
Antonio Ospitebfb61ab2016-02-09 13:55:04 +01001800x09, 0x04, /* Usage (Joystick), */
Simon Wood7f505472013-10-10 08:20:12 -06001810xA1, 0x01, /* Collection (Application), */
1820xA1, 0x02, /* Collection (Logical), */
1830x95, 0x01, /* Report Count (1), */
1840x75, 0x0A, /* Report Size (10), */
1850x15, 0x00, /* Logical Minimum (0), */
1860x26, 0xFF, 0x03, /* Logical Maximum (1023), */
1870x35, 0x00, /* Physical Minimum (0), */
1880x46, 0xFF, 0x03, /* Physical Maximum (1023), */
1890x09, 0x30, /* Usage (X), */
1900x81, 0x02, /* Input (Variable), */
1910x95, 0x0C, /* Report Count (12), */
1920x75, 0x01, /* Report Size (1), */
1930x25, 0x01, /* Logical Maximum (1), */
1940x45, 0x01, /* Physical Maximum (1), */
1950x05, 0x09, /* Usage Page (Button), */
1960x19, 0x01, /* Usage Minimum (01h), */
1970x29, 0x0C, /* Usage Maximum (0Ch), */
1980x81, 0x02, /* Input (Variable), */
1990x95, 0x02, /* Report Count (2), */
2000x06, 0x00, 0xFF, /* Usage Page (FF00h), */
2010x09, 0x01, /* Usage (01h), */
2020x81, 0x02, /* Input (Variable), */
2030x09, 0x02, /* Usage (02h), */
2040x26, 0xFF, 0x00, /* Logical Maximum (255), */
2050x46, 0xFF, 0x00, /* Physical Maximum (255), */
2060x95, 0x01, /* Report Count (1), */
2070x75, 0x08, /* Report Size (8), */
2080x81, 0x02, /* Input (Variable), */
2090x05, 0x01, /* Usage Page (Desktop), */
2100x25, 0x07, /* Logical Maximum (7), */
2110x46, 0x3B, 0x01, /* Physical Maximum (315), */
2120x75, 0x04, /* Report Size (4), */
2130x65, 0x14, /* Unit (Degrees), */
2140x09, 0x39, /* Usage (Hat Switch), */
2150x81, 0x42, /* Input (Variable, Null State), */
2160x75, 0x01, /* Report Size (1), */
2170x95, 0x04, /* Report Count (4), */
2180x65, 0x00, /* Unit, */
2190x06, 0x00, 0xFF, /* Usage Page (FF00h), */
2200x09, 0x01, /* Usage (01h), */
2210x25, 0x01, /* Logical Maximum (1), */
2220x45, 0x01, /* Physical Maximum (1), */
2230x81, 0x02, /* Input (Variable), */
2240x05, 0x01, /* Usage Page (Desktop), */
2250x95, 0x01, /* Report Count (1), */
2260x75, 0x08, /* Report Size (8), */
2270x26, 0xFF, 0x00, /* Logical Maximum (255), */
2280x46, 0xFF, 0x00, /* Physical Maximum (255), */
2290x09, 0x31, /* Usage (Y), */
2300x81, 0x02, /* Input (Variable), */
2310x09, 0x32, /* Usage (Z), */
2320x81, 0x02, /* Input (Variable), */
2330xC0, /* End Collection, */
2340xA1, 0x02, /* Collection (Logical), */
2350x26, 0xFF, 0x00, /* Logical Maximum (255), */
2360x46, 0xFF, 0x00, /* Physical Maximum (255), */
2370x95, 0x07, /* Report Count (7), */
2380x75, 0x08, /* Report Size (8), */
2390x09, 0x03, /* Usage (03h), */
2400x91, 0x02, /* Output (Variable), */
2410xC0, /* End Collection, */
2420xC0 /* End Collection */
243};
244
Simon Wood270baef2013-02-19 20:25:10 -0700245static __u8 momo_rdesc_fixed[] = {
2460x05, 0x01, /* Usage Page (Desktop), */
Antonio Ospitebfb61ab2016-02-09 13:55:04 +01002470x09, 0x04, /* Usage (Joystick), */
Simon Wood270baef2013-02-19 20:25:10 -07002480xA1, 0x01, /* Collection (Application), */
2490xA1, 0x02, /* Collection (Logical), */
2500x95, 0x01, /* Report Count (1), */
2510x75, 0x0A, /* Report Size (10), */
2520x15, 0x00, /* Logical Minimum (0), */
2530x26, 0xFF, 0x03, /* Logical Maximum (1023), */
2540x35, 0x00, /* Physical Minimum (0), */
2550x46, 0xFF, 0x03, /* Physical Maximum (1023), */
2560x09, 0x30, /* Usage (X), */
2570x81, 0x02, /* Input (Variable), */
2580x95, 0x08, /* Report Count (8), */
2590x75, 0x01, /* Report Size (1), */
2600x25, 0x01, /* Logical Maximum (1), */
2610x45, 0x01, /* Physical Maximum (1), */
2620x05, 0x09, /* Usage Page (Button), */
2630x19, 0x01, /* Usage Minimum (01h), */
2640x29, 0x08, /* Usage Maximum (08h), */
2650x81, 0x02, /* Input (Variable), */
2660x06, 0x00, 0xFF, /* Usage Page (FF00h), */
2670x75, 0x0E, /* Report Size (14), */
2680x95, 0x01, /* Report Count (1), */
2690x26, 0xFF, 0x00, /* Logical Maximum (255), */
2700x46, 0xFF, 0x00, /* Physical Maximum (255), */
2710x09, 0x00, /* Usage (00h), */
2720x81, 0x02, /* Input (Variable), */
2730x05, 0x01, /* Usage Page (Desktop), */
2740x75, 0x08, /* Report Size (8), */
2750x09, 0x31, /* Usage (Y), */
2760x81, 0x02, /* Input (Variable), */
2770x09, 0x32, /* Usage (Z), */
2780x81, 0x02, /* Input (Variable), */
2790x06, 0x00, 0xFF, /* Usage Page (FF00h), */
2800x09, 0x01, /* Usage (01h), */
2810x81, 0x02, /* Input (Variable), */
2820xC0, /* End Collection, */
2830xA1, 0x02, /* Collection (Logical), */
2840x09, 0x02, /* Usage (02h), */
2850x95, 0x07, /* Report Count (7), */
2860x91, 0x02, /* Output (Variable), */
2870xC0, /* End Collection, */
2880xC0 /* End Collection */
289};
Michael Bauerdc0a4f02011-06-02 15:40:14 -0700290
Simon Wood348cbaa2013-10-10 08:20:13 -0600291static __u8 momo2_rdesc_fixed[] = {
2920x05, 0x01, /* Usage Page (Desktop), */
Antonio Ospitebfb61ab2016-02-09 13:55:04 +01002930x09, 0x04, /* Usage (Joystick), */
Simon Wood348cbaa2013-10-10 08:20:13 -06002940xA1, 0x01, /* Collection (Application), */
2950xA1, 0x02, /* Collection (Logical), */
2960x95, 0x01, /* Report Count (1), */
2970x75, 0x0A, /* Report Size (10), */
2980x15, 0x00, /* Logical Minimum (0), */
2990x26, 0xFF, 0x03, /* Logical Maximum (1023), */
3000x35, 0x00, /* Physical Minimum (0), */
3010x46, 0xFF, 0x03, /* Physical Maximum (1023), */
3020x09, 0x30, /* Usage (X), */
3030x81, 0x02, /* Input (Variable), */
3040x95, 0x0A, /* Report Count (10), */
3050x75, 0x01, /* Report Size (1), */
3060x25, 0x01, /* Logical Maximum (1), */
3070x45, 0x01, /* Physical Maximum (1), */
3080x05, 0x09, /* Usage Page (Button), */
3090x19, 0x01, /* Usage Minimum (01h), */
3100x29, 0x0A, /* Usage Maximum (0Ah), */
3110x81, 0x02, /* Input (Variable), */
3120x06, 0x00, 0xFF, /* Usage Page (FF00h), */
3130x09, 0x00, /* Usage (00h), */
3140x95, 0x04, /* Report Count (4), */
3150x81, 0x02, /* Input (Variable), */
3160x95, 0x01, /* Report Count (1), */
3170x75, 0x08, /* Report Size (8), */
3180x26, 0xFF, 0x00, /* Logical Maximum (255), */
3190x46, 0xFF, 0x00, /* Physical Maximum (255), */
3200x09, 0x01, /* Usage (01h), */
3210x81, 0x02, /* Input (Variable), */
3220x05, 0x01, /* Usage Page (Desktop), */
3230x09, 0x31, /* Usage (Y), */
3240x81, 0x02, /* Input (Variable), */
3250x09, 0x32, /* Usage (Z), */
3260x81, 0x02, /* Input (Variable), */
3270x06, 0x00, 0xFF, /* Usage Page (FF00h), */
3280x09, 0x00, /* Usage (00h), */
3290x81, 0x02, /* Input (Variable), */
3300xC0, /* End Collection, */
3310xA1, 0x02, /* Collection (Logical), */
3320x09, 0x02, /* Usage (02h), */
3330x95, 0x07, /* Report Count (7), */
3340x91, 0x02, /* Output (Variable), */
3350xC0, /* End Collection, */
3360xC0 /* End Collection */
337};
338
Simon Wood560bea32016-09-18 10:55:41 -0600339static __u8 ffg_rdesc_fixed[] = {
3400x05, 0x01, /* Usage Page (Desktop), */
3410x09, 0x04, /* Usage (Joystik), */
3420xA1, 0x01, /* Collection (Application), */
3430xA1, 0x02, /* Collection (Logical), */
3440x95, 0x01, /* Report Count (1), */
3450x75, 0x0A, /* Report Size (10), */
3460x15, 0x00, /* Logical Minimum (0), */
3470x26, 0xFF, 0x03, /* Logical Maximum (1023), */
3480x35, 0x00, /* Physical Minimum (0), */
3490x46, 0xFF, 0x03, /* Physical Maximum (1023), */
3500x09, 0x30, /* Usage (X), */
3510x81, 0x02, /* Input (Variable), */
3520x95, 0x06, /* Report Count (6), */
3530x75, 0x01, /* Report Size (1), */
3540x25, 0x01, /* Logical Maximum (1), */
3550x45, 0x01, /* Physical Maximum (1), */
3560x05, 0x09, /* Usage Page (Button), */
3570x19, 0x01, /* Usage Minimum (01h), */
3580x29, 0x06, /* Usage Maximum (06h), */
3590x81, 0x02, /* Input (Variable), */
3600x95, 0x01, /* Report Count (1), */
3610x75, 0x08, /* Report Size (8), */
3620x26, 0xFF, 0x00, /* Logical Maximum (255), */
3630x46, 0xFF, 0x00, /* Physical Maximum (255), */
3640x06, 0x00, 0xFF, /* Usage Page (FF00h), */
3650x09, 0x01, /* Usage (01h), */
3660x81, 0x02, /* Input (Variable), */
3670x05, 0x01, /* Usage Page (Desktop), */
3680x81, 0x01, /* Input (Constant), */
3690x09, 0x31, /* Usage (Y), */
3700x81, 0x02, /* Input (Variable), */
3710x09, 0x32, /* Usage (Z), */
3720x81, 0x02, /* Input (Variable), */
3730x06, 0x00, 0xFF, /* Usage Page (FF00h), */
3740x09, 0x01, /* Usage (01h), */
3750x81, 0x02, /* Input (Variable), */
3760xC0, /* End Collection, */
3770xA1, 0x02, /* Collection (Logical), */
3780x09, 0x02, /* Usage (02h), */
3790x95, 0x07, /* Report Count (7), */
3800x91, 0x02, /* Output (Variable), */
3810xC0, /* End Collection, */
3820xC0 /* End Collection */
383};
384
Jarrad Whitakere41b3cd2019-01-24 22:40:50 +1100385static __u8 fg_rdesc_fixed[] = {
3860x05, 0x01, /* Usage Page (Desktop), */
3870x09, 0x04, /* Usage (Joystik), */
3880xA1, 0x01, /* Collection (Application), */
3890xA1, 0x02, /* Collection (Logical), */
3900x15, 0x00, /* Logical Minimum (0), */
3910x26, 0xFF, 0x00, /* Logical Maximum (255), */
3920x35, 0x00, /* Physical Minimum (0), */
3930x46, 0xFF, 0x00, /* Physical Maximum (255), */
3940x75, 0x08, /* Report Size (8), */
3950x95, 0x01, /* Report Count (1), */
3960x09, 0x30, /* Usage (X), */
3970x81, 0x02, /* Input (Variable), */
3980xA4, /* Push, */
3990x25, 0x01, /* Logical Maximum (1), */
4000x45, 0x01, /* Physical Maximum (1), */
4010x75, 0x01, /* Report Size (1), */
4020x95, 0x02, /* Report Count (2), */
4030x81, 0x01, /* Input (Constant), */
4040x95, 0x06, /* Report Count (6), */
4050x05, 0x09, /* Usage Page (Button), */
4060x19, 0x01, /* Usage Minimum (01h), */
4070x29, 0x06, /* Usage Maximum (06h), */
4080x81, 0x02, /* Input (Variable), */
4090x05, 0x01, /* Usage Page (Desktop), */
4100xB4, /* Pop, */
4110x81, 0x02, /* Input (Constant), */
4120x09, 0x31, /* Usage (Y), */
4130x81, 0x02, /* Input (Variable), */
4140x09, 0x32, /* Usage (Z), */
4150x81, 0x02, /* Input (Variable), */
4160xC0, /* End Collection, */
4170xA1, 0x02, /* Collection (Logical), */
4180x26, 0xFF, 0x00, /* Logical Maximum (255), */
4190x46, 0xFF, 0x00, /* Physical Maximum (255), */
4200x75, 0x08, /* Report Size (8), */
4210x95, 0x04, /* Report Count (4), */
4220x09, 0x02, /* Usage (02h), */
4230xB1, 0x02, /* Feature (Variable), */
4240xC0, /* End Collection, */
4250xC0 /* End Collection, */
426};
427
Jiri Slaby5f22a792008-05-16 11:49:19 +0200428/*
429 * Certain Logitech keyboards send in report #3 keys which are far
430 * above the logical maximum described in descriptor. This extends
431 * the original value of 0x28c of logical maximum to 0x104d
432 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400433static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
434 unsigned int *rsize)
Jiri Slaby5f22a792008-05-16 11:49:19 +0200435{
Axel Lin25751552012-09-13 14:08:32 +0800436 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200437
Jiri Kosina4ab25782014-08-21 09:57:48 -0500438 if ((drv_data->quirks & LG_RDESC) && *rsize >= 91 && rdesc[83] == 0x26 &&
Jiri Slaby5f22a792008-05-16 11:49:19 +0200439 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
Joe Perches4291ee32010-12-09 19:29:03 -0800440 hid_info(hdev,
441 "fixing up Logitech keyboard report descriptor\n");
Jiri Slaby5f22a792008-05-16 11:49:19 +0200442 rdesc[84] = rdesc[89] = 0x4d;
443 rdesc[85] = rdesc[90] = 0x10;
444 }
Jiri Kosina4ab25782014-08-21 09:57:48 -0500445 if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 51 &&
Jiri Kosina24985cf2009-11-13 10:45:53 +0100446 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
447 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
Joe Perches4291ee32010-12-09 19:29:03 -0800448 hid_info(hdev,
449 "fixing up rel/abs in Logitech report descriptor\n");
Jiri Kosina24985cf2009-11-13 10:45:53 +0100450 rdesc[33] = rdesc[50] = 0x02;
451 }
Michael Bauerdc0a4f02011-06-02 15:40:14 -0700452
453 switch (hdev->product) {
Paul Sbarra54bfe3f2013-02-17 11:53:13 -0600454
Jarrad Whitakere41b3cd2019-01-24 22:40:50 +1100455 case USB_DEVICE_ID_LOGITECH_WINGMAN_FG:
456 if (*rsize == FG_RDESC_ORIG_SIZE) {
457 hid_info(hdev,
458 "fixing up Logitech Wingman Formula GP report descriptor\n");
459 rdesc = fg_rdesc_fixed;
460 *rsize = sizeof(fg_rdesc_fixed);
461 } else {
462 hid_info(hdev,
463 "rdesc size test failed for formula gp\n");
464 }
465 break;
466
467
Simon Wood560bea32016-09-18 10:55:41 -0600468 case USB_DEVICE_ID_LOGITECH_WINGMAN_FFG:
469 if (*rsize == FFG_RDESC_ORIG_SIZE) {
470 hid_info(hdev,
471 "fixing up Logitech Wingman Formula Force GP report descriptor\n");
472 rdesc = ffg_rdesc_fixed;
473 *rsize = sizeof(ffg_rdesc_fixed);
474 }
475 break;
476
Paul Sbarra54bfe3f2013-02-17 11:53:13 -0600477 /* Several wheels report as this id when operating in emulation mode. */
478 case USB_DEVICE_ID_LOGITECH_WHEEL:
Simon Wood7363b252016-09-18 10:55:40 -0600479 if (*rsize == DF_RDESC_ORIG_SIZE) {
Paul Sbarra54bfe3f2013-02-17 11:53:13 -0600480 hid_info(hdev,
481 "fixing up Logitech Driving Force report descriptor\n");
482 rdesc = df_rdesc_fixed;
483 *rsize = sizeof(df_rdesc_fixed);
484 }
485 break;
486
Simon Wood270baef2013-02-19 20:25:10 -0700487 case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL:
488 if (*rsize == MOMO_RDESC_ORIG_SIZE) {
489 hid_info(hdev,
490 "fixing up Logitech Momo Force (Red) report descriptor\n");
491 rdesc = momo_rdesc_fixed;
492 *rsize = sizeof(momo_rdesc_fixed);
493 }
494 break;
495
Simon Wood348cbaa2013-10-10 08:20:13 -0600496 case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
497 if (*rsize == MOMO2_RDESC_ORIG_SIZE) {
498 hid_info(hdev,
499 "fixing up Logitech Momo Racing Force (Black) report descriptor\n");
500 rdesc = momo2_rdesc_fixed;
501 *rsize = sizeof(momo2_rdesc_fixed);
502 }
503 break;
504
Simon Wood7f505472013-10-10 08:20:12 -0600505 case USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL:
506 if (*rsize == FV_RDESC_ORIG_SIZE) {
507 hid_info(hdev,
508 "fixing up Logitech Formula Vibration report descriptor\n");
509 rdesc = fv_rdesc_fixed;
510 *rsize = sizeof(fv_rdesc_fixed);
511 }
512 break;
513
Michael Bauerdc0a4f02011-06-02 15:40:14 -0700514 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
515 if (*rsize == DFP_RDESC_ORIG_SIZE) {
516 hid_info(hdev,
517 "fixing up Logitech Driving Force Pro report descriptor\n");
518 rdesc = dfp_rdesc_fixed;
519 *rsize = sizeof(dfp_rdesc_fixed);
520 }
521 break;
Simon Woodb58362462013-02-19 20:25:11 -0700522
523 case USB_DEVICE_ID_LOGITECH_WII_WHEEL:
524 if (*rsize >= 101 && rdesc[41] == 0x95 && rdesc[42] == 0x0B &&
525 rdesc[47] == 0x05 && rdesc[48] == 0x09) {
526 hid_info(hdev, "fixing up Logitech Speed Force Wireless report descriptor\n");
527 rdesc[41] = 0x05;
528 rdesc[42] = 0x09;
529 rdesc[47] = 0x95;
530 rdesc[48] = 0x0B;
531 }
532 break;
Michael Bauerdc0a4f02011-06-02 15:40:14 -0700533 }
534
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400535 return rdesc;
Jiri Slaby5f22a792008-05-16 11:49:19 +0200536}
537
538#define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
539 EV_KEY, (c))
540
541static int lg_ultrax_remote_mapping(struct hid_input *hi,
542 struct hid_usage *usage, unsigned long **bit, int *max)
543{
544 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
545 return 0;
546
547 set_bit(EV_REP, hi->input->evbit);
548 switch (usage->hid & HID_USAGE) {
549 /* Reported on Logitech Ultra X Media Remote */
550 case 0x004: lg_map_key_clear(KEY_AGAIN); break;
551 case 0x00d: lg_map_key_clear(KEY_HOME); break;
552 case 0x024: lg_map_key_clear(KEY_SHUFFLE); break;
553 case 0x025: lg_map_key_clear(KEY_TV); break;
554 case 0x026: lg_map_key_clear(KEY_MENU); break;
555 case 0x031: lg_map_key_clear(KEY_AUDIO); break;
556 case 0x032: lg_map_key_clear(KEY_TEXT); break;
557 case 0x033: lg_map_key_clear(KEY_LAST); break;
558 case 0x047: lg_map_key_clear(KEY_MP3); break;
559 case 0x048: lg_map_key_clear(KEY_DVD); break;
560 case 0x049: lg_map_key_clear(KEY_MEDIA); break;
561 case 0x04a: lg_map_key_clear(KEY_VIDEO); break;
562 case 0x04b: lg_map_key_clear(KEY_ANGLE); break;
563 case 0x04c: lg_map_key_clear(KEY_LANGUAGE); break;
564 case 0x04d: lg_map_key_clear(KEY_SUBTITLE); break;
565 case 0x051: lg_map_key_clear(KEY_RED); break;
566 case 0x052: lg_map_key_clear(KEY_CLOSE); break;
567
568 default:
569 return 0;
570 }
571 return 1;
572}
573
Jiri Kosina66d61be2009-11-24 18:22:20 +0100574static int lg_dinovo_mapping(struct hid_input *hi, struct hid_usage *usage,
575 unsigned long **bit, int *max)
576{
577 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
578 return 0;
579
580 switch (usage->hid & HID_USAGE) {
581
582 case 0x00d: lg_map_key_clear(KEY_MEDIA); break;
583 default:
584 return 0;
585
586 }
587 return 1;
588}
589
Jiri Slaby5f22a792008-05-16 11:49:19 +0200590static int lg_wireless_mapping(struct hid_input *hi, struct hid_usage *usage,
591 unsigned long **bit, int *max)
592{
593 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
594 return 0;
595
596 switch (usage->hid & HID_USAGE) {
597 case 0x1001: lg_map_key_clear(KEY_MESSENGER); break;
598 case 0x1003: lg_map_key_clear(KEY_SOUND); break;
599 case 0x1004: lg_map_key_clear(KEY_VIDEO); break;
600 case 0x1005: lg_map_key_clear(KEY_AUDIO); break;
601 case 0x100a: lg_map_key_clear(KEY_DOCUMENTS); break;
Lorenzo Castelli183922122010-04-16 19:00:31 +0200602 /* The following two entries are Playlist 1 and 2 on the MX3200 */
603 case 0x100f: lg_map_key_clear(KEY_FN_1); break;
604 case 0x1010: lg_map_key_clear(KEY_FN_2); break;
Jiri Slaby5f22a792008-05-16 11:49:19 +0200605 case 0x1011: lg_map_key_clear(KEY_PREVIOUSSONG); break;
606 case 0x1012: lg_map_key_clear(KEY_NEXTSONG); break;
607 case 0x1013: lg_map_key_clear(KEY_CAMERA); break;
608 case 0x1014: lg_map_key_clear(KEY_MESSENGER); break;
609 case 0x1015: lg_map_key_clear(KEY_RECORD); break;
610 case 0x1016: lg_map_key_clear(KEY_PLAYER); break;
611 case 0x1017: lg_map_key_clear(KEY_EJECTCD); break;
612 case 0x1018: lg_map_key_clear(KEY_MEDIA); break;
613 case 0x1019: lg_map_key_clear(KEY_PROG1); break;
614 case 0x101a: lg_map_key_clear(KEY_PROG2); break;
615 case 0x101b: lg_map_key_clear(KEY_PROG3); break;
Lorenzo Castelli183922122010-04-16 19:00:31 +0200616 case 0x101c: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
Jiri Slaby5f22a792008-05-16 11:49:19 +0200617 case 0x101f: lg_map_key_clear(KEY_ZOOMIN); break;
618 case 0x1020: lg_map_key_clear(KEY_ZOOMOUT); break;
619 case 0x1021: lg_map_key_clear(KEY_ZOOMRESET); break;
620 case 0x1023: lg_map_key_clear(KEY_CLOSE); break;
621 case 0x1027: lg_map_key_clear(KEY_MENU); break;
622 /* this one is marked as 'Rotate' */
623 case 0x1028: lg_map_key_clear(KEY_ANGLE); break;
624 case 0x1029: lg_map_key_clear(KEY_SHUFFLE); break;
625 case 0x102a: lg_map_key_clear(KEY_BACK); break;
626 case 0x102b: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
Lorenzo Castelli183922122010-04-16 19:00:31 +0200627 case 0x102d: lg_map_key_clear(KEY_WWW); break;
628 /* The following two are 'Start/answer call' and 'End/reject call'
629 on the MX3200 */
630 case 0x1031: lg_map_key_clear(KEY_OK); break;
631 case 0x1032: lg_map_key_clear(KEY_CANCEL); break;
Jiri Slaby5f22a792008-05-16 11:49:19 +0200632 case 0x1041: lg_map_key_clear(KEY_BATTERY); break;
633 case 0x1042: lg_map_key_clear(KEY_WORDPROCESSOR); break;
634 case 0x1043: lg_map_key_clear(KEY_SPREADSHEET); break;
635 case 0x1044: lg_map_key_clear(KEY_PRESENTATION); break;
636 case 0x1045: lg_map_key_clear(KEY_UNDO); break;
637 case 0x1046: lg_map_key_clear(KEY_REDO); break;
638 case 0x1047: lg_map_key_clear(KEY_PRINT); break;
639 case 0x1048: lg_map_key_clear(KEY_SAVE); break;
640 case 0x1049: lg_map_key_clear(KEY_PROG1); break;
641 case 0x104a: lg_map_key_clear(KEY_PROG2); break;
642 case 0x104b: lg_map_key_clear(KEY_PROG3); break;
643 case 0x104c: lg_map_key_clear(KEY_PROG4); break;
644
645 default:
646 return 0;
647 }
648 return 1;
649}
650
651static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi,
652 struct hid_field *field, struct hid_usage *usage,
653 unsigned long **bit, int *max)
654{
655 /* extended mapping for certain Logitech hardware (Logitech cordless
656 desktop LX500) */
657 static const u8 e_keymap[] = {
658 0,216, 0,213,175,156, 0, 0, 0, 0,
659 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
660 174,167,152,161,112, 0, 0, 0,154, 0,
661 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
662 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
663 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
664 0, 0, 0, 0, 0,183,184,185,186,187,
665 188,189,190,191,192,193,194, 0, 0, 0
666 };
Axel Lin25751552012-09-13 14:08:32 +0800667 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200668 unsigned int hid = usage->hid;
669
670 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
671 lg_ultrax_remote_mapping(hi, usage, bit, max))
672 return 1;
673
Jiri Kosina66d61be2009-11-24 18:22:20 +0100674 if (hdev->product == USB_DEVICE_ID_DINOVO_MINI &&
675 lg_dinovo_mapping(hi, usage, bit, max))
676 return 1;
677
Michal Malý8577dbf2012-03-31 11:17:25 +0200678 if ((drv_data->quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
Jiri Slaby5f22a792008-05-16 11:49:19 +0200679 return 1;
680
681 if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
682 return 0;
683
684 hid &= HID_USAGE;
685
686 /* Special handling for Logitech Cordless Desktop */
687 if (field->application == HID_GD_MOUSE) {
Michal Malý8577dbf2012-03-31 11:17:25 +0200688 if ((drv_data->quirks & LG_IGNORE_DOUBLED_WHEEL) &&
Jiri Slaby5f22a792008-05-16 11:49:19 +0200689 (hid == 7 || hid == 8))
690 return -1;
691 } else {
Michal Malý8577dbf2012-03-31 11:17:25 +0200692 if ((drv_data->quirks & LG_EXPANDED_KEYMAP) &&
Jiri Slaby5f22a792008-05-16 11:49:19 +0200693 hid < ARRAY_SIZE(e_keymap) &&
694 e_keymap[hid] != 0) {
695 hid_map_usage(hi, usage, bit, max, EV_KEY,
696 e_keymap[hid]);
697 return 1;
698 }
699 }
700
701 return 0;
702}
703
704static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
705 struct hid_field *field, struct hid_usage *usage,
706 unsigned long **bit, int *max)
707{
Axel Lin25751552012-09-13 14:08:32 +0800708 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200709
Michal Malý8577dbf2012-03-31 11:17:25 +0200710 if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
Jiri Slaby5f22a792008-05-16 11:49:19 +0200711 (field->flags & HID_MAIN_ITEM_RELATIVE))
712 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
713
Michal Malý8577dbf2012-03-31 11:17:25 +0200714 if ((drv_data->quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
Jiri Slaby5f22a792008-05-16 11:49:19 +0200715 usage->type == EV_REL || usage->type == EV_ABS))
716 clear_bit(usage->code, *bit);
717
Simon Wood94b3f712013-02-19 20:25:12 -0700718 /* Ensure that Logitech wheels are not given a default fuzz/flat value */
719 if (usage->type == EV_ABS && (usage->code == ABS_X ||
720 usage->code == ABS_Y || usage->code == ABS_Z ||
721 usage->code == ABS_RZ)) {
722 switch (hdev->product) {
Simon Wood29fae1c2015-11-02 07:56:52 -0700723 case USB_DEVICE_ID_LOGITECH_G29_WHEEL:
Jarrad Whitakere41b3cd2019-01-24 22:40:50 +1100724 case USB_DEVICE_ID_LOGITECH_WINGMAN_FG:
Simon Wood560bea32016-09-18 10:55:41 -0600725 case USB_DEVICE_ID_LOGITECH_WINGMAN_FFG:
Simon Wood94b3f712013-02-19 20:25:12 -0700726 case USB_DEVICE_ID_LOGITECH_WHEEL:
727 case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL:
728 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
729 case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
730 case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
731 case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
732 case USB_DEVICE_ID_LOGITECH_WII_WHEEL:
733 case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
Elias Vanderstuyftbd043632013-10-07 19:48:12 +0300734 case USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL:
Simon Wood94b3f712013-02-19 20:25:12 -0700735 field->application = HID_GD_MULTIAXIS;
736 break;
737 default:
738 break;
739 }
740 }
741
Jiri Slaby5f22a792008-05-16 11:49:19 +0200742 return 0;
743}
744
745static int lg_event(struct hid_device *hdev, struct hid_field *field,
746 struct hid_usage *usage, __s32 value)
747{
Axel Lin25751552012-09-13 14:08:32 +0800748 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200749
Michal Malý8577dbf2012-03-31 11:17:25 +0200750 if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
Jiri Slaby5f22a792008-05-16 11:49:19 +0200751 input_event(field->hidinput->input, usage->type, usage->code,
752 -value);
753 return 1;
754 }
Michal Malý2b24a962012-09-23 22:41:08 +0200755 if (drv_data->quirks & LG_FF4) {
756 return lg4ff_adjust_input_event(hdev, field, usage, value, drv_data);
757 }
Jiri Slaby5f22a792008-05-16 11:49:19 +0200758
759 return 0;
760}
761
Simon Woodc832f862016-09-18 10:55:38 -0600762static int lg_raw_event(struct hid_device *hdev, struct hid_report *report,
763 u8 *rd, int size)
764{
765 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
766
767 if (drv_data->quirks & LG_FF4)
768 return lg4ff_raw_event(hdev, report, rd, size, drv_data);
769
770 return 0;
771}
772
Jiri Slaby5f22a792008-05-16 11:49:19 +0200773static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
774{
Simon Wood29fae1c2015-11-02 07:56:52 -0700775 struct usb_interface *iface = to_usb_interface(hdev->dev.parent);
776 __u8 iface_num = iface->cur_altsetting->desc.bInterfaceNumber;
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200777 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Michal Malý8577dbf2012-03-31 11:17:25 +0200778 struct lg_drv_data *drv_data;
Jiri Slaby5f22a792008-05-16 11:49:19 +0200779 int ret;
780
Benjamin Tissoires20786652015-12-01 10:26:24 +0100781 /* G29 only work with the 1st interface */
782 if ((hdev->product == USB_DEVICE_ID_LOGITECH_G29_WHEEL) &&
783 (iface_num != 0)) {
Simon Wood29fae1c2015-11-02 07:56:52 -0700784 dbg_hid("%s: ignoring ifnum %d\n", __func__, iface_num);
785 return -ENODEV;
786 }
787
Michal Malý8577dbf2012-03-31 11:17:25 +0200788 drv_data = kzalloc(sizeof(struct lg_drv_data), GFP_KERNEL);
789 if (!drv_data) {
790 hid_err(hdev, "Insufficient memory, cannot allocate driver data\n");
791 return -ENOMEM;
792 }
793 drv_data->quirks = id->driver_data;
Michal Malýa80fe5d2012-09-24 01:13:17 +0200794
Michal Malý8577dbf2012-03-31 11:17:25 +0200795 hid_set_drvdata(hdev, (void *)drv_data);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200796
Michal Malý8577dbf2012-03-31 11:17:25 +0200797 if (drv_data->quirks & LG_NOGET)
Jiri Slaby5f22a792008-05-16 11:49:19 +0200798 hdev->quirks |= HID_QUIRK_NOGET;
799
800 ret = hid_parse(hdev);
801 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800802 hid_err(hdev, "parse failed\n");
Jiri Slaby5f22a792008-05-16 11:49:19 +0200803 goto err_free;
804 }
805
Michal Malý8577dbf2012-03-31 11:17:25 +0200806 if (drv_data->quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4))
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200807 connect_mask &= ~HID_CONNECT_FF;
808
809 ret = hid_hw_start(hdev, connect_mask);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200810 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800811 hid_err(hdev, "hw start failed\n");
Jiri Slaby5f22a792008-05-16 11:49:19 +0200812 goto err_free;
813 }
814
Michal Malý7362cd22011-08-04 16:16:09 +0200815 /* Setup wireless link with Logitech Wii wheel */
Michal Malýa80fe5d2012-09-24 01:13:17 +0200816 if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) {
Colin Ian King47af1cd2017-08-25 18:12:50 +0100817 static const unsigned char cbuf[] = {
818 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
819 };
Benjamin Tissoires061232f2016-11-21 11:48:40 +0100820 u8 *buf = kmemdup(cbuf, sizeof(cbuf), GFP_KERNEL);
Simon Wood32c88cb2010-09-22 13:19:42 +0200821
Benjamin Tissoires061232f2016-11-21 11:48:40 +0100822 if (!buf) {
823 ret = -ENOMEM;
824 goto err_free;
825 }
826
827 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(cbuf),
Benjamin Tissoiresb0dd72a2014-02-10 12:58:54 -0500828 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
Simon Wood32c88cb2010-09-22 13:19:42 +0200829 if (ret >= 0) {
830 /* insert a little delay of 10 jiffies ~ 40ms */
831 wait_queue_head_t wait;
832 init_waitqueue_head (&wait);
Nicholas Mc Guiree0393062015-05-02 17:55:15 +0200833 wait_event_interruptible_timeout(wait, 0,
834 msecs_to_jiffies(40));
Simon Wood32c88cb2010-09-22 13:19:42 +0200835
836 /* Select random Address */
837 buf[1] = 0xB2;
838 get_random_bytes(&buf[2], 2);
839
Benjamin Tissoires061232f2016-11-21 11:48:40 +0100840 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(cbuf),
Benjamin Tissoiresb0dd72a2014-02-10 12:58:54 -0500841 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
Simon Wood32c88cb2010-09-22 13:19:42 +0200842 }
Benjamin Tissoires061232f2016-11-21 11:48:40 +0100843 kfree(buf);
Simon Wood32c88cb2010-09-22 13:19:42 +0200844 }
845
Michal Malý8577dbf2012-03-31 11:17:25 +0200846 if (drv_data->quirks & LG_FF)
Michal Malý2dbf6352015-04-08 22:56:45 +0200847 ret = lgff_init(hdev);
Michal Malýf4e1eb92015-04-08 22:56:53 +0200848 else if (drv_data->quirks & LG_FF2)
Michal Malý2dbf6352015-04-08 22:56:45 +0200849 ret = lg2ff_init(hdev);
Michal Malýf4e1eb92015-04-08 22:56:53 +0200850 else if (drv_data->quirks & LG_FF3)
Michal Malý2dbf6352015-04-08 22:56:45 +0200851 ret = lg3ff_init(hdev);
Michal Malýf4e1eb92015-04-08 22:56:53 +0200852 else if (drv_data->quirks & LG_FF4)
Michal Malý2dbf6352015-04-08 22:56:45 +0200853 ret = lg4ff_init(hdev);
854
855 if (ret)
856 goto err_free;
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200857
Jiri Slaby5f22a792008-05-16 11:49:19 +0200858 return 0;
859err_free:
Michal Malý8577dbf2012-03-31 11:17:25 +0200860 kfree(drv_data);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200861 return ret;
862}
863
Michal Malý30bb75d2011-08-04 16:20:40 +0200864static void lg_remove(struct hid_device *hdev)
865{
Axel Lin25751552012-09-13 14:08:32 +0800866 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
Michal Malý8577dbf2012-03-31 11:17:25 +0200867 if (drv_data->quirks & LG_FF4)
Michal Malý30bb75d2011-08-04 16:20:40 +0200868 lg4ff_deinit(hdev);
Michal Malýb211a632015-04-08 22:56:47 +0200869 else
870 hid_hw_stop(hdev);
Michal Malý8577dbf2012-03-31 11:17:25 +0200871 kfree(drv_data);
Michal Malý30bb75d2011-08-04 16:20:40 +0200872}
873
Jiri Slaby5f22a792008-05-16 11:49:19 +0200874static const struct hid_device_id lg_devices[] = {
875 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
876 .driver_data = LG_RDESC | LG_WIRELESS },
877 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
878 .driver_data = LG_RDESC | LG_WIRELESS },
879 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),
880 .driver_data = LG_RDESC | LG_WIRELESS },
881
882 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),
883 .driver_data = LG_BAD_RELATIVE_KEYS },
884
885 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP),
886 .driver_data = LG_DUPLICATE_USAGES },
887 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE),
888 .driver_data = LG_DUPLICATE_USAGES },
889 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI),
890 .driver_data = LG_DUPLICATE_USAGES },
891
Jiri Slaby5f22a792008-05-16 11:49:19 +0200892 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD),
893 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
894 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500),
895 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
896
Jiri Slaby5f22a792008-05-16 11:49:19 +0200897 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D),
898 .driver_data = LG_NOGET },
Vitaly Katraew56d0c8b2013-11-30 13:51:28 +0400899 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DUAL_ACTION),
900 .driver_data = LG_NOGET },
Jiri Slaby5f22a792008-05-16 11:49:19 +0200901 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL),
Michal Malý7362cd22011-08-04 16:16:09 +0200902 .driver_data = LG_NOGET | LG_FF4 },
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200903
Hendrik Iben2c6118e2010-10-04 15:39:49 +0200904 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD),
905 .driver_data = LG_FF2 },
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200906 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD),
907 .driver_data = LG_FF },
908 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2),
909 .driver_data = LG_FF },
Simon Woodc873d9a2015-07-23 19:10:03 -0600910 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G29_WHEEL),
911 .driver_data = LG_FF4 },
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200912 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D),
913 .driver_data = LG_FF },
914 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO),
915 .driver_data = LG_FF },
916 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL),
Simon Wood270baef2013-02-19 20:25:10 -0700917 .driver_data = LG_NOGET | LG_FF4 },
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200918 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2),
Michal Malý7362cd22011-08-04 16:16:09 +0200919 .driver_data = LG_FF4 },
Elias Vanderstuyftbd043632013-10-07 19:48:12 +0300920 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL),
921 .driver_data = LG_FF2 },
Christophe Borivant243b7062009-04-17 11:39:39 +0200922 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL),
Michal Malý7362cd22011-08-04 16:16:09 +0200923 .driver_data = LG_FF4 },
924 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL),
925 .driver_data = LG_FF4 },
Peter Gundermannfdc68072011-05-03 10:15:03 +0200926 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL),
Michal Malý7362cd22011-08-04 16:16:09 +0200927 .driver_data = LG_FF4 },
Jiri Kosina5623a242011-03-17 00:43:23 +0100928 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL),
Michal Malý7362cd22011-08-04 16:16:09 +0200929 .driver_data = LG_NOGET | LG_FF4 },
Simon Wood32c88cb2010-09-22 13:19:42 +0200930 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL),
931 .driver_data = LG_FF4 },
Jarrad Whitakere41b3cd2019-01-24 22:40:50 +1100932 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FG),
933 .driver_data = LG_NOGET },
Michal Malýa80fe5d2012-09-24 01:13:17 +0200934 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG),
Simon Wood560bea32016-09-18 10:55:41 -0600935 .driver_data = LG_NOGET | LG_FF4 },
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200936 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2),
Ardinartsev Nikita877a0212017-01-26 16:54:42 +0300937 .driver_data = LG_NOGET | LG_FF2 },
Gary Stein74f292c2010-01-13 00:25:58 +0100938 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940),
939 .driver_data = LG_FF3 },
Jiri Kosina24985cf2009-11-13 10:45:53 +0100940 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR),
941 .driver_data = LG_RDESC_REL_ABS },
942 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER),
943 .driver_data = LG_RDESC_REL_ABS },
Jiri Slaby5f22a792008-05-16 11:49:19 +0200944 { }
945};
Jiri Kosina24985cf2009-11-13 10:45:53 +0100946
Jiri Slaby5f22a792008-05-16 11:49:19 +0200947MODULE_DEVICE_TABLE(hid, lg_devices);
948
949static struct hid_driver lg_driver = {
950 .name = "logitech",
951 .id_table = lg_devices,
952 .report_fixup = lg_report_fixup,
953 .input_mapping = lg_input_mapping,
954 .input_mapped = lg_input_mapped,
955 .event = lg_event,
Simon Woodc832f862016-09-18 10:55:38 -0600956 .raw_event = lg_raw_event,
Jiri Slaby5f22a792008-05-16 11:49:19 +0200957 .probe = lg_probe,
Michal Malý30bb75d2011-08-04 16:20:40 +0200958 .remove = lg_remove,
Jiri Slaby5f22a792008-05-16 11:49:19 +0200959};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700960module_hid_driver(lg_driver);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200961
Michal Malýa54dc7792015-02-18 17:59:22 +0100962#ifdef CONFIG_LOGIWHEELS_FF
963int lg4ff_no_autoswitch = 0;
964module_param_named(lg4ff_no_autoswitch, lg4ff_no_autoswitch, int, S_IRUGO);
965MODULE_PARM_DESC(lg4ff_no_autoswitch, "Do not switch multimode wheels to their native mode automatically");
966#endif
967
Jiri Slaby5f22a792008-05-16 11:49:19 +0200968MODULE_LICENSE("GPL");