@@ -69,12 +69,11 @@ MODULE_PARM_DESC(disable_tap_to_click,
69
69
#define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
70
70
#define HIDPP_QUIRK_DELAYED_INIT BIT(23)
71
71
#define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
72
- #define HIDPP_QUIRK_UNIFYING BIT(25)
73
- #define HIDPP_QUIRK_HIDPP_WHEELS BIT(26)
74
- #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(27)
75
- #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(28)
76
- #define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(29)
77
- #define HIDPP_QUIRK_WIRELESS_STATUS BIT(30)
72
+ #define HIDPP_QUIRK_HIDPP_WHEELS BIT(25)
73
+ #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(26)
74
+ #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(27)
75
+ #define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(28)
76
+ #define HIDPP_QUIRK_WIRELESS_STATUS BIT(29)
78
77
79
78
/* These are just aliases for now */
80
79
#define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
@@ -194,7 +193,6 @@ struct hidpp_device {
194
193
195
194
struct work_struct work ;
196
195
struct kfifo delayed_work_fifo ;
197
- atomic_t connected ;
198
196
struct input_dev * delayed_input ;
199
197
200
198
unsigned long quirks ;
@@ -235,8 +233,6 @@ struct hidpp_device {
235
233
#define HIDPP20_ERROR_UNSUPPORTED 0x09
236
234
#define HIDPP20_ERROR 0xff
237
235
238
- static void hidpp_connect_event (struct hidpp_device * hidpp_dev );
239
-
240
236
static int __hidpp_send_report (struct hid_device * hdev ,
241
237
struct hidpp_report * hidpp_report )
242
238
{
@@ -450,13 +446,6 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
450
446
return ret ;
451
447
}
452
448
453
- static void delayed_work_cb (struct work_struct * work )
454
- {
455
- struct hidpp_device * hidpp = container_of (work , struct hidpp_device ,
456
- work );
457
- hidpp_connect_event (hidpp );
458
- }
459
-
460
449
static inline bool hidpp_match_answer (struct hidpp_report * question ,
461
450
struct hidpp_report * answer )
462
451
{
@@ -1835,15 +1824,14 @@ static int hidpp_battery_get_property(struct power_supply *psy,
1835
1824
/* -------------------------------------------------------------------------- */
1836
1825
#define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b
1837
1826
1838
- static int hidpp_set_wireless_feature_index (struct hidpp_device * hidpp )
1827
+ static int hidpp_get_wireless_feature_index (struct hidpp_device * hidpp , u8 * feature_index )
1839
1828
{
1840
1829
u8 feature_type ;
1841
1830
int ret ;
1842
1831
1843
1832
ret = hidpp_root_get_feature (hidpp ,
1844
1833
HIDPP_PAGE_WIRELESS_DEVICE_STATUS ,
1845
- & hidpp -> wireless_feature_index ,
1846
- & feature_type );
1834
+ feature_index , & feature_type );
1847
1835
1848
1836
return ret ;
1849
1837
}
@@ -3142,7 +3130,7 @@ static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
3142
3130
return 0 ;
3143
3131
};
3144
3132
3145
- static int wtp_connect (struct hid_device * hdev , bool connected )
3133
+ static int wtp_connect (struct hid_device * hdev )
3146
3134
{
3147
3135
struct hidpp_device * hidpp = hid_get_drvdata (hdev );
3148
3136
struct wtp_data * wd = hidpp -> private_data ;
@@ -3204,7 +3192,7 @@ static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
3204
3192
#define M560_SUB_ID 0x0a
3205
3193
#define M560_BUTTON_MODE_REGISTER 0x35
3206
3194
3207
- static int m560_send_config_command (struct hid_device * hdev , bool connected )
3195
+ static int m560_send_config_command (struct hid_device * hdev )
3208
3196
{
3209
3197
struct hidpp_report response ;
3210
3198
struct hidpp_device * hidpp_dev ;
@@ -3399,7 +3387,7 @@ static int k400_allocate(struct hid_device *hdev)
3399
3387
return 0 ;
3400
3388
};
3401
3389
3402
- static int k400_connect (struct hid_device * hdev , bool connected )
3390
+ static int k400_connect (struct hid_device * hdev )
3403
3391
{
3404
3392
struct hidpp_device * hidpp = hid_get_drvdata (hdev );
3405
3393
@@ -3894,8 +3882,6 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
3894
3882
}
3895
3883
3896
3884
if (unlikely (hidpp_report_is_connect_event (hidpp , report ))) {
3897
- atomic_set (& hidpp -> connected ,
3898
- !(report -> rap .params [0 ] & (1 << 6 )));
3899
3885
if (schedule_work (& hidpp -> work ) == 0 )
3900
3886
dbg_hid ("%s: connect event already queued\n" , __func__ );
3901
3887
return 1 ;
@@ -4131,24 +4117,22 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
4131
4117
return ret ;
4132
4118
}
4133
4119
4134
- static void hidpp_overwrite_name (struct hid_device * hdev )
4120
+ /* Get name + serial for USB and Bluetooth HID++ devices */
4121
+ static void hidpp_non_unifying_init (struct hidpp_device * hidpp )
4135
4122
{
4136
- struct hidpp_device * hidpp = hid_get_drvdata ( hdev ) ;
4123
+ struct hid_device * hdev = hidpp -> hid_dev ;
4137
4124
char * name ;
4138
4125
4139
- if (hidpp -> protocol_major < 2 )
4140
- return ;
4126
+ /* Bluetooth devices already have their serialnr set */
4127
+ if (hid_is_usb (hdev ))
4128
+ hidpp_serial_init (hidpp );
4141
4129
4142
4130
name = hidpp_get_device_name (hidpp );
4143
-
4144
- if (!name ) {
4145
- hid_err (hdev , "unable to retrieve the name of the device" );
4146
- } else {
4131
+ if (name ) {
4147
4132
dbg_hid ("HID++: Got name: %s\n" , name );
4148
4133
snprintf (hdev -> name , sizeof (hdev -> name ), "%s" , name );
4134
+ kfree (name );
4149
4135
}
4150
-
4151
- kfree (name );
4152
4136
}
4153
4137
4154
4138
static int hidpp_input_open (struct input_dev * dev )
@@ -4189,15 +4173,18 @@ static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
4189
4173
return input_dev ;
4190
4174
}
4191
4175
4192
- static void hidpp_connect_event (struct hidpp_device * hidpp )
4176
+ static void hidpp_connect_event (struct work_struct * work )
4193
4177
{
4178
+ struct hidpp_device * hidpp = container_of (work , struct hidpp_device , work );
4194
4179
struct hid_device * hdev = hidpp -> hid_dev ;
4195
- int ret = 0 ;
4196
- bool connected = atomic_read (& hidpp -> connected );
4197
4180
struct input_dev * input ;
4198
4181
char * name , * devm_name ;
4182
+ int ret ;
4199
4183
4200
- if (!connected ) {
4184
+ /* Get device version to check if it is connected */
4185
+ ret = hidpp_root_get_protocol_version (hidpp );
4186
+ if (ret ) {
4187
+ hid_info (hidpp -> hid_dev , "Disconnected\n" );
4201
4188
if (hidpp -> battery .ps ) {
4202
4189
hidpp -> battery .online = false;
4203
4190
hidpp -> battery .status = POWER_SUPPLY_STATUS_UNKNOWN ;
@@ -4208,15 +4195,15 @@ static void hidpp_connect_event(struct hidpp_device *hidpp)
4208
4195
}
4209
4196
4210
4197
if (hidpp -> quirks & HIDPP_QUIRK_CLASS_WTP ) {
4211
- ret = wtp_connect (hdev , connected );
4198
+ ret = wtp_connect (hdev );
4212
4199
if (ret )
4213
4200
return ;
4214
4201
} else if (hidpp -> quirks & HIDPP_QUIRK_CLASS_M560 ) {
4215
- ret = m560_send_config_command (hdev , connected );
4202
+ ret = m560_send_config_command (hdev );
4216
4203
if (ret )
4217
4204
return ;
4218
4205
} else if (hidpp -> quirks & HIDPP_QUIRK_CLASS_K400 ) {
4219
- ret = k400_connect (hdev , connected );
4206
+ ret = k400_connect (hdev );
4220
4207
if (ret )
4221
4208
return ;
4222
4209
}
@@ -4239,14 +4226,11 @@ static void hidpp_connect_event(struct hidpp_device *hidpp)
4239
4226
return ;
4240
4227
}
4241
4228
4242
- /* the device is already connected, we can ask for its name and
4243
- * protocol */
4244
- if (!hidpp -> protocol_major ) {
4245
- ret = hidpp_root_get_protocol_version (hidpp );
4246
- if (ret ) {
4247
- hid_err (hdev , "Can not get the protocol version.\n" );
4248
- return ;
4249
- }
4229
+ if (hidpp -> protocol_major >= 2 ) {
4230
+ u8 feature_index ;
4231
+
4232
+ if (!hidpp_get_wireless_feature_index (hidpp , & feature_index ))
4233
+ hidpp -> wireless_feature_index = feature_index ;
4250
4234
}
4251
4235
4252
4236
if (hidpp -> name == hdev -> name && hidpp -> protocol_major >= 2 ) {
@@ -4391,10 +4375,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4391
4375
{
4392
4376
struct hidpp_device * hidpp ;
4393
4377
int ret ;
4394
- bool connected ;
4395
4378
unsigned int connect_mask = HID_CONNECT_DEFAULT ;
4396
- struct hidpp_ff_private_data data ;
4397
- bool will_restart = false;
4398
4379
4399
4380
/* report_fixup needs drvdata to be set before we call hid_parse */
4400
4381
hidpp = devm_kzalloc (& hdev -> dev , sizeof (* hidpp ), GFP_KERNEL );
@@ -4423,9 +4404,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4423
4404
return hid_hw_start (hdev , HID_CONNECT_DEFAULT );
4424
4405
}
4425
4406
4426
- if (id -> group == HID_GROUP_LOGITECH_DJ_DEVICE )
4427
- hidpp -> quirks |= HIDPP_QUIRK_UNIFYING ;
4428
-
4429
4407
if (id -> group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
4430
4408
hidpp_application_equals (hdev , HID_GD_MOUSE ))
4431
4409
hidpp -> quirks |= HIDPP_QUIRK_HIDPP_WHEELS |
@@ -4445,11 +4423,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4445
4423
return ret ;
4446
4424
}
4447
4425
4448
- if (hidpp -> quirks & HIDPP_QUIRK_DELAYED_INIT ||
4449
- hidpp -> quirks & HIDPP_QUIRK_UNIFYING )
4450
- will_restart = true;
4451
-
4452
- INIT_WORK (& hidpp -> work , delayed_work_cb );
4426
+ INIT_WORK (& hidpp -> work , hidpp_connect_event );
4453
4427
mutex_init (& hidpp -> send_mutex );
4454
4428
init_waitqueue_head (& hidpp -> wait );
4455
4429
@@ -4460,10 +4434,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4460
4434
hdev -> name );
4461
4435
4462
4436
/*
4463
- * Plain USB connections need to actually call start and open
4464
- * on the transport driver to allow incoming data.
4437
+ * First call hid_hw_start(hdev, 0) to allow IO without connecting any
4438
+ * hid subdrivers (hid-input, hidraw). This allows retrieving the dev's
4439
+ * name and serial number and store these in hdev->name and hdev->uniq,
4440
+ * before the hid-input and hidraw drivers expose these to userspace.
4465
4441
*/
4466
- ret = hid_hw_start (hdev , will_restart ? 0 : connect_mask );
4442
+ ret = hid_hw_start (hdev , 0 );
4467
4443
if (ret ) {
4468
4444
hid_err (hdev , "hw start failed\n" );
4469
4445
goto hid_hw_start_fail ;
@@ -4479,70 +4455,46 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4479
4455
/* Allow incoming packets */
4480
4456
hid_device_io_start (hdev );
4481
4457
4482
- if (hidpp -> quirks & HIDPP_QUIRK_UNIFYING )
4458
+ /* Get name + serial, store in hdev->name + hdev->uniq */
4459
+ if (id -> group == HID_GROUP_LOGITECH_DJ_DEVICE )
4483
4460
hidpp_unifying_init (hidpp );
4484
- else if (hid_is_usb (hidpp -> hid_dev ))
4485
- hidpp_serial_init (hidpp );
4486
-
4487
- connected = hidpp_root_get_protocol_version (hidpp ) == 0 ;
4488
- atomic_set (& hidpp -> connected , connected );
4489
- if (!(hidpp -> quirks & HIDPP_QUIRK_UNIFYING )) {
4490
- if (!connected ) {
4491
- ret = - ENODEV ;
4492
- hid_err (hdev , "Device not connected" );
4493
- goto hid_hw_init_fail ;
4494
- }
4495
-
4496
- hidpp_overwrite_name (hdev );
4497
- }
4461
+ else
4462
+ hidpp_non_unifying_init (hidpp );
4498
4463
4499
- if (connected && hidpp -> protocol_major >= 2 ) {
4500
- ret = hidpp_set_wireless_feature_index (hidpp );
4501
- if (ret == - ENOENT )
4502
- hidpp -> wireless_feature_index = 0 ;
4503
- else if (ret )
4504
- goto hid_hw_init_fail ;
4505
- ret = 0 ;
4506
- }
4464
+ if (hidpp -> quirks & HIDPP_QUIRK_DELAYED_INIT )
4465
+ connect_mask &= ~HID_CONNECT_HIDINPUT ;
4507
4466
4508
- if (connected && (hidpp -> quirks & HIDPP_QUIRK_CLASS_WTP )) {
4509
- ret = wtp_get_config (hidpp );
4510
- if (ret )
4511
- goto hid_hw_init_fail ;
4512
- } else if (connected && (hidpp -> quirks & HIDPP_QUIRK_CLASS_G920 )) {
4513
- ret = g920_get_config (hidpp , & data );
4514
- if (ret )
4515
- goto hid_hw_init_fail ;
4467
+ /* Now export the actual inputs and hidraw nodes to the world */
4468
+ hid_device_io_stop (hdev );
4469
+ ret = hid_connect (hdev , connect_mask );
4470
+ if (ret ) {
4471
+ hid_err (hdev , "%s:hid_connect returned error %d\n" , __func__ , ret );
4472
+ goto hid_hw_init_fail ;
4516
4473
}
4517
4474
4475
+ /* Check for connected devices now that incoming packets will not be disabled again */
4476
+ hid_device_io_start (hdev );
4518
4477
schedule_work (& hidpp -> work );
4519
4478
flush_work (& hidpp -> work );
4520
4479
4521
- if (will_restart ) {
4522
- /* Reset the HID node state */
4523
- hid_device_io_stop (hdev );
4524
- hid_hw_close (hdev );
4525
- hid_hw_stop (hdev );
4526
-
4527
- if (hidpp -> quirks & HIDPP_QUIRK_DELAYED_INIT )
4528
- connect_mask &= ~HID_CONNECT_HIDINPUT ;
4480
+ if (hidpp -> quirks & HIDPP_QUIRK_CLASS_G920 ) {
4481
+ struct hidpp_ff_private_data data ;
4529
4482
4530
- /* Now export the actual inputs and hidraw nodes to the world */
4531
- ret = hid_hw_start (hdev , connect_mask );
4532
- if (ret ) {
4533
- hid_err (hdev , "%s:hid_hw_start returned error\n" , __func__ );
4534
- goto hid_hw_start_fail ;
4535
- }
4536
- }
4483
+ ret = g920_get_config (hidpp , & data );
4484
+ if (!ret )
4485
+ ret = hidpp_ff_init (hidpp , & data );
4537
4486
4538
- if (hidpp -> quirks & HIDPP_QUIRK_CLASS_G920 ) {
4539
- ret = hidpp_ff_init (hidpp , & data );
4540
4487
if (ret )
4541
4488
hid_warn (hidpp -> hid_dev ,
4542
4489
"Unable to initialize force feedback support, errno %d\n" ,
4543
4490
ret );
4544
4491
}
4545
4492
4493
+ /*
4494
+ * This relies on logi_dj_ll_close() being a no-op so that DJ connection
4495
+ * events will still be received.
4496
+ */
4497
+ hid_hw_close (hdev );
4546
4498
return ret ;
4547
4499
4548
4500
hid_hw_init_fail :
0 commit comments