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

1 // SPDX-License-Identifier: GPL-2.0+
17 * This driver will disable the lizard mode when the input device is opened
18 * and re-enable it when the input device is closed, so as not to break user
22 * the hidraw interface directly to create input devices (XTest, uinput...).
25 * - it will not send any command to the controller.
26 * - this input device will be removed, to avoid double input of the same
28 * When the client is closed, this input device will be created again.
30 * For additional functions, such as changing the right-pad margin or switching
31 * the led, you can use the user-space tool at:
37 #include <linux/input.h>
45 #include "hid-ids.h"
118 struct input_dev __rcu *input; member
136 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_recv_report()
138 return -EINVAL; in steam_recv_report()
142 return -ENOMEM; in steam_recv_report()
150 ret = hid_hw_raw_request(steam->hdev, 0x00, in steam_recv_report()
154 memcpy(data, buf + 1, min(size, ret - 1)); in steam_recv_report()
167 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_send_report()
169 return -EINVAL; in steam_send_report()
173 return -ENOMEM; in steam_send_report()
185 ret = hid_hw_raw_request(steam->hdev, 0, in steam_send_report()
188 if (ret != -EPIPE) in steam_send_report()
191 } while (--retries); in steam_send_report()
195 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, in steam_send_report()
247 return -EIO; in steam_get_serial()
249 strlcpy(steam->serial_no, reply + 3, sizeof(steam->serial_no)); in steam_get_serial()
287 mutex_lock(&steam->mutex); in steam_input_open()
288 if (!steam->client_opened && lizard_mode) in steam_input_open()
290 mutex_unlock(&steam->mutex); in steam_input_open()
298 mutex_lock(&steam->mutex); in steam_input_close()
299 if (!steam->client_opened && lizard_mode) in steam_input_close()
301 mutex_unlock(&steam->mutex); in steam_input_close()
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()
328 val->intval = 1; in steam_battery_get_property()
331 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in steam_battery_get_property()
334 val->intval = volts * 1000; /* mV -> uV */ in steam_battery_get_property()
337 val->intval = batt; in steam_battery_get_property()
340 ret = -EINVAL; in steam_battery_get_property()
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()
358 GFP_KERNEL, "steam-controller-%s-battery", in steam_battery_register()
359 steam->serial_no); in steam_battery_register()
360 if (!steam->battery_desc.name) in steam_battery_register()
361 return -ENOMEM; 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()
385 struct hid_device *hdev = steam->hdev; in steam_input_register()
386 struct input_dev *input; in steam_input_register() local
390 input = rcu_dereference(steam->input); in steam_input_register()
392 if (input) { in steam_input_register()
397 input = input_allocate_device(); in steam_input_register()
398 if (!input) in steam_input_register()
399 return -ENOMEM; in steam_input_register()
401 input_set_drvdata(input, steam); in steam_input_register()
402 input->dev.parent = &hdev->dev; in steam_input_register()
403 input->open = steam_input_open; in steam_input_register()
404 input->close = steam_input_close; in steam_input_register()
406 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? in steam_input_register()
409 input->phys = hdev->phys; in steam_input_register()
410 input->uniq = steam->serial_no; in steam_input_register()
411 input->id.bustype = hdev->bus; in steam_input_register()
412 input->id.vendor = hdev->vendor; in steam_input_register()
413 input->id.product = hdev->product; in steam_input_register()
414 input->id.version = hdev->version; in steam_input_register()
416 input_set_capability(input, EV_KEY, BTN_TR2); in steam_input_register()
417 input_set_capability(input, EV_KEY, BTN_TL2); in steam_input_register()
418 input_set_capability(input, EV_KEY, BTN_TR); in steam_input_register()
419 input_set_capability(input, EV_KEY, BTN_TL); in steam_input_register()
420 input_set_capability(input, EV_KEY, BTN_Y); in steam_input_register()
421 input_set_capability(input, EV_KEY, BTN_B); in steam_input_register()
422 input_set_capability(input, EV_KEY, BTN_X); in steam_input_register()
423 input_set_capability(input, EV_KEY, BTN_A); in steam_input_register()
424 input_set_capability(input, EV_KEY, BTN_DPAD_UP); in steam_input_register()
425 input_set_capability(input, EV_KEY, BTN_DPAD_RIGHT); in steam_input_register()
426 input_set_capability(input, EV_KEY, BTN_DPAD_LEFT); in steam_input_register()
427 input_set_capability(input, EV_KEY, BTN_DPAD_DOWN); in steam_input_register()
428 input_set_capability(input, EV_KEY, BTN_SELECT); in steam_input_register()
429 input_set_capability(input, EV_KEY, BTN_MODE); in steam_input_register()
430 input_set_capability(input, EV_KEY, BTN_START); in steam_input_register()
431 input_set_capability(input, EV_KEY, BTN_GEAR_DOWN); in steam_input_register()
432 input_set_capability(input, EV_KEY, BTN_GEAR_UP); in steam_input_register()
433 input_set_capability(input, EV_KEY, BTN_THUMBR); in steam_input_register()
434 input_set_capability(input, EV_KEY, BTN_THUMBL); in steam_input_register()
435 input_set_capability(input, EV_KEY, BTN_THUMB); in steam_input_register()
436 input_set_capability(input, EV_KEY, BTN_THUMB2); in steam_input_register()
438 input_set_abs_params(input, ABS_HAT2Y, 0, 255, 0, 0); in steam_input_register()
439 input_set_abs_params(input, ABS_HAT2X, 0, 255, 0, 0); in steam_input_register()
440 input_set_abs_params(input, ABS_X, -32767, 32767, 0, 0); in steam_input_register()
441 input_set_abs_params(input, ABS_Y, -32767, 32767, 0, 0); in steam_input_register()
442 input_set_abs_params(input, ABS_RX, -32767, 32767, in steam_input_register()
444 input_set_abs_params(input, ABS_RY, -32767, 32767, in steam_input_register()
446 input_set_abs_params(input, ABS_HAT0X, -32767, 32767, in steam_input_register()
448 input_set_abs_params(input, ABS_HAT0Y, -32767, 32767, in steam_input_register()
450 input_abs_set_res(input, ABS_X, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
451 input_abs_set_res(input, ABS_Y, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
452 input_abs_set_res(input, ABS_RX, STEAM_PAD_RESOLUTION); in steam_input_register()
453 input_abs_set_res(input, ABS_RY, STEAM_PAD_RESOLUTION); in steam_input_register()
454 input_abs_set_res(input, ABS_HAT0X, STEAM_PAD_RESOLUTION); in steam_input_register()
455 input_abs_set_res(input, ABS_HAT0Y, STEAM_PAD_RESOLUTION); in steam_input_register()
456 input_abs_set_res(input, ABS_HAT2Y, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
457 input_abs_set_res(input, ABS_HAT2X, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
459 ret = input_register_device(input); in steam_input_register()
463 rcu_assign_pointer(steam->input, input); in steam_input_register()
467 input_free_device(input); in steam_input_register()
473 struct input_dev *input; in steam_input_unregister() local
475 input = rcu_dereference(steam->input); in steam_input_unregister()
477 if (!input) in steam_input_unregister()
479 RCU_INIT_POINTER(steam->input, NULL); in steam_input_unregister()
481 input_unregister_device(input); in steam_input_unregister()
489 battery = rcu_dereference(steam->battery); in steam_battery_unregister()
494 RCU_INIT_POINTER(steam->battery, NULL); in steam_battery_unregister()
510 if (!steam->serial_no[0]) { in steam_register()
515 mutex_lock(&steam->mutex); 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()
529 if (list_empty(&steam->list)) in steam_register()
530 list_add(&steam->list, &steam_devices); in steam_register()
534 mutex_lock(&steam->mutex); in steam_register()
535 client_opened = steam->client_opened; in steam_register()
538 mutex_unlock(&steam->mutex); in steam_register()
552 if (steam->serial_no[0]) { in steam_unregister()
553 hid_info(steam->hdev, "Steam Controller '%s' disconnected", in steam_unregister()
554 steam->serial_no); in steam_unregister()
556 list_del_init(&steam->list); in steam_unregister()
558 steam->serial_no[0] = 0; in steam_unregister()
570 spin_lock_irqsave(&steam->lock, flags); in steam_work_connect_cb()
571 connected = steam->connected; in steam_work_connect_cb()
572 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_connect_cb()
577 hid_err(steam->hdev, in steam_work_connect_cb()
597 * 1-4: slots where up to 4 real game pads will be connected to. in steam_is_valve_interface()
601 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; in steam_is_valve_interface()
602 return !list_empty(&rep_enum->report_list); in steam_is_valve_interface()
607 struct steam_device *steam = hdev->driver_data; in steam_client_ll_parse()
609 return hid_parse_report(hdev, steam->hdev->dev_rdesc, in steam_client_ll_parse()
610 steam->hdev->dev_rsize); in steam_client_ll_parse()
624 struct steam_device *steam = hdev->driver_data; in steam_client_ll_open()
626 mutex_lock(&steam->mutex); in steam_client_ll_open()
627 steam->client_opened = true; in steam_client_ll_open()
628 mutex_unlock(&steam->mutex); in steam_client_ll_open()
637 struct steam_device *steam = hdev->driver_data; in steam_client_ll_close()
642 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_close()
643 connected = steam->connected; in steam_client_ll_close()
644 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_close()
646 mutex_lock(&steam->mutex); in steam_client_ll_close()
647 steam->client_opened = false; in steam_client_ll_close()
650 mutex_unlock(&steam->mutex); in steam_client_ll_close()
661 struct steam_device *steam = hdev->driver_data; in steam_client_ll_raw_request()
663 return hid_hw_raw_request(steam->hdev, reportnum, buf, count, in steam_client_ll_raw_request()
684 client_hdev->ll_driver = &steam_client_ll_driver; in steam_create_client_hid()
685 client_hdev->dev.parent = hdev->dev.parent; in steam_create_client_hid()
686 client_hdev->bus = hdev->bus; in steam_create_client_hid()
687 client_hdev->vendor = hdev->vendor; in steam_create_client_hid()
688 client_hdev->product = hdev->product; in steam_create_client_hid()
689 client_hdev->version = hdev->version; in steam_create_client_hid()
690 client_hdev->type = hdev->type; in steam_create_client_hid()
691 client_hdev->country = hdev->country; in steam_create_client_hid()
692 strlcpy(client_hdev->name, hdev->name, in steam_create_client_hid()
693 sizeof(client_hdev->name)); in steam_create_client_hid()
694 strlcpy(client_hdev->phys, hdev->phys, in steam_create_client_hid()
695 sizeof(client_hdev->phys)); in steam_create_client_hid()
701 client_hdev->group = HID_GROUP_STEAM; in steam_create_client_hid()
722 if (hdev->group == HID_GROUP_STEAM) in steam_probe()
725 * The non-valve interfaces (mouse and keyboard emulation) are in steam_probe()
731 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); in steam_probe()
733 ret = -ENOMEM; in steam_probe()
736 steam->hdev = hdev; in steam_probe()
738 spin_lock_init(&steam->lock); in steam_probe()
739 mutex_init(&steam->mutex); in steam_probe()
740 steam->quirks = id->driver_data; in steam_probe()
741 INIT_WORK(&steam->work_connect, steam_work_connect_cb); in steam_probe()
742 INIT_LIST_HEAD(&steam->list); in steam_probe()
744 steam->client_hdev = steam_create_client_hid(hdev); in steam_probe()
745 if (IS_ERR(steam->client_hdev)) { in steam_probe()
746 ret = PTR_ERR(steam->client_hdev); in steam_probe()
749 steam->client_hdev->driver_data = steam; in steam_probe()
759 ret = hid_add_device(steam->client_hdev); in steam_probe()
771 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_probe()
774 steam->connected = false; in steam_probe()
778 steam->connected = true; in steam_probe()
795 hid_destroy_device(steam->client_hdev); in steam_probe()
797 cancel_work_sync(&steam->work_connect); in steam_probe()
808 if (!steam || hdev->group == HID_GROUP_STEAM) { in steam_remove()
813 hid_destroy_device(steam->client_hdev); in steam_remove()
814 steam->client_opened = false; in steam_remove()
815 cancel_work_sync(&steam->work_connect); in steam_remove()
816 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_remove()
829 spin_lock_irqsave(&steam->lock, flags); in steam_do_connect_event()
830 changed = steam->connected != connected; in steam_do_connect_event()
831 steam->connected = connected; in steam_do_connect_event()
832 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_connect_event()
834 if (changed && schedule_work(&steam->work_connect) == 0) in steam_do_connect_event()
840 * Some input data in the protocol has the opposite sign.
841 * Clamp the values to 32767..-32767 so that the range is
848 return x == -32768 ? -32767 : x; in steam_le16()
857 * -------+-------+-----------+--------------------------
858 * 4-7 | u32 | -- | sequence number
859 * 8-10 | 24bit | see below | buttons
862 * 13-15 | -- | -- | always 0
863 * 16-17 | s16 | ABS_X/ABS_HAT0X | X value
864 * 18-19 | s16 | ABS_Y/ABS_HAT0Y | Y value
865 * 20-21 | s16 | ABS_RX | right-pad X value
866 * 22-23 | s16 | ABS_RY | right-pad Y value
867 * 24-25 | s16 | -- | * left trigger
868 * 26-27 | s16 | -- | * right trigger
869 * 28-29 | s16 | -- | * accelerometer X value
870 * 30-31 | s16 | -- | * accelerometer Y value
871 * 32-33 | s16 | -- | * accelerometer Z value
872 * 34-35 | s16 | -- | gyro X value
873 * 36-36 | s16 | -- | gyro Y value
874 * 38-39 | s16 | -- | gyro Z value
875 * 40-41 | s16 | -- | quaternion W value
876 * 42-43 | s16 | -- | quaternion X value
877 * 44-45 | s16 | -- | quaternion Y value
878 * 46-47 | s16 | -- | quaternion Z value
879 * 48-49 | -- | -- | always 0
880 * 50-51 | s16 | -- | * left trigger (uncalibrated)
881 * 52-53 | s16 | -- | * right trigger (uncalibrated)
882 * 54-55 | s16 | -- | * joystick X value (uncalibrated)
883 * 56-57 | s16 | -- | * joystick Y value (uncalibrated)
884 * 58-59 | s16 | -- | * left-pad X value
885 * 60-61 | s16 | -- | * left-pad Y value
886 * 62-63 | u16 | -- | * battery voltage
890 * ------+------------+--------------------------------
899 * 9.0 | BTN_DPAD_UP | lef-pad up
900 * 9.1 | BTN_DPAD_RIGHT | lef-pad right
901 * 9.2 | BTN_DPAD_LEFT | lef-pad left
902 * 9.3 | BTN_DPAD_DOWN | lef-pad down
908 * 10.1 | -- | left-pad clicked
909 * 10.2 | BTN_THUMBR | right-pad clicked
910 * 10.3 | BTN_THUMB | left-pad touched (but see explanation below)
911 * 10.4 | BTN_THUMB2 | right-pad touched
912 * 10.5 | -- | unknown
914 * 10.7 | -- | lpad_and_joy
918 struct input_dev *input, u8 *data) in steam_do_input_event() argument
929 input_report_abs(input, ABS_HAT2Y, data[11]); in steam_do_input_event()
930 input_report_abs(input, ABS_HAT2X, data[12]); in steam_do_input_event()
943 y = -steam_le16(data + 18); in steam_do_input_event()
945 input_report_abs(input, lpad_touched ? ABS_HAT0X : ABS_X, x); in steam_do_input_event()
946 input_report_abs(input, lpad_touched ? ABS_HAT0Y : ABS_Y, y); in steam_do_input_event()
949 input_report_abs(input, ABS_X, 0); in steam_do_input_event()
950 input_report_abs(input, ABS_Y, 0); in steam_do_input_event()
954 input_report_abs(input, ABS_HAT0X, 0); in steam_do_input_event()
955 input_report_abs(input, ABS_HAT0Y, 0); in steam_do_input_event()
958 input_report_abs(input, ABS_RX, steam_le16(data + 20)); in steam_do_input_event()
959 input_report_abs(input, ABS_RY, -steam_le16(data + 22)); in steam_do_input_event()
961 input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); in steam_do_input_event()
962 input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); in steam_do_input_event()
963 input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); in steam_do_input_event()
964 input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); in steam_do_input_event()
965 input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); in steam_do_input_event()
966 input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); in steam_do_input_event()
967 input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); in steam_do_input_event()
968 input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); in steam_do_input_event()
969 input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); in steam_do_input_event()
970 input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); in steam_do_input_event()
971 input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); in steam_do_input_event()
972 input_event(input, EV_KEY, BTN_GEAR_DOWN, !!(b9 & BIT(7))); in steam_do_input_event()
973 input_event(input, EV_KEY, BTN_GEAR_UP, !!(b10 & BIT(0))); in steam_do_input_event()
974 input_event(input, EV_KEY, BTN_THUMBR, !!(b10 & BIT(2))); in steam_do_input_event()
975 input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); in steam_do_input_event()
976 input_event(input, EV_KEY, BTN_THUMB, lpad_touched || lpad_and_joy); in steam_do_input_event()
977 input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(4))); in steam_do_input_event()
978 input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); in steam_do_input_event()
979 input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); in steam_do_input_event()
980 input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); in steam_do_input_event()
981 input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); in steam_do_input_event()
983 input_sync(input); in steam_do_input_event()
990 * -------+-------+---------------------------
991 * 4-7 | u32 | sequence number
992 * 8-11 | -- | always 0
993 * 12-13 | u16 | voltage (mV)
1006 battery = rcu_dereference(steam->battery); in steam_do_battery_event()
1008 spin_lock_irqsave(&steam->lock, flags); in steam_do_battery_event()
1009 steam->voltage = volts; in steam_do_battery_event()
1010 steam->battery_charge = batt; in steam_do_battery_event()
1011 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_battery_event()
1022 struct input_dev *input; in steam_raw_event() local
1028 if (steam->client_opened) in steam_raw_event()
1029 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, in steam_raw_event()
1032 * All messages are size=64, all values little-endian. in steam_raw_event()
1035 * -------+-------------------------------------------- in steam_raw_event()
1036 * 0-1 | always 0x01, 0x00, maybe protocol version? in steam_raw_event()
1039 * 4-n | payload data, depends on the type in steam_raw_event()
1042 * 0x01: input data (60 bytes) in steam_raw_event()
1052 if (steam->client_opened) in steam_raw_event()
1055 input = rcu_dereference(steam->input); in steam_raw_event()
1056 if (likely(input)) in steam_raw_event()
1057 steam_do_input_event(steam, input, data); in steam_raw_event()
1076 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_raw_event()
1078 battery = rcu_dereference(steam->battery); in steam_raw_event()
1106 mutex_lock(&steam->mutex); in steam_param_set_lizard_mode()
1107 if (!steam->client_opened) in steam_param_set_lizard_mode()
1109 mutex_unlock(&steam->mutex); in steam_param_set_lizard_mode()
1140 .name = "hid-steam",