diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2024-05-15 01:12:46 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2024-05-15 01:12:46 +0300 |
commit | 614da38e2f7afe9e01c6e359dfa09285f26fa381 (patch) | |
tree | bd5b66bade4842bb1a8b2c55771c1d23398a1213 /drivers/hid/hid-nintendo.c | |
parent | ce952d8f0e9b58dc6a2bde7e47ca7fa7925583cc (diff) | |
parent | c9c92fc4c2ef4e2f11af0ba19cb18d9b5e3e6f08 (diff) | |
download | linux-614da38e2f7afe9e01c6e359dfa09285f26fa381.tar.xz |
Merge tag 'hid-for-linus-2024051401' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID updates from Jiri Kosina:
- Firmware loading from host support in intel-ish driver, needed to
support Lunar Lake and later (Zhang Lixu)
- updates to HID-BPF infrastructure, with some of the specific fixes
(e.g. rdesc fixups) abstracted into separate BPF programs for
consumption from libevdev/udev-hid-bpf (Benjamin Tissoires)
- support for Deck IMU in hid-steam (Max Maisel)
- fixes for better support of 3rd party playstation DS4 controllers
(Max Staudt)
- support for missing mappings and codes from HUT 1.5 in hid-debug
(Thomas Kuehne)
- initial support for ROG Ally and ROG X13 devices (Luke D. Jones)
- full support for WinWing Orion2 (Ivan Gorinov)
* tag 'hid-for-linus-2024051401' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (74 commits)
selftests/hid: skip tests with HID-BPF if udev-hid-bpf is not installed
selftests/hid: add tests for the Raptor Mach 2 joystick
selftests/hid: move the gamepads definitions in the test file
selftests/hid: import base_gamepad.py from hid-tools
selftests/hid: add Huion Kamvas Pro 19 tests
selftests/hid: tablets: also check for XP-Pen offset correction
selftests/hid: tablets: add a couple of XP-PEN tablets
selftests/hid: tablets: reduce the number of pen state
selftests/hid: add support for HID-BPF pre-loading before starting a test
selftests/hid: import base_device.py from hid-tools
HID: bpf: add in-tree HID-BPF fix for the Raptor Mach 2
HID: bpf: add in-tree HID-BPF fix for the Huion Kamvas Pro 19
HID: bpf: add in-tree HID-BPF fix for the XBox Elite 2 over Bluetooth
HID: bpf: add in-tree HID-BPF fix for the Wacom ArtPen
HID: bpf: add in-tree HID-BPF fix for the IOGear Kaliber Gaming MMOmentum mouse
HID: bpf: add in-tree HID-BPF fix for the HP Elite Presenter Mouse
HID: bpf: add in-tree HID-BPF fix for the XPPen Artist 16
HID: bpf: add first in-tree HID-BPF fix for the XPPen Artist 24
HID: do not assume HAT Switch logical max < 8
HID: amd_sfh: Use amd_get_c2p_val() to read C2P register
...
Diffstat (limited to 'drivers/hid/hid-nintendo.c')
-rw-r--r-- | drivers/hid/hid-nintendo.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c index 80e0f23c1c33..b4a97803eca3 100644 --- a/drivers/hid/hid-nintendo.c +++ b/drivers/hid/hid-nintendo.c @@ -34,6 +34,7 @@ #include <linux/device.h> #include <linux/kernel.h> #include <linux/hid.h> +#include <linux/idr.h> #include <linux/input.h> #include <linux/jiffies.h> #include <linux/leds.h> @@ -569,6 +570,7 @@ static const enum led_brightness joycon_player_led_patterns[JC_NUM_LED_PATTERNS] struct joycon_ctlr { struct hid_device *hdev; struct input_dev *input; + u32 player_id; struct led_classdev leds[JC_NUM_LEDS]; /* player leds */ struct led_classdev home_led; enum joycon_ctlr_state ctlr_state; @@ -692,15 +694,6 @@ static inline bool joycon_device_is_n64con(struct joycon_ctlr *ctlr) return ctlr->hdev->product == USB_DEVICE_ID_NINTENDO_N64CON; } -static inline bool joycon_device_has_usb(struct joycon_ctlr *ctlr) -{ - return joycon_device_is_procon(ctlr) || - joycon_device_is_chrggrip(ctlr) || - joycon_device_is_snescon(ctlr) || - joycon_device_is_gencon(ctlr) || - joycon_device_is_n64con(ctlr); -} - /* * Controller type helpers * @@ -2261,7 +2254,8 @@ static int joycon_home_led_brightness_set(struct led_classdev *led, return ret; } -static DEFINE_SPINLOCK(joycon_input_num_spinlock); +static DEFINE_IDA(nintendo_player_id_allocator); + static int joycon_leds_create(struct joycon_ctlr *ctlr) { struct hid_device *hdev = ctlr->hdev; @@ -2272,20 +2266,19 @@ static int joycon_leds_create(struct joycon_ctlr *ctlr) char *name; int ret; int i; - unsigned long flags; int player_led_pattern; - static int input_num; - - /* - * Set the player leds based on controller number - * Because there is no standard concept of "player number", the pattern - * number will simply increase by 1 every time a controller is connected. - */ - spin_lock_irqsave(&joycon_input_num_spinlock, flags); - player_led_pattern = input_num++ % JC_NUM_LED_PATTERNS; - spin_unlock_irqrestore(&joycon_input_num_spinlock, flags); /* configure the player LEDs */ + ctlr->player_id = U32_MAX; + ret = ida_alloc(&nintendo_player_id_allocator, GFP_KERNEL); + if (ret < 0) { + hid_warn(hdev, "Failed to allocate player ID, skipping; ret=%d\n", ret); + goto home_led; + } + ctlr->player_id = ret; + player_led_pattern = ret % JC_NUM_LED_PATTERNS; + hid_info(ctlr->hdev, "assigned player %d led pattern", player_led_pattern + 1); + for (i = 0; i < JC_NUM_LEDS; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s:%s", d_name, @@ -2501,8 +2494,11 @@ static int joycon_init(struct hid_device *hdev) /* set baudrate for improved latency */ ret = joycon_send_usb(ctlr, JC_USB_CMD_BAUDRATE_3M, HZ); if (ret) { - hid_err(hdev, "Failed to set baudrate; ret=%d\n", ret); - goto out_unlock; + /* + * We can function with the default baudrate. + * Provide a warning, and continue on. + */ + hid_warn(hdev, "Failed to set baudrate (ret=%d), continuing anyway\n", ret); } /* handshake */ ret = joycon_send_usb(ctlr, JC_USB_CMD_HANDSHAKE, HZ); @@ -2767,6 +2763,7 @@ static void nintendo_hid_remove(struct hid_device *hdev) spin_unlock_irqrestore(&ctlr->lock, flags); destroy_workqueue(ctlr->rumble_queue); + ida_free(&nintendo_player_id_allocator, ctlr->player_id); hid_hw_close(hdev); hid_hw_stop(hdev); @@ -2824,7 +2821,19 @@ static struct hid_driver nintendo_hid_driver = { .resume = nintendo_hid_resume, #endif }; -module_hid_driver(nintendo_hid_driver); +static int __init nintendo_init(void) +{ + return hid_register_driver(&nintendo_hid_driver); +} + +static void __exit nintendo_exit(void) +{ + hid_unregister_driver(&nintendo_hid_driver); + ida_destroy(&nintendo_player_id_allocator); +} + +module_init(nintendo_init); +module_exit(nintendo_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Ryan McClelland <rymcclel@gmail.com>"); |