Lines Matching refs:steam
129 static int steam_recv_report(struct steam_device *steam, in steam_recv_report() argument
136 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_recv_report()
138 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_recv_report()
155 ret = hid_hw_raw_request(steam->hdev, 0x00, in steam_recv_report()
164 static int steam_send_report(struct steam_device *steam, in steam_send_report() argument
172 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_send_report()
174 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_send_report()
195 ret = hid_hw_raw_request(steam->hdev, 0, in steam_send_report()
205 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, in steam_send_report()
210 static inline int steam_send_report_byte(struct steam_device *steam, u8 cmd) in steam_send_report_byte() argument
212 return steam_send_report(steam, &cmd, 1); in steam_send_report_byte()
215 static int steam_write_registers(struct steam_device *steam, in steam_write_registers() argument
224 va_start(args, steam); in steam_write_registers()
237 return steam_send_report(steam, cmd, 2 + cmd[1]); in steam_write_registers()
240 static int steam_get_serial(struct steam_device *steam) in steam_get_serial() argument
250 ret = steam_send_report(steam, cmd, sizeof(cmd)); in steam_get_serial()
253 ret = steam_recv_report(steam, reply, sizeof(reply)); in steam_get_serial()
259 strscpy(steam->serial_no, reply + 3, sizeof(steam->serial_no)); in steam_get_serial()
268 static inline int steam_request_conn_status(struct steam_device *steam) in steam_request_conn_status() argument
270 return steam_send_report_byte(steam, STEAM_CMD_REQUEST_COMM_STATUS); in steam_request_conn_status()
273 static void steam_set_lizard_mode(struct steam_device *steam, bool enable) in steam_set_lizard_mode() argument
277 steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MAPPINGS); in steam_set_lizard_mode()
279 steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MOUSE); in steam_set_lizard_mode()
280 steam_write_registers(steam, in steam_set_lizard_mode()
285 steam_send_report_byte(steam, STEAM_CMD_CLEAR_MAPPINGS); in steam_set_lizard_mode()
286 steam_write_registers(steam, in steam_set_lizard_mode()
295 struct steam_device *steam = input_get_drvdata(dev); in steam_input_open() local
297 mutex_lock(&steam->mutex); in steam_input_open()
298 if (!steam->client_opened && lizard_mode) in steam_input_open()
299 steam_set_lizard_mode(steam, false); in steam_input_open()
300 mutex_unlock(&steam->mutex); in steam_input_open()
306 struct steam_device *steam = input_get_drvdata(dev); in steam_input_close() local
308 mutex_lock(&steam->mutex); in steam_input_close()
309 if (!steam->client_opened && lizard_mode) in steam_input_close()
310 steam_set_lizard_mode(steam, true); in steam_input_close()
311 mutex_unlock(&steam->mutex); in steam_input_close()
325 struct steam_device *steam = power_supply_get_drvdata(psy); in steam_battery_get_property() local
331 spin_lock_irqsave(&steam->lock, flags); in steam_battery_get_property()
332 volts = steam->voltage; in steam_battery_get_property()
333 batt = steam->battery_charge; in steam_battery_get_property()
334 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_get_property()
356 static int steam_battery_register(struct steam_device *steam) in steam_battery_register() argument
359 struct power_supply_config battery_cfg = { .drv_data = steam, }; in steam_battery_register()
363 steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in steam_battery_register()
364 steam->battery_desc.properties = steam_battery_props; in steam_battery_register()
365 steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props); in steam_battery_register()
366 steam->battery_desc.get_property = steam_battery_get_property; in steam_battery_register()
367 steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev, in steam_battery_register()
369 steam->serial_no); in steam_battery_register()
370 if (!steam->battery_desc.name) in steam_battery_register()
374 spin_lock_irqsave(&steam->lock, flags); in steam_battery_register()
375 steam->voltage = 3000; in steam_battery_register()
376 steam->battery_charge = 100; in steam_battery_register()
377 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_register()
379 battery = power_supply_register(&steam->hdev->dev, in steam_battery_register()
380 &steam->battery_desc, &battery_cfg); in steam_battery_register()
383 hid_err(steam->hdev, in steam_battery_register()
388 rcu_assign_pointer(steam->battery, battery); in steam_battery_register()
389 power_supply_powers(battery, &steam->hdev->dev); in steam_battery_register()
393 static int steam_input_register(struct steam_device *steam) in steam_input_register() argument
395 struct hid_device *hdev = steam->hdev; in steam_input_register()
400 input = rcu_dereference(steam->input); in steam_input_register()
411 input_set_drvdata(input, steam); in steam_input_register()
416 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? in steam_input_register()
420 input->uniq = steam->serial_no; in steam_input_register()
473 rcu_assign_pointer(steam->input, input); in steam_input_register()
481 static void steam_input_unregister(struct steam_device *steam) in steam_input_unregister() argument
485 input = rcu_dereference(steam->input); in steam_input_unregister()
489 RCU_INIT_POINTER(steam->input, NULL); in steam_input_unregister()
494 static void steam_battery_unregister(struct steam_device *steam) in steam_battery_unregister() argument
499 battery = rcu_dereference(steam->battery); in steam_battery_unregister()
504 RCU_INIT_POINTER(steam->battery, NULL); in steam_battery_unregister()
509 static int steam_register(struct steam_device *steam) in steam_register() argument
520 if (!steam->serial_no[0]) { in steam_register()
525 mutex_lock(&steam->mutex); in steam_register()
526 if (steam_get_serial(steam) < 0) in steam_register()
527 strscpy(steam->serial_no, "XXXXXXXXXX", in steam_register()
528 sizeof(steam->serial_no)); in steam_register()
529 mutex_unlock(&steam->mutex); in steam_register()
531 hid_info(steam->hdev, "Steam Controller '%s' connected", in steam_register()
532 steam->serial_no); in steam_register()
535 if (steam->quirks & STEAM_QUIRK_WIRELESS) in steam_register()
536 steam_battery_register(steam); in steam_register()
539 if (list_empty(&steam->list)) in steam_register()
540 list_add(&steam->list, &steam_devices); in steam_register()
544 mutex_lock(&steam->mutex); in steam_register()
545 client_opened = steam->client_opened; in steam_register()
547 steam_set_lizard_mode(steam, lizard_mode); in steam_register()
548 mutex_unlock(&steam->mutex); in steam_register()
551 ret = steam_input_register(steam); in steam_register()
558 static void steam_unregister(struct steam_device *steam) in steam_unregister() argument
560 steam_battery_unregister(steam); in steam_unregister()
561 steam_input_unregister(steam); in steam_unregister()
562 if (steam->serial_no[0]) { in steam_unregister()
563 hid_info(steam->hdev, "Steam Controller '%s' disconnected", in steam_unregister()
564 steam->serial_no); in steam_unregister()
566 list_del_init(&steam->list); in steam_unregister()
568 steam->serial_no[0] = 0; in steam_unregister()
574 struct steam_device *steam = container_of(work, struct steam_device, in steam_work_connect_cb() local
580 spin_lock_irqsave(&steam->lock, flags); in steam_work_connect_cb()
581 connected = steam->connected; in steam_work_connect_cb()
582 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_connect_cb()
585 ret = steam_register(steam); in steam_work_connect_cb()
587 hid_err(steam->hdev, in steam_work_connect_cb()
592 steam_unregister(steam); in steam_work_connect_cb()
617 struct steam_device *steam = hdev->driver_data; in steam_client_ll_parse() local
619 return hid_parse_report(hdev, steam->hdev->dev_rdesc, in steam_client_ll_parse()
620 steam->hdev->dev_rsize); in steam_client_ll_parse()
634 struct steam_device *steam = hdev->driver_data; in steam_client_ll_open() local
636 mutex_lock(&steam->mutex); in steam_client_ll_open()
637 steam->client_opened = true; in steam_client_ll_open()
638 mutex_unlock(&steam->mutex); in steam_client_ll_open()
640 steam_input_unregister(steam); in steam_client_ll_open()
647 struct steam_device *steam = hdev->driver_data; in steam_client_ll_close() local
652 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_close()
653 connected = steam->connected; in steam_client_ll_close()
654 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_close()
656 mutex_lock(&steam->mutex); in steam_client_ll_close()
657 steam->client_opened = false; in steam_client_ll_close()
659 steam_set_lizard_mode(steam, lizard_mode); in steam_client_ll_close()
660 mutex_unlock(&steam->mutex); in steam_client_ll_close()
663 steam_input_register(steam); in steam_client_ll_close()
671 struct steam_device *steam = hdev->driver_data; in steam_client_ll_raw_request() local
673 return hid_hw_raw_request(steam->hdev, reportnum, buf, count, in steam_client_ll_raw_request()
718 struct steam_device *steam; in steam_probe() local
741 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); in steam_probe()
742 if (!steam) { in steam_probe()
746 steam->hdev = hdev; in steam_probe()
747 hid_set_drvdata(hdev, steam); in steam_probe()
748 spin_lock_init(&steam->lock); in steam_probe()
749 mutex_init(&steam->mutex); in steam_probe()
750 steam->quirks = id->driver_data; in steam_probe()
751 INIT_WORK(&steam->work_connect, steam_work_connect_cb); in steam_probe()
752 INIT_LIST_HEAD(&steam->list); in steam_probe()
754 steam->client_hdev = steam_create_client_hid(hdev); in steam_probe()
755 if (IS_ERR(steam->client_hdev)) { in steam_probe()
756 ret = PTR_ERR(steam->client_hdev); in steam_probe()
759 steam->client_hdev->driver_data = steam; in steam_probe()
769 ret = hid_add_device(steam->client_hdev); in steam_probe()
781 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_probe()
784 steam->connected = false; in steam_probe()
785 steam_request_conn_status(steam); in steam_probe()
788 steam->connected = true; in steam_probe()
789 ret = steam_register(steam); in steam_probe()
805 hid_destroy_device(steam->client_hdev); in steam_probe()
807 cancel_work_sync(&steam->work_connect); in steam_probe()
816 struct steam_device *steam = hid_get_drvdata(hdev); in steam_remove() local
818 if (!steam || hdev->group == HID_GROUP_STEAM) { in steam_remove()
823 hid_destroy_device(steam->client_hdev); in steam_remove()
824 steam->client_opened = false; in steam_remove()
825 cancel_work_sync(&steam->work_connect); in steam_remove()
826 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_remove()
831 steam_unregister(steam); in steam_remove()
834 static void steam_do_connect_event(struct steam_device *steam, bool connected) in steam_do_connect_event() argument
839 spin_lock_irqsave(&steam->lock, flags); in steam_do_connect_event()
840 changed = steam->connected != connected; in steam_do_connect_event()
841 steam->connected = connected; in steam_do_connect_event()
842 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_connect_event()
844 if (changed && schedule_work(&steam->work_connect) == 0) in steam_do_connect_event()
927 static void steam_do_input_event(struct steam_device *steam, in steam_do_input_event() argument
1006 static void steam_do_battery_event(struct steam_device *steam, in steam_do_battery_event() argument
1016 battery = rcu_dereference(steam->battery); in steam_do_battery_event()
1018 spin_lock_irqsave(&steam->lock, flags); in steam_do_battery_event()
1019 steam->voltage = volts; in steam_do_battery_event()
1020 steam->battery_charge = batt; in steam_do_battery_event()
1021 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_battery_event()
1031 struct steam_device *steam = hid_get_drvdata(hdev); in steam_raw_event() local
1035 if (!steam) in steam_raw_event()
1038 if (steam->client_opened) in steam_raw_event()
1039 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, in steam_raw_event()
1062 if (steam->client_opened) in steam_raw_event()
1065 input = rcu_dereference(steam->input); in steam_raw_event()
1067 steam_do_input_event(steam, input, data); in steam_raw_event()
1078 steam_do_connect_event(steam, false); in steam_raw_event()
1081 steam_do_connect_event(steam, true); in steam_raw_event()
1086 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_raw_event()
1088 battery = rcu_dereference(steam->battery); in steam_raw_event()
1090 steam_do_battery_event(steam, battery, data); in steam_raw_event()
1095 steam_do_connect_event(steam, true); in steam_raw_event()
1107 struct steam_device *steam; in steam_param_set_lizard_mode() local
1115 list_for_each_entry(steam, &steam_devices, list) { in steam_param_set_lizard_mode()
1116 mutex_lock(&steam->mutex); in steam_param_set_lizard_mode()
1117 if (!steam->client_opened) in steam_param_set_lizard_mode()
1118 steam_set_lizard_mode(steam, lizard_mode); in steam_param_set_lizard_mode()
1119 mutex_unlock(&steam->mutex); in steam_param_set_lizard_mode()