Skip to content

Commit d610274

Browse files
bentissJiri Kosina
authored andcommitted
HID: logitech-dj: rely on hid groups to separate receivers from dj devices
Several benefits here: - we can drop the macro is_dj_device: I never been really conviced by this macro as we could fall into a null pointer anytime. Anyway time showed that this never happened. - we can simplify the hid driver logitech-djdevice, and make it aware of any new receiver VID/PID. - we can use the Wireless PID of the DJ device as the product id of the hid device, this way the sysfs will differentiate between different DJ devices. Signed-off-by: Benjamin Tisssoires <[email protected]> Tested-by: Andrew de los Reyes <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 9578f41 commit d610274

File tree

3 files changed

+11
-38
lines changed

3 files changed

+11
-38
lines changed

drivers/hid/hid-logitech-dj.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,15 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
256256
dj_hiddev->dev.parent = &djrcv_hdev->dev;
257257
dj_hiddev->bus = BUS_USB;
258258
dj_hiddev->vendor = le16_to_cpu(usbdev->descriptor.idVendor);
259-
dj_hiddev->product = le16_to_cpu(usbdev->descriptor.idProduct);
259+
dj_hiddev->product =
260+
(dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB]
261+
<< 8) |
262+
dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB];
260263
snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
261-
"Logitech Unifying Device. Wireless PID:%02x%02x",
262-
dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB],
263-
dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB]);
264+
"Logitech Unifying Device. Wireless PID:%04x",
265+
dj_hiddev->product);
266+
267+
dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE;
264268

265269
usb_make_path(usbdev, dj_hiddev->phys, sizeof(dj_hiddev->phys));
266270
snprintf(tmpstr, sizeof(tmpstr), ":%d", dj_report->device_index);
@@ -714,9 +718,6 @@ static int logi_dj_probe(struct hid_device *hdev,
714718
struct dj_receiver_dev *djrcv_dev;
715719
int retval;
716720

717-
if (is_dj_device((struct dj_device *)hdev->driver_data))
718-
return -ENODEV;
719-
720721
dbg_hid("%s called for ifnum %d\n", __func__,
721722
intf->cur_altsetting->desc.bInterfaceNumber);
722723

@@ -869,22 +870,6 @@ static void logi_dj_remove(struct hid_device *hdev)
869870
hid_set_drvdata(hdev, NULL);
870871
}
871872

872-
static int logi_djdevice_probe(struct hid_device *hdev,
873-
const struct hid_device_id *id)
874-
{
875-
int ret;
876-
struct dj_device *dj_dev = hdev->driver_data;
877-
878-
if (!is_dj_device(dj_dev))
879-
return -ENODEV;
880-
881-
ret = hid_parse(hdev);
882-
if (!ret)
883-
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
884-
885-
return ret;
886-
}
887-
888873
static const struct hid_device_id logi_dj_receivers[] = {
889874
{HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
890875
USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER)},
@@ -908,17 +893,14 @@ static struct hid_driver logi_djreceiver_driver = {
908893

909894

910895
static const struct hid_device_id logi_dj_devices[] = {
911-
{HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
912-
USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER)},
913-
{HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
914-
USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2)},
896+
{ HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
897+
USB_VENDOR_ID_LOGITECH, HID_ANY_ID)},
915898
{}
916899
};
917900

918901
static struct hid_driver logi_djdevice_driver = {
919902
.name = "logitech-djdevice",
920903
.id_table = logi_dj_devices,
921-
.probe = logi_djdevice_probe,
922904
};
923905

924906

drivers/hid/hid-logitech-dj.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,4 @@ struct dj_device {
112112
u8 device_index;
113113
};
114114

115-
/**
116-
* is_dj_device - know if the given dj_device is not the receiver.
117-
* @dj_dev: the dj device to test
118-
*
119-
* This macro tests if a struct dj_device pointer is a device created
120-
* by the bus enumarator.
121-
*/
122-
#define is_dj_device(dj_dev) \
123-
(&(dj_dev)->dj_receiver_dev->hdev->dev == (dj_dev)->hdev->dev.parent)
124-
125115
#endif

include/linux/hid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ struct hid_item {
313313
*/
314314
#define HID_GROUP_RMI 0x0100
315315
#define HID_GROUP_WACOM 0x0101
316+
#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102
316317

317318
/*
318319
* This is the global environment of the parser. This information is

0 commit comments

Comments
 (0)