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()
150 ret = hid_hw_raw_request(steam->hdev, 0x00, in steam_recv_report()
159 static int steam_send_report(struct steam_device *steam, in steam_send_report() argument
167 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_send_report()
185 ret = hid_hw_raw_request(steam->hdev, 0, in steam_send_report()
195 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, in steam_send_report()
200 static inline int steam_send_report_byte(struct steam_device *steam, u8 cmd) in steam_send_report_byte() argument
202 return steam_send_report(steam, &cmd, 1); in steam_send_report_byte()
205 static int steam_write_registers(struct steam_device *steam, in steam_write_registers() argument
214 va_start(args, steam); in steam_write_registers()
227 return steam_send_report(steam, cmd, 2 + cmd[1]); in steam_write_registers()
230 static int steam_get_serial(struct steam_device *steam) in steam_get_serial() argument
240 ret = steam_send_report(steam, cmd, sizeof(cmd)); in steam_get_serial()
243 ret = steam_recv_report(steam, reply, sizeof(reply)); in steam_get_serial()
249 strlcpy(steam->serial_no, reply + 3, sizeof(steam->serial_no)); in steam_get_serial()
258 static inline int steam_request_conn_status(struct steam_device *steam) in steam_request_conn_status() argument
260 return steam_send_report_byte(steam, STEAM_CMD_REQUEST_COMM_STATUS); in steam_request_conn_status()
263 static void steam_set_lizard_mode(struct steam_device *steam, bool enable) in steam_set_lizard_mode() argument
267 steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MAPPINGS); in steam_set_lizard_mode()
269 steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MOUSE); in steam_set_lizard_mode()
270 steam_write_registers(steam, in steam_set_lizard_mode()
275 steam_send_report_byte(steam, STEAM_CMD_CLEAR_MAPPINGS); in steam_set_lizard_mode()
276 steam_write_registers(steam, in steam_set_lizard_mode()
285 struct steam_device *steam = input_get_drvdata(dev); in steam_input_open() local
287 mutex_lock(&steam->mutex); in steam_input_open()
288 if (!steam->client_opened && lizard_mode) in steam_input_open()
289 steam_set_lizard_mode(steam, false); in steam_input_open()
290 mutex_unlock(&steam->mutex); in steam_input_open()
296 struct steam_device *steam = input_get_drvdata(dev); in steam_input_close() local
298 mutex_lock(&steam->mutex); in steam_input_close()
299 if (!steam->client_opened && lizard_mode) in steam_input_close()
300 steam_set_lizard_mode(steam, true); in steam_input_close()
301 mutex_unlock(&steam->mutex); in steam_input_close()
315 struct steam_device *steam = power_supply_get_drvdata(psy); in steam_battery_get_property() local
321 spin_lock_irqsave(&steam->lock, flags); in steam_battery_get_property()
322 volts = steam->voltage; in steam_battery_get_property()
323 batt = steam->battery_charge; in steam_battery_get_property()
324 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_get_property()
346 static int steam_battery_register(struct steam_device *steam) in steam_battery_register() argument
349 struct power_supply_config battery_cfg = { .drv_data = steam, }; in steam_battery_register()
353 steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in steam_battery_register()
354 steam->battery_desc.properties = steam_battery_props; in steam_battery_register()
355 steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props); in steam_battery_register()
356 steam->battery_desc.get_property = steam_battery_get_property; in steam_battery_register()
357 steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev, in steam_battery_register()
359 steam->serial_no); in steam_battery_register()
360 if (!steam->battery_desc.name) in steam_battery_register()
364 spin_lock_irqsave(&steam->lock, flags); in steam_battery_register()
365 steam->voltage = 3000; in steam_battery_register()
366 steam->battery_charge = 100; in steam_battery_register()
367 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_register()
369 battery = power_supply_register(&steam->hdev->dev, in steam_battery_register()
370 &steam->battery_desc, &battery_cfg); in steam_battery_register()
373 hid_err(steam->hdev, in steam_battery_register()
378 rcu_assign_pointer(steam->battery, battery); in steam_battery_register()
379 power_supply_powers(battery, &steam->hdev->dev); in steam_battery_register()
383 static int steam_input_register(struct steam_device *steam) in steam_input_register() argument
385 struct hid_device *hdev = steam->hdev; in steam_input_register()
390 input = rcu_dereference(steam->input); in steam_input_register()
401 input_set_drvdata(input, steam); in steam_input_register()
406 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? in steam_input_register()
410 input->uniq = steam->serial_no; in steam_input_register()
463 rcu_assign_pointer(steam->input, input); in steam_input_register()
471 static void steam_input_unregister(struct steam_device *steam) in steam_input_unregister() argument
475 input = rcu_dereference(steam->input); in steam_input_unregister()
479 RCU_INIT_POINTER(steam->input, NULL); in steam_input_unregister()
484 static void steam_battery_unregister(struct steam_device *steam) in steam_battery_unregister() argument
489 battery = rcu_dereference(steam->battery); in steam_battery_unregister()
494 RCU_INIT_POINTER(steam->battery, NULL); in steam_battery_unregister()
499 static int steam_register(struct steam_device *steam) in steam_register() argument
510 if (!steam->serial_no[0]) { in steam_register()
515 mutex_lock(&steam->mutex); in steam_register()
516 if (steam_get_serial(steam) < 0) in steam_register()
517 strlcpy(steam->serial_no, "XXXXXXXXXX", in steam_register()
518 sizeof(steam->serial_no)); in steam_register()
519 mutex_unlock(&steam->mutex); in steam_register()
521 hid_info(steam->hdev, "Steam Controller '%s' connected", in steam_register()
522 steam->serial_no); in steam_register()
525 if (steam->quirks & STEAM_QUIRK_WIRELESS) in steam_register()
526 steam_battery_register(steam); in steam_register()
529 list_add(&steam->list, &steam_devices); in steam_register()
533 mutex_lock(&steam->mutex); in steam_register()
534 client_opened = steam->client_opened; in steam_register()
536 steam_set_lizard_mode(steam, lizard_mode); in steam_register()
537 mutex_unlock(&steam->mutex); in steam_register()
540 ret = steam_input_register(steam); in steam_register()
547 static void steam_unregister(struct steam_device *steam) in steam_unregister() argument
549 steam_battery_unregister(steam); in steam_unregister()
550 steam_input_unregister(steam); in steam_unregister()
551 if (steam->serial_no[0]) { in steam_unregister()
552 hid_info(steam->hdev, "Steam Controller '%s' disconnected", in steam_unregister()
553 steam->serial_no); in steam_unregister()
555 list_del(&steam->list); in steam_unregister()
557 steam->serial_no[0] = 0; in steam_unregister()
563 struct steam_device *steam = container_of(work, struct steam_device, in steam_work_connect_cb() local
569 spin_lock_irqsave(&steam->lock, flags); in steam_work_connect_cb()
570 connected = steam->connected; in steam_work_connect_cb()
571 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_connect_cb()
574 ret = steam_register(steam); in steam_work_connect_cb()
576 hid_err(steam->hdev, in steam_work_connect_cb()
581 steam_unregister(steam); in steam_work_connect_cb()
606 struct steam_device *steam = hdev->driver_data; in steam_client_ll_parse() local
608 return hid_parse_report(hdev, steam->hdev->dev_rdesc, in steam_client_ll_parse()
609 steam->hdev->dev_rsize); in steam_client_ll_parse()
623 struct steam_device *steam = hdev->driver_data; in steam_client_ll_open() local
625 mutex_lock(&steam->mutex); in steam_client_ll_open()
626 steam->client_opened = true; in steam_client_ll_open()
627 mutex_unlock(&steam->mutex); in steam_client_ll_open()
629 steam_input_unregister(steam); in steam_client_ll_open()
636 struct steam_device *steam = hdev->driver_data; in steam_client_ll_close() local
641 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_close()
642 connected = steam->connected; in steam_client_ll_close()
643 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_close()
645 mutex_lock(&steam->mutex); in steam_client_ll_close()
646 steam->client_opened = false; in steam_client_ll_close()
648 steam_set_lizard_mode(steam, lizard_mode); in steam_client_ll_close()
649 mutex_unlock(&steam->mutex); in steam_client_ll_close()
652 steam_input_register(steam); in steam_client_ll_close()
660 struct steam_device *steam = hdev->driver_data; in steam_client_ll_raw_request() local
662 return hid_hw_raw_request(steam->hdev, reportnum, buf, count, in steam_client_ll_raw_request()
707 struct steam_device *steam; in steam_probe() local
730 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); in steam_probe()
731 if (!steam) { in steam_probe()
735 steam->hdev = hdev; in steam_probe()
736 hid_set_drvdata(hdev, steam); in steam_probe()
737 spin_lock_init(&steam->lock); in steam_probe()
738 mutex_init(&steam->mutex); in steam_probe()
739 steam->quirks = id->driver_data; in steam_probe()
740 INIT_WORK(&steam->work_connect, steam_work_connect_cb); in steam_probe()
742 steam->client_hdev = steam_create_client_hid(hdev); in steam_probe()
743 if (IS_ERR(steam->client_hdev)) { in steam_probe()
744 ret = PTR_ERR(steam->client_hdev); in steam_probe()
747 steam->client_hdev->driver_data = steam; in steam_probe()
757 ret = hid_add_device(steam->client_hdev); in steam_probe()
769 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_probe()
771 steam_request_conn_status(steam); in steam_probe()
773 ret = steam_register(steam); in steam_probe()
789 hid_destroy_device(steam->client_hdev); in steam_probe()
791 cancel_work_sync(&steam->work_connect); in steam_probe()
800 struct steam_device *steam = hid_get_drvdata(hdev); in steam_remove() local
802 if (!steam || hdev->group == HID_GROUP_STEAM) { in steam_remove()
807 hid_destroy_device(steam->client_hdev); in steam_remove()
808 steam->client_opened = false; in steam_remove()
809 cancel_work_sync(&steam->work_connect); in steam_remove()
810 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_remove()
815 steam_unregister(steam); in steam_remove()
818 static void steam_do_connect_event(struct steam_device *steam, bool connected) in steam_do_connect_event() argument
823 spin_lock_irqsave(&steam->lock, flags); in steam_do_connect_event()
824 changed = steam->connected != connected; in steam_do_connect_event()
825 steam->connected = connected; in steam_do_connect_event()
826 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_connect_event()
828 if (changed && schedule_work(&steam->work_connect) == 0) in steam_do_connect_event()
911 static void steam_do_input_event(struct steam_device *steam, in steam_do_input_event() argument
990 static void steam_do_battery_event(struct steam_device *steam, in steam_do_battery_event() argument
1000 battery = rcu_dereference(steam->battery); in steam_do_battery_event()
1002 spin_lock_irqsave(&steam->lock, flags); in steam_do_battery_event()
1003 steam->voltage = volts; in steam_do_battery_event()
1004 steam->battery_charge = batt; in steam_do_battery_event()
1005 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_battery_event()
1015 struct steam_device *steam = hid_get_drvdata(hdev); in steam_raw_event() local
1019 if (!steam) in steam_raw_event()
1022 if (steam->client_opened) in steam_raw_event()
1023 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, in steam_raw_event()
1046 if (steam->client_opened) in steam_raw_event()
1049 input = rcu_dereference(steam->input); in steam_raw_event()
1051 steam_do_input_event(steam, input, data); in steam_raw_event()
1062 steam_do_connect_event(steam, false); in steam_raw_event()
1065 steam_do_connect_event(steam, true); in steam_raw_event()
1070 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_raw_event()
1072 battery = rcu_dereference(steam->battery); in steam_raw_event()
1074 steam_do_battery_event(steam, battery, data); in steam_raw_event()
1079 steam_do_connect_event(steam, true); in steam_raw_event()
1091 struct steam_device *steam; in steam_param_set_lizard_mode() local
1099 list_for_each_entry(steam, &steam_devices, list) { in steam_param_set_lizard_mode()
1100 mutex_lock(&steam->mutex); in steam_param_set_lizard_mode()
1101 if (!steam->client_opened) in steam_param_set_lizard_mode()
1102 steam_set_lizard_mode(steam, lizard_mode); in steam_param_set_lizard_mode()
1103 mutex_unlock(&steam->mutex); in steam_param_set_lizard_mode()