• Home
  • Raw
  • Download

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 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_recv_report()
139 return -EINVAL; in steam_recv_report()
143 return -EINVAL; in steam_recv_report()
147 return -ENOMEM; in steam_recv_report()
155 ret = hid_hw_raw_request(steam->hdev, 0x00, in steam_recv_report()
159 memcpy(data, buf + 1, min(size, ret - 1)); in steam_recv_report()
172 r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; in steam_send_report()
174 hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); in steam_send_report()
175 return -EINVAL; in steam_send_report()
179 return -EINVAL; in steam_send_report()
183 return -ENOMEM; in steam_send_report()
195 ret = hid_hw_raw_request(steam->hdev, 0, in steam_send_report()
198 if (ret != -EPIPE) in steam_send_report()
201 } while (--retries); in steam_send_report()
205 hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, in steam_send_report()
257 return -EIO; in steam_get_serial()
259 strlcpy(steam->serial_no, reply + 3, sizeof(steam->serial_no)); in steam_get_serial()
297 mutex_lock(&steam->mutex); in steam_input_open()
298 if (!steam->client_opened && lizard_mode) in steam_input_open()
300 mutex_unlock(&steam->mutex); in steam_input_open()
308 mutex_lock(&steam->mutex); in steam_input_close()
309 if (!steam->client_opened && lizard_mode) in steam_input_close()
311 mutex_unlock(&steam->mutex); in steam_input_close()
331 spin_lock_irqsave(&steam->lock, flags); in steam_battery_get_property()
332 volts = steam->voltage; in steam_battery_get_property()
333 batt = steam->battery_charge; in steam_battery_get_property()
334 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_get_property()
338 val->intval = 1; in steam_battery_get_property()
341 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in steam_battery_get_property()
344 val->intval = volts * 1000; /* mV -> uV */ in steam_battery_get_property()
347 val->intval = batt; in steam_battery_get_property()
350 ret = -EINVAL; in steam_battery_get_property()
363 steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in steam_battery_register()
364 steam->battery_desc.properties = steam_battery_props; in steam_battery_register()
365 steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props); in steam_battery_register()
366 steam->battery_desc.get_property = steam_battery_get_property; in steam_battery_register()
367 steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev, in steam_battery_register()
368 GFP_KERNEL, "steam-controller-%s-battery", in steam_battery_register()
369 steam->serial_no); in steam_battery_register()
370 if (!steam->battery_desc.name) in steam_battery_register()
371 return -ENOMEM; in steam_battery_register()
374 spin_lock_irqsave(&steam->lock, flags); in steam_battery_register()
375 steam->voltage = 3000; in steam_battery_register()
376 steam->battery_charge = 100; in steam_battery_register()
377 spin_unlock_irqrestore(&steam->lock, flags); in steam_battery_register()
379 battery = power_supply_register(&steam->hdev->dev, in steam_battery_register()
380 &steam->battery_desc, &battery_cfg); in steam_battery_register()
383 hid_err(steam->hdev, in steam_battery_register()
388 rcu_assign_pointer(steam->battery, battery); in steam_battery_register()
389 power_supply_powers(battery, &steam->hdev->dev); in steam_battery_register()
395 struct hid_device *hdev = steam->hdev; in steam_input_register()
396 struct input_dev *input; in steam_input_register() local
400 input = rcu_dereference(steam->input); in steam_input_register()
402 if (input) { in steam_input_register()
407 input = input_allocate_device(); in steam_input_register()
408 if (!input) in steam_input_register()
409 return -ENOMEM; in steam_input_register()
411 input_set_drvdata(input, steam); in steam_input_register()
412 input->dev.parent = &hdev->dev; in steam_input_register()
413 input->open = steam_input_open; in steam_input_register()
414 input->close = steam_input_close; in steam_input_register()
416 input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? in steam_input_register()
419 input->phys = hdev->phys; in steam_input_register()
420 input->uniq = steam->serial_no; in steam_input_register()
421 input->id.bustype = hdev->bus; in steam_input_register()
422 input->id.vendor = hdev->vendor; in steam_input_register()
423 input->id.product = hdev->product; in steam_input_register()
424 input->id.version = hdev->version; in steam_input_register()
426 input_set_capability(input, EV_KEY, BTN_TR2); in steam_input_register()
427 input_set_capability(input, EV_KEY, BTN_TL2); in steam_input_register()
428 input_set_capability(input, EV_KEY, BTN_TR); in steam_input_register()
429 input_set_capability(input, EV_KEY, BTN_TL); in steam_input_register()
430 input_set_capability(input, EV_KEY, BTN_Y); in steam_input_register()
431 input_set_capability(input, EV_KEY, BTN_B); in steam_input_register()
432 input_set_capability(input, EV_KEY, BTN_X); in steam_input_register()
433 input_set_capability(input, EV_KEY, BTN_A); in steam_input_register()
434 input_set_capability(input, EV_KEY, BTN_DPAD_UP); in steam_input_register()
435 input_set_capability(input, EV_KEY, BTN_DPAD_RIGHT); in steam_input_register()
436 input_set_capability(input, EV_KEY, BTN_DPAD_LEFT); in steam_input_register()
437 input_set_capability(input, EV_KEY, BTN_DPAD_DOWN); in steam_input_register()
438 input_set_capability(input, EV_KEY, BTN_SELECT); in steam_input_register()
439 input_set_capability(input, EV_KEY, BTN_MODE); in steam_input_register()
440 input_set_capability(input, EV_KEY, BTN_START); in steam_input_register()
441 input_set_capability(input, EV_KEY, BTN_GEAR_DOWN); in steam_input_register()
442 input_set_capability(input, EV_KEY, BTN_GEAR_UP); in steam_input_register()
443 input_set_capability(input, EV_KEY, BTN_THUMBR); in steam_input_register()
444 input_set_capability(input, EV_KEY, BTN_THUMBL); in steam_input_register()
445 input_set_capability(input, EV_KEY, BTN_THUMB); in steam_input_register()
446 input_set_capability(input, EV_KEY, BTN_THUMB2); in steam_input_register()
448 input_set_abs_params(input, ABS_HAT2Y, 0, 255, 0, 0); in steam_input_register()
449 input_set_abs_params(input, ABS_HAT2X, 0, 255, 0, 0); in steam_input_register()
450 input_set_abs_params(input, ABS_X, -32767, 32767, 0, 0); in steam_input_register()
451 input_set_abs_params(input, ABS_Y, -32767, 32767, 0, 0); in steam_input_register()
452 input_set_abs_params(input, ABS_RX, -32767, 32767, in steam_input_register()
454 input_set_abs_params(input, ABS_RY, -32767, 32767, in steam_input_register()
456 input_set_abs_params(input, ABS_HAT0X, -32767, 32767, in steam_input_register()
458 input_set_abs_params(input, ABS_HAT0Y, -32767, 32767, in steam_input_register()
460 input_abs_set_res(input, ABS_X, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
461 input_abs_set_res(input, ABS_Y, STEAM_JOYSTICK_RESOLUTION); in steam_input_register()
462 input_abs_set_res(input, ABS_RX, STEAM_PAD_RESOLUTION); in steam_input_register()
463 input_abs_set_res(input, ABS_RY, STEAM_PAD_RESOLUTION); in steam_input_register()
464 input_abs_set_res(input, ABS_HAT0X, STEAM_PAD_RESOLUTION); in steam_input_register()
465 input_abs_set_res(input, ABS_HAT0Y, STEAM_PAD_RESOLUTION); in steam_input_register()
466 input_abs_set_res(input, ABS_HAT2Y, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
467 input_abs_set_res(input, ABS_HAT2X, STEAM_TRIGGER_RESOLUTION); in steam_input_register()
469 ret = input_register_device(input); in steam_input_register()
473 rcu_assign_pointer(steam->input, input); in steam_input_register()
477 input_free_device(input); in steam_input_register()
483 struct input_dev *input; in steam_input_unregister() local
485 input = rcu_dereference(steam->input); in steam_input_unregister()
487 if (!input) in steam_input_unregister()
489 RCU_INIT_POINTER(steam->input, NULL); in steam_input_unregister()
491 input_unregister_device(input); in steam_input_unregister()
499 battery = rcu_dereference(steam->battery); in steam_battery_unregister()
504 RCU_INIT_POINTER(steam->battery, NULL); in steam_battery_unregister()
520 if (!steam->serial_no[0]) { in steam_register()
525 mutex_lock(&steam->mutex); in steam_register()
527 strlcpy(steam->serial_no, "XXXXXXXXXX", in steam_register()
528 sizeof(steam->serial_no)); in steam_register()
529 mutex_unlock(&steam->mutex); in steam_register()
531 hid_info(steam->hdev, "Steam Controller '%s' connected", in steam_register()
532 steam->serial_no); in steam_register()
535 if (steam->quirks & STEAM_QUIRK_WIRELESS) in steam_register()
539 if (list_empty(&steam->list)) in steam_register()
540 list_add(&steam->list, &steam_devices); in steam_register()
544 mutex_lock(&steam->mutex); in steam_register()
545 client_opened = steam->client_opened; in steam_register()
548 mutex_unlock(&steam->mutex); in steam_register()
562 if (steam->serial_no[0]) { in steam_unregister()
563 hid_info(steam->hdev, "Steam Controller '%s' disconnected", in steam_unregister()
564 steam->serial_no); in steam_unregister()
566 list_del_init(&steam->list); in steam_unregister()
568 steam->serial_no[0] = 0; in steam_unregister()
580 spin_lock_irqsave(&steam->lock, flags); in steam_work_connect_cb()
581 connected = steam->connected; in steam_work_connect_cb()
582 spin_unlock_irqrestore(&steam->lock, flags); in steam_work_connect_cb()
587 hid_err(steam->hdev, in steam_work_connect_cb()
607 * 1-4: slots where up to 4 real game pads will be connected to. in steam_is_valve_interface()
611 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; in steam_is_valve_interface()
612 return !list_empty(&rep_enum->report_list); in steam_is_valve_interface()
617 struct steam_device *steam = hdev->driver_data; in steam_client_ll_parse()
619 return hid_parse_report(hdev, steam->hdev->dev_rdesc, in steam_client_ll_parse()
620 steam->hdev->dev_rsize); in steam_client_ll_parse()
634 struct steam_device *steam = hdev->driver_data; in steam_client_ll_open()
636 mutex_lock(&steam->mutex); in steam_client_ll_open()
637 steam->client_opened = true; in steam_client_ll_open()
638 mutex_unlock(&steam->mutex); in steam_client_ll_open()
647 struct steam_device *steam = hdev->driver_data; in steam_client_ll_close()
652 spin_lock_irqsave(&steam->lock, flags); in steam_client_ll_close()
653 connected = steam->connected; in steam_client_ll_close()
654 spin_unlock_irqrestore(&steam->lock, flags); in steam_client_ll_close()
656 mutex_lock(&steam->mutex); in steam_client_ll_close()
657 steam->client_opened = false; in steam_client_ll_close()
660 mutex_unlock(&steam->mutex); in steam_client_ll_close()
671 struct steam_device *steam = hdev->driver_data; in steam_client_ll_raw_request()
673 return hid_hw_raw_request(steam->hdev, reportnum, buf, count, in steam_client_ll_raw_request()
694 client_hdev->ll_driver = &steam_client_ll_driver; in steam_create_client_hid()
695 client_hdev->dev.parent = hdev->dev.parent; in steam_create_client_hid()
696 client_hdev->bus = hdev->bus; in steam_create_client_hid()
697 client_hdev->vendor = hdev->vendor; in steam_create_client_hid()
698 client_hdev->product = hdev->product; in steam_create_client_hid()
699 client_hdev->version = hdev->version; in steam_create_client_hid()
700 client_hdev->type = hdev->type; in steam_create_client_hid()
701 client_hdev->country = hdev->country; in steam_create_client_hid()
702 strlcpy(client_hdev->name, hdev->name, in steam_create_client_hid()
703 sizeof(client_hdev->name)); in steam_create_client_hid()
704 strlcpy(client_hdev->phys, hdev->phys, in steam_create_client_hid()
705 sizeof(client_hdev->phys)); in steam_create_client_hid()
711 client_hdev->group = HID_GROUP_STEAM; in steam_create_client_hid()
732 if (hdev->group == HID_GROUP_STEAM) in steam_probe()
735 * The non-valve interfaces (mouse and keyboard emulation) are in steam_probe()
741 steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); in steam_probe()
743 ret = -ENOMEM; in steam_probe()
746 steam->hdev = hdev; in steam_probe()
748 spin_lock_init(&steam->lock); in steam_probe()
749 mutex_init(&steam->mutex); in steam_probe()
750 steam->quirks = id->driver_data; in steam_probe()
751 INIT_WORK(&steam->work_connect, steam_work_connect_cb); in steam_probe()
752 INIT_LIST_HEAD(&steam->list); in steam_probe()
754 steam->client_hdev = steam_create_client_hid(hdev); in steam_probe()
755 if (IS_ERR(steam->client_hdev)) { in steam_probe()
756 ret = PTR_ERR(steam->client_hdev); in steam_probe()
759 steam->client_hdev->driver_data = steam; in steam_probe()
769 ret = hid_add_device(steam->client_hdev); in steam_probe()
781 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_probe()
784 steam->connected = false; in steam_probe()
788 steam->connected = true; in steam_probe()
805 hid_destroy_device(steam->client_hdev); in steam_probe()
807 cancel_work_sync(&steam->work_connect); in steam_probe()
818 if (!steam || hdev->group == HID_GROUP_STEAM) { in steam_remove()
823 hid_destroy_device(steam->client_hdev); in steam_remove()
824 steam->client_opened = false; in steam_remove()
825 cancel_work_sync(&steam->work_connect); in steam_remove()
826 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_remove()
839 spin_lock_irqsave(&steam->lock, flags); in steam_do_connect_event()
840 changed = steam->connected != connected; in steam_do_connect_event()
841 steam->connected = connected; in steam_do_connect_event()
842 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_connect_event()
844 if (changed && schedule_work(&steam->work_connect) == 0) in steam_do_connect_event()
850 * Some input data in the protocol has the opposite sign.
851 * Clamp the values to 32767..-32767 so that the range is
858 return x == -32768 ? -32767 : x; in steam_le16()
867 * -------+-------+-----------+--------------------------
868 * 4-7 | u32 | -- | sequence number
869 * 8-10 | 24bit | see below | buttons
872 * 13-15 | -- | -- | always 0
873 * 16-17 | s16 | ABS_X/ABS_HAT0X | X value
874 * 18-19 | s16 | ABS_Y/ABS_HAT0Y | Y value
875 * 20-21 | s16 | ABS_RX | right-pad X value
876 * 22-23 | s16 | ABS_RY | right-pad Y value
877 * 24-25 | s16 | -- | * left trigger
878 * 26-27 | s16 | -- | * right trigger
879 * 28-29 | s16 | -- | * accelerometer X value
880 * 30-31 | s16 | -- | * accelerometer Y value
881 * 32-33 | s16 | -- | * accelerometer Z value
882 * 34-35 | s16 | -- | gyro X value
883 * 36-36 | s16 | -- | gyro Y value
884 * 38-39 | s16 | -- | gyro Z value
885 * 40-41 | s16 | -- | quaternion W value
886 * 42-43 | s16 | -- | quaternion X value
887 * 44-45 | s16 | -- | quaternion Y value
888 * 46-47 | s16 | -- | quaternion Z value
889 * 48-49 | -- | -- | always 0
890 * 50-51 | s16 | -- | * left trigger (uncalibrated)
891 * 52-53 | s16 | -- | * right trigger (uncalibrated)
892 * 54-55 | s16 | -- | * joystick X value (uncalibrated)
893 * 56-57 | s16 | -- | * joystick Y value (uncalibrated)
894 * 58-59 | s16 | -- | * left-pad X value
895 * 60-61 | s16 | -- | * left-pad Y value
896 * 62-63 | u16 | -- | * battery voltage
900 * ------+------------+--------------------------------
909 * 9.0 | BTN_DPAD_UP | lef-pad up
910 * 9.1 | BTN_DPAD_RIGHT | lef-pad right
911 * 9.2 | BTN_DPAD_LEFT | lef-pad left
912 * 9.3 | BTN_DPAD_DOWN | lef-pad down
918 * 10.1 | -- | left-pad clicked
919 * 10.2 | BTN_THUMBR | right-pad clicked
920 * 10.3 | BTN_THUMB | left-pad touched (but see explanation below)
921 * 10.4 | BTN_THUMB2 | right-pad touched
922 * 10.5 | -- | unknown
924 * 10.7 | -- | lpad_and_joy
928 struct input_dev *input, u8 *data) in steam_do_input_event() argument
939 input_report_abs(input, ABS_HAT2Y, data[11]); in steam_do_input_event()
940 input_report_abs(input, ABS_HAT2X, data[12]); in steam_do_input_event()
953 y = -steam_le16(data + 18); in steam_do_input_event()
955 input_report_abs(input, lpad_touched ? ABS_HAT0X : ABS_X, x); in steam_do_input_event()
956 input_report_abs(input, lpad_touched ? ABS_HAT0Y : ABS_Y, y); in steam_do_input_event()
959 input_report_abs(input, ABS_X, 0); in steam_do_input_event()
960 input_report_abs(input, ABS_Y, 0); in steam_do_input_event()
964 input_report_abs(input, ABS_HAT0X, 0); in steam_do_input_event()
965 input_report_abs(input, ABS_HAT0Y, 0); in steam_do_input_event()
968 input_report_abs(input, ABS_RX, steam_le16(data + 20)); in steam_do_input_event()
969 input_report_abs(input, ABS_RY, -steam_le16(data + 22)); in steam_do_input_event()
971 input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); in steam_do_input_event()
972 input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); in steam_do_input_event()
973 input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); in steam_do_input_event()
974 input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); in steam_do_input_event()
975 input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); in steam_do_input_event()
976 input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); in steam_do_input_event()
977 input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); in steam_do_input_event()
978 input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); in steam_do_input_event()
979 input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); in steam_do_input_event()
980 input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); in steam_do_input_event()
981 input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); in steam_do_input_event()
982 input_event(input, EV_KEY, BTN_GEAR_DOWN, !!(b9 & BIT(7))); in steam_do_input_event()
983 input_event(input, EV_KEY, BTN_GEAR_UP, !!(b10 & BIT(0))); in steam_do_input_event()
984 input_event(input, EV_KEY, BTN_THUMBR, !!(b10 & BIT(2))); in steam_do_input_event()
985 input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); in steam_do_input_event()
986 input_event(input, EV_KEY, BTN_THUMB, lpad_touched || lpad_and_joy); in steam_do_input_event()
987 input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(4))); in steam_do_input_event()
988 input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); in steam_do_input_event()
989 input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); in steam_do_input_event()
990 input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); in steam_do_input_event()
991 input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); in steam_do_input_event()
993 input_sync(input); in steam_do_input_event()
1000 * -------+-------+---------------------------
1001 * 4-7 | u32 | sequence number
1002 * 8-11 | -- | always 0
1003 * 12-13 | u16 | voltage (mV)
1016 battery = rcu_dereference(steam->battery); in steam_do_battery_event()
1018 spin_lock_irqsave(&steam->lock, flags); in steam_do_battery_event()
1019 steam->voltage = volts; in steam_do_battery_event()
1020 steam->battery_charge = batt; in steam_do_battery_event()
1021 spin_unlock_irqrestore(&steam->lock, flags); in steam_do_battery_event()
1032 struct input_dev *input; in steam_raw_event() local
1038 if (steam->client_opened) in steam_raw_event()
1039 hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, in steam_raw_event()
1042 * All messages are size=64, all values little-endian. in steam_raw_event()
1045 * -------+-------------------------------------------- in steam_raw_event()
1046 * 0-1 | always 0x01, 0x00, maybe protocol version? in steam_raw_event()
1049 * 4-n | payload data, depends on the type in steam_raw_event()
1052 * 0x01: input data (60 bytes) in steam_raw_event()
1062 if (steam->client_opened) in steam_raw_event()
1065 input = rcu_dereference(steam->input); in steam_raw_event()
1066 if (likely(input)) in steam_raw_event()
1067 steam_do_input_event(steam, input, data); in steam_raw_event()
1086 if (steam->quirks & STEAM_QUIRK_WIRELESS) { in steam_raw_event()
1088 battery = rcu_dereference(steam->battery); in steam_raw_event()
1116 mutex_lock(&steam->mutex); in steam_param_set_lizard_mode()
1117 if (!steam->client_opened) in steam_param_set_lizard_mode()
1119 mutex_unlock(&steam->mutex); in steam_param_set_lizard_mode()
1150 .name = "hid-steam",