diff options
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/Kconfig | 29 | ||||
-rw-r--r-- | drivers/hid/Makefile | 3 | ||||
-rw-r--r-- | drivers/hid/hid-axff.c | 36 | ||||
-rw-r--r-- | drivers/hid/hid-core.c | 11 | ||||
-rw-r--r-- | drivers/hid/hid-ids.h | 9 | ||||
-rw-r--r-- | drivers/hid/hid-input.c | 11 | ||||
-rw-r--r-- | drivers/hid/hid-lg.c | 29 | ||||
-rw-r--r-- | drivers/hid/hid-lg.h | 4 | ||||
-rw-r--r-- | drivers/hid/hid-lg4ff.c | 403 | ||||
-rw-r--r-- | drivers/hid/hid-lgff.c | 13 | ||||
-rw-r--r-- | drivers/hid/hid-logitech-dj.c | 922 | ||||
-rw-r--r-- | drivers/hid/hid-logitech-dj.h | 123 | ||||
-rw-r--r-- | drivers/hid/hid-multitouch.c | 93 | ||||
-rw-r--r-- | drivers/hid/hid-roccat-kone.c | 63 | ||||
-rw-r--r-- | drivers/hid/hid-roccat-kovaplus.c | 17 | ||||
-rw-r--r-- | drivers/hid/hid-roccat-pyra.c | 23 | ||||
-rw-r--r-- | drivers/hid/hid-wacom.c | 3 | ||||
-rw-r--r-- | drivers/hid/hid-wiimote.c | 800 |
18 files changed, 2462 insertions, 130 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 1130a8987125..2b006bfa0935 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -69,7 +69,7 @@ config HID_ACRUX | |||
69 | Say Y here if you want to enable support for ACRUX game controllers. | 69 | Say Y here if you want to enable support for ACRUX game controllers. |
70 | 70 | ||
71 | config HID_ACRUX_FF | 71 | config HID_ACRUX_FF |
72 | tristate "ACRUX force feedback support" | 72 | bool "ACRUX force feedback support" |
73 | depends on HID_ACRUX | 73 | depends on HID_ACRUX |
74 | select INPUT_FF_MEMLESS | 74 | select INPUT_FF_MEMLESS |
75 | ---help--- | 75 | ---help--- |
@@ -245,6 +245,15 @@ config HID_LOGITECH | |||
245 | ---help--- | 245 | ---help--- |
246 | Support for Logitech devices that are not fully compliant with HID standard. | 246 | Support for Logitech devices that are not fully compliant with HID standard. |
247 | 247 | ||
248 | config HID_LOGITECH_DJ | ||
249 | tristate "Logitech Unifying receivers full support" | ||
250 | depends on HID_LOGITECH | ||
251 | default m | ||
252 | ---help--- | ||
253 | Say Y if you want support for Logitech Unifying receivers and devices. | ||
254 | Unifying receivers are capable of pairing up to 6 Logitech compliant | ||
255 | devices to the same receiver. | ||
256 | |||
248 | config LOGITECH_FF | 257 | config LOGITECH_FF |
249 | bool "Logitech force feedback support" | 258 | bool "Logitech force feedback support" |
250 | depends on HID_LOGITECH | 259 | depends on HID_LOGITECH |
@@ -278,13 +287,21 @@ config LOGIG940_FF | |||
278 | Say Y here if you want to enable force feedback support for Logitech | 287 | Say Y here if you want to enable force feedback support for Logitech |
279 | Flight System G940 devices. | 288 | Flight System G940 devices. |
280 | 289 | ||
281 | config LOGIWII_FF | 290 | config LOGIWHEELS_FF |
282 | bool "Logitech Speed Force Wireless force feedback support" | 291 | bool "Logitech wheels configuration and force feedback support" |
283 | depends on HID_LOGITECH | 292 | depends on HID_LOGITECH |
284 | select INPUT_FF_MEMLESS | 293 | select INPUT_FF_MEMLESS |
294 | default LOGITECH_FF | ||
285 | help | 295 | help |
286 | Say Y here if you want to enable force feedback support for Logitech | 296 | Say Y here if you want to enable force feedback and range setting |
287 | Speed Force Wireless (Wii) devices. | 297 | support for following Logitech wheels: |
298 | - Logitech Driving Force | ||
299 | - Logitech Driving Force Pro | ||
300 | - Logitech Driving Force GT | ||
301 | - Logitech G25 | ||
302 | - Logitech G27 | ||
303 | - Logitech MOMO/MOMO 2 | ||
304 | - Logitech Formula Force EX | ||
288 | 305 | ||
289 | config HID_MAGICMOUSE | 306 | config HID_MAGICMOUSE |
290 | tristate "Apple MagicMouse multi-touch support" | 307 | tristate "Apple MagicMouse multi-touch support" |
@@ -328,6 +345,7 @@ config HID_MULTITOUCH | |||
328 | - Hanvon dual touch panels | 345 | - Hanvon dual touch panels |
329 | - Ilitek dual touch panels | 346 | - Ilitek dual touch panels |
330 | - IrTouch Infrared USB panels | 347 | - IrTouch Infrared USB panels |
348 | - LG Display panels (Dell ST2220Tc) | ||
331 | - Lumio CrystalTouch panels | 349 | - Lumio CrystalTouch panels |
332 | - MosArt dual-touch panels | 350 | - MosArt dual-touch panels |
333 | - PenMount dual touch panels | 351 | - PenMount dual touch panels |
@@ -590,6 +608,7 @@ config HID_WIIMOTE | |||
590 | tristate "Nintendo Wii Remote support" | 608 | tristate "Nintendo Wii Remote support" |
591 | depends on BT_HIDP | 609 | depends on BT_HIDP |
592 | depends on LEDS_CLASS | 610 | depends on LEDS_CLASS |
611 | select POWER_SUPPLY | ||
593 | ---help--- | 612 | ---help--- |
594 | Support for the Nintendo Wii Remote bluetooth device. | 613 | Support for the Nintendo Wii Remote bluetooth device. |
595 | 614 | ||
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 0a0a38e9fd28..b7ddabb0b34c 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -21,7 +21,7 @@ endif | |||
21 | ifdef CONFIG_LOGIG940_FF | 21 | ifdef CONFIG_LOGIG940_FF |
22 | hid-logitech-y += hid-lg3ff.o | 22 | hid-logitech-y += hid-lg3ff.o |
23 | endif | 23 | endif |
24 | ifdef CONFIG_LOGIWII_FF | 24 | ifdef CONFIG_LOGIWHEELS_FF |
25 | hid-logitech-y += hid-lg4ff.o | 25 | hid-logitech-y += hid-lg4ff.o |
26 | endif | 26 | endif |
27 | 27 | ||
@@ -43,6 +43,7 @@ obj-$(CONFIG_HID_KEYTOUCH) += hid-keytouch.o | |||
43 | obj-$(CONFIG_HID_KYE) += hid-kye.o | 43 | obj-$(CONFIG_HID_KYE) += hid-kye.o |
44 | obj-$(CONFIG_HID_LCPOWER) += hid-lcpower.o | 44 | obj-$(CONFIG_HID_LCPOWER) += hid-lcpower.o |
45 | obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o | 45 | obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o |
46 | obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o | ||
46 | obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o | 47 | obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o |
47 | obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o | 48 | obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o |
48 | obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o | 49 | obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o |
diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c index 121514149e0b..3bdb4500f95e 100644 --- a/drivers/hid/hid-axff.c +++ b/drivers/hid/hid-axff.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * Xbox 360 controller. | 6 | * Xbox 360 controller. |
7 | * | 7 | * |
8 | * 1a34:0802 "ACRUX USB GAMEPAD 8116" | 8 | * 1a34:0802 "ACRUX USB GAMEPAD 8116" |
9 | * - tested with a EXEQ EQ-PCU-02090 game controller. | 9 | * - tested with an EXEQ EQ-PCU-02090 game controller. |
10 | * | 10 | * |
11 | * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru> | 11 | * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru> |
12 | */ | 12 | */ |
@@ -45,7 +45,10 @@ static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect | |||
45 | { | 45 | { |
46 | struct hid_device *hid = input_get_drvdata(dev); | 46 | struct hid_device *hid = input_get_drvdata(dev); |
47 | struct axff_device *axff = data; | 47 | struct axff_device *axff = data; |
48 | struct hid_report *report = axff->report; | ||
49 | int field_count = 0; | ||
48 | int left, right; | 50 | int left, right; |
51 | int i, j; | ||
49 | 52 | ||
50 | left = effect->u.rumble.strong_magnitude; | 53 | left = effect->u.rumble.strong_magnitude; |
51 | right = effect->u.rumble.weak_magnitude; | 54 | right = effect->u.rumble.weak_magnitude; |
@@ -55,10 +58,14 @@ static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect | |||
55 | left = left * 0xff / 0xffff; | 58 | left = left * 0xff / 0xffff; |
56 | right = right * 0xff / 0xffff; | 59 | right = right * 0xff / 0xffff; |
57 | 60 | ||
58 | axff->report->field[0]->value[0] = left; | 61 | for (i = 0; i < report->maxfield; i++) { |
59 | axff->report->field[1]->value[0] = right; | 62 | for (j = 0; j < report->field[i]->report_count; j++) { |
60 | axff->report->field[2]->value[0] = left; | 63 | report->field[i]->value[j] = |
61 | axff->report->field[3]->value[0] = right; | 64 | field_count % 2 ? right : left; |
65 | field_count++; | ||
66 | } | ||
67 | } | ||
68 | |||
62 | dbg_hid("running with 0x%02x 0x%02x", left, right); | 69 | dbg_hid("running with 0x%02x 0x%02x", left, right); |
63 | usbhid_submit_report(hid, axff->report, USB_DIR_OUT); | 70 | usbhid_submit_report(hid, axff->report, USB_DIR_OUT); |
64 | 71 | ||
@@ -72,6 +79,8 @@ static int axff_init(struct hid_device *hid) | |||
72 | struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list); | 79 | struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list); |
73 | struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list; | 80 | struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list; |
74 | struct input_dev *dev = hidinput->input; | 81 | struct input_dev *dev = hidinput->input; |
82 | int field_count = 0; | ||
83 | int i, j; | ||
75 | int error; | 84 | int error; |
76 | 85 | ||
77 | if (list_empty(report_list)) { | 86 | if (list_empty(report_list)) { |
@@ -80,9 +89,16 @@ static int axff_init(struct hid_device *hid) | |||
80 | } | 89 | } |
81 | 90 | ||
82 | report = list_first_entry(report_list, struct hid_report, list); | 91 | report = list_first_entry(report_list, struct hid_report, list); |
92 | for (i = 0; i < report->maxfield; i++) { | ||
93 | for (j = 0; j < report->field[i]->report_count; j++) { | ||
94 | report->field[i]->value[j] = 0x00; | ||
95 | field_count++; | ||
96 | } | ||
97 | } | ||
83 | 98 | ||
84 | if (report->maxfield < 4) { | 99 | if (field_count < 4) { |
85 | hid_err(hid, "no fields in the report: %d\n", report->maxfield); | 100 | hid_err(hid, "not enough fields in the report: %d\n", |
101 | field_count); | ||
86 | return -ENODEV; | 102 | return -ENODEV; |
87 | } | 103 | } |
88 | 104 | ||
@@ -97,13 +113,9 @@ static int axff_init(struct hid_device *hid) | |||
97 | goto err_free_mem; | 113 | goto err_free_mem; |
98 | 114 | ||
99 | axff->report = report; | 115 | axff->report = report; |
100 | axff->report->field[0]->value[0] = 0x00; | ||
101 | axff->report->field[1]->value[0] = 0x00; | ||
102 | axff->report->field[2]->value[0] = 0x00; | ||
103 | axff->report->field[3]->value[0] = 0x00; | ||
104 | usbhid_submit_report(hid, axff->report, USB_DIR_OUT); | 116 | usbhid_submit_report(hid, axff->report, USB_DIR_OUT); |
105 | 117 | ||
106 | hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n"); | 118 | hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <x0r@dv-life.ru>\n"); |
107 | 119 | ||
108 | return 0; | 120 | return 0; |
109 | 121 | ||
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 242353df3dc4..c5606724b77a 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -1212,6 +1212,12 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) | |||
1212 | if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, | 1212 | if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, |
1213 | connect_mask & HID_CONNECT_HIDINPUT_FORCE)) | 1213 | connect_mask & HID_CONNECT_HIDINPUT_FORCE)) |
1214 | hdev->claimed |= HID_CLAIMED_INPUT; | 1214 | hdev->claimed |= HID_CLAIMED_INPUT; |
1215 | if (hdev->quirks & HID_QUIRK_MULTITOUCH) { | ||
1216 | /* this device should be handled by hid-multitouch, skip it */ | ||
1217 | hdev->quirks &= ~HID_QUIRK_MULTITOUCH; | ||
1218 | return -ENODEV; | ||
1219 | } | ||
1220 | |||
1215 | if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && | 1221 | if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && |
1216 | !hdev->hiddev_connect(hdev, | 1222 | !hdev->hiddev_connect(hdev, |
1217 | connect_mask & HID_CONNECT_HIDDEV_FORCE)) | 1223 | connect_mask & HID_CONNECT_HIDDEV_FORCE)) |
@@ -1391,6 +1397,7 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1391 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, | 1397 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, |
1392 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, | 1398 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, |
1393 | { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) }, | 1399 | { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) }, |
1400 | { HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, USB_DEVICE_ID_IDEACOM_IDC6650) }, | ||
1394 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) }, | 1401 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) }, |
1395 | { HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) }, | 1402 | { HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) }, |
1396 | { HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, | 1403 | { HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, |
@@ -1399,6 +1406,7 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1399 | { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, | 1406 | { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, |
1400 | { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, | 1407 | { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, |
1401 | { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, | 1408 | { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, |
1409 | { HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MULTITOUCH) }, | ||
1402 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, | 1410 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, |
1403 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, | 1411 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, |
1404 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, | 1412 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, |
@@ -1420,8 +1428,11 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1420 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, | 1428 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, |
1421 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, | 1429 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, |
1422 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) }, | 1430 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) }, |
1431 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) }, | ||
1423 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, | 1432 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, |
1424 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) }, | 1433 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) }, |
1434 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) }, | ||
1435 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) }, | ||
1425 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) }, | 1436 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) }, |
1426 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, | 1437 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, |
1427 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, | 1438 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 7484e1b67249..d5dbb1a4f76b 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
@@ -351,6 +351,9 @@ | |||
351 | #define USB_DEVICE_ID_UGCI_FLYING 0x0020 | 351 | #define USB_DEVICE_ID_UGCI_FLYING 0x0020 |
352 | #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 | 352 | #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 |
353 | 353 | ||
354 | #define USB_VENDOR_ID_IDEACOM 0x1cb6 | ||
355 | #define USB_DEVICE_ID_IDEACOM_IDC6650 0x6650 | ||
356 | |||
354 | #define USB_VENDOR_ID_ILITEK 0x222a | 357 | #define USB_VENDOR_ID_ILITEK 0x222a |
355 | #define USB_DEVICE_ID_ILITEK_MULTITOUCH 0x0001 | 358 | #define USB_DEVICE_ID_ILITEK_MULTITOUCH 0x0001 |
356 | 359 | ||
@@ -423,6 +426,9 @@ | |||
423 | #define USB_DEVICE_ID_LD_HYBRID 0x2090 | 426 | #define USB_DEVICE_ID_LD_HYBRID 0x2090 |
424 | #define USB_DEVICE_ID_LD_HEATCONTROL 0x20A0 | 427 | #define USB_DEVICE_ID_LD_HEATCONTROL 0x20A0 |
425 | 428 | ||
429 | #define USB_VENDOR_ID_LG 0x1fd2 | ||
430 | #define USB_DEVICE_ID_LG_MULTITOUCH 0x0064 | ||
431 | |||
426 | #define USB_VENDOR_ID_LOGITECH 0x046d | 432 | #define USB_VENDOR_ID_LOGITECH 0x046d |
427 | #define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 | 433 | #define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 |
428 | #define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110 | 434 | #define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110 |
@@ -440,6 +446,7 @@ | |||
440 | #define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL 0xc295 | 446 | #define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL 0xc295 |
441 | #define USB_DEVICE_ID_LOGITECH_DFP_WHEEL 0xc298 | 447 | #define USB_DEVICE_ID_LOGITECH_DFP_WHEEL 0xc298 |
442 | #define USB_DEVICE_ID_LOGITECH_G25_WHEEL 0xc299 | 448 | #define USB_DEVICE_ID_LOGITECH_G25_WHEEL 0xc299 |
449 | #define USB_DEVICE_ID_LOGITECH_DFGT_WHEEL 0xc29a | ||
443 | #define USB_DEVICE_ID_LOGITECH_G27_WHEEL 0xc29b | 450 | #define USB_DEVICE_ID_LOGITECH_G27_WHEEL 0xc29b |
444 | #define USB_DEVICE_ID_LOGITECH_WII_WHEEL 0xc29c | 451 | #define USB_DEVICE_ID_LOGITECH_WII_WHEEL 0xc29c |
445 | #define USB_DEVICE_ID_LOGITECH_ELITE_KBD 0xc30a | 452 | #define USB_DEVICE_ID_LOGITECH_ELITE_KBD 0xc30a |
@@ -447,6 +454,8 @@ | |||
447 | #define USB_DEVICE_ID_S510_RECEIVER_2 0xc517 | 454 | #define USB_DEVICE_ID_S510_RECEIVER_2 0xc517 |
448 | #define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512 | 455 | #define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512 |
449 | #define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 | 456 | #define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 |
457 | #define USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER 0xc52b | ||
458 | #define USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2 0xc532 | ||
450 | #define USB_DEVICE_ID_SPACETRAVELLER 0xc623 | 459 | #define USB_DEVICE_ID_SPACETRAVELLER 0xc623 |
451 | #define USB_DEVICE_ID_SPACENAVIGATOR 0xc626 | 460 | #define USB_DEVICE_ID_SPACENAVIGATOR 0xc626 |
452 | #define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704 | 461 | #define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704 |
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 6559e2e3364e..f333139d1a48 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -474,6 +474,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel | |||
474 | map_key_clear(BTN_STYLUS2); | 474 | map_key_clear(BTN_STYLUS2); |
475 | break; | 475 | break; |
476 | 476 | ||
477 | case 0x51: /* ContactID */ | ||
478 | device->quirks |= HID_QUIRK_MULTITOUCH; | ||
479 | goto unknown; | ||
480 | |||
477 | default: goto unknown; | 481 | default: goto unknown; |
478 | } | 482 | } |
479 | break; | 483 | break; |
@@ -978,6 +982,13 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
978 | } | 982 | } |
979 | } | 983 | } |
980 | 984 | ||
985 | if (hid->quirks & HID_QUIRK_MULTITOUCH) { | ||
986 | /* generic hid does not know how to handle multitouch devices */ | ||
987 | if (hidinput) | ||
988 | goto out_cleanup; | ||
989 | goto out_unwind; | ||
990 | } | ||
991 | |||
981 | if (hidinput && input_register_device(hidinput->input)) | 992 | if (hidinput && input_register_device(hidinput->input)) |
982 | goto out_cleanup; | 993 | goto out_cleanup; |
983 | 994 | ||
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c index a7f916e8fc32..e7a7bd1eb34a 100644 --- a/drivers/hid/hid-lg.c +++ b/drivers/hid/hid-lg.c | |||
@@ -363,7 +363,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
363 | goto err_free; | 363 | goto err_free; |
364 | } | 364 | } |
365 | 365 | ||
366 | if (quirks & (LG_FF | LG_FF2 | LG_FF3)) | 366 | if (quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4)) |
367 | connect_mask &= ~HID_CONNECT_FF; | 367 | connect_mask &= ~HID_CONNECT_FF; |
368 | 368 | ||
369 | ret = hid_hw_start(hdev, connect_mask); | 369 | ret = hid_hw_start(hdev, connect_mask); |
@@ -372,7 +372,8 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
372 | goto err_free; | 372 | goto err_free; |
373 | } | 373 | } |
374 | 374 | ||
375 | if (quirks & LG_FF4) { | 375 | /* Setup wireless link with Logitech Wii wheel */ |
376 | if(hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { | ||
376 | unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | 377 | unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
377 | 378 | ||
378 | ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); | 379 | ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); |
@@ -405,6 +406,15 @@ err_free: | |||
405 | return ret; | 406 | return ret; |
406 | } | 407 | } |
407 | 408 | ||
409 | static void lg_remove(struct hid_device *hdev) | ||
410 | { | ||
411 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
412 | if(quirks & LG_FF4) | ||
413 | lg4ff_deinit(hdev); | ||
414 | |||
415 | hid_hw_stop(hdev); | ||
416 | } | ||
417 | |||
408 | static const struct hid_device_id lg_devices[] = { | 418 | static const struct hid_device_id lg_devices[] = { |
409 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER), | 419 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER), |
410 | .driver_data = LG_RDESC | LG_WIRELESS }, | 420 | .driver_data = LG_RDESC | LG_WIRELESS }, |
@@ -431,7 +441,7 @@ static const struct hid_device_id lg_devices[] = { | |||
431 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D), | 441 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D), |
432 | .driver_data = LG_NOGET }, | 442 | .driver_data = LG_NOGET }, |
433 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL), | 443 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL), |
434 | .driver_data = LG_NOGET | LG_FF }, | 444 | .driver_data = LG_NOGET | LG_FF4 }, |
435 | 445 | ||
436 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD), | 446 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD), |
437 | .driver_data = LG_FF2 }, | 447 | .driver_data = LG_FF2 }, |
@@ -444,15 +454,17 @@ static const struct hid_device_id lg_devices[] = { | |||
444 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO), | 454 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO), |
445 | .driver_data = LG_FF }, | 455 | .driver_data = LG_FF }, |
446 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL), | 456 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL), |
447 | .driver_data = LG_FF }, | 457 | .driver_data = LG_FF4 }, |
448 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2), | 458 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2), |
449 | .driver_data = LG_FF }, | 459 | .driver_data = LG_FF4 }, |
450 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL), | 460 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL), |
451 | .driver_data = LG_FF }, | 461 | .driver_data = LG_FF4 }, |
462 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL), | ||
463 | .driver_data = LG_FF4 }, | ||
452 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL), | 464 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL), |
453 | .driver_data = LG_FF }, | 465 | .driver_data = LG_FF4 }, |
454 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL), | 466 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL), |
455 | .driver_data = LG_NOGET | LG_FF }, | 467 | .driver_data = LG_NOGET | LG_FF4 }, |
456 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL), | 468 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL), |
457 | .driver_data = LG_FF4 }, | 469 | .driver_data = LG_FF4 }, |
458 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ), | 470 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ), |
@@ -478,6 +490,7 @@ static struct hid_driver lg_driver = { | |||
478 | .input_mapped = lg_input_mapped, | 490 | .input_mapped = lg_input_mapped, |
479 | .event = lg_event, | 491 | .event = lg_event, |
480 | .probe = lg_probe, | 492 | .probe = lg_probe, |
493 | .remove = lg_remove, | ||
481 | }; | 494 | }; |
482 | 495 | ||
483 | static int __init lg_init(void) | 496 | static int __init lg_init(void) |
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h index b0100ba2ae0b..4b097286dc78 100644 --- a/drivers/hid/hid-lg.h +++ b/drivers/hid/hid-lg.h | |||
@@ -19,10 +19,12 @@ int lg3ff_init(struct hid_device *hdev); | |||
19 | static inline int lg3ff_init(struct hid_device *hdev) { return -1; } | 19 | static inline int lg3ff_init(struct hid_device *hdev) { return -1; } |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #ifdef CONFIG_LOGIWII_FF | 22 | #ifdef CONFIG_LOGIWHEELS_FF |
23 | int lg4ff_init(struct hid_device *hdev); | 23 | int lg4ff_init(struct hid_device *hdev); |
24 | int lg4ff_deinit(struct hid_device *hdev); | ||
24 | #else | 25 | #else |
25 | static inline int lg4ff_init(struct hid_device *hdev) { return -1; } | 26 | static inline int lg4ff_init(struct hid_device *hdev) { return -1; } |
27 | static inline int lg4ff_deinit(struct hid_device *hdev) { return -1; } | ||
26 | #endif | 28 | #endif |
27 | 29 | ||
28 | #endif | 30 | #endif |
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index fa550c8e1d1b..103f30d93f76 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c | |||
@@ -29,19 +29,108 @@ | |||
29 | 29 | ||
30 | #include "usbhid/usbhid.h" | 30 | #include "usbhid/usbhid.h" |
31 | #include "hid-lg.h" | 31 | #include "hid-lg.h" |
32 | #include "hid-ids.h" | ||
32 | 33 | ||
33 | struct lg4ff_device { | 34 | #define DFGT_REV_MAJ 0x13 |
34 | struct hid_report *report; | 35 | #define DFGT_REV_MIN 0x22 |
36 | #define DFP_REV_MAJ 0x11 | ||
37 | #define DFP_REV_MIN 0x06 | ||
38 | #define FFEX_REV_MAJ 0x21 | ||
39 | #define FFEX_REV_MIN 0x00 | ||
40 | #define G25_REV_MAJ 0x12 | ||
41 | #define G25_REV_MIN 0x22 | ||
42 | #define G27_REV_MAJ 0x12 | ||
43 | #define G27_REV_MIN 0x38 | ||
44 | |||
45 | #define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) | ||
46 | |||
47 | static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range); | ||
48 | static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range); | ||
49 | static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr, char *buf); | ||
50 | static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); | ||
51 | |||
52 | static DEVICE_ATTR(range, S_IRWXU | S_IRWXG | S_IRWXO, lg4ff_range_show, lg4ff_range_store); | ||
53 | |||
54 | static bool list_inited; | ||
55 | |||
56 | struct lg4ff_device_entry { | ||
57 | char *device_id; /* Use name in respective kobject structure's address as the ID */ | ||
58 | __u16 range; | ||
59 | __u16 min_range; | ||
60 | __u16 max_range; | ||
61 | __u8 leds; | ||
62 | struct list_head list; | ||
63 | void (*set_range)(struct hid_device *hid, u16 range); | ||
35 | }; | 64 | }; |
36 | 65 | ||
37 | static const signed short ff4_wheel_ac[] = { | 66 | static struct lg4ff_device_entry device_list; |
67 | |||
68 | static const signed short lg4ff_wheel_effects[] = { | ||
38 | FF_CONSTANT, | 69 | FF_CONSTANT, |
39 | FF_AUTOCENTER, | 70 | FF_AUTOCENTER, |
40 | -1 | 71 | -1 |
41 | }; | 72 | }; |
42 | 73 | ||
43 | static int hid_lg4ff_play(struct input_dev *dev, void *data, | 74 | struct lg4ff_wheel { |
44 | struct ff_effect *effect) | 75 | const __u32 product_id; |
76 | const signed short *ff_effects; | ||
77 | const __u16 min_range; | ||
78 | const __u16 max_range; | ||
79 | void (*set_range)(struct hid_device *hid, u16 range); | ||
80 | }; | ||
81 | |||
82 | static const struct lg4ff_wheel lg4ff_devices[] = { | ||
83 | {USB_DEVICE_ID_LOGITECH_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, | ||
84 | {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, | ||
85 | {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_dfp}, | ||
86 | {USB_DEVICE_ID_LOGITECH_G25_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_g25}, | ||
87 | {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_g25}, | ||
88 | {USB_DEVICE_ID_LOGITECH_G27_WHEEL, lg4ff_wheel_effects, 40, 900, hid_lg4ff_set_range_g25}, | ||
89 | {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2, lg4ff_wheel_effects, 40, 270, NULL}, | ||
90 | {USB_DEVICE_ID_LOGITECH_WII_WHEEL, lg4ff_wheel_effects, 40, 270, NULL} | ||
91 | }; | ||
92 | |||
93 | struct lg4ff_native_cmd { | ||
94 | const __u8 cmd_num; /* Number of commands to send */ | ||
95 | const __u8 cmd[]; | ||
96 | }; | ||
97 | |||
98 | struct lg4ff_usb_revision { | ||
99 | const __u16 rev_maj; | ||
100 | const __u16 rev_min; | ||
101 | const struct lg4ff_native_cmd *command; | ||
102 | }; | ||
103 | |||
104 | static const struct lg4ff_native_cmd native_dfp = { | ||
105 | 1, | ||
106 | {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00} | ||
107 | }; | ||
108 | |||
109 | static const struct lg4ff_native_cmd native_dfgt = { | ||
110 | 2, | ||
111 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1st command */ | ||
112 | 0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00} /* 2nd command */ | ||
113 | }; | ||
114 | |||
115 | static const struct lg4ff_native_cmd native_g25 = { | ||
116 | 1, | ||
117 | {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00} | ||
118 | }; | ||
119 | |||
120 | static const struct lg4ff_native_cmd native_g27 = { | ||
121 | 2, | ||
122 | {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1st command */ | ||
123 | 0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00} /* 2nd command */ | ||
124 | }; | ||
125 | |||
126 | static const struct lg4ff_usb_revision lg4ff_revs[] = { | ||
127 | {DFGT_REV_MAJ, DFGT_REV_MIN, &native_dfgt}, /* Driving Force GT */ | ||
128 | {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */ | ||
129 | {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */ | ||
130 | {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ | ||
131 | }; | ||
132 | |||
133 | static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *effect) | ||
45 | { | 134 | { |
46 | struct hid_device *hid = input_get_drvdata(dev); | 135 | struct hid_device *hid = input_get_drvdata(dev); |
47 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 136 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
@@ -55,13 +144,12 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, | |||
55 | x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ | 144 | x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ |
56 | CLAMP(x); | 145 | CLAMP(x); |
57 | report->field[0]->value[0] = 0x11; /* Slot 1 */ | 146 | report->field[0]->value[0] = 0x11; /* Slot 1 */ |
58 | report->field[0]->value[1] = 0x10; | 147 | report->field[0]->value[1] = 0x08; |
59 | report->field[0]->value[2] = x; | 148 | report->field[0]->value[2] = x; |
60 | report->field[0]->value[3] = 0x00; | 149 | report->field[0]->value[3] = 0x80; |
61 | report->field[0]->value[4] = 0x00; | 150 | report->field[0]->value[4] = 0x00; |
62 | report->field[0]->value[5] = 0x08; | 151 | report->field[0]->value[5] = 0x00; |
63 | report->field[0]->value[6] = 0x00; | 152 | report->field[0]->value[6] = 0x00; |
64 | dbg_hid("Autocenter, x=0x%02X\n", x); | ||
65 | 153 | ||
66 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 154 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
67 | break; | 155 | break; |
@@ -69,24 +157,184 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, | |||
69 | return 0; | 157 | return 0; |
70 | } | 158 | } |
71 | 159 | ||
72 | static void hid_lg4ff_set_autocenter(struct input_dev *dev, u16 magnitude) | 160 | /* Sends default autocentering command compatible with |
161 | * all wheels except Formula Force EX */ | ||
162 | static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitude) | ||
73 | { | 163 | { |
74 | struct hid_device *hid = input_get_drvdata(dev); | 164 | struct hid_device *hid = input_get_drvdata(dev); |
75 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 165 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
76 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | 166 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
77 | __s32 *value = report->field[0]->value; | ||
78 | 167 | ||
79 | *value++ = 0xfe; | 168 | report->field[0]->value[0] = 0xfe; |
80 | *value++ = 0x0d; | 169 | report->field[0]->value[1] = 0x0d; |
81 | *value++ = 0x07; | 170 | report->field[0]->value[2] = magnitude >> 13; |
82 | *value++ = 0x07; | 171 | report->field[0]->value[3] = magnitude >> 13; |
83 | *value++ = (magnitude >> 8) & 0xff; | 172 | report->field[0]->value[4] = magnitude >> 8; |
84 | *value++ = 0x00; | 173 | report->field[0]->value[5] = 0x00; |
85 | *value = 0x00; | 174 | report->field[0]->value[6] = 0x00; |
175 | |||
176 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
177 | } | ||
178 | |||
179 | /* Sends autocentering command compatible with Formula Force EX */ | ||
180 | static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude) | ||
181 | { | ||
182 | struct hid_device *hid = input_get_drvdata(dev); | ||
183 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
184 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | ||
185 | magnitude = magnitude * 90 / 65535; | ||
186 | |||
187 | |||
188 | report->field[0]->value[0] = 0xfe; | ||
189 | report->field[0]->value[1] = 0x03; | ||
190 | report->field[0]->value[2] = magnitude >> 14; | ||
191 | report->field[0]->value[3] = magnitude >> 14; | ||
192 | report->field[0]->value[4] = magnitude; | ||
193 | report->field[0]->value[5] = 0x00; | ||
194 | report->field[0]->value[6] = 0x00; | ||
195 | |||
196 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
197 | } | ||
198 | |||
199 | /* Sends command to set range compatible with G25/G27/Driving Force GT */ | ||
200 | static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range) | ||
201 | { | ||
202 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
203 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | ||
204 | dbg_hid("G25/G27/DFGT: setting range to %u\n", range); | ||
205 | |||
206 | report->field[0]->value[0] = 0xf8; | ||
207 | report->field[0]->value[1] = 0x81; | ||
208 | report->field[0]->value[2] = range & 0x00ff; | ||
209 | report->field[0]->value[3] = (range & 0xff00) >> 8; | ||
210 | report->field[0]->value[4] = 0x00; | ||
211 | report->field[0]->value[5] = 0x00; | ||
212 | report->field[0]->value[6] = 0x00; | ||
213 | |||
214 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
215 | } | ||
216 | |||
217 | /* Sends commands to set range compatible with Driving Force Pro wheel */ | ||
218 | static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) | ||
219 | { | ||
220 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
221 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | ||
222 | int start_left, start_right, full_range; | ||
223 | dbg_hid("Driving Force Pro: setting range to %u\n", range); | ||
224 | |||
225 | /* Prepare "coarse" limit command */ | ||
226 | report->field[0]->value[0] = 0xf8; | ||
227 | report->field[0]->value[1] = 0x00; /* Set later */ | ||
228 | report->field[0]->value[2] = 0x00; | ||
229 | report->field[0]->value[3] = 0x00; | ||
230 | report->field[0]->value[4] = 0x00; | ||
231 | report->field[0]->value[5] = 0x00; | ||
232 | report->field[0]->value[6] = 0x00; | ||
233 | |||
234 | if (range > 200) { | ||
235 | report->field[0]->value[1] = 0x03; | ||
236 | full_range = 900; | ||
237 | } else { | ||
238 | report->field[0]->value[1] = 0x02; | ||
239 | full_range = 200; | ||
240 | } | ||
241 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
242 | |||
243 | /* Prepare "fine" limit command */ | ||
244 | report->field[0]->value[0] = 0x81; | ||
245 | report->field[0]->value[1] = 0x0b; | ||
246 | report->field[0]->value[2] = 0x00; | ||
247 | report->field[0]->value[3] = 0x00; | ||
248 | report->field[0]->value[4] = 0x00; | ||
249 | report->field[0]->value[5] = 0x00; | ||
250 | report->field[0]->value[6] = 0x00; | ||
251 | |||
252 | if (range == 200 || range == 900) { /* Do not apply any fine limit */ | ||
253 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
254 | return; | ||
255 | } | ||
256 | |||
257 | /* Construct fine limit command */ | ||
258 | start_left = (((full_range - range + 1) * 2047) / full_range); | ||
259 | start_right = 0xfff - start_left; | ||
260 | |||
261 | report->field[0]->value[2] = start_left >> 4; | ||
262 | report->field[0]->value[3] = start_right >> 4; | ||
263 | report->field[0]->value[4] = 0xff; | ||
264 | report->field[0]->value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); | ||
265 | report->field[0]->value[6] = 0xff; | ||
86 | 266 | ||
87 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 267 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
88 | } | 268 | } |
89 | 269 | ||
270 | static void hid_lg4ff_switch_native(struct hid_device *hid, const struct lg4ff_native_cmd *cmd) | ||
271 | { | ||
272 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
273 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | ||
274 | __u8 i, j; | ||
275 | |||
276 | j = 0; | ||
277 | while (j < 7*cmd->cmd_num) { | ||
278 | for (i = 0; i < 7; i++) | ||
279 | report->field[0]->value[i] = cmd->cmd[j++]; | ||
280 | |||
281 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
282 | } | ||
283 | } | ||
284 | |||
285 | /* Read current range and display it in terminal */ | ||
286 | static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr, char *buf) | ||
287 | { | ||
288 | struct lg4ff_device_entry *uninitialized_var(entry); | ||
289 | struct list_head *h; | ||
290 | struct hid_device *hid = to_hid_device(dev); | ||
291 | size_t count; | ||
292 | |||
293 | list_for_each(h, &device_list.list) { | ||
294 | entry = list_entry(h, struct lg4ff_device_entry, list); | ||
295 | if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) | ||
296 | break; | ||
297 | } | ||
298 | if (h == &device_list.list) { | ||
299 | dbg_hid("Device not found!"); | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | count = scnprintf(buf, PAGE_SIZE, "%u\n", entry->range); | ||
304 | return count; | ||
305 | } | ||
306 | |||
307 | /* Set range to user specified value, call appropriate function | ||
308 | * according to the type of the wheel */ | ||
309 | static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | ||
310 | { | ||
311 | struct lg4ff_device_entry *uninitialized_var(entry); | ||
312 | struct list_head *h; | ||
313 | struct hid_device *hid = to_hid_device(dev); | ||
314 | __u16 range = simple_strtoul(buf, NULL, 10); | ||
315 | |||
316 | list_for_each(h, &device_list.list) { | ||
317 | entry = list_entry(h, struct lg4ff_device_entry, list); | ||
318 | if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) | ||
319 | break; | ||
320 | } | ||
321 | if (h == &device_list.list) { | ||
322 | dbg_hid("Device not found!"); | ||
323 | return count; | ||
324 | } | ||
325 | |||
326 | if (range == 0) | ||
327 | range = entry->max_range; | ||
328 | |||
329 | /* Check if the wheel supports range setting | ||
330 | * and that the range is within limits for the wheel */ | ||
331 | if (entry->set_range != NULL && range >= entry->min_range && range <= entry->max_range) { | ||
332 | entry->set_range(hid, range); | ||
333 | entry->range = range; | ||
334 | } | ||
335 | |||
336 | return count; | ||
337 | } | ||
90 | 338 | ||
91 | int lg4ff_init(struct hid_device *hid) | 339 | int lg4ff_init(struct hid_device *hid) |
92 | { | 340 | { |
@@ -95,9 +343,10 @@ int lg4ff_init(struct hid_device *hid) | |||
95 | struct input_dev *dev = hidinput->input; | 343 | struct input_dev *dev = hidinput->input; |
96 | struct hid_report *report; | 344 | struct hid_report *report; |
97 | struct hid_field *field; | 345 | struct hid_field *field; |
98 | const signed short *ff_bits = ff4_wheel_ac; | 346 | struct lg4ff_device_entry *entry; |
99 | int error; | 347 | struct usb_device_descriptor *udesc; |
100 | int i; | 348 | int error, i, j; |
349 | __u16 bcdDevice, rev_maj, rev_min; | ||
101 | 350 | ||
102 | /* Find the report to use */ | 351 | /* Find the report to use */ |
103 | if (list_empty(report_list)) { | 352 | if (list_empty(report_list)) { |
@@ -118,18 +367,122 @@ int lg4ff_init(struct hid_device *hid) | |||
118 | return -1; | 367 | return -1; |
119 | } | 368 | } |
120 | 369 | ||
121 | for (i = 0; ff_bits[i] >= 0; i++) | 370 | /* Check what wheel has been connected */ |
122 | set_bit(ff_bits[i], dev->ffbit); | 371 | for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) { |
372 | if (hid->product == lg4ff_devices[i].product_id) { | ||
373 | dbg_hid("Found compatible device, product ID %04X\n", lg4ff_devices[i].product_id); | ||
374 | break; | ||
375 | } | ||
376 | } | ||
377 | |||
378 | if (i == ARRAY_SIZE(lg4ff_devices)) { | ||
379 | hid_err(hid, "Device is not supported by lg4ff driver. If you think it should be, consider reporting a bug to" | ||
380 | "LKML, Simon Wood <simon@mungewell.org> or Michal Maly <madcatxster@gmail.com>\n"); | ||
381 | return -1; | ||
382 | } | ||
383 | |||
384 | /* Attempt to switch wheel to native mode when applicable */ | ||
385 | udesc = &(hid_to_usb_dev(hid)->descriptor); | ||
386 | if (!udesc) { | ||
387 | hid_err(hid, "NULL USB device descriptor\n"); | ||
388 | return -1; | ||
389 | } | ||
390 | bcdDevice = le16_to_cpu(udesc->bcdDevice); | ||
391 | rev_maj = bcdDevice >> 8; | ||
392 | rev_min = bcdDevice & 0xff; | ||
393 | |||
394 | if (lg4ff_devices[i].product_id == USB_DEVICE_ID_LOGITECH_WHEEL) { | ||
395 | dbg_hid("Generic wheel detected, can it do native?\n"); | ||
396 | dbg_hid("USB revision: %2x.%02x\n", rev_maj, rev_min); | ||
397 | |||
398 | for (j = 0; j < ARRAY_SIZE(lg4ff_revs); j++) { | ||
399 | if (lg4ff_revs[j].rev_maj == rev_maj && lg4ff_revs[j].rev_min == rev_min) { | ||
400 | hid_lg4ff_switch_native(hid, lg4ff_revs[j].command); | ||
401 | hid_info(hid, "Switched to native mode\n"); | ||
402 | } | ||
403 | } | ||
404 | } | ||
405 | |||
406 | /* Set supported force feedback capabilities */ | ||
407 | for (j = 0; lg4ff_devices[i].ff_effects[j] >= 0; j++) | ||
408 | set_bit(lg4ff_devices[i].ff_effects[j], dev->ffbit); | ||
123 | 409 | ||
124 | error = input_ff_create_memless(dev, NULL, hid_lg4ff_play); | 410 | error = input_ff_create_memless(dev, NULL, hid_lg4ff_play); |
125 | 411 | ||
126 | if (error) | 412 | if (error) |
127 | return error; | 413 | return error; |
128 | 414 | ||
129 | if (test_bit(FF_AUTOCENTER, dev->ffbit)) | 415 | /* Check if autocentering is available and |
130 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter; | 416 | * set the centering force to zero by default */ |
417 | if (test_bit(FF_AUTOCENTER, dev->ffbit)) { | ||
418 | if(rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */ | ||
419 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; | ||
420 | else | ||
421 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; | ||
422 | |||
423 | dev->ff->set_autocenter(dev, 0); | ||
424 | } | ||
425 | |||
426 | /* Initialize device_list if this is the first device to handle by lg4ff */ | ||
427 | if (!list_inited) { | ||
428 | INIT_LIST_HEAD(&device_list.list); | ||
429 | list_inited = 1; | ||
430 | } | ||
431 | |||
432 | /* Add the device to device_list */ | ||
433 | entry = (struct lg4ff_device_entry *)kzalloc(sizeof(struct lg4ff_device_entry), GFP_KERNEL); | ||
434 | if (!entry) { | ||
435 | hid_err(hid, "Cannot add device, insufficient memory.\n"); | ||
436 | return -ENOMEM; | ||
437 | } | ||
438 | entry->device_id = kstrdup((&hid->dev)->kobj.name, GFP_KERNEL); | ||
439 | if (!entry->device_id) { | ||
440 | hid_err(hid, "Cannot set device_id, insufficient memory.\n"); | ||
441 | kfree(entry); | ||
442 | return -ENOMEM; | ||
443 | } | ||
444 | entry->min_range = lg4ff_devices[i].min_range; | ||
445 | entry->max_range = lg4ff_devices[i].max_range; | ||
446 | entry->set_range = lg4ff_devices[i].set_range; | ||
447 | list_add(&entry->list, &device_list.list); | ||
448 | |||
449 | /* Create sysfs interface */ | ||
450 | error = device_create_file(&hid->dev, &dev_attr_range); | ||
451 | if (error) | ||
452 | return error; | ||
453 | dbg_hid("sysfs interface created\n"); | ||
454 | |||
455 | /* Set the maximum range to start with */ | ||
456 | entry->range = entry->max_range; | ||
457 | if (entry->set_range != NULL) | ||
458 | entry->set_range(hid, entry->range); | ||
131 | 459 | ||
132 | hid_info(hid, "Force feedback for Logitech Speed Force Wireless by Simon Wood <simon@mungewell.org>\n"); | 460 | hid_info(hid, "Force feedback for Logitech Speed Force Wireless by Simon Wood <simon@mungewell.org>\n"); |
133 | return 0; | 461 | return 0; |
134 | } | 462 | } |
135 | 463 | ||
464 | int lg4ff_deinit(struct hid_device *hid) | ||
465 | { | ||
466 | bool found = 0; | ||
467 | struct lg4ff_device_entry *entry; | ||
468 | struct list_head *h, *g; | ||
469 | list_for_each_safe(h, g, &device_list.list) { | ||
470 | entry = list_entry(h, struct lg4ff_device_entry, list); | ||
471 | if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) { | ||
472 | list_del(h); | ||
473 | kfree(entry->device_id); | ||
474 | kfree(entry); | ||
475 | found = 1; | ||
476 | break; | ||
477 | } | ||
478 | } | ||
479 | |||
480 | if (!found) { | ||
481 | dbg_hid("Device entry not found!\n"); | ||
482 | return -1; | ||
483 | } | ||
484 | |||
485 | device_remove_file(&hid->dev, &dev_attr_range); | ||
486 | dbg_hid("Device successfully unregistered\n"); | ||
487 | return 0; | ||
488 | } | ||
diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c index 088f85049290..27bc54f92f44 100644 --- a/drivers/hid/hid-lgff.c +++ b/drivers/hid/hid-lgff.c | |||
@@ -58,12 +58,6 @@ static const signed short ff_joystick_ac[] = { | |||
58 | -1 | 58 | -1 |
59 | }; | 59 | }; |
60 | 60 | ||
61 | static const signed short ff_wheel[] = { | ||
62 | FF_CONSTANT, | ||
63 | FF_AUTOCENTER, | ||
64 | -1 | ||
65 | }; | ||
66 | |||
67 | static const struct dev_type devices[] = { | 61 | static const struct dev_type devices[] = { |
68 | { 0x046d, 0xc211, ff_rumble }, | 62 | { 0x046d, 0xc211, ff_rumble }, |
69 | { 0x046d, 0xc219, ff_rumble }, | 63 | { 0x046d, 0xc219, ff_rumble }, |
@@ -71,14 +65,7 @@ static const struct dev_type devices[] = { | |||
71 | { 0x046d, 0xc286, ff_joystick_ac }, | 65 | { 0x046d, 0xc286, ff_joystick_ac }, |
72 | { 0x046d, 0xc287, ff_joystick_ac }, | 66 | { 0x046d, 0xc287, ff_joystick_ac }, |
73 | { 0x046d, 0xc293, ff_joystick }, | 67 | { 0x046d, 0xc293, ff_joystick }, |
74 | { 0x046d, 0xc294, ff_wheel }, | ||
75 | { 0x046d, 0xc298, ff_wheel }, | ||
76 | { 0x046d, 0xc299, ff_wheel }, | ||
77 | { 0x046d, 0xc29b, ff_wheel }, | ||
78 | { 0x046d, 0xc295, ff_joystick }, | 68 | { 0x046d, 0xc295, ff_joystick }, |
79 | { 0x046d, 0xc298, ff_wheel }, | ||
80 | { 0x046d, 0xc299, ff_wheel }, | ||
81 | { 0x046d, 0xca03, ff_wheel }, | ||
82 | }; | 69 | }; |
83 | 70 | ||
84 | static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) | 71 | static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) |
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c new file mode 100644 index 000000000000..38b12e45780c --- /dev/null +++ b/drivers/hid/hid-logitech-dj.c | |||
@@ -0,0 +1,922 @@ | |||
1 | /* | ||
2 | * HID driver for Logitech Unifying receivers | ||
3 | * | ||
4 | * Copyright (c) 2011 Logitech | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | |||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | |||
25 | #include <linux/device.h> | ||
26 | #include <linux/hid.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/usb.h> | ||
29 | #include "usbhid/usbhid.h" | ||
30 | #include "hid-ids.h" | ||
31 | #include "hid-logitech-dj.h" | ||
32 | |||
33 | /* Keyboard descriptor (1) */ | ||
34 | static const char kbd_descriptor[] = { | ||
35 | 0x05, 0x01, /* USAGE_PAGE (generic Desktop) */ | ||
36 | 0x09, 0x06, /* USAGE (Keyboard) */ | ||
37 | 0xA1, 0x01, /* COLLECTION (Application) */ | ||
38 | 0x85, 0x01, /* REPORT_ID (1) */ | ||
39 | 0x95, 0x08, /* REPORT_COUNT (8) */ | ||
40 | 0x75, 0x01, /* REPORT_SIZE (1) */ | ||
41 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | ||
42 | 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ | ||
43 | 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ | ||
44 | 0x19, 0xE0, /* USAGE_MINIMUM (Left Control) */ | ||
45 | 0x29, 0xE7, /* USAGE_MAXIMUM (Right GUI) */ | ||
46 | 0x81, 0x02, /* INPUT (Data,Var,Abs) */ | ||
47 | 0x95, 0x05, /* REPORT COUNT (5) */ | ||
48 | 0x05, 0x08, /* USAGE PAGE (LED page) */ | ||
49 | 0x19, 0x01, /* USAGE MINIMUM (1) */ | ||
50 | 0x29, 0x05, /* USAGE MAXIMUM (5) */ | ||
51 | 0x91, 0x02, /* OUTPUT (Data, Variable, Absolute) */ | ||
52 | 0x95, 0x01, /* REPORT COUNT (1) */ | ||
53 | 0x75, 0x03, /* REPORT SIZE (3) */ | ||
54 | 0x91, 0x01, /* OUTPUT (Constant) */ | ||
55 | 0x95, 0x06, /* REPORT_COUNT (6) */ | ||
56 | 0x75, 0x08, /* REPORT_SIZE (8) */ | ||
57 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | ||
58 | 0x26, 0xFF, 0x00, /* LOGICAL_MAXIMUM (255) */ | ||
59 | 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ | ||
60 | 0x19, 0x00, /* USAGE_MINIMUM (no event) */ | ||
61 | 0x2A, 0xFF, 0x00, /* USAGE_MAXIMUM (reserved) */ | ||
62 | 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ | ||
63 | 0xC0 | ||
64 | }; | ||
65 | |||
66 | /* Mouse descriptor (2) */ | ||
67 | static const char mse_descriptor[] = { | ||
68 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ | ||
69 | 0x09, 0x02, /* USAGE (Mouse) */ | ||
70 | 0xA1, 0x01, /* COLLECTION (Application) */ | ||
71 | 0x85, 0x02, /* REPORT_ID = 2 */ | ||
72 | 0x09, 0x01, /* USAGE (pointer) */ | ||
73 | 0xA1, 0x00, /* COLLECTION (physical) */ | ||
74 | 0x05, 0x09, /* USAGE_PAGE (buttons) */ | ||
75 | 0x19, 0x01, /* USAGE_MIN (1) */ | ||
76 | 0x29, 0x10, /* USAGE_MAX (16) */ | ||
77 | 0x15, 0x00, /* LOGICAL_MIN (0) */ | ||
78 | 0x25, 0x01, /* LOGICAL_MAX (1) */ | ||
79 | 0x95, 0x10, /* REPORT_COUNT (16) */ | ||
80 | 0x75, 0x01, /* REPORT_SIZE (1) */ | ||
81 | 0x81, 0x02, /* INPUT (data var abs) */ | ||
82 | 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ | ||
83 | 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */ | ||
84 | 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */ | ||
85 | 0x75, 0x0C, /* REPORT_SIZE (12) */ | ||
86 | 0x95, 0x02, /* REPORT_COUNT (2) */ | ||
87 | 0x09, 0x30, /* USAGE (X) */ | ||
88 | 0x09, 0x31, /* USAGE (Y) */ | ||
89 | 0x81, 0x06, /* INPUT */ | ||
90 | 0x15, 0x81, /* LOGICAL_MIN (-127) */ | ||
91 | 0x25, 0x7F, /* LOGICAL_MAX (127) */ | ||
92 | 0x75, 0x08, /* REPORT_SIZE (8) */ | ||
93 | 0x95, 0x01, /* REPORT_COUNT (1) */ | ||
94 | 0x09, 0x38, /* USAGE (wheel) */ | ||
95 | 0x81, 0x06, /* INPUT */ | ||
96 | 0x05, 0x0C, /* USAGE_PAGE(consumer) */ | ||
97 | 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ | ||
98 | 0x95, 0x01, /* REPORT_COUNT (1) */ | ||
99 | 0x81, 0x06, /* INPUT */ | ||
100 | 0xC0, /* END_COLLECTION */ | ||
101 | 0xC0, /* END_COLLECTION */ | ||
102 | }; | ||
103 | |||
104 | /* Consumer Control descriptor (3) */ | ||
105 | static const char consumer_descriptor[] = { | ||
106 | 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */ | ||
107 | 0x09, 0x01, /* USAGE (Consumer Control) */ | ||
108 | 0xA1, 0x01, /* COLLECTION (Application) */ | ||
109 | 0x85, 0x03, /* REPORT_ID = 3 */ | ||
110 | 0x75, 0x10, /* REPORT_SIZE (16) */ | ||
111 | 0x95, 0x02, /* REPORT_COUNT (2) */ | ||
112 | 0x15, 0x01, /* LOGICAL_MIN (1) */ | ||
113 | 0x26, 0x8C, 0x02, /* LOGICAL_MAX (652) */ | ||
114 | 0x19, 0x01, /* USAGE_MIN (1) */ | ||
115 | 0x2A, 0x8C, 0x02, /* USAGE_MAX (652) */ | ||
116 | 0x81, 0x00, /* INPUT (Data Ary Abs) */ | ||
117 | 0xC0, /* END_COLLECTION */ | ||
118 | }; /* */ | ||
119 | |||
120 | /* System control descriptor (4) */ | ||
121 | static const char syscontrol_descriptor[] = { | ||
122 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ | ||
123 | 0x09, 0x80, /* USAGE (System Control) */ | ||
124 | 0xA1, 0x01, /* COLLECTION (Application) */ | ||
125 | 0x85, 0x04, /* REPORT_ID = 4 */ | ||
126 | 0x75, 0x02, /* REPORT_SIZE (2) */ | ||
127 | 0x95, 0x01, /* REPORT_COUNT (1) */ | ||
128 | 0x15, 0x01, /* LOGICAL_MIN (1) */ | ||
129 | 0x25, 0x03, /* LOGICAL_MAX (3) */ | ||
130 | 0x09, 0x82, /* USAGE (System Sleep) */ | ||
131 | 0x09, 0x81, /* USAGE (System Power Down) */ | ||
132 | 0x09, 0x83, /* USAGE (System Wake Up) */ | ||
133 | 0x81, 0x60, /* INPUT (Data Ary Abs NPrf Null) */ | ||
134 | 0x75, 0x06, /* REPORT_SIZE (6) */ | ||
135 | 0x81, 0x03, /* INPUT (Cnst Var Abs) */ | ||
136 | 0xC0, /* END_COLLECTION */ | ||
137 | }; | ||
138 | |||
139 | /* Media descriptor (8) */ | ||
140 | static const char media_descriptor[] = { | ||
141 | 0x06, 0xbc, 0xff, /* Usage Page 0xffbc */ | ||
142 | 0x09, 0x88, /* Usage 0x0088 */ | ||
143 | 0xa1, 0x01, /* BeginCollection */ | ||
144 | 0x85, 0x08, /* Report ID 8 */ | ||
145 | 0x19, 0x01, /* Usage Min 0x0001 */ | ||
146 | 0x29, 0xff, /* Usage Max 0x00ff */ | ||
147 | 0x15, 0x01, /* Logical Min 1 */ | ||
148 | 0x26, 0xff, 0x00, /* Logical Max 255 */ | ||
149 | 0x75, 0x08, /* Report Size 8 */ | ||
150 | 0x95, 0x01, /* Report Count 1 */ | ||
151 | 0x81, 0x00, /* Input */ | ||
152 | 0xc0, /* EndCollection */ | ||
153 | }; /* */ | ||
154 | |||
155 | /* Maximum size of all defined hid reports in bytes (including report id) */ | ||
156 | #define MAX_REPORT_SIZE 8 | ||
157 | |||
158 | /* Number of possible hid report types that can be created by this driver. | ||
159 | * | ||
160 | * Right now, RF report types have the same report types (or report id's) | ||
161 | * than the hid report created from those RF reports. In the future | ||
162 | * this doesnt have to be true. | ||
163 | * | ||
164 | * For instance, RF report type 0x01 which has a size of 8 bytes, corresponds | ||
165 | * to hid report id 0x01, this is standard keyboard. Same thing applies to mice | ||
166 | * reports and consumer control, etc. If a new RF report is created, it doesn't | ||
167 | * has to have the same report id as its corresponding hid report, so an | ||
168 | * translation may have to take place for future report types. | ||
169 | */ | ||
170 | #define NUMBER_OF_HID_REPORTS 32 | ||
171 | static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = { | ||
172 | [1] = 8, /* Standard keyboard */ | ||
173 | [2] = 8, /* Standard mouse */ | ||
174 | [3] = 5, /* Consumer control */ | ||
175 | [4] = 2, /* System control */ | ||
176 | [8] = 2, /* Media Center */ | ||
177 | }; | ||
178 | |||
179 | |||
180 | #define LOGITECH_DJ_INTERFACE_NUMBER 0x02 | ||
181 | |||
182 | static struct hid_ll_driver logi_dj_ll_driver; | ||
183 | |||
184 | static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | ||
185 | size_t count, | ||
186 | unsigned char report_type); | ||
187 | |||
188 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, | ||
189 | struct dj_report *dj_report) | ||
190 | { | ||
191 | /* Called in delayed work context */ | ||
192 | struct dj_device *dj_dev; | ||
193 | unsigned long flags; | ||
194 | |||
195 | spin_lock_irqsave(&djrcv_dev->lock, flags); | ||
196 | dj_dev = djrcv_dev->paired_dj_devices[dj_report->device_index]; | ||
197 | djrcv_dev->paired_dj_devices[dj_report->device_index] = NULL; | ||
198 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); | ||
199 | |||
200 | if (dj_dev != NULL) { | ||
201 | hid_destroy_device(dj_dev->hdev); | ||
202 | kfree(dj_dev); | ||
203 | } else { | ||
204 | dev_err(&djrcv_dev->hdev->dev, "%s: can't destroy a NULL device\n", | ||
205 | __func__); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, | ||
210 | struct dj_report *dj_report) | ||
211 | { | ||
212 | /* Called in delayed work context */ | ||
213 | struct hid_device *djrcv_hdev = djrcv_dev->hdev; | ||
214 | struct usb_interface *intf = to_usb_interface(djrcv_hdev->dev.parent); | ||
215 | struct usb_device *usbdev = interface_to_usbdev(intf); | ||
216 | struct hid_device *dj_hiddev; | ||
217 | struct dj_device *dj_dev; | ||
218 | |||
219 | /* Device index goes from 1 to 6, we need 3 bytes to store the | ||
220 | * semicolon, the index, and a null terminator | ||
221 | */ | ||
222 | unsigned char tmpstr[3]; | ||
223 | |||
224 | if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] & | ||
225 | SPFUNCTION_DEVICE_LIST_EMPTY) { | ||
226 | dbg_hid("%s: device list is empty\n", __func__); | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) || | ||
231 | (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) { | ||
232 | dev_err(&djrcv_hdev->dev, "%s: invalid device index:%d\n", | ||
233 | __func__, dj_report->device_index); | ||
234 | return; | ||
235 | } | ||
236 | |||
237 | dj_hiddev = hid_allocate_device(); | ||
238 | if (IS_ERR(dj_hiddev)) { | ||
239 | dev_err(&djrcv_hdev->dev, "%s: hid_allocate_device failed\n", | ||
240 | __func__); | ||
241 | return; | ||
242 | } | ||
243 | |||
244 | dj_hiddev->ll_driver = &logi_dj_ll_driver; | ||
245 | dj_hiddev->hid_output_raw_report = logi_dj_output_hidraw_report; | ||
246 | |||
247 | dj_hiddev->dev.parent = &djrcv_hdev->dev; | ||
248 | dj_hiddev->bus = BUS_USB; | ||
249 | dj_hiddev->vendor = le16_to_cpu(usbdev->descriptor.idVendor); | ||
250 | dj_hiddev->product = le16_to_cpu(usbdev->descriptor.idProduct); | ||
251 | snprintf(dj_hiddev->name, sizeof(dj_hiddev->name), | ||
252 | "Logitech Unifying Device. Wireless PID:%02x%02x", | ||
253 | dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB], | ||
254 | dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB]); | ||
255 | |||
256 | usb_make_path(usbdev, dj_hiddev->phys, sizeof(dj_hiddev->phys)); | ||
257 | snprintf(tmpstr, sizeof(tmpstr), ":%d", dj_report->device_index); | ||
258 | strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys)); | ||
259 | |||
260 | dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL); | ||
261 | |||
262 | if (!dj_dev) { | ||
263 | dev_err(&djrcv_hdev->dev, "%s: failed allocating dj_device\n", | ||
264 | __func__); | ||
265 | goto dj_device_allocate_fail; | ||
266 | } | ||
267 | |||
268 | dj_dev->reports_supported = le32_to_cpu( | ||
269 | dj_report->report_params[DEVICE_PAIRED_RF_REPORT_TYPE]); | ||
270 | dj_dev->hdev = dj_hiddev; | ||
271 | dj_dev->dj_receiver_dev = djrcv_dev; | ||
272 | dj_dev->device_index = dj_report->device_index; | ||
273 | dj_hiddev->driver_data = dj_dev; | ||
274 | |||
275 | djrcv_dev->paired_dj_devices[dj_report->device_index] = dj_dev; | ||
276 | |||
277 | if (hid_add_device(dj_hiddev)) { | ||
278 | dev_err(&djrcv_hdev->dev, "%s: failed adding dj_device\n", | ||
279 | __func__); | ||
280 | goto hid_add_device_fail; | ||
281 | } | ||
282 | |||
283 | return; | ||
284 | |||
285 | hid_add_device_fail: | ||
286 | djrcv_dev->paired_dj_devices[dj_report->device_index] = NULL; | ||
287 | kfree(dj_dev); | ||
288 | dj_device_allocate_fail: | ||
289 | hid_destroy_device(dj_hiddev); | ||
290 | } | ||
291 | |||
292 | static void delayedwork_callback(struct work_struct *work) | ||
293 | { | ||
294 | struct dj_receiver_dev *djrcv_dev = | ||
295 | container_of(work, struct dj_receiver_dev, work); | ||
296 | |||
297 | struct dj_report dj_report; | ||
298 | unsigned long flags; | ||
299 | int count; | ||
300 | |||
301 | dbg_hid("%s\n", __func__); | ||
302 | |||
303 | spin_lock_irqsave(&djrcv_dev->lock, flags); | ||
304 | |||
305 | count = kfifo_out(&djrcv_dev->notif_fifo, &dj_report, | ||
306 | sizeof(struct dj_report)); | ||
307 | |||
308 | if (count != sizeof(struct dj_report)) { | ||
309 | dev_err(&djrcv_dev->hdev->dev, "%s: workitem triggered without " | ||
310 | "notifications available\n", __func__); | ||
311 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); | ||
312 | return; | ||
313 | } | ||
314 | |||
315 | if (!kfifo_is_empty(&djrcv_dev->notif_fifo)) { | ||
316 | if (schedule_work(&djrcv_dev->work) == 0) { | ||
317 | dbg_hid("%s: did not schedule the work item, was " | ||
318 | "already queued\n", __func__); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); | ||
323 | |||
324 | switch (dj_report.report_type) { | ||
325 | case REPORT_TYPE_NOTIF_DEVICE_PAIRED: | ||
326 | logi_dj_recv_add_djhid_device(djrcv_dev, &dj_report); | ||
327 | break; | ||
328 | case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED: | ||
329 | logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report); | ||
330 | break; | ||
331 | default: | ||
332 | dbg_hid("%s: unexpected report type\n", __func__); | ||
333 | } | ||
334 | } | ||
335 | |||
336 | static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev, | ||
337 | struct dj_report *dj_report) | ||
338 | { | ||
339 | /* We are called from atomic context (tasklet && djrcv->lock held) */ | ||
340 | |||
341 | kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report)); | ||
342 | |||
343 | if (schedule_work(&djrcv_dev->work) == 0) { | ||
344 | dbg_hid("%s: did not schedule the work item, was already " | ||
345 | "queued\n", __func__); | ||
346 | } | ||
347 | } | ||
348 | |||
349 | static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, | ||
350 | struct dj_report *dj_report) | ||
351 | { | ||
352 | /* We are called from atomic context (tasklet && djrcv->lock held) */ | ||
353 | unsigned int i; | ||
354 | u8 reportbuffer[MAX_REPORT_SIZE]; | ||
355 | struct dj_device *djdev; | ||
356 | |||
357 | djdev = djrcv_dev->paired_dj_devices[dj_report->device_index]; | ||
358 | |||
359 | if (!djdev) { | ||
360 | dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]" | ||
361 | " is NULL, index %d\n", dj_report->device_index); | ||
362 | return; | ||
363 | } | ||
364 | |||
365 | memset(reportbuffer, 0, sizeof(reportbuffer)); | ||
366 | |||
367 | for (i = 0; i < NUMBER_OF_HID_REPORTS; i++) { | ||
368 | if (djdev->reports_supported & (1 << i)) { | ||
369 | reportbuffer[0] = i; | ||
370 | if (hid_input_report(djdev->hdev, | ||
371 | HID_INPUT_REPORT, | ||
372 | reportbuffer, | ||
373 | hid_reportid_size_map[i], 1)) { | ||
374 | dbg_hid("hid_input_report error sending null " | ||
375 | "report\n"); | ||
376 | } | ||
377 | } | ||
378 | } | ||
379 | } | ||
380 | |||
381 | static void logi_dj_recv_forward_report(struct dj_receiver_dev *djrcv_dev, | ||
382 | struct dj_report *dj_report) | ||
383 | { | ||
384 | /* We are called from atomic context (tasklet && djrcv->lock held) */ | ||
385 | struct dj_device *dj_device; | ||
386 | |||
387 | dj_device = djrcv_dev->paired_dj_devices[dj_report->device_index]; | ||
388 | |||
389 | if (dj_device == NULL) { | ||
390 | dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]" | ||
391 | " is NULL, index %d\n", dj_report->device_index); | ||
392 | return; | ||
393 | } | ||
394 | |||
395 | if ((dj_report->report_type > ARRAY_SIZE(hid_reportid_size_map) - 1) || | ||
396 | (hid_reportid_size_map[dj_report->report_type] == 0)) { | ||
397 | dbg_hid("invalid report type:%x\n", dj_report->report_type); | ||
398 | return; | ||
399 | } | ||
400 | |||
401 | if (hid_input_report(dj_device->hdev, | ||
402 | HID_INPUT_REPORT, &dj_report->report_type, | ||
403 | hid_reportid_size_map[dj_report->report_type], 1)) { | ||
404 | dbg_hid("hid_input_report error\n"); | ||
405 | } | ||
406 | } | ||
407 | |||
408 | |||
409 | static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev, | ||
410 | struct dj_report *dj_report) | ||
411 | { | ||
412 | struct hid_device *hdev = djrcv_dev->hdev; | ||
413 | int sent_bytes; | ||
414 | |||
415 | if (!hdev->hid_output_raw_report) { | ||
416 | dev_err(&hdev->dev, "%s:" | ||
417 | "hid_output_raw_report is null\n", __func__); | ||
418 | return -ENODEV; | ||
419 | } | ||
420 | |||
421 | sent_bytes = hdev->hid_output_raw_report(hdev, (u8 *) dj_report, | ||
422 | sizeof(struct dj_report), | ||
423 | HID_OUTPUT_REPORT); | ||
424 | |||
425 | return (sent_bytes < 0) ? sent_bytes : 0; | ||
426 | } | ||
427 | |||
428 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev) | ||
429 | { | ||
430 | struct dj_report dj_report; | ||
431 | |||
432 | memset(&dj_report, 0, sizeof(dj_report)); | ||
433 | dj_report.report_id = REPORT_ID_DJ_SHORT; | ||
434 | dj_report.device_index = 0xFF; | ||
435 | dj_report.report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES; | ||
436 | return logi_dj_recv_send_report(djrcv_dev, &dj_report); | ||
437 | } | ||
438 | |||
439 | static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, | ||
440 | unsigned timeout) | ||
441 | { | ||
442 | struct dj_report dj_report; | ||
443 | |||
444 | memset(&dj_report, 0, sizeof(dj_report)); | ||
445 | dj_report.report_id = REPORT_ID_DJ_SHORT; | ||
446 | dj_report.device_index = 0xFF; | ||
447 | dj_report.report_type = REPORT_TYPE_CMD_SWITCH; | ||
448 | dj_report.report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x1F; | ||
449 | dj_report.report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] = (u8)timeout; | ||
450 | return logi_dj_recv_send_report(djrcv_dev, &dj_report); | ||
451 | } | ||
452 | |||
453 | |||
454 | static int logi_dj_ll_open(struct hid_device *hid) | ||
455 | { | ||
456 | dbg_hid("%s:%s\n", __func__, hid->phys); | ||
457 | return 0; | ||
458 | |||
459 | } | ||
460 | |||
461 | static void logi_dj_ll_close(struct hid_device *hid) | ||
462 | { | ||
463 | dbg_hid("%s:%s\n", __func__, hid->phys); | ||
464 | } | ||
465 | |||
466 | static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | ||
467 | size_t count, | ||
468 | unsigned char report_type) | ||
469 | { | ||
470 | /* Called by hid raw to send data */ | ||
471 | dbg_hid("%s\n", __func__); | ||
472 | |||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | static int logi_dj_ll_parse(struct hid_device *hid) | ||
477 | { | ||
478 | struct dj_device *djdev = hid->driver_data; | ||
479 | int retval; | ||
480 | |||
481 | dbg_hid("%s\n", __func__); | ||
482 | |||
483 | djdev->hdev->version = 0x0111; | ||
484 | djdev->hdev->country = 0x00; | ||
485 | |||
486 | if (djdev->reports_supported & STD_KEYBOARD) { | ||
487 | dbg_hid("%s: sending a kbd descriptor, reports_supported: %x\n", | ||
488 | __func__, djdev->reports_supported); | ||
489 | retval = hid_parse_report(hid, | ||
490 | (u8 *) kbd_descriptor, | ||
491 | sizeof(kbd_descriptor)); | ||
492 | if (retval) { | ||
493 | dbg_hid("%s: sending a kbd descriptor, hid_parse failed" | ||
494 | " error: %d\n", __func__, retval); | ||
495 | return retval; | ||
496 | } | ||
497 | } | ||
498 | |||
499 | if (djdev->reports_supported & STD_MOUSE) { | ||
500 | dbg_hid("%s: sending a mouse descriptor, reports_supported: " | ||
501 | "%x\n", __func__, djdev->reports_supported); | ||
502 | retval = hid_parse_report(hid, | ||
503 | (u8 *) mse_descriptor, | ||
504 | sizeof(mse_descriptor)); | ||
505 | if (retval) { | ||
506 | dbg_hid("%s: sending a mouse descriptor, hid_parse " | ||
507 | "failed error: %d\n", __func__, retval); | ||
508 | return retval; | ||
509 | } | ||
510 | } | ||
511 | |||
512 | if (djdev->reports_supported & MULTIMEDIA) { | ||
513 | dbg_hid("%s: sending a multimedia report descriptor: %x\n", | ||
514 | __func__, djdev->reports_supported); | ||
515 | retval = hid_parse_report(hid, | ||
516 | (u8 *) consumer_descriptor, | ||
517 | sizeof(consumer_descriptor)); | ||
518 | if (retval) { | ||
519 | dbg_hid("%s: sending a consumer_descriptor, hid_parse " | ||
520 | "failed error: %d\n", __func__, retval); | ||
521 | return retval; | ||
522 | } | ||
523 | } | ||
524 | |||
525 | if (djdev->reports_supported & POWER_KEYS) { | ||
526 | dbg_hid("%s: sending a power keys report descriptor: %x\n", | ||
527 | __func__, djdev->reports_supported); | ||
528 | retval = hid_parse_report(hid, | ||
529 | (u8 *) syscontrol_descriptor, | ||
530 | sizeof(syscontrol_descriptor)); | ||
531 | if (retval) { | ||
532 | dbg_hid("%s: sending a syscontrol_descriptor, " | ||
533 | "hid_parse failed error: %d\n", | ||
534 | __func__, retval); | ||
535 | return retval; | ||
536 | } | ||
537 | } | ||
538 | |||
539 | if (djdev->reports_supported & MEDIA_CENTER) { | ||
540 | dbg_hid("%s: sending a media center report descriptor: %x\n", | ||
541 | __func__, djdev->reports_supported); | ||
542 | retval = hid_parse_report(hid, | ||
543 | (u8 *) media_descriptor, | ||
544 | sizeof(media_descriptor)); | ||
545 | if (retval) { | ||
546 | dbg_hid("%s: sending a media_descriptor, hid_parse " | ||
547 | "failed error: %d\n", __func__, retval); | ||
548 | return retval; | ||
549 | } | ||
550 | } | ||
551 | |||
552 | if (djdev->reports_supported & KBD_LEDS) { | ||
553 | dbg_hid("%s: need to send kbd leds report descriptor: %x\n", | ||
554 | __func__, djdev->reports_supported); | ||
555 | } | ||
556 | |||
557 | return 0; | ||
558 | } | ||
559 | |||
560 | static int logi_dj_ll_input_event(struct input_dev *dev, unsigned int type, | ||
561 | unsigned int code, int value) | ||
562 | { | ||
563 | /* Sent by the input layer to handle leds and Force Feedback */ | ||
564 | struct hid_device *dj_hiddev = input_get_drvdata(dev); | ||
565 | struct dj_device *dj_dev = dj_hiddev->driver_data; | ||
566 | |||
567 | struct dj_receiver_dev *djrcv_dev = | ||
568 | dev_get_drvdata(dj_hiddev->dev.parent); | ||
569 | struct hid_device *dj_rcv_hiddev = djrcv_dev->hdev; | ||
570 | struct hid_report_enum *output_report_enum; | ||
571 | |||
572 | struct hid_field *field; | ||
573 | struct hid_report *report; | ||
574 | unsigned char data[8]; | ||
575 | int offset; | ||
576 | |||
577 | dbg_hid("%s: %s, type:%d | code:%d | value:%d\n", | ||
578 | __func__, dev->phys, type, code, value); | ||
579 | |||
580 | if (type != EV_LED) | ||
581 | return -1; | ||
582 | |||
583 | offset = hidinput_find_field(dj_hiddev, type, code, &field); | ||
584 | |||
585 | if (offset == -1) { | ||
586 | dev_warn(&dev->dev, "event field not found\n"); | ||
587 | return -1; | ||
588 | } | ||
589 | hid_set_field(field, offset, value); | ||
590 | hid_output_report(field->report, &data[0]); | ||
591 | |||
592 | output_report_enum = &dj_rcv_hiddev->report_enum[HID_OUTPUT_REPORT]; | ||
593 | report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT]; | ||
594 | hid_set_field(report->field[0], 0, dj_dev->device_index); | ||
595 | hid_set_field(report->field[0], 1, REPORT_TYPE_LEDS); | ||
596 | hid_set_field(report->field[0], 2, data[1]); | ||
597 | |||
598 | usbhid_submit_report(dj_rcv_hiddev, report, USB_DIR_OUT); | ||
599 | |||
600 | return 0; | ||
601 | |||
602 | } | ||
603 | |||
604 | static int logi_dj_ll_start(struct hid_device *hid) | ||
605 | { | ||
606 | dbg_hid("%s\n", __func__); | ||
607 | return 0; | ||
608 | } | ||
609 | |||
610 | static void logi_dj_ll_stop(struct hid_device *hid) | ||
611 | { | ||
612 | dbg_hid("%s\n", __func__); | ||
613 | } | ||
614 | |||
615 | |||
616 | static struct hid_ll_driver logi_dj_ll_driver = { | ||
617 | .parse = logi_dj_ll_parse, | ||
618 | .start = logi_dj_ll_start, | ||
619 | .stop = logi_dj_ll_stop, | ||
620 | .open = logi_dj_ll_open, | ||
621 | .close = logi_dj_ll_close, | ||
622 | .hidinput_input_event = logi_dj_ll_input_event, | ||
623 | }; | ||
624 | |||
625 | |||
626 | static int logi_dj_raw_event(struct hid_device *hdev, | ||
627 | struct hid_report *report, u8 *data, | ||
628 | int size) | ||
629 | { | ||
630 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); | ||
631 | struct dj_report *dj_report = (struct dj_report *) data; | ||
632 | unsigned long flags; | ||
633 | bool report_processed = false; | ||
634 | |||
635 | dbg_hid("%s, size:%d\n", __func__, size); | ||
636 | |||
637 | /* Here we receive all data coming from iface 2, there are 4 cases: | ||
638 | * | ||
639 | * 1) Data should continue its normal processing i.e. data does not | ||
640 | * come from the DJ collection, in which case we do nothing and | ||
641 | * return 0, so hid-core can continue normal processing (will forward | ||
642 | * to associated hidraw device) | ||
643 | * | ||
644 | * 2) Data is from DJ collection, and is intended for this driver i. e. | ||
645 | * data contains arrival, departure, etc notifications, in which case | ||
646 | * we queue them for delayed processing by the work queue. We return 1 | ||
647 | * to hid-core as no further processing is required from it. | ||
648 | * | ||
649 | * 3) Data is from DJ collection, and informs a connection change, | ||
650 | * if the change means rf link loss, then we must send a null report | ||
651 | * to the upper layer to discard potentially pressed keys that may be | ||
652 | * repeated forever by the input layer. Return 1 to hid-core as no | ||
653 | * further processing is required. | ||
654 | * | ||
655 | * 4) Data is from DJ collection and is an actual input event from | ||
656 | * a paired DJ device in which case we forward it to the correct hid | ||
657 | * device (via hid_input_report() ) and return 1 so hid-core does not do | ||
658 | * anything else with it. | ||
659 | */ | ||
660 | |||
661 | spin_lock_irqsave(&djrcv_dev->lock, flags); | ||
662 | if (dj_report->report_id == REPORT_ID_DJ_SHORT) { | ||
663 | switch (dj_report->report_type) { | ||
664 | case REPORT_TYPE_NOTIF_DEVICE_PAIRED: | ||
665 | case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED: | ||
666 | logi_dj_recv_queue_notification(djrcv_dev, dj_report); | ||
667 | break; | ||
668 | case REPORT_TYPE_NOTIF_CONNECTION_STATUS: | ||
669 | if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] == | ||
670 | STATUS_LINKLOSS) { | ||
671 | logi_dj_recv_forward_null_report(djrcv_dev, dj_report); | ||
672 | } | ||
673 | break; | ||
674 | default: | ||
675 | logi_dj_recv_forward_report(djrcv_dev, dj_report); | ||
676 | } | ||
677 | report_processed = true; | ||
678 | } | ||
679 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); | ||
680 | |||
681 | return report_processed; | ||
682 | } | ||
683 | |||
684 | static int logi_dj_probe(struct hid_device *hdev, | ||
685 | const struct hid_device_id *id) | ||
686 | { | ||
687 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | ||
688 | struct dj_receiver_dev *djrcv_dev; | ||
689 | int retval; | ||
690 | |||
691 | if (is_dj_device((struct dj_device *)hdev->driver_data)) | ||
692 | return -ENODEV; | ||
693 | |||
694 | dbg_hid("%s called for ifnum %d\n", __func__, | ||
695 | intf->cur_altsetting->desc.bInterfaceNumber); | ||
696 | |||
697 | /* Ignore interfaces 0 and 1, they will not carry any data, dont create | ||
698 | * any hid_device for them */ | ||
699 | if (intf->cur_altsetting->desc.bInterfaceNumber != | ||
700 | LOGITECH_DJ_INTERFACE_NUMBER) { | ||
701 | dbg_hid("%s: ignoring ifnum %d\n", __func__, | ||
702 | intf->cur_altsetting->desc.bInterfaceNumber); | ||
703 | return -ENODEV; | ||
704 | } | ||
705 | |||
706 | /* Treat interface 2 */ | ||
707 | |||
708 | djrcv_dev = kzalloc(sizeof(struct dj_receiver_dev), GFP_KERNEL); | ||
709 | if (!djrcv_dev) { | ||
710 | dev_err(&hdev->dev, | ||
711 | "%s:failed allocating dj_receiver_dev\n", __func__); | ||
712 | return -ENOMEM; | ||
713 | } | ||
714 | djrcv_dev->hdev = hdev; | ||
715 | INIT_WORK(&djrcv_dev->work, delayedwork_callback); | ||
716 | spin_lock_init(&djrcv_dev->lock); | ||
717 | if (kfifo_alloc(&djrcv_dev->notif_fifo, | ||
718 | DJ_MAX_NUMBER_NOTIFICATIONS * sizeof(struct dj_report), | ||
719 | GFP_KERNEL)) { | ||
720 | dev_err(&hdev->dev, | ||
721 | "%s:failed allocating notif_fifo\n", __func__); | ||
722 | kfree(djrcv_dev); | ||
723 | return -ENOMEM; | ||
724 | } | ||
725 | hid_set_drvdata(hdev, djrcv_dev); | ||
726 | |||
727 | /* Call to usbhid to fetch the HID descriptors of interface 2 and | ||
728 | * subsequently call to the hid/hid-core to parse the fetched | ||
729 | * descriptors, this will in turn create the hidraw and hiddev nodes | ||
730 | * for interface 2 of the receiver */ | ||
731 | retval = hid_parse(hdev); | ||
732 | if (retval) { | ||
733 | dev_err(&hdev->dev, | ||
734 | "%s:parse of interface 2 failed\n", __func__); | ||
735 | goto hid_parse_fail; | ||
736 | } | ||
737 | |||
738 | /* Starts the usb device and connects to upper interfaces hiddev and | ||
739 | * hidraw */ | ||
740 | retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
741 | if (retval) { | ||
742 | dev_err(&hdev->dev, | ||
743 | "%s:hid_hw_start returned error\n", __func__); | ||
744 | goto hid_hw_start_fail; | ||
745 | } | ||
746 | |||
747 | retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); | ||
748 | if (retval < 0) { | ||
749 | dev_err(&hdev->dev, | ||
750 | "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n", | ||
751 | __func__, retval); | ||
752 | goto switch_to_dj_mode_fail; | ||
753 | } | ||
754 | |||
755 | /* This is enabling the polling urb on the IN endpoint */ | ||
756 | retval = hdev->ll_driver->open(hdev); | ||
757 | if (retval < 0) { | ||
758 | dev_err(&hdev->dev, "%s:hdev->ll_driver->open returned " | ||
759 | "error:%d\n", __func__, retval); | ||
760 | goto llopen_failed; | ||
761 | } | ||
762 | |||
763 | retval = logi_dj_recv_query_paired_devices(djrcv_dev); | ||
764 | if (retval < 0) { | ||
765 | dev_err(&hdev->dev, "%s:logi_dj_recv_query_paired_devices " | ||
766 | "error:%d\n", __func__, retval); | ||
767 | goto logi_dj_recv_query_paired_devices_failed; | ||
768 | } | ||
769 | |||
770 | return retval; | ||
771 | |||
772 | logi_dj_recv_query_paired_devices_failed: | ||
773 | hdev->ll_driver->close(hdev); | ||
774 | |||
775 | llopen_failed: | ||
776 | switch_to_dj_mode_fail: | ||
777 | hid_hw_stop(hdev); | ||
778 | |||
779 | hid_hw_start_fail: | ||
780 | hid_parse_fail: | ||
781 | kfifo_free(&djrcv_dev->notif_fifo); | ||
782 | kfree(djrcv_dev); | ||
783 | hid_set_drvdata(hdev, NULL); | ||
784 | return retval; | ||
785 | |||
786 | } | ||
787 | |||
788 | #ifdef CONFIG_PM | ||
789 | static int logi_dj_reset_resume(struct hid_device *hdev) | ||
790 | { | ||
791 | int retval; | ||
792 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); | ||
793 | |||
794 | retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); | ||
795 | if (retval < 0) { | ||
796 | dev_err(&hdev->dev, | ||
797 | "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n", | ||
798 | __func__, retval); | ||
799 | } | ||
800 | |||
801 | return 0; | ||
802 | } | ||
803 | #endif | ||
804 | |||
805 | static void logi_dj_remove(struct hid_device *hdev) | ||
806 | { | ||
807 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); | ||
808 | struct dj_device *dj_dev; | ||
809 | int i; | ||
810 | |||
811 | dbg_hid("%s\n", __func__); | ||
812 | |||
813 | cancel_work_sync(&djrcv_dev->work); | ||
814 | |||
815 | hdev->ll_driver->close(hdev); | ||
816 | hid_hw_stop(hdev); | ||
817 | |||
818 | /* I suppose that at this point the only context that can access | ||
819 | * the djrecv_data is this thread as the work item is guaranteed to | ||
820 | * have finished and no more raw_event callbacks should arrive after | ||
821 | * the remove callback was triggered so no locks are put around the | ||
822 | * code below */ | ||
823 | for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) { | ||
824 | dj_dev = djrcv_dev->paired_dj_devices[i]; | ||
825 | if (dj_dev != NULL) { | ||
826 | hid_destroy_device(dj_dev->hdev); | ||
827 | kfree(dj_dev); | ||
828 | djrcv_dev->paired_dj_devices[i] = NULL; | ||
829 | } | ||
830 | } | ||
831 | |||
832 | kfifo_free(&djrcv_dev->notif_fifo); | ||
833 | kfree(djrcv_dev); | ||
834 | hid_set_drvdata(hdev, NULL); | ||
835 | } | ||
836 | |||
837 | static int logi_djdevice_probe(struct hid_device *hdev, | ||
838 | const struct hid_device_id *id) | ||
839 | { | ||
840 | int ret; | ||
841 | struct dj_device *dj_dev = hdev->driver_data; | ||
842 | |||
843 | if (!is_dj_device(dj_dev)) | ||
844 | return -ENODEV; | ||
845 | |||
846 | ret = hid_parse(hdev); | ||
847 | if (!ret) | ||
848 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
849 | |||
850 | return ret; | ||
851 | } | ||
852 | |||
853 | static const struct hid_device_id logi_dj_receivers[] = { | ||
854 | {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, | ||
855 | USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER)}, | ||
856 | {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, | ||
857 | USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2)}, | ||
858 | {} | ||
859 | }; | ||
860 | |||
861 | MODULE_DEVICE_TABLE(hid, logi_dj_receivers); | ||
862 | |||
863 | static struct hid_driver logi_djreceiver_driver = { | ||
864 | .name = "logitech-djreceiver", | ||
865 | .id_table = logi_dj_receivers, | ||
866 | .probe = logi_dj_probe, | ||
867 | .remove = logi_dj_remove, | ||
868 | .raw_event = logi_dj_raw_event, | ||
869 | #ifdef CONFIG_PM | ||
870 | .reset_resume = logi_dj_reset_resume, | ||
871 | #endif | ||
872 | }; | ||
873 | |||
874 | |||
875 | static const struct hid_device_id logi_dj_devices[] = { | ||
876 | {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, | ||
877 | USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER)}, | ||
878 | {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, | ||
879 | USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2)}, | ||
880 | {} | ||
881 | }; | ||
882 | |||
883 | static struct hid_driver logi_djdevice_driver = { | ||
884 | .name = "logitech-djdevice", | ||
885 | .id_table = logi_dj_devices, | ||
886 | .probe = logi_djdevice_probe, | ||
887 | }; | ||
888 | |||
889 | |||
890 | static int __init logi_dj_init(void) | ||
891 | { | ||
892 | int retval; | ||
893 | |||
894 | dbg_hid("Logitech-DJ:%s\n", __func__); | ||
895 | |||
896 | retval = hid_register_driver(&logi_djreceiver_driver); | ||
897 | if (retval) | ||
898 | return retval; | ||
899 | |||
900 | retval = hid_register_driver(&logi_djdevice_driver); | ||
901 | if (retval) | ||
902 | hid_unregister_driver(&logi_djreceiver_driver); | ||
903 | |||
904 | return retval; | ||
905 | |||
906 | } | ||
907 | |||
908 | static void __exit logi_dj_exit(void) | ||
909 | { | ||
910 | dbg_hid("Logitech-DJ:%s\n", __func__); | ||
911 | |||
912 | hid_unregister_driver(&logi_djdevice_driver); | ||
913 | hid_unregister_driver(&logi_djreceiver_driver); | ||
914 | |||
915 | } | ||
916 | |||
917 | module_init(logi_dj_init); | ||
918 | module_exit(logi_dj_exit); | ||
919 | MODULE_LICENSE("GPL"); | ||
920 | MODULE_AUTHOR("Logitech"); | ||
921 | MODULE_AUTHOR("Nestor Lopez Casado"); | ||
922 | MODULE_AUTHOR("nlopezcasad@logitech.com"); | ||
diff --git a/drivers/hid/hid-logitech-dj.h b/drivers/hid/hid-logitech-dj.h new file mode 100644 index 000000000000..fd28a5e0ca3b --- /dev/null +++ b/drivers/hid/hid-logitech-dj.h | |||
@@ -0,0 +1,123 @@ | |||
1 | #ifndef __HID_LOGITECH_DJ_H | ||
2 | #define __HID_LOGITECH_DJ_H | ||
3 | |||
4 | /* | ||
5 | * HID driver for Logitech Unifying receivers | ||
6 | * | ||
7 | * Copyright (c) 2011 Logitech | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/kfifo.h> | ||
27 | |||
28 | #define DJ_MAX_PAIRED_DEVICES 6 | ||
29 | #define DJ_MAX_NUMBER_NOTIFICATIONS 8 | ||
30 | #define DJ_DEVICE_INDEX_MIN 1 | ||
31 | #define DJ_DEVICE_INDEX_MAX 6 | ||
32 | |||
33 | #define DJREPORT_SHORT_LENGTH 15 | ||
34 | #define DJREPORT_LONG_LENGTH 32 | ||
35 | |||
36 | #define REPORT_ID_DJ_SHORT 0x20 | ||
37 | #define REPORT_ID_DJ_LONG 0x21 | ||
38 | |||
39 | #define REPORT_TYPE_RFREPORT_FIRST 0x01 | ||
40 | #define REPORT_TYPE_RFREPORT_LAST 0x1F | ||
41 | |||
42 | /* Command Switch to DJ mode */ | ||
43 | #define REPORT_TYPE_CMD_SWITCH 0x80 | ||
44 | #define CMD_SWITCH_PARAM_DEVBITFIELD 0x00 | ||
45 | #define CMD_SWITCH_PARAM_TIMEOUT_SECONDS 0x01 | ||
46 | #define TIMEOUT_NO_KEEPALIVE 0x00 | ||
47 | |||
48 | /* Command to Get the list of Paired devices */ | ||
49 | #define REPORT_TYPE_CMD_GET_PAIRED_DEVICES 0x81 | ||
50 | |||
51 | /* Device Paired Notification */ | ||
52 | #define REPORT_TYPE_NOTIF_DEVICE_PAIRED 0x41 | ||
53 | #define SPFUNCTION_MORE_NOTIF_EXPECTED 0x01 | ||
54 | #define SPFUNCTION_DEVICE_LIST_EMPTY 0x02 | ||
55 | #define DEVICE_PAIRED_PARAM_SPFUNCTION 0x00 | ||
56 | #define DEVICE_PAIRED_PARAM_EQUAD_ID_LSB 0x01 | ||
57 | #define DEVICE_PAIRED_PARAM_EQUAD_ID_MSB 0x02 | ||
58 | #define DEVICE_PAIRED_RF_REPORT_TYPE 0x03 | ||
59 | |||
60 | /* Device Un-Paired Notification */ | ||
61 | #define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x40 | ||
62 | |||
63 | |||
64 | /* Connection Status Notification */ | ||
65 | #define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42 | ||
66 | #define CONNECTION_STATUS_PARAM_STATUS 0x00 | ||
67 | #define STATUS_LINKLOSS 0x01 | ||
68 | |||
69 | /* Error Notification */ | ||
70 | #define REPORT_TYPE_NOTIF_ERROR 0x7F | ||
71 | #define NOTIF_ERROR_PARAM_ETYPE 0x00 | ||
72 | #define ETYPE_KEEPALIVE_TIMEOUT 0x01 | ||
73 | |||
74 | /* supported DJ HID && RF report types */ | ||
75 | #define REPORT_TYPE_KEYBOARD 0x01 | ||
76 | #define REPORT_TYPE_MOUSE 0x02 | ||
77 | #define REPORT_TYPE_CONSUMER_CONTROL 0x03 | ||
78 | #define REPORT_TYPE_SYSTEM_CONTROL 0x04 | ||
79 | #define REPORT_TYPE_MEDIA_CENTER 0x08 | ||
80 | #define REPORT_TYPE_LEDS 0x0E | ||
81 | |||
82 | /* RF Report types bitfield */ | ||
83 | #define STD_KEYBOARD 0x00000002 | ||
84 | #define STD_MOUSE 0x00000004 | ||
85 | #define MULTIMEDIA 0x00000008 | ||
86 | #define POWER_KEYS 0x00000010 | ||
87 | #define MEDIA_CENTER 0x00000100 | ||
88 | #define KBD_LEDS 0x00004000 | ||
89 | |||
90 | struct dj_report { | ||
91 | u8 report_id; | ||
92 | u8 device_index; | ||
93 | u8 report_type; | ||
94 | u8 report_params[DJREPORT_SHORT_LENGTH - 3]; | ||
95 | }; | ||
96 | |||
97 | struct dj_receiver_dev { | ||
98 | struct hid_device *hdev; | ||
99 | struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES + | ||
100 | DJ_DEVICE_INDEX_MIN]; | ||
101 | struct work_struct work; | ||
102 | struct kfifo notif_fifo; | ||
103 | spinlock_t lock; | ||
104 | }; | ||
105 | |||
106 | struct dj_device { | ||
107 | struct hid_device *hdev; | ||
108 | struct dj_receiver_dev *dj_receiver_dev; | ||
109 | u32 reports_supported; | ||
110 | u8 device_index; | ||
111 | }; | ||
112 | |||
113 | /** | ||
114 | * is_dj_device - know if the given dj_device is not the receiver. | ||
115 | * @dj_dev: the dj device to test | ||
116 | * | ||
117 | * This macro tests if a struct dj_device pointer is a device created | ||
118 | * by the bus enumarator. | ||
119 | */ | ||
120 | #define is_dj_device(dj_dev) \ | ||
121 | (&(dj_dev)->dj_receiver_dev->hdev->dev == (dj_dev)->hdev->dev.parent) | ||
122 | |||
123 | #endif | ||
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 58d0e7aaf088..fa5d7a1ffa9e 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
@@ -47,10 +47,11 @@ MODULE_LICENSE("GPL"); | |||
47 | #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1) | 47 | #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1) |
48 | #define MT_QUIRK_CYPRESS (1 << 2) | 48 | #define MT_QUIRK_CYPRESS (1 << 2) |
49 | #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3) | 49 | #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3) |
50 | #define MT_QUIRK_VALID_IS_INRANGE (1 << 4) | 50 | #define MT_QUIRK_ALWAYS_VALID (1 << 4) |
51 | #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 5) | 51 | #define MT_QUIRK_VALID_IS_INRANGE (1 << 5) |
52 | #define MT_QUIRK_EGALAX_XYZ_FIXUP (1 << 6) | 52 | #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6) |
53 | #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 7) | 53 | #define MT_QUIRK_EGALAX_XYZ_FIXUP (1 << 7) |
54 | #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8) | ||
54 | 55 | ||
55 | struct mt_slot { | 56 | struct mt_slot { |
56 | __s32 x, y, p, w, h; | 57 | __s32 x, y, p, w, h; |
@@ -86,11 +87,12 @@ struct mt_class { | |||
86 | /* classes of device behavior */ | 87 | /* classes of device behavior */ |
87 | #define MT_CLS_DEFAULT 0x0001 | 88 | #define MT_CLS_DEFAULT 0x0001 |
88 | 89 | ||
89 | #define MT_CLS_CONFIDENCE 0x0002 | 90 | #define MT_CLS_SERIAL 0x0002 |
90 | #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0003 | 91 | #define MT_CLS_CONFIDENCE 0x0003 |
91 | #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0004 | 92 | #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0004 |
92 | #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0005 | 93 | #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0005 |
93 | #define MT_CLS_DUAL_NSMU_CONTACTID 0x0006 | 94 | #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0006 |
95 | #define MT_CLS_DUAL_NSMU_CONTACTID 0x0007 | ||
94 | 96 | ||
95 | /* vendor specific classes */ | 97 | /* vendor specific classes */ |
96 | #define MT_CLS_3M 0x0101 | 98 | #define MT_CLS_3M 0x0101 |
@@ -134,6 +136,8 @@ static int find_slot_from_contactid(struct mt_device *td) | |||
134 | struct mt_class mt_classes[] = { | 136 | struct mt_class mt_classes[] = { |
135 | { .name = MT_CLS_DEFAULT, | 137 | { .name = MT_CLS_DEFAULT, |
136 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, | 138 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, |
139 | { .name = MT_CLS_SERIAL, | ||
140 | .quirks = MT_QUIRK_ALWAYS_VALID}, | ||
137 | { .name = MT_CLS_CONFIDENCE, | 141 | { .name = MT_CLS_CONFIDENCE, |
138 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE }, | 142 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE }, |
139 | { .name = MT_CLS_CONFIDENCE_MINUS_ONE, | 143 | { .name = MT_CLS_CONFIDENCE_MINUS_ONE, |
@@ -213,6 +217,16 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
213 | struct mt_class *cls = td->mtclass; | 217 | struct mt_class *cls = td->mtclass; |
214 | __s32 quirks = cls->quirks; | 218 | __s32 quirks = cls->quirks; |
215 | 219 | ||
220 | /* Only map fields from TouchScreen or TouchPad collections. | ||
221 | * We need to ignore fields that belong to other collections | ||
222 | * such as Mouse that might have the same GenericDesktop usages. */ | ||
223 | if (field->application == HID_DG_TOUCHSCREEN) | ||
224 | set_bit(INPUT_PROP_DIRECT, hi->input->propbit); | ||
225 | else if (field->application == HID_DG_TOUCHPAD) | ||
226 | set_bit(INPUT_PROP_POINTER, hi->input->propbit); | ||
227 | else | ||
228 | return 0; | ||
229 | |||
216 | switch (usage->hid & HID_USAGE_PAGE) { | 230 | switch (usage->hid & HID_USAGE_PAGE) { |
217 | 231 | ||
218 | case HID_UP_GENDESK: | 232 | case HID_UP_GENDESK: |
@@ -277,6 +291,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
277 | td->last_slot_field = usage->hid; | 291 | td->last_slot_field = usage->hid; |
278 | td->last_field_index = field->index; | 292 | td->last_field_index = field->index; |
279 | td->last_mt_collection = usage->collection_index; | 293 | td->last_mt_collection = usage->collection_index; |
294 | hdev->quirks &= ~HID_QUIRK_MULTITOUCH; | ||
280 | return 1; | 295 | return 1; |
281 | case HID_DG_WIDTH: | 296 | case HID_DG_WIDTH: |
282 | hid_map_usage(hi, usage, bit, max, | 297 | hid_map_usage(hi, usage, bit, max, |
@@ -435,7 +450,9 @@ static int mt_event(struct hid_device *hid, struct hid_field *field, | |||
435 | if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { | 450 | if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { |
436 | switch (usage->hid) { | 451 | switch (usage->hid) { |
437 | case HID_DG_INRANGE: | 452 | case HID_DG_INRANGE: |
438 | if (quirks & MT_QUIRK_VALID_IS_INRANGE) | 453 | if (quirks & MT_QUIRK_ALWAYS_VALID) |
454 | td->curvalid = true; | ||
455 | else if (quirks & MT_QUIRK_VALID_IS_INRANGE) | ||
439 | td->curvalid = value; | 456 | td->curvalid = value; |
440 | break; | 457 | break; |
441 | case HID_DG_TIPSWITCH: | 458 | case HID_DG_TIPSWITCH: |
@@ -513,12 +530,44 @@ static void mt_set_input_mode(struct hid_device *hdev) | |||
513 | } | 530 | } |
514 | } | 531 | } |
515 | 532 | ||
533 | /* a list of devices for which there is a specialized multitouch driver */ | ||
534 | static const struct hid_device_id mt_have_special_driver[] = { | ||
535 | { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, 0x0001) }, | ||
536 | { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, 0x0006) }, | ||
537 | { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, | ||
538 | USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) }, | ||
539 | { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, | ||
540 | USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, | ||
541 | { } | ||
542 | }; | ||
543 | |||
544 | static bool mt_match_one_id(struct hid_device *hdev, | ||
545 | const struct hid_device_id *id) | ||
546 | { | ||
547 | return id->bus == hdev->bus && | ||
548 | (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && | ||
549 | (id->product == HID_ANY_ID || id->product == hdev->product); | ||
550 | } | ||
551 | |||
552 | static const struct hid_device_id *mt_match_id(struct hid_device *hdev, | ||
553 | const struct hid_device_id *id) | ||
554 | { | ||
555 | for (; id->bus; id++) | ||
556 | if (mt_match_one_id(hdev, id)) | ||
557 | return id; | ||
558 | |||
559 | return NULL; | ||
560 | } | ||
561 | |||
516 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | 562 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
517 | { | 563 | { |
518 | int ret, i; | 564 | int ret, i; |
519 | struct mt_device *td; | 565 | struct mt_device *td; |
520 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ | 566 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
521 | 567 | ||
568 | if (mt_match_id(hdev, mt_have_special_driver)) | ||
569 | return -ENODEV; | ||
570 | |||
522 | for (i = 0; mt_classes[i].name ; i++) { | 571 | for (i = 0; mt_classes[i].name ; i++) { |
523 | if (id->driver_data == mt_classes[i].name) { | 572 | if (id->driver_data == mt_classes[i].name) { |
524 | mtclass = &(mt_classes[i]); | 573 | mtclass = &(mt_classes[i]); |
@@ -526,10 +575,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
526 | } | 575 | } |
527 | } | 576 | } |
528 | 577 | ||
529 | /* This allows the driver to correctly support devices | ||
530 | * that emit events over several HID messages. | ||
531 | */ | ||
532 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; | ||
533 | 578 | ||
534 | td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); | 579 | td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); |
535 | if (!td) { | 580 | if (!td) { |
@@ -545,10 +590,16 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
545 | if (ret != 0) | 590 | if (ret != 0) |
546 | goto fail; | 591 | goto fail; |
547 | 592 | ||
593 | hdev->quirks |= HID_QUIRK_MULTITOUCH; | ||
548 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | 594 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
549 | if (ret) | 595 | if (ret) |
550 | goto fail; | 596 | goto fail; |
551 | 597 | ||
598 | /* This allows the driver to correctly support devices | ||
599 | * that emit events over several HID messages. | ||
600 | */ | ||
601 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; | ||
602 | |||
552 | td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot), | 603 | td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot), |
553 | GFP_KERNEL); | 604 | GFP_KERNEL); |
554 | if (!td->slots) { | 605 | if (!td->slots) { |
@@ -662,6 +713,11 @@ static const struct hid_device_id mt_devices[] = { | |||
662 | HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, | 713 | HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, |
663 | USB_DEVICE_ID_GOODTOUCH_000f) }, | 714 | USB_DEVICE_ID_GOODTOUCH_000f) }, |
664 | 715 | ||
716 | /* Ideacom panel */ | ||
717 | { .driver_data = MT_CLS_SERIAL, | ||
718 | HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, | ||
719 | USB_DEVICE_ID_IDEACOM_IDC6650) }, | ||
720 | |||
665 | /* Ilitek dual touch panel */ | 721 | /* Ilitek dual touch panel */ |
666 | { .driver_data = MT_CLS_DEFAULT, | 722 | { .driver_data = MT_CLS_DEFAULT, |
667 | HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, | 723 | HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, |
@@ -672,6 +728,11 @@ static const struct hid_device_id mt_devices[] = { | |||
672 | HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, | 728 | HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, |
673 | USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, | 729 | USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, |
674 | 730 | ||
731 | /* LG Display panels */ | ||
732 | { .driver_data = MT_CLS_DEFAULT, | ||
733 | HID_USB_DEVICE(USB_VENDOR_ID_LG, | ||
734 | USB_DEVICE_ID_LG_MULTITOUCH) }, | ||
735 | |||
675 | /* Lumio panels */ | 736 | /* Lumio panels */ |
676 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | 737 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
677 | HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, | 738 | HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, |
@@ -732,6 +793,10 @@ static const struct hid_device_id mt_devices[] = { | |||
732 | HID_USB_DEVICE(USB_VENDOR_ID_XAT, | 793 | HID_USB_DEVICE(USB_VENDOR_ID_XAT, |
733 | USB_DEVICE_ID_XAT_CSR) }, | 794 | USB_DEVICE_ID_XAT_CSR) }, |
734 | 795 | ||
796 | /* Rest of the world */ | ||
797 | { .driver_data = MT_CLS_DEFAULT, | ||
798 | HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) }, | ||
799 | |||
735 | { } | 800 | { } |
736 | }; | 801 | }; |
737 | MODULE_DEVICE_TABLE(hid, mt_devices); | 802 | MODULE_DEVICE_TABLE(hid, mt_devices); |
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index 2b8f3a31ffb3..e2072afb34bb 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c | |||
@@ -37,6 +37,21 @@ | |||
37 | 37 | ||
38 | static uint profile_numbers[5] = {0, 1, 2, 3, 4}; | 38 | static uint profile_numbers[5] = {0, 1, 2, 3, 4}; |
39 | 39 | ||
40 | static void kone_profile_activated(struct kone_device *kone, uint new_profile) | ||
41 | { | ||
42 | kone->actual_profile = new_profile; | ||
43 | kone->actual_dpi = kone->profiles[new_profile - 1].startup_dpi; | ||
44 | } | ||
45 | |||
46 | static void kone_profile_report(struct kone_device *kone, uint new_profile) | ||
47 | { | ||
48 | struct kone_roccat_report roccat_report; | ||
49 | roccat_report.event = kone_mouse_event_switch_profile; | ||
50 | roccat_report.value = new_profile; | ||
51 | roccat_report.key = 0; | ||
52 | roccat_report_event(kone->chrdev_minor, (uint8_t *)&roccat_report); | ||
53 | } | ||
54 | |||
40 | static int kone_receive(struct usb_device *usb_dev, uint usb_command, | 55 | static int kone_receive(struct usb_device *usb_dev, uint usb_command, |
41 | void *data, uint size) | 56 | void *data, uint size) |
42 | { | 57 | { |
@@ -283,7 +298,7 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, | |||
283 | container_of(kobj, struct device, kobj)->parent->parent; | 298 | container_of(kobj, struct device, kobj)->parent->parent; |
284 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); | 299 | struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); |
285 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 300 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
286 | int retval = 0, difference; | 301 | int retval = 0, difference, old_profile; |
287 | 302 | ||
288 | /* I need to get my data in one piece */ | 303 | /* I need to get my data in one piece */ |
289 | if (off != 0 || count != sizeof(struct kone_settings)) | 304 | if (off != 0 || count != sizeof(struct kone_settings)) |
@@ -294,21 +309,20 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, | |||
294 | if (difference) { | 309 | if (difference) { |
295 | retval = kone_set_settings(usb_dev, | 310 | retval = kone_set_settings(usb_dev, |
296 | (struct kone_settings const *)buf); | 311 | (struct kone_settings const *)buf); |
297 | if (!retval) | 312 | if (retval) { |
298 | memcpy(&kone->settings, buf, | 313 | mutex_unlock(&kone->kone_lock); |
299 | sizeof(struct kone_settings)); | 314 | return retval; |
300 | } | 315 | } |
301 | mutex_unlock(&kone->kone_lock); | ||
302 | 316 | ||
303 | if (retval) | 317 | old_profile = kone->settings.startup_profile; |
304 | return retval; | 318 | memcpy(&kone->settings, buf, sizeof(struct kone_settings)); |
305 | 319 | ||
306 | /* | 320 | kone_profile_activated(kone, kone->settings.startup_profile); |
307 | * If we get here, treat settings as okay and update actual values | 321 | |
308 | * according to startup_profile | 322 | if (kone->settings.startup_profile != old_profile) |
309 | */ | 323 | kone_profile_report(kone, kone->settings.startup_profile); |
310 | kone->actual_profile = kone->settings.startup_profile; | 324 | } |
311 | kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi; | 325 | mutex_unlock(&kone->kone_lock); |
312 | 326 | ||
313 | return sizeof(struct kone_settings); | 327 | return sizeof(struct kone_settings); |
314 | } | 328 | } |
@@ -501,6 +515,8 @@ static ssize_t kone_sysfs_set_tcu(struct device *dev, | |||
501 | goto exit_no_settings; | 515 | goto exit_no_settings; |
502 | goto exit_unlock; | 516 | goto exit_unlock; |
503 | } | 517 | } |
518 | /* calibration resets profile */ | ||
519 | kone_profile_activated(kone, kone->settings.startup_profile); | ||
504 | } | 520 | } |
505 | 521 | ||
506 | retval = size; | 522 | retval = size; |
@@ -544,16 +560,16 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev, | |||
544 | kone_set_settings_checksum(&kone->settings); | 560 | kone_set_settings_checksum(&kone->settings); |
545 | 561 | ||
546 | retval = kone_set_settings(usb_dev, &kone->settings); | 562 | retval = kone_set_settings(usb_dev, &kone->settings); |
547 | 563 | if (retval) { | |
548 | mutex_unlock(&kone->kone_lock); | 564 | mutex_unlock(&kone->kone_lock); |
549 | |||
550 | if (retval) | ||
551 | return retval; | 565 | return retval; |
566 | } | ||
552 | 567 | ||
553 | /* changing the startup profile immediately activates this profile */ | 568 | /* changing the startup profile immediately activates this profile */ |
554 | kone->actual_profile = new_startup_profile; | 569 | kone_profile_activated(kone, new_startup_profile); |
555 | kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi; | 570 | kone_profile_report(kone, new_startup_profile); |
556 | 571 | ||
572 | mutex_unlock(&kone->kone_lock); | ||
557 | return size; | 573 | return size; |
558 | } | 574 | } |
559 | 575 | ||
@@ -665,8 +681,7 @@ static int kone_init_kone_device_struct(struct usb_device *usb_dev, | |||
665 | if (retval) | 681 | if (retval) |
666 | return retval; | 682 | return retval; |
667 | 683 | ||
668 | kone->actual_profile = kone->settings.startup_profile; | 684 | kone_profile_activated(kone, kone->settings.startup_profile); |
669 | kone->actual_dpi = kone->profiles[kone->actual_profile].startup_dpi; | ||
670 | 685 | ||
671 | return 0; | 686 | return 0; |
672 | } | 687 | } |
@@ -776,10 +791,10 @@ static void kone_keep_values_up_to_date(struct kone_device *kone, | |||
776 | { | 791 | { |
777 | switch (event->event) { | 792 | switch (event->event) { |
778 | case kone_mouse_event_switch_profile: | 793 | case kone_mouse_event_switch_profile: |
794 | kone->actual_dpi = kone->profiles[event->value - 1]. | ||
795 | startup_dpi; | ||
779 | case kone_mouse_event_osd_profile: | 796 | case kone_mouse_event_osd_profile: |
780 | kone->actual_profile = event->value; | 797 | kone->actual_profile = event->value; |
781 | kone->actual_dpi = kone->profiles[kone->actual_profile - 1]. | ||
782 | startup_dpi; | ||
783 | break; | 798 | break; |
784 | case kone_mouse_event_switch_dpi: | 799 | case kone_mouse_event_switch_dpi: |
785 | case kone_mouse_event_osd_dpi: | 800 | case kone_mouse_event_osd_dpi: |
diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c index 1f8336e3f584..112d934132c8 100644 --- a/drivers/hid/hid-roccat-kovaplus.c +++ b/drivers/hid/hid-roccat-kovaplus.c | |||
@@ -323,6 +323,7 @@ static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev, | |||
323 | struct usb_device *usb_dev; | 323 | struct usb_device *usb_dev; |
324 | unsigned long profile; | 324 | unsigned long profile; |
325 | int retval; | 325 | int retval; |
326 | struct kovaplus_roccat_report roccat_report; | ||
326 | 327 | ||
327 | dev = dev->parent->parent; | 328 | dev = dev->parent->parent; |
328 | kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); | 329 | kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); |
@@ -337,10 +338,22 @@ static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev, | |||
337 | 338 | ||
338 | mutex_lock(&kovaplus->kovaplus_lock); | 339 | mutex_lock(&kovaplus->kovaplus_lock); |
339 | retval = kovaplus_set_actual_profile(usb_dev, profile); | 340 | retval = kovaplus_set_actual_profile(usb_dev, profile); |
341 | if (retval) { | ||
342 | mutex_unlock(&kovaplus->kovaplus_lock); | ||
343 | return retval; | ||
344 | } | ||
345 | |||
340 | kovaplus_profile_activated(kovaplus, profile); | 346 | kovaplus_profile_activated(kovaplus, profile); |
347 | |||
348 | roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1; | ||
349 | roccat_report.profile = profile + 1; | ||
350 | roccat_report.button = 0; | ||
351 | roccat_report.data1 = profile + 1; | ||
352 | roccat_report.data2 = 0; | ||
353 | roccat_report_event(kovaplus->chrdev_minor, | ||
354 | (uint8_t const *)&roccat_report); | ||
355 | |||
341 | mutex_unlock(&kovaplus->kovaplus_lock); | 356 | mutex_unlock(&kovaplus->kovaplus_lock); |
342 | if (retval) | ||
343 | return retval; | ||
344 | 357 | ||
345 | return size; | 358 | return size; |
346 | } | 359 | } |
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index 8140776bd8c5..df05c1b1064f 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c | |||
@@ -298,6 +298,7 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp, | |||
298 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 298 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
299 | int retval = 0; | 299 | int retval = 0; |
300 | int difference; | 300 | int difference; |
301 | struct pyra_roccat_report roccat_report; | ||
301 | 302 | ||
302 | if (off != 0 || count != sizeof(struct pyra_settings)) | 303 | if (off != 0 || count != sizeof(struct pyra_settings)) |
303 | return -EINVAL; | 304 | return -EINVAL; |
@@ -307,17 +308,23 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp, | |||
307 | if (difference) { | 308 | if (difference) { |
308 | retval = pyra_set_settings(usb_dev, | 309 | retval = pyra_set_settings(usb_dev, |
309 | (struct pyra_settings const *)buf); | 310 | (struct pyra_settings const *)buf); |
310 | if (!retval) | 311 | if (retval) { |
311 | memcpy(&pyra->settings, buf, | 312 | mutex_unlock(&pyra->pyra_lock); |
312 | sizeof(struct pyra_settings)); | 313 | return retval; |
313 | } | 314 | } |
314 | mutex_unlock(&pyra->pyra_lock); | ||
315 | 315 | ||
316 | if (retval) | 316 | memcpy(&pyra->settings, buf, |
317 | return retval; | 317 | sizeof(struct pyra_settings)); |
318 | 318 | ||
319 | profile_activated(pyra, pyra->settings.startup_profile); | 319 | profile_activated(pyra, pyra->settings.startup_profile); |
320 | 320 | ||
321 | roccat_report.type = PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2; | ||
322 | roccat_report.value = pyra->settings.startup_profile + 1; | ||
323 | roccat_report.key = 0; | ||
324 | roccat_report_event(pyra->chrdev_minor, | ||
325 | (uint8_t const *)&roccat_report); | ||
326 | } | ||
327 | mutex_unlock(&pyra->pyra_lock); | ||
321 | return sizeof(struct pyra_settings); | 328 | return sizeof(struct pyra_settings); |
322 | } | 329 | } |
323 | 330 | ||
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index 519f56c787bb..17bb88f782b6 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c | |||
@@ -310,6 +310,8 @@ static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi, | |||
310 | { | 310 | { |
311 | struct input_dev *input = hi->input; | 311 | struct input_dev *input = hi->input; |
312 | 312 | ||
313 | __set_bit(INPUT_PROP_POINTER, input->propbit); | ||
314 | |||
313 | /* Basics */ | 315 | /* Basics */ |
314 | input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); | 316 | input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); |
315 | 317 | ||
@@ -408,7 +410,6 @@ static int wacom_probe(struct hid_device *hdev, | |||
408 | goto err_ac; | 410 | goto err_ac; |
409 | } | 411 | } |
410 | #endif | 412 | #endif |
411 | |||
412 | return 0; | 413 | return 0; |
413 | 414 | ||
414 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY | 415 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index 85a02e5f9fe8..76739c07fa3c 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c | |||
@@ -10,15 +10,18 @@ | |||
10 | * any later version. | 10 | * any later version. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/completion.h> | ||
13 | #include <linux/device.h> | 14 | #include <linux/device.h> |
14 | #include <linux/hid.h> | 15 | #include <linux/hid.h> |
15 | #include <linux/input.h> | 16 | #include <linux/input.h> |
16 | #include <linux/leds.h> | 17 | #include <linux/leds.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/mutex.h> | ||
20 | #include <linux/power_supply.h> | ||
18 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
19 | #include "hid-ids.h" | 22 | #include "hid-ids.h" |
20 | 23 | ||
21 | #define WIIMOTE_VERSION "0.1" | 24 | #define WIIMOTE_VERSION "0.2" |
22 | #define WIIMOTE_NAME "Nintendo Wii Remote" | 25 | #define WIIMOTE_NAME "Nintendo Wii Remote" |
23 | #define WIIMOTE_BUFSIZE 32 | 26 | #define WIIMOTE_BUFSIZE 32 |
24 | 27 | ||
@@ -30,12 +33,26 @@ struct wiimote_buf { | |||
30 | struct wiimote_state { | 33 | struct wiimote_state { |
31 | spinlock_t lock; | 34 | spinlock_t lock; |
32 | __u8 flags; | 35 | __u8 flags; |
36 | __u8 accel_split[2]; | ||
37 | |||
38 | /* synchronous cmd requests */ | ||
39 | struct mutex sync; | ||
40 | struct completion ready; | ||
41 | int cmd; | ||
42 | __u32 opt; | ||
43 | |||
44 | /* results of synchronous requests */ | ||
45 | __u8 cmd_battery; | ||
46 | __u8 cmd_err; | ||
33 | }; | 47 | }; |
34 | 48 | ||
35 | struct wiimote_data { | 49 | struct wiimote_data { |
36 | struct hid_device *hdev; | 50 | struct hid_device *hdev; |
37 | struct input_dev *input; | 51 | struct input_dev *input; |
38 | struct led_classdev *leds[4]; | 52 | struct led_classdev *leds[4]; |
53 | struct input_dev *accel; | ||
54 | struct input_dev *ir; | ||
55 | struct power_supply battery; | ||
39 | 56 | ||
40 | spinlock_t qlock; | 57 | spinlock_t qlock; |
41 | __u8 head; | 58 | __u8 head; |
@@ -46,23 +63,47 @@ struct wiimote_data { | |||
46 | struct wiimote_state state; | 63 | struct wiimote_state state; |
47 | }; | 64 | }; |
48 | 65 | ||
49 | #define WIIPROTO_FLAG_LED1 0x01 | 66 | #define WIIPROTO_FLAG_LED1 0x01 |
50 | #define WIIPROTO_FLAG_LED2 0x02 | 67 | #define WIIPROTO_FLAG_LED2 0x02 |
51 | #define WIIPROTO_FLAG_LED3 0x04 | 68 | #define WIIPROTO_FLAG_LED3 0x04 |
52 | #define WIIPROTO_FLAG_LED4 0x08 | 69 | #define WIIPROTO_FLAG_LED4 0x08 |
70 | #define WIIPROTO_FLAG_RUMBLE 0x10 | ||
71 | #define WIIPROTO_FLAG_ACCEL 0x20 | ||
72 | #define WIIPROTO_FLAG_IR_BASIC 0x40 | ||
73 | #define WIIPROTO_FLAG_IR_EXT 0x80 | ||
74 | #define WIIPROTO_FLAG_IR_FULL 0xc0 /* IR_BASIC | IR_EXT */ | ||
53 | #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \ | 75 | #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \ |
54 | WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4) | 76 | WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4) |
77 | #define WIIPROTO_FLAGS_IR (WIIPROTO_FLAG_IR_BASIC | WIIPROTO_FLAG_IR_EXT | \ | ||
78 | WIIPROTO_FLAG_IR_FULL) | ||
55 | 79 | ||
56 | /* return flag for led \num */ | 80 | /* return flag for led \num */ |
57 | #define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1)) | 81 | #define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1)) |
58 | 82 | ||
59 | enum wiiproto_reqs { | 83 | enum wiiproto_reqs { |
60 | WIIPROTO_REQ_NULL = 0x0, | 84 | WIIPROTO_REQ_NULL = 0x0, |
85 | WIIPROTO_REQ_RUMBLE = 0x10, | ||
61 | WIIPROTO_REQ_LED = 0x11, | 86 | WIIPROTO_REQ_LED = 0x11, |
62 | WIIPROTO_REQ_DRM = 0x12, | 87 | WIIPROTO_REQ_DRM = 0x12, |
88 | WIIPROTO_REQ_IR1 = 0x13, | ||
89 | WIIPROTO_REQ_SREQ = 0x15, | ||
90 | WIIPROTO_REQ_WMEM = 0x16, | ||
91 | WIIPROTO_REQ_RMEM = 0x17, | ||
92 | WIIPROTO_REQ_IR2 = 0x1a, | ||
63 | WIIPROTO_REQ_STATUS = 0x20, | 93 | WIIPROTO_REQ_STATUS = 0x20, |
94 | WIIPROTO_REQ_DATA = 0x21, | ||
64 | WIIPROTO_REQ_RETURN = 0x22, | 95 | WIIPROTO_REQ_RETURN = 0x22, |
65 | WIIPROTO_REQ_DRM_K = 0x30, | 96 | WIIPROTO_REQ_DRM_K = 0x30, |
97 | WIIPROTO_REQ_DRM_KA = 0x31, | ||
98 | WIIPROTO_REQ_DRM_KE = 0x32, | ||
99 | WIIPROTO_REQ_DRM_KAI = 0x33, | ||
100 | WIIPROTO_REQ_DRM_KEE = 0x34, | ||
101 | WIIPROTO_REQ_DRM_KAE = 0x35, | ||
102 | WIIPROTO_REQ_DRM_KIE = 0x36, | ||
103 | WIIPROTO_REQ_DRM_KAIE = 0x37, | ||
104 | WIIPROTO_REQ_DRM_E = 0x3d, | ||
105 | WIIPROTO_REQ_DRM_SKAI1 = 0x3e, | ||
106 | WIIPROTO_REQ_DRM_SKAI2 = 0x3f, | ||
66 | }; | 107 | }; |
67 | 108 | ||
68 | enum wiiproto_keys { | 109 | enum wiiproto_keys { |
@@ -94,6 +135,56 @@ static __u16 wiiproto_keymap[] = { | |||
94 | BTN_MODE, /* WIIPROTO_KEY_HOME */ | 135 | BTN_MODE, /* WIIPROTO_KEY_HOME */ |
95 | }; | 136 | }; |
96 | 137 | ||
138 | static enum power_supply_property wiimote_battery_props[] = { | ||
139 | POWER_SUPPLY_PROP_CAPACITY | ||
140 | }; | ||
141 | |||
142 | /* requires the state.lock spinlock to be held */ | ||
143 | static inline bool wiimote_cmd_pending(struct wiimote_data *wdata, int cmd, | ||
144 | __u32 opt) | ||
145 | { | ||
146 | return wdata->state.cmd == cmd && wdata->state.opt == opt; | ||
147 | } | ||
148 | |||
149 | /* requires the state.lock spinlock to be held */ | ||
150 | static inline void wiimote_cmd_complete(struct wiimote_data *wdata) | ||
151 | { | ||
152 | wdata->state.cmd = WIIPROTO_REQ_NULL; | ||
153 | complete(&wdata->state.ready); | ||
154 | } | ||
155 | |||
156 | static inline int wiimote_cmd_acquire(struct wiimote_data *wdata) | ||
157 | { | ||
158 | return mutex_lock_interruptible(&wdata->state.sync) ? -ERESTARTSYS : 0; | ||
159 | } | ||
160 | |||
161 | /* requires the state.lock spinlock to be held */ | ||
162 | static inline void wiimote_cmd_set(struct wiimote_data *wdata, int cmd, | ||
163 | __u32 opt) | ||
164 | { | ||
165 | INIT_COMPLETION(wdata->state.ready); | ||
166 | wdata->state.cmd = cmd; | ||
167 | wdata->state.opt = opt; | ||
168 | } | ||
169 | |||
170 | static inline void wiimote_cmd_release(struct wiimote_data *wdata) | ||
171 | { | ||
172 | mutex_unlock(&wdata->state.sync); | ||
173 | } | ||
174 | |||
175 | static inline int wiimote_cmd_wait(struct wiimote_data *wdata) | ||
176 | { | ||
177 | int ret; | ||
178 | |||
179 | ret = wait_for_completion_interruptible_timeout(&wdata->state.ready, HZ); | ||
180 | if (ret < 0) | ||
181 | return -ERESTARTSYS; | ||
182 | else if (ret == 0) | ||
183 | return -EIO; | ||
184 | else | ||
185 | return 0; | ||
186 | } | ||
187 | |||
97 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, | 188 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, |
98 | size_t count) | 189 | size_t count) |
99 | { | 190 | { |
@@ -172,6 +263,39 @@ static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer, | |||
172 | spin_unlock_irqrestore(&wdata->qlock, flags); | 263 | spin_unlock_irqrestore(&wdata->qlock, flags); |
173 | } | 264 | } |
174 | 265 | ||
266 | /* | ||
267 | * This sets the rumble bit on the given output report if rumble is | ||
268 | * currently enabled. | ||
269 | * \cmd1 must point to the second byte in the output report => &cmd[1] | ||
270 | * This must be called on nearly every output report before passing it | ||
271 | * into the output queue! | ||
272 | */ | ||
273 | static inline void wiiproto_keep_rumble(struct wiimote_data *wdata, __u8 *cmd1) | ||
274 | { | ||
275 | if (wdata->state.flags & WIIPROTO_FLAG_RUMBLE) | ||
276 | *cmd1 |= 0x01; | ||
277 | } | ||
278 | |||
279 | static void wiiproto_req_rumble(struct wiimote_data *wdata, __u8 rumble) | ||
280 | { | ||
281 | __u8 cmd[2]; | ||
282 | |||
283 | rumble = !!rumble; | ||
284 | if (rumble == !!(wdata->state.flags & WIIPROTO_FLAG_RUMBLE)) | ||
285 | return; | ||
286 | |||
287 | if (rumble) | ||
288 | wdata->state.flags |= WIIPROTO_FLAG_RUMBLE; | ||
289 | else | ||
290 | wdata->state.flags &= ~WIIPROTO_FLAG_RUMBLE; | ||
291 | |||
292 | cmd[0] = WIIPROTO_REQ_RUMBLE; | ||
293 | cmd[1] = 0; | ||
294 | |||
295 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
296 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
297 | } | ||
298 | |||
175 | static void wiiproto_req_leds(struct wiimote_data *wdata, int leds) | 299 | static void wiiproto_req_leds(struct wiimote_data *wdata, int leds) |
176 | { | 300 | { |
177 | __u8 cmd[2]; | 301 | __u8 cmd[2]; |
@@ -193,6 +317,7 @@ static void wiiproto_req_leds(struct wiimote_data *wdata, int leds) | |||
193 | if (leds & WIIPROTO_FLAG_LED4) | 317 | if (leds & WIIPROTO_FLAG_LED4) |
194 | cmd[1] |= 0x80; | 318 | cmd[1] |= 0x80; |
195 | 319 | ||
320 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
196 | wiimote_queue(wdata, cmd, sizeof(cmd)); | 321 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
197 | } | 322 | } |
198 | 323 | ||
@@ -203,7 +328,23 @@ static void wiiproto_req_leds(struct wiimote_data *wdata, int leds) | |||
203 | */ | 328 | */ |
204 | static __u8 select_drm(struct wiimote_data *wdata) | 329 | static __u8 select_drm(struct wiimote_data *wdata) |
205 | { | 330 | { |
206 | return WIIPROTO_REQ_DRM_K; | 331 | __u8 ir = wdata->state.flags & WIIPROTO_FLAGS_IR; |
332 | |||
333 | if (ir == WIIPROTO_FLAG_IR_BASIC) { | ||
334 | if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) | ||
335 | return WIIPROTO_REQ_DRM_KAIE; | ||
336 | else | ||
337 | return WIIPROTO_REQ_DRM_KIE; | ||
338 | } else if (ir == WIIPROTO_FLAG_IR_EXT) { | ||
339 | return WIIPROTO_REQ_DRM_KAI; | ||
340 | } else if (ir == WIIPROTO_FLAG_IR_FULL) { | ||
341 | return WIIPROTO_REQ_DRM_SKAI1; | ||
342 | } else { | ||
343 | if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) | ||
344 | return WIIPROTO_REQ_DRM_KA; | ||
345 | else | ||
346 | return WIIPROTO_REQ_DRM_K; | ||
347 | } | ||
207 | } | 348 | } |
208 | 349 | ||
209 | static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) | 350 | static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) |
@@ -217,9 +358,256 @@ static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) | |||
217 | cmd[1] = 0; | 358 | cmd[1] = 0; |
218 | cmd[2] = drm; | 359 | cmd[2] = drm; |
219 | 360 | ||
361 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
362 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
363 | } | ||
364 | |||
365 | static void wiiproto_req_status(struct wiimote_data *wdata) | ||
366 | { | ||
367 | __u8 cmd[2]; | ||
368 | |||
369 | cmd[0] = WIIPROTO_REQ_SREQ; | ||
370 | cmd[1] = 0; | ||
371 | |||
372 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
373 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
374 | } | ||
375 | |||
376 | static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) | ||
377 | { | ||
378 | accel = !!accel; | ||
379 | if (accel == !!(wdata->state.flags & WIIPROTO_FLAG_ACCEL)) | ||
380 | return; | ||
381 | |||
382 | if (accel) | ||
383 | wdata->state.flags |= WIIPROTO_FLAG_ACCEL; | ||
384 | else | ||
385 | wdata->state.flags &= ~WIIPROTO_FLAG_ACCEL; | ||
386 | |||
387 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | ||
388 | } | ||
389 | |||
390 | static void wiiproto_req_ir1(struct wiimote_data *wdata, __u8 flags) | ||
391 | { | ||
392 | __u8 cmd[2]; | ||
393 | |||
394 | cmd[0] = WIIPROTO_REQ_IR1; | ||
395 | cmd[1] = flags; | ||
396 | |||
397 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
398 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
399 | } | ||
400 | |||
401 | static void wiiproto_req_ir2(struct wiimote_data *wdata, __u8 flags) | ||
402 | { | ||
403 | __u8 cmd[2]; | ||
404 | |||
405 | cmd[0] = WIIPROTO_REQ_IR2; | ||
406 | cmd[1] = flags; | ||
407 | |||
408 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
409 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
410 | } | ||
411 | |||
412 | #define wiiproto_req_wreg(wdata, os, buf, sz) \ | ||
413 | wiiproto_req_wmem((wdata), false, (os), (buf), (sz)) | ||
414 | |||
415 | #define wiiproto_req_weeprom(wdata, os, buf, sz) \ | ||
416 | wiiproto_req_wmem((wdata), true, (os), (buf), (sz)) | ||
417 | |||
418 | static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom, | ||
419 | __u32 offset, const __u8 *buf, __u8 size) | ||
420 | { | ||
421 | __u8 cmd[22]; | ||
422 | |||
423 | if (size > 16 || size == 0) { | ||
424 | hid_warn(wdata->hdev, "Invalid length %d wmem request\n", size); | ||
425 | return; | ||
426 | } | ||
427 | |||
428 | memset(cmd, 0, sizeof(cmd)); | ||
429 | cmd[0] = WIIPROTO_REQ_WMEM; | ||
430 | cmd[2] = (offset >> 16) & 0xff; | ||
431 | cmd[3] = (offset >> 8) & 0xff; | ||
432 | cmd[4] = offset & 0xff; | ||
433 | cmd[5] = size; | ||
434 | memcpy(&cmd[6], buf, size); | ||
435 | |||
436 | if (!eeprom) | ||
437 | cmd[1] |= 0x04; | ||
438 | |||
439 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
220 | wiimote_queue(wdata, cmd, sizeof(cmd)); | 440 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
221 | } | 441 | } |
222 | 442 | ||
443 | /* requries the cmd-mutex to be held */ | ||
444 | static int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset, | ||
445 | const __u8 *wmem, __u8 size) | ||
446 | { | ||
447 | unsigned long flags; | ||
448 | int ret; | ||
449 | |||
450 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
451 | wiimote_cmd_set(wdata, WIIPROTO_REQ_WMEM, 0); | ||
452 | wiiproto_req_wreg(wdata, offset, wmem, size); | ||
453 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
454 | |||
455 | ret = wiimote_cmd_wait(wdata); | ||
456 | if (!ret && wdata->state.cmd_err) | ||
457 | ret = -EIO; | ||
458 | |||
459 | return ret; | ||
460 | } | ||
461 | |||
462 | static int wiimote_battery_get_property(struct power_supply *psy, | ||
463 | enum power_supply_property psp, | ||
464 | union power_supply_propval *val) | ||
465 | { | ||
466 | struct wiimote_data *wdata = container_of(psy, | ||
467 | struct wiimote_data, battery); | ||
468 | int ret = 0, state; | ||
469 | unsigned long flags; | ||
470 | |||
471 | ret = wiimote_cmd_acquire(wdata); | ||
472 | if (ret) | ||
473 | return ret; | ||
474 | |||
475 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
476 | wiimote_cmd_set(wdata, WIIPROTO_REQ_SREQ, 0); | ||
477 | wiiproto_req_status(wdata); | ||
478 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
479 | |||
480 | ret = wiimote_cmd_wait(wdata); | ||
481 | state = wdata->state.cmd_battery; | ||
482 | wiimote_cmd_release(wdata); | ||
483 | |||
484 | if (ret) | ||
485 | return ret; | ||
486 | |||
487 | switch (psp) { | ||
488 | case POWER_SUPPLY_PROP_CAPACITY: | ||
489 | val->intval = state * 100 / 255; | ||
490 | break; | ||
491 | default: | ||
492 | ret = -EINVAL; | ||
493 | break; | ||
494 | } | ||
495 | |||
496 | return ret; | ||
497 | } | ||
498 | |||
499 | static int wiimote_init_ir(struct wiimote_data *wdata, __u16 mode) | ||
500 | { | ||
501 | int ret; | ||
502 | unsigned long flags; | ||
503 | __u8 format = 0; | ||
504 | static const __u8 data_enable[] = { 0x01 }; | ||
505 | static const __u8 data_sens1[] = { 0x02, 0x00, 0x00, 0x71, 0x01, | ||
506 | 0x00, 0xaa, 0x00, 0x64 }; | ||
507 | static const __u8 data_sens2[] = { 0x63, 0x03 }; | ||
508 | static const __u8 data_fin[] = { 0x08 }; | ||
509 | |||
510 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
511 | |||
512 | if (mode == (wdata->state.flags & WIIPROTO_FLAGS_IR)) { | ||
513 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | if (mode == 0) { | ||
518 | wdata->state.flags &= ~WIIPROTO_FLAGS_IR; | ||
519 | wiiproto_req_ir1(wdata, 0); | ||
520 | wiiproto_req_ir2(wdata, 0); | ||
521 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | ||
522 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
527 | |||
528 | ret = wiimote_cmd_acquire(wdata); | ||
529 | if (ret) | ||
530 | return ret; | ||
531 | |||
532 | /* send PIXEL CLOCK ENABLE cmd first */ | ||
533 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
534 | wiimote_cmd_set(wdata, WIIPROTO_REQ_IR1, 0); | ||
535 | wiiproto_req_ir1(wdata, 0x06); | ||
536 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
537 | |||
538 | ret = wiimote_cmd_wait(wdata); | ||
539 | if (ret) | ||
540 | goto unlock; | ||
541 | if (wdata->state.cmd_err) { | ||
542 | ret = -EIO; | ||
543 | goto unlock; | ||
544 | } | ||
545 | |||
546 | /* enable IR LOGIC */ | ||
547 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
548 | wiimote_cmd_set(wdata, WIIPROTO_REQ_IR2, 0); | ||
549 | wiiproto_req_ir2(wdata, 0x06); | ||
550 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
551 | |||
552 | ret = wiimote_cmd_wait(wdata); | ||
553 | if (ret) | ||
554 | goto unlock; | ||
555 | if (wdata->state.cmd_err) { | ||
556 | ret = -EIO; | ||
557 | goto unlock; | ||
558 | } | ||
559 | |||
560 | /* enable IR cam but do not make it send data, yet */ | ||
561 | ret = wiimote_cmd_write(wdata, 0xb00030, data_enable, | ||
562 | sizeof(data_enable)); | ||
563 | if (ret) | ||
564 | goto unlock; | ||
565 | |||
566 | /* write first sensitivity block */ | ||
567 | ret = wiimote_cmd_write(wdata, 0xb00000, data_sens1, | ||
568 | sizeof(data_sens1)); | ||
569 | if (ret) | ||
570 | goto unlock; | ||
571 | |||
572 | /* write second sensitivity block */ | ||
573 | ret = wiimote_cmd_write(wdata, 0xb0001a, data_sens2, | ||
574 | sizeof(data_sens2)); | ||
575 | if (ret) | ||
576 | goto unlock; | ||
577 | |||
578 | /* put IR cam into desired state */ | ||
579 | switch (mode) { | ||
580 | case WIIPROTO_FLAG_IR_FULL: | ||
581 | format = 5; | ||
582 | break; | ||
583 | case WIIPROTO_FLAG_IR_EXT: | ||
584 | format = 3; | ||
585 | break; | ||
586 | case WIIPROTO_FLAG_IR_BASIC: | ||
587 | format = 1; | ||
588 | break; | ||
589 | } | ||
590 | ret = wiimote_cmd_write(wdata, 0xb00033, &format, sizeof(format)); | ||
591 | if (ret) | ||
592 | goto unlock; | ||
593 | |||
594 | /* make IR cam send data */ | ||
595 | ret = wiimote_cmd_write(wdata, 0xb00030, data_fin, sizeof(data_fin)); | ||
596 | if (ret) | ||
597 | goto unlock; | ||
598 | |||
599 | /* request new DRM mode compatible to IR mode */ | ||
600 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
601 | wdata->state.flags &= ~WIIPROTO_FLAGS_IR; | ||
602 | wdata->state.flags |= mode & WIIPROTO_FLAGS_IR; | ||
603 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | ||
604 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
605 | |||
606 | unlock: | ||
607 | wiimote_cmd_release(wdata); | ||
608 | return ret; | ||
609 | } | ||
610 | |||
223 | static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev) | 611 | static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev) |
224 | { | 612 | { |
225 | struct wiimote_data *wdata; | 613 | struct wiimote_data *wdata; |
@@ -268,9 +656,28 @@ static void wiimote_leds_set(struct led_classdev *led_dev, | |||
268 | } | 656 | } |
269 | } | 657 | } |
270 | 658 | ||
271 | static int wiimote_input_event(struct input_dev *dev, unsigned int type, | 659 | static int wiimote_ff_play(struct input_dev *dev, void *data, |
272 | unsigned int code, int value) | 660 | struct ff_effect *eff) |
273 | { | 661 | { |
662 | struct wiimote_data *wdata = input_get_drvdata(dev); | ||
663 | __u8 value; | ||
664 | unsigned long flags; | ||
665 | |||
666 | /* | ||
667 | * The wiimote supports only a single rumble motor so if any magnitude | ||
668 | * is set to non-zero then we start the rumble motor. If both are set to | ||
669 | * zero, we stop the rumble motor. | ||
670 | */ | ||
671 | |||
672 | if (eff->u.rumble.strong_magnitude || eff->u.rumble.weak_magnitude) | ||
673 | value = 1; | ||
674 | else | ||
675 | value = 0; | ||
676 | |||
677 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
678 | wiiproto_req_rumble(wdata, value); | ||
679 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
680 | |||
274 | return 0; | 681 | return 0; |
275 | } | 682 | } |
276 | 683 | ||
@@ -288,6 +695,61 @@ static void wiimote_input_close(struct input_dev *dev) | |||
288 | hid_hw_close(wdata->hdev); | 695 | hid_hw_close(wdata->hdev); |
289 | } | 696 | } |
290 | 697 | ||
698 | static int wiimote_accel_open(struct input_dev *dev) | ||
699 | { | ||
700 | struct wiimote_data *wdata = input_get_drvdata(dev); | ||
701 | int ret; | ||
702 | unsigned long flags; | ||
703 | |||
704 | ret = hid_hw_open(wdata->hdev); | ||
705 | if (ret) | ||
706 | return ret; | ||
707 | |||
708 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
709 | wiiproto_req_accel(wdata, true); | ||
710 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
711 | |||
712 | return 0; | ||
713 | } | ||
714 | |||
715 | static void wiimote_accel_close(struct input_dev *dev) | ||
716 | { | ||
717 | struct wiimote_data *wdata = input_get_drvdata(dev); | ||
718 | unsigned long flags; | ||
719 | |||
720 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
721 | wiiproto_req_accel(wdata, false); | ||
722 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
723 | |||
724 | hid_hw_close(wdata->hdev); | ||
725 | } | ||
726 | |||
727 | static int wiimote_ir_open(struct input_dev *dev) | ||
728 | { | ||
729 | struct wiimote_data *wdata = input_get_drvdata(dev); | ||
730 | int ret; | ||
731 | |||
732 | ret = hid_hw_open(wdata->hdev); | ||
733 | if (ret) | ||
734 | return ret; | ||
735 | |||
736 | ret = wiimote_init_ir(wdata, WIIPROTO_FLAG_IR_BASIC); | ||
737 | if (ret) { | ||
738 | hid_hw_close(wdata->hdev); | ||
739 | return ret; | ||
740 | } | ||
741 | |||
742 | return 0; | ||
743 | } | ||
744 | |||
745 | static void wiimote_ir_close(struct input_dev *dev) | ||
746 | { | ||
747 | struct wiimote_data *wdata = input_get_drvdata(dev); | ||
748 | |||
749 | wiimote_init_ir(wdata, 0); | ||
750 | hid_hw_close(wdata->hdev); | ||
751 | } | ||
752 | |||
291 | static void handler_keys(struct wiimote_data *wdata, const __u8 *payload) | 753 | static void handler_keys(struct wiimote_data *wdata, const __u8 *payload) |
292 | { | 754 | { |
293 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_LEFT], | 755 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_LEFT], |
@@ -315,12 +777,100 @@ static void handler_keys(struct wiimote_data *wdata, const __u8 *payload) | |||
315 | input_sync(wdata->input); | 777 | input_sync(wdata->input); |
316 | } | 778 | } |
317 | 779 | ||
780 | static void handler_accel(struct wiimote_data *wdata, const __u8 *payload) | ||
781 | { | ||
782 | __u16 x, y, z; | ||
783 | |||
784 | if (!(wdata->state.flags & WIIPROTO_FLAG_ACCEL)) | ||
785 | return; | ||
786 | |||
787 | /* | ||
788 | * payload is: BB BB XX YY ZZ | ||
789 | * Accelerometer data is encoded into 3 10bit values. XX, YY and ZZ | ||
790 | * contain the upper 8 bits of each value. The lower 2 bits are | ||
791 | * contained in the buttons data BB BB. | ||
792 | * Bits 6 and 7 of the first buttons byte BB is the lower 2 bits of the | ||
793 | * X accel value. Bit 5 of the second buttons byte is the 2nd bit of Y | ||
794 | * accel value and bit 6 is the second bit of the Z value. | ||
795 | * The first bit of Y and Z values is not available and always set to 0. | ||
796 | * 0x200 is returned on no movement. | ||
797 | */ | ||
798 | |||
799 | x = payload[2] << 2; | ||
800 | y = payload[3] << 2; | ||
801 | z = payload[4] << 2; | ||
802 | |||
803 | x |= (payload[0] >> 5) & 0x3; | ||
804 | y |= (payload[1] >> 4) & 0x2; | ||
805 | z |= (payload[1] >> 5) & 0x2; | ||
806 | |||
807 | input_report_abs(wdata->accel, ABS_RX, x - 0x200); | ||
808 | input_report_abs(wdata->accel, ABS_RY, y - 0x200); | ||
809 | input_report_abs(wdata->accel, ABS_RZ, z - 0x200); | ||
810 | input_sync(wdata->accel); | ||
811 | } | ||
812 | |||
813 | #define ir_to_input0(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ | ||
814 | ABS_HAT0X, ABS_HAT0Y) | ||
815 | #define ir_to_input1(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ | ||
816 | ABS_HAT1X, ABS_HAT1Y) | ||
817 | #define ir_to_input2(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ | ||
818 | ABS_HAT2X, ABS_HAT2Y) | ||
819 | #define ir_to_input3(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ | ||
820 | ABS_HAT3X, ABS_HAT3Y) | ||
821 | |||
822 | static void __ir_to_input(struct wiimote_data *wdata, const __u8 *ir, | ||
823 | bool packed, __u8 xid, __u8 yid) | ||
824 | { | ||
825 | __u16 x, y; | ||
826 | |||
827 | if (!(wdata->state.flags & WIIPROTO_FLAGS_IR)) | ||
828 | return; | ||
829 | |||
830 | /* | ||
831 | * Basic IR data is encoded into 3 bytes. The first two bytes are the | ||
832 | * upper 8 bit of the X/Y data, the 3rd byte contains the lower 2 bits | ||
833 | * of both. | ||
834 | * If data is packed, then the 3rd byte is put first and slightly | ||
835 | * reordered. This allows to interleave packed and non-packed data to | ||
836 | * have two IR sets in 5 bytes instead of 6. | ||
837 | * The resulting 10bit X/Y values are passed to the ABS_HATXY input dev. | ||
838 | */ | ||
839 | |||
840 | if (packed) { | ||
841 | x = ir[1] << 2; | ||
842 | y = ir[2] << 2; | ||
843 | |||
844 | x |= ir[0] & 0x3; | ||
845 | y |= (ir[0] >> 2) & 0x3; | ||
846 | } else { | ||
847 | x = ir[0] << 2; | ||
848 | y = ir[1] << 2; | ||
849 | |||
850 | x |= (ir[2] >> 4) & 0x3; | ||
851 | y |= (ir[2] >> 6) & 0x3; | ||
852 | } | ||
853 | |||
854 | input_report_abs(wdata->ir, xid, x); | ||
855 | input_report_abs(wdata->ir, yid, y); | ||
856 | } | ||
857 | |||
318 | static void handler_status(struct wiimote_data *wdata, const __u8 *payload) | 858 | static void handler_status(struct wiimote_data *wdata, const __u8 *payload) |
319 | { | 859 | { |
320 | handler_keys(wdata, payload); | 860 | handler_keys(wdata, payload); |
321 | 861 | ||
322 | /* on status reports the drm is reset so we need to resend the drm */ | 862 | /* on status reports the drm is reset so we need to resend the drm */ |
323 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | 863 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); |
864 | |||
865 | if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) { | ||
866 | wdata->state.cmd_battery = payload[5]; | ||
867 | wiimote_cmd_complete(wdata); | ||
868 | } | ||
869 | } | ||
870 | |||
871 | static void handler_data(struct wiimote_data *wdata, const __u8 *payload) | ||
872 | { | ||
873 | handler_keys(wdata, payload); | ||
324 | } | 874 | } |
325 | 875 | ||
326 | static void handler_return(struct wiimote_data *wdata, const __u8 *payload) | 876 | static void handler_return(struct wiimote_data *wdata, const __u8 *payload) |
@@ -330,9 +880,105 @@ static void handler_return(struct wiimote_data *wdata, const __u8 *payload) | |||
330 | 880 | ||
331 | handler_keys(wdata, payload); | 881 | handler_keys(wdata, payload); |
332 | 882 | ||
333 | if (err) | 883 | if (wiimote_cmd_pending(wdata, cmd, 0)) { |
884 | wdata->state.cmd_err = err; | ||
885 | wiimote_cmd_complete(wdata); | ||
886 | } else if (err) { | ||
334 | hid_warn(wdata->hdev, "Remote error %hhu on req %hhu\n", err, | 887 | hid_warn(wdata->hdev, "Remote error %hhu on req %hhu\n", err, |
335 | cmd); | 888 | cmd); |
889 | } | ||
890 | } | ||
891 | |||
892 | static void handler_drm_KA(struct wiimote_data *wdata, const __u8 *payload) | ||
893 | { | ||
894 | handler_keys(wdata, payload); | ||
895 | handler_accel(wdata, payload); | ||
896 | } | ||
897 | |||
898 | static void handler_drm_KE(struct wiimote_data *wdata, const __u8 *payload) | ||
899 | { | ||
900 | handler_keys(wdata, payload); | ||
901 | } | ||
902 | |||
903 | static void handler_drm_KAI(struct wiimote_data *wdata, const __u8 *payload) | ||
904 | { | ||
905 | handler_keys(wdata, payload); | ||
906 | handler_accel(wdata, payload); | ||
907 | ir_to_input0(wdata, &payload[5], false); | ||
908 | ir_to_input1(wdata, &payload[8], false); | ||
909 | ir_to_input2(wdata, &payload[11], false); | ||
910 | ir_to_input3(wdata, &payload[14], false); | ||
911 | input_sync(wdata->ir); | ||
912 | } | ||
913 | |||
914 | static void handler_drm_KEE(struct wiimote_data *wdata, const __u8 *payload) | ||
915 | { | ||
916 | handler_keys(wdata, payload); | ||
917 | } | ||
918 | |||
919 | static void handler_drm_KIE(struct wiimote_data *wdata, const __u8 *payload) | ||
920 | { | ||
921 | handler_keys(wdata, payload); | ||
922 | ir_to_input0(wdata, &payload[2], false); | ||
923 | ir_to_input1(wdata, &payload[4], true); | ||
924 | ir_to_input2(wdata, &payload[7], false); | ||
925 | ir_to_input3(wdata, &payload[9], true); | ||
926 | input_sync(wdata->ir); | ||
927 | } | ||
928 | |||
929 | static void handler_drm_KAE(struct wiimote_data *wdata, const __u8 *payload) | ||
930 | { | ||
931 | handler_keys(wdata, payload); | ||
932 | handler_accel(wdata, payload); | ||
933 | } | ||
934 | |||
935 | static void handler_drm_KAIE(struct wiimote_data *wdata, const __u8 *payload) | ||
936 | { | ||
937 | handler_keys(wdata, payload); | ||
938 | handler_accel(wdata, payload); | ||
939 | ir_to_input0(wdata, &payload[5], false); | ||
940 | ir_to_input1(wdata, &payload[7], true); | ||
941 | ir_to_input2(wdata, &payload[10], false); | ||
942 | ir_to_input3(wdata, &payload[12], true); | ||
943 | input_sync(wdata->ir); | ||
944 | } | ||
945 | |||
946 | static void handler_drm_E(struct wiimote_data *wdata, const __u8 *payload) | ||
947 | { | ||
948 | } | ||
949 | |||
950 | static void handler_drm_SKAI1(struct wiimote_data *wdata, const __u8 *payload) | ||
951 | { | ||
952 | handler_keys(wdata, payload); | ||
953 | |||
954 | wdata->state.accel_split[0] = payload[2]; | ||
955 | wdata->state.accel_split[1] = (payload[0] >> 1) & (0x10 | 0x20); | ||
956 | wdata->state.accel_split[1] |= (payload[1] << 1) & (0x40 | 0x80); | ||
957 | |||
958 | ir_to_input0(wdata, &payload[3], false); | ||
959 | ir_to_input1(wdata, &payload[12], false); | ||
960 | input_sync(wdata->ir); | ||
961 | } | ||
962 | |||
963 | static void handler_drm_SKAI2(struct wiimote_data *wdata, const __u8 *payload) | ||
964 | { | ||
965 | __u8 buf[5]; | ||
966 | |||
967 | handler_keys(wdata, payload); | ||
968 | |||
969 | wdata->state.accel_split[1] |= (payload[0] >> 5) & (0x01 | 0x02); | ||
970 | wdata->state.accel_split[1] |= (payload[1] >> 3) & (0x04 | 0x08); | ||
971 | |||
972 | buf[0] = 0; | ||
973 | buf[1] = 0; | ||
974 | buf[2] = wdata->state.accel_split[0]; | ||
975 | buf[3] = payload[2]; | ||
976 | buf[4] = wdata->state.accel_split[1]; | ||
977 | handler_accel(wdata, buf); | ||
978 | |||
979 | ir_to_input2(wdata, &payload[3], false); | ||
980 | ir_to_input3(wdata, &payload[12], false); | ||
981 | input_sync(wdata->ir); | ||
336 | } | 982 | } |
337 | 983 | ||
338 | struct wiiproto_handler { | 984 | struct wiiproto_handler { |
@@ -343,8 +989,19 @@ struct wiiproto_handler { | |||
343 | 989 | ||
344 | static struct wiiproto_handler handlers[] = { | 990 | static struct wiiproto_handler handlers[] = { |
345 | { .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status }, | 991 | { .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status }, |
992 | { .id = WIIPROTO_REQ_DATA, .size = 21, .func = handler_data }, | ||
346 | { .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return }, | 993 | { .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return }, |
347 | { .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys }, | 994 | { .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys }, |
995 | { .id = WIIPROTO_REQ_DRM_KA, .size = 5, .func = handler_drm_KA }, | ||
996 | { .id = WIIPROTO_REQ_DRM_KE, .size = 10, .func = handler_drm_KE }, | ||
997 | { .id = WIIPROTO_REQ_DRM_KAI, .size = 17, .func = handler_drm_KAI }, | ||
998 | { .id = WIIPROTO_REQ_DRM_KEE, .size = 21, .func = handler_drm_KEE }, | ||
999 | { .id = WIIPROTO_REQ_DRM_KAE, .size = 21, .func = handler_drm_KAE }, | ||
1000 | { .id = WIIPROTO_REQ_DRM_KIE, .size = 21, .func = handler_drm_KIE }, | ||
1001 | { .id = WIIPROTO_REQ_DRM_KAIE, .size = 21, .func = handler_drm_KAIE }, | ||
1002 | { .id = WIIPROTO_REQ_DRM_E, .size = 21, .func = handler_drm_E }, | ||
1003 | { .id = WIIPROTO_REQ_DRM_SKAI1, .size = 21, .func = handler_drm_SKAI1 }, | ||
1004 | { .id = WIIPROTO_REQ_DRM_SKAI2, .size = 21, .func = handler_drm_SKAI2 }, | ||
348 | { .id = 0 } | 1005 | { .id = 0 } |
349 | }; | 1006 | }; |
350 | 1007 | ||
@@ -355,6 +1012,7 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, | |||
355 | struct wiiproto_handler *h; | 1012 | struct wiiproto_handler *h; |
356 | int i; | 1013 | int i; |
357 | unsigned long flags; | 1014 | unsigned long flags; |
1015 | bool handled = false; | ||
358 | 1016 | ||
359 | if (size < 1) | 1017 | if (size < 1) |
360 | return -EINVAL; | 1018 | return -EINVAL; |
@@ -363,10 +1021,16 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, | |||
363 | 1021 | ||
364 | for (i = 0; handlers[i].id; ++i) { | 1022 | for (i = 0; handlers[i].id; ++i) { |
365 | h = &handlers[i]; | 1023 | h = &handlers[i]; |
366 | if (h->id == raw_data[0] && h->size < size) | 1024 | if (h->id == raw_data[0] && h->size < size) { |
367 | h->func(wdata, &raw_data[1]); | 1025 | h->func(wdata, &raw_data[1]); |
1026 | handled = true; | ||
1027 | } | ||
368 | } | 1028 | } |
369 | 1029 | ||
1030 | if (!handled) | ||
1031 | hid_warn(hdev, "Unhandled report %hhu size %d\n", raw_data[0], | ||
1032 | size); | ||
1033 | |||
370 | spin_unlock_irqrestore(&wdata->state.lock, flags); | 1034 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
371 | 1035 | ||
372 | return 0; | 1036 | return 0; |
@@ -434,16 +1098,13 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) | |||
434 | return NULL; | 1098 | return NULL; |
435 | 1099 | ||
436 | wdata->input = input_allocate_device(); | 1100 | wdata->input = input_allocate_device(); |
437 | if (!wdata->input) { | 1101 | if (!wdata->input) |
438 | kfree(wdata); | 1102 | goto err; |
439 | return NULL; | ||
440 | } | ||
441 | 1103 | ||
442 | wdata->hdev = hdev; | 1104 | wdata->hdev = hdev; |
443 | hid_set_drvdata(hdev, wdata); | 1105 | hid_set_drvdata(hdev, wdata); |
444 | 1106 | ||
445 | input_set_drvdata(wdata->input, wdata); | 1107 | input_set_drvdata(wdata->input, wdata); |
446 | wdata->input->event = wiimote_input_event; | ||
447 | wdata->input->open = wiimote_input_open; | 1108 | wdata->input->open = wiimote_input_open; |
448 | wdata->input->close = wiimote_input_close; | 1109 | wdata->input->close = wiimote_input_close; |
449 | wdata->input->dev.parent = &wdata->hdev->dev; | 1110 | wdata->input->dev.parent = &wdata->hdev->dev; |
@@ -457,18 +1118,89 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) | |||
457 | for (i = 0; i < WIIPROTO_KEY_COUNT; ++i) | 1118 | for (i = 0; i < WIIPROTO_KEY_COUNT; ++i) |
458 | set_bit(wiiproto_keymap[i], wdata->input->keybit); | 1119 | set_bit(wiiproto_keymap[i], wdata->input->keybit); |
459 | 1120 | ||
1121 | set_bit(FF_RUMBLE, wdata->input->ffbit); | ||
1122 | if (input_ff_create_memless(wdata->input, NULL, wiimote_ff_play)) | ||
1123 | goto err_input; | ||
1124 | |||
1125 | wdata->accel = input_allocate_device(); | ||
1126 | if (!wdata->accel) | ||
1127 | goto err_input; | ||
1128 | |||
1129 | input_set_drvdata(wdata->accel, wdata); | ||
1130 | wdata->accel->open = wiimote_accel_open; | ||
1131 | wdata->accel->close = wiimote_accel_close; | ||
1132 | wdata->accel->dev.parent = &wdata->hdev->dev; | ||
1133 | wdata->accel->id.bustype = wdata->hdev->bus; | ||
1134 | wdata->accel->id.vendor = wdata->hdev->vendor; | ||
1135 | wdata->accel->id.product = wdata->hdev->product; | ||
1136 | wdata->accel->id.version = wdata->hdev->version; | ||
1137 | wdata->accel->name = WIIMOTE_NAME " Accelerometer"; | ||
1138 | |||
1139 | set_bit(EV_ABS, wdata->accel->evbit); | ||
1140 | set_bit(ABS_RX, wdata->accel->absbit); | ||
1141 | set_bit(ABS_RY, wdata->accel->absbit); | ||
1142 | set_bit(ABS_RZ, wdata->accel->absbit); | ||
1143 | input_set_abs_params(wdata->accel, ABS_RX, -500, 500, 2, 4); | ||
1144 | input_set_abs_params(wdata->accel, ABS_RY, -500, 500, 2, 4); | ||
1145 | input_set_abs_params(wdata->accel, ABS_RZ, -500, 500, 2, 4); | ||
1146 | |||
1147 | wdata->ir = input_allocate_device(); | ||
1148 | if (!wdata->ir) | ||
1149 | goto err_ir; | ||
1150 | |||
1151 | input_set_drvdata(wdata->ir, wdata); | ||
1152 | wdata->ir->open = wiimote_ir_open; | ||
1153 | wdata->ir->close = wiimote_ir_close; | ||
1154 | wdata->ir->dev.parent = &wdata->hdev->dev; | ||
1155 | wdata->ir->id.bustype = wdata->hdev->bus; | ||
1156 | wdata->ir->id.vendor = wdata->hdev->vendor; | ||
1157 | wdata->ir->id.product = wdata->hdev->product; | ||
1158 | wdata->ir->id.version = wdata->hdev->version; | ||
1159 | wdata->ir->name = WIIMOTE_NAME " IR"; | ||
1160 | |||
1161 | set_bit(EV_ABS, wdata->ir->evbit); | ||
1162 | set_bit(ABS_HAT0X, wdata->ir->absbit); | ||
1163 | set_bit(ABS_HAT0Y, wdata->ir->absbit); | ||
1164 | set_bit(ABS_HAT1X, wdata->ir->absbit); | ||
1165 | set_bit(ABS_HAT1Y, wdata->ir->absbit); | ||
1166 | set_bit(ABS_HAT2X, wdata->ir->absbit); | ||
1167 | set_bit(ABS_HAT2Y, wdata->ir->absbit); | ||
1168 | set_bit(ABS_HAT3X, wdata->ir->absbit); | ||
1169 | set_bit(ABS_HAT3Y, wdata->ir->absbit); | ||
1170 | input_set_abs_params(wdata->ir, ABS_HAT0X, 0, 1023, 2, 4); | ||
1171 | input_set_abs_params(wdata->ir, ABS_HAT0Y, 0, 767, 2, 4); | ||
1172 | input_set_abs_params(wdata->ir, ABS_HAT1X, 0, 1023, 2, 4); | ||
1173 | input_set_abs_params(wdata->ir, ABS_HAT1Y, 0, 767, 2, 4); | ||
1174 | input_set_abs_params(wdata->ir, ABS_HAT2X, 0, 1023, 2, 4); | ||
1175 | input_set_abs_params(wdata->ir, ABS_HAT2Y, 0, 767, 2, 4); | ||
1176 | input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4); | ||
1177 | input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4); | ||
1178 | |||
460 | spin_lock_init(&wdata->qlock); | 1179 | spin_lock_init(&wdata->qlock); |
461 | INIT_WORK(&wdata->worker, wiimote_worker); | 1180 | INIT_WORK(&wdata->worker, wiimote_worker); |
462 | 1181 | ||
463 | spin_lock_init(&wdata->state.lock); | 1182 | spin_lock_init(&wdata->state.lock); |
1183 | init_completion(&wdata->state.ready); | ||
1184 | mutex_init(&wdata->state.sync); | ||
464 | 1185 | ||
465 | return wdata; | 1186 | return wdata; |
1187 | |||
1188 | err_ir: | ||
1189 | input_free_device(wdata->accel); | ||
1190 | err_input: | ||
1191 | input_free_device(wdata->input); | ||
1192 | err: | ||
1193 | kfree(wdata); | ||
1194 | return NULL; | ||
466 | } | 1195 | } |
467 | 1196 | ||
468 | static void wiimote_destroy(struct wiimote_data *wdata) | 1197 | static void wiimote_destroy(struct wiimote_data *wdata) |
469 | { | 1198 | { |
470 | wiimote_leds_destroy(wdata); | 1199 | wiimote_leds_destroy(wdata); |
471 | 1200 | ||
1201 | power_supply_unregister(&wdata->battery); | ||
1202 | input_unregister_device(wdata->accel); | ||
1203 | input_unregister_device(wdata->ir); | ||
472 | input_unregister_device(wdata->input); | 1204 | input_unregister_device(wdata->input); |
473 | cancel_work_sync(&wdata->worker); | 1205 | cancel_work_sync(&wdata->worker); |
474 | hid_hw_stop(wdata->hdev); | 1206 | hid_hw_stop(wdata->hdev); |
@@ -500,12 +1232,37 @@ static int wiimote_hid_probe(struct hid_device *hdev, | |||
500 | goto err; | 1232 | goto err; |
501 | } | 1233 | } |
502 | 1234 | ||
503 | ret = input_register_device(wdata->input); | 1235 | ret = input_register_device(wdata->accel); |
504 | if (ret) { | 1236 | if (ret) { |
505 | hid_err(hdev, "Cannot register input device\n"); | 1237 | hid_err(hdev, "Cannot register input device\n"); |
506 | goto err_stop; | 1238 | goto err_stop; |
507 | } | 1239 | } |
508 | 1240 | ||
1241 | ret = input_register_device(wdata->ir); | ||
1242 | if (ret) { | ||
1243 | hid_err(hdev, "Cannot register input device\n"); | ||
1244 | goto err_ir; | ||
1245 | } | ||
1246 | |||
1247 | ret = input_register_device(wdata->input); | ||
1248 | if (ret) { | ||
1249 | hid_err(hdev, "Cannot register input device\n"); | ||
1250 | goto err_input; | ||
1251 | } | ||
1252 | |||
1253 | wdata->battery.properties = wiimote_battery_props; | ||
1254 | wdata->battery.num_properties = ARRAY_SIZE(wiimote_battery_props); | ||
1255 | wdata->battery.get_property = wiimote_battery_get_property; | ||
1256 | wdata->battery.name = "wiimote_battery"; | ||
1257 | wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; | ||
1258 | wdata->battery.use_for_apm = 0; | ||
1259 | |||
1260 | ret = power_supply_register(&wdata->hdev->dev, &wdata->battery); | ||
1261 | if (ret) { | ||
1262 | hid_err(hdev, "Cannot register battery device\n"); | ||
1263 | goto err_battery; | ||
1264 | } | ||
1265 | |||
509 | ret = wiimote_leds_create(wdata); | 1266 | ret = wiimote_leds_create(wdata); |
510 | if (ret) | 1267 | if (ret) |
511 | goto err_free; | 1268 | goto err_free; |
@@ -523,9 +1280,20 @@ err_free: | |||
523 | wiimote_destroy(wdata); | 1280 | wiimote_destroy(wdata); |
524 | return ret; | 1281 | return ret; |
525 | 1282 | ||
1283 | err_battery: | ||
1284 | input_unregister_device(wdata->input); | ||
1285 | wdata->input = NULL; | ||
1286 | err_input: | ||
1287 | input_unregister_device(wdata->ir); | ||
1288 | wdata->ir = NULL; | ||
1289 | err_ir: | ||
1290 | input_unregister_device(wdata->accel); | ||
1291 | wdata->accel = NULL; | ||
526 | err_stop: | 1292 | err_stop: |
527 | hid_hw_stop(hdev); | 1293 | hid_hw_stop(hdev); |
528 | err: | 1294 | err: |
1295 | input_free_device(wdata->ir); | ||
1296 | input_free_device(wdata->accel); | ||
529 | input_free_device(wdata->input); | 1297 | input_free_device(wdata->input); |
530 | kfree(wdata); | 1298 | kfree(wdata); |
531 | return ret; | 1299 | return ret; |