Lines Matching +full:0 +full:- +full:987
1 // SPDX-License-Identifier: GPL-2.0+
3 * HID driver for Nintendo Switch Joy-Cons and Pro Controllers
5 * Copyright (c) 2019-2021 Daniel J. Ogorchock <djogorchock@gmail.com>
9 * https://gitlab.com/pjranki/joycon-linux-kernel (Peter Rankin)
13 * hid-wiimote kernel hid driver
14 * hid-logitech-hidpp driver
15 * hid-sony driver
17 * This driver supports the Nintendo Switch Joy-Cons and Pro Controllers. The
25 #include "hid-ids.h"
44 #define JC_OUTPUT_RUMBLE_AND_SUBCMD 0x01
45 #define JC_OUTPUT_FW_UPDATE_PKT 0x03
46 #define JC_OUTPUT_RUMBLE_ONLY 0x10
47 #define JC_OUTPUT_MCU_DATA 0x11
48 #define JC_OUTPUT_USB_CMD 0x80
51 #define JC_SUBCMD_STATE 0x00
52 #define JC_SUBCMD_MANUAL_BT_PAIRING 0x01
53 #define JC_SUBCMD_REQ_DEV_INFO 0x02
54 #define JC_SUBCMD_SET_REPORT_MODE 0x03
55 #define JC_SUBCMD_TRIGGERS_ELAPSED 0x04
56 #define JC_SUBCMD_GET_PAGE_LIST_STATE 0x05
57 #define JC_SUBCMD_SET_HCI_STATE 0x06
58 #define JC_SUBCMD_RESET_PAIRING_INFO 0x07
59 #define JC_SUBCMD_LOW_POWER_MODE 0x08
60 #define JC_SUBCMD_SPI_FLASH_READ 0x10
61 #define JC_SUBCMD_SPI_FLASH_WRITE 0x11
62 #define JC_SUBCMD_RESET_MCU 0x20
63 #define JC_SUBCMD_SET_MCU_CONFIG 0x21
64 #define JC_SUBCMD_SET_MCU_STATE 0x22
65 #define JC_SUBCMD_SET_PLAYER_LIGHTS 0x30
66 #define JC_SUBCMD_GET_PLAYER_LIGHTS 0x31
67 #define JC_SUBCMD_SET_HOME_LIGHT 0x38
68 #define JC_SUBCMD_ENABLE_IMU 0x40
69 #define JC_SUBCMD_SET_IMU_SENSITIVITY 0x41
70 #define JC_SUBCMD_WRITE_IMU_REG 0x42
71 #define JC_SUBCMD_READ_IMU_REG 0x43
72 #define JC_SUBCMD_ENABLE_VIBRATION 0x48
73 #define JC_SUBCMD_GET_REGULATED_VOLTAGE 0x50
76 #define JC_INPUT_BUTTON_EVENT 0x3F
77 #define JC_INPUT_SUBCMD_REPLY 0x21
78 #define JC_INPUT_IMU_DATA 0x30
79 #define JC_INPUT_MCU_DATA 0x31
80 #define JC_INPUT_USB_RESPONSE 0x81
83 #define JC_FEATURE_LAST_SUBCMD 0x02
84 #define JC_FEATURE_OTA_FW_UPGRADE 0x70
85 #define JC_FEATURE_SETUP_MEM_READ 0x71
86 #define JC_FEATURE_MEM_READ 0x72
87 #define JC_FEATURE_ERASE_MEM_SECTOR 0x73
88 #define JC_FEATURE_MEM_WRITE 0x74
89 #define JC_FEATURE_LAUNCH 0x75
92 #define JC_USB_CMD_CONN_STATUS 0x01
93 #define JC_USB_CMD_HANDSHAKE 0x02
94 #define JC_USB_CMD_BAUDRATE_3M 0x03
95 #define JC_USB_CMD_NO_TIMEOUT 0x04
96 #define JC_USB_CMD_EN_TIMEOUT 0x05
97 #define JC_USB_RESET 0x06
98 #define JC_USB_PRE_HANDSHAKE 0x91
99 #define JC_USB_SEND_UART 0x92
102 #define JC_CAL_USR_MAGIC_0 0xB2
103 #define JC_CAL_USR_MAGIC_1 0xA1
107 #define JC_CAL_USR_LEFT_MAGIC_ADDR 0x8010
108 #define JC_CAL_USR_LEFT_DATA_ADDR 0x8012
109 #define JC_CAL_USR_LEFT_DATA_END 0x801A
110 #define JC_CAL_USR_RIGHT_MAGIC_ADDR 0x801B
111 #define JC_CAL_USR_RIGHT_DATA_ADDR 0x801D
113 (JC_CAL_USR_LEFT_DATA_END - JC_CAL_USR_LEFT_DATA_ADDR + 1)
116 #define JC_CAL_FCT_DATA_LEFT_ADDR 0x603d
117 #define JC_CAL_FCT_DATA_RIGHT_ADDR 0x6046
120 #define JC_IMU_CAL_FCT_DATA_ADDR 0x6020
121 #define JC_IMU_CAL_FCT_DATA_END 0x6037
123 (JC_IMU_CAL_FCT_DATA_END - JC_IMU_CAL_FCT_DATA_ADDR + 1)
125 #define JC_IMU_CAL_USR_MAGIC_ADDR 0x8026
126 #define JC_IMU_CAL_USR_DATA_ADDR 0x8028
133 /* Hat values for pro controller's d-pad */
135 #define JC_DPAD_FUZZ 0
136 #define JC_DPAD_FLAT 0
147 * configured with a range of +-8000 milliGs. Therefore, the resolution can be
148 * calculated thus: (2^16-1)/(8000 * 2) = 4.096 digits per milliG
155 #define JC_IMU_ACCEL_FLAT 0
159 * configured with a range of +-2000 degrees/second.
160 * Digits per dps: (2^16 -1)/(2000*2) = 16.38375
161 * dps per digit: 16.38375E-1 = .0610
167 * digits per dps (corrected): .0702E-1 = 14.247
174 #define JC_IMU_MAX_GYRO_MAG 32767000 /* (2^16-1)*1000 */
177 #define JC_IMU_GYRO_FLAT 0
199 { 0x0000, 0x01, 41 }, { 0x0000, 0x02, 42 }, { 0x0000, 0x03, 43 },
200 { 0x0000, 0x04, 44 }, { 0x0000, 0x05, 45 }, { 0x0000, 0x06, 46 },
201 { 0x0000, 0x07, 47 }, { 0x0000, 0x08, 48 }, { 0x0000, 0x09, 49 },
202 { 0x0000, 0x0A, 50 }, { 0x0000, 0x0B, 51 }, { 0x0000, 0x0C, 52 },
203 { 0x0000, 0x0D, 53 }, { 0x0000, 0x0E, 54 }, { 0x0000, 0x0F, 55 },
204 { 0x0000, 0x10, 57 }, { 0x0000, 0x11, 58 }, { 0x0000, 0x12, 59 },
205 { 0x0000, 0x13, 60 }, { 0x0000, 0x14, 62 }, { 0x0000, 0x15, 63 },
206 { 0x0000, 0x16, 64 }, { 0x0000, 0x17, 66 }, { 0x0000, 0x18, 67 },
207 { 0x0000, 0x19, 69 }, { 0x0000, 0x1A, 70 }, { 0x0000, 0x1B, 72 },
208 { 0x0000, 0x1C, 73 }, { 0x0000, 0x1D, 75 }, { 0x0000, 0x1e, 77 },
209 { 0x0000, 0x1f, 78 }, { 0x0000, 0x20, 80 }, { 0x0400, 0x21, 82 },
210 { 0x0800, 0x22, 84 }, { 0x0c00, 0x23, 85 }, { 0x1000, 0x24, 87 },
211 { 0x1400, 0x25, 89 }, { 0x1800, 0x26, 91 }, { 0x1c00, 0x27, 93 },
212 { 0x2000, 0x28, 95 }, { 0x2400, 0x29, 97 }, { 0x2800, 0x2a, 99 },
213 { 0x2c00, 0x2b, 102 }, { 0x3000, 0x2c, 104 }, { 0x3400, 0x2d, 106 },
214 { 0x3800, 0x2e, 108 }, { 0x3c00, 0x2f, 111 }, { 0x4000, 0x30, 113 },
215 { 0x4400, 0x31, 116 }, { 0x4800, 0x32, 118 }, { 0x4c00, 0x33, 121 },
216 { 0x5000, 0x34, 123 }, { 0x5400, 0x35, 126 }, { 0x5800, 0x36, 129 },
217 { 0x5c00, 0x37, 132 }, { 0x6000, 0x38, 135 }, { 0x6400, 0x39, 137 },
218 { 0x6800, 0x3a, 141 }, { 0x6c00, 0x3b, 144 }, { 0x7000, 0x3c, 147 },
219 { 0x7400, 0x3d, 150 }, { 0x7800, 0x3e, 153 }, { 0x7c00, 0x3f, 157 },
220 { 0x8000, 0x40, 160 }, { 0x8400, 0x41, 164 }, { 0x8800, 0x42, 167 },
221 { 0x8c00, 0x43, 171 }, { 0x9000, 0x44, 174 }, { 0x9400, 0x45, 178 },
222 { 0x9800, 0x46, 182 }, { 0x9c00, 0x47, 186 }, { 0xa000, 0x48, 190 },
223 { 0xa400, 0x49, 194 }, { 0xa800, 0x4a, 199 }, { 0xac00, 0x4b, 203 },
224 { 0xb000, 0x4c, 207 }, { 0xb400, 0x4d, 212 }, { 0xb800, 0x4e, 217 },
225 { 0xbc00, 0x4f, 221 }, { 0xc000, 0x50, 226 }, { 0xc400, 0x51, 231 },
226 { 0xc800, 0x52, 236 }, { 0xcc00, 0x53, 241 }, { 0xd000, 0x54, 247 },
227 { 0xd400, 0x55, 252 }, { 0xd800, 0x56, 258 }, { 0xdc00, 0x57, 263 },
228 { 0xe000, 0x58, 269 }, { 0xe400, 0x59, 275 }, { 0xe800, 0x5a, 281 },
229 { 0xec00, 0x5b, 287 }, { 0xf000, 0x5c, 293 }, { 0xf400, 0x5d, 300 },
230 { 0xf800, 0x5e, 306 }, { 0xfc00, 0x5f, 313 }, { 0x0001, 0x60, 320 },
231 { 0x0401, 0x61, 327 }, { 0x0801, 0x62, 334 }, { 0x0c01, 0x63, 341 },
232 { 0x1001, 0x64, 349 }, { 0x1401, 0x65, 357 }, { 0x1801, 0x66, 364 },
233 { 0x1c01, 0x67, 372 }, { 0x2001, 0x68, 381 }, { 0x2401, 0x69, 389 },
234 { 0x2801, 0x6a, 397 }, { 0x2c01, 0x6b, 406 }, { 0x3001, 0x6c, 415 },
235 { 0x3401, 0x6d, 424 }, { 0x3801, 0x6e, 433 }, { 0x3c01, 0x6f, 443 },
236 { 0x4001, 0x70, 453 }, { 0x4401, 0x71, 462 }, { 0x4801, 0x72, 473 },
237 { 0x4c01, 0x73, 483 }, { 0x5001, 0x74, 494 }, { 0x5401, 0x75, 504 },
238 { 0x5801, 0x76, 515 }, { 0x5c01, 0x77, 527 }, { 0x6001, 0x78, 538 },
239 { 0x6401, 0x79, 550 }, { 0x6801, 0x7a, 562 }, { 0x6c01, 0x7b, 574 },
240 { 0x7001, 0x7c, 587 }, { 0x7401, 0x7d, 600 }, { 0x7801, 0x7e, 613 },
241 { 0x7c01, 0x7f, 626 }, { 0x8001, 0x00, 640 }, { 0x8401, 0x00, 654 },
242 { 0x8801, 0x00, 668 }, { 0x8c01, 0x00, 683 }, { 0x9001, 0x00, 698 },
243 { 0x9401, 0x00, 713 }, { 0x9801, 0x00, 729 }, { 0x9c01, 0x00, 745 },
244 { 0xa001, 0x00, 761 }, { 0xa401, 0x00, 778 }, { 0xa801, 0x00, 795 },
245 { 0xac01, 0x00, 812 }, { 0xb001, 0x00, 830 }, { 0xb401, 0x00, 848 },
246 { 0xb801, 0x00, 867 }, { 0xbc01, 0x00, 886 }, { 0xc001, 0x00, 905 },
247 { 0xc401, 0x00, 925 }, { 0xc801, 0x00, 945 }, { 0xcc01, 0x00, 966 },
248 { 0xd001, 0x00, 987 }, { 0xd401, 0x00, 1009 }, { 0xd801, 0x00, 1031 },
249 { 0xdc01, 0x00, 1053 }, { 0xe001, 0x00, 1076 }, { 0xe401, 0x00, 1100 },
250 { 0xe801, 0x00, 1124 }, { 0xec01, 0x00, 1149 }, { 0xf001, 0x00, 1174 },
251 { 0xf401, 0x00, 1199 }, { 0xf801, 0x00, 1226 }, { 0xfc01, 0x00, 1253 }
257 { 0x00, 0x0040, 0 },
258 { 0x02, 0x8040, 10 }, { 0x04, 0x0041, 12 }, { 0x06, 0x8041, 14 },
259 { 0x08, 0x0042, 17 }, { 0x0a, 0x8042, 20 }, { 0x0c, 0x0043, 24 },
260 { 0x0e, 0x8043, 28 }, { 0x10, 0x0044, 33 }, { 0x12, 0x8044, 40 },
261 { 0x14, 0x0045, 47 }, { 0x16, 0x8045, 56 }, { 0x18, 0x0046, 67 },
262 { 0x1a, 0x8046, 80 }, { 0x1c, 0x0047, 95 }, { 0x1e, 0x8047, 112 },
263 { 0x20, 0x0048, 117 }, { 0x22, 0x8048, 123 }, { 0x24, 0x0049, 128 },
264 { 0x26, 0x8049, 134 }, { 0x28, 0x004a, 140 }, { 0x2a, 0x804a, 146 },
265 { 0x2c, 0x004b, 152 }, { 0x2e, 0x804b, 159 }, { 0x30, 0x004c, 166 },
266 { 0x32, 0x804c, 173 }, { 0x34, 0x004d, 181 }, { 0x36, 0x804d, 189 },
267 { 0x38, 0x004e, 198 }, { 0x3a, 0x804e, 206 }, { 0x3c, 0x004f, 215 },
268 { 0x3e, 0x804f, 225 }, { 0x40, 0x0050, 230 }, { 0x42, 0x8050, 235 },
269 { 0x44, 0x0051, 240 }, { 0x46, 0x8051, 245 }, { 0x48, 0x0052, 251 },
270 { 0x4a, 0x8052, 256 }, { 0x4c, 0x0053, 262 }, { 0x4e, 0x8053, 268 },
271 { 0x50, 0x0054, 273 }, { 0x52, 0x8054, 279 }, { 0x54, 0x0055, 286 },
272 { 0x56, 0x8055, 292 }, { 0x58, 0x0056, 298 }, { 0x5a, 0x8056, 305 },
273 { 0x5c, 0x0057, 311 }, { 0x5e, 0x8057, 318 }, { 0x60, 0x0058, 325 },
274 { 0x62, 0x8058, 332 }, { 0x64, 0x0059, 340 }, { 0x66, 0x8059, 347 },
275 { 0x68, 0x005a, 355 }, { 0x6a, 0x805a, 362 }, { 0x6c, 0x005b, 370 },
276 { 0x6e, 0x805b, 378 }, { 0x70, 0x005c, 387 }, { 0x72, 0x805c, 395 },
277 { 0x74, 0x005d, 404 }, { 0x76, 0x805d, 413 }, { 0x78, 0x005e, 422 },
278 { 0x7a, 0x805e, 431 }, { 0x7c, 0x005f, 440 }, { 0x7e, 0x805f, 450 },
279 { 0x80, 0x0060, 460 }, { 0x82, 0x8060, 470 }, { 0x84, 0x0061, 480 },
280 { 0x86, 0x8061, 491 }, { 0x88, 0x0062, 501 }, { 0x8a, 0x8062, 512 },
281 { 0x8c, 0x0063, 524 }, { 0x8e, 0x8063, 535 }, { 0x90, 0x0064, 547 },
282 { 0x92, 0x8064, 559 }, { 0x94, 0x0065, 571 }, { 0x96, 0x8065, 584 },
283 { 0x98, 0x0066, 596 }, { 0x9a, 0x8066, 609 }, { 0x9c, 0x0067, 623 },
284 { 0x9e, 0x8067, 636 }, { 0xa0, 0x0068, 650 }, { 0xa2, 0x8068, 665 },
285 { 0xa4, 0x0069, 679 }, { 0xa6, 0x8069, 694 }, { 0xa8, 0x006a, 709 },
286 { 0xaa, 0x806a, 725 }, { 0xac, 0x006b, 741 }, { 0xae, 0x806b, 757 },
287 { 0xb0, 0x006c, 773 }, { 0xb2, 0x806c, 790 }, { 0xb4, 0x006d, 808 },
288 { 0xb6, 0x806d, 825 }, { 0xb8, 0x006e, 843 }, { 0xba, 0x806e, 862 },
289 { 0xbc, 0x006f, 881 }, { 0xbe, 0x806f, 900 }, { 0xc0, 0x0070, 920 },
290 { 0xc2, 0x8070, 940 }, { 0xc4, 0x0071, 960 }, { 0xc6, 0x8071, 981 },
291 { 0xc8, 0x0072, joycon_max_rumble_amp }
308 JOYCON_CTLR_TYPE_JCL = 0x01,
309 JOYCON_CTLR_TYPE_JCR = 0x02,
310 JOYCON_CTLR_TYPE_PRO = 0x03,
328 static const u32 JC_BTN_Y = BIT(0);
364 u8 output_id; /* must be 0x01 for subcommand, 0x10 for rumble only */
372 u8 ack; /* MSB 1 for ACK, 0 for NACK */
484 (ctlr->hdev->product == USB_DEVICE_ID_NINTENDO_JOYCONL || \
485 ctlr->hdev->product == USB_DEVICE_ID_NINTENDO_JOYCONR || \
486 ctlr->hdev->product == USB_DEVICE_ID_NINTENDO_CHRGGRIP)
488 (ctlr->hdev->product == USB_DEVICE_ID_NINTENDO_PROCON)
490 (ctlr->hdev->product == USB_DEVICE_ID_NINTENDO_CHRGGRIP)
494 (ctlr->ctlr_type == JOYCON_CTLR_TYPE_JCL || \
495 ctlr->ctlr_type == JOYCON_CTLR_TYPE_PRO)
499 (ctlr->ctlr_type == JOYCON_CTLR_TYPE_JCR || \
500 ctlr->ctlr_type == JOYCON_CTLR_TYPE_PRO)
509 return -ENOMEM; in __joycon_hid_send()
512 if (ret < 0) in __joycon_hid_send()
526 if (ctlr->ctlr_state == JOYCON_CTLR_STATE_READ) { in joycon_wait_for_input_report()
529 spin_lock_irqsave(&ctlr->lock, flags); in joycon_wait_for_input_report()
530 ctlr->received_input_report = false; in joycon_wait_for_input_report()
531 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_wait_for_input_report()
532 ret = wait_event_timeout(ctlr->wait, in joycon_wait_for_input_report()
533 ctlr->received_input_report, in joycon_wait_for_input_report()
537 hid_warn(ctlr->hdev, in joycon_wait_for_input_report()
550 unsigned int delta_ms = current_ms - ctlr->last_subcmd_sent_msecs; in joycon_enforce_subcmd_rate()
553 ctlr->ctlr_state == JOYCON_CTLR_STATE_READ) { in joycon_enforce_subcmd_rate()
556 delta_ms = current_ms - ctlr->last_subcmd_sent_msecs; in joycon_enforce_subcmd_rate()
558 ctlr->last_subcmd_sent_msecs = current_ms; in joycon_enforce_subcmd_rate()
571 while (tries--) { in joycon_hid_send_sync()
574 ret = __joycon_hid_send(ctlr->hdev, data, len); in joycon_hid_send_sync()
575 if (ret < 0) { in joycon_hid_send_sync()
576 memset(ctlr->input_buf, 0, JC_MAX_RESP_SIZE); in joycon_hid_send_sync()
580 ret = wait_event_timeout(ctlr->wait, ctlr->received_resp, in joycon_hid_send_sync()
583 hid_dbg(ctlr->hdev, in joycon_hid_send_sync()
586 hid_dbg(ctlr->hdev, in joycon_hid_send_sync()
589 memset(ctlr->input_buf, 0, JC_MAX_RESP_SIZE); in joycon_hid_send_sync()
590 ret = -ETIMEDOUT; in joycon_hid_send_sync()
592 ret = 0; in joycon_hid_send_sync()
597 ctlr->received_resp = false; in joycon_hid_send_sync()
607 ctlr->usb_ack_match = cmd; in joycon_send_usb()
608 ctlr->msg_type = JOYCON_MSG_TYPE_USB; in joycon_send_usb()
611 hid_dbg(ctlr->hdev, "send usb command failed; ret=%d\n", ret); in joycon_send_usb()
622 spin_lock_irqsave(&ctlr->lock, flags); in joycon_send_subcmd()
627 if (ctlr->ctlr_state == JOYCON_CTLR_STATE_REMOVED) { in joycon_send_subcmd()
628 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_send_subcmd()
629 return -ENODEV; in joycon_send_subcmd()
631 memcpy(subcmd->rumble_data, ctlr->rumble_data[ctlr->rumble_queue_tail], in joycon_send_subcmd()
633 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_send_subcmd()
635 subcmd->output_id = JC_OUTPUT_RUMBLE_AND_SUBCMD; in joycon_send_subcmd()
636 subcmd->packet_num = ctlr->subcmd_num; in joycon_send_subcmd()
637 if (++ctlr->subcmd_num > 0xF) in joycon_send_subcmd()
638 ctlr->subcmd_num = 0; in joycon_send_subcmd()
639 ctlr->subcmd_ack_match = subcmd->subcmd_id; in joycon_send_subcmd()
640 ctlr->msg_type = JOYCON_MSG_TYPE_SUBCMD; in joycon_send_subcmd()
644 if (ret < 0) in joycon_send_subcmd()
645 hid_dbg(ctlr->hdev, "send subcommand failed; ret=%d\n", ret); in joycon_send_subcmd()
647 ret = 0; in joycon_send_subcmd()
655 u8 buffer[sizeof(*req) + 1] = { 0 }; in joycon_set_player_leds()
658 req->subcmd_id = JC_SUBCMD_SET_PLAYER_LIGHTS; in joycon_set_player_leds()
659 req->data[0] = (flash << 4) | on; in joycon_set_player_leds()
661 hid_dbg(ctlr->hdev, "setting player leds\n"); in joycon_set_player_leds()
670 u8 buffer[sizeof(*req) + 5] = { 0 }; in joycon_request_spi_flash_read()
675 return -EINVAL; in joycon_request_spi_flash_read()
678 req->subcmd_id = JC_SUBCMD_SPI_FLASH_READ; in joycon_request_spi_flash_read()
679 data = req->data; in joycon_request_spi_flash_read()
683 hid_dbg(ctlr->hdev, "requesting SPI flash data\n"); in joycon_request_spi_flash_read()
686 hid_err(ctlr->hdev, "failed reading SPI flash; ret=%d\n", ret); in joycon_request_spi_flash_read()
688 report = (struct joycon_input_report *)ctlr->input_buf; in joycon_request_spi_flash_read()
690 *reply = &report->subcmd_reply.data[5]; in joycon_request_spi_flash_read()
697 * returns 0 if magic val is present, 1 if not present, < 0 on error
709 return reply[0] != JC_CAL_USR_MAGIC_0 || reply[1] != JC_CAL_USR_MAGIC_1; in joycon_check_for_cal_magic()
731 x_max_above = hid_field_extract(ctlr->hdev, (raw_cal + 0), 0, in joycon_read_stick_calibration()
733 y_max_above = hid_field_extract(ctlr->hdev, (raw_cal + 1), 4, in joycon_read_stick_calibration()
735 cal_x->center = hid_field_extract(ctlr->hdev, (raw_cal + 3), 0, in joycon_read_stick_calibration()
737 cal_y->center = hid_field_extract(ctlr->hdev, (raw_cal + 4), 4, in joycon_read_stick_calibration()
739 x_min_below = hid_field_extract(ctlr->hdev, (raw_cal + 6), 0, in joycon_read_stick_calibration()
741 y_min_below = hid_field_extract(ctlr->hdev, (raw_cal + 7), 4, in joycon_read_stick_calibration()
744 cal_x->center = hid_field_extract(ctlr->hdev, (raw_cal + 0), 0, in joycon_read_stick_calibration()
746 cal_y->center = hid_field_extract(ctlr->hdev, (raw_cal + 1), 4, in joycon_read_stick_calibration()
748 x_min_below = hid_field_extract(ctlr->hdev, (raw_cal + 3), 0, in joycon_read_stick_calibration()
750 y_min_below = hid_field_extract(ctlr->hdev, (raw_cal + 4), 4, in joycon_read_stick_calibration()
752 x_max_above = hid_field_extract(ctlr->hdev, (raw_cal + 6), 0, in joycon_read_stick_calibration()
754 y_max_above = hid_field_extract(ctlr->hdev, (raw_cal + 7), 4, in joycon_read_stick_calibration()
758 cal_x->max = cal_x->center + x_max_above; in joycon_read_stick_calibration()
759 cal_x->min = cal_x->center - x_min_below; in joycon_read_stick_calibration()
760 cal_y->max = cal_y->center + y_max_above; in joycon_read_stick_calibration()
761 cal_y->min = cal_y->center - y_min_below; in joycon_read_stick_calibration()
764 if (cal_x->min >= cal_x->center || cal_x->center >= cal_x->max || in joycon_read_stick_calibration()
765 cal_y->min >= cal_y->center || cal_y->center >= cal_y->max) in joycon_read_stick_calibration()
766 ret = -EINVAL; in joycon_read_stick_calibration()
783 cal_x->center = cal_y->center = DFLT_STICK_CAL_CEN; in joycon_use_default_calibration()
784 cal_x->max = cal_y->max = DFLT_STICK_CAL_MAX; in joycon_use_default_calibration()
785 cal_x->min = cal_y->min = DFLT_STICK_CAL_MIN; in joycon_use_default_calibration()
794 hid_dbg(ctlr->hdev, "requesting cal data\n"); in joycon_request_calibration()
799 hid_info(ctlr->hdev, "using user cal for left stick\n"); in joycon_request_calibration()
801 hid_info(ctlr->hdev, "using factory cal for left stick\n"); in joycon_request_calibration()
805 hid_info(ctlr->hdev, "using user cal for right stick\n"); in joycon_request_calibration()
807 hid_info(ctlr->hdev, "using factory cal for right stick\n"); in joycon_request_calibration()
812 &ctlr->left_stick_cal_x, in joycon_request_calibration()
813 &ctlr->left_stick_cal_y, in joycon_request_calibration()
817 joycon_use_default_calibration(ctlr->hdev, in joycon_request_calibration()
818 &ctlr->left_stick_cal_x, in joycon_request_calibration()
819 &ctlr->left_stick_cal_y, in joycon_request_calibration()
824 &ctlr->right_stick_cal_x, in joycon_request_calibration()
825 &ctlr->right_stick_cal_y, in joycon_request_calibration()
829 joycon_use_default_calibration(ctlr->hdev, in joycon_request_calibration()
830 &ctlr->right_stick_cal_x, in joycon_request_calibration()
831 &ctlr->right_stick_cal_y, in joycon_request_calibration()
834 hid_dbg(ctlr->hdev, "calibration:\n" in joycon_request_calibration()
839 ctlr->left_stick_cal_x.center, in joycon_request_calibration()
840 ctlr->left_stick_cal_x.max, in joycon_request_calibration()
841 ctlr->left_stick_cal_x.min, in joycon_request_calibration()
842 ctlr->left_stick_cal_y.center, in joycon_request_calibration()
843 ctlr->left_stick_cal_y.max, in joycon_request_calibration()
844 ctlr->left_stick_cal_y.min, in joycon_request_calibration()
845 ctlr->right_stick_cal_x.center, in joycon_request_calibration()
846 ctlr->right_stick_cal_x.max, in joycon_request_calibration()
847 ctlr->right_stick_cal_x.min, in joycon_request_calibration()
848 ctlr->right_stick_cal_y.center, in joycon_request_calibration()
849 ctlr->right_stick_cal_y.max, in joycon_request_calibration()
850 ctlr->right_stick_cal_y.min); in joycon_request_calibration()
852 return 0; in joycon_request_calibration()
864 for (i = 0; i < 3; i++) { in joycon_calc_imu_cal_divisors()
865 ctlr->imu_cal_accel_divisor[i] = ctlr->accel_cal.scale[i] - in joycon_calc_imu_cal_divisors()
866 ctlr->accel_cal.offset[i]; in joycon_calc_imu_cal_divisors()
867 ctlr->imu_cal_gyro_divisor[i] = ctlr->gyro_cal.scale[i] - in joycon_calc_imu_cal_divisors()
868 ctlr->gyro_cal.offset[i]; in joycon_calc_imu_cal_divisors()
872 static const s16 DFLT_ACCEL_OFFSET /*= 0*/;
874 static const s16 DFLT_GYRO_OFFSET /*= 0*/;
886 hid_info(ctlr->hdev, "using user cal for IMU\n"); in joycon_request_imu_calibration()
888 hid_info(ctlr->hdev, "using factory cal for IMU\n"); in joycon_request_imu_calibration()
892 hid_dbg(ctlr->hdev, "requesting IMU cal data\n"); in joycon_request_imu_calibration()
896 hid_warn(ctlr->hdev, in joycon_request_imu_calibration()
900 for (i = 0; i < 3; i++) { in joycon_request_imu_calibration()
901 ctlr->accel_cal.offset[i] = DFLT_ACCEL_OFFSET; in joycon_request_imu_calibration()
902 ctlr->accel_cal.scale[i] = DFLT_ACCEL_SCALE; in joycon_request_imu_calibration()
903 ctlr->gyro_cal.offset[i] = DFLT_GYRO_OFFSET; in joycon_request_imu_calibration()
904 ctlr->gyro_cal.scale[i] = DFLT_GYRO_SCALE; in joycon_request_imu_calibration()
911 for (i = 0; i < 3; i++) { in joycon_request_imu_calibration()
914 ctlr->accel_cal.offset[i] = get_unaligned_le16(raw_cal + j); in joycon_request_imu_calibration()
915 ctlr->accel_cal.scale[i] = get_unaligned_le16(raw_cal + j + 6); in joycon_request_imu_calibration()
916 ctlr->gyro_cal.offset[i] = get_unaligned_le16(raw_cal + j + 12); in joycon_request_imu_calibration()
917 ctlr->gyro_cal.scale[i] = get_unaligned_le16(raw_cal + j + 18); in joycon_request_imu_calibration()
922 hid_dbg(ctlr->hdev, "IMU calibration:\n" in joycon_request_imu_calibration()
923 "a_o[0]=%d a_o[1]=%d a_o[2]=%d\n" in joycon_request_imu_calibration()
924 "a_s[0]=%d a_s[1]=%d a_s[2]=%d\n" in joycon_request_imu_calibration()
925 "g_o[0]=%d g_o[1]=%d g_o[2]=%d\n" in joycon_request_imu_calibration()
926 "g_s[0]=%d g_s[1]=%d g_s[2]=%d\n", in joycon_request_imu_calibration()
927 ctlr->accel_cal.offset[0], in joycon_request_imu_calibration()
928 ctlr->accel_cal.offset[1], in joycon_request_imu_calibration()
929 ctlr->accel_cal.offset[2], in joycon_request_imu_calibration()
930 ctlr->accel_cal.scale[0], in joycon_request_imu_calibration()
931 ctlr->accel_cal.scale[1], in joycon_request_imu_calibration()
932 ctlr->accel_cal.scale[2], in joycon_request_imu_calibration()
933 ctlr->gyro_cal.offset[0], in joycon_request_imu_calibration()
934 ctlr->gyro_cal.offset[1], in joycon_request_imu_calibration()
935 ctlr->gyro_cal.offset[2], in joycon_request_imu_calibration()
936 ctlr->gyro_cal.scale[0], in joycon_request_imu_calibration()
937 ctlr->gyro_cal.scale[1], in joycon_request_imu_calibration()
938 ctlr->gyro_cal.scale[2]); in joycon_request_imu_calibration()
940 return 0; in joycon_request_imu_calibration()
946 u8 buffer[sizeof(*req) + 1] = { 0 }; in joycon_set_report_mode()
949 req->subcmd_id = JC_SUBCMD_SET_REPORT_MODE; in joycon_set_report_mode()
950 req->data[0] = 0x30; /* standard, full report mode */ in joycon_set_report_mode()
952 hid_dbg(ctlr->hdev, "setting controller report mode\n"); in joycon_set_report_mode()
959 u8 buffer[sizeof(*req) + 1] = { 0 }; in joycon_enable_rumble()
962 req->subcmd_id = JC_SUBCMD_ENABLE_VIBRATION; in joycon_enable_rumble()
963 req->data[0] = 0x01; /* note: 0x00 would disable */ in joycon_enable_rumble()
965 hid_dbg(ctlr->hdev, "enabling rumble\n"); in joycon_enable_rumble()
972 u8 buffer[sizeof(*req) + 1] = { 0 }; in joycon_enable_imu()
975 req->subcmd_id = JC_SUBCMD_ENABLE_IMU; in joycon_enable_imu()
976 req->data[0] = 0x01; /* note: 0x00 would disable */ in joycon_enable_imu()
978 hid_dbg(ctlr->hdev, "enabling IMU\n"); in joycon_enable_imu()
984 s32 center = cal->center; in joycon_map_stick_val()
985 s32 min = cal->min; in joycon_map_stick_val()
986 s32 max = cal->max; in joycon_map_stick_val()
990 new_val = (val - center) * JC_MAX_STICK_MAG; in joycon_map_stick_val()
991 new_val /= (max - center); in joycon_map_stick_val()
993 new_val = (center - val) * -JC_MAX_STICK_MAG; in joycon_map_stick_val()
994 new_val /= (center - min); in joycon_map_stick_val()
996 new_val = clamp(new_val, (s32)-JC_MAX_STICK_MAG, (s32)JC_MAX_STICK_MAG); in joycon_map_stick_val()
1004 u8 *raw = rep->imu_raw_bytes; in joycon_input_report_parse_imu_data()
1007 for (i = 0; i < 3; i++) { in joycon_input_report_parse_imu_data()
1010 data->accel_x = get_unaligned_le16(raw + 0); in joycon_input_report_parse_imu_data()
1011 data->accel_y = get_unaligned_le16(raw + 2); in joycon_input_report_parse_imu_data()
1012 data->accel_z = get_unaligned_le16(raw + 4); in joycon_input_report_parse_imu_data()
1013 data->gyro_x = get_unaligned_le16(raw + 6); in joycon_input_report_parse_imu_data()
1014 data->gyro_y = get_unaligned_le16(raw + 8); in joycon_input_report_parse_imu_data()
1015 data->gyro_z = get_unaligned_le16(raw + 10); in joycon_input_report_parse_imu_data()
1024 struct joycon_imu_data imu_data[3] = {0}; /* 3 reports per packet */ in joycon_parse_imu_report()
1025 struct input_dev *idev = ctlr->imu_input; in joycon_parse_imu_report()
1027 unsigned int last_msecs = ctlr->imu_last_pkt_ms; in joycon_parse_imu_report()
1037 * incrementing 8-bit counter per input report, but it is not very in joycon_parse_imu_report()
1039 * increments at or if it varies based on packet push rate - more on in joycon_parse_imu_report()
1042 * The reverse engineering work done on the joy-cons and pro controllers in joycon_parse_imu_report()
1044 * - The controller samples the IMU every 1.35ms. It then does some of in joycon_parse_imu_report()
1046 * - Each imu input report contains 3 IMU samples, (usually 5ms apart). in joycon_parse_imu_report()
1047 * - In the standard reporting mode (which this driver uses exclusively) in joycon_parse_imu_report()
1049 * * joy-con (bluetooth): every 15 ms in joycon_parse_imu_report()
1050 * * joy-cons (in charging grip via USB): every 15 ms in joycon_parse_imu_report()
1057 * SSR to 11ms for both the joy-cons and pro controllers). in joycon_parse_imu_report()
1080 if (!ctlr->imu_first_packet_received) { in joycon_parse_imu_report()
1081 ctlr->imu_timestamp_us = 0; in joycon_parse_imu_report()
1082 ctlr->imu_delta_samples_count = 0; in joycon_parse_imu_report()
1083 ctlr->imu_delta_samples_sum = 0; in joycon_parse_imu_report()
1084 ctlr->imu_avg_delta_ms = JC_IMU_DFLT_AVG_DELTA_MS; in joycon_parse_imu_report()
1085 ctlr->imu_first_packet_received = true; in joycon_parse_imu_report()
1087 unsigned int delta = msecs - last_msecs; in joycon_parse_imu_report()
1092 ctlr->imu_delta_samples_sum += delta; in joycon_parse_imu_report()
1093 ctlr->imu_delta_samples_count++; in joycon_parse_imu_report()
1094 if (ctlr->imu_delta_samples_count >= in joycon_parse_imu_report()
1096 ctlr->imu_avg_delta_ms = ctlr->imu_delta_samples_sum / in joycon_parse_imu_report()
1097 ctlr->imu_delta_samples_count; in joycon_parse_imu_report()
1099 if (ctlr->imu_avg_delta_ms == 0) { in joycon_parse_imu_report()
1100 ctlr->imu_avg_delta_ms = 1; in joycon_parse_imu_report()
1101 hid_warn(ctlr->hdev, in joycon_parse_imu_report()
1102 "calculated avg imu delta of 0\n"); in joycon_parse_imu_report()
1104 ctlr->imu_delta_samples_count = 0; in joycon_parse_imu_report()
1105 ctlr->imu_delta_samples_sum = 0; in joycon_parse_imu_report()
1109 hid_dbg(ctlr->hdev, in joycon_parse_imu_report()
1111 msecs, last_msecs, delta, ctlr->imu_avg_delta_ms); in joycon_parse_imu_report()
1114 dropped_threshold = ctlr->imu_avg_delta_ms * 3 / 2; in joycon_parse_imu_report()
1115 dropped_pkts = (delta - min(delta, dropped_threshold)) / in joycon_parse_imu_report()
1116 ctlr->imu_avg_delta_ms; in joycon_parse_imu_report()
1117 ctlr->imu_timestamp_us += 1000 * ctlr->imu_avg_delta_ms; in joycon_parse_imu_report()
1119 hid_warn(ctlr->hdev, in joycon_parse_imu_report()
1122 hid_warn(ctlr->hdev, in joycon_parse_imu_report()
1124 delta, ctlr->imu_avg_delta_ms); in joycon_parse_imu_report()
1127 ctlr->imu_last_pkt_ms = msecs; in joycon_parse_imu_report()
1130 for (i = 0; i < 3; i++) { in joycon_parse_imu_report()
1132 ctlr->imu_timestamp_us); in joycon_parse_imu_report()
1137 * found in the community's reverse-engineering repo (linked at in joycon_parse_imu_report()
1138 * top of driver). For hid-nintendo, we make sure that the final in joycon_parse_imu_report()
1147 * precision-saving scaling factor to prevent large inaccuracies in joycon_parse_imu_report()
1152 value[0] = mult_frac((JC_IMU_PREC_RANGE_SCALE * in joycon_parse_imu_report()
1153 (imu_data[i].gyro_x - in joycon_parse_imu_report()
1154 ctlr->gyro_cal.offset[0])), in joycon_parse_imu_report()
1155 ctlr->gyro_cal.scale[0], in joycon_parse_imu_report()
1156 ctlr->imu_cal_gyro_divisor[0]); in joycon_parse_imu_report()
1158 (imu_data[i].gyro_y - in joycon_parse_imu_report()
1159 ctlr->gyro_cal.offset[1])), in joycon_parse_imu_report()
1160 ctlr->gyro_cal.scale[1], in joycon_parse_imu_report()
1161 ctlr->imu_cal_gyro_divisor[1]); in joycon_parse_imu_report()
1163 (imu_data[i].gyro_z - in joycon_parse_imu_report()
1164 ctlr->gyro_cal.offset[2])), in joycon_parse_imu_report()
1165 ctlr->gyro_cal.scale[2], in joycon_parse_imu_report()
1166 ctlr->imu_cal_gyro_divisor[2]); in joycon_parse_imu_report()
1169 ctlr->accel_cal.scale[0]) / in joycon_parse_imu_report()
1170 ctlr->imu_cal_accel_divisor[0]; in joycon_parse_imu_report()
1172 ctlr->accel_cal.scale[1]) / in joycon_parse_imu_report()
1173 ctlr->imu_cal_accel_divisor[1]; in joycon_parse_imu_report()
1175 ctlr->accel_cal.scale[2]) / in joycon_parse_imu_report()
1176 ctlr->imu_cal_accel_divisor[2]; in joycon_parse_imu_report()
1178 hid_dbg(ctlr->hdev, "raw_gyro: g_x=%d g_y=%d g_z=%d\n", in joycon_parse_imu_report()
1181 hid_dbg(ctlr->hdev, "raw_accel: a_x=%d a_y=%d a_z=%d\n", in joycon_parse_imu_report()
1186 * The right joy-con has 2 axes negated, Y and Z. This is due to in joycon_parse_imu_report()
1188 * axes' values in order to be consistent with the left joy-con in joycon_parse_imu_report()
1193 * The axes follow the right-hand rule. in joycon_parse_imu_report()
1202 value[j] *= -1; in joycon_parse_imu_report()
1206 input_report_abs(idev, ABS_RX, value[0]); in joycon_parse_imu_report()
1214 ctlr->imu_timestamp_us += ctlr->imu_avg_delta_ms * 1000 / 3; in joycon_parse_imu_report()
1221 struct input_dev *dev = ctlr->input; in joycon_parse_report()
1227 spin_lock_irqsave(&ctlr->lock, flags); in joycon_parse_report()
1228 if (IS_ENABLED(CONFIG_NINTENDO_FF) && rep->vibrator_report && in joycon_parse_report()
1229 ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED && in joycon_parse_report()
1230 (msecs - ctlr->rumble_msecs) >= JC_RUMBLE_PERIOD_MS && in joycon_parse_report()
1231 (ctlr->rumble_queue_head != ctlr->rumble_queue_tail || in joycon_parse_report()
1232 ctlr->rumble_zero_countdown > 0)) { in joycon_parse_report()
1234 * When this value reaches 0, we know we've sent multiple in joycon_parse_report()
1239 if (ctlr->rumble_zero_countdown > 0) in joycon_parse_report()
1240 ctlr->rumble_zero_countdown--; in joycon_parse_report()
1241 queue_work(ctlr->rumble_queue, &ctlr->rumble_worker); in joycon_parse_report()
1245 tmp = rep->bat_con; in joycon_parse_report()
1246 ctlr->host_powered = tmp & BIT(0); in joycon_parse_report()
1247 ctlr->battery_charging = tmp & BIT(4); in joycon_parse_report()
1250 case 0: /* empty */ in joycon_parse_report()
1251 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; in joycon_parse_report()
1254 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_LOW; in joycon_parse_report()
1257 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; in joycon_parse_report()
1260 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_HIGH; in joycon_parse_report()
1263 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_FULL; in joycon_parse_report()
1266 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; in joycon_parse_report()
1267 hid_warn(ctlr->hdev, "Invalid battery status\n"); in joycon_parse_report()
1270 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_parse_report()
1273 btns = hid_field_extract(ctlr->hdev, rep->button_status, 0, 24); in joycon_parse_report()
1282 raw_x = hid_field_extract(ctlr->hdev, rep->left_stick, 0, 12); in joycon_parse_report()
1283 raw_y = hid_field_extract(ctlr->hdev, in joycon_parse_report()
1284 rep->left_stick + 1, 4, 12); in joycon_parse_report()
1286 x = joycon_map_stick_val(&ctlr->left_stick_cal_x, raw_x); in joycon_parse_report()
1287 y = -joycon_map_stick_val(&ctlr->left_stick_cal_y, raw_y); in joycon_parse_report()
1300 /* Report the S buttons as the non-existent triggers */ in joycon_parse_report()
1304 /* Report d-pad as digital buttons for the joy-cons */ in joycon_parse_report()
1313 int hatx = 0; in joycon_parse_report()
1314 int haty = 0; in joycon_parse_report()
1316 /* d-pad x */ in joycon_parse_report()
1318 hatx = -1; in joycon_parse_report()
1323 /* d-pad y */ in joycon_parse_report()
1325 haty = -1; in joycon_parse_report()
1338 raw_x = hid_field_extract(ctlr->hdev, rep->right_stick, 0, 12); in joycon_parse_report()
1339 raw_y = hid_field_extract(ctlr->hdev, in joycon_parse_report()
1340 rep->right_stick + 1, 4, 12); in joycon_parse_report()
1342 x = joycon_map_stick_val(&ctlr->right_stick_cal_x, raw_x); in joycon_parse_report()
1343 y = -joycon_map_stick_val(&ctlr->right_stick_cal_y, raw_y); in joycon_parse_report()
1352 /* Report the S buttons as the non-existent triggers */ in joycon_parse_report()
1372 if (unlikely(mutex_is_locked(&ctlr->output_mutex))) { in joycon_parse_report()
1373 spin_lock_irqsave(&ctlr->lock, flags); in joycon_parse_report()
1374 ctlr->received_input_report = true; in joycon_parse_report()
1375 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_parse_report()
1376 wake_up(&ctlr->wait); in joycon_parse_report()
1380 if (rep->id == JC_INPUT_IMU_DATA) in joycon_parse_report()
1388 struct joycon_rumble_output rumble_output = { 0 }; in joycon_send_rumble_data()
1390 spin_lock_irqsave(&ctlr->lock, flags); in joycon_send_rumble_data()
1395 if (ctlr->ctlr_state == JOYCON_CTLR_STATE_REMOVED) { in joycon_send_rumble_data()
1396 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_send_rumble_data()
1397 return -ENODEV; in joycon_send_rumble_data()
1400 ctlr->rumble_data[ctlr->rumble_queue_tail], in joycon_send_rumble_data()
1402 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_send_rumble_data()
1405 rumble_output.packet_num = ctlr->subcmd_num; in joycon_send_rumble_data()
1406 if (++ctlr->subcmd_num > 0xF) in joycon_send_rumble_data()
1407 ctlr->subcmd_num = 0; in joycon_send_rumble_data()
1411 ret = __joycon_hid_send(ctlr->hdev, (u8 *)&rumble_output, in joycon_send_rumble_data()
1425 mutex_lock(&ctlr->output_mutex); in joycon_rumble_worker()
1427 mutex_unlock(&ctlr->output_mutex); in joycon_rumble_worker()
1429 /* -ENODEV means the controller was just unplugged */ in joycon_rumble_worker()
1430 spin_lock_irqsave(&ctlr->lock, flags); in joycon_rumble_worker()
1431 if (ret < 0 && ret != -ENODEV && in joycon_rumble_worker()
1432 ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED) in joycon_rumble_worker()
1433 hid_warn(ctlr->hdev, "Failed to set rumble; e=%d", ret); in joycon_rumble_worker()
1435 ctlr->rumble_msecs = jiffies_to_msecs(jiffies); in joycon_rumble_worker()
1436 if (ctlr->rumble_queue_tail != ctlr->rumble_queue_head) { in joycon_rumble_worker()
1437 if (++ctlr->rumble_queue_tail >= JC_RUMBLE_QUEUE_SIZE) in joycon_rumble_worker()
1438 ctlr->rumble_queue_tail = 0; in joycon_rumble_worker()
1442 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_rumble_worker()
1451 int i = 0; in joycon_find_rumble_freq()
1453 if (freq > data[0].freq) { in joycon_find_rumble_freq()
1454 for (i = 1; i < length - 1; i++) { in joycon_find_rumble_freq()
1455 if (freq > data[i - 1].freq && freq <= data[i].freq) in joycon_find_rumble_freq()
1467 int i = 0; in joycon_find_rumble_amp()
1469 if (amp > data[0].amp) { in joycon_find_rumble_amp()
1470 for (i = 1; i < length - 1; i++) { in joycon_find_rumble_amp()
1471 if (amp > data[i - 1].amp && amp <= data[i].amp) in joycon_find_rumble_amp()
1489 data[0] = (freq_data_high.high >> 8) & 0xFF; in joycon_encode_rumble()
1490 data[1] = (freq_data_high.high & 0xFF) + amp_data.high; in joycon_encode_rumble()
1491 data[2] = freq_data_low.low + ((amp_data.low >> 8) & 0xFF); in joycon_encode_rumble()
1492 data[3] = amp_data.low & 0xFF; in joycon_encode_rumble()
1504 spin_lock_irqsave(&ctlr->lock, flags); in joycon_clamp_rumble_freqs()
1505 ctlr->rumble_ll_freq = clamp(ctlr->rumble_ll_freq, in joycon_clamp_rumble_freqs()
1508 ctlr->rumble_lh_freq = clamp(ctlr->rumble_lh_freq, in joycon_clamp_rumble_freqs()
1511 ctlr->rumble_rl_freq = clamp(ctlr->rumble_rl_freq, in joycon_clamp_rumble_freqs()
1514 ctlr->rumble_rh_freq = clamp(ctlr->rumble_rh_freq, in joycon_clamp_rumble_freqs()
1517 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_clamp_rumble_freqs()
1531 spin_lock_irqsave(&ctlr->lock, flags); in joycon_set_rumble()
1532 freq_r_low = ctlr->rumble_rl_freq; in joycon_set_rumble()
1533 freq_r_high = ctlr->rumble_rh_freq; in joycon_set_rumble()
1534 freq_l_low = ctlr->rumble_ll_freq; in joycon_set_rumble()
1535 freq_l_high = ctlr->rumble_lh_freq; in joycon_set_rumble()
1537 if (amp_l != 0 || amp_r != 0) in joycon_set_rumble()
1538 ctlr->rumble_zero_countdown = JC_RUMBLE_ZERO_AMP_PKT_CNT; in joycon_set_rumble()
1539 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_set_rumble()
1541 /* right joy-con */ in joycon_set_rumble()
1545 /* left joy-con */ in joycon_set_rumble()
1549 spin_lock_irqsave(&ctlr->lock, flags); in joycon_set_rumble()
1550 if (++ctlr->rumble_queue_head >= JC_RUMBLE_QUEUE_SIZE) in joycon_set_rumble()
1551 ctlr->rumble_queue_head = 0; in joycon_set_rumble()
1552 memcpy(ctlr->rumble_data[ctlr->rumble_queue_head], data, in joycon_set_rumble()
1556 if (schedule_now && ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED) in joycon_set_rumble()
1557 queue_work(ctlr->rumble_queue, &ctlr->rumble_worker); in joycon_set_rumble()
1559 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_set_rumble()
1561 return 0; in joycon_set_rumble()
1569 if (effect->type != FF_RUMBLE) in joycon_play_effect()
1570 return 0; in joycon_play_effect()
1573 effect->u.rumble.weak_magnitude, in joycon_play_effect()
1574 effect->u.rumble.strong_magnitude, in joycon_play_effect()
1582 0 /* 0 signals end of array */
1589 0 /* 0 signals end of array */
1592 /* We report joy-con d-pad inputs as buttons and pro controller as a hat. */
1595 0 /* 0 signals end of array */
1606 hdev = ctlr->hdev; in joycon_input_create()
1608 switch (hdev->product) { in joycon_input_create()
1615 name = "Nintendo Switch Left Joy-Con (Grip)"; in joycon_input_create()
1616 imu_name = "Nintendo Switch Left Joy-Con IMU (Grip)"; in joycon_input_create()
1618 name = "Nintendo Switch Right Joy-Con (Grip)"; in joycon_input_create()
1619 imu_name = "Nintendo Switch Right Joy-Con IMU (Grip)"; in joycon_input_create()
1623 name = "Nintendo Switch Left Joy-Con"; in joycon_input_create()
1624 imu_name = "Nintendo Switch Left Joy-Con IMU"; in joycon_input_create()
1627 name = "Nintendo Switch Right Joy-Con"; in joycon_input_create()
1628 imu_name = "Nintendo Switch Right Joy-Con IMU"; in joycon_input_create()
1632 return -EINVAL; in joycon_input_create()
1635 ctlr->input = devm_input_allocate_device(&hdev->dev); in joycon_input_create()
1636 if (!ctlr->input) in joycon_input_create()
1637 return -ENOMEM; in joycon_input_create()
1638 ctlr->input->id.bustype = hdev->bus; in joycon_input_create()
1639 ctlr->input->id.vendor = hdev->vendor; in joycon_input_create()
1640 ctlr->input->id.product = hdev->product; in joycon_input_create()
1641 ctlr->input->id.version = hdev->version; in joycon_input_create()
1642 ctlr->input->uniq = ctlr->mac_addr_str; in joycon_input_create()
1643 ctlr->input->name = name; in joycon_input_create()
1644 ctlr->input->phys = hdev->phys; in joycon_input_create()
1645 input_set_drvdata(ctlr->input, ctlr); in joycon_input_create()
1649 input_set_abs_params(ctlr->input, ABS_X, in joycon_input_create()
1650 -JC_MAX_STICK_MAG, JC_MAX_STICK_MAG, in joycon_input_create()
1652 input_set_abs_params(ctlr->input, ABS_Y, in joycon_input_create()
1653 -JC_MAX_STICK_MAG, JC_MAX_STICK_MAG, in joycon_input_create()
1656 for (i = 0; joycon_button_inputs_l[i] > 0; i++) in joycon_input_create()
1657 input_set_capability(ctlr->input, EV_KEY, in joycon_input_create()
1660 /* configure d-pad differently for joy-con vs pro controller */ in joycon_input_create()
1661 if (hdev->product != USB_DEVICE_ID_NINTENDO_PROCON) { in joycon_input_create()
1662 for (i = 0; joycon_dpad_inputs_jc[i] > 0; i++) in joycon_input_create()
1663 input_set_capability(ctlr->input, EV_KEY, in joycon_input_create()
1666 input_set_abs_params(ctlr->input, ABS_HAT0X, in joycon_input_create()
1667 -JC_MAX_DPAD_MAG, JC_MAX_DPAD_MAG, in joycon_input_create()
1669 input_set_abs_params(ctlr->input, ABS_HAT0Y, in joycon_input_create()
1670 -JC_MAX_DPAD_MAG, JC_MAX_DPAD_MAG, in joycon_input_create()
1675 input_set_abs_params(ctlr->input, ABS_RX, in joycon_input_create()
1676 -JC_MAX_STICK_MAG, JC_MAX_STICK_MAG, in joycon_input_create()
1678 input_set_abs_params(ctlr->input, ABS_RY, in joycon_input_create()
1679 -JC_MAX_STICK_MAG, JC_MAX_STICK_MAG, in joycon_input_create()
1682 for (i = 0; joycon_button_inputs_r[i] > 0; i++) in joycon_input_create()
1683 input_set_capability(ctlr->input, EV_KEY, in joycon_input_create()
1687 /* Let's report joy-con S triggers separately */ in joycon_input_create()
1688 if (hdev->product == USB_DEVICE_ID_NINTENDO_JOYCONL) { in joycon_input_create()
1689 input_set_capability(ctlr->input, EV_KEY, BTN_TR); in joycon_input_create()
1690 input_set_capability(ctlr->input, EV_KEY, BTN_TR2); in joycon_input_create()
1691 } else if (hdev->product == USB_DEVICE_ID_NINTENDO_JOYCONR) { in joycon_input_create()
1692 input_set_capability(ctlr->input, EV_KEY, BTN_TL); in joycon_input_create()
1693 input_set_capability(ctlr->input, EV_KEY, BTN_TL2); in joycon_input_create()
1698 input_set_capability(ctlr->input, EV_FF, FF_RUMBLE); in joycon_input_create()
1699 input_ff_create_memless(ctlr->input, NULL, joycon_play_effect); in joycon_input_create()
1700 ctlr->rumble_ll_freq = JC_RUMBLE_DFLT_LOW_FREQ; in joycon_input_create()
1701 ctlr->rumble_lh_freq = JC_RUMBLE_DFLT_HIGH_FREQ; in joycon_input_create()
1702 ctlr->rumble_rl_freq = JC_RUMBLE_DFLT_LOW_FREQ; in joycon_input_create()
1703 ctlr->rumble_rh_freq = JC_RUMBLE_DFLT_HIGH_FREQ; in joycon_input_create()
1705 joycon_set_rumble(ctlr, 0, 0, false); in joycon_input_create()
1706 ctlr->rumble_msecs = jiffies_to_msecs(jiffies); in joycon_input_create()
1709 ret = input_register_device(ctlr->input); in joycon_input_create()
1714 ctlr->imu_input = devm_input_allocate_device(&hdev->dev); in joycon_input_create()
1715 if (!ctlr->imu_input) in joycon_input_create()
1716 return -ENOMEM; in joycon_input_create()
1718 ctlr->imu_input->id.bustype = hdev->bus; in joycon_input_create()
1719 ctlr->imu_input->id.vendor = hdev->vendor; in joycon_input_create()
1720 ctlr->imu_input->id.product = hdev->product; in joycon_input_create()
1721 ctlr->imu_input->id.version = hdev->version; in joycon_input_create()
1722 ctlr->imu_input->uniq = ctlr->mac_addr_str; in joycon_input_create()
1723 ctlr->imu_input->name = imu_name; in joycon_input_create()
1724 ctlr->imu_input->phys = hdev->phys; in joycon_input_create()
1725 input_set_drvdata(ctlr->imu_input, ctlr); in joycon_input_create()
1728 input_set_abs_params(ctlr->imu_input, ABS_X, in joycon_input_create()
1729 -JC_IMU_MAX_ACCEL_MAG, JC_IMU_MAX_ACCEL_MAG, in joycon_input_create()
1731 input_set_abs_params(ctlr->imu_input, ABS_Y, in joycon_input_create()
1732 -JC_IMU_MAX_ACCEL_MAG, JC_IMU_MAX_ACCEL_MAG, in joycon_input_create()
1734 input_set_abs_params(ctlr->imu_input, ABS_Z, in joycon_input_create()
1735 -JC_IMU_MAX_ACCEL_MAG, JC_IMU_MAX_ACCEL_MAG, in joycon_input_create()
1737 input_abs_set_res(ctlr->imu_input, ABS_X, JC_IMU_ACCEL_RES_PER_G); in joycon_input_create()
1738 input_abs_set_res(ctlr->imu_input, ABS_Y, JC_IMU_ACCEL_RES_PER_G); in joycon_input_create()
1739 input_abs_set_res(ctlr->imu_input, ABS_Z, JC_IMU_ACCEL_RES_PER_G); in joycon_input_create()
1741 input_set_abs_params(ctlr->imu_input, ABS_RX, in joycon_input_create()
1742 -JC_IMU_MAX_GYRO_MAG, JC_IMU_MAX_GYRO_MAG, in joycon_input_create()
1744 input_set_abs_params(ctlr->imu_input, ABS_RY, in joycon_input_create()
1745 -JC_IMU_MAX_GYRO_MAG, JC_IMU_MAX_GYRO_MAG, in joycon_input_create()
1747 input_set_abs_params(ctlr->imu_input, ABS_RZ, in joycon_input_create()
1748 -JC_IMU_MAX_GYRO_MAG, JC_IMU_MAX_GYRO_MAG, in joycon_input_create()
1751 input_abs_set_res(ctlr->imu_input, ABS_RX, JC_IMU_GYRO_RES_PER_DPS); in joycon_input_create()
1752 input_abs_set_res(ctlr->imu_input, ABS_RY, JC_IMU_GYRO_RES_PER_DPS); in joycon_input_create()
1753 input_abs_set_res(ctlr->imu_input, ABS_RZ, JC_IMU_GYRO_RES_PER_DPS); in joycon_input_create()
1755 __set_bit(EV_MSC, ctlr->imu_input->evbit); in joycon_input_create()
1756 __set_bit(MSC_TIMESTAMP, ctlr->imu_input->mscbit); in joycon_input_create()
1757 __set_bit(INPUT_PROP_ACCELEROMETER, ctlr->imu_input->propbit); in joycon_input_create()
1759 ret = input_register_device(ctlr->imu_input); in joycon_input_create()
1763 return 0; in joycon_input_create()
1769 struct device *dev = led->dev->parent; in joycon_player_led_brightness_set()
1772 int val = 0; in joycon_player_led_brightness_set()
1780 return -ENODEV; in joycon_player_led_brightness_set()
1784 for (num = 0; num < JC_NUM_LEDS; num++) { in joycon_player_led_brightness_set()
1785 if (&ctlr->leds[num] == led) in joycon_player_led_brightness_set()
1789 return -EINVAL; in joycon_player_led_brightness_set()
1791 mutex_lock(&ctlr->output_mutex); in joycon_player_led_brightness_set()
1792 for (i = 0; i < JC_NUM_LEDS; i++) { in joycon_player_led_brightness_set()
1796 val |= ctlr->leds[i].brightness << i; in joycon_player_led_brightness_set()
1798 ret = joycon_set_player_leds(ctlr, 0, val); in joycon_player_led_brightness_set()
1799 mutex_unlock(&ctlr->output_mutex); in joycon_player_led_brightness_set()
1807 struct device *dev = led->dev->parent; in joycon_home_led_brightness_set()
1811 u8 buffer[sizeof(*req) + 5] = { 0 }; in joycon_home_led_brightness_set()
1818 return -ENODEV; in joycon_home_led_brightness_set()
1822 req->subcmd_id = JC_SUBCMD_SET_HOME_LIGHT; in joycon_home_led_brightness_set()
1823 data = req->data; in joycon_home_led_brightness_set()
1824 data[0] = 0x01; in joycon_home_led_brightness_set()
1827 data[3] = 0x11; in joycon_home_led_brightness_set()
1828 data[4] = 0x11; in joycon_home_led_brightness_set()
1831 mutex_lock(&ctlr->output_mutex); in joycon_home_led_brightness_set()
1833 mutex_unlock(&ctlr->output_mutex); in joycon_home_led_brightness_set()
1841 struct hid_device *hdev = ctlr->hdev; in joycon_leds_create()
1842 struct device *dev = &hdev->dev; in joycon_leds_create()
1846 int ret = 0; in joycon_leds_create()
1852 mutex_lock(&ctlr->output_mutex); in joycon_leds_create()
1853 ret = joycon_set_player_leds(ctlr, 0, 0xF >> (4 - input_num)); in joycon_leds_create()
1855 hid_warn(ctlr->hdev, "Failed to set leds; ret=%d\n", ret); in joycon_leds_create()
1856 mutex_unlock(&ctlr->output_mutex); in joycon_leds_create()
1859 for (i = 0; i < JC_NUM_LEDS; i++) { in joycon_leds_create()
1866 return -ENOMEM; in joycon_leds_create()
1869 led = &ctlr->leds[i]; in joycon_leds_create()
1870 led->name = name; in joycon_leds_create()
1871 led->brightness = ((i + 1) <= input_num) ? 1 : 0; in joycon_leds_create()
1872 led->max_brightness = 1; in joycon_leds_create()
1873 led->brightness_set_blocking = in joycon_leds_create()
1875 led->flags = LED_CORE_SUSPENDRESUME | LED_HW_PLUGGABLE; in joycon_leds_create()
1877 ret = devm_led_classdev_register(&hdev->dev, led); in joycon_leds_create()
1879 hid_err(hdev, "Failed registering %s LED\n", led->name); in joycon_leds_create()
1896 return -ENOMEM; in joycon_leds_create()
1898 led = &ctlr->home_led; in joycon_leds_create()
1899 led->name = name; in joycon_leds_create()
1900 led->brightness = 0; in joycon_leds_create()
1901 led->max_brightness = 0xF; in joycon_leds_create()
1902 led->brightness_set_blocking = joycon_home_led_brightness_set; in joycon_leds_create()
1903 led->flags = LED_CORE_SUSPENDRESUME | LED_HW_PLUGGABLE; in joycon_leds_create()
1904 ret = devm_led_classdev_register(&hdev->dev, led); in joycon_leds_create()
1909 /* Set the home LED to 0 as default state */ in joycon_leds_create()
1910 ret = joycon_home_led_brightness_set(led, 0); in joycon_leds_create()
1913 devm_led_classdev_unregister(&hdev->dev, led); in joycon_leds_create()
1917 return 0; in joycon_leds_create()
1926 int ret = 0; in joycon_battery_get_property()
1931 spin_lock_irqsave(&ctlr->lock, flags); in joycon_battery_get_property()
1932 capacity = ctlr->battery_capacity; in joycon_battery_get_property()
1933 charging = ctlr->battery_charging; in joycon_battery_get_property()
1934 powered = ctlr->host_powered; in joycon_battery_get_property()
1935 spin_unlock_irqrestore(&ctlr->lock, flags); in joycon_battery_get_property()
1939 val->intval = 1; in joycon_battery_get_property()
1942 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in joycon_battery_get_property()
1945 val->intval = capacity; in joycon_battery_get_property()
1949 val->intval = POWER_SUPPLY_STATUS_CHARGING; in joycon_battery_get_property()
1952 val->intval = POWER_SUPPLY_STATUS_FULL; in joycon_battery_get_property()
1954 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in joycon_battery_get_property()
1957 ret = -EINVAL; in joycon_battery_get_property()
1972 struct hid_device *hdev = ctlr->hdev; in joycon_power_supply_create()
1975 int ret = 0; in joycon_power_supply_create()
1978 ctlr->battery_capacity = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; in joycon_power_supply_create()
1981 ctlr->battery_desc.properties = joycon_battery_props; in joycon_power_supply_create()
1982 ctlr->battery_desc.num_properties = in joycon_power_supply_create()
1984 ctlr->battery_desc.get_property = joycon_battery_get_property; in joycon_power_supply_create()
1985 ctlr->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in joycon_power_supply_create()
1986 ctlr->battery_desc.use_for_apm = 0; in joycon_power_supply_create()
1987 ctlr->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in joycon_power_supply_create()
1989 dev_name(&hdev->dev)); in joycon_power_supply_create()
1990 if (!ctlr->battery_desc.name) in joycon_power_supply_create()
1991 return -ENOMEM; in joycon_power_supply_create()
1993 ctlr->battery = devm_power_supply_register(&hdev->dev, in joycon_power_supply_create()
1994 &ctlr->battery_desc, in joycon_power_supply_create()
1996 if (IS_ERR(ctlr->battery)) { in joycon_power_supply_create()
1997 ret = PTR_ERR(ctlr->battery); in joycon_power_supply_create()
2002 return power_supply_powers(ctlr->battery, &hdev->dev); in joycon_power_supply_create()
2010 struct joycon_subcmd_request req = { 0 }; in joycon_read_info()
2014 ret = joycon_send_subcmd(ctlr, &req, 0, HZ); in joycon_read_info()
2016 hid_err(ctlr->hdev, "Failed to get joycon info; ret=%d\n", ret); in joycon_read_info()
2020 report = (struct joycon_input_report *)ctlr->input_buf; in joycon_read_info()
2022 for (i = 4, j = 0; j < 6; i++, j++) in joycon_read_info()
2023 ctlr->mac_addr[j] = report->subcmd_reply.data[i]; in joycon_read_info()
2025 ctlr->mac_addr_str = devm_kasprintf(&ctlr->hdev->dev, GFP_KERNEL, in joycon_read_info()
2027 ctlr->mac_addr[0], in joycon_read_info()
2028 ctlr->mac_addr[1], in joycon_read_info()
2029 ctlr->mac_addr[2], in joycon_read_info()
2030 ctlr->mac_addr[3], in joycon_read_info()
2031 ctlr->mac_addr[4], in joycon_read_info()
2032 ctlr->mac_addr[5]); in joycon_read_info()
2033 if (!ctlr->mac_addr_str) in joycon_read_info()
2034 return -ENOMEM; in joycon_read_info()
2035 hid_info(ctlr->hdev, "controller MAC = %s\n", ctlr->mac_addr_str); in joycon_read_info()
2038 ctlr->ctlr_type = report->subcmd_reply.data[2]; in joycon_read_info()
2040 return 0; in joycon_read_info()
2047 if (data[0] == JC_INPUT_SUBCMD_REPLY || data[0] == JC_INPUT_IMU_DATA || in joycon_ctlr_read_handler()
2048 data[0] == JC_INPUT_MCU_DATA) { in joycon_ctlr_read_handler()
2054 return 0; in joycon_ctlr_read_handler()
2060 int ret = 0; in joycon_ctlr_handle_event()
2064 if (unlikely(mutex_is_locked(&ctlr->output_mutex)) && in joycon_ctlr_handle_event()
2065 ctlr->msg_type != JOYCON_MSG_TYPE_NONE) { in joycon_ctlr_handle_event()
2066 switch (ctlr->msg_type) { in joycon_ctlr_handle_event()
2070 if (data[0] == JC_INPUT_USB_RESPONSE && in joycon_ctlr_handle_event()
2071 data[1] == ctlr->usb_ack_match) in joycon_ctlr_handle_event()
2076 data[0] != JC_INPUT_SUBCMD_REPLY) in joycon_ctlr_handle_event()
2079 if (report->subcmd_reply.id == ctlr->subcmd_ack_match) in joycon_ctlr_handle_event()
2087 memcpy(ctlr->input_buf, data, in joycon_ctlr_handle_event()
2089 ctlr->msg_type = JOYCON_MSG_TYPE_NONE; in joycon_ctlr_handle_event()
2090 ctlr->received_resp = true; in joycon_ctlr_handle_event()
2091 wake_up(&ctlr->wait); in joycon_ctlr_handle_event()
2098 if (ctlr->ctlr_state == JOYCON_CTLR_STATE_READ) in joycon_ctlr_handle_event()
2110 return -EINVAL; in nintendo_hid_event()
2121 hid_dbg(hdev, "probe - start\n"); in nintendo_hid_probe()
2123 ctlr = devm_kzalloc(&hdev->dev, sizeof(*ctlr), GFP_KERNEL); in nintendo_hid_probe()
2125 ret = -ENOMEM; in nintendo_hid_probe()
2129 ctlr->hdev = hdev; in nintendo_hid_probe()
2130 ctlr->ctlr_state = JOYCON_CTLR_STATE_INIT; in nintendo_hid_probe()
2131 ctlr->rumble_queue_head = JC_RUMBLE_QUEUE_SIZE - 1; in nintendo_hid_probe()
2132 ctlr->rumble_queue_tail = 0; in nintendo_hid_probe()
2134 mutex_init(&ctlr->output_mutex); in nintendo_hid_probe()
2135 init_waitqueue_head(&ctlr->wait); in nintendo_hid_probe()
2136 spin_lock_init(&ctlr->lock); in nintendo_hid_probe()
2137 ctlr->rumble_queue = alloc_workqueue("hid-nintendo-rumble_wq", in nintendo_hid_probe()
2138 WQ_FREEZABLE | WQ_MEM_RECLAIM, 0); in nintendo_hid_probe()
2139 if (!ctlr->rumble_queue) { in nintendo_hid_probe()
2140 ret = -ENOMEM; in nintendo_hid_probe()
2143 INIT_WORK(&ctlr->rumble_worker, joycon_rumble_worker); in nintendo_hid_probe()
2158 hdev->version |= 0x8000; in nintendo_hid_probe()
2175 mutex_lock(&ctlr->output_mutex); in nintendo_hid_probe()
2199 ret = -ETIMEDOUT; in nintendo_hid_probe()
2223 /* Set the reporting mode to 0x30, which is the full report mode */ in nintendo_hid_probe()
2251 mutex_unlock(&ctlr->output_mutex); in nintendo_hid_probe()
2273 ctlr->ctlr_state = JOYCON_CTLR_STATE_READ; in nintendo_hid_probe()
2275 hid_dbg(hdev, "probe - success\n"); in nintendo_hid_probe()
2276 return 0; in nintendo_hid_probe()
2279 mutex_unlock(&ctlr->output_mutex); in nintendo_hid_probe()
2285 destroy_workqueue(ctlr->rumble_queue); in nintendo_hid_probe()
2287 hid_err(hdev, "probe - fail = %d\n", ret); in nintendo_hid_probe()
2299 spin_lock_irqsave(&ctlr->lock, flags); in nintendo_hid_remove()
2300 ctlr->ctlr_state = JOYCON_CTLR_STATE_REMOVED; in nintendo_hid_remove()
2301 spin_unlock_irqrestore(&ctlr->lock, flags); in nintendo_hid_remove()
2303 destroy_workqueue(ctlr->rumble_queue); in nintendo_hid_remove()