• Home
  • Raw
  • Download

Lines Matching +full:input +full:- +full:value

1 // SPDX-License-Identifier: GPL-2.0+
18 * This driver will disable the lizard mode when the input device is opened
19 * and re-enable it when the input device is closed, so as not to break user
23 * the hidraw interface directly to create input devices (XTest, uinput...).
26 * - it will not send any command to the controller.
27 * - this input device will be removed, to avoid double input of the same
29 * When the client is closed, this input device will be created again.
31 * For additional functions, such as changing the right-pad margin or switching
32 * the led, you can use the user-space tool at:
38 #include <linux/input.h>
46 #include "hid-ids.h"
69 /* Accelerometer has 16 bit resolution and a range of +/- 2g */
73 /* Gyroscope has 16 bit resolution and a range of +/- 2000 dps */
242 /* Input report identifiers */
298 struct input_dev __rcu *input; member
325 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_recv_report()
327 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_recv_report()
328 return -EINVAL; in steam_recv_report()
332 return -EINVAL; in steam_recv_report()
336 return -ENOMEM; in steam_recv_report()
344 ret = hid_hw_raw_request(steam->hdev, 0x00, in steam_recv_report()
348 memcpy(data, buf + 1, min(size, ret - 1)); in steam_recv_report()
361 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_send_report()
363 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_send_report()
364 return -EINVAL; in steam_send_report()
368 return -EINVAL; in steam_send_report()
372 return -ENOMEM; in steam_send_report()
384 ret = hid_hw_raw_request(steam->hdev, 0, in steam_send_report()
387 if (ret != -EPIPE) in steam_send_report()
390 } while (--retries); in steam_send_report()
394 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, in steam_send_report()
449 mutex_lock(&steam->report_mutex); in steam_get_serial()
457 ret = -EIO; in steam_get_serial()
461 strscpy(steam->serial_no, reply + 3, sizeof(steam->serial_no)); in steam_get_serial()
463 mutex_unlock(&steam->report_mutex); in steam_get_serial()
475 mutex_lock(&steam->report_mutex); in steam_request_conn_status()
477 mutex_unlock(&steam->report_mutex); in steam_request_conn_status()
485 * and gain is measured in decibels, ranging from -24 to +6
506 mutex_lock(&steam->report_mutex); in steam_haptic_pulse()
508 mutex_unlock(&steam->report_mutex); in steam_haptic_pulse()
528 mutex_lock(&steam->report_mutex); in steam_haptic_rumble()
530 mutex_unlock(&steam->report_mutex); in steam_haptic_rumble()
538 steam_haptic_rumble(steam, 0, steam->rumble_left, in steam_haptic_rumble_cb()
539 steam->rumble_right, 2, 0); in steam_haptic_rumble_cb()
548 steam->rumble_left = effect->u.rumble.strong_magnitude; in steam_play_effect()
549 steam->rumble_right = effect->u.rumble.weak_magnitude; in steam_play_effect()
551 return schedule_work(&steam->rumble_work); in steam_play_effect()
557 if (steam->gamepad_mode) in steam_set_lizard_mode()
561 mutex_lock(&steam->report_mutex); in steam_set_lizard_mode()
566 mutex_unlock(&steam->report_mutex); in steam_set_lizard_mode()
568 mutex_lock(&steam->report_mutex); in steam_set_lizard_mode()
572 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_set_lizard_mode()
580 mutex_unlock(&steam->report_mutex); in steam_set_lizard_mode()
586 mutex_unlock(&steam->report_mutex); in steam_set_lizard_mode()
602 if (!(steam->quirks & STEAM_QUIRK_DECK)) { in steam_input_open()
603 spin_lock_irqsave(&steam->lock, flags); in steam_input_open()
604 set_lizard_mode = !steam->client_opened && lizard_mode; in steam_input_open()
605 spin_unlock_irqrestore(&steam->lock, flags); in steam_input_open()
619 if (!(steam->quirks & STEAM_QUIRK_DECK)) { in steam_input_close()
620 spin_lock_irqsave(&steam->lock, flags); in steam_input_close()
621 set_lizard_mode = !steam->client_opened && lizard_mode; in steam_input_close()
622 spin_unlock_irqrestore(&steam->lock, flags); in steam_input_close()
645 spin_lock_irqsave(&steam->lock, flags); in steam_battery_get_property()
646 volts = steam->voltage; in steam_battery_get_property()
647 batt = steam->battery_charge; in steam_battery_get_property()
648 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_get_property()
652 val->intval = 1; in steam_battery_get_property()
655 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in steam_battery_get_property()
658 val->intval = volts * 1000; /* mV -> uV */ in steam_battery_get_property()
661 val->intval = batt; in steam_battery_get_property()
664 ret = -EINVAL; in steam_battery_get_property()
677 steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in steam_battery_register()
678 steam->battery_desc.properties = steam_battery_props; in steam_battery_register()
679 steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props); in steam_battery_register()
680 steam->battery_desc.get_property = steam_battery_get_property; in steam_battery_register()
681 steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev, in steam_battery_register()
682 GFP_KERNEL, "steam-controller-%s-battery", in steam_battery_register()
683 steam->serial_no); in steam_battery_register()
684 if (!steam->battery_desc.name) in steam_battery_register()
685 return -ENOMEM; in steam_battery_register()
688 spin_lock_irqsave(&steam->lock, flags); in steam_battery_register()
689 steam->voltage = 3000; in steam_battery_register()
690 steam->battery_charge = 100; in steam_battery_register()
691 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_register()
693 battery = power_supply_register(&steam->hdev->dev, in steam_battery_register()
694 &steam->battery_desc, &battery_cfg); in steam_battery_register()
697 hid_err(steam->hdev, in steam_battery_register()
702 rcu_assign_pointer(steam->battery, battery); in steam_battery_register()
703 power_supply_powers(battery, &steam->hdev->dev); in steam_battery_register()
709 struct hid_device *hdev = steam->hdev; in steam_input_register()
710 struct input_dev *input; in steam_input_register() local
714 input = rcu_dereference(steam->input); in steam_input_register()
716 if (input) { in steam_input_register()
721 input = input_allocate_device(); in steam_input_register()
722 if (!input) in steam_input_register()
723 return -ENOMEM; in steam_input_register()
725 input_set_drvdata(input, steam); in steam_input_register()
726 input->dev.parent = &hdev->dev; in steam_input_register()
727 input->open = steam_input_open; in steam_input_register()
728 input->close = steam_input_close; in steam_input_register()
730 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? "Wireless Steam Controller" : in steam_input_register()
731 (steam->quirks & STEAM_QUIRK_DECK) ? "Steam Deck" : in steam_input_register()
733 input->phys = hdev->phys; in steam_input_register()
734 input->uniq = steam->serial_no; in steam_input_register()
735 input->id.bustype = hdev->bus; in steam_input_register()
736 input->id.vendor = hdev->vendor; in steam_input_register()
737 input->id.product = hdev->product; in steam_input_register()
738 input->id.version = hdev->version; in steam_input_register()
740 input_set_capability(input, EV_KEY, BTN_TR2); in steam_input_register()
741 input_set_capability(input, EV_KEY, BTN_TL2); in steam_input_register()
742 input_set_capability(input, EV_KEY, BTN_TR); in steam_input_register()
743 input_set_capability(input, EV_KEY, BTN_TL); in steam_input_register()
744 input_set_capability(input, EV_KEY, BTN_Y); in steam_input_register()
745 input_set_capability(input, EV_KEY, BTN_B); in steam_input_register()
746 input_set_capability(input, EV_KEY, BTN_X); in steam_input_register()
747 input_set_capability(input, EV_KEY, BTN_A); in steam_input_register()
748 input_set_capability(input, EV_KEY, BTN_DPAD_UP); in steam_input_register()
749 input_set_capability(input, EV_KEY, BTN_DPAD_RIGHT); in steam_input_register()
750 input_set_capability(input, EV_KEY, BTN_DPAD_LEFT); in steam_input_register()
751 input_set_capability(input, EV_KEY, BTN_DPAD_DOWN); in steam_input_register()
752 input_set_capability(input, EV_KEY, BTN_SELECT); in steam_input_register()
753 input_set_capability(input, EV_KEY, BTN_MODE); in steam_input_register()
754 input_set_capability(input, EV_KEY, BTN_START); in steam_input_register()
755 input_set_capability(input, EV_KEY, BTN_THUMBR); in steam_input_register()
756 input_set_capability(input, EV_KEY, BTN_THUMBL); in steam_input_register()
757 input_set_capability(input, EV_KEY, BTN_THUMB); in steam_input_register()
758 input_set_capability(input, EV_KEY, BTN_THUMB2); in steam_input_register()
759 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_input_register()
760 input_set_capability(input, EV_KEY, BTN_BASE); in steam_input_register()
761 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY1); in steam_input_register()
762 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY2); in steam_input_register()
763 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY3); in steam_input_register()
764 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY4); in steam_input_register()
766 input_set_capability(input, EV_KEY, BTN_GEAR_DOWN); in steam_input_register()
767 input_set_capability(input, EV_KEY, BTN_GEAR_UP); in steam_input_register()
770 input_set_abs_params(input, ABS_X, -32767, 32767, 0, 0); in steam_input_register()
771 input_set_abs_params(input, ABS_Y, -32767, 32767, 0, 0); in steam_input_register()
773 input_set_abs_params(input, ABS_HAT0X, -32767, 32767, in steam_input_register()
775 input_set_abs_params(input, ABS_HAT0Y, -32767, 32767, in steam_input_register()
778 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_input_register()
779 input_set_abs_params(input, ABS_HAT2Y, 0, 32767, 0, 0); in steam_input_register()
780 input_set_abs_params(input, ABS_HAT2X, 0, 32767, 0, 0); in steam_input_register()
782 input_set_abs_params(input, ABS_RX, -32767, 32767, 0, 0); in steam_input_register()
783 input_set_abs_params(input, ABS_RY, -32767, 32767, 0, 0); in steam_input_register()
785 input_set_abs_params(input, ABS_HAT1X, -32767, 32767, in steam_input_register()
787 input_set_abs_params(input, ABS_HAT1Y, -32767, 32767, in steam_input_register()
790 input_abs_set_res(input, ABS_X, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
791 input_abs_set_res(input, ABS_Y, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
792 input_abs_set_res(input, ABS_RX, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
793 input_abs_set_res(input, ABS_RY, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
794 input_abs_set_res(input, ABS_HAT1X, STEAM_PAD_RESOLUTION); in steam_input_register()
795 input_abs_set_res(input, ABS_HAT1Y, STEAM_PAD_RESOLUTION); in steam_input_register()
796 input_abs_set_res(input, ABS_HAT2Y, STEAM_DECK_TRIGGER_RESOLUTION); in steam_input_register()
797 input_abs_set_res(input, ABS_HAT2X, STEAM_DECK_TRIGGER_RESOLUTION); in steam_input_register()
799 input_set_abs_params(input, ABS_HAT2Y, 0, 255, 0, 0); in steam_input_register()
800 input_set_abs_params(input, ABS_HAT2X, 0, 255, 0, 0); in steam_input_register()
802 input_set_abs_params(input, ABS_RX, -32767, 32767, in steam_input_register()
804 input_set_abs_params(input, ABS_RY, -32767, 32767, in steam_input_register()
807 input_abs_set_res(input, ABS_X, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
808 input_abs_set_res(input, ABS_Y, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
809 input_abs_set_res(input, ABS_RX, STEAM_PAD_RESOLUTION); in steam_input_register()
810 input_abs_set_res(input, ABS_RY, STEAM_PAD_RESOLUTION); in steam_input_register()
811 input_abs_set_res(input, ABS_HAT2Y, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
812 input_abs_set_res(input, ABS_HAT2X, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
814 input_abs_set_res(input, ABS_HAT0X, STEAM_PAD_RESOLUTION); in steam_input_register()
815 input_abs_set_res(input, ABS_HAT0Y, STEAM_PAD_RESOLUTION); in steam_input_register()
818 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_input_register()
819 input_set_capability(input, EV_FF, FF_RUMBLE); in steam_input_register()
820 ret = input_ff_create_memless(input, NULL, steam_play_effect); in steam_input_register()
826 ret = input_register_device(input); in steam_input_register()
830 rcu_assign_pointer(steam->input, input); in steam_input_register()
834 input_free_device(input); in steam_input_register()
840 struct hid_device *hdev = steam->hdev; in steam_sensors_register()
844 if (!(steam->quirks & STEAM_QUIRK_DECK)) in steam_sensors_register()
848 sensors = rcu_dereference(steam->sensors); in steam_sensors_register()
857 return -ENOMEM; in steam_sensors_register()
860 sensors->dev.parent = &hdev->dev; in steam_sensors_register()
862 sensors->name = "Steam Deck Motion Sensors"; in steam_sensors_register()
863 sensors->phys = hdev->phys; in steam_sensors_register()
864 sensors->uniq = steam->serial_no; in steam_sensors_register()
865 sensors->id.bustype = hdev->bus; in steam_sensors_register()
866 sensors->id.vendor = hdev->vendor; in steam_sensors_register()
867 sensors->id.product = hdev->product; in steam_sensors_register()
868 sensors->id.version = hdev->version; in steam_sensors_register()
870 __set_bit(INPUT_PROP_ACCELEROMETER, sensors->propbit); in steam_sensors_register()
871 __set_bit(EV_MSC, sensors->evbit); in steam_sensors_register()
872 __set_bit(MSC_TIMESTAMP, sensors->mscbit); in steam_sensors_register()
874 input_set_abs_params(sensors, ABS_X, -STEAM_DECK_ACCEL_RANGE, in steam_sensors_register()
876 input_set_abs_params(sensors, ABS_Y, -STEAM_DECK_ACCEL_RANGE, in steam_sensors_register()
878 input_set_abs_params(sensors, ABS_Z, -STEAM_DECK_ACCEL_RANGE, in steam_sensors_register()
884 input_set_abs_params(sensors, ABS_RX, -STEAM_DECK_GYRO_RANGE, in steam_sensors_register()
886 input_set_abs_params(sensors, ABS_RY, -STEAM_DECK_GYRO_RANGE, in steam_sensors_register()
888 input_set_abs_params(sensors, ABS_RZ, -STEAM_DECK_GYRO_RANGE, in steam_sensors_register()
898 rcu_assign_pointer(steam->sensors, sensors); in steam_sensors_register()
908 struct input_dev *input; in steam_input_unregister() local
910 input = rcu_dereference(steam->input); in steam_input_unregister()
912 if (!input) in steam_input_unregister()
914 RCU_INIT_POINTER(steam->input, NULL); in steam_input_unregister()
916 input_unregister_device(input); in steam_input_unregister()
923 if (!(steam->quirks & STEAM_QUIRK_DECK)) in steam_sensors_unregister()
927 sensors = rcu_dereference(steam->sensors); in steam_sensors_unregister()
932 RCU_INIT_POINTER(steam->sensors, NULL); in steam_sensors_unregister()
942 battery = rcu_dereference(steam->battery); in steam_battery_unregister()
947 RCU_INIT_POINTER(steam->battery, NULL); in steam_battery_unregister()
964 if (!steam->serial_no[0]) { in steam_register()
970 strscpy(steam->serial_no, "XXXXXXXXXX", in steam_register()
971 sizeof(steam->serial_no)); in steam_register()
973 hid_info(steam->hdev, "Steam Controller '%s' connected", in steam_register()
974 steam->serial_no); in steam_register()
977 if (steam->quirks & STEAM_QUIRK_WIRELESS) in steam_register()
981 if (list_empty(&steam->list)) in steam_register()
982 list_add(&steam->list, &steam_devices); in steam_register()
986 spin_lock_irqsave(&steam->lock, flags); in steam_register()
987 client_opened = steam->client_opened; in steam_register()
988 spin_unlock_irqrestore(&steam->lock, flags); in steam_register()
1012 if (steam->serial_no[0]) { in steam_unregister()
1013 hid_info(steam->hdev, "Steam Controller '%s' disconnected", in steam_unregister()
1014 steam->serial_no); in steam_unregister()
1016 list_del_init(&steam->list); in steam_unregister()
1018 steam->serial_no[0] = 0; in steam_unregister()
1030 spin_lock_irqsave(&steam->lock, flags); in steam_work_connect_cb()
1031 connected = steam->connected; in steam_work_connect_cb()
1032 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_connect_cb()
1037 hid_err(steam->hdev, in steam_work_connect_cb()
1052 steam->gamepad_mode = !steam->gamepad_mode; in steam_mode_switch_cb()
1056 if (steam->gamepad_mode) in steam_mode_switch_cb()
1059 spin_lock_irqsave(&steam->lock, flags); in steam_mode_switch_cb()
1060 client_opened = steam->client_opened; in steam_mode_switch_cb()
1061 spin_unlock_irqrestore(&steam->lock, flags); in steam_mode_switch_cb()
1067 if (steam->gamepad_mode) { in steam_mode_switch_cb()
1082 spin_lock_irqsave(&steam->lock, flags); in steam_work_unregister_cb()
1083 opened = steam->client_opened; in steam_work_unregister_cb()
1084 connected = steam->connected; in steam_work_unregister_cb()
1085 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_unregister_cb()
1110 * 1-4: slots where up to 4 real game pads will be connected to. in steam_is_valve_interface()
1114 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; in steam_is_valve_interface()
1115 return !list_empty(&rep_enum->report_list); in steam_is_valve_interface()
1120 struct steam_device *steam = hdev->driver_data; in steam_client_ll_parse()
1122 return hid_parse_report(hdev, steam->hdev->dev_rdesc, in steam_client_ll_parse()
1123 steam->hdev->dev_rsize); in steam_client_ll_parse()
1137 struct steam_device *steam = hdev->driver_data; in steam_client_ll_open()
1140 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_open()
1141 steam->client_opened = true; in steam_client_ll_open()
1142 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_open()
1144 schedule_work(&steam->unregister_work); in steam_client_ll_open()
1151 struct steam_device *steam = hdev->driver_data; in steam_client_ll_close()
1156 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_close()
1157 steam->client_opened = false; in steam_client_ll_close()
1158 connected = steam->connected && !steam->client_opened; in steam_client_ll_close()
1159 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_close()
1161 schedule_work(&steam->unregister_work); in steam_client_ll_close()
1169 struct steam_device *steam = hdev->driver_data; in steam_client_ll_raw_request()
1171 return hid_hw_raw_request(steam->hdev, reportnum, buf, count, in steam_client_ll_raw_request()
1192 client_hdev->ll_driver = &steam_client_ll_driver; in steam_create_client_hid()
1193 client_hdev->dev.parent = hdev->dev.parent; in steam_create_client_hid()
1194 client_hdev->bus = hdev->bus; in steam_create_client_hid()
1195 client_hdev->vendor = hdev->vendor; in steam_create_client_hid()
1196 client_hdev->product = hdev->product; in steam_create_client_hid()
1197 client_hdev->version = hdev->version; in steam_create_client_hid()
1198 client_hdev->type = hdev->type; in steam_create_client_hid()
1199 client_hdev->country = hdev->country; in steam_create_client_hid()
1200 strscpy(client_hdev->name, hdev->name, in steam_create_client_hid()
1201 sizeof(client_hdev->name)); in steam_create_client_hid()
1202 strscpy(client_hdev->phys, hdev->phys, in steam_create_client_hid()
1203 sizeof(client_hdev->phys)); in steam_create_client_hid()
1209 client_hdev->group = HID_GROUP_STEAM; in steam_create_client_hid()
1230 if (hdev->group == HID_GROUP_STEAM) in steam_probe()
1233 * The non-valve interfaces (mouse and keyboard emulation) are in steam_probe()
1239 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); in steam_probe()
1241 return -ENOMEM; in steam_probe()
1243 steam->hdev = hdev; in steam_probe()
1245 spin_lock_init(&steam->lock); in steam_probe()
1246 mutex_init(&steam->report_mutex); in steam_probe()
1247 steam->quirks = id->driver_data; in steam_probe()
1248 INIT_WORK(&steam->work_connect, steam_work_connect_cb); in steam_probe()
1249 INIT_DELAYED_WORK(&steam->mode_switch, steam_mode_switch_cb); in steam_probe()
1250 INIT_LIST_HEAD(&steam->list); in steam_probe()
1251 INIT_WORK(&steam->rumble_work, steam_haptic_rumble_cb); in steam_probe()
1252 steam->sensor_timestamp_us = 0; in steam_probe()
1253 INIT_WORK(&steam->unregister_work, steam_work_unregister_cb); in steam_probe()
1271 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_probe()
1274 steam->connected = false; in steam_probe()
1278 steam->connected = true; in steam_probe()
1288 steam->client_hdev = steam_create_client_hid(hdev); in steam_probe()
1289 if (IS_ERR(steam->client_hdev)) { in steam_probe()
1290 ret = PTR_ERR(steam->client_hdev); in steam_probe()
1293 steam->client_hdev->driver_data = steam; in steam_probe()
1295 ret = hid_add_device(steam->client_hdev); in steam_probe()
1302 hid_destroy_device(steam->client_hdev); in steam_probe()
1304 if (steam->connected) in steam_probe()
1311 cancel_work_sync(&steam->work_connect); in steam_probe()
1312 cancel_delayed_work_sync(&steam->mode_switch); in steam_probe()
1313 cancel_work_sync(&steam->rumble_work); in steam_probe()
1314 cancel_work_sync(&steam->unregister_work); in steam_probe()
1323 if (!steam || hdev->group == HID_GROUP_STEAM) { in steam_remove()
1328 hid_destroy_device(steam->client_hdev); in steam_remove()
1329 cancel_delayed_work_sync(&steam->mode_switch); in steam_remove()
1330 cancel_work_sync(&steam->work_connect); in steam_remove()
1331 cancel_work_sync(&steam->rumble_work); in steam_remove()
1332 cancel_work_sync(&steam->unregister_work); in steam_remove()
1333 steam->client_hdev = NULL; in steam_remove()
1334 steam->client_opened = false; in steam_remove()
1335 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_remove()
1348 spin_lock_irqsave(&steam->lock, flags); in steam_do_connect_event()
1349 changed = steam->connected != connected; in steam_do_connect_event()
1350 steam->connected = connected; in steam_do_connect_event()
1351 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_connect_event()
1353 if (changed && schedule_work(&steam->work_connect) == 0) in steam_do_connect_event()
1359 * Some input data in the protocol has the opposite sign.
1360 * Clamp the values to 32767..-32767 so that the range is
1367 return x == -32768 ? -32767 : x; in steam_le16()
1376 * -------+-------+-----------+--------------------------
1377 * 4-7 | u32 | -- | sequence number
1378 * 8-10 | 24bit | see below | buttons
1381 * 13-15 | -- | -- | always 0
1382 * 16-17 | s16 | ABS_X/ABS_HAT0X | X value
1383 * 18-19 | s16 | ABS_Y/ABS_HAT0Y | Y value
1384 * 20-21 | s16 | ABS_RX | right-pad X value
1385 * 22-23 | s16 | ABS_RY | right-pad Y value
1386 * 24-25 | s16 | -- | * left trigger
1387 * 26-27 | s16 | -- | * right trigger
1388 * 28-29 | s16 | -- | * accelerometer X value
1389 * 30-31 | s16 | -- | * accelerometer Y value
1390 * 32-33 | s16 | -- | * accelerometer Z value
1391 * 34-35 | s16 | -- | gyro X value
1392 * 36-36 | s16 | -- | gyro Y value
1393 * 38-39 | s16 | -- | gyro Z value
1394 * 40-41 | s16 | -- | quaternion W value
1395 * 42-43 | s16 | -- | quaternion X value
1396 * 44-45 | s16 | -- | quaternion Y value
1397 * 46-47 | s16 | -- | quaternion Z value
1398 * 48-49 | -- | -- | always 0
1399 * 50-51 | s16 | -- | * left trigger (uncalibrated)
1400 * 52-53 | s16 | -- | * right trigger (uncalibrated)
1401 * 54-55 | s16 | -- | * joystick X value (uncalibrated)
1402 * 56-57 | s16 | -- | * joystick Y value (uncalibrated)
1403 * 58-59 | s16 | -- | * left-pad X value
1404 * 60-61 | s16 | -- | * left-pad Y value
1405 * 62-63 | u16 | -- | * battery voltage
1409 * ------+------------+--------------------------------
1418 * 9.0 | BTN_DPAD_UP | left-pad up
1419 * 9.1 | BTN_DPAD_RIGHT | left-pad right
1420 * 9.2 | BTN_DPAD_LEFT | left-pad left
1421 * 9.3 | BTN_DPAD_DOWN | left-pad down
1427 * 10.1 | -- | left-pad clicked
1428 * 10.2 | BTN_THUMBR | right-pad clicked
1429 * 10.3 | BTN_THUMB | left-pad touched (but see explanation below)
1430 * 10.4 | BTN_THUMB2 | right-pad touched
1431 * 10.5 | -- | unknown
1433 * 10.7 | -- | lpad_and_joy
1437 struct input_dev *input, u8 *data) in steam_do_input_event() argument
1448 input_report_abs(input, ABS_HAT2Y, data[11]); in steam_do_input_event()
1449 input_report_abs(input, ABS_HAT2X, data[12]); in steam_do_input_event()
1462 y = -steam_le16(data + 18); in steam_do_input_event()
1464 input_report_abs(input, lpad_touched ? ABS_HAT0X : ABS_X, x); in steam_do_input_event()
1465 input_report_abs(input, lpad_touched ? ABS_HAT0Y : ABS_Y, y); in steam_do_input_event()
1468 input_report_abs(input, ABS_X, 0); in steam_do_input_event()
1469 input_report_abs(input, ABS_Y, 0); in steam_do_input_event()
1473 input_report_abs(input, ABS_HAT0X, 0); in steam_do_input_event()
1474 input_report_abs(input, ABS_HAT0Y, 0); in steam_do_input_event()
1477 input_report_abs(input, ABS_RX, steam_le16(data + 20)); in steam_do_input_event()
1478 input_report_abs(input, ABS_RY, -steam_le16(data + 22)); in steam_do_input_event()
1480 input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); in steam_do_input_event()
1481 input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); in steam_do_input_event()
1482 input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); in steam_do_input_event()
1483 input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); in steam_do_input_event()
1484 input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); in steam_do_input_event()
1485 input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); in steam_do_input_event()
1486 input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); in steam_do_input_event()
1487 input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); in steam_do_input_event()
1488 input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); in steam_do_input_event()
1489 input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); in steam_do_input_event()
1490 input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); in steam_do_input_event()
1491 input_event(input, EV_KEY, BTN_GEAR_DOWN, !!(b9 & BIT(7))); in steam_do_input_event()
1492 input_event(input, EV_KEY, BTN_GEAR_UP, !!(b10 & BIT(0))); in steam_do_input_event()
1493 input_event(input, EV_KEY, BTN_THUMBR, !!(b10 & BIT(2))); in steam_do_input_event()
1494 input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); in steam_do_input_event()
1495 input_event(input, EV_KEY, BTN_THUMB, lpad_touched || lpad_and_joy); in steam_do_input_event()
1496 input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(4))); in steam_do_input_event()
1497 input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); in steam_do_input_event()
1498 input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); in steam_do_input_event()
1499 input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); in steam_do_input_event()
1500 input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); in steam_do_input_event()
1502 input_sync(input); in steam_do_input_event()
1509 * -------+-------+-----------+--------------------------
1510 * 4-7 | u32 | -- | sequence number
1511 * 8-15 | u64 | see below | buttons
1512 * 16-17 | s16 | ABS_HAT0X | left-pad X value
1513 * 18-19 | s16 | ABS_HAT0Y | left-pad Y value
1514 * 20-21 | s16 | ABS_HAT1X | right-pad X value
1515 * 22-23 | s16 | ABS_HAT1Y | right-pad Y value
1516 * 24-25 | s16 | IMU ABS_X | accelerometer X value
1517 * 26-27 | s16 | IMU ABS_Z | accelerometer Y value
1518 * 28-29 | s16 | IMU ABS_Y | accelerometer Z value
1519 * 30-31 | s16 | IMU ABS_RX | gyro X value
1520 * 32-33 | s16 | IMU ABS_RZ | gyro Y value
1521 * 34-35 | s16 | IMU ABS_RY | gyro Z value
1522 * 36-37 | s16 | -- | quaternion W value
1523 * 38-39 | s16 | -- | quaternion X value
1524 * 40-41 | s16 | -- | quaternion Y value
1525 * 42-43 | s16 | -- | quaternion Z value
1526 * 44-45 | u16 | ABS_HAT2Y | left trigger (uncalibrated)
1527 * 46-47 | u16 | ABS_HAT2X | right trigger (uncalibrated)
1528 * 48-49 | s16 | ABS_X | left joystick X
1529 * 50-51 | s16 | ABS_Y | left joystick Y
1530 * 52-53 | s16 | ABS_RX | right joystick X
1531 * 54-55 | s16 | ABS_RY | right joystick Y
1532 * 56-57 | u16 | -- | left pad pressure
1533 * 58-59 | u16 | -- | right pad pressure
1537 * ------+------------+--------------------------------
1546 * 9.0 | BTN_DPAD_UP | left-pad up
1547 * 9.1 | BTN_DPAD_RIGHT | left-pad right
1548 * 9.2 | BTN_DPAD_LEFT | left-pad left
1549 * 9.3 | BTN_DPAD_DOWN | left-pad down
1557 * 10.3 | -- | left pad touched
1558 * 10.4 | -- | right pad touched
1559 * 10.5 | -- | unknown
1561 * 10.7 | -- | unknown
1562 * 11.0 | -- | unknown
1563 * 11.1 | -- | unknown
1565 * 11.3 | -- | unknown
1566 * 11.4 | -- | unknown
1567 * 11.5 | -- | unknown
1568 * 11.6 | -- | unknown
1569 * 11.7 | -- | unknown
1570 * 12.0 | -- | unknown
1571 * 12.1 | -- | unknown
1572 * 12.2 | -- | unknown
1573 * 12.3 | -- | unknown
1574 * 12.4 | -- | unknown
1575 * 12.5 | -- | unknown
1576 * 12.6 | -- | unknown
1577 * 12.7 | -- | unknown
1578 * 13.0 | -- | unknown
1581 * 13.3 | -- | unknown
1582 * 13.4 | -- | unknown
1583 * 13.5 | -- | unknown
1584 * 13.6 | -- | left joystick touched
1585 * 13.7 | -- | right joystick touched
1586 * 14.0 | -- | unknown
1587 * 14.1 | -- | unknown
1589 * 14.3 | -- | unknown
1590 * 14.4 | -- | unknown
1591 * 14.5 | -- | unknown
1592 * 14.6 | -- | unknown
1593 * 14.7 | -- | unknown
1594 * 15.0 | -- | unknown
1595 * 15.1 | -- | unknown
1596 * 15.2 | -- | unknown
1597 * 15.3 | -- | unknown
1598 * 15.4 | -- | unknown
1599 * 15.5 | -- | unknown
1600 * 15.6 | -- | unknown
1601 * 15.7 | -- | unknown
1604 struct input_dev *input, u8 *data) in steam_do_deck_input_event() argument
1616 if (!(b9 & BIT(6)) && steam->did_mode_switch) { in steam_do_deck_input_event()
1617 steam->did_mode_switch = false; in steam_do_deck_input_event()
1618 cancel_delayed_work(&steam->mode_switch); in steam_do_deck_input_event()
1619 } else if (!steam->client_opened && (b9 & BIT(6)) && !steam->did_mode_switch) { in steam_do_deck_input_event()
1620 steam->did_mode_switch = true; in steam_do_deck_input_event()
1621 schedule_delayed_work(&steam->mode_switch, 45 * HZ / 100); in steam_do_deck_input_event()
1624 if (!steam->gamepad_mode) in steam_do_deck_input_event()
1631 input_report_abs(input, ABS_HAT0X, steam_le16(data + 16)); in steam_do_deck_input_event()
1632 input_report_abs(input, ABS_HAT0Y, steam_le16(data + 18)); in steam_do_deck_input_event()
1634 input_report_abs(input, ABS_HAT0X, 0); in steam_do_deck_input_event()
1635 input_report_abs(input, ABS_HAT0Y, 0); in steam_do_deck_input_event()
1639 input_report_abs(input, ABS_HAT1X, steam_le16(data + 20)); in steam_do_deck_input_event()
1640 input_report_abs(input, ABS_HAT1Y, steam_le16(data + 22)); in steam_do_deck_input_event()
1642 input_report_abs(input, ABS_HAT1X, 0); in steam_do_deck_input_event()
1643 input_report_abs(input, ABS_HAT1Y, 0); in steam_do_deck_input_event()
1646 input_report_abs(input, ABS_X, steam_le16(data + 48)); in steam_do_deck_input_event()
1647 input_report_abs(input, ABS_Y, -steam_le16(data + 50)); in steam_do_deck_input_event()
1648 input_report_abs(input, ABS_RX, steam_le16(data + 52)); in steam_do_deck_input_event()
1649 input_report_abs(input, ABS_RY, -steam_le16(data + 54)); in steam_do_deck_input_event()
1651 input_report_abs(input, ABS_HAT2Y, steam_le16(data + 44)); in steam_do_deck_input_event()
1652 input_report_abs(input, ABS_HAT2X, steam_le16(data + 46)); in steam_do_deck_input_event()
1654 input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); in steam_do_deck_input_event()
1655 input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); in steam_do_deck_input_event()
1656 input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); in steam_do_deck_input_event()
1657 input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); in steam_do_deck_input_event()
1658 input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); in steam_do_deck_input_event()
1659 input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); in steam_do_deck_input_event()
1660 input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); in steam_do_deck_input_event()
1661 input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); in steam_do_deck_input_event()
1662 input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); in steam_do_deck_input_event()
1663 input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); in steam_do_deck_input_event()
1664 input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); in steam_do_deck_input_event()
1665 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY3, !!(b9 & BIT(7))); in steam_do_deck_input_event()
1666 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY4, !!(b10 & BIT(0))); in steam_do_deck_input_event()
1667 input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); in steam_do_deck_input_event()
1668 input_event(input, EV_KEY, BTN_THUMBR, !!(b11 & BIT(2))); in steam_do_deck_input_event()
1669 input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); in steam_do_deck_input_event()
1670 input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); in steam_do_deck_input_event()
1671 input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); in steam_do_deck_input_event()
1672 input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); in steam_do_deck_input_event()
1673 input_event(input, EV_KEY, BTN_THUMB, !!(b10 & BIT(1))); in steam_do_deck_input_event()
1674 input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(2))); in steam_do_deck_input_event()
1675 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY1, !!(b13 & BIT(1))); in steam_do_deck_input_event()
1676 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY2, !!(b13 & BIT(2))); in steam_do_deck_input_event()
1677 input_event(input, EV_KEY, BTN_BASE, !!(b14 & BIT(2))); in steam_do_deck_input_event()
1679 input_sync(input); in steam_do_deck_input_event()
1686 * The deck input report is received every 4 ms on average, in steam_do_deck_sensors_event()
1687 * with a jitter of +/- 4 ms even though the USB descriptor claims in steam_do_deck_sensors_event()
1692 steam->sensor_timestamp_us += 4000; in steam_do_deck_sensors_event()
1694 if (!steam->gamepad_mode) in steam_do_deck_sensors_event()
1697 input_event(sensors, EV_MSC, MSC_TIMESTAMP, steam->sensor_timestamp_us); in steam_do_deck_sensors_event()
1699 input_report_abs(sensors, ABS_Z, -steam_le16(data + 26)); in steam_do_deck_sensors_event()
1702 input_report_abs(sensors, ABS_RZ, -steam_le16(data + 32)); in steam_do_deck_sensors_event()
1712 * -------+-------+---------------------------
1713 * 4-7 | u32 | sequence number
1714 * 8-11 | -- | always 0
1715 * 12-13 | u16 | voltage (mV)
1728 battery = rcu_dereference(steam->battery); in steam_do_battery_event()
1730 spin_lock_irqsave(&steam->lock, flags); in steam_do_battery_event()
1731 steam->voltage = volts; in steam_do_battery_event()
1732 steam->battery_charge = batt; in steam_do_battery_event()
1733 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_battery_event()
1744 struct input_dev *input; in steam_raw_event() local
1751 if (steam->client_opened) in steam_raw_event()
1752 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, in steam_raw_event()
1755 * All messages are size=64, all values little-endian. in steam_raw_event()
1758 * -------+-------------------------------------------- in steam_raw_event()
1759 * 0-1 | always 0x01, 0x00, maybe protocol version? in steam_raw_event()
1762 * 4-n | payload data, depends on the type in steam_raw_event()
1765 * 0x01: input data (60 bytes) in steam_raw_event()
1768 * 0x09: Steam Deck input data (56 bytes) in steam_raw_event()
1776 if (steam->client_opened) in steam_raw_event()
1779 input = rcu_dereference(steam->input); in steam_raw_event()
1780 if (likely(input)) in steam_raw_event()
1781 steam_do_input_event(steam, input, data); in steam_raw_event()
1785 if (steam->client_opened) in steam_raw_event()
1788 input = rcu_dereference(steam->input); in steam_raw_event()
1789 if (likely(input)) in steam_raw_event()
1790 steam_do_deck_input_event(steam, input, data); in steam_raw_event()
1791 sensors = rcu_dereference(steam->sensors); in steam_raw_event()
1812 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_raw_event()
1814 battery = rcu_dereference(steam->battery); in steam_raw_event()
1842 if (!steam->client_opened) in steam_param_set_lizard_mode()
1879 .name = "hid-steam",