@@ -279,30 +279,55 @@ static const struct hwmon_chip_info thelio_io_chip_info = {
279279 .info = thelio_io_info ,
280280};
281281
282- static int thelio_io_probe (struct hid_device * hdev , const struct hid_device_id * id )
282+ static int thelio_io_probe_cmd_dev (struct hid_device * hdev )
283283{
284284 struct thelio_io_device * thelio_io ;
285285 int ret ;
286286
287- ret = hid_parse (hdev );
287+ thelio_io = devm_kzalloc (& hdev -> dev , sizeof (* thelio_io ), GFP_KERNEL );
288+ if (!thelio_io )
289+ return - ENOMEM ;
290+
291+ thelio_io -> buffer = devm_kmalloc (& hdev -> dev , BUFFER_SIZE , GFP_KERNEL );
292+ if (!thelio_io -> buffer )
293+ return - ENOMEM ;
294+
295+ ret = hid_hw_start (hdev , HID_CONNECT_DEFAULT );
288296 if (ret )
289297 return ret ;
290298
291- if (hdev -> rsize != 34 ) {
292- // Wrong report size
293- return - ENODEV ;
294- }
299+ ret = hid_hw_open (hdev );
300+ if (ret )
301+ goto out_hw_stop ;
295302
296- if ( hdev -> maxcollection != 1 ) {
297- // Wrong number of collections
298- return - ENODEV ;
299- }
303+ thelio_io -> hdev = hdev ;
304+ hid_set_drvdata ( hdev , thelio_io );
305+ mutex_init ( & thelio_io -> mutex ) ;
306+ init_completion ( & thelio_io -> wait_input_report );
300307
301- if (hdev -> collection [0 ].usage != 0xFF600061 ) {
302- // Wrong collection usage
303- return - ENODEV ;
308+ hid_device_io_start (hdev );
309+
310+ thelio_io -> hwmon_dev = hwmon_device_register_with_info (& hdev -> dev , "system76_thelio_io" ,
311+ thelio_io , & thelio_io_chip_info , 0 );
312+ if (IS_ERR (thelio_io -> hwmon_dev )) {
313+ ret = PTR_ERR (thelio_io -> hwmon_dev );
314+ goto out_hw_close ;
304315 }
305316
317+ return 0 ;
318+
319+ out_hw_close :
320+ hid_hw_close (hdev );
321+ out_hw_stop :
322+ hid_hw_stop (hdev );
323+ return ret ;
324+ }
325+
326+ static int thelio_io_probe (struct hid_device * hdev , const struct hid_device_id * id )
327+ {
328+ struct thelio_io_device * thelio_io ;
329+ int ret ;
330+
306331 thelio_io = devm_kzalloc (& hdev -> dev , sizeof (* thelio_io ), GFP_KERNEL );
307332 if (!thelio_io )
308333 return - ENOMEM ;
@@ -311,7 +336,11 @@ static int thelio_io_probe(struct hid_device *hdev, const struct hid_device_id *
311336 if (!thelio_io -> buffer )
312337 return - ENOMEM ;
313338
314- ret = hid_hw_start (hdev , HID_CONNECT_HIDRAW );
339+ ret = hid_parse (hdev );
340+ if (ret )
341+ return ret ;
342+
343+ ret = hid_hw_start (hdev , HID_CONNECT_DEFAULT );
315344 if (ret )
316345 return ret ;
317346
@@ -326,11 +355,14 @@ static int thelio_io_probe(struct hid_device *hdev, const struct hid_device_id *
326355
327356 hid_device_io_start (hdev );
328357
329- thelio_io -> hwmon_dev = hwmon_device_register_with_info (& hdev -> dev , "system76_thelio_io" ,
330- thelio_io , & thelio_io_chip_info , 0 );
331- if (IS_ERR (thelio_io -> hwmon_dev )) {
332- ret = PTR_ERR (thelio_io -> hwmon_dev );
333- goto out_hw_close ;
358+ if (hdev -> maxcollection == 1 && hdev -> collection [0 ].usage == 0xFF600061 ) {
359+ hid_info (hdev , "found command device\n" );
360+ thelio_io -> hwmon_dev = hwmon_device_register_with_info (& hdev -> dev , "system76_thelio_io" ,
361+ thelio_io , & thelio_io_chip_info , 0 );
362+ if (IS_ERR (thelio_io -> hwmon_dev )) {
363+ ret = PTR_ERR (thelio_io -> hwmon_dev );
364+ goto out_hw_close ;
365+ }
334366 }
335367
336368 return 0 ;
@@ -346,7 +378,9 @@ static void thelio_io_remove(struct hid_device *hdev)
346378{
347379 struct thelio_io_device * thelio_io = hid_get_drvdata (hdev );
348380
349- hwmon_device_unregister (thelio_io -> hwmon_dev );
381+ if (thelio_io -> hwmon_dev ) {
382+ hwmon_device_unregister (thelio_io -> hwmon_dev );
383+ }
350384 hid_hw_close (hdev );
351385 hid_hw_stop (hdev );
352386}
0 commit comments