25 #include <linux/device.h>
26 #include <linux/hid.h>
27 #include <linux/module.h>
29 #include <asm/unaligned.h>
35 static const char kbd_descriptor[] = {
68 static const char mse_descriptor[] = {
106 static const char consumer_descriptor[] = {
122 static const char syscontrol_descriptor[] = {
141 static const char media_descriptor[] = {
157 #define MAX_REPORT_SIZE 8
160 #define MAX_RDESC_SIZE \
161 (sizeof(kbd_descriptor) + \
162 sizeof(mse_descriptor) + \
163 sizeof(consumer_descriptor) + \
164 sizeof(syscontrol_descriptor) + \
165 sizeof(media_descriptor))
179 #define NUMBER_OF_HID_REPORTS 32
189 #define LOGITECH_DJ_INTERFACE_NUMBER 0x02
193 static int logi_dj_output_hidraw_report(
struct hid_device *hid,
u8 *
buf,
195 unsigned char report_type);
196 static int logi_dj_recv_query_paired_devices(
struct dj_receiver_dev *djrcv_dev);
198 static void logi_dj_recv_destroy_djhid_device(
struct dj_receiver_dev *djrcv_dev,
208 spin_unlock_irqrestore(&djrcv_dev->
lock, flags);
210 if (dj_dev !=
NULL) {
214 dev_err(&djrcv_dev->
hdev->dev,
"%s: can't destroy a NULL device\n",
219 static void logi_dj_recv_add_djhid_device(
struct dj_receiver_dev *djrcv_dev,
220 struct dj_report *dj_report)
225 struct usb_device *usbdev = interface_to_usbdev(intf);
232 unsigned char tmpstr[3];
236 dbg_hid(
"%s: device list is empty\n", __func__);
243 dev_err(&djrcv_hdev->
dev,
"%s: invalid device index:%d\n",
250 dbg_hid(
"%s: device is already known\n", __func__);
255 if (IS_ERR(dj_hiddev)) {
256 dev_err(&djrcv_hdev->
dev,
"%s: hid_allocate_device failed\n",
261 dj_hiddev->
ll_driver = &logi_dj_ll_driver;
264 dj_hiddev->
dev.parent = &djrcv_hdev->
dev;
269 "Logitech Unifying Device. Wireless PID:%02x%02x",
273 usb_make_path(usbdev, dj_hiddev->
phys,
sizeof(dj_hiddev->
phys));
280 dev_err(&djrcv_hdev->
dev,
"%s: failed allocating dj_device\n",
282 goto dj_device_allocate_fail;
287 dj_dev->
hdev = dj_hiddev;
295 dev_err(&djrcv_hdev->
dev,
"%s: failed adding dj_device\n",
297 goto hid_add_device_fail;
305 dj_device_allocate_fail:
314 struct dj_report dj_report;
324 sizeof(
struct dj_report));
326 if (count !=
sizeof(
struct dj_report)) {
327 dev_err(&djrcv_dev->
hdev->dev,
"%s: workitem triggered without "
328 "notifications available\n", __func__);
329 spin_unlock_irqrestore(&djrcv_dev->
lock, flags);
335 dbg_hid(
"%s: did not schedule the work item, was "
336 "already queued\n", __func__);
340 spin_unlock_irqrestore(&djrcv_dev->
lock, flags);
344 logi_dj_recv_add_djhid_device(djrcv_dev, &dj_report);
347 logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report);
360 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
366 "%s:logi_dj_recv_query_paired_devices "
367 "error:%d\n", __func__, retval);
369 dbg_hid(
"%s: unexpected report type\n", __func__);
373 static void logi_dj_recv_queue_notification(
struct dj_receiver_dev *djrcv_dev,
374 struct dj_report *dj_report)
381 dbg_hid(
"%s: did not schedule the work item, was already "
382 "queued\n", __func__);
386 static void logi_dj_recv_forward_null_report(
struct dj_receiver_dev *djrcv_dev,
387 struct dj_report *dj_report)
397 dbg_hid(
"djrcv_dev->paired_dj_devices[dj_report->device_index]"
402 dbg_hid(
"%s: did not schedule the work item, was already "
403 "queued\n", __func__);
408 memset(reportbuffer, 0,
sizeof(reportbuffer));
416 hid_reportid_size_map[i], 1)) {
417 dbg_hid(
"hid_input_report error sending null "
424 static void logi_dj_recv_forward_report(
struct dj_receiver_dev *djrcv_dev,
425 struct dj_report *dj_report)
432 if (dj_device ==
NULL) {
433 dbg_hid(
"djrcv_dev->paired_dj_devices[dj_report->device_index]"
438 dbg_hid(
"%s: did not schedule the work item, was already "
439 "queued\n", __func__);
445 (hid_reportid_size_map[dj_report->
report_type] == 0)) {
452 hid_reportid_size_map[dj_report->
report_type], 1)) {
453 dbg_hid(
"hid_input_report error\n");
459 struct dj_report *dj_report)
466 "hid_output_raw_report is null\n", __func__);
471 sizeof(
struct dj_report),
474 return (sent_bytes < 0) ? sent_bytes : 0;
477 static int logi_dj_recv_query_paired_devices(
struct dj_receiver_dev *djrcv_dev)
479 struct dj_report *dj_report;
486 dj_report = kzalloc(
sizeof(
struct dj_report),
GFP_KERNEL);
492 retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
498 static int logi_dj_recv_switch_to_dj_mode(
struct dj_receiver_dev *djrcv_dev,
501 struct dj_report *dj_report;
504 dj_report = kzalloc(
sizeof(
struct dj_report),
GFP_KERNEL);
512 retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
518 static int logi_dj_ll_open(
struct hid_device *hid)
525 static void logi_dj_ll_close(
struct hid_device *hid)
530 static int logi_dj_output_hidraw_report(
struct hid_device *hid,
u8 *
buf,
540 static void rdcat(
char **rdesc,
unsigned int *rsize,
const char *
data,
unsigned int size)
542 memcpy(*rdesc + *rsize, data, size);
546 static int logi_dj_ll_parse(
struct hid_device *hid)
549 unsigned int rsize = 0;
555 djdev->
hdev->version = 0x0111;
556 djdev->
hdev->country = 0x00;
563 dbg_hid(
"%s: sending a kbd descriptor, reports_supported: %x\n",
565 rdcat(&rdesc, &rsize, kbd_descriptor,
sizeof(kbd_descriptor));
569 dbg_hid(
"%s: sending a mouse descriptor, reports_supported: "
571 rdcat(&rdesc, &rsize, mse_descriptor,
sizeof(mse_descriptor));
575 dbg_hid(
"%s: sending a multimedia report descriptor: %x\n",
577 rdcat(&rdesc, &rsize, consumer_descriptor,
sizeof(consumer_descriptor));
581 dbg_hid(
"%s: sending a power keys report descriptor: %x\n",
583 rdcat(&rdesc, &rsize, syscontrol_descriptor,
sizeof(syscontrol_descriptor));
587 dbg_hid(
"%s: sending a media center report descriptor: %x\n",
589 rdcat(&rdesc, &rsize, media_descriptor,
sizeof(media_descriptor));
593 dbg_hid(
"%s: need to send kbd leds report descriptor: %x\n",
603 static int logi_dj_ll_input_event(
struct input_dev *
dev,
unsigned int type,
607 struct hid_device *dj_hiddev = input_get_drvdata(dev);
617 unsigned char data[8];
620 dbg_hid(
"%s: %s, type:%d | code:%d | value:%d\n",
621 __func__, dev->phys, type, code, value);
629 dev_warn(&dev->dev,
"event field not found\n");
647 static int logi_dj_ll_start(
struct hid_device *hid)
653 static void logi_dj_ll_stop(
struct hid_device *hid)
660 .parse = logi_dj_ll_parse,
661 .start = logi_dj_ll_start,
662 .stop = logi_dj_ll_stop,
663 .open = logi_dj_ll_open,
664 .close = logi_dj_ll_close,
665 .hidinput_input_event = logi_dj_ll_input_event,
669 static int logi_dj_raw_event(
struct hid_device *hdev,
674 struct dj_report *dj_report = (
struct dj_report *) data;
676 bool report_processed =
false;
678 dbg_hid(
"%s, size:%d\n", __func__, size);
709 logi_dj_recv_queue_notification(djrcv_dev, dj_report);
714 logi_dj_recv_forward_null_report(djrcv_dev, dj_report);
718 logi_dj_recv_forward_report(djrcv_dev, dj_report);
720 report_processed =
true;
722 spin_unlock_irqrestore(&djrcv_dev->
lock, flags);
724 return report_processed;
727 static int logi_dj_probe(
struct hid_device *hdev,
737 dbg_hid(
"%s called for ifnum %d\n", __func__,
738 intf->cur_altsetting->desc.bInterfaceNumber);
742 if (intf->cur_altsetting->desc.bInterfaceNumber !=
744 dbg_hid(
"%s: ignoring ifnum %d\n", __func__,
745 intf->cur_altsetting->desc.bInterfaceNumber);
754 "%s:failed allocating dj_receiver_dev\n", __func__);
764 "%s:failed allocating notif_fifo\n", __func__);
768 hid_set_drvdata(hdev, djrcv_dev);
774 retval = hid_parse(hdev);
777 "%s:parse of interface 2 failed\n", __func__);
786 "%s:hid_hw_start returned error\n", __func__);
787 goto hid_hw_start_fail;
790 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
793 "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n",
795 goto switch_to_dj_mode_fail;
801 dev_err(&hdev->
dev,
"%s:hdev->ll_driver->open returned "
802 "error:%d\n", __func__, retval);
806 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
808 dev_err(&hdev->
dev,
"%s:logi_dj_recv_query_paired_devices "
809 "error:%d\n", __func__, retval);
810 goto logi_dj_recv_query_paired_devices_failed;
815 logi_dj_recv_query_paired_devices_failed:
819 switch_to_dj_mode_fail:
826 hid_set_drvdata(hdev,
NULL);
832 static int logi_dj_reset_resume(
struct hid_device *hdev)
837 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
840 "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n",
848 static void logi_dj_remove(
struct hid_device *hdev)
851 struct dj_device *dj_dev;
868 if (dj_dev !=
NULL) {
877 hid_set_drvdata(hdev,
NULL);
880 static int logi_djdevice_probe(
struct hid_device *hdev,
889 ret = hid_parse(hdev);
906 static struct hid_driver logi_djreceiver_driver = {
907 .name =
"logitech-djreceiver",
908 .id_table = logi_dj_receivers,
909 .probe = logi_dj_probe,
910 .remove = logi_dj_remove,
911 .raw_event = logi_dj_raw_event,
913 .reset_resume = logi_dj_reset_resume,
926 static struct hid_driver logi_djdevice_driver = {
927 .name =
"logitech-djdevice",
928 .id_table = logi_dj_devices,
929 .probe = logi_djdevice_probe,
933 static int __init logi_dj_init(
void)
937 dbg_hid(
"Logitech-DJ:%s\n", __func__);
951 static void __exit logi_dj_exit(
void)
953 dbg_hid(
"Logitech-DJ:%s\n", __func__);