Lines Matching refs:steam

143 static int steam_recv_report(struct steam_device *steam,
150 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
152 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n");
169 ret = hid_hw_raw_request(steam->hdev, 0x00,
178 static int steam_send_report(struct steam_device *steam,
186 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
188 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n");
209 ret = hid_hw_raw_request(steam->hdev, 0,
219 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__,
224 static inline int steam_send_report_byte(struct steam_device *steam, u8 cmd)
226 return steam_send_report(steam, &cmd, 1);
229 static int steam_write_registers(struct steam_device *steam,
239 va_start(args, steam);
252 ret = steam_send_report(steam, cmd, 2 + cmd[1]);
261 return steam_recv_report(steam, cmd, 2 + cmd[1]);
264 static int steam_get_serial(struct steam_device *steam)
274 ret = steam_send_report(steam, cmd, sizeof(cmd));
277 ret = steam_recv_report(steam, reply, sizeof(reply));
283 strscpy(steam->serial_no, reply + 3, sizeof(steam->serial_no));
292 static inline int steam_request_conn_status(struct steam_device *steam)
294 return steam_send_report_byte(steam, STEAM_CMD_REQUEST_COMM_STATUS);
297 static inline int steam_haptic_rumble(struct steam_device *steam,
312 return steam_send_report(steam, report, sizeof(report));
317 struct steam_device *steam = container_of(work, struct steam_device,
319 steam_haptic_rumble(steam, 0, steam->rumble_left,
320 steam->rumble_right, 2, 0);
327 struct steam_device *steam = input_get_drvdata(dev);
329 steam->rumble_left = effect->u.rumble.strong_magnitude;
330 steam->rumble_right = effect->u.rumble.weak_magnitude;
332 return schedule_work(&steam->rumble_work);
336 static void steam_set_lizard_mode(struct steam_device *steam, bool enable)
340 steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MAPPINGS);
342 steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MOUSE);
343 steam_write_registers(steam,
347 cancel_delayed_work_sync(&steam->heartbeat);
350 steam_send_report_byte(steam, STEAM_CMD_CLEAR_MAPPINGS);
352 if (steam->quirks & STEAM_QUIRK_DECK) {
353 steam_write_registers(steam,
364 if (!work_busy(&steam->heartbeat.work))
365 schedule_delayed_work(&steam->heartbeat, 5 * HZ);
367 steam_write_registers(steam,
378 struct steam_device *steam = input_get_drvdata(dev);
380 mutex_lock(&steam->mutex);
381 if (!steam->client_opened && lizard_mode)
382 steam_set_lizard_mode(steam, false);
383 mutex_unlock(&steam->mutex);
389 struct steam_device *steam = input_get_drvdata(dev);
391 mutex_lock(&steam->mutex);
392 if (!steam->client_opened && lizard_mode)
393 steam_set_lizard_mode(steam, true);
394 mutex_unlock(&steam->mutex);
408 struct steam_device *steam = power_supply_get_drvdata(psy);
414 spin_lock_irqsave(&steam->lock, flags);
415 volts = steam->voltage;
416 batt = steam->battery_charge;
417 spin_unlock_irqrestore(&steam->lock, flags);
439 static int steam_battery_register(struct steam_device *steam)
442 struct power_supply_config battery_cfg = { .drv_data = steam, };
446 steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
447 steam->battery_desc.properties = steam_battery_props;
448 steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props);
449 steam->battery_desc.get_property = steam_battery_get_property;
450 steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev,
451 GFP_KERNEL, "steam-controller-%s-battery",
452 steam->serial_no);
453 if (!steam->battery_desc.name)
457 spin_lock_irqsave(&steam->lock, flags);
458 steam->voltage = 3000;
459 steam->battery_charge = 100;
460 spin_unlock_irqrestore(&steam->lock, flags);
462 battery = power_supply_register(&steam->hdev->dev,
463 &steam->battery_desc, &battery_cfg);
466 hid_err(steam->hdev,
471 rcu_assign_pointer(steam->battery, battery);
472 power_supply_powers(battery, &steam->hdev->dev);
476 static int steam_input_register(struct steam_device *steam)
478 struct hid_device *hdev = steam->hdev;
483 input = rcu_dereference(steam->input);
494 input_set_drvdata(input, steam);
499 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? "Wireless Steam Controller" :
500 (steam->quirks & STEAM_QUIRK_DECK) ? "Steam Deck" :
503 input->uniq = steam->serial_no;
528 if (steam->quirks & STEAM_QUIRK_DECK) {
547 if (steam->quirks & STEAM_QUIRK_DECK) {
587 if (steam->quirks & STEAM_QUIRK_DECK) {
599 rcu_assign_pointer(steam->input, input);
607 static void steam_input_unregister(struct steam_device *steam)
611 input = rcu_dereference(steam->input);
615 RCU_INIT_POINTER(steam->input, NULL);
620 static void steam_battery_unregister(struct steam_device *steam)
625 battery = rcu_dereference(steam->battery);
630 RCU_INIT_POINTER(steam->battery, NULL);
635 static int steam_register(struct steam_device *steam)
646 if (!steam->serial_no[0]) {
651 mutex_lock(&steam->mutex);
652 if (steam_get_serial(steam) < 0)
653 strscpy(steam->serial_no, "XXXXXXXXXX",
654 sizeof(steam->serial_no));
655 mutex_unlock(&steam->mutex);
657 hid_info(steam->hdev, "Steam Controller '%s' connected",
658 steam->serial_no);
661 if (steam->quirks & STEAM_QUIRK_WIRELESS)
662 steam_battery_register(steam);
665 if (list_empty(&steam->list))
666 list_add(&steam->list, &steam_devices);
670 mutex_lock(&steam->mutex);
671 client_opened = steam->client_opened;
673 steam_set_lizard_mode(steam, lizard_mode);
674 mutex_unlock(&steam->mutex);
677 ret = steam_input_register(steam);
684 static void steam_unregister(struct steam_device *steam)
686 steam_battery_unregister(steam);
687 steam_input_unregister(steam);
688 if (steam->serial_no[0]) {
689 hid_info(steam->hdev, "Steam Controller '%s' disconnected",
690 steam->serial_no);
692 list_del_init(&steam->list);
694 steam->serial_no[0] = 0;
700 struct steam_device *steam = container_of(work, struct steam_device,
706 spin_lock_irqsave(&steam->lock, flags);
707 connected = steam->connected;
708 spin_unlock_irqrestore(&steam->lock, flags);
711 ret = steam_register(steam);
713 hid_err(steam->hdev,
718 steam_unregister(steam);
743 struct steam_device *steam = container_of(work, struct steam_device,
746 mutex_lock(&steam->mutex);
747 if (!steam->client_opened && steam->client_hdev) {
748 steam_send_report_byte(steam, STEAM_CMD_CLEAR_MAPPINGS);
749 steam_write_registers(steam,
752 schedule_delayed_work(&steam->heartbeat, 5 * HZ);
754 mutex_unlock(&steam->mutex);
759 struct steam_device *steam = hdev->driver_data;
761 return hid_parse_report(hdev, steam->hdev->dev_rdesc,
762 steam->hdev->dev_rsize);
776 struct steam_device *steam = hdev->driver_data;
778 mutex_lock(&steam->mutex);
779 steam->client_opened = true;
780 mutex_unlock(&steam->mutex);
782 steam_input_unregister(steam);
789 struct steam_device *steam = hdev->driver_data;
794 spin_lock_irqsave(&steam->lock, flags);
795 connected = steam->connected;
796 spin_unlock_irqrestore(&steam->lock, flags);
798 mutex_lock(&steam->mutex);
799 steam->client_opened = false;
801 steam_set_lizard_mode(steam, lizard_mode);
802 mutex_unlock(&steam->mutex);
805 steam_input_register(steam);
813 struct steam_device *steam = hdev->driver_data;
815 return hid_hw_raw_request(steam->hdev, reportnum, buf, count,
860 struct steam_device *steam;
883 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL);
884 if (!steam) {
888 steam->hdev = hdev;
889 hid_set_drvdata(hdev, steam);
890 spin_lock_init(&steam->lock);
891 mutex_init(&steam->mutex);
892 steam->quirks = id->driver_data;
893 INIT_WORK(&steam->work_connect, steam_work_connect_cb);
894 INIT_LIST_HEAD(&steam->list);
895 INIT_DEFERRABLE_WORK(&steam->heartbeat, steam_lizard_mode_heartbeat);
896 INIT_WORK(&steam->rumble_work, steam_haptic_rumble_cb);
898 steam->client_hdev = steam_create_client_hid(hdev);
899 if (IS_ERR(steam->client_hdev)) {
900 ret = PTR_ERR(steam->client_hdev);
903 steam->client_hdev->driver_data = steam;
906 * With the real steam controller interface, do not connect hidraw.
913 ret = hid_add_device(steam->client_hdev);
925 if (steam->quirks & STEAM_QUIRK_WIRELESS) {
928 steam->connected = false;
929 steam_request_conn_status(steam);
932 steam->connected = true;
933 ret = steam_register(steam);
949 hid_destroy_device(steam->client_hdev);
951 cancel_work_sync(&steam->work_connect);
952 cancel_delayed_work_sync(&steam->heartbeat);
953 cancel_work_sync(&steam->rumble_work);
962 struct steam_device *steam = hid_get_drvdata(hdev);
964 if (!steam || hdev->group == HID_GROUP_STEAM) {
969 hid_destroy_device(steam->client_hdev);
970 mutex_lock(&steam->mutex);
971 steam->client_hdev = NULL;
972 steam->client_opened = false;
973 cancel_delayed_work_sync(&steam->heartbeat);
974 mutex_unlock(&steam->mutex);
975 cancel_work_sync(&steam->work_connect);
976 if (steam->quirks & STEAM_QUIRK_WIRELESS) {
981 steam_unregister(steam);
984 static void steam_do_connect_event(struct steam_device *steam, bool connected)
989 spin_lock_irqsave(&steam->lock, flags);
990 changed = steam->connected != connected;
991 steam->connected = connected;
992 spin_unlock_irqrestore(&steam->lock, flags);
994 if (changed && schedule_work(&steam->work_connect) == 0)
1064 * 9.5 | BTN_MODE | steam logo
1077 static void steam_do_input_event(struct steam_device *steam,
1192 * 9.5 | BTN_MODE | steam logo
1244 static void steam_do_deck_input_event(struct steam_device *steam,
1322 static void steam_do_battery_event(struct steam_device *steam,
1332 battery = rcu_dereference(steam->battery);
1334 spin_lock_irqsave(&steam->lock, flags);
1335 steam->voltage = volts;
1336 steam->battery_charge = batt;
1337 spin_unlock_irqrestore(&steam->lock, flags);
1347 struct steam_device *steam = hid_get_drvdata(hdev);
1351 if (!steam)
1354 if (steam->client_opened)
1355 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT,
1379 if (steam->client_opened)
1382 input = rcu_dereference(steam->input);
1384 steam_do_input_event(steam, input, data);
1388 if (steam->client_opened)
1391 input = rcu_dereference(steam->input);
1393 steam_do_deck_input_event(steam, input, data);
1404 steam_do_connect_event(steam, false);
1407 steam_do_connect_event(steam, true);
1412 if (steam->quirks & STEAM_QUIRK_WIRELESS) {
1414 battery = rcu_dereference(steam->battery);
1416 steam_do_battery_event(steam, battery, data);
1421 steam_do_connect_event(steam, true);
1433 struct steam_device *steam;
1441 list_for_each_entry(steam, &steam_devices, list) {
1442 mutex_lock(&steam->mutex);
1443 if (!steam->client_opened)
1444 steam_set_lizard_mode(steam, lizard_mode);
1445 mutex_unlock(&steam->mutex);
1481 .name = "hid-steam",