hid-steelseries.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * HID driver for Steelseries devices
  4. *
  5. * Copyright (c) 2013 Simon Wood
  6. * Copyright (c) 2023 Bastien Nocera
  7. */
  8. /*
  9. */
  10. #include <linux/device.h>
  11. #include <linux/hid.h>
  12. #include <linux/module.h>
  13. #include <linux/usb.h>
  14. #include <linux/leds.h>
  15. #include "hid-ids.h"
  16. #define STEELSERIES_SRWS1 BIT(0)
  17. #define STEELSERIES_ARCTIS_1 BIT(1)
  18. struct steelseries_device {
  19. struct hid_device *hdev;
  20. unsigned long quirks;
  21. struct delayed_work battery_work;
  22. spinlock_t lock;
  23. bool removed;
  24. struct power_supply_desc battery_desc;
  25. struct power_supply *battery;
  26. uint8_t battery_capacity;
  27. bool headset_connected;
  28. };
  29. #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
  30. (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
  31. #define SRWS1_NUMBER_LEDS 15
  32. struct steelseries_srws1_data {
  33. __u16 led_state;
  34. /* the last element is used for setting all leds simultaneously */
  35. struct led_classdev *led[SRWS1_NUMBER_LEDS + 1];
  36. };
  37. #endif
  38. /* Fixed report descriptor for Steelseries SRW-S1 wheel controller
  39. *
  40. * The original descriptor hides the sensitivity and assists dials
  41. * a custom vendor usage page. This inserts a patch to make them
  42. * appear in the 'Generic Desktop' usage.
  43. */
  44. static const __u8 steelseries_srws1_rdesc_fixed[] = {
  45. 0x05, 0x01, /* Usage Page (Desktop) */
  46. 0x09, 0x08, /* Usage (MultiAxis), Changed */
  47. 0xA1, 0x01, /* Collection (Application), */
  48. 0xA1, 0x02, /* Collection (Logical), */
  49. 0x95, 0x01, /* Report Count (1), */
  50. 0x05, 0x01, /* Changed Usage Page (Desktop), */
  51. 0x09, 0x30, /* Changed Usage (X), */
  52. 0x16, 0xF8, 0xF8, /* Logical Minimum (-1800), */
  53. 0x26, 0x08, 0x07, /* Logical Maximum (1800), */
  54. 0x65, 0x14, /* Unit (Degrees), */
  55. 0x55, 0x0F, /* Unit Exponent (15), */
  56. 0x75, 0x10, /* Report Size (16), */
  57. 0x81, 0x02, /* Input (Variable), */
  58. 0x09, 0x31, /* Changed Usage (Y), */
  59. 0x15, 0x00, /* Logical Minimum (0), */
  60. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  61. 0x75, 0x0C, /* Report Size (12), */
  62. 0x81, 0x02, /* Input (Variable), */
  63. 0x09, 0x32, /* Changed Usage (Z), */
  64. 0x15, 0x00, /* Logical Minimum (0), */
  65. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  66. 0x75, 0x0C, /* Report Size (12), */
  67. 0x81, 0x02, /* Input (Variable), */
  68. 0x05, 0x01, /* Usage Page (Desktop), */
  69. 0x09, 0x39, /* Usage (Hat Switch), */
  70. 0x25, 0x07, /* Logical Maximum (7), */
  71. 0x35, 0x00, /* Physical Minimum (0), */
  72. 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
  73. 0x65, 0x14, /* Unit (Degrees), */
  74. 0x75, 0x04, /* Report Size (4), */
  75. 0x95, 0x01, /* Report Count (1), */
  76. 0x81, 0x02, /* Input (Variable), */
  77. 0x25, 0x01, /* Logical Maximum (1), */
  78. 0x45, 0x01, /* Physical Maximum (1), */
  79. 0x65, 0x00, /* Unit, */
  80. 0x75, 0x01, /* Report Size (1), */
  81. 0x95, 0x03, /* Report Count (3), */
  82. 0x81, 0x01, /* Input (Constant), */
  83. 0x05, 0x09, /* Usage Page (Button), */
  84. 0x19, 0x01, /* Usage Minimum (01h), */
  85. 0x29, 0x11, /* Usage Maximum (11h), */
  86. 0x95, 0x11, /* Report Count (17), */
  87. 0x81, 0x02, /* Input (Variable), */
  88. /* ---- Dial patch starts here ---- */
  89. 0x05, 0x01, /* Usage Page (Desktop), */
  90. 0x09, 0x33, /* Usage (RX), */
  91. 0x75, 0x04, /* Report Size (4), */
  92. 0x95, 0x02, /* Report Count (2), */
  93. 0x15, 0x00, /* Logical Minimum (0), */
  94. 0x25, 0x0b, /* Logical Maximum (b), */
  95. 0x81, 0x02, /* Input (Variable), */
  96. 0x09, 0x35, /* Usage (RZ), */
  97. 0x75, 0x04, /* Report Size (4), */
  98. 0x95, 0x01, /* Report Count (1), */
  99. 0x25, 0x03, /* Logical Maximum (3), */
  100. 0x81, 0x02, /* Input (Variable), */
  101. /* ---- Dial patch ends here ---- */
  102. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  103. 0x09, 0x01, /* Usage (01h), */
  104. 0x75, 0x04, /* Changed Report Size (4), */
  105. 0x95, 0x0D, /* Changed Report Count (13), */
  106. 0x81, 0x02, /* Input (Variable), */
  107. 0xC0, /* End Collection, */
  108. 0xA1, 0x02, /* Collection (Logical), */
  109. 0x09, 0x02, /* Usage (02h), */
  110. 0x75, 0x08, /* Report Size (8), */
  111. 0x95, 0x10, /* Report Count (16), */
  112. 0x91, 0x02, /* Output (Variable), */
  113. 0xC0, /* End Collection, */
  114. 0xC0 /* End Collection */
  115. };
  116. #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
  117. (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
  118. static void steelseries_srws1_set_leds(struct hid_device *hdev, __u16 leds)
  119. {
  120. struct list_head *report_list = &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
  121. struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
  122. __s32 *value = report->field[0]->value;
  123. value[0] = 0x40;
  124. value[1] = leds & 0xFF;
  125. value[2] = leds >> 8;
  126. value[3] = 0x00;
  127. value[4] = 0x00;
  128. value[5] = 0x00;
  129. value[6] = 0x00;
  130. value[7] = 0x00;
  131. value[8] = 0x00;
  132. value[9] = 0x00;
  133. value[10] = 0x00;
  134. value[11] = 0x00;
  135. value[12] = 0x00;
  136. value[13] = 0x00;
  137. value[14] = 0x00;
  138. value[15] = 0x00;
  139. hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
  140. /* Note: LED change does not show on device until the device is read/polled */
  141. }
  142. static void steelseries_srws1_led_all_set_brightness(struct led_classdev *led_cdev,
  143. enum led_brightness value)
  144. {
  145. struct device *dev = led_cdev->dev->parent;
  146. struct hid_device *hid = to_hid_device(dev);
  147. struct steelseries_srws1_data *drv_data = hid_get_drvdata(hid);
  148. if (!drv_data) {
  149. hid_err(hid, "Device data not found.");
  150. return;
  151. }
  152. if (value == LED_OFF)
  153. drv_data->led_state = 0;
  154. else
  155. drv_data->led_state = (1 << (SRWS1_NUMBER_LEDS + 1)) - 1;
  156. steelseries_srws1_set_leds(hid, drv_data->led_state);
  157. }
  158. static enum led_brightness steelseries_srws1_led_all_get_brightness(struct led_classdev *led_cdev)
  159. {
  160. struct device *dev = led_cdev->dev->parent;
  161. struct hid_device *hid = to_hid_device(dev);
  162. struct steelseries_srws1_data *drv_data;
  163. drv_data = hid_get_drvdata(hid);
  164. if (!drv_data) {
  165. hid_err(hid, "Device data not found.");
  166. return LED_OFF;
  167. }
  168. return (drv_data->led_state >> SRWS1_NUMBER_LEDS) ? LED_FULL : LED_OFF;
  169. }
  170. static void steelseries_srws1_led_set_brightness(struct led_classdev *led_cdev,
  171. enum led_brightness value)
  172. {
  173. struct device *dev = led_cdev->dev->parent;
  174. struct hid_device *hid = to_hid_device(dev);
  175. struct steelseries_srws1_data *drv_data = hid_get_drvdata(hid);
  176. int i, state = 0;
  177. if (!drv_data) {
  178. hid_err(hid, "Device data not found.");
  179. return;
  180. }
  181. for (i = 0; i < SRWS1_NUMBER_LEDS; i++) {
  182. if (led_cdev != drv_data->led[i])
  183. continue;
  184. state = (drv_data->led_state >> i) & 1;
  185. if (value == LED_OFF && state) {
  186. drv_data->led_state &= ~(1 << i);
  187. steelseries_srws1_set_leds(hid, drv_data->led_state);
  188. } else if (value != LED_OFF && !state) {
  189. drv_data->led_state |= 1 << i;
  190. steelseries_srws1_set_leds(hid, drv_data->led_state);
  191. }
  192. break;
  193. }
  194. }
  195. static enum led_brightness steelseries_srws1_led_get_brightness(struct led_classdev *led_cdev)
  196. {
  197. struct device *dev = led_cdev->dev->parent;
  198. struct hid_device *hid = to_hid_device(dev);
  199. struct steelseries_srws1_data *drv_data;
  200. int i, value = 0;
  201. drv_data = hid_get_drvdata(hid);
  202. if (!drv_data) {
  203. hid_err(hid, "Device data not found.");
  204. return LED_OFF;
  205. }
  206. for (i = 0; i < SRWS1_NUMBER_LEDS; i++)
  207. if (led_cdev == drv_data->led[i]) {
  208. value = (drv_data->led_state >> i) & 1;
  209. break;
  210. }
  211. return value ? LED_FULL : LED_OFF;
  212. }
  213. static int steelseries_srws1_probe(struct hid_device *hdev,
  214. const struct hid_device_id *id)
  215. {
  216. int ret, i;
  217. struct led_classdev *led;
  218. size_t name_sz;
  219. char *name;
  220. struct steelseries_srws1_data *drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
  221. if (drv_data == NULL) {
  222. hid_err(hdev, "can't alloc SRW-S1 memory\n");
  223. return -ENOMEM;
  224. }
  225. hid_set_drvdata(hdev, drv_data);
  226. ret = hid_parse(hdev);
  227. if (ret) {
  228. hid_err(hdev, "parse failed\n");
  229. goto err_free;
  230. }
  231. if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 16)) {
  232. ret = -ENODEV;
  233. goto err_free;
  234. }
  235. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  236. if (ret) {
  237. hid_err(hdev, "hw start failed\n");
  238. goto err_free;
  239. }
  240. /* register led subsystem */
  241. drv_data->led_state = 0;
  242. for (i = 0; i < SRWS1_NUMBER_LEDS + 1; i++)
  243. drv_data->led[i] = NULL;
  244. steelseries_srws1_set_leds(hdev, 0);
  245. name_sz = strlen(hdev->uniq) + 16;
  246. /* 'ALL', for setting all LEDs simultaneously */
  247. led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL);
  248. if (!led) {
  249. hid_err(hdev, "can't allocate memory for LED ALL\n");
  250. goto err_led;
  251. }
  252. name = (void *)(&led[1]);
  253. snprintf(name, name_sz, "SRWS1::%s::RPMALL", hdev->uniq);
  254. led->name = name;
  255. led->brightness = 0;
  256. led->max_brightness = 1;
  257. led->brightness_get = steelseries_srws1_led_all_get_brightness;
  258. led->brightness_set = steelseries_srws1_led_all_set_brightness;
  259. drv_data->led[SRWS1_NUMBER_LEDS] = led;
  260. ret = led_classdev_register(&hdev->dev, led);
  261. if (ret)
  262. goto err_led;
  263. /* Each individual LED */
  264. for (i = 0; i < SRWS1_NUMBER_LEDS; i++) {
  265. led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL);
  266. if (!led) {
  267. hid_err(hdev, "can't allocate memory for LED %d\n", i);
  268. goto err_led;
  269. }
  270. name = (void *)(&led[1]);
  271. snprintf(name, name_sz, "SRWS1::%s::RPM%d", hdev->uniq, i+1);
  272. led->name = name;
  273. led->brightness = 0;
  274. led->max_brightness = 1;
  275. led->brightness_get = steelseries_srws1_led_get_brightness;
  276. led->brightness_set = steelseries_srws1_led_set_brightness;
  277. drv_data->led[i] = led;
  278. ret = led_classdev_register(&hdev->dev, led);
  279. if (ret) {
  280. hid_err(hdev, "failed to register LED %d. Aborting.\n", i);
  281. err_led:
  282. /* Deregister all LEDs (if any) */
  283. for (i = 0; i < SRWS1_NUMBER_LEDS + 1; i++) {
  284. led = drv_data->led[i];
  285. drv_data->led[i] = NULL;
  286. if (!led)
  287. continue;
  288. led_classdev_unregister(led);
  289. kfree(led);
  290. }
  291. goto out; /* but let the driver continue without LEDs */
  292. }
  293. }
  294. out:
  295. return 0;
  296. err_free:
  297. kfree(drv_data);
  298. return ret;
  299. }
  300. static void steelseries_srws1_remove(struct hid_device *hdev)
  301. {
  302. int i;
  303. struct led_classdev *led;
  304. struct steelseries_srws1_data *drv_data = hid_get_drvdata(hdev);
  305. if (drv_data) {
  306. /* Deregister LEDs (if any) */
  307. for (i = 0; i < SRWS1_NUMBER_LEDS + 1; i++) {
  308. led = drv_data->led[i];
  309. drv_data->led[i] = NULL;
  310. if (!led)
  311. continue;
  312. led_classdev_unregister(led);
  313. kfree(led);
  314. }
  315. }
  316. hid_hw_stop(hdev);
  317. kfree(drv_data);
  318. return;
  319. }
  320. #endif
  321. #define STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS 3000
  322. #define ARCTIS_1_BATTERY_RESPONSE_LEN 8
  323. static const char arctis_1_battery_request[] = { 0x06, 0x12 };
  324. static int steelseries_headset_arctis_1_fetch_battery(struct hid_device *hdev)
  325. {
  326. u8 *write_buf;
  327. int ret;
  328. /* Request battery information */
  329. write_buf = kmemdup(arctis_1_battery_request, sizeof(arctis_1_battery_request), GFP_KERNEL);
  330. if (!write_buf)
  331. return -ENOMEM;
  332. ret = hid_hw_raw_request(hdev, arctis_1_battery_request[0],
  333. write_buf, sizeof(arctis_1_battery_request),
  334. HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
  335. if (ret < (int)sizeof(arctis_1_battery_request)) {
  336. hid_err(hdev, "hid_hw_raw_request() failed with %d\n", ret);
  337. ret = -ENODATA;
  338. }
  339. kfree(write_buf);
  340. return ret;
  341. }
  342. static void steelseries_headset_fetch_battery(struct hid_device *hdev)
  343. {
  344. struct steelseries_device *sd = hid_get_drvdata(hdev);
  345. int ret = 0;
  346. if (sd->quirks & STEELSERIES_ARCTIS_1)
  347. ret = steelseries_headset_arctis_1_fetch_battery(hdev);
  348. if (ret < 0)
  349. hid_dbg(hdev,
  350. "Battery query failed (err: %d)\n", ret);
  351. }
  352. static void steelseries_headset_battery_timer_tick(struct work_struct *work)
  353. {
  354. struct steelseries_device *sd = container_of(work,
  355. struct steelseries_device, battery_work.work);
  356. struct hid_device *hdev = sd->hdev;
  357. steelseries_headset_fetch_battery(hdev);
  358. }
  359. static int steelseries_headset_battery_get_property(struct power_supply *psy,
  360. enum power_supply_property psp,
  361. union power_supply_propval *val)
  362. {
  363. struct steelseries_device *sd = power_supply_get_drvdata(psy);
  364. int ret = 0;
  365. switch (psp) {
  366. case POWER_SUPPLY_PROP_PRESENT:
  367. val->intval = 1;
  368. break;
  369. case POWER_SUPPLY_PROP_STATUS:
  370. val->intval = sd->headset_connected ?
  371. POWER_SUPPLY_STATUS_DISCHARGING :
  372. POWER_SUPPLY_STATUS_UNKNOWN;
  373. break;
  374. case POWER_SUPPLY_PROP_SCOPE:
  375. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  376. break;
  377. case POWER_SUPPLY_PROP_CAPACITY:
  378. val->intval = sd->battery_capacity;
  379. break;
  380. default:
  381. ret = -EINVAL;
  382. break;
  383. }
  384. return ret;
  385. }
  386. static void
  387. steelseries_headset_set_wireless_status(struct hid_device *hdev,
  388. bool connected)
  389. {
  390. struct usb_interface *intf;
  391. if (!hid_is_usb(hdev))
  392. return;
  393. intf = to_usb_interface(hdev->dev.parent);
  394. usb_set_wireless_status(intf, connected ?
  395. USB_WIRELESS_STATUS_CONNECTED :
  396. USB_WIRELESS_STATUS_DISCONNECTED);
  397. }
  398. static enum power_supply_property steelseries_headset_battery_props[] = {
  399. POWER_SUPPLY_PROP_PRESENT,
  400. POWER_SUPPLY_PROP_STATUS,
  401. POWER_SUPPLY_PROP_SCOPE,
  402. POWER_SUPPLY_PROP_CAPACITY,
  403. };
  404. static int steelseries_headset_battery_register(struct steelseries_device *sd)
  405. {
  406. static atomic_t battery_no = ATOMIC_INIT(0);
  407. struct power_supply_config battery_cfg = { .drv_data = sd, };
  408. unsigned long n;
  409. int ret;
  410. sd->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
  411. sd->battery_desc.properties = steelseries_headset_battery_props;
  412. sd->battery_desc.num_properties = ARRAY_SIZE(steelseries_headset_battery_props);
  413. sd->battery_desc.get_property = steelseries_headset_battery_get_property;
  414. sd->battery_desc.use_for_apm = 0;
  415. n = atomic_inc_return(&battery_no) - 1;
  416. sd->battery_desc.name = devm_kasprintf(&sd->hdev->dev, GFP_KERNEL,
  417. "steelseries_headset_battery_%ld", n);
  418. if (!sd->battery_desc.name)
  419. return -ENOMEM;
  420. /* avoid the warning of 0% battery while waiting for the first info */
  421. steelseries_headset_set_wireless_status(sd->hdev, false);
  422. sd->battery_capacity = 100;
  423. sd->battery = devm_power_supply_register(&sd->hdev->dev,
  424. &sd->battery_desc, &battery_cfg);
  425. if (IS_ERR(sd->battery)) {
  426. ret = PTR_ERR(sd->battery);
  427. hid_err(sd->hdev,
  428. "%s:power_supply_register failed with error %d\n",
  429. __func__, ret);
  430. return ret;
  431. }
  432. power_supply_powers(sd->battery, &sd->hdev->dev);
  433. INIT_DELAYED_WORK(&sd->battery_work, steelseries_headset_battery_timer_tick);
  434. steelseries_headset_fetch_battery(sd->hdev);
  435. return 0;
  436. }
  437. static int steelseries_probe(struct hid_device *hdev, const struct hid_device_id *id)
  438. {
  439. struct steelseries_device *sd;
  440. int ret;
  441. sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL);
  442. if (!sd)
  443. return -ENOMEM;
  444. hid_set_drvdata(hdev, sd);
  445. sd->hdev = hdev;
  446. sd->quirks = id->driver_data;
  447. if (sd->quirks & STEELSERIES_SRWS1) {
  448. #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
  449. (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
  450. return steelseries_srws1_probe(hdev, id);
  451. #else
  452. return -ENODEV;
  453. #endif
  454. }
  455. ret = hid_parse(hdev);
  456. if (ret)
  457. return ret;
  458. spin_lock_init(&sd->lock);
  459. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  460. if (ret)
  461. return ret;
  462. if (steelseries_headset_battery_register(sd) < 0)
  463. hid_err(sd->hdev,
  464. "Failed to register battery for headset\n");
  465. return ret;
  466. }
  467. static void steelseries_remove(struct hid_device *hdev)
  468. {
  469. struct steelseries_device *sd = hid_get_drvdata(hdev);
  470. unsigned long flags;
  471. if (sd->quirks & STEELSERIES_SRWS1) {
  472. #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
  473. (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
  474. steelseries_srws1_remove(hdev);
  475. #endif
  476. return;
  477. }
  478. spin_lock_irqsave(&sd->lock, flags);
  479. sd->removed = true;
  480. spin_unlock_irqrestore(&sd->lock, flags);
  481. cancel_delayed_work_sync(&sd->battery_work);
  482. hid_hw_stop(hdev);
  483. }
  484. static const __u8 *steelseries_srws1_report_fixup(struct hid_device *hdev,
  485. __u8 *rdesc, unsigned int *rsize)
  486. {
  487. if (hdev->vendor != USB_VENDOR_ID_STEELSERIES ||
  488. hdev->product != USB_DEVICE_ID_STEELSERIES_SRWS1)
  489. return rdesc;
  490. if (*rsize >= 115 && rdesc[11] == 0x02 && rdesc[13] == 0xc8
  491. && rdesc[29] == 0xbb && rdesc[40] == 0xc5) {
  492. hid_info(hdev, "Fixing up Steelseries SRW-S1 report descriptor\n");
  493. *rsize = sizeof(steelseries_srws1_rdesc_fixed);
  494. return steelseries_srws1_rdesc_fixed;
  495. }
  496. return rdesc;
  497. }
  498. static int steelseries_headset_raw_event(struct hid_device *hdev,
  499. struct hid_report *report, u8 *read_buf,
  500. int size)
  501. {
  502. struct steelseries_device *sd = hid_get_drvdata(hdev);
  503. int capacity = sd->battery_capacity;
  504. bool connected = sd->headset_connected;
  505. unsigned long flags;
  506. /* Not a headset */
  507. if (sd->quirks & STEELSERIES_SRWS1)
  508. return 0;
  509. if (sd->quirks & STEELSERIES_ARCTIS_1) {
  510. hid_dbg(sd->hdev,
  511. "Parsing raw event for Arctis 1 headset (%*ph)\n", size, read_buf);
  512. if (size < ARCTIS_1_BATTERY_RESPONSE_LEN ||
  513. memcmp (read_buf, arctis_1_battery_request, sizeof(arctis_1_battery_request)))
  514. return 0;
  515. if (read_buf[2] == 0x01) {
  516. connected = false;
  517. capacity = 100;
  518. } else {
  519. connected = true;
  520. capacity = read_buf[3];
  521. }
  522. }
  523. if (connected != sd->headset_connected) {
  524. hid_dbg(sd->hdev,
  525. "Connected status changed from %sconnected to %sconnected\n",
  526. sd->headset_connected ? "" : "not ",
  527. connected ? "" : "not ");
  528. sd->headset_connected = connected;
  529. steelseries_headset_set_wireless_status(hdev, connected);
  530. }
  531. if (capacity != sd->battery_capacity) {
  532. hid_dbg(sd->hdev,
  533. "Battery capacity changed from %d%% to %d%%\n",
  534. sd->battery_capacity, capacity);
  535. sd->battery_capacity = capacity;
  536. power_supply_changed(sd->battery);
  537. }
  538. spin_lock_irqsave(&sd->lock, flags);
  539. if (!sd->removed)
  540. schedule_delayed_work(&sd->battery_work,
  541. msecs_to_jiffies(STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS));
  542. spin_unlock_irqrestore(&sd->lock, flags);
  543. return 0;
  544. }
  545. static const struct hid_device_id steelseries_devices[] = {
  546. { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1),
  547. .driver_data = STEELSERIES_SRWS1 },
  548. { /* SteelSeries Arctis 1 Wireless for XBox */
  549. HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, 0x12b6),
  550. .driver_data = STEELSERIES_ARCTIS_1 },
  551. { }
  552. };
  553. MODULE_DEVICE_TABLE(hid, steelseries_devices);
  554. static struct hid_driver steelseries_driver = {
  555. .name = "steelseries",
  556. .id_table = steelseries_devices,
  557. .probe = steelseries_probe,
  558. .remove = steelseries_remove,
  559. .report_fixup = steelseries_srws1_report_fixup,
  560. .raw_event = steelseries_headset_raw_event,
  561. };
  562. module_hid_driver(steelseries_driver);
  563. MODULE_DESCRIPTION("HID driver for Steelseries devices");
  564. MODULE_LICENSE("GPL");
  565. MODULE_AUTHOR("Bastien Nocera <hadess@hadess.net>");
  566. MODULE_AUTHOR("Simon Wood <simon@mungewell.org>");