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"
70 /* Accelerometer has 16 bit resolution and a range of +/- 2g */
74 /* Gyroscope has 16 bit resolution and a range of +/- 2000 dps */
243 /* Input report identifiers */
299 struct input_dev __rcu *input; member
326 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_recv_report()
328 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_recv_report()
329 return -EINVAL; in steam_recv_report()
333 return -EINVAL; in steam_recv_report()
337 return -ENOMEM; in steam_recv_report()
345 ret = hid_hw_raw_request(steam->hdev, 0x00, in steam_recv_report()
349 memcpy(data, buf + 1, min(size, ret - 1)); in steam_recv_report()
362 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_send_report()
364 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_send_report()
365 return -EINVAL; in steam_send_report()
369 return -EINVAL; in steam_send_report()
373 return -ENOMEM; in steam_send_report()
385 ret = hid_hw_raw_request(steam->hdev, 0, in steam_send_report()
388 if (ret != -EPIPE) in steam_send_report()
391 } while (--retries); in steam_send_report()
395 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, in steam_send_report()
447 u8 cmd[] = {ID_GET_STRING_ATTRIBUTE, sizeof(steam->serial_no), ATTRIB_STR_UNIT_SERIAL}; in steam_get_serial()
450 mutex_lock(&steam->report_mutex); in steam_get_serial()
458 reply[1] > sizeof(steam->serial_no) || reply[2] != ATTRIB_STR_UNIT_SERIAL) { in steam_get_serial()
459 ret = -EIO; in steam_get_serial()
463 strscpy(steam->serial_no, reply + 3, reply[1]); in steam_get_serial()
465 mutex_unlock(&steam->report_mutex); in steam_get_serial()
477 mutex_lock(&steam->report_mutex); in steam_request_conn_status()
479 mutex_unlock(&steam->report_mutex); in steam_request_conn_status()
487 * and gain is measured in decibels, ranging from -24 to +6
508 mutex_lock(&steam->report_mutex); in steam_haptic_pulse()
510 mutex_unlock(&steam->report_mutex); in steam_haptic_pulse()
530 mutex_lock(&steam->report_mutex); in steam_haptic_rumble()
532 mutex_unlock(&steam->report_mutex); in steam_haptic_rumble()
540 steam_haptic_rumble(steam, 0, steam->rumble_left, in steam_haptic_rumble_cb()
541 steam->rumble_right, 2, 0); in steam_haptic_rumble_cb()
550 steam->rumble_left = effect->u.rumble.strong_magnitude; in steam_play_effect()
551 steam->rumble_right = effect->u.rumble.weak_magnitude; in steam_play_effect()
553 return schedule_work(&steam->rumble_work); in steam_play_effect()
559 if (steam->gamepad_mode) in steam_set_lizard_mode()
563 mutex_lock(&steam->report_mutex); in steam_set_lizard_mode()
568 mutex_unlock(&steam->report_mutex); in steam_set_lizard_mode()
570 mutex_lock(&steam->report_mutex); in steam_set_lizard_mode()
574 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_set_lizard_mode()
582 mutex_unlock(&steam->report_mutex); in steam_set_lizard_mode()
588 mutex_unlock(&steam->report_mutex); in steam_set_lizard_mode()
604 if (!(steam->quirks & STEAM_QUIRK_DECK)) { in steam_input_open()
605 spin_lock_irqsave(&steam->lock, flags); in steam_input_open()
606 set_lizard_mode = !steam->client_opened && lizard_mode; in steam_input_open()
607 spin_unlock_irqrestore(&steam->lock, flags); in steam_input_open()
621 if (!(steam->quirks & STEAM_QUIRK_DECK)) { in steam_input_close()
622 spin_lock_irqsave(&steam->lock, flags); in steam_input_close()
623 set_lizard_mode = !steam->client_opened && lizard_mode; in steam_input_close()
624 spin_unlock_irqrestore(&steam->lock, flags); in steam_input_close()
647 spin_lock_irqsave(&steam->lock, flags); in steam_battery_get_property()
648 volts = steam->voltage; in steam_battery_get_property()
649 batt = steam->battery_charge; in steam_battery_get_property()
650 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_get_property()
654 val->intval = 1; in steam_battery_get_property()
657 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in steam_battery_get_property()
660 val->intval = volts * 1000; /* mV -> uV */ in steam_battery_get_property()
663 val->intval = batt; in steam_battery_get_property()
666 ret = -EINVAL; in steam_battery_get_property()
679 steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in steam_battery_register()
680 steam->battery_desc.properties = steam_battery_props; in steam_battery_register()
681 steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props); in steam_battery_register()
682 steam->battery_desc.get_property = steam_battery_get_property; in steam_battery_register()
683 steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev, in steam_battery_register()
684 GFP_KERNEL, "steam-controller-%s-battery", in steam_battery_register()
685 steam->serial_no); in steam_battery_register()
686 if (!steam->battery_desc.name) in steam_battery_register()
687 return -ENOMEM; in steam_battery_register()
690 spin_lock_irqsave(&steam->lock, flags); in steam_battery_register()
691 steam->voltage = 3000; in steam_battery_register()
692 steam->battery_charge = 100; in steam_battery_register()
693 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_register()
695 battery = power_supply_register(&steam->hdev->dev, in steam_battery_register()
696 &steam->battery_desc, &battery_cfg); in steam_battery_register()
699 hid_err(steam->hdev, in steam_battery_register()
704 rcu_assign_pointer(steam->battery, battery); in steam_battery_register()
705 power_supply_powers(battery, &steam->hdev->dev); in steam_battery_register()
711 struct hid_device *hdev = steam->hdev; in steam_input_register()
712 struct input_dev *input; in steam_input_register() local
716 input = rcu_dereference(steam->input); in steam_input_register()
718 if (input) { in steam_input_register()
723 input = input_allocate_device(); in steam_input_register()
724 if (!input) in steam_input_register()
725 return -ENOMEM; in steam_input_register()
727 input_set_drvdata(input, steam); in steam_input_register()
728 input->dev.parent = &hdev->dev; in steam_input_register()
729 input->open = steam_input_open; in steam_input_register()
730 input->close = steam_input_close; in steam_input_register()
732 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? "Wireless Steam Controller" : in steam_input_register()
733 (steam->quirks & STEAM_QUIRK_DECK) ? "Steam Deck" : in steam_input_register()
735 input->phys = hdev->phys; in steam_input_register()
736 input->uniq = steam->serial_no; in steam_input_register()
737 input->id.bustype = hdev->bus; in steam_input_register()
738 input->id.vendor = hdev->vendor; in steam_input_register()
739 input->id.product = hdev->product; in steam_input_register()
740 input->id.version = hdev->version; in steam_input_register()
742 input_set_capability(input, EV_KEY, BTN_TR2); in steam_input_register()
743 input_set_capability(input, EV_KEY, BTN_TL2); in steam_input_register()
744 input_set_capability(input, EV_KEY, BTN_TR); in steam_input_register()
745 input_set_capability(input, EV_KEY, BTN_TL); in steam_input_register()
746 input_set_capability(input, EV_KEY, BTN_Y); in steam_input_register()
747 input_set_capability(input, EV_KEY, BTN_B); in steam_input_register()
748 input_set_capability(input, EV_KEY, BTN_X); in steam_input_register()
749 input_set_capability(input, EV_KEY, BTN_A); in steam_input_register()
750 input_set_capability(input, EV_KEY, BTN_DPAD_UP); in steam_input_register()
751 input_set_capability(input, EV_KEY, BTN_DPAD_RIGHT); in steam_input_register()
752 input_set_capability(input, EV_KEY, BTN_DPAD_LEFT); in steam_input_register()
753 input_set_capability(input, EV_KEY, BTN_DPAD_DOWN); in steam_input_register()
754 input_set_capability(input, EV_KEY, BTN_SELECT); in steam_input_register()
755 input_set_capability(input, EV_KEY, BTN_MODE); in steam_input_register()
756 input_set_capability(input, EV_KEY, BTN_START); in steam_input_register()
757 input_set_capability(input, EV_KEY, BTN_THUMBR); in steam_input_register()
758 input_set_capability(input, EV_KEY, BTN_THUMBL); in steam_input_register()
759 input_set_capability(input, EV_KEY, BTN_THUMB); in steam_input_register()
760 input_set_capability(input, EV_KEY, BTN_THUMB2); in steam_input_register()
761 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_input_register()
762 input_set_capability(input, EV_KEY, BTN_BASE); in steam_input_register()
763 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY1); in steam_input_register()
764 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY2); in steam_input_register()
765 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY3); in steam_input_register()
766 input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY4); in steam_input_register()
768 input_set_capability(input, EV_KEY, BTN_GEAR_DOWN); in steam_input_register()
769 input_set_capability(input, EV_KEY, BTN_GEAR_UP); in steam_input_register()
772 input_set_abs_params(input, ABS_X, -32767, 32767, 0, 0); in steam_input_register()
773 input_set_abs_params(input, ABS_Y, -32767, 32767, 0, 0); in steam_input_register()
775 input_set_abs_params(input, ABS_HAT0X, -32767, 32767, in steam_input_register()
777 input_set_abs_params(input, ABS_HAT0Y, -32767, 32767, in steam_input_register()
780 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_input_register()
781 input_set_abs_params(input, ABS_HAT2Y, 0, 32767, 0, 0); in steam_input_register()
782 input_set_abs_params(input, ABS_HAT2X, 0, 32767, 0, 0); in steam_input_register()
784 input_set_abs_params(input, ABS_RX, -32767, 32767, 0, 0); in steam_input_register()
785 input_set_abs_params(input, ABS_RY, -32767, 32767, 0, 0); in steam_input_register()
787 input_set_abs_params(input, ABS_HAT1X, -32767, 32767, in steam_input_register()
789 input_set_abs_params(input, ABS_HAT1Y, -32767, 32767, in steam_input_register()
792 input_abs_set_res(input, ABS_X, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
793 input_abs_set_res(input, ABS_Y, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
794 input_abs_set_res(input, ABS_RX, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
795 input_abs_set_res(input, ABS_RY, STEAM_DECK_JOYSTICK_RESOLUTION); in steam_input_register()
796 input_abs_set_res(input, ABS_HAT1X, STEAM_PAD_RESOLUTION); in steam_input_register()
797 input_abs_set_res(input, ABS_HAT1Y, STEAM_PAD_RESOLUTION); in steam_input_register()
798 input_abs_set_res(input, ABS_HAT2Y, STEAM_DECK_TRIGGER_RESOLUTION); in steam_input_register()
799 input_abs_set_res(input, ABS_HAT2X, STEAM_DECK_TRIGGER_RESOLUTION); in steam_input_register()
801 input_set_abs_params(input, ABS_HAT2Y, 0, 255, 0, 0); in steam_input_register()
802 input_set_abs_params(input, ABS_HAT2X, 0, 255, 0, 0); in steam_input_register()
804 input_set_abs_params(input, ABS_RX, -32767, 32767, in steam_input_register()
806 input_set_abs_params(input, ABS_RY, -32767, 32767, in steam_input_register()
809 input_abs_set_res(input, ABS_X, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
810 input_abs_set_res(input, ABS_Y, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
811 input_abs_set_res(input, ABS_RX, STEAM_PAD_RESOLUTION); in steam_input_register()
812 input_abs_set_res(input, ABS_RY, STEAM_PAD_RESOLUTION); in steam_input_register()
813 input_abs_set_res(input, ABS_HAT2Y, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
814 input_abs_set_res(input, ABS_HAT2X, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
816 input_abs_set_res(input, ABS_HAT0X, STEAM_PAD_RESOLUTION); in steam_input_register()
817 input_abs_set_res(input, ABS_HAT0Y, STEAM_PAD_RESOLUTION); in steam_input_register()
820 if (steam->quirks & STEAM_QUIRK_DECK) { in steam_input_register()
821 input_set_capability(input, EV_FF, FF_RUMBLE); in steam_input_register()
822 ret = input_ff_create_memless(input, NULL, steam_play_effect); in steam_input_register()
828 ret = input_register_device(input); in steam_input_register()
832 rcu_assign_pointer(steam->input, input); in steam_input_register()
836 input_free_device(input); in steam_input_register()
842 struct hid_device *hdev = steam->hdev; in steam_sensors_register()
846 if (!(steam->quirks & STEAM_QUIRK_DECK)) in steam_sensors_register()
850 sensors = rcu_dereference(steam->sensors); in steam_sensors_register()
859 return -ENOMEM; in steam_sensors_register()
862 sensors->dev.parent = &hdev->dev; in steam_sensors_register()
864 sensors->name = "Steam Deck Motion Sensors"; in steam_sensors_register()
865 sensors->phys = hdev->phys; in steam_sensors_register()
866 sensors->uniq = steam->serial_no; in steam_sensors_register()
867 sensors->id.bustype = hdev->bus; in steam_sensors_register()
868 sensors->id.vendor = hdev->vendor; in steam_sensors_register()
869 sensors->id.product = hdev->product; in steam_sensors_register()
870 sensors->id.version = hdev->version; in steam_sensors_register()
872 __set_bit(INPUT_PROP_ACCELEROMETER, sensors->propbit); in steam_sensors_register()
873 __set_bit(EV_MSC, sensors->evbit); in steam_sensors_register()
874 __set_bit(MSC_TIMESTAMP, sensors->mscbit); in steam_sensors_register()
876 input_set_abs_params(sensors, ABS_X, -STEAM_DECK_ACCEL_RANGE, in steam_sensors_register()
878 input_set_abs_params(sensors, ABS_Y, -STEAM_DECK_ACCEL_RANGE, in steam_sensors_register()
880 input_set_abs_params(sensors, ABS_Z, -STEAM_DECK_ACCEL_RANGE, in steam_sensors_register()
886 input_set_abs_params(sensors, ABS_RX, -STEAM_DECK_GYRO_RANGE, in steam_sensors_register()
888 input_set_abs_params(sensors, ABS_RY, -STEAM_DECK_GYRO_RANGE, in steam_sensors_register()
890 input_set_abs_params(sensors, ABS_RZ, -STEAM_DECK_GYRO_RANGE, in steam_sensors_register()
900 rcu_assign_pointer(steam->sensors, sensors); in steam_sensors_register()
910 struct input_dev *input; in steam_input_unregister() local
912 input = rcu_dereference(steam->input); in steam_input_unregister()
914 if (!input) in steam_input_unregister()
916 RCU_INIT_POINTER(steam->input, NULL); in steam_input_unregister()
918 input_unregister_device(input); in steam_input_unregister()
925 if (!(steam->quirks & STEAM_QUIRK_DECK)) in steam_sensors_unregister()
929 sensors = rcu_dereference(steam->sensors); in steam_sensors_unregister()
934 RCU_INIT_POINTER(steam->sensors, NULL); in steam_sensors_unregister()
944 battery = rcu_dereference(steam->battery); in steam_battery_unregister()
949 RCU_INIT_POINTER(steam->battery, NULL); in steam_battery_unregister()
966 if (!steam->serial_no[0]) { in steam_register()
972 strscpy(steam->serial_no, "XXXXXXXXXX", in steam_register()
973 sizeof(steam->serial_no)); in steam_register()
975 hid_info(steam->hdev, "Steam Controller '%s' connected", in steam_register()
976 steam->serial_no); in steam_register()
979 if (steam->quirks & STEAM_QUIRK_WIRELESS) in steam_register()
983 if (list_empty(&steam->list)) in steam_register()
984 list_add(&steam->list, &steam_devices); in steam_register()
988 spin_lock_irqsave(&steam->lock, flags); in steam_register()
989 client_opened = steam->client_opened; in steam_register()
990 spin_unlock_irqrestore(&steam->lock, flags); in steam_register()
1014 if (steam->serial_no[0]) { in steam_unregister()
1015 hid_info(steam->hdev, "Steam Controller '%s' disconnected", in steam_unregister()
1016 steam->serial_no); in steam_unregister()
1018 list_del_init(&steam->list); in steam_unregister()
1020 steam->serial_no[0] = 0; in steam_unregister()
1032 spin_lock_irqsave(&steam->lock, flags); in steam_work_connect_cb()
1033 connected = steam->connected; in steam_work_connect_cb()
1034 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_connect_cb()
1039 hid_err(steam->hdev, in steam_work_connect_cb()
1057 steam->gamepad_mode = !steam->gamepad_mode; in steam_mode_switch_cb()
1058 if (steam->gamepad_mode) in steam_mode_switch_cb()
1061 spin_lock_irqsave(&steam->lock, flags); in steam_mode_switch_cb()
1062 client_opened = steam->client_opened; in steam_mode_switch_cb()
1063 spin_unlock_irqrestore(&steam->lock, flags); in steam_mode_switch_cb()
1069 if (steam->gamepad_mode) { in steam_mode_switch_cb()
1084 spin_lock_irqsave(&steam->lock, flags); in steam_work_unregister_cb()
1085 opened = steam->client_opened; in steam_work_unregister_cb()
1086 connected = steam->connected; in steam_work_unregister_cb()
1087 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_unregister_cb()
1112 * 1-4: slots where up to 4 real game pads will be connected to. in steam_is_valve_interface()
1116 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; in steam_is_valve_interface()
1117 return !list_empty(&rep_enum->report_list); in steam_is_valve_interface()
1122 struct steam_device *steam = hdev->driver_data; in steam_client_ll_parse()
1124 return hid_parse_report(hdev, steam->hdev->dev_rdesc, in steam_client_ll_parse()
1125 steam->hdev->dev_rsize); in steam_client_ll_parse()
1139 struct steam_device *steam = hdev->driver_data; in steam_client_ll_open()
1142 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_open()
1143 steam->client_opened++; in steam_client_ll_open()
1144 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_open()
1146 schedule_work(&steam->unregister_work); in steam_client_ll_open()
1153 struct steam_device *steam = hdev->driver_data; in steam_client_ll_close()
1158 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_close()
1159 steam->client_opened--; in steam_client_ll_close()
1160 connected = steam->connected && !steam->client_opened; in steam_client_ll_close()
1161 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_close()
1163 schedule_work(&steam->unregister_work); in steam_client_ll_close()
1171 struct steam_device *steam = hdev->driver_data; in steam_client_ll_raw_request()
1173 return hid_hw_raw_request(steam->hdev, reportnum, buf, count, in steam_client_ll_raw_request()
1194 client_hdev->ll_driver = &steam_client_ll_driver; in steam_create_client_hid()
1195 client_hdev->dev.parent = hdev->dev.parent; in steam_create_client_hid()
1196 client_hdev->bus = hdev->bus; in steam_create_client_hid()
1197 client_hdev->vendor = hdev->vendor; in steam_create_client_hid()
1198 client_hdev->product = hdev->product; in steam_create_client_hid()
1199 client_hdev->version = hdev->version; in steam_create_client_hid()
1200 client_hdev->type = hdev->type; in steam_create_client_hid()
1201 client_hdev->country = hdev->country; in steam_create_client_hid()
1202 strscpy(client_hdev->name, hdev->name, in steam_create_client_hid()
1203 sizeof(client_hdev->name)); in steam_create_client_hid()
1204 strscpy(client_hdev->phys, hdev->phys, in steam_create_client_hid()
1205 sizeof(client_hdev->phys)); in steam_create_client_hid()
1211 client_hdev->group = HID_GROUP_STEAM; in steam_create_client_hid()
1232 if (hdev->group == HID_GROUP_STEAM) in steam_probe()
1235 * The non-valve interfaces (mouse and keyboard emulation) are in steam_probe()
1241 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); in steam_probe()
1243 return -ENOMEM; in steam_probe()
1245 steam->hdev = hdev; in steam_probe()
1247 spin_lock_init(&steam->lock); in steam_probe()
1248 mutex_init(&steam->report_mutex); in steam_probe()
1249 steam->quirks = id->driver_data; in steam_probe()
1250 INIT_WORK(&steam->work_connect, steam_work_connect_cb); in steam_probe()
1251 INIT_DELAYED_WORK(&steam->mode_switch, steam_mode_switch_cb); in steam_probe()
1252 INIT_LIST_HEAD(&steam->list); in steam_probe()
1253 INIT_WORK(&steam->rumble_work, steam_haptic_rumble_cb); in steam_probe()
1254 steam->sensor_timestamp_us = 0; in steam_probe()
1255 INIT_WORK(&steam->unregister_work, steam_work_unregister_cb); in steam_probe()
1273 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_probe()
1276 steam->connected = false; in steam_probe()
1280 steam->connected = true; in steam_probe()
1290 steam->client_hdev = steam_create_client_hid(hdev); in steam_probe()
1291 if (IS_ERR(steam->client_hdev)) { in steam_probe()
1292 ret = PTR_ERR(steam->client_hdev); in steam_probe()
1295 steam->client_hdev->driver_data = steam; in steam_probe()
1297 ret = hid_add_device(steam->client_hdev); in steam_probe()
1304 hid_destroy_device(steam->client_hdev); in steam_probe()
1306 if (steam->connected) in steam_probe()
1313 cancel_work_sync(&steam->work_connect); in steam_probe()
1314 cancel_delayed_work_sync(&steam->mode_switch); in steam_probe()
1315 cancel_work_sync(&steam->rumble_work); in steam_probe()
1316 cancel_work_sync(&steam->unregister_work); in steam_probe()
1325 if (!steam || hdev->group == HID_GROUP_STEAM) { in steam_remove()
1330 hid_destroy_device(steam->client_hdev); in steam_remove()
1331 cancel_delayed_work_sync(&steam->mode_switch); in steam_remove()
1332 cancel_work_sync(&steam->work_connect); in steam_remove()
1333 cancel_work_sync(&steam->rumble_work); in steam_remove()
1334 cancel_work_sync(&steam->unregister_work); in steam_remove()
1335 steam->client_hdev = NULL; in steam_remove()
1336 steam->client_opened = 0; in steam_remove()
1337 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_remove()
1350 spin_lock_irqsave(&steam->lock, flags); in steam_do_connect_event()
1351 changed = steam->connected != connected; in steam_do_connect_event()
1352 steam->connected = connected; in steam_do_connect_event()
1353 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_connect_event()
1355 if (changed && schedule_work(&steam->work_connect) == 0) in steam_do_connect_event()
1361 * Some input data in the protocol has the opposite sign.
1362 * Clamp the values to 32767..-32767 so that the range is
1369 return x == -32768 ? -32767 : x; in steam_le16()
1378 * -------+-------+-----------+--------------------------
1379 * 4-7 | u32 | -- | sequence number
1380 * 8-10 | 24bit | see below | buttons
1383 * 13-15 | -- | -- | always 0
1384 * 16-17 | s16 | ABS_X/ABS_HAT0X | X value
1385 * 18-19 | s16 | ABS_Y/ABS_HAT0Y | Y value
1386 * 20-21 | s16 | ABS_RX | right-pad X value
1387 * 22-23 | s16 | ABS_RY | right-pad Y value
1388 * 24-25 | s16 | -- | * left trigger
1389 * 26-27 | s16 | -- | * right trigger
1390 * 28-29 | s16 | -- | * accelerometer X value
1391 * 30-31 | s16 | -- | * accelerometer Y value
1392 * 32-33 | s16 | -- | * accelerometer Z value
1393 * 34-35 | s16 | -- | gyro X value
1394 * 36-36 | s16 | -- | gyro Y value
1395 * 38-39 | s16 | -- | gyro Z value
1396 * 40-41 | s16 | -- | quaternion W value
1397 * 42-43 | s16 | -- | quaternion X value
1398 * 44-45 | s16 | -- | quaternion Y value
1399 * 46-47 | s16 | -- | quaternion Z value
1400 * 48-49 | -- | -- | always 0
1401 * 50-51 | s16 | -- | * left trigger (uncalibrated)
1402 * 52-53 | s16 | -- | * right trigger (uncalibrated)
1403 * 54-55 | s16 | -- | * joystick X value (uncalibrated)
1404 * 56-57 | s16 | -- | * joystick Y value (uncalibrated)
1405 * 58-59 | s16 | -- | * left-pad X value
1406 * 60-61 | s16 | -- | * left-pad Y value
1407 * 62-63 | u16 | -- | * battery voltage
1411 * ------+------------+--------------------------------
1420 * 9.0 | BTN_DPAD_UP | left-pad up
1421 * 9.1 | BTN_DPAD_RIGHT | left-pad right
1422 * 9.2 | BTN_DPAD_LEFT | left-pad left
1423 * 9.3 | BTN_DPAD_DOWN | left-pad down
1429 * 10.1 | -- | left-pad clicked
1430 * 10.2 | BTN_THUMBR | right-pad clicked
1431 * 10.3 | BTN_THUMB | left-pad touched (but see explanation below)
1432 * 10.4 | BTN_THUMB2 | right-pad touched
1433 * 10.5 | -- | unknown
1435 * 10.7 | -- | lpad_and_joy
1439 struct input_dev *input, u8 *data) in steam_do_input_event() argument
1450 input_report_abs(input, ABS_HAT2Y, data[11]); in steam_do_input_event()
1451 input_report_abs(input, ABS_HAT2X, data[12]); in steam_do_input_event()
1464 y = -steam_le16(data + 18); in steam_do_input_event()
1466 input_report_abs(input, lpad_touched ? ABS_HAT0X : ABS_X, x); in steam_do_input_event()
1467 input_report_abs(input, lpad_touched ? ABS_HAT0Y : ABS_Y, y); in steam_do_input_event()
1470 input_report_abs(input, ABS_X, 0); in steam_do_input_event()
1471 input_report_abs(input, ABS_Y, 0); in steam_do_input_event()
1475 input_report_abs(input, ABS_HAT0X, 0); in steam_do_input_event()
1476 input_report_abs(input, ABS_HAT0Y, 0); in steam_do_input_event()
1479 input_report_abs(input, ABS_RX, steam_le16(data + 20)); in steam_do_input_event()
1480 input_report_abs(input, ABS_RY, -steam_le16(data + 22)); in steam_do_input_event()
1482 input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); in steam_do_input_event()
1483 input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); in steam_do_input_event()
1484 input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); in steam_do_input_event()
1485 input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); in steam_do_input_event()
1486 input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); in steam_do_input_event()
1487 input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); in steam_do_input_event()
1488 input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); in steam_do_input_event()
1489 input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); in steam_do_input_event()
1490 input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); in steam_do_input_event()
1491 input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); in steam_do_input_event()
1492 input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); in steam_do_input_event()
1493 input_event(input, EV_KEY, BTN_GEAR_DOWN, !!(b9 & BIT(7))); in steam_do_input_event()
1494 input_event(input, EV_KEY, BTN_GEAR_UP, !!(b10 & BIT(0))); in steam_do_input_event()
1495 input_event(input, EV_KEY, BTN_THUMBR, !!(b10 & BIT(2))); in steam_do_input_event()
1496 input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); in steam_do_input_event()
1497 input_event(input, EV_KEY, BTN_THUMB, lpad_touched || lpad_and_joy); in steam_do_input_event()
1498 input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(4))); in steam_do_input_event()
1499 input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); in steam_do_input_event()
1500 input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); in steam_do_input_event()
1501 input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); in steam_do_input_event()
1502 input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); in steam_do_input_event()
1504 input_sync(input); in steam_do_input_event()
1511 * -------+-------+-----------+--------------------------
1512 * 4-7 | u32 | -- | sequence number
1513 * 8-15 | u64 | see below | buttons
1514 * 16-17 | s16 | ABS_HAT0X | left-pad X value
1515 * 18-19 | s16 | ABS_HAT0Y | left-pad Y value
1516 * 20-21 | s16 | ABS_HAT1X | right-pad X value
1517 * 22-23 | s16 | ABS_HAT1Y | right-pad Y value
1518 * 24-25 | s16 | IMU ABS_X | accelerometer X value
1519 * 26-27 | s16 | IMU ABS_Z | accelerometer Y value
1520 * 28-29 | s16 | IMU ABS_Y | accelerometer Z value
1521 * 30-31 | s16 | IMU ABS_RX | gyro X value
1522 * 32-33 | s16 | IMU ABS_RZ | gyro Y value
1523 * 34-35 | s16 | IMU ABS_RY | gyro Z value
1524 * 36-37 | s16 | -- | quaternion W value
1525 * 38-39 | s16 | -- | quaternion X value
1526 * 40-41 | s16 | -- | quaternion Y value
1527 * 42-43 | s16 | -- | quaternion Z value
1528 * 44-45 | u16 | ABS_HAT2Y | left trigger (uncalibrated)
1529 * 46-47 | u16 | ABS_HAT2X | right trigger (uncalibrated)
1530 * 48-49 | s16 | ABS_X | left joystick X
1531 * 50-51 | s16 | ABS_Y | left joystick Y
1532 * 52-53 | s16 | ABS_RX | right joystick X
1533 * 54-55 | s16 | ABS_RY | right joystick Y
1534 * 56-57 | u16 | -- | left pad pressure
1535 * 58-59 | u16 | -- | right pad pressure
1539 * ------+------------+--------------------------------
1548 * 9.0 | BTN_DPAD_UP | left-pad up
1549 * 9.1 | BTN_DPAD_RIGHT | left-pad right
1550 * 9.2 | BTN_DPAD_LEFT | left-pad left
1551 * 9.3 | BTN_DPAD_DOWN | left-pad down
1559 * 10.3 | -- | left pad touched
1560 * 10.4 | -- | right pad touched
1561 * 10.5 | -- | unknown
1563 * 10.7 | -- | unknown
1564 * 11.0 | -- | unknown
1565 * 11.1 | -- | unknown
1567 * 11.3 | -- | unknown
1568 * 11.4 | -- | unknown
1569 * 11.5 | -- | unknown
1570 * 11.6 | -- | unknown
1571 * 11.7 | -- | unknown
1572 * 12.0 | -- | unknown
1573 * 12.1 | -- | unknown
1574 * 12.2 | -- | unknown
1575 * 12.3 | -- | unknown
1576 * 12.4 | -- | unknown
1577 * 12.5 | -- | unknown
1578 * 12.6 | -- | unknown
1579 * 12.7 | -- | unknown
1580 * 13.0 | -- | unknown
1583 * 13.3 | -- | unknown
1584 * 13.4 | -- | unknown
1585 * 13.5 | -- | unknown
1586 * 13.6 | -- | left joystick touched
1587 * 13.7 | -- | right joystick touched
1588 * 14.0 | -- | unknown
1589 * 14.1 | -- | unknown
1591 * 14.3 | -- | unknown
1592 * 14.4 | -- | unknown
1593 * 14.5 | -- | unknown
1594 * 14.6 | -- | unknown
1595 * 14.7 | -- | unknown
1596 * 15.0 | -- | unknown
1597 * 15.1 | -- | unknown
1598 * 15.2 | -- | unknown
1599 * 15.3 | -- | unknown
1600 * 15.4 | -- | unknown
1601 * 15.5 | -- | unknown
1602 * 15.6 | -- | unknown
1603 * 15.7 | -- | unknown
1606 struct input_dev *input, u8 *data) in steam_do_deck_input_event() argument
1618 if (!(b9 & BIT(6)) && steam->did_mode_switch) { in steam_do_deck_input_event()
1619 steam->did_mode_switch = false; in steam_do_deck_input_event()
1620 cancel_delayed_work(&steam->mode_switch); in steam_do_deck_input_event()
1621 } else if (!steam->client_opened && (b9 & BIT(6)) && !steam->did_mode_switch) { in steam_do_deck_input_event()
1622 steam->did_mode_switch = true; in steam_do_deck_input_event()
1623 schedule_delayed_work(&steam->mode_switch, 45 * HZ / 100); in steam_do_deck_input_event()
1626 if (!steam->gamepad_mode && lizard_mode) in steam_do_deck_input_event()
1633 input_report_abs(input, ABS_HAT0X, steam_le16(data + 16)); in steam_do_deck_input_event()
1634 input_report_abs(input, ABS_HAT0Y, steam_le16(data + 18)); in steam_do_deck_input_event()
1636 input_report_abs(input, ABS_HAT0X, 0); in steam_do_deck_input_event()
1637 input_report_abs(input, ABS_HAT0Y, 0); in steam_do_deck_input_event()
1641 input_report_abs(input, ABS_HAT1X, steam_le16(data + 20)); in steam_do_deck_input_event()
1642 input_report_abs(input, ABS_HAT1Y, steam_le16(data + 22)); in steam_do_deck_input_event()
1644 input_report_abs(input, ABS_HAT1X, 0); in steam_do_deck_input_event()
1645 input_report_abs(input, ABS_HAT1Y, 0); in steam_do_deck_input_event()
1648 input_report_abs(input, ABS_X, steam_le16(data + 48)); in steam_do_deck_input_event()
1649 input_report_abs(input, ABS_Y, -steam_le16(data + 50)); in steam_do_deck_input_event()
1650 input_report_abs(input, ABS_RX, steam_le16(data + 52)); in steam_do_deck_input_event()
1651 input_report_abs(input, ABS_RY, -steam_le16(data + 54)); in steam_do_deck_input_event()
1653 input_report_abs(input, ABS_HAT2Y, steam_le16(data + 44)); in steam_do_deck_input_event()
1654 input_report_abs(input, ABS_HAT2X, steam_le16(data + 46)); in steam_do_deck_input_event()
1656 input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); in steam_do_deck_input_event()
1657 input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); in steam_do_deck_input_event()
1658 input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); in steam_do_deck_input_event()
1659 input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); in steam_do_deck_input_event()
1660 input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); in steam_do_deck_input_event()
1661 input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); in steam_do_deck_input_event()
1662 input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); in steam_do_deck_input_event()
1663 input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); in steam_do_deck_input_event()
1664 input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); in steam_do_deck_input_event()
1665 input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); in steam_do_deck_input_event()
1666 input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); in steam_do_deck_input_event()
1667 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY3, !!(b9 & BIT(7))); in steam_do_deck_input_event()
1668 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY4, !!(b10 & BIT(0))); in steam_do_deck_input_event()
1669 input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); in steam_do_deck_input_event()
1670 input_event(input, EV_KEY, BTN_THUMBR, !!(b11 & BIT(2))); in steam_do_deck_input_event()
1671 input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); in steam_do_deck_input_event()
1672 input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); in steam_do_deck_input_event()
1673 input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); in steam_do_deck_input_event()
1674 input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); in steam_do_deck_input_event()
1675 input_event(input, EV_KEY, BTN_THUMB, !!(b10 & BIT(1))); in steam_do_deck_input_event()
1676 input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(2))); in steam_do_deck_input_event()
1677 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY1, !!(b13 & BIT(1))); in steam_do_deck_input_event()
1678 input_event(input, EV_KEY, BTN_TRIGGER_HAPPY2, !!(b13 & BIT(2))); in steam_do_deck_input_event()
1679 input_event(input, EV_KEY, BTN_BASE, !!(b14 & BIT(2))); in steam_do_deck_input_event()
1681 input_sync(input); in steam_do_deck_input_event()
1688 * The deck input report is received every 4 ms on average, in steam_do_deck_sensors_event()
1689 * with a jitter of +/- 4 ms even though the USB descriptor claims in steam_do_deck_sensors_event()
1694 steam->sensor_timestamp_us += 4000; in steam_do_deck_sensors_event()
1696 if (!steam->gamepad_mode && lizard_mode) in steam_do_deck_sensors_event()
1699 input_event(sensors, EV_MSC, MSC_TIMESTAMP, steam->sensor_timestamp_us); in steam_do_deck_sensors_event()
1701 input_report_abs(sensors, ABS_Z, -steam_le16(data + 26)); in steam_do_deck_sensors_event()
1704 input_report_abs(sensors, ABS_RZ, -steam_le16(data + 32)); in steam_do_deck_sensors_event()
1714 * -------+-------+---------------------------
1715 * 4-7 | u32 | sequence number
1716 * 8-11 | -- | always 0
1717 * 12-13 | u16 | voltage (mV)
1730 battery = rcu_dereference(steam->battery); in steam_do_battery_event()
1732 spin_lock_irqsave(&steam->lock, flags); in steam_do_battery_event()
1733 steam->voltage = volts; in steam_do_battery_event()
1734 steam->battery_charge = batt; in steam_do_battery_event()
1735 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_battery_event()
1746 struct input_dev *input; in steam_raw_event() local
1753 if (steam->client_opened) in steam_raw_event()
1754 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, in steam_raw_event()
1757 * All messages are size=64, all values little-endian. in steam_raw_event()
1760 * -------+-------------------------------------------- in steam_raw_event()
1761 * 0-1 | always 0x01, 0x00, maybe protocol version? in steam_raw_event()
1764 * 4-n | payload data, depends on the type in steam_raw_event()
1767 * 0x01: input data (60 bytes) in steam_raw_event()
1770 * 0x09: Steam Deck input data (56 bytes) in steam_raw_event()
1778 if (steam->client_opened) in steam_raw_event()
1781 input = rcu_dereference(steam->input); in steam_raw_event()
1782 if (likely(input)) in steam_raw_event()
1783 steam_do_input_event(steam, input, data); in steam_raw_event()
1787 if (steam->client_opened) in steam_raw_event()
1790 input = rcu_dereference(steam->input); in steam_raw_event()
1791 if (likely(input)) in steam_raw_event()
1792 steam_do_deck_input_event(steam, input, data); in steam_raw_event()
1793 sensors = rcu_dereference(steam->sensors); in steam_raw_event()
1814 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_raw_event()
1816 battery = rcu_dereference(steam->battery); in steam_raw_event()
1844 if (!steam->client_opened) in steam_param_set_lizard_mode()
1881 .name = "hid-steam",