Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  HID driver for Logitech receivers
0004  *
0005  *  Copyright (c) 2011 Logitech
0006  */
0007 
0008 
0009 
0010 #include <linux/device.h>
0011 #include <linux/hid.h>
0012 #include <linux/module.h>
0013 #include <linux/kfifo.h>
0014 #include <linux/delay.h>
0015 #include <linux/usb.h> /* For to_usb_interface for kvm extra intf check */
0016 #include <asm/unaligned.h>
0017 #include "hid-ids.h"
0018 
0019 #define DJ_MAX_PAIRED_DEVICES           7
0020 #define DJ_MAX_NUMBER_NOTIFS            8
0021 #define DJ_RECEIVER_INDEX           0
0022 #define DJ_DEVICE_INDEX_MIN         1
0023 #define DJ_DEVICE_INDEX_MAX         7
0024 
0025 #define DJREPORT_SHORT_LENGTH           15
0026 #define DJREPORT_LONG_LENGTH            32
0027 
0028 #define REPORT_ID_DJ_SHORT          0x20
0029 #define REPORT_ID_DJ_LONG           0x21
0030 
0031 #define REPORT_ID_HIDPP_SHORT           0x10
0032 #define REPORT_ID_HIDPP_LONG            0x11
0033 #define REPORT_ID_HIDPP_VERY_LONG       0x12
0034 
0035 #define HIDPP_REPORT_SHORT_LENGTH       7
0036 #define HIDPP_REPORT_LONG_LENGTH        20
0037 
0038 #define HIDPP_RECEIVER_INDEX            0xff
0039 
0040 #define REPORT_TYPE_RFREPORT_FIRST      0x01
0041 #define REPORT_TYPE_RFREPORT_LAST       0x1F
0042 
0043 /* Command Switch to DJ mode */
0044 #define REPORT_TYPE_CMD_SWITCH          0x80
0045 #define CMD_SWITCH_PARAM_DEVBITFIELD        0x00
0046 #define CMD_SWITCH_PARAM_TIMEOUT_SECONDS    0x01
0047 #define TIMEOUT_NO_KEEPALIVE            0x00
0048 
0049 /* Command to Get the list of Paired devices */
0050 #define REPORT_TYPE_CMD_GET_PAIRED_DEVICES  0x81
0051 
0052 /* Device Paired Notification */
0053 #define REPORT_TYPE_NOTIF_DEVICE_PAIRED     0x41
0054 #define SPFUNCTION_MORE_NOTIF_EXPECTED      0x01
0055 #define SPFUNCTION_DEVICE_LIST_EMPTY        0x02
0056 #define DEVICE_PAIRED_PARAM_SPFUNCTION      0x00
0057 #define DEVICE_PAIRED_PARAM_EQUAD_ID_LSB    0x01
0058 #define DEVICE_PAIRED_PARAM_EQUAD_ID_MSB    0x02
0059 #define DEVICE_PAIRED_RF_REPORT_TYPE        0x03
0060 
0061 /* Device Un-Paired Notification */
0062 #define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED   0x40
0063 
0064 /* Connection Status Notification */
0065 #define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42
0066 #define CONNECTION_STATUS_PARAM_STATUS      0x00
0067 #define STATUS_LINKLOSS             0x01
0068 
0069 /* Error Notification */
0070 #define REPORT_TYPE_NOTIF_ERROR         0x7F
0071 #define NOTIF_ERROR_PARAM_ETYPE         0x00
0072 #define ETYPE_KEEPALIVE_TIMEOUT         0x01
0073 
0074 /* supported DJ HID && RF report types */
0075 #define REPORT_TYPE_KEYBOARD            0x01
0076 #define REPORT_TYPE_MOUSE           0x02
0077 #define REPORT_TYPE_CONSUMER_CONTROL        0x03
0078 #define REPORT_TYPE_SYSTEM_CONTROL      0x04
0079 #define REPORT_TYPE_MEDIA_CENTER        0x08
0080 #define REPORT_TYPE_LEDS            0x0E
0081 
0082 /* RF Report types bitfield */
0083 #define STD_KEYBOARD                BIT(1)
0084 #define STD_MOUSE               BIT(2)
0085 #define MULTIMEDIA              BIT(3)
0086 #define POWER_KEYS              BIT(4)
0087 #define KBD_MOUSE               BIT(5)
0088 #define MEDIA_CENTER                BIT(8)
0089 #define KBD_LEDS                BIT(14)
0090 /* Fake (bitnr > NUMBER_OF_HID_REPORTS) bit to track HID++ capability */
0091 #define HIDPP                   BIT_ULL(63)
0092 
0093 /* HID++ Device Connected Notification */
0094 #define REPORT_TYPE_NOTIF_DEVICE_CONNECTED  0x41
0095 #define HIDPP_PARAM_PROTO_TYPE          0x00
0096 #define HIDPP_PARAM_DEVICE_INFO         0x01
0097 #define HIDPP_PARAM_EQUAD_LSB           0x02
0098 #define HIDPP_PARAM_EQUAD_MSB           0x03
0099 #define HIDPP_PARAM_27MHZ_DEVID         0x03
0100 #define HIDPP_DEVICE_TYPE_MASK          GENMASK(3, 0)
0101 #define HIDPP_LINK_STATUS_MASK          BIT(6)
0102 #define HIDPP_MANUFACTURER_MASK         BIT(7)
0103 #define HIDPP_27MHZ_SECURE_MASK         BIT(7)
0104 
0105 #define HIDPP_DEVICE_TYPE_KEYBOARD      1
0106 #define HIDPP_DEVICE_TYPE_MOUSE         2
0107 
0108 #define HIDPP_SET_REGISTER          0x80
0109 #define HIDPP_GET_LONG_REGISTER         0x83
0110 #define HIDPP_REG_CONNECTION_STATE      0x02
0111 #define HIDPP_REG_PAIRING_INFORMATION       0xB5
0112 #define HIDPP_PAIRING_INFORMATION       0x20
0113 #define HIDPP_FAKE_DEVICE_ARRIVAL       0x02
0114 
0115 enum recvr_type {
0116     recvr_type_dj,
0117     recvr_type_hidpp,
0118     recvr_type_gaming_hidpp,
0119     recvr_type_mouse_only,
0120     recvr_type_27mhz,
0121     recvr_type_bluetooth,
0122     recvr_type_dinovo,
0123 };
0124 
0125 struct dj_report {
0126     u8 report_id;
0127     u8 device_index;
0128     u8 report_type;
0129     u8 report_params[DJREPORT_SHORT_LENGTH - 3];
0130 };
0131 
0132 struct hidpp_event {
0133     u8 report_id;
0134     u8 device_index;
0135     u8 sub_id;
0136     u8 params[HIDPP_REPORT_LONG_LENGTH - 3U];
0137 } __packed;
0138 
0139 struct dj_receiver_dev {
0140     struct hid_device *mouse;
0141     struct hid_device *keyboard;
0142     struct hid_device *hidpp;
0143     struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES +
0144                         DJ_DEVICE_INDEX_MIN];
0145     struct list_head list;
0146     struct kref kref;
0147     struct work_struct work;
0148     struct kfifo notif_fifo;
0149     unsigned long last_query; /* in jiffies */
0150     bool ready;
0151     enum recvr_type type;
0152     unsigned int unnumbered_application;
0153     spinlock_t lock;
0154 };
0155 
0156 struct dj_device {
0157     struct hid_device *hdev;
0158     struct dj_receiver_dev *dj_receiver_dev;
0159     u64 reports_supported;
0160     u8 device_index;
0161 };
0162 
0163 #define WORKITEM_TYPE_EMPTY 0
0164 #define WORKITEM_TYPE_PAIRED    1
0165 #define WORKITEM_TYPE_UNPAIRED  2
0166 #define WORKITEM_TYPE_UNKNOWN   255
0167 
0168 struct dj_workitem {
0169     u8 type;        /* WORKITEM_TYPE_* */
0170     u8 device_index;
0171     u8 device_type;
0172     u8 quad_id_msb;
0173     u8 quad_id_lsb;
0174     u64 reports_supported;
0175 };
0176 
0177 /* Keyboard descriptor (1) */
0178 static const char kbd_descriptor[] = {
0179     0x05, 0x01,     /* USAGE_PAGE (generic Desktop)     */
0180     0x09, 0x06,     /* USAGE (Keyboard)         */
0181     0xA1, 0x01,     /* COLLECTION (Application)     */
0182     0x85, 0x01,     /* REPORT_ID (1)            */
0183     0x95, 0x08,     /*   REPORT_COUNT (8)           */
0184     0x75, 0x01,     /*   REPORT_SIZE (1)            */
0185     0x15, 0x00,     /*   LOGICAL_MINIMUM (0)        */
0186     0x25, 0x01,     /*   LOGICAL_MAXIMUM (1)        */
0187     0x05, 0x07,     /*   USAGE_PAGE (Keyboard)      */
0188     0x19, 0xE0,     /*   USAGE_MINIMUM (Left Control)   */
0189     0x29, 0xE7,     /*   USAGE_MAXIMUM (Right GUI)      */
0190     0x81, 0x02,     /*   INPUT (Data,Var,Abs)       */
0191     0x95, 0x06,     /*   REPORT_COUNT (6)           */
0192     0x75, 0x08,     /*   REPORT_SIZE (8)            */
0193     0x15, 0x00,     /*   LOGICAL_MINIMUM (0)        */
0194     0x26, 0xFF, 0x00,   /*   LOGICAL_MAXIMUM (255)      */
0195     0x05, 0x07,     /*   USAGE_PAGE (Keyboard)      */
0196     0x19, 0x00,     /*   USAGE_MINIMUM (no event)       */
0197     0x2A, 0xFF, 0x00,   /*   USAGE_MAXIMUM (reserved)       */
0198     0x81, 0x00,     /*   INPUT (Data,Ary,Abs)       */
0199     0x85, 0x0e,     /* REPORT_ID (14)               */
0200     0x05, 0x08,     /*   USAGE PAGE (LED page)      */
0201     0x95, 0x05,     /*   REPORT COUNT (5)           */
0202     0x75, 0x01,     /*   REPORT SIZE (1)            */
0203     0x15, 0x00,     /*   LOGICAL_MINIMUM (0)        */
0204     0x25, 0x01,     /*   LOGICAL_MAXIMUM (1)        */
0205     0x19, 0x01,     /*   USAGE MINIMUM (1)          */
0206     0x29, 0x05,     /*   USAGE MAXIMUM (5)          */
0207     0x91, 0x02,     /*   OUTPUT (Data, Variable, Absolute)  */
0208     0x95, 0x01,     /*   REPORT COUNT (1)           */
0209     0x75, 0x03,     /*   REPORT SIZE (3)            */
0210     0x91, 0x01,     /*   OUTPUT (Constant)          */
0211     0xC0
0212 };
0213 
0214 /* Mouse descriptor (2)     */
0215 static const char mse_descriptor[] = {
0216     0x05, 0x01,     /*  USAGE_PAGE (Generic Desktop)        */
0217     0x09, 0x02,     /*  USAGE (Mouse)                       */
0218     0xA1, 0x01,     /*  COLLECTION (Application)            */
0219     0x85, 0x02,     /*    REPORT_ID = 2                     */
0220     0x09, 0x01,     /*    USAGE (pointer)                   */
0221     0xA1, 0x00,     /*    COLLECTION (physical)             */
0222     0x05, 0x09,     /*      USAGE_PAGE (buttons)            */
0223     0x19, 0x01,     /*      USAGE_MIN (1)                   */
0224     0x29, 0x10,     /*      USAGE_MAX (16)                  */
0225     0x15, 0x00,     /*      LOGICAL_MIN (0)                 */
0226     0x25, 0x01,     /*      LOGICAL_MAX (1)                 */
0227     0x95, 0x10,     /*      REPORT_COUNT (16)               */
0228     0x75, 0x01,     /*      REPORT_SIZE (1)                 */
0229     0x81, 0x02,     /*      INPUT (data var abs)            */
0230     0x05, 0x01,     /*      USAGE_PAGE (generic desktop)    */
0231     0x16, 0x01, 0xF8,   /*      LOGICAL_MIN (-2047)             */
0232     0x26, 0xFF, 0x07,   /*      LOGICAL_MAX (2047)              */
0233     0x75, 0x0C,     /*      REPORT_SIZE (12)                */
0234     0x95, 0x02,     /*      REPORT_COUNT (2)                */
0235     0x09, 0x30,     /*      USAGE (X)                       */
0236     0x09, 0x31,     /*      USAGE (Y)                       */
0237     0x81, 0x06,     /*      INPUT                           */
0238     0x15, 0x81,     /*      LOGICAL_MIN (-127)              */
0239     0x25, 0x7F,     /*      LOGICAL_MAX (127)               */
0240     0x75, 0x08,     /*      REPORT_SIZE (8)                 */
0241     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0242     0x09, 0x38,     /*      USAGE (wheel)                   */
0243     0x81, 0x06,     /*      INPUT                           */
0244     0x05, 0x0C,     /*      USAGE_PAGE(consumer)            */
0245     0x0A, 0x38, 0x02,   /*      USAGE(AC Pan)                   */
0246     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0247     0x81, 0x06,     /*      INPUT                           */
0248     0xC0,           /*    END_COLLECTION                    */
0249     0xC0,           /*  END_COLLECTION                      */
0250 };
0251 
0252 /* Mouse descriptor (2) for 27 MHz receiver, only 8 buttons */
0253 static const char mse_27mhz_descriptor[] = {
0254     0x05, 0x01,     /*  USAGE_PAGE (Generic Desktop)        */
0255     0x09, 0x02,     /*  USAGE (Mouse)                       */
0256     0xA1, 0x01,     /*  COLLECTION (Application)            */
0257     0x85, 0x02,     /*    REPORT_ID = 2                     */
0258     0x09, 0x01,     /*    USAGE (pointer)                   */
0259     0xA1, 0x00,     /*    COLLECTION (physical)             */
0260     0x05, 0x09,     /*      USAGE_PAGE (buttons)            */
0261     0x19, 0x01,     /*      USAGE_MIN (1)                   */
0262     0x29, 0x08,     /*      USAGE_MAX (8)                   */
0263     0x15, 0x00,     /*      LOGICAL_MIN (0)                 */
0264     0x25, 0x01,     /*      LOGICAL_MAX (1)                 */
0265     0x95, 0x08,     /*      REPORT_COUNT (8)                */
0266     0x75, 0x01,     /*      REPORT_SIZE (1)                 */
0267     0x81, 0x02,     /*      INPUT (data var abs)            */
0268     0x05, 0x01,     /*      USAGE_PAGE (generic desktop)    */
0269     0x16, 0x01, 0xF8,   /*      LOGICAL_MIN (-2047)             */
0270     0x26, 0xFF, 0x07,   /*      LOGICAL_MAX (2047)              */
0271     0x75, 0x0C,     /*      REPORT_SIZE (12)                */
0272     0x95, 0x02,     /*      REPORT_COUNT (2)                */
0273     0x09, 0x30,     /*      USAGE (X)                       */
0274     0x09, 0x31,     /*      USAGE (Y)                       */
0275     0x81, 0x06,     /*      INPUT                           */
0276     0x15, 0x81,     /*      LOGICAL_MIN (-127)              */
0277     0x25, 0x7F,     /*      LOGICAL_MAX (127)               */
0278     0x75, 0x08,     /*      REPORT_SIZE (8)                 */
0279     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0280     0x09, 0x38,     /*      USAGE (wheel)                   */
0281     0x81, 0x06,     /*      INPUT                           */
0282     0x05, 0x0C,     /*      USAGE_PAGE(consumer)            */
0283     0x0A, 0x38, 0x02,   /*      USAGE(AC Pan)                   */
0284     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0285     0x81, 0x06,     /*      INPUT                           */
0286     0xC0,           /*    END_COLLECTION                    */
0287     0xC0,           /*  END_COLLECTION                      */
0288 };
0289 
0290 /* Mouse descriptor (2) for Bluetooth receiver, low-res hwheel, 12 buttons */
0291 static const char mse_bluetooth_descriptor[] = {
0292     0x05, 0x01,     /*  USAGE_PAGE (Generic Desktop)        */
0293     0x09, 0x02,     /*  USAGE (Mouse)                       */
0294     0xA1, 0x01,     /*  COLLECTION (Application)            */
0295     0x85, 0x02,     /*    REPORT_ID = 2                     */
0296     0x09, 0x01,     /*    USAGE (pointer)                   */
0297     0xA1, 0x00,     /*    COLLECTION (physical)             */
0298     0x05, 0x09,     /*      USAGE_PAGE (buttons)            */
0299     0x19, 0x01,     /*      USAGE_MIN (1)                   */
0300     0x29, 0x08,     /*      USAGE_MAX (8)                   */
0301     0x15, 0x00,     /*      LOGICAL_MIN (0)                 */
0302     0x25, 0x01,     /*      LOGICAL_MAX (1)                 */
0303     0x95, 0x08,     /*      REPORT_COUNT (8)                */
0304     0x75, 0x01,     /*      REPORT_SIZE (1)                 */
0305     0x81, 0x02,     /*      INPUT (data var abs)            */
0306     0x05, 0x01,     /*      USAGE_PAGE (generic desktop)    */
0307     0x16, 0x01, 0xF8,   /*      LOGICAL_MIN (-2047)             */
0308     0x26, 0xFF, 0x07,   /*      LOGICAL_MAX (2047)              */
0309     0x75, 0x0C,     /*      REPORT_SIZE (12)                */
0310     0x95, 0x02,     /*      REPORT_COUNT (2)                */
0311     0x09, 0x30,     /*      USAGE (X)                       */
0312     0x09, 0x31,     /*      USAGE (Y)                       */
0313     0x81, 0x06,     /*      INPUT                           */
0314     0x15, 0x81,     /*      LOGICAL_MIN (-127)              */
0315     0x25, 0x7F,     /*      LOGICAL_MAX (127)               */
0316     0x75, 0x08,     /*      REPORT_SIZE (8)                 */
0317     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0318     0x09, 0x38,     /*      USAGE (wheel)                   */
0319     0x81, 0x06,     /*      INPUT                           */
0320     0x05, 0x0C,     /*      USAGE_PAGE(consumer)            */
0321     0x0A, 0x38, 0x02,   /*      USAGE(AC Pan)                   */
0322     0x15, 0xF9,     /*      LOGICAL_MIN (-7)                */
0323     0x25, 0x07,     /*      LOGICAL_MAX (7)                 */
0324     0x75, 0x04,     /*      REPORT_SIZE (4)                 */
0325     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0326     0x81, 0x06,     /*      INPUT                           */
0327     0x05, 0x09,     /*      USAGE_PAGE (buttons)            */
0328     0x19, 0x09,     /*      USAGE_MIN (9)                   */
0329     0x29, 0x0C,     /*      USAGE_MAX (12)                  */
0330     0x15, 0x00,     /*      LOGICAL_MIN (0)                 */
0331     0x25, 0x01,     /*      LOGICAL_MAX (1)                 */
0332     0x75, 0x01,     /*      REPORT_SIZE (1)                 */
0333     0x95, 0x04,     /*      REPORT_COUNT (4)                */
0334     0x81, 0x02,     /*      INPUT (Data,Var,Abs)            */
0335     0xC0,           /*    END_COLLECTION                    */
0336     0xC0,           /*  END_COLLECTION                      */
0337 };
0338 
0339 /* Mouse descriptor (5) for Bluetooth receiver, normal-res hwheel, 8 buttons */
0340 static const char mse5_bluetooth_descriptor[] = {
0341     0x05, 0x01,     /*  USAGE_PAGE (Generic Desktop)        */
0342     0x09, 0x02,     /*  Usage (Mouse)                       */
0343     0xa1, 0x01,     /*  Collection (Application)            */
0344     0x85, 0x05,     /*   Report ID (5)                      */
0345     0x09, 0x01,     /*   Usage (Pointer)                    */
0346     0xa1, 0x00,     /*   Collection (Physical)              */
0347     0x05, 0x09,     /*    Usage Page (Button)               */
0348     0x19, 0x01,     /*    Usage Minimum (1)                 */
0349     0x29, 0x08,     /*    Usage Maximum (8)                 */
0350     0x15, 0x00,     /*    Logical Minimum (0)               */
0351     0x25, 0x01,     /*    Logical Maximum (1)               */
0352     0x95, 0x08,     /*    Report Count (8)                  */
0353     0x75, 0x01,     /*    Report Size (1)                   */
0354     0x81, 0x02,     /*    Input (Data,Var,Abs)              */
0355     0x05, 0x01,     /*    Usage Page (Generic Desktop)      */
0356     0x16, 0x01, 0xf8,   /*    Logical Minimum (-2047)           */
0357     0x26, 0xff, 0x07,   /*    Logical Maximum (2047)            */
0358     0x75, 0x0c,     /*    Report Size (12)                  */
0359     0x95, 0x02,     /*    Report Count (2)                  */
0360     0x09, 0x30,     /*    Usage (X)                         */
0361     0x09, 0x31,     /*    Usage (Y)                         */
0362     0x81, 0x06,     /*    Input (Data,Var,Rel)              */
0363     0x15, 0x81,     /*    Logical Minimum (-127)            */
0364     0x25, 0x7f,     /*    Logical Maximum (127)             */
0365     0x75, 0x08,     /*    Report Size (8)                   */
0366     0x95, 0x01,     /*    Report Count (1)                  */
0367     0x09, 0x38,     /*    Usage (Wheel)                     */
0368     0x81, 0x06,     /*    Input (Data,Var,Rel)              */
0369     0x05, 0x0c,     /*    Usage Page (Consumer Devices)     */
0370     0x0a, 0x38, 0x02,   /*    Usage (AC Pan)                    */
0371     0x15, 0x81,     /*    Logical Minimum (-127)            */
0372     0x25, 0x7f,     /*    Logical Maximum (127)             */
0373     0x75, 0x08,     /*    Report Size (8)                   */
0374     0x95, 0x01,     /*    Report Count (1)                  */
0375     0x81, 0x06,     /*    Input (Data,Var,Rel)              */
0376     0xc0,           /*   End Collection                     */
0377     0xc0,           /*  End Collection                      */
0378 };
0379 
0380 /* Gaming Mouse descriptor (2) */
0381 static const char mse_high_res_descriptor[] = {
0382     0x05, 0x01,     /*  USAGE_PAGE (Generic Desktop)        */
0383     0x09, 0x02,     /*  USAGE (Mouse)                       */
0384     0xA1, 0x01,     /*  COLLECTION (Application)            */
0385     0x85, 0x02,     /*    REPORT_ID = 2                     */
0386     0x09, 0x01,     /*    USAGE (pointer)                   */
0387     0xA1, 0x00,     /*    COLLECTION (physical)             */
0388     0x05, 0x09,     /*      USAGE_PAGE (buttons)            */
0389     0x19, 0x01,     /*      USAGE_MIN (1)                   */
0390     0x29, 0x10,     /*      USAGE_MAX (16)                  */
0391     0x15, 0x00,     /*      LOGICAL_MIN (0)                 */
0392     0x25, 0x01,     /*      LOGICAL_MAX (1)                 */
0393     0x95, 0x10,     /*      REPORT_COUNT (16)               */
0394     0x75, 0x01,     /*      REPORT_SIZE (1)                 */
0395     0x81, 0x02,     /*      INPUT (data var abs)            */
0396     0x05, 0x01,     /*      USAGE_PAGE (generic desktop)    */
0397     0x16, 0x01, 0x80,   /*      LOGICAL_MIN (-32767)            */
0398     0x26, 0xFF, 0x7F,   /*      LOGICAL_MAX (32767)             */
0399     0x75, 0x10,     /*      REPORT_SIZE (16)                */
0400     0x95, 0x02,     /*      REPORT_COUNT (2)                */
0401     0x09, 0x30,     /*      USAGE (X)                       */
0402     0x09, 0x31,     /*      USAGE (Y)                       */
0403     0x81, 0x06,     /*      INPUT                           */
0404     0x15, 0x81,     /*      LOGICAL_MIN (-127)              */
0405     0x25, 0x7F,     /*      LOGICAL_MAX (127)               */
0406     0x75, 0x08,     /*      REPORT_SIZE (8)                 */
0407     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0408     0x09, 0x38,     /*      USAGE (wheel)                   */
0409     0x81, 0x06,     /*      INPUT                           */
0410     0x05, 0x0C,     /*      USAGE_PAGE(consumer)            */
0411     0x0A, 0x38, 0x02,   /*      USAGE(AC Pan)                   */
0412     0x95, 0x01,     /*      REPORT_COUNT (1)                */
0413     0x81, 0x06,     /*      INPUT                           */
0414     0xC0,           /*    END_COLLECTION                    */
0415     0xC0,           /*  END_COLLECTION                      */
0416 };
0417 
0418 /* Consumer Control descriptor (3) */
0419 static const char consumer_descriptor[] = {
0420     0x05, 0x0C,     /* USAGE_PAGE (Consumer Devices)       */
0421     0x09, 0x01,     /* USAGE (Consumer Control)            */
0422     0xA1, 0x01,     /* COLLECTION (Application)            */
0423     0x85, 0x03,     /* REPORT_ID = 3                       */
0424     0x75, 0x10,     /* REPORT_SIZE (16)                    */
0425     0x95, 0x02,     /* REPORT_COUNT (2)                    */
0426     0x15, 0x01,     /* LOGICAL_MIN (1)                     */
0427     0x26, 0xFF, 0x02,   /* LOGICAL_MAX (767)                   */
0428     0x19, 0x01,     /* USAGE_MIN (1)                       */
0429     0x2A, 0xFF, 0x02,   /* USAGE_MAX (767)                     */
0430     0x81, 0x00,     /* INPUT (Data Ary Abs)                */
0431     0xC0,           /* END_COLLECTION                      */
0432 };              /*                                     */
0433 
0434 /* System control descriptor (4) */
0435 static const char syscontrol_descriptor[] = {
0436     0x05, 0x01,     /*   USAGE_PAGE (Generic Desktop)      */
0437     0x09, 0x80,     /*   USAGE (System Control)            */
0438     0xA1, 0x01,     /*   COLLECTION (Application)          */
0439     0x85, 0x04,     /*   REPORT_ID = 4                     */
0440     0x75, 0x02,     /*   REPORT_SIZE (2)                   */
0441     0x95, 0x01,     /*   REPORT_COUNT (1)                  */
0442     0x15, 0x01,     /*   LOGICAL_MIN (1)                   */
0443     0x25, 0x03,     /*   LOGICAL_MAX (3)                   */
0444     0x09, 0x82,     /*   USAGE (System Sleep)              */
0445     0x09, 0x81,     /*   USAGE (System Power Down)         */
0446     0x09, 0x83,     /*   USAGE (System Wake Up)            */
0447     0x81, 0x60,     /*   INPUT (Data Ary Abs NPrf Null)    */
0448     0x75, 0x06,     /*   REPORT_SIZE (6)                   */
0449     0x81, 0x03,     /*   INPUT (Cnst Var Abs)              */
0450     0xC0,           /*   END_COLLECTION                    */
0451 };
0452 
0453 /* Media descriptor (8) */
0454 static const char media_descriptor[] = {
0455     0x06, 0xbc, 0xff,   /* Usage Page 0xffbc                   */
0456     0x09, 0x88,     /* Usage 0x0088                        */
0457     0xa1, 0x01,     /* BeginCollection                     */
0458     0x85, 0x08,     /*   Report ID 8                       */
0459     0x19, 0x01,     /*   Usage Min 0x0001                  */
0460     0x29, 0xff,     /*   Usage Max 0x00ff                  */
0461     0x15, 0x01,     /*   Logical Min 1                     */
0462     0x26, 0xff, 0x00,   /*   Logical Max 255                   */
0463     0x75, 0x08,     /*   Report Size 8                     */
0464     0x95, 0x01,     /*   Report Count 1                    */
0465     0x81, 0x00,     /*   Input                             */
0466     0xc0,           /* EndCollection                       */
0467 };              /*                                     */
0468 
0469 /* HIDPP descriptor */
0470 static const char hidpp_descriptor[] = {
0471     0x06, 0x00, 0xff,   /* Usage Page (Vendor Defined Page 1)  */
0472     0x09, 0x01,     /* Usage (Vendor Usage 1)              */
0473     0xa1, 0x01,     /* Collection (Application)            */
0474     0x85, 0x10,     /*   Report ID (16)                    */
0475     0x75, 0x08,     /*   Report Size (8)                   */
0476     0x95, 0x06,     /*   Report Count (6)                  */
0477     0x15, 0x00,     /*   Logical Minimum (0)               */
0478     0x26, 0xff, 0x00,   /*   Logical Maximum (255)             */
0479     0x09, 0x01,     /*   Usage (Vendor Usage 1)            */
0480     0x81, 0x00,     /*   Input (Data,Arr,Abs)              */
0481     0x09, 0x01,     /*   Usage (Vendor Usage 1)            */
0482     0x91, 0x00,     /*   Output (Data,Arr,Abs)             */
0483     0xc0,           /* End Collection                      */
0484     0x06, 0x00, 0xff,   /* Usage Page (Vendor Defined Page 1)  */
0485     0x09, 0x02,     /* Usage (Vendor Usage 2)              */
0486     0xa1, 0x01,     /* Collection (Application)            */
0487     0x85, 0x11,     /*   Report ID (17)                    */
0488     0x75, 0x08,     /*   Report Size (8)                   */
0489     0x95, 0x13,     /*   Report Count (19)                 */
0490     0x15, 0x00,     /*   Logical Minimum (0)               */
0491     0x26, 0xff, 0x00,   /*   Logical Maximum (255)             */
0492     0x09, 0x02,     /*   Usage (Vendor Usage 2)            */
0493     0x81, 0x00,     /*   Input (Data,Arr,Abs)              */
0494     0x09, 0x02,     /*   Usage (Vendor Usage 2)            */
0495     0x91, 0x00,     /*   Output (Data,Arr,Abs)             */
0496     0xc0,           /* End Collection                      */
0497     0x06, 0x00, 0xff,   /* Usage Page (Vendor Defined Page 1)  */
0498     0x09, 0x04,     /* Usage (Vendor Usage 0x04)           */
0499     0xa1, 0x01,     /* Collection (Application)            */
0500     0x85, 0x20,     /*   Report ID (32)                    */
0501     0x75, 0x08,     /*   Report Size (8)                   */
0502     0x95, 0x0e,     /*   Report Count (14)                 */
0503     0x15, 0x00,     /*   Logical Minimum (0)               */
0504     0x26, 0xff, 0x00,   /*   Logical Maximum (255)             */
0505     0x09, 0x41,     /*   Usage (Vendor Usage 0x41)         */
0506     0x81, 0x00,     /*   Input (Data,Arr,Abs)              */
0507     0x09, 0x41,     /*   Usage (Vendor Usage 0x41)         */
0508     0x91, 0x00,     /*   Output (Data,Arr,Abs)             */
0509     0x85, 0x21,     /*   Report ID (33)                    */
0510     0x95, 0x1f,     /*   Report Count (31)                 */
0511     0x15, 0x00,     /*   Logical Minimum (0)               */
0512     0x26, 0xff, 0x00,   /*   Logical Maximum (255)             */
0513     0x09, 0x42,     /*   Usage (Vendor Usage 0x42)         */
0514     0x81, 0x00,     /*   Input (Data,Arr,Abs)              */
0515     0x09, 0x42,     /*   Usage (Vendor Usage 0x42)         */
0516     0x91, 0x00,     /*   Output (Data,Arr,Abs)             */
0517     0xc0,           /* End Collection                      */
0518 };
0519 
0520 /* Maximum size of all defined hid reports in bytes (including report id) */
0521 #define MAX_REPORT_SIZE 8
0522 
0523 /* Make sure all descriptors are present here */
0524 #define MAX_RDESC_SIZE              \
0525     (sizeof(kbd_descriptor) +       \
0526      sizeof(mse_bluetooth_descriptor) + \
0527      sizeof(mse5_bluetooth_descriptor) +    \
0528      sizeof(consumer_descriptor) +      \
0529      sizeof(syscontrol_descriptor) +    \
0530      sizeof(media_descriptor) + \
0531      sizeof(hidpp_descriptor))
0532 
0533 /* Number of possible hid report types that can be created by this driver.
0534  *
0535  * Right now, RF report types have the same report types (or report id's)
0536  * than the hid report created from those RF reports. In the future
0537  * this doesnt have to be true.
0538  *
0539  * For instance, RF report type 0x01 which has a size of 8 bytes, corresponds
0540  * to hid report id 0x01, this is standard keyboard. Same thing applies to mice
0541  * reports and consumer control, etc. If a new RF report is created, it doesn't
0542  * has to have the same report id as its corresponding hid report, so an
0543  * translation may have to take place for future report types.
0544  */
0545 #define NUMBER_OF_HID_REPORTS 32
0546 static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = {
0547     [1] = 8,        /* Standard keyboard */
0548     [2] = 8,        /* Standard mouse */
0549     [3] = 5,        /* Consumer control */
0550     [4] = 2,        /* System control */
0551     [8] = 2,        /* Media Center */
0552 };
0553 
0554 
0555 #define LOGITECH_DJ_INTERFACE_NUMBER 0x02
0556 
0557 static struct hid_ll_driver logi_dj_ll_driver;
0558 
0559 static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);
0560 static void delayedwork_callback(struct work_struct *work);
0561 
0562 static LIST_HEAD(dj_hdev_list);
0563 static DEFINE_MUTEX(dj_hdev_list_lock);
0564 
0565 static bool recvr_type_is_bluetooth(enum recvr_type type)
0566 {
0567     return type == recvr_type_bluetooth || type == recvr_type_dinovo;
0568 }
0569 
0570 /*
0571  * dj/HID++ receivers are really a single logical entity, but for BIOS/Windows
0572  * compatibility they have multiple USB interfaces. On HID++ receivers we need
0573  * to listen for input reports on both interfaces. The functions below are used
0574  * to create a single struct dj_receiver_dev for all interfaces belonging to
0575  * a single USB-device / receiver.
0576  */
0577 static struct dj_receiver_dev *dj_find_receiver_dev(struct hid_device *hdev,
0578                             enum recvr_type type)
0579 {
0580     struct dj_receiver_dev *djrcv_dev;
0581     char sep;
0582 
0583     /*
0584      * The bluetooth receiver contains a built-in hub and has separate
0585      * USB-devices for the keyboard and mouse interfaces.
0586      */
0587     sep = recvr_type_is_bluetooth(type) ? '.' : '/';
0588 
0589     /* Try to find an already-probed interface from the same device */
0590     list_for_each_entry(djrcv_dev, &dj_hdev_list, list) {
0591         if (djrcv_dev->mouse &&
0592             hid_compare_device_paths(hdev, djrcv_dev->mouse, sep)) {
0593             kref_get(&djrcv_dev->kref);
0594             return djrcv_dev;
0595         }
0596         if (djrcv_dev->keyboard &&
0597             hid_compare_device_paths(hdev, djrcv_dev->keyboard, sep)) {
0598             kref_get(&djrcv_dev->kref);
0599             return djrcv_dev;
0600         }
0601         if (djrcv_dev->hidpp &&
0602             hid_compare_device_paths(hdev, djrcv_dev->hidpp, sep)) {
0603             kref_get(&djrcv_dev->kref);
0604             return djrcv_dev;
0605         }
0606     }
0607 
0608     return NULL;
0609 }
0610 
0611 static void dj_release_receiver_dev(struct kref *kref)
0612 {
0613     struct dj_receiver_dev *djrcv_dev = container_of(kref, struct dj_receiver_dev, kref);
0614 
0615     list_del(&djrcv_dev->list);
0616     kfifo_free(&djrcv_dev->notif_fifo);
0617     kfree(djrcv_dev);
0618 }
0619 
0620 static void dj_put_receiver_dev(struct hid_device *hdev)
0621 {
0622     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
0623 
0624     mutex_lock(&dj_hdev_list_lock);
0625 
0626     if (djrcv_dev->mouse == hdev)
0627         djrcv_dev->mouse = NULL;
0628     if (djrcv_dev->keyboard == hdev)
0629         djrcv_dev->keyboard = NULL;
0630     if (djrcv_dev->hidpp == hdev)
0631         djrcv_dev->hidpp = NULL;
0632 
0633     kref_put(&djrcv_dev->kref, dj_release_receiver_dev);
0634 
0635     mutex_unlock(&dj_hdev_list_lock);
0636 }
0637 
0638 static struct dj_receiver_dev *dj_get_receiver_dev(struct hid_device *hdev,
0639                            enum recvr_type type,
0640                            unsigned int application,
0641                            bool is_hidpp)
0642 {
0643     struct dj_receiver_dev *djrcv_dev;
0644 
0645     mutex_lock(&dj_hdev_list_lock);
0646 
0647     djrcv_dev = dj_find_receiver_dev(hdev, type);
0648     if (!djrcv_dev) {
0649         djrcv_dev = kzalloc(sizeof(*djrcv_dev), GFP_KERNEL);
0650         if (!djrcv_dev)
0651             goto out;
0652 
0653         INIT_WORK(&djrcv_dev->work, delayedwork_callback);
0654         spin_lock_init(&djrcv_dev->lock);
0655         if (kfifo_alloc(&djrcv_dev->notif_fifo,
0656                 DJ_MAX_NUMBER_NOTIFS * sizeof(struct dj_workitem),
0657                 GFP_KERNEL)) {
0658             kfree(djrcv_dev);
0659             djrcv_dev = NULL;
0660             goto out;
0661         }
0662         kref_init(&djrcv_dev->kref);
0663         list_add_tail(&djrcv_dev->list, &dj_hdev_list);
0664         djrcv_dev->last_query = jiffies;
0665         djrcv_dev->type = type;
0666     }
0667 
0668     if (application == HID_GD_KEYBOARD)
0669         djrcv_dev->keyboard = hdev;
0670     if (application == HID_GD_MOUSE)
0671         djrcv_dev->mouse = hdev;
0672     if (is_hidpp)
0673         djrcv_dev->hidpp = hdev;
0674 
0675     hid_set_drvdata(hdev, djrcv_dev);
0676 out:
0677     mutex_unlock(&dj_hdev_list_lock);
0678     return djrcv_dev;
0679 }
0680 
0681 static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev,
0682                           struct dj_workitem *workitem)
0683 {
0684     /* Called in delayed work context */
0685     struct dj_device *dj_dev;
0686     unsigned long flags;
0687 
0688     spin_lock_irqsave(&djrcv_dev->lock, flags);
0689     dj_dev = djrcv_dev->paired_dj_devices[workitem->device_index];
0690     djrcv_dev->paired_dj_devices[workitem->device_index] = NULL;
0691     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
0692 
0693     if (dj_dev != NULL) {
0694         hid_destroy_device(dj_dev->hdev);
0695         kfree(dj_dev);
0696     } else {
0697         hid_err(djrcv_dev->hidpp, "%s: can't destroy a NULL device\n",
0698             __func__);
0699     }
0700 }
0701 
0702 static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
0703                       struct dj_workitem *workitem)
0704 {
0705     /* Called in delayed work context */
0706     struct hid_device *djrcv_hdev = djrcv_dev->hidpp;
0707     struct hid_device *dj_hiddev;
0708     struct dj_device *dj_dev;
0709     u8 device_index = workitem->device_index;
0710     unsigned long flags;
0711 
0712     /* Device index goes from 1 to 6, we need 3 bytes to store the
0713      * semicolon, the index, and a null terminator
0714      */
0715     unsigned char tmpstr[3];
0716 
0717     /* We are the only one ever adding a device, no need to lock */
0718     if (djrcv_dev->paired_dj_devices[device_index]) {
0719         /* The device is already known. No need to reallocate it. */
0720         dbg_hid("%s: device is already known\n", __func__);
0721         return;
0722     }
0723 
0724     dj_hiddev = hid_allocate_device();
0725     if (IS_ERR(dj_hiddev)) {
0726         hid_err(djrcv_hdev, "%s: hid_allocate_dev failed\n", __func__);
0727         return;
0728     }
0729 
0730     dj_hiddev->ll_driver = &logi_dj_ll_driver;
0731 
0732     dj_hiddev->dev.parent = &djrcv_hdev->dev;
0733     dj_hiddev->bus = BUS_USB;
0734     dj_hiddev->vendor = djrcv_hdev->vendor;
0735     dj_hiddev->product = (workitem->quad_id_msb << 8) |
0736                   workitem->quad_id_lsb;
0737     if (workitem->device_type) {
0738         const char *type_str = "Device";
0739 
0740         switch (workitem->device_type) {
0741         case 0x01: type_str = "Keyboard";   break;
0742         case 0x02: type_str = "Mouse";      break;
0743         case 0x03: type_str = "Numpad";     break;
0744         case 0x04: type_str = "Presenter";  break;
0745         case 0x07: type_str = "Remote Control"; break;
0746         case 0x08: type_str = "Trackball";  break;
0747         case 0x09: type_str = "Touchpad";   break;
0748         }
0749         snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
0750             "Logitech Wireless %s PID:%04x",
0751             type_str, dj_hiddev->product);
0752     } else {
0753         snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
0754             "Logitech Wireless Device PID:%04x",
0755             dj_hiddev->product);
0756     }
0757 
0758     if (djrcv_dev->type == recvr_type_27mhz)
0759         dj_hiddev->group = HID_GROUP_LOGITECH_27MHZ_DEVICE;
0760     else
0761         dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE;
0762 
0763     memcpy(dj_hiddev->phys, djrcv_hdev->phys, sizeof(djrcv_hdev->phys));
0764     snprintf(tmpstr, sizeof(tmpstr), ":%d", device_index);
0765     strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys));
0766 
0767     dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL);
0768 
0769     if (!dj_dev) {
0770         hid_err(djrcv_hdev, "%s: failed allocating dj_dev\n", __func__);
0771         goto dj_device_allocate_fail;
0772     }
0773 
0774     dj_dev->reports_supported = workitem->reports_supported;
0775     dj_dev->hdev = dj_hiddev;
0776     dj_dev->dj_receiver_dev = djrcv_dev;
0777     dj_dev->device_index = device_index;
0778     dj_hiddev->driver_data = dj_dev;
0779 
0780     spin_lock_irqsave(&djrcv_dev->lock, flags);
0781     djrcv_dev->paired_dj_devices[device_index] = dj_dev;
0782     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
0783 
0784     if (hid_add_device(dj_hiddev)) {
0785         hid_err(djrcv_hdev, "%s: failed adding dj_device\n", __func__);
0786         goto hid_add_device_fail;
0787     }
0788 
0789     return;
0790 
0791 hid_add_device_fail:
0792     spin_lock_irqsave(&djrcv_dev->lock, flags);
0793     djrcv_dev->paired_dj_devices[device_index] = NULL;
0794     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
0795     kfree(dj_dev);
0796 dj_device_allocate_fail:
0797     hid_destroy_device(dj_hiddev);
0798 }
0799 
0800 static void delayedwork_callback(struct work_struct *work)
0801 {
0802     struct dj_receiver_dev *djrcv_dev =
0803         container_of(work, struct dj_receiver_dev, work);
0804 
0805     struct dj_workitem workitem;
0806     unsigned long flags;
0807     int count;
0808     int retval;
0809 
0810     dbg_hid("%s\n", __func__);
0811 
0812     spin_lock_irqsave(&djrcv_dev->lock, flags);
0813 
0814     /*
0815      * Since we attach to multiple interfaces, we may get scheduled before
0816      * we are bound to the HID++ interface, catch this.
0817      */
0818     if (!djrcv_dev->ready) {
0819         pr_warn("%s: delayedwork queued before hidpp interface was enumerated\n",
0820             __func__);
0821         spin_unlock_irqrestore(&djrcv_dev->lock, flags);
0822         return;
0823     }
0824 
0825     count = kfifo_out(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
0826 
0827     if (count != sizeof(workitem)) {
0828         spin_unlock_irqrestore(&djrcv_dev->lock, flags);
0829         return;
0830     }
0831 
0832     if (!kfifo_is_empty(&djrcv_dev->notif_fifo))
0833         schedule_work(&djrcv_dev->work);
0834 
0835     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
0836 
0837     switch (workitem.type) {
0838     case WORKITEM_TYPE_PAIRED:
0839         logi_dj_recv_add_djhid_device(djrcv_dev, &workitem);
0840         break;
0841     case WORKITEM_TYPE_UNPAIRED:
0842         logi_dj_recv_destroy_djhid_device(djrcv_dev, &workitem);
0843         break;
0844     case WORKITEM_TYPE_UNKNOWN:
0845         retval = logi_dj_recv_query_paired_devices(djrcv_dev);
0846         if (retval) {
0847             hid_err(djrcv_dev->hidpp, "%s: logi_dj_recv_query_paired_devices error: %d\n",
0848                 __func__, retval);
0849         }
0850         break;
0851     case WORKITEM_TYPE_EMPTY:
0852         dbg_hid("%s: device list is empty\n", __func__);
0853         break;
0854     }
0855 }
0856 
0857 /*
0858  * Sometimes we receive reports for which we do not have a paired dj_device
0859  * associated with the device_index or report-type to forward the report to.
0860  * This means that the original "device paired" notification corresponding
0861  * to the dj_device never arrived to this driver. Possible reasons for this are:
0862  * 1) hid-core discards all packets coming from a device during probe().
0863  * 2) if the receiver is plugged into a KVM switch then the pairing reports
0864  * are only forwarded to it if the focus is on this PC.
0865  * This function deals with this by re-asking the receiver for the list of
0866  * connected devices in the delayed work callback.
0867  * This function MUST be called with djrcv->lock held.
0868  */
0869 static void logi_dj_recv_queue_unknown_work(struct dj_receiver_dev *djrcv_dev)
0870 {
0871     struct dj_workitem workitem = { .type = WORKITEM_TYPE_UNKNOWN };
0872 
0873     /* Rate limit queries done because of unhandled reports to 2/sec */
0874     if (time_before(jiffies, djrcv_dev->last_query + HZ / 2))
0875         return;
0876 
0877     kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
0878     schedule_work(&djrcv_dev->work);
0879 }
0880 
0881 static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,
0882                        struct dj_report *dj_report)
0883 {
0884     /* We are called from atomic context (tasklet && djrcv->lock held) */
0885     struct dj_workitem workitem = {
0886         .device_index = dj_report->device_index,
0887     };
0888 
0889     switch (dj_report->report_type) {
0890     case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
0891         workitem.type = WORKITEM_TYPE_PAIRED;
0892         if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] &
0893             SPFUNCTION_DEVICE_LIST_EMPTY) {
0894             workitem.type = WORKITEM_TYPE_EMPTY;
0895             break;
0896         }
0897         fallthrough;
0898     case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
0899         workitem.quad_id_msb =
0900             dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB];
0901         workitem.quad_id_lsb =
0902             dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB];
0903         workitem.reports_supported = get_unaligned_le32(
0904                         dj_report->report_params +
0905                         DEVICE_PAIRED_RF_REPORT_TYPE);
0906         workitem.reports_supported |= HIDPP;
0907         if (dj_report->report_type == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED)
0908             workitem.type = WORKITEM_TYPE_UNPAIRED;
0909         break;
0910     default:
0911         logi_dj_recv_queue_unknown_work(djrcv_dev);
0912         return;
0913     }
0914 
0915     kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
0916     schedule_work(&djrcv_dev->work);
0917 }
0918 
0919 /*
0920  * Some quad/bluetooth keyboards have a builtin touchpad in this case we see
0921  * only 1 paired device with a device_type of REPORT_TYPE_KEYBOARD. For the
0922  * touchpad to work we must also forward mouse input reports to the dj_hiddev
0923  * created for the keyboard (instead of forwarding them to a second paired
0924  * device with a device_type of REPORT_TYPE_MOUSE as we normally would).
0925  *
0926  * On Dinovo receivers the keyboard's touchpad and an optional paired actual
0927  * mouse send separate input reports, INPUT(2) aka STD_MOUSE for the mouse
0928  * and INPUT(5) aka KBD_MOUSE for the keyboard's touchpad.
0929  *
0930  * On MX5x00 receivers (which can also be paired with a Dinovo keyboard)
0931  * INPUT(2) is used for both an optional paired actual mouse and for the
0932  * keyboard's touchpad.
0933  */
0934 static const u16 kbd_builtin_touchpad_ids[] = {
0935     0xb309, /* Dinovo Edge */
0936     0xb30c, /* Dinovo Mini */
0937 };
0938 
0939 static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev,
0940                         struct hidpp_event *hidpp_report,
0941                         struct dj_workitem *workitem)
0942 {
0943     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
0944     int i, id;
0945 
0946     workitem->type = WORKITEM_TYPE_PAIRED;
0947     workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
0948                 HIDPP_DEVICE_TYPE_MASK;
0949     workitem->quad_id_msb = hidpp_report->params[HIDPP_PARAM_EQUAD_MSB];
0950     workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_EQUAD_LSB];
0951     switch (workitem->device_type) {
0952     case REPORT_TYPE_KEYBOARD:
0953         workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
0954                            POWER_KEYS | MEDIA_CENTER |
0955                            HIDPP;
0956         id = (workitem->quad_id_msb << 8) | workitem->quad_id_lsb;
0957         for (i = 0; i < ARRAY_SIZE(kbd_builtin_touchpad_ids); i++) {
0958             if (id == kbd_builtin_touchpad_ids[i]) {
0959                 if (djrcv_dev->type == recvr_type_dinovo)
0960                     workitem->reports_supported |= KBD_MOUSE;
0961                 else
0962                     workitem->reports_supported |= STD_MOUSE;
0963                 break;
0964             }
0965         }
0966         break;
0967     case REPORT_TYPE_MOUSE:
0968         workitem->reports_supported |= STD_MOUSE | HIDPP;
0969         if (djrcv_dev->type == recvr_type_mouse_only)
0970             workitem->reports_supported |= MULTIMEDIA;
0971         break;
0972     }
0973 }
0974 
0975 static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev,
0976                         struct hidpp_event *hidpp_report,
0977                         struct dj_workitem *workitem)
0978 {
0979     workitem->type = WORKITEM_TYPE_PAIRED;
0980     workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID];
0981     switch (hidpp_report->device_index) {
0982     case 1: /* Index 1 is always a mouse */
0983     case 2: /* Index 2 is always a mouse */
0984         workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE;
0985         workitem->reports_supported |= STD_MOUSE | HIDPP;
0986         break;
0987     case 3: /* Index 3 is always the keyboard */
0988         if (hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & HIDPP_27MHZ_SECURE_MASK) {
0989             hid_info(hdev, "Keyboard connection is encrypted\n");
0990         } else {
0991             hid_warn(hdev, "Keyboard events are send over the air in plain-text / unencrypted\n");
0992             hid_warn(hdev, "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n");
0993         }
0994         fallthrough;
0995     case 4: /* Index 4 is used for an optional separate numpad */
0996         workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD;
0997         workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
0998                            POWER_KEYS | HIDPP;
0999         break;
1000     default:
1001         hid_warn(hdev, "%s: unexpected device-index %d", __func__,
1002              hidpp_report->device_index);
1003     }
1004 }
1005 
1006 static void logi_hidpp_recv_queue_notif(struct hid_device *hdev,
1007                     struct hidpp_event *hidpp_report)
1008 {
1009     /* We are called from atomic context (tasklet && djrcv->lock held) */
1010     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1011     const char *device_type = "UNKNOWN";
1012     struct dj_workitem workitem = {
1013         .type = WORKITEM_TYPE_EMPTY,
1014         .device_index = hidpp_report->device_index,
1015     };
1016 
1017     switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) {
1018     case 0x01:
1019         device_type = "Bluetooth";
1020         /* Bluetooth connect packet contents is the same as (e)QUAD */
1021         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1022         if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
1023                         HIDPP_MANUFACTURER_MASK)) {
1024             hid_info(hdev, "Non Logitech device connected on slot %d\n",
1025                  hidpp_report->device_index);
1026             workitem.reports_supported &= ~HIDPP;
1027         }
1028         break;
1029     case 0x02:
1030         device_type = "27 Mhz";
1031         logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem);
1032         break;
1033     case 0x03:
1034         device_type = "QUAD or eQUAD";
1035         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1036         break;
1037     case 0x04:
1038         device_type = "eQUAD step 4 DJ";
1039         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1040         break;
1041     case 0x05:
1042         device_type = "DFU Lite";
1043         break;
1044     case 0x06:
1045         device_type = "eQUAD step 4 Lite";
1046         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1047         break;
1048     case 0x07:
1049         device_type = "eQUAD step 4 Gaming";
1050         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1051         workitem.reports_supported |= STD_KEYBOARD;
1052         break;
1053     case 0x08:
1054         device_type = "eQUAD step 4 for gamepads";
1055         break;
1056     case 0x0a:
1057         device_type = "eQUAD nano Lite";
1058         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1059         break;
1060     case 0x0c:
1061         device_type = "eQUAD Lightspeed 1";
1062         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1063         workitem.reports_supported |= STD_KEYBOARD;
1064         break;
1065     case 0x0d:
1066         device_type = "eQUAD Lightspeed 1.1";
1067         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1068         workitem.reports_supported |= STD_KEYBOARD;
1069         break;
1070     case 0x0f:
1071     case 0x11:
1072         device_type = "eQUAD Lightspeed 1.2";
1073         logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1074         workitem.reports_supported |= STD_KEYBOARD;
1075         break;
1076     }
1077 
1078     /* custom receiver device (eg. powerplay) */
1079     if (hidpp_report->device_index == 7) {
1080         workitem.reports_supported |= HIDPP;
1081     }
1082 
1083     if (workitem.type == WORKITEM_TYPE_EMPTY) {
1084         hid_warn(hdev,
1085              "unusable device of type %s (0x%02x) connected on slot %d",
1086              device_type,
1087              hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
1088              hidpp_report->device_index);
1089         return;
1090     }
1091 
1092     hid_info(hdev, "device of type %s (0x%02x) connected on slot %d",
1093          device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
1094          hidpp_report->device_index);
1095 
1096     kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
1097     schedule_work(&djrcv_dev->work);
1098 }
1099 
1100 static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,
1101                          struct dj_report *dj_report)
1102 {
1103     /* We are called from atomic context (tasklet && djrcv->lock held) */
1104     unsigned int i;
1105     u8 reportbuffer[MAX_REPORT_SIZE];
1106     struct dj_device *djdev;
1107 
1108     djdev = djrcv_dev->paired_dj_devices[dj_report->device_index];
1109 
1110     memset(reportbuffer, 0, sizeof(reportbuffer));
1111 
1112     for (i = 0; i < NUMBER_OF_HID_REPORTS; i++) {
1113         if (djdev->reports_supported & (1 << i)) {
1114             reportbuffer[0] = i;
1115             if (hid_input_report(djdev->hdev,
1116                          HID_INPUT_REPORT,
1117                          reportbuffer,
1118                          hid_reportid_size_map[i], 1)) {
1119                 dbg_hid("hid_input_report error sending null "
1120                     "report\n");
1121             }
1122         }
1123     }
1124 }
1125 
1126 static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev,
1127                     struct dj_report *dj_report)
1128 {
1129     /* We are called from atomic context (tasklet && djrcv->lock held) */
1130     struct dj_device *dj_device;
1131 
1132     dj_device = djrcv_dev->paired_dj_devices[dj_report->device_index];
1133 
1134     if ((dj_report->report_type > ARRAY_SIZE(hid_reportid_size_map) - 1) ||
1135         (hid_reportid_size_map[dj_report->report_type] == 0)) {
1136         dbg_hid("invalid report type:%x\n", dj_report->report_type);
1137         return;
1138     }
1139 
1140     if (hid_input_report(dj_device->hdev,
1141             HID_INPUT_REPORT, &dj_report->report_type,
1142             hid_reportid_size_map[dj_report->report_type], 1)) {
1143         dbg_hid("hid_input_report error\n");
1144     }
1145 }
1146 
1147 static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data,
1148                     int size)
1149 {
1150     /* We are called from atomic context (tasklet && djrcv->lock held) */
1151     if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1))
1152         dbg_hid("hid_input_report error\n");
1153 }
1154 
1155 static void logi_dj_recv_forward_input_report(struct hid_device *hdev,
1156                           u8 *data, int size)
1157 {
1158     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1159     struct dj_device *dj_dev;
1160     unsigned long flags;
1161     u8 report = data[0];
1162     int i;
1163 
1164     if (report > REPORT_TYPE_RFREPORT_LAST) {
1165         hid_err(hdev, "Unexpected input report number %d\n", report);
1166         return;
1167     }
1168 
1169     spin_lock_irqsave(&djrcv_dev->lock, flags);
1170     for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
1171         dj_dev = djrcv_dev->paired_dj_devices[i];
1172         if (dj_dev && (dj_dev->reports_supported & BIT(report))) {
1173             logi_dj_recv_forward_report(dj_dev, data, size);
1174             spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1175             return;
1176         }
1177     }
1178 
1179     logi_dj_recv_queue_unknown_work(djrcv_dev);
1180     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1181 
1182     dbg_hid("No dj-devs handling input report number %d\n", report);
1183 }
1184 
1185 static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
1186                     struct dj_report *dj_report)
1187 {
1188     struct hid_device *hdev = djrcv_dev->hidpp;
1189     struct hid_report *report;
1190     struct hid_report_enum *output_report_enum;
1191     u8 *data = (u8 *)(&dj_report->device_index);
1192     unsigned int i;
1193 
1194     output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
1195     report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
1196 
1197     if (!report) {
1198         hid_err(hdev, "%s: unable to find dj report\n", __func__);
1199         return -ENODEV;
1200     }
1201 
1202     for (i = 0; i < DJREPORT_SHORT_LENGTH - 1; i++)
1203         report->field[0]->value[i] = data[i];
1204 
1205     hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
1206 
1207     return 0;
1208 }
1209 
1210 static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev)
1211 {
1212     static const u8 template[] = {
1213         REPORT_ID_HIDPP_SHORT,
1214         HIDPP_RECEIVER_INDEX,
1215         HIDPP_SET_REGISTER,
1216         HIDPP_REG_CONNECTION_STATE,
1217         HIDPP_FAKE_DEVICE_ARRIVAL,
1218         0x00, 0x00
1219     };
1220     u8 *hidpp_report;
1221     int retval;
1222 
1223     hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL);
1224     if (!hidpp_report)
1225         return -ENOMEM;
1226 
1227     retval = hid_hw_raw_request(djrcv_dev->hidpp,
1228                     REPORT_ID_HIDPP_SHORT,
1229                     hidpp_report, sizeof(template),
1230                     HID_OUTPUT_REPORT,
1231                     HID_REQ_SET_REPORT);
1232 
1233     kfree(hidpp_report);
1234     return (retval < 0) ? retval : 0;
1235 }
1236 
1237 static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
1238 {
1239     struct dj_report *dj_report;
1240     int retval;
1241 
1242     djrcv_dev->last_query = jiffies;
1243 
1244     if (djrcv_dev->type != recvr_type_dj)
1245         return logi_dj_recv_query_hidpp_devices(djrcv_dev);
1246 
1247     dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
1248     if (!dj_report)
1249         return -ENOMEM;
1250     dj_report->report_id = REPORT_ID_DJ_SHORT;
1251     dj_report->device_index = HIDPP_RECEIVER_INDEX;
1252     dj_report->report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES;
1253     retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
1254     kfree(dj_report);
1255     return retval;
1256 }
1257 
1258 
1259 static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
1260                       unsigned timeout)
1261 {
1262     struct hid_device *hdev = djrcv_dev->hidpp;
1263     struct dj_report *dj_report;
1264     u8 *buf;
1265     int retval = 0;
1266 
1267     dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
1268     if (!dj_report)
1269         return -ENOMEM;
1270 
1271     if (djrcv_dev->type == recvr_type_dj) {
1272         dj_report->report_id = REPORT_ID_DJ_SHORT;
1273         dj_report->device_index = HIDPP_RECEIVER_INDEX;
1274         dj_report->report_type = REPORT_TYPE_CMD_SWITCH;
1275         dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F;
1276         dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] =
1277                                 (u8)timeout;
1278 
1279         retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
1280 
1281         /*
1282          * Ugly sleep to work around a USB 3.0 bug when the receiver is
1283          * still processing the "switch-to-dj" command while we send an
1284          * other command.
1285          * 50 msec should gives enough time to the receiver to be ready.
1286          */
1287         msleep(50);
1288     }
1289 
1290     /*
1291      * Magical bits to set up hidpp notifications when the dj devices
1292      * are connected/disconnected.
1293      *
1294      * We can reuse dj_report because HIDPP_REPORT_SHORT_LENGTH is smaller
1295      * than DJREPORT_SHORT_LENGTH.
1296      */
1297     buf = (u8 *)dj_report;
1298 
1299     memset(buf, 0, HIDPP_REPORT_SHORT_LENGTH);
1300 
1301     buf[0] = REPORT_ID_HIDPP_SHORT;
1302     buf[1] = HIDPP_RECEIVER_INDEX;
1303     buf[2] = 0x80;
1304     buf[3] = 0x00;
1305     buf[4] = 0x00;
1306     buf[5] = 0x09;
1307     buf[6] = 0x00;
1308 
1309     hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
1310             HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT,
1311             HID_REQ_SET_REPORT);
1312 
1313     kfree(dj_report);
1314     return retval;
1315 }
1316 
1317 
1318 static int logi_dj_ll_open(struct hid_device *hid)
1319 {
1320     dbg_hid("%s: %s\n", __func__, hid->phys);
1321     return 0;
1322 
1323 }
1324 
1325 static void logi_dj_ll_close(struct hid_device *hid)
1326 {
1327     dbg_hid("%s: %s\n", __func__, hid->phys);
1328 }
1329 
1330 /*
1331  * Register 0xB5 is "pairing information". It is solely intended for the
1332  * receiver, so do not overwrite the device index.
1333  */
1334 static u8 unifying_pairing_query[]  = { REPORT_ID_HIDPP_SHORT,
1335                     HIDPP_RECEIVER_INDEX,
1336                     HIDPP_GET_LONG_REGISTER,
1337                     HIDPP_REG_PAIRING_INFORMATION };
1338 static u8 unifying_pairing_answer[] = { REPORT_ID_HIDPP_LONG,
1339                     HIDPP_RECEIVER_INDEX,
1340                     HIDPP_GET_LONG_REGISTER,
1341                     HIDPP_REG_PAIRING_INFORMATION };
1342 
1343 static int logi_dj_ll_raw_request(struct hid_device *hid,
1344                   unsigned char reportnum, __u8 *buf,
1345                   size_t count, unsigned char report_type,
1346                   int reqtype)
1347 {
1348     struct dj_device *djdev = hid->driver_data;
1349     struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev;
1350     u8 *out_buf;
1351     int ret;
1352 
1353     if ((buf[0] == REPORT_ID_HIDPP_SHORT) ||
1354         (buf[0] == REPORT_ID_HIDPP_LONG) ||
1355         (buf[0] == REPORT_ID_HIDPP_VERY_LONG)) {
1356         if (count < 2)
1357             return -EINVAL;
1358 
1359         /* special case where we should not overwrite
1360          * the device_index */
1361         if (count == 7 && !memcmp(buf, unifying_pairing_query,
1362                       sizeof(unifying_pairing_query)))
1363             buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1);
1364         else
1365             buf[1] = djdev->device_index;
1366         return hid_hw_raw_request(djrcv_dev->hidpp, reportnum, buf,
1367                 count, report_type, reqtype);
1368     }
1369 
1370     if (buf[0] != REPORT_TYPE_LEDS)
1371         return -EINVAL;
1372 
1373     if (djrcv_dev->type != recvr_type_dj && count >= 2) {
1374         if (!djrcv_dev->keyboard) {
1375             hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n");
1376             return 0;
1377         }
1378         /* usbhid overrides the report ID and ignores the first byte */
1379         return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count,
1380                       report_type, reqtype);
1381     }
1382 
1383     out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC);
1384     if (!out_buf)
1385         return -ENOMEM;
1386 
1387     if (count > DJREPORT_SHORT_LENGTH - 2)
1388         count = DJREPORT_SHORT_LENGTH - 2;
1389 
1390     out_buf[0] = REPORT_ID_DJ_SHORT;
1391     out_buf[1] = djdev->device_index;
1392     memcpy(out_buf + 2, buf, count);
1393 
1394     ret = hid_hw_raw_request(djrcv_dev->hidpp, out_buf[0], out_buf,
1395         DJREPORT_SHORT_LENGTH, report_type, reqtype);
1396 
1397     kfree(out_buf);
1398     return ret;
1399 }
1400 
1401 static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size)
1402 {
1403     memcpy(rdesc + *rsize, data, size);
1404     *rsize += size;
1405 }
1406 
1407 static int logi_dj_ll_parse(struct hid_device *hid)
1408 {
1409     struct dj_device *djdev = hid->driver_data;
1410     unsigned int rsize = 0;
1411     char *rdesc;
1412     int retval;
1413 
1414     dbg_hid("%s\n", __func__);
1415 
1416     djdev->hdev->version = 0x0111;
1417     djdev->hdev->country = 0x00;
1418 
1419     rdesc = kmalloc(MAX_RDESC_SIZE, GFP_KERNEL);
1420     if (!rdesc)
1421         return -ENOMEM;
1422 
1423     if (djdev->reports_supported & STD_KEYBOARD) {
1424         dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n",
1425             __func__, djdev->reports_supported);
1426         rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
1427     }
1428 
1429     if (djdev->reports_supported & STD_MOUSE) {
1430         dbg_hid("%s: sending a mouse descriptor, reports_supported: %llx\n",
1431             __func__, djdev->reports_supported);
1432         if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp ||
1433             djdev->dj_receiver_dev->type == recvr_type_mouse_only)
1434             rdcat(rdesc, &rsize, mse_high_res_descriptor,
1435                   sizeof(mse_high_res_descriptor));
1436         else if (djdev->dj_receiver_dev->type == recvr_type_27mhz)
1437             rdcat(rdesc, &rsize, mse_27mhz_descriptor,
1438                   sizeof(mse_27mhz_descriptor));
1439         else if (recvr_type_is_bluetooth(djdev->dj_receiver_dev->type))
1440             rdcat(rdesc, &rsize, mse_bluetooth_descriptor,
1441                   sizeof(mse_bluetooth_descriptor));
1442         else
1443             rdcat(rdesc, &rsize, mse_descriptor,
1444                   sizeof(mse_descriptor));
1445     }
1446 
1447     if (djdev->reports_supported & KBD_MOUSE) {
1448         dbg_hid("%s: sending a kbd-mouse descriptor, reports_supported: %llx\n",
1449             __func__, djdev->reports_supported);
1450         rdcat(rdesc, &rsize, mse5_bluetooth_descriptor,
1451               sizeof(mse5_bluetooth_descriptor));
1452     }
1453 
1454     if (djdev->reports_supported & MULTIMEDIA) {
1455         dbg_hid("%s: sending a multimedia report descriptor: %llx\n",
1456             __func__, djdev->reports_supported);
1457         rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));
1458     }
1459 
1460     if (djdev->reports_supported & POWER_KEYS) {
1461         dbg_hid("%s: sending a power keys report descriptor: %llx\n",
1462             __func__, djdev->reports_supported);
1463         rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));
1464     }
1465 
1466     if (djdev->reports_supported & MEDIA_CENTER) {
1467         dbg_hid("%s: sending a media center report descriptor: %llx\n",
1468             __func__, djdev->reports_supported);
1469         rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor));
1470     }
1471 
1472     if (djdev->reports_supported & KBD_LEDS) {
1473         dbg_hid("%s: need to send kbd leds report descriptor: %llx\n",
1474             __func__, djdev->reports_supported);
1475     }
1476 
1477     if (djdev->reports_supported & HIDPP) {
1478         dbg_hid("%s: sending a HID++ descriptor, reports_supported: %llx\n",
1479             __func__, djdev->reports_supported);
1480         rdcat(rdesc, &rsize, hidpp_descriptor,
1481               sizeof(hidpp_descriptor));
1482     }
1483 
1484     retval = hid_parse_report(hid, rdesc, rsize);
1485     kfree(rdesc);
1486 
1487     return retval;
1488 }
1489 
1490 static int logi_dj_ll_start(struct hid_device *hid)
1491 {
1492     dbg_hid("%s\n", __func__);
1493     return 0;
1494 }
1495 
1496 static void logi_dj_ll_stop(struct hid_device *hid)
1497 {
1498     dbg_hid("%s\n", __func__);
1499 }
1500 
1501 static bool logi_dj_ll_may_wakeup(struct hid_device *hid)
1502 {
1503     struct dj_device *djdev = hid->driver_data;
1504     struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev;
1505 
1506     return hid_hw_may_wakeup(djrcv_dev->hidpp);
1507 }
1508 
1509 static struct hid_ll_driver logi_dj_ll_driver = {
1510     .parse = logi_dj_ll_parse,
1511     .start = logi_dj_ll_start,
1512     .stop = logi_dj_ll_stop,
1513     .open = logi_dj_ll_open,
1514     .close = logi_dj_ll_close,
1515     .raw_request = logi_dj_ll_raw_request,
1516     .may_wakeup = logi_dj_ll_may_wakeup,
1517 };
1518 
1519 static int logi_dj_dj_event(struct hid_device *hdev,
1520                  struct hid_report *report, u8 *data,
1521                  int size)
1522 {
1523     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1524     struct dj_report *dj_report = (struct dj_report *) data;
1525     unsigned long flags;
1526 
1527     /*
1528      * Here we receive all data coming from iface 2, there are 3 cases:
1529      *
1530      * 1) Data is intended for this driver i. e. data contains arrival,
1531      * departure, etc notifications, in which case we queue them for delayed
1532      * processing by the work queue. We return 1 to hid-core as no further
1533      * processing is required from it.
1534      *
1535      * 2) Data informs a connection change, if the change means rf link
1536      * loss, then we must send a null report to the upper layer to discard
1537      * potentially pressed keys that may be repeated forever by the input
1538      * layer. Return 1 to hid-core as no further processing is required.
1539      *
1540      * 3) Data is an actual input event from a paired DJ device in which
1541      * case we forward it to the correct hid device (via hid_input_report()
1542      * ) and return 1 so hid-core does not anything else with it.
1543      */
1544 
1545     if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
1546         (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
1547         /*
1548          * Device index is wrong, bail out.
1549          * This driver can ignore safely the receiver notifications,
1550          * so ignore those reports too.
1551          */
1552         if (dj_report->device_index != DJ_RECEIVER_INDEX)
1553             hid_err(hdev, "%s: invalid device index:%d\n",
1554                 __func__, dj_report->device_index);
1555         return false;
1556     }
1557 
1558     spin_lock_irqsave(&djrcv_dev->lock, flags);
1559 
1560     if (!djrcv_dev->paired_dj_devices[dj_report->device_index]) {
1561         /* received an event for an unknown device, bail out */
1562         logi_dj_recv_queue_notification(djrcv_dev, dj_report);
1563         goto out;
1564     }
1565 
1566     switch (dj_report->report_type) {
1567     case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
1568         /* pairing notifications are handled above the switch */
1569         break;
1570     case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
1571         logi_dj_recv_queue_notification(djrcv_dev, dj_report);
1572         break;
1573     case REPORT_TYPE_NOTIF_CONNECTION_STATUS:
1574         if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] ==
1575             STATUS_LINKLOSS) {
1576             logi_dj_recv_forward_null_report(djrcv_dev, dj_report);
1577         }
1578         break;
1579     default:
1580         logi_dj_recv_forward_dj(djrcv_dev, dj_report);
1581     }
1582 
1583 out:
1584     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1585 
1586     return true;
1587 }
1588 
1589 static int logi_dj_hidpp_event(struct hid_device *hdev,
1590                  struct hid_report *report, u8 *data,
1591                  int size)
1592 {
1593     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1594     struct hidpp_event *hidpp_report = (struct hidpp_event *) data;
1595     struct dj_device *dj_dev;
1596     unsigned long flags;
1597     u8 device_index = hidpp_report->device_index;
1598 
1599     if (device_index == HIDPP_RECEIVER_INDEX) {
1600         /* special case were the device wants to know its unifying
1601          * name */
1602         if (size == HIDPP_REPORT_LONG_LENGTH &&
1603             !memcmp(data, unifying_pairing_answer,
1604                 sizeof(unifying_pairing_answer)))
1605             device_index = (data[4] & 0x0F) + 1;
1606         else
1607             return false;
1608     }
1609 
1610     /*
1611      * Data is from the HID++ collection, in this case, we forward the
1612      * data to the corresponding child dj device and return 0 to hid-core
1613      * so he data also goes to the hidraw device of the receiver. This
1614      * allows a user space application to implement the full HID++ routing
1615      * via the receiver.
1616      */
1617 
1618     if ((device_index < DJ_DEVICE_INDEX_MIN) ||
1619         (device_index > DJ_DEVICE_INDEX_MAX)) {
1620         /*
1621          * Device index is wrong, bail out.
1622          * This driver can ignore safely the receiver notifications,
1623          * so ignore those reports too.
1624          */
1625         hid_err(hdev, "%s: invalid device index:%d\n", __func__,
1626             hidpp_report->device_index);
1627         return false;
1628     }
1629 
1630     spin_lock_irqsave(&djrcv_dev->lock, flags);
1631 
1632     dj_dev = djrcv_dev->paired_dj_devices[device_index];
1633 
1634     /*
1635      * With 27 MHz receivers, we do not get an explicit unpair event,
1636      * remove the old device if the user has paired a *different* device.
1637      */
1638     if (djrcv_dev->type == recvr_type_27mhz && dj_dev &&
1639         hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED &&
1640         hidpp_report->params[HIDPP_PARAM_PROTO_TYPE] == 0x02 &&
1641         hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID] !=
1642                         dj_dev->hdev->product) {
1643         struct dj_workitem workitem = {
1644             .device_index = hidpp_report->device_index,
1645             .type = WORKITEM_TYPE_UNPAIRED,
1646         };
1647         kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
1648         /* logi_hidpp_recv_queue_notif will queue the work */
1649         dj_dev = NULL;
1650     }
1651 
1652     if (dj_dev) {
1653         logi_dj_recv_forward_report(dj_dev, data, size);
1654     } else {
1655         if (hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED)
1656             logi_hidpp_recv_queue_notif(hdev, hidpp_report);
1657         else
1658             logi_dj_recv_queue_unknown_work(djrcv_dev);
1659     }
1660 
1661     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1662 
1663     return false;
1664 }
1665 
1666 static int logi_dj_raw_event(struct hid_device *hdev,
1667                  struct hid_report *report, u8 *data,
1668                  int size)
1669 {
1670     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1671     dbg_hid("%s, size:%d\n", __func__, size);
1672 
1673     if (!djrcv_dev)
1674         return 0;
1675 
1676     if (!hdev->report_enum[HID_INPUT_REPORT].numbered) {
1677 
1678         if (djrcv_dev->unnumbered_application == HID_GD_KEYBOARD) {
1679             /*
1680              * For the keyboard, we can reuse the same report by
1681              * using the second byte which is constant in the USB
1682              * HID report descriptor.
1683              */
1684             data[1] = data[0];
1685             data[0] = REPORT_TYPE_KEYBOARD;
1686 
1687             logi_dj_recv_forward_input_report(hdev, data, size);
1688 
1689             /* restore previous state */
1690             data[0] = data[1];
1691             data[1] = 0;
1692         }
1693         /*
1694          * Mouse-only receivers send unnumbered mouse data. The 27 MHz
1695          * receiver uses 6 byte packets, the nano receiver 8 bytes.
1696          */
1697         if (djrcv_dev->unnumbered_application == HID_GD_MOUSE &&
1698             size <= 8) {
1699             u8 mouse_report[9];
1700 
1701             /* Prepend report id */
1702             mouse_report[0] = REPORT_TYPE_MOUSE;
1703             memcpy(mouse_report + 1, data, size);
1704             logi_dj_recv_forward_input_report(hdev, mouse_report,
1705                               size + 1);
1706         }
1707 
1708         return false;
1709     }
1710 
1711     switch (data[0]) {
1712     case REPORT_ID_DJ_SHORT:
1713         if (size != DJREPORT_SHORT_LENGTH) {
1714             hid_err(hdev, "Short DJ report bad size (%d)", size);
1715             return false;
1716         }
1717         return logi_dj_dj_event(hdev, report, data, size);
1718     case REPORT_ID_DJ_LONG:
1719         if (size != DJREPORT_LONG_LENGTH) {
1720             hid_err(hdev, "Long DJ report bad size (%d)", size);
1721             return false;
1722         }
1723         return logi_dj_dj_event(hdev, report, data, size);
1724     case REPORT_ID_HIDPP_SHORT:
1725         if (size != HIDPP_REPORT_SHORT_LENGTH) {
1726             hid_err(hdev, "Short HID++ report bad size (%d)", size);
1727             return false;
1728         }
1729         return logi_dj_hidpp_event(hdev, report, data, size);
1730     case REPORT_ID_HIDPP_LONG:
1731         if (size != HIDPP_REPORT_LONG_LENGTH) {
1732             hid_err(hdev, "Long HID++ report bad size (%d)", size);
1733             return false;
1734         }
1735         return logi_dj_hidpp_event(hdev, report, data, size);
1736     }
1737 
1738     logi_dj_recv_forward_input_report(hdev, data, size);
1739 
1740     return false;
1741 }
1742 
1743 static int logi_dj_probe(struct hid_device *hdev,
1744              const struct hid_device_id *id)
1745 {
1746     struct hid_report_enum *rep_enum;
1747     struct hid_report *rep;
1748     struct dj_receiver_dev *djrcv_dev;
1749     struct usb_interface *intf;
1750     unsigned int no_dj_interfaces = 0;
1751     bool has_hidpp = false;
1752     unsigned long flags;
1753     int retval;
1754 
1755     /*
1756      * Call to usbhid to fetch the HID descriptors of the current
1757      * interface subsequently call to the hid/hid-core to parse the
1758      * fetched descriptors.
1759      */
1760     retval = hid_parse(hdev);
1761     if (retval) {
1762         hid_err(hdev, "%s: parse failed\n", __func__);
1763         return retval;
1764     }
1765 
1766     /*
1767      * Some KVMs add an extra interface for e.g. mouse emulation. If we
1768      * treat these as logitech-dj interfaces then this causes input events
1769      * reported through this extra interface to not be reported correctly.
1770      * To avoid this, we treat these as generic-hid devices.
1771      */
1772     switch (id->driver_data) {
1773     case recvr_type_dj:     no_dj_interfaces = 3; break;
1774     case recvr_type_hidpp:      no_dj_interfaces = 2; break;
1775     case recvr_type_gaming_hidpp:   no_dj_interfaces = 3; break;
1776     case recvr_type_mouse_only: no_dj_interfaces = 2; break;
1777     case recvr_type_27mhz:      no_dj_interfaces = 2; break;
1778     case recvr_type_bluetooth:  no_dj_interfaces = 2; break;
1779     case recvr_type_dinovo:     no_dj_interfaces = 2; break;
1780     }
1781     if (hid_is_usb(hdev)) {
1782         intf = to_usb_interface(hdev->dev.parent);
1783         if (intf && intf->altsetting->desc.bInterfaceNumber >=
1784                             no_dj_interfaces) {
1785             hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1786             return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1787         }
1788     }
1789 
1790     rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
1791 
1792     /* no input reports, bail out */
1793     if (list_empty(&rep_enum->report_list))
1794         return -ENODEV;
1795 
1796     /*
1797      * Check for the HID++ application.
1798      * Note: we should theoretically check for HID++ and DJ
1799      * collections, but this will do.
1800      */
1801     list_for_each_entry(rep, &rep_enum->report_list, list) {
1802         if (rep->application == 0xff000001)
1803             has_hidpp = true;
1804     }
1805 
1806     /*
1807      * Ignore interfaces without DJ/HID++ collection, they will not carry
1808      * any data, dont create any hid_device for them.
1809      */
1810     if (!has_hidpp && id->driver_data == recvr_type_dj)
1811         return -ENODEV;
1812 
1813     /* get the current application attached to the node */
1814     rep = list_first_entry(&rep_enum->report_list, struct hid_report, list);
1815     djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data,
1816                     rep->application, has_hidpp);
1817     if (!djrcv_dev) {
1818         hid_err(hdev, "%s: dj_get_receiver_dev failed\n", __func__);
1819         return -ENOMEM;
1820     }
1821 
1822     if (!rep_enum->numbered)
1823         djrcv_dev->unnumbered_application = rep->application;
1824 
1825     /* Starts the usb device and connects to upper interfaces hiddev and
1826      * hidraw */
1827     retval = hid_hw_start(hdev, HID_CONNECT_HIDRAW|HID_CONNECT_HIDDEV);
1828     if (retval) {
1829         hid_err(hdev, "%s: hid_hw_start returned error\n", __func__);
1830         goto hid_hw_start_fail;
1831     }
1832 
1833     if (has_hidpp) {
1834         retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
1835         if (retval < 0) {
1836             hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1837                 __func__, retval);
1838             goto switch_to_dj_mode_fail;
1839         }
1840     }
1841 
1842     /* This is enabling the polling urb on the IN endpoint */
1843     retval = hid_hw_open(hdev);
1844     if (retval < 0) {
1845         hid_err(hdev, "%s: hid_hw_open returned error:%d\n",
1846             __func__, retval);
1847         goto llopen_failed;
1848     }
1849 
1850     /* Allow incoming packets to arrive: */
1851     hid_device_io_start(hdev);
1852 
1853     if (has_hidpp) {
1854         spin_lock_irqsave(&djrcv_dev->lock, flags);
1855         djrcv_dev->ready = true;
1856         spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1857         retval = logi_dj_recv_query_paired_devices(djrcv_dev);
1858         if (retval < 0) {
1859             hid_err(hdev, "%s: logi_dj_recv_query_paired_devices error:%d\n",
1860                 __func__, retval);
1861             /*
1862              * This can happen with a KVM, let the probe succeed,
1863              * logi_dj_recv_queue_unknown_work will retry later.
1864              */
1865         }
1866     }
1867 
1868     return 0;
1869 
1870 llopen_failed:
1871 switch_to_dj_mode_fail:
1872     hid_hw_stop(hdev);
1873 
1874 hid_hw_start_fail:
1875     dj_put_receiver_dev(hdev);
1876     return retval;
1877 }
1878 
1879 #ifdef CONFIG_PM
1880 static int logi_dj_reset_resume(struct hid_device *hdev)
1881 {
1882     int retval;
1883     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1884 
1885     if (!djrcv_dev || djrcv_dev->hidpp != hdev)
1886         return 0;
1887 
1888     retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
1889     if (retval < 0) {
1890         hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1891             __func__, retval);
1892     }
1893 
1894     return 0;
1895 }
1896 #endif
1897 
1898 static void logi_dj_remove(struct hid_device *hdev)
1899 {
1900     struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1901     struct dj_device *dj_dev;
1902     unsigned long flags;
1903     int i;
1904 
1905     dbg_hid("%s\n", __func__);
1906 
1907     if (!djrcv_dev)
1908         return hid_hw_stop(hdev);
1909 
1910     /*
1911      * This ensures that if the work gets requeued from another
1912      * interface of the same receiver it will be a no-op.
1913      */
1914     spin_lock_irqsave(&djrcv_dev->lock, flags);
1915     djrcv_dev->ready = false;
1916     spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1917 
1918     cancel_work_sync(&djrcv_dev->work);
1919 
1920     hid_hw_close(hdev);
1921     hid_hw_stop(hdev);
1922 
1923     /*
1924      * For proper operation we need access to all interfaces, so we destroy
1925      * the paired devices when we're unbound from any interface.
1926      *
1927      * Note we may still be bound to other interfaces, sharing the same
1928      * djrcv_dev, so we need locking here.
1929      */
1930     for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
1931         spin_lock_irqsave(&djrcv_dev->lock, flags);
1932         dj_dev = djrcv_dev->paired_dj_devices[i];
1933         djrcv_dev->paired_dj_devices[i] = NULL;
1934         spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1935         if (dj_dev != NULL) {
1936             hid_destroy_device(dj_dev->hdev);
1937             kfree(dj_dev);
1938         }
1939     }
1940 
1941     dj_put_receiver_dev(hdev);
1942 }
1943 
1944 static const struct hid_device_id logi_dj_receivers[] = {
1945     { /* Logitech unifying receiver (0xc52b) */
1946       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1947         USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER),
1948      .driver_data = recvr_type_dj},
1949     { /* Logitech unifying receiver (0xc532) */
1950       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1951         USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2),
1952      .driver_data = recvr_type_dj},
1953 
1954     { /* Logitech Nano mouse only receiver (0xc52f) */
1955       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1956              USB_DEVICE_ID_LOGITECH_NANO_RECEIVER),
1957      .driver_data = recvr_type_mouse_only},
1958     { /* Logitech Nano (non DJ) receiver (0xc534) */
1959       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1960              USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2),
1961      .driver_data = recvr_type_hidpp},
1962 
1963     { /* Logitech G700(s) receiver (0xc531) */
1964       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1965              USB_DEVICE_ID_LOGITECH_G700_RECEIVER),
1966      .driver_data = recvr_type_gaming_hidpp},
1967     { /* Logitech G602 receiver (0xc537) */
1968       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1969         0xc537),
1970      .driver_data = recvr_type_gaming_hidpp},
1971     { /* Logitech lightspeed receiver (0xc539) */
1972       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1973         USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1),
1974      .driver_data = recvr_type_gaming_hidpp},
1975     { /* Logitech powerplay receiver (0xc53a) */
1976       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1977         USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY),
1978      .driver_data = recvr_type_gaming_hidpp},
1979     { /* Logitech lightspeed receiver (0xc53f) */
1980       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1981         USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1),
1982      .driver_data = recvr_type_gaming_hidpp},
1983 
1984     { /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */
1985       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
1986      .driver_data = recvr_type_27mhz},
1987     { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */
1988       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1989         USB_DEVICE_ID_S510_RECEIVER_2),
1990      .driver_data = recvr_type_27mhz},
1991     { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */
1992       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1993         USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER),
1994      .driver_data = recvr_type_27mhz},
1995 
1996     { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. (0xc70e) */
1997       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1998         USB_DEVICE_ID_MX5000_RECEIVER_KBD_DEV),
1999      .driver_data = recvr_type_bluetooth},
2000     { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. (0xc70a) */
2001       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2002         USB_DEVICE_ID_MX5000_RECEIVER_MOUSE_DEV),
2003      .driver_data = recvr_type_bluetooth},
2004     { /* Logitech MX5500 HID++ / bluetooth receiver keyboard intf. (0xc71b) */
2005       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2006         USB_DEVICE_ID_MX5500_RECEIVER_KBD_DEV),
2007      .driver_data = recvr_type_bluetooth},
2008     { /* Logitech MX5500 HID++ / bluetooth receiver mouse intf. (0xc71c) */
2009       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2010         USB_DEVICE_ID_MX5500_RECEIVER_MOUSE_DEV),
2011      .driver_data = recvr_type_bluetooth},
2012 
2013     { /* Logitech Dinovo Edge HID++ / bluetooth receiver keyboard intf. (0xc713) */
2014       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2015         USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_KBD_DEV),
2016      .driver_data = recvr_type_dinovo},
2017     { /* Logitech Dinovo Edge HID++ / bluetooth receiver mouse intf. (0xc714) */
2018       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2019         USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_MOUSE_DEV),
2020      .driver_data = recvr_type_dinovo},
2021     { /* Logitech DiNovo Mini HID++ / bluetooth receiver mouse intf. (0xc71e) */
2022       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2023         USB_DEVICE_ID_DINOVO_MINI_RECEIVER_KBD_DEV),
2024      .driver_data = recvr_type_dinovo},
2025     { /* Logitech DiNovo Mini HID++ / bluetooth receiver keyboard intf. (0xc71f) */
2026       HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2027         USB_DEVICE_ID_DINOVO_MINI_RECEIVER_MOUSE_DEV),
2028      .driver_data = recvr_type_dinovo},
2029     {}
2030 };
2031 
2032 MODULE_DEVICE_TABLE(hid, logi_dj_receivers);
2033 
2034 static struct hid_driver logi_djreceiver_driver = {
2035     .name = "logitech-djreceiver",
2036     .id_table = logi_dj_receivers,
2037     .probe = logi_dj_probe,
2038     .remove = logi_dj_remove,
2039     .raw_event = logi_dj_raw_event,
2040 #ifdef CONFIG_PM
2041     .reset_resume = logi_dj_reset_resume,
2042 #endif
2043 };
2044 
2045 module_hid_driver(logi_djreceiver_driver);
2046 
2047 MODULE_LICENSE("GPL");
2048 MODULE_AUTHOR("Logitech");
2049 MODULE_AUTHOR("Nestor Lopez Casado");
2050 MODULE_AUTHOR("nlopezcasad@logitech.com");