From nobody Mon Feb 9 10:25:41 2026 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3493B30BB8D for ; Mon, 12 Jan 2026 04:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768191689; cv=none; b=XLhd6jL98T1uzWPMQBvXHMuWWBzgpeNDNcXAXVrITaa/5TpCMPs1tFjMHjyTzxpmQmFRDxGy3PLFelO1GqYFyoO8haVyxIeKoDcISlNNrJG10x6nmNXOMplsr/nQbaXI7IR6rxPonNVQH64CZb9YuovumARWrGcMGpP7m+h5zGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768191689; c=relaxed/simple; bh=7KupU8plT/Xn2/stWgD4+qjwfFojDlfPlgZKGF9Lw84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T8FoM1UrL+cu/e2z0j19Qmp9Bjob+4rcsVPJ3J50WWjHHuv+gcbK3M47uc0V5dBcwXpvlhx2d0+vRYQTnFlS2Ri1YiEJjqKXtVB/P98RnBR+k/hNfpoF9Uq8iCIRMkagtuBuuAA0j46qxXzNarTnhHeRrb6pHrIvFlYUKj6PoS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MIi1oDdk; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MIi1oDdk" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-8b2ed01b95dso661841985a.0 for ; Sun, 11 Jan 2026 20:21:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768191670; x=1768796470; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dVt5xK139IY5UuyrJxByRbDMj9qpXpLr/BwvYNYUW/o=; b=MIi1oDdkavYAODhVAjjeW/rtTjvcWzzhcOBxMXlupS8BH4n+ecaJ7GPeSqSwZtCd1l bSY1YiLpJlQqwWJE5QUWngJaJbBegpvbZjugUPb2HYG2jfLwonjfKuf9C5LUrn7bfyuT Wzc/aSo9HvEzSfouNT5+olMBCupY/gxl03Gp88fx8kU7zkPcBMA/tA3VnppFlhD/xuKo I0WNJH8Cay3parFemgjF/DxKiPhu4FsdsdA6dHczzkpHdyAFvt7gFfT5b5aDqv5Chj+U THDtXSw3tEWNtQ8/Cb4B+UtNzXZ2wcH4ffyPKHltUQhANeV33hBopK9jjhLopSmZ82iN k7hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768191670; x=1768796470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dVt5xK139IY5UuyrJxByRbDMj9qpXpLr/BwvYNYUW/o=; b=Mb3UMItIr24jA76ZCmzhxIOceqrv5GLkZp2KDoKGBKJ2LtVzDW3+Z54OJ7Zs4BCtIo XdcrmedjUpEqKCcFfjjNwqebTeUpyS+LVPwNuGocoaFiwRrYwFis+4cDWLE4JEMf2Tfq c9iWQ+vfiMpK0fTwoIGGa06HxeZlU49X3q6nVSZrnNhUBPaBCfAyGR61LMY+K7INW5y4 Q9ayXlYAZnkM9vjgGqPfcCtgqKDjcIxfOLoQE6+cuqCoLsbIE9ah9H0Md/o9g1aG1/wg SEPxjiaRIP8/jm+qLP4v55uLT1vKAg8V+broH3+7+6YcIeyySp9OQFnohU0yAfgteqz5 009Q== X-Forwarded-Encrypted: i=1; AJvYcCX4L3ON9bNwRZN/KwQD2rwthlyJ1hO3qu2UbkFs3n5Nn/XJDWm80JAILFZrS+i7QK0z0kfFOXGxWq05EV8=@vger.kernel.org X-Gm-Message-State: AOJu0YzzLnUsHHBPF14TJcvntShfNGAMeKjDZ0wqXKQfT9I+MmWnQU2A LCD4IWNLoHHekm2BdByMhDbr8jdO+5cHsByHIK7Ylm/7VeU83GRY9gwc X-Gm-Gg: AY/fxX73jlGE1U7P+jbvBc5ghFTeEbiWhhhQYUekvj6UcNWIYZlVcHgakfovi7JR7UB Dr2KEhUj+vN3QUlX78EXPtsdnYy7nDtAOKzUV+y7jer+FFpYDqN38spbAmNsHwsxbP2fgiU9XvU JCyPqMk9WkQwKO1u5ECJg5Wgee/mMCmSFtogU8zN2824xJ5vAnIKTsXCyrs2gbzbUwFfYNZys9Q 5I0vFnWoV0fLShRDnpjJ6CY8I3D6N1XldZrPLcpB5QYX8AsTonxM7QmUtNeAwp136PEKr4ySbev eLGla8jNlkuoHWiK4BI7WcVDjTN6YEaxTNcAkAQjx0F79F0BCHFdm0JSsAx/HVirWaFLJQf9+1q E6QVkto9HAmWA5xDjj7XGg15kNOn4Dx+1h/KdOimWMSo7Gdv+sAdjhldsiNVUv48daGBuNnhD3/ HCq4LhYK0XuCrL2f440SaWYtEV2cHssYBHXRwNsw== X-Google-Smtp-Source: AGHT+IEPVsAEw1e9mk3EChbuqK05lRBMLAj1h5pfrZHXko8IHjDLdUHDvD2ACOr0GKyVM01gbmBzEQ== X-Received: by 2002:a05:620a:2991:b0:8b2:e6b1:a9b6 with SMTP id af79cd13be357-8c3893690c1mr2127115485a.2.1768191669605; Sun, 11 Jan 2026 20:21:09 -0800 (PST) Received: from achantapc.tail227c81.ts.net ([128.172.224.28]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c37f4cd7a3sm1470618385a.24.2026.01.11.20.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jan 2026 20:21:09 -0800 (PST) From: Sriman Achanta To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sriman Achanta Subject: [PATCH v2 4/4] HID: steelseries: Add support for Arctis headset lineup Date: Sun, 11 Jan 2026 23:19:41 -0500 Message-ID: <20260112041941.40531-5-srimanachanta@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112041941.40531-1-srimanachanta@gmail.com> References: <20260112041941.40531-1-srimanachanta@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add full support for the SteelSeries Arctis wireless gaming headset lineup, extending the driver from basic support for 2 models (Arctis 1 and 9) to comprehensive support for 25+ models across all Arctis generations. This is a major restructure of the hid-steelseries driver that replaces the previous minimal implementation with a unified, capability-based architecture. Architecture changes: - Introduce steelseries_device_info structure to define per-device capabilities, interface bindings, and metadata - Implement capability system (SS_CAP_*) for feature detection: battery, sidetone, chatmix, microphone controls, volume limiting, and Bluetooth settings - Add interface binding logic to correctly bind to HID control interfaces on multi-interface USB devices using two modes: * Mode 0: Bind to first enumerated interface (for Arctis 9, Pro) * Mode 1: Bind to specific interface via bitmask (for other models) - Create device info tables for all supported Arctis models with their specific capabilities and interface requirements Features added: - Battery monitoring: Implement power_supply integration with periodic polling and device-specific battery request protocols for all model families. Supports battery capacity reporting, charging status, and wireless connection tracking. - Sidetone control: Sysfs attribute to adjust microphone monitoring volume (0-128) with device-specific mapping to hardware ranges - Auto-sleep timeout: Configure inactivity timeout (0-90 minutes) before headset enters standby mode - ChatMix reporting: Read-only sysfs attribute reporting game/chat audio balance from physical dial on supported models - Microphone controls: * Mute LED brightness (0-3 or 0-10 depending on model) * Internal microphone gain/volume (0-128) - Volume limiter: Enable/disable EU hearing protection (max volume cap) - Bluetooth controls (Nova 7 series): * Auto-enable Bluetooth on power-on * Configure game audio attenuation during BT calls Implementation details: - Device-specific raw_event parsing for battery updates across different HID report formats (8-byte, 12-byte, 64-byte, 128-byte) - Helper functions for HID feature reports and output reports to handle different communication methods across device families - Attribute visibility system to expose only relevant controls for each device based on capability flags - Save-state commands after configuration changes to persist settings across power cycles The legacy SRW-S1 racing wheel controller support is preserved unchanged. Tested on Arctis Nova 7 (0x2202). All other implementation details are based on the reverse engineering done in the HeadsetControl library (abe3ac8). Signed-off-by: Sriman Achanta --- drivers/hid/hid-steelseries.c | 2061 ++++++++++++++++++++++++++++----- 1 file changed, 1740 insertions(+), 321 deletions(-) diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c index f98435631aa1..a0046fbc830b 100644 --- a/drivers/hid/hid-steelseries.c +++ b/drivers/hid/hid-steelseries.c @@ -4,9 +4,7 @@ * * Copyright (c) 2013 Simon Wood * Copyright (c) 2023 Bastien Nocera - */ - -/* + * Copyright (c) 2025 Sriman Achanta */ =20 #include @@ -14,124 +12,144 @@ #include #include #include +#include +#include +#include =20 #include "hid-ids.h" =20 -#define STEELSERIES_SRWS1 BIT(0) -#define STEELSERIES_ARCTIS_1 BIT(1) -#define STEELSERIES_ARCTIS_9 BIT(2) +#define SS_CAP_SIDETONE BIT(0) +#define SS_CAP_BATTERY BIT(1) +#define SS_CAP_INACTIVE_TIME BIT(2) +#define SS_CAP_CHATMIX BIT(3) +#define SS_CAP_MIC_MUTE_LED BIT(4) +#define SS_CAP_MIC_VOLUME BIT(5) +#define SS_CAP_VOLUME_LIMITER BIT(6) +#define SS_CAP_BT_POWER_ON BIT(7) +#define SS_CAP_BT_CALL_VOL BIT(8) + +/* Legacy quirk flag for SRW-S1 */ +#define STEELSERIES_SRWS1 BIT(0) + +struct steelseries_device_info { + u16 product_id; + const char *name; + u8 interface_binding_mode; /* 0 =3D first enumerated, 1 =3D specific inte= rface(s) */ + u16 valid_interfaces; /* Bitmask when mode =3D 1, ignored when mode =3D 0= */ + unsigned long capabilities; +}; =20 struct steelseries_device { struct hid_device *hdev; - unsigned long quirks; - - struct delayed_work battery_work; - spinlock_t lock; - bool removed; + const struct steelseries_device_info *info; =20 + /* Battery subsystem */ struct power_supply_desc battery_desc; struct power_supply *battery; - uint8_t battery_capacity; + struct delayed_work battery_work; + u8 battery_capacity; bool headset_connected; bool battery_charging; + + /* Synchronization */ + spinlock_t lock; + bool removed; + + /* Cached chatmix value (read-only from status) */ + int chatmix_level; }; =20 #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ - (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) + (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) #define SRWS1_NUMBER_LEDS 15 struct steelseries_srws1_data { __u16 led_state; - /* the last element is used for setting all leds simultaneously */ struct led_classdev *led[SRWS1_NUMBER_LEDS + 1]; }; #endif =20 -/* Fixed report descriptor for Steelseries SRW-S1 wheel controller - * - * The original descriptor hides the sensitivity and assists dials - * a custom vendor usage page. This inserts a patch to make them - * appear in the 'Generic Desktop' usage. - */ - +/* Fixed report descriptor for Steelseries SRW-S1 wheel controller */ static const __u8 steelseries_srws1_rdesc_fixed[] =3D { -0x05, 0x01, /* Usage Page (Desktop) */ -0x09, 0x08, /* Usage (MultiAxis), Changed */ -0xA1, 0x01, /* Collection (Application), */ -0xA1, 0x02, /* Collection (Logical), */ -0x95, 0x01, /* Report Count (1), */ -0x05, 0x01, /* Changed Usage Page (Desktop), */ -0x09, 0x30, /* Changed Usage (X), */ -0x16, 0xF8, 0xF8, /* Logical Minimum (-1800), */ -0x26, 0x08, 0x07, /* Logical Maximum (1800), */ -0x65, 0x14, /* Unit (Degrees), */ -0x55, 0x0F, /* Unit Exponent (15), */ -0x75, 0x10, /* Report Size (16), */ -0x81, 0x02, /* Input (Variable), */ -0x09, 0x31, /* Changed Usage (Y), */ -0x15, 0x00, /* Logical Minimum (0), */ -0x26, 0xFF, 0x03, /* Logical Maximum (1023), */ -0x75, 0x0C, /* Report Size (12), */ -0x81, 0x02, /* Input (Variable), */ -0x09, 0x32, /* Changed Usage (Z), */ -0x15, 0x00, /* Logical Minimum (0), */ -0x26, 0xFF, 0x03, /* Logical Maximum (1023), */ -0x75, 0x0C, /* Report Size (12), */ -0x81, 0x02, /* Input (Variable), */ -0x05, 0x01, /* Usage Page (Desktop), */ -0x09, 0x39, /* Usage (Hat Switch), */ -0x25, 0x07, /* Logical Maximum (7), */ -0x35, 0x00, /* Physical Minimum (0), */ -0x46, 0x3B, 0x01, /* Physical Maximum (315), */ -0x65, 0x14, /* Unit (Degrees), */ -0x75, 0x04, /* Report Size (4), */ -0x95, 0x01, /* Report Count (1), */ -0x81, 0x02, /* Input (Variable), */ -0x25, 0x01, /* Logical Maximum (1), */ -0x45, 0x01, /* Physical Maximum (1), */ -0x65, 0x00, /* Unit, */ -0x75, 0x01, /* Report Size (1), */ -0x95, 0x03, /* Report Count (3), */ -0x81, 0x01, /* Input (Constant), */ -0x05, 0x09, /* Usage Page (Button), */ -0x19, 0x01, /* Usage Minimum (01h), */ -0x29, 0x11, /* Usage Maximum (11h), */ -0x95, 0x11, /* Report Count (17), */ -0x81, 0x02, /* Input (Variable), */ - /* ---- Dial patch starts here ---- */ -0x05, 0x01, /* Usage Page (Desktop), */ -0x09, 0x33, /* Usage (RX), */ -0x75, 0x04, /* Report Size (4), */ -0x95, 0x02, /* Report Count (2), */ -0x15, 0x00, /* Logical Minimum (0), */ -0x25, 0x0b, /* Logical Maximum (b), */ -0x81, 0x02, /* Input (Variable), */ -0x09, 0x35, /* Usage (RZ), */ -0x75, 0x04, /* Report Size (4), */ -0x95, 0x01, /* Report Count (1), */ -0x25, 0x03, /* Logical Maximum (3), */ -0x81, 0x02, /* Input (Variable), */ - /* ---- Dial patch ends here ---- */ -0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ -0x09, 0x01, /* Usage (01h), */ -0x75, 0x04, /* Changed Report Size (4), */ -0x95, 0x0D, /* Changed Report Count (13), */ -0x81, 0x02, /* Input (Variable), */ -0xC0, /* End Collection, */ -0xA1, 0x02, /* Collection (Logical), */ -0x09, 0x02, /* Usage (02h), */ -0x75, 0x08, /* Report Size (8), */ -0x95, 0x10, /* Report Count (16), */ -0x91, 0x02, /* Output (Variable), */ -0xC0, /* End Collection, */ -0xC0 /* End Collection */ + 0x05, 0x01, /* Usage Page (Desktop) */ + 0x09, 0x08, /* Usage (MultiAxis), Changed */ + 0xA1, 0x01, /* Collection (Application), */ + 0xA1, 0x02, /* Collection (Logical), */ + 0x95, 0x01, /* Report Count (1), */ + 0x05, 0x01, /* Changed Usage Page (Desktop), */ + 0x09, 0x30, /* Changed Usage (X), */ + 0x16, 0xF8, 0xF8, /* Logical Minimum (-1800), */ + 0x26, 0x08, 0x07, /* Logical Maximum (1800), */ + 0x65, 0x14, /* Unit (Degrees), */ + 0x55, 0x0F, /* Unit Exponent (15), */ + 0x75, 0x10, /* Report Size (16), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x31, /* Changed Usage (Y), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */ + 0x75, 0x0C, /* Report Size (12), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x32, /* Changed Usage (Z), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */ + 0x75, 0x0C, /* Report Size (12), */ + 0x81, 0x02, /* Input (Variable), */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x39, /* Usage (Hat Switch), */ + 0x25, 0x07, /* Logical Maximum (7), */ + 0x35, 0x00, /* Physical Minimum (0), */ + 0x46, 0x3B, 0x01, /* Physical Maximum (315), */ + 0x65, 0x14, /* Unit (Degrees), */ + 0x75, 0x04, /* Report Size (4), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x45, 0x01, /* Physical Maximum (1), */ + 0x65, 0x00, /* Unit, */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x03, /* Report Count (3), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x09, /* Usage Page (Button), */ + 0x19, 0x01, /* Usage Minimum (01h), */ + 0x29, 0x11, /* Usage Maximum (11h), */ + 0x95, 0x11, /* Report Count (17), */ + 0x81, 0x02, /* Input (Variable), */ + /* ---- Dial patch starts here ---- */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x33, /* Usage (RX), */ + 0x75, 0x04, /* Report Size (4), */ + 0x95, 0x02, /* Report Count (2), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x25, 0x0b, /* Logical Maximum (b), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x35, /* Usage (RZ), */ + 0x75, 0x04, /* Report Size (4), */ + 0x95, 0x01, /* Report Count (1), */ + 0x25, 0x03, /* Logical Maximum (3), */ + 0x81, 0x02, /* Input (Variable), */ + /* ---- Dial patch ends here ---- */ + 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ + 0x09, 0x01, /* Usage (01h), */ + 0x75, 0x04, /* Changed Report Size (4), */ + 0x95, 0x0D, /* Changed Report Count (13), */ + 0x81, 0x02, /* Input (Variable), */ + 0xC0, /* End Collection, */ + 0xA1, 0x02, /* Collection (Logical), */ + 0x09, 0x02, /* Usage (02h), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x10, /* Report Count (16), */ + 0x91, 0x02, /* Output (Variable), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ }; =20 #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ - (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) + (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) static void steelseries_srws1_set_leds(struct hid_device *hdev, __u16 leds) { - struct list_head *report_list =3D &hdev->report_enum[HID_OUTPUT_REPORT].r= eport_list; - struct hid_report *report =3D list_entry(report_list->next, struct hid_re= port, list); + struct list_head *report_list =3D + &hdev->report_enum[HID_OUTPUT_REPORT].report_list; + struct hid_report *report =3D + list_entry(report_list->next, struct hid_report, list); __s32 *value =3D report->field[0]->value; =20 value[0] =3D 0x40; @@ -152,12 +170,11 @@ static void steelseries_srws1_set_leds(struct hid_dev= ice *hdev, __u16 leds) value[15] =3D 0x00; =20 hid_hw_request(hdev, report, HID_REQ_SET_REPORT); - - /* Note: LED change does not show on device until the device is read/poll= ed */ } =20 -static void steelseries_srws1_led_all_set_brightness(struct led_classdev *= led_cdev, - enum led_brightness value) +static void +steelseries_srws1_led_all_set_brightness(struct led_classdev *led_cdev, + enum led_brightness value) { struct device *dev =3D led_cdev->dev->parent; struct hid_device *hid =3D to_hid_device(dev); @@ -176,7 +193,8 @@ static void steelseries_srws1_led_all_set_brightness(st= ruct led_classdev *led_cd steelseries_srws1_set_leds(hid, drv_data->led_state); } =20 -static enum led_brightness steelseries_srws1_led_all_get_brightness(struct= led_classdev *led_cdev) +static enum led_brightness +steelseries_srws1_led_all_get_brightness(struct led_classdev *led_cdev) { struct device *dev =3D led_cdev->dev->parent; struct hid_device *hid =3D to_hid_device(dev); @@ -193,7 +211,7 @@ static enum led_brightness steelseries_srws1_led_all_ge= t_brightness(struct led_c } =20 static void steelseries_srws1_led_set_brightness(struct led_classdev *led_= cdev, - enum led_brightness value) + enum led_brightness value) { struct device *dev =3D led_cdev->dev->parent; struct hid_device *hid =3D to_hid_device(dev); @@ -221,7 +239,8 @@ static void steelseries_srws1_led_set_brightness(struct= led_classdev *led_cdev, } } =20 -static enum led_brightness steelseries_srws1_led_get_brightness(struct led= _classdev *led_cdev) +static enum led_brightness +steelseries_srws1_led_get_brightness(struct led_classdev *led_cdev) { struct device *dev =3D led_cdev->dev->parent; struct hid_device *hid =3D to_hid_device(dev); @@ -245,7 +264,7 @@ static enum led_brightness steelseries_srws1_led_get_br= ightness(struct led_class } =20 static int steelseries_srws1_probe(struct hid_device *hdev, - const struct hid_device_id *id) + const struct hid_device_id *id) { int ret, i; struct led_classdev *led; @@ -288,7 +307,8 @@ static int steelseries_srws1_probe(struct hid_device *h= dev, name_sz =3D strlen(hdev->uniq) + 16; =20 /* 'ALL', for setting all LEDs simultaneously */ - led =3D devm_kzalloc(&hdev->dev, sizeof(struct led_classdev)+name_sz, GFP= _KERNEL); + led =3D devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, + GFP_KERNEL); if (!led) { hid_err(hdev, "can't allocate memory for LED ALL\n"); goto out; @@ -305,20 +325,23 @@ static int steelseries_srws1_probe(struct hid_device = *hdev, drv_data->led[SRWS1_NUMBER_LEDS] =3D led; ret =3D devm_led_classdev_register(&hdev->dev, led); if (ret) { - hid_err(hdev, "failed to register LED %d. Aborting.\n", SRWS1_NUMBER_LED= S); - goto out; /* let the driver continue without LEDs */ + hid_err(hdev, "failed to register LED %d. Aborting.\n", + SRWS1_NUMBER_LEDS); + goto out; } =20 /* Each individual LED */ for (i =3D 0; i < SRWS1_NUMBER_LEDS; i++) { - led =3D devm_kzalloc(&hdev->dev, sizeof(struct led_classdev)+name_sz, GF= P_KERNEL); + led =3D devm_kzalloc(&hdev->dev, + sizeof(struct led_classdev) + name_sz, + GFP_KERNEL); if (!led) { hid_err(hdev, "can't allocate memory for LED %d\n", i); break; } =20 name =3D (void *)(&led[1]); - snprintf(name, name_sz, "SRWS1::%s::RPM%d", hdev->uniq, i+1); + snprintf(name, name_sz, "SRWS1::%s::RPM%d", hdev->uniq, i + 1); led->name =3D name; led->brightness =3D 0; led->max_brightness =3D 1; @@ -329,8 +352,9 @@ static int steelseries_srws1_probe(struct hid_device *h= dev, ret =3D devm_led_classdev_register(&hdev->dev, led); =20 if (ret) { - hid_err(hdev, "failed to register LED %d. Aborting.\n", i); - break; /* but let the driver continue without LEDs */ + hid_err(hdev, "failed to register LED %d. Aborting.\n", + i); + break; } } out: @@ -340,51 +364,277 @@ static int steelseries_srws1_probe(struct hid_device= *hdev, } #endif =20 -#define STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS 3000 +static const __u8 *steelseries_srws1_report_fixup(struct hid_device *hdev, + __u8 *rdesc, + unsigned int *rsize) +{ + if (hdev->vendor !=3D USB_VENDOR_ID_STEELSERIES || + hdev->product !=3D USB_DEVICE_ID_STEELSERIES_SRWS1) + return rdesc; + + if (*rsize >=3D 115 && rdesc[11] =3D=3D 0x02 && rdesc[13] =3D=3D 0xc8 && + rdesc[29] =3D=3D 0xbb && rdesc[40] =3D=3D 0xc5) { + hid_info(hdev, + "Fixing up Steelseries SRW-S1 report descriptor\n"); + *rsize =3D sizeof(steelseries_srws1_rdesc_fixed); + return steelseries_srws1_rdesc_fixed; + } + return rdesc; +} + +static const struct steelseries_device_info arctis_1_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1, + .name =3D "Arctis 1 Wireless", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; =20 -#define ARCTIS_1_BATTERY_RESPONSE_LEN 8 -#define ARCTIS_9_BATTERY_RESPONSE_LEN 64 -static const char arctis_1_battery_request[] =3D { 0x06, 0x12 }; -static const char arctis_9_battery_request[] =3D { 0x00, 0x20 }; +static const struct steelseries_device_info arctis_1_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1_X, + .name =3D "Arctis 1 Wireless for Xbox", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; =20 -static int steelseries_headset_request_battery(struct hid_device *hdev, - const char *request, size_t len) -{ - u8 *write_buf; - int ret; +static const struct steelseries_device_info arctis_7_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7, + .name =3D "Arctis 7", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(5), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; =20 - /* Request battery information */ - write_buf =3D kmemdup(request, len, GFP_KERNEL); - if (!write_buf) - return -ENOMEM; +static const struct steelseries_device_info arctis_7_p_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_P, + .name =3D "Arctis 7P", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; =20 - hid_dbg(hdev, "Sending battery request report"); - ret =3D hid_hw_raw_request(hdev, request[0], write_buf, len, - HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); - if (ret < (int)len) { - hid_err(hdev, "hid_hw_raw_request() failed with %d\n", ret); - ret =3D -ENODATA; - } +static const struct steelseries_device_info arctis_7_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_X, + .name =3D "Arctis 7X", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; =20 - kfree(write_buf); - return ret; -} +static const struct steelseries_device_info arctis_7_gen2_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_GEN2, + .name =3D "Arctis 7 (2019 Edition)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(5), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; =20 -static void steelseries_headset_fetch_battery(struct hid_device *hdev) -{ - int ret =3D 0; +static const struct steelseries_device_info arctis_7_plus_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS, + .name =3D "Arctis 7+", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_CHATMIX, +}; =20 - if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1) - ret =3D steelseries_headset_request_battery(hdev, - arctis_1_battery_request, sizeof(arctis_1_battery_request)); - else if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) - ret =3D steelseries_headset_request_battery(hdev, - arctis_9_battery_request, sizeof(arctis_9_battery_request)); +static const struct steelseries_device_info arctis_7_plus_p_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_P, + .name =3D "Arctis 7+ (PlayStation)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_CHATMIX, +}; =20 - if (ret < 0) - hid_dbg(hdev, - "Battery query failed (err: %d)\n", ret); -} +static const struct steelseries_device_info arctis_7_plus_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_X, + .name =3D "Arctis 7+ (Xbox)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_CHATMIX, +}; + +static const struct steelseries_device_info arctis_7_plus_destiny_info =3D= { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_DESTINY, + .name =3D "Arctis 7+ (Destiny Edition)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_CHATMIX, +}; + +static const struct steelseries_device_info arctis_9_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9, + .name =3D "Arctis 9", + .interface_binding_mode =3D 0, + .valid_interfaces =3D 0, + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_CHATMIX, +}; + +static const struct steelseries_device_info arctis_pro_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_PRO, + .name =3D "Arctis Pro Wireless", + .interface_binding_mode =3D 0, + .valid_interfaces =3D 0, + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; + +static const struct steelseries_device_info arctis_nova_3_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3, + .name =3D "Arctis Nova 3", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(4), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME, +}; + +static const struct steelseries_device_info arctis_nova_3_p_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P, + .name =3D "Arctis Nova 3 (PlayStation)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(0), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_VOLUME, +}; + +static const struct steelseries_device_info arctis_nova_3_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X, + .name =3D "Arctis Nova 3 (Xbox)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(0), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_VOLUME, +}; + +static const struct steelseries_device_info arctis_nova_5_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5, + .name =3D "Arctis Nova 5", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER, +}; + +static const struct steelseries_device_info arctis_nova_5_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X, + .name =3D "Arctis Nova 5X", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER, +}; + +static const struct steelseries_device_info arctis_nova_7_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7, + .name =3D "Arctis Nova 7", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X, + .name =3D "Arctis Nova 7X", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_p_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_P, + .name =3D "Arctis Nova 7P", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_x_rev2_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X_REV2, + .name =3D "Arctis Nova 7X (Rev 2)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_diablo_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_DIABLO, + .name =3D "Arctis Nova 7 (Diablo IV Edition)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_wow_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_WOW, + .name =3D "Arctis Nova 7 (World of Warcraft Edition)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_gen2_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_GEN2, + .name =3D "Arctis Nova 7 (Gen 2)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_7_x_gen2_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X_GEN2, + .name =3D "Arctis Nova 7X (Gen 2)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(3), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_CHATMIX | + SS_CAP_INACTIVE_TIME | SS_CAP_MIC_MUTE_LED | + SS_CAP_MIC_VOLUME | SS_CAP_VOLUME_LIMITER | + SS_CAP_BT_POWER_ON | SS_CAP_BT_CALL_VOL, +}; + +static const struct steelseries_device_info arctis_nova_pro_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO, + .name =3D "Arctis Nova Pro Wireless", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(4), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; + +static const struct steelseries_device_info arctis_nova_pro_x_info =3D { + .product_id =3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO_X, + .name =3D "Arctis Nova Pro Wireless (Xbox)", + .interface_binding_mode =3D 1, + .valid_interfaces =3D BIT(4), + .capabilities =3D SS_CAP_SIDETONE | SS_CAP_BATTERY | SS_CAP_INACTIVE_TIME, +}; + +#define STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS 3000 =20 static int battery_capacity_to_level(int capacity) { @@ -395,29 +645,45 @@ static int battery_capacity_to_level(int capacity) return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; } =20 -static void steelseries_headset_battery_timer_tick(struct work_struct *wor= k) +static u8 steelseries_map_battery(u8 capacity, u8 min_in, u8 max_in) +{ + if (capacity >=3D max_in) + return 100; + if (capacity <=3D min_in) + return 0; + return (capacity - min_in) * 100 / (max_in - min_in); +} + +static void steelseries_headset_set_wireless_status(struct hid_device *hde= v, + bool connected) { - struct steelseries_device *sd =3D container_of(work, - struct steelseries_device, battery_work.work); - struct hid_device *hdev =3D sd->hdev; + struct usb_interface *intf; =20 - steelseries_headset_fetch_battery(hdev); + if (!hid_is_usb(hdev)) + return; + + intf =3D to_usb_interface(hdev->dev.parent); + usb_set_wireless_status(intf, connected ? + USB_WIRELESS_STATUS_CONNECTED : + USB_WIRELESS_STATUS_DISCONNECTED); } =20 #define STEELSERIES_PREFIX "SteelSeries " #define STEELSERIES_PREFIX_LEN strlen(STEELSERIES_PREFIX) =20 -static int steelseries_headset_battery_get_property(struct power_supply *p= sy, - enum power_supply_property psp, - union power_supply_propval *val) +static int steelseries_battery_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) { struct steelseries_device *sd =3D power_supply_get_drvdata(psy); + unsigned long flags; int ret =3D 0; =20 switch (psp) { case POWER_SUPPLY_PROP_MODEL_NAME: val->strval =3D sd->hdev->name; - while (!strncmp(val->strval, STEELSERIES_PREFIX, STEELSERIES_PREFIX_LEN)) + while (!strncmp(val->strval, STEELSERIES_PREFIX, + STEELSERIES_PREFIX_LEN)) val->strval +=3D STEELSERIES_PREFIX_LEN; break; case POWER_SUPPLY_PROP_MANUFACTURER: @@ -427,21 +693,28 @@ static int steelseries_headset_battery_get_property(s= truct power_supply *psy, val->intval =3D 1; break; case POWER_SUPPLY_PROP_STATUS: + spin_lock_irqsave(&sd->lock, flags); if (sd->headset_connected) { val->intval =3D sd->battery_charging ? - POWER_SUPPLY_STATUS_CHARGING : - POWER_SUPPLY_STATUS_DISCHARGING; - } else + POWER_SUPPLY_STATUS_CHARGING : + POWER_SUPPLY_STATUS_DISCHARGING; + } else { val->intval =3D POWER_SUPPLY_STATUS_UNKNOWN; + } + spin_unlock_irqrestore(&sd->lock, flags); break; case POWER_SUPPLY_PROP_SCOPE: val->intval =3D POWER_SUPPLY_SCOPE_DEVICE; break; case POWER_SUPPLY_PROP_CAPACITY: + spin_lock_irqsave(&sd->lock, flags); val->intval =3D sd->battery_capacity; + spin_unlock_irqrestore(&sd->lock, flags); break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: + spin_lock_irqsave(&sd->lock, flags); val->intval =3D battery_capacity_to_level(sd->battery_capacity); + spin_unlock_irqrestore(&sd->lock, flags); break; default: ret =3D -EINVAL; @@ -450,289 +723,1434 @@ static int steelseries_headset_battery_get_propert= y(struct power_supply *psy, return ret; } =20 -static void -steelseries_headset_set_wireless_status(struct hid_device *hdev, - bool connected) +static enum power_supply_property steelseries_battery_props[] =3D { + POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, + POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_CAPACITY_LEVEL, +}; + +/* Forward declarations for battery request functions */ +static int steelseries_arctis_1_request_battery(struct hid_device *hdev); +static int steelseries_arctis_7_plus_request_battery(struct hid_device *hd= ev); +static int steelseries_arctis_9_request_battery(struct hid_device *hdev); +static int steelseries_arctis_nova_request_battery(struct hid_device *hdev= ); +static int steelseries_arctis_nova_3p_request_battery(struct hid_device *h= dev); +static int +steelseries_arctis_pro_wireless_request_battery(struct hid_device *hdev); + +static int steelseries_request_battery(struct hid_device *hdev) { - struct usb_interface *intf; + u16 product =3D hdev->product; =20 - if (!hid_is_usb(hdev)) - return; + /* Route to device-specific battery request handler */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_X) + return steelseries_arctis_1_request_battery(hdev); =20 - intf =3D to_usb_interface(hdev->dev.parent); - usb_set_wireless_status(intf, connected ? - USB_WIRELESS_STATUS_CONNECTED : - USB_WIRELESS_STATUS_DISCONNECTED); + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_DESTINY) + return steelseries_arctis_7_plus_request_battery(hdev); + + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) + return steelseries_arctis_9_request_battery(hdev); + + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_PRO) + return steelseries_arctis_pro_wireless_request_battery(hdev); + + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X) + return steelseries_arctis_nova_3p_request_battery(hdev); + + /* All other Nova series use the same battery request */ + return steelseries_arctis_nova_request_battery(hdev); } =20 -static enum power_supply_property steelseries_headset_battery_props[] =3D { - POWER_SUPPLY_PROP_MODEL_NAME, - POWER_SUPPLY_PROP_MANUFACTURER, - POWER_SUPPLY_PROP_PRESENT, - POWER_SUPPLY_PROP_STATUS, - POWER_SUPPLY_PROP_SCOPE, - POWER_SUPPLY_PROP_CAPACITY, - POWER_SUPPLY_PROP_CAPACITY_LEVEL, -}; +static void steelseries_battery_timer_tick(struct work_struct *work) +{ + struct steelseries_device *sd =3D container_of( + work, struct steelseries_device, battery_work.work); + + steelseries_request_battery(sd->hdev); +} =20 -static int steelseries_headset_battery_register(struct steelseries_device = *sd) +static int steelseries_battery_register(struct steelseries_device *sd) { static atomic_t battery_no =3D ATOMIC_INIT(0); - struct power_supply_config battery_cfg =3D { .drv_data =3D sd, }; + struct power_supply_config battery_cfg =3D { + .drv_data =3D sd, + }; unsigned long n; int ret; =20 sd->battery_desc.type =3D POWER_SUPPLY_TYPE_BATTERY; - sd->battery_desc.properties =3D steelseries_headset_battery_props; - sd->battery_desc.num_properties =3D ARRAY_SIZE(steelseries_headset_batter= y_props); - sd->battery_desc.get_property =3D steelseries_headset_battery_get_propert= y; + sd->battery_desc.properties =3D steelseries_battery_props; + sd->battery_desc.num_properties =3D ARRAY_SIZE(steelseries_battery_props); + sd->battery_desc.get_property =3D steelseries_battery_get_property; sd->battery_desc.use_for_apm =3D 0; n =3D atomic_inc_return(&battery_no) - 1; - sd->battery_desc.name =3D devm_kasprintf(&sd->hdev->dev, GFP_KERNEL, - "steelseries_headset_battery_%ld", n); + sd->battery_desc.name =3D + devm_kasprintf(&sd->hdev->dev, GFP_KERNEL, + "steelseries_headset_battery_%ld", n); if (!sd->battery_desc.name) return -ENOMEM; =20 - /* avoid the warning of 0% battery while waiting for the first info */ steelseries_headset_set_wireless_status(sd->hdev, false); - sd->battery_capacity =3D 100; + sd->battery_capacity =3D + 100; /* Start with full to avoid low battery warnings */ sd->battery_charging =3D false; + sd->headset_connected =3D false; + sd->chatmix_level =3D 64; =20 - sd->battery =3D devm_power_supply_register(&sd->hdev->dev, - &sd->battery_desc, &battery_cfg); + sd->battery =3D devm_power_supply_register( + &sd->hdev->dev, &sd->battery_desc, &battery_cfg); if (IS_ERR(sd->battery)) { ret =3D PTR_ERR(sd->battery); - hid_err(sd->hdev, - "%s:power_supply_register failed with error %d\n", - __func__, ret); + hid_err(sd->hdev, "Failed to register battery: %d\n", ret); return ret; } power_supply_powers(sd->battery, &sd->hdev->dev); =20 - INIT_DELAYED_WORK(&sd->battery_work, steelseries_headset_battery_timer_ti= ck); - steelseries_headset_fetch_battery(sd->hdev); + INIT_DELAYED_WORK(&sd->battery_work, steelseries_battery_timer_tick); + steelseries_request_battery(sd->hdev); =20 - if (sd->quirks & STEELSERIES_ARCTIS_9) { - /* The first fetch_battery request can remain unanswered in some cases */ - schedule_delayed_work(&sd->battery_work, - msecs_to_jiffies(STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS)); + /* Arctis 9 may need a retry */ + if (sd->hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) { + schedule_delayed_work( + &sd->battery_work, + msecs_to_jiffies( + STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS)); } =20 return 0; } =20 -static bool steelseries_is_vendor_usage_page(struct hid_device *hdev, uint= 8_t usage_page) +/* Helper function to send feature reports */ +static int steelseries_send_feature_report(struct hid_device *hdev, + const u8 *data, size_t len) { - return hdev->rdesc[0] =3D=3D 0x06 && - hdev->rdesc[1] =3D=3D usage_page && - hdev->rdesc[2] =3D=3D 0xff; + u8 *buf; + int ret; + + buf =3D kmemdup(data, len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret =3D hid_hw_raw_request(hdev, data[0], buf, len, HID_FEATURE_REPORT, + HID_REQ_SET_REPORT); + kfree(buf); + + if (ret < 0) + return ret; + if (ret < len) + return -EIO; + + return 0; } =20 -static int steelseries_probe(struct hid_device *hdev, const struct hid_dev= ice_id *id) +/* Helper function to send output reports */ +static int steelseries_send_output_report(struct hid_device *hdev, + const u8 *data, size_t len) { - struct steelseries_device *sd; + u8 *buf; int ret; =20 - if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_SRWS1) { -#if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ - (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) - return steelseries_srws1_probe(hdev, id); -#else - return -ENODEV; -#endif - } - - sd =3D devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); - if (!sd) + buf =3D kmemdup(data, len, GFP_KERNEL); + if (!buf) return -ENOMEM; - hid_set_drvdata(hdev, sd); - sd->hdev =3D hdev; - sd->quirks =3D id->driver_data; =20 - ret =3D hid_parse(hdev); - if (ret) + /* Use raw_request with OUTPUT_REPORT type for devices without Interrupt = OUT */ + ret =3D hid_hw_raw_request(hdev, data[0], buf, len, HID_OUTPUT_REPORT, + HID_REQ_SET_REPORT); + kfree(buf); + + if (ret < 0) return ret; + if (ret < len) + return -EIO; =20 - if (sd->quirks & STEELSERIES_ARCTIS_9 && - !steelseries_is_vendor_usage_page(hdev, 0xc0)) - return -ENODEV; + return 0; +} =20 - spin_lock_init(&sd->lock); +/* Sidetone level attribute */ +static ssize_t sidetone_level_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + /* Sidetone is write-only, no way to read current value */ + return sysfs_emit(buf, "Write-only attribute (0-128)\n"); +} =20 - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT); - if (ret) - return ret; +static ssize_t sidetone_level_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev =3D to_hid_device(dev); + u16 product =3D hdev->product; + unsigned int value; + u8 data[64] =3D { 0 }; + int ret; =20 - ret =3D hid_hw_open(hdev); - if (ret) - return ret; + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + if (value > 128) + return -EINVAL; + + /* Device-specific sidetone mappings */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_GEN2) { + /* Map 0-128 to 0x00-0x12 (18) */ + u8 level =3D (value * 0x12) / 128; + + if (level =3D=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x35; + data[2] =3D 0x00; + ret =3D steelseries_send_feature_report(hdev, data, 31); + } else { + data[0] =3D 0x06; + data[1] =3D 0x35; + data[2] =3D 0x01; + data[3] =3D 0x00; + data[4] =3D level; + ret =3D steelseries_send_feature_report(hdev, data, 31); + } + if (ret >=3D 0) { + /* Save state */ + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_DESTINY) { + /* Map to 0-3 levels */ + u8 level; + + if (value < 26) + level =3D 0x0; + else if (value < 51) + level =3D 0x1; + else if (value < 76) + level =3D 0x2; + else + level =3D 0x3; + + data[0] =3D 0x00; + data[1] =3D 0x39; + data[2] =3D level; + ret =3D steelseries_send_feature_report(hdev, data, 64); + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) { + /* Arctis 9: exponential mapping to 0xc0-0xfd */ + u8 level; + + if (value =3D=3D 0) + level =3D 0xc0; + else + level =3D 0xc0 + ((value * (0xfd - 0xc0)) / 128); + + data[0] =3D 0x06; + data[1] =3D 0x00; + data[2] =3D level; + ret =3D steelseries_send_feature_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x90; + data[1] =3D 0x00; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_PRO) { + /* Arctis Pro Wireless: 0x00-0x09 */ + u8 level =3D (value * 0x09) / 128; + + data[0] =3D 0x39; + data[1] =3D 0xAA; + data[2] =3D level; + ret =3D steelseries_send_feature_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x90; + data[1] =3D 0xAA; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3) { + /* Nova 3: 0-3 levels */ + u8 level; + + if (value < 26) + level =3D 0x0; + else if (value < 51) + level =3D 0x1; + else if (value < 76) + level =3D 0x2; + else + level =3D 0x3; + + data[0] =3D 0x06; + data[1] =3D 0x39; + data[2] =3D level; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X) { + /* Nova 3P/3X: Map to 0-10 */ + u8 level =3D (value * 0x0a) / 128; + + data[0] =3D 0x39; + data[1] =3D level; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X) { + /* Nova 5: Map to 0-10 */ + u8 level =3D (value * 0x0a) / 128; + + data[0] =3D 0x00; + data[1] =3D 0x39; + data[2] =3D level; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + data[0] =3D 0x00; + data[1] =3D 0x35; + data[2] =3D 0x01; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO_X) { + /* Nova Pro: 0-3 only */ + if (value > 3) + return -EINVAL; + data[0] =3D 0x06; + data[1] =3D 0x39; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 31); + } + } else { + /* Nova 7 series: 0-3 levels */ + u8 level; + + if (value < 26) + level =3D 0x0; + else if (value < 51) + level =3D 0x1; + else if (value < 76) + level =3D 0x2; + else + level =3D 0x3; + + data[0] =3D 0x00; + data[1] =3D 0x39; + data[2] =3D level; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + memset(data, 0, sizeof(data)); + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } =20 - if (steelseries_headset_battery_register(sd) < 0) - hid_err(sd->hdev, - "Failed to register battery for headset\n"); + return (ret < 0) ? ret : count; +} +static DEVICE_ATTR_RW(sidetone_level); =20 - return ret; +/* Inactive time attribute */ +static ssize_t inactive_time_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "Write-only attribute (0-90 minutes)\n"); } =20 -static void steelseries_remove(struct hid_device *hdev) +static ssize_t inactive_time_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - struct steelseries_device *sd; - unsigned long flags; + struct hid_device *hdev =3D to_hid_device(dev); + u16 product =3D hdev->product; + unsigned int value; + u8 data[64] =3D { 0 }; + int ret; =20 - if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_SRWS1) { -#if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ - (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) - hid_hw_stop(hdev); -#endif - return; + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + if (value > 90) + return -EINVAL; + + /* Device-specific mappings */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_X) { + data[0] =3D 0x06; + data[1] =3D 0x53; + data[2] =3D value; + ret =3D steelseries_send_feature_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_GEN2) { + data[0] =3D 0x06; + data[1] =3D 0x51; + data[2] =3D value; + ret =3D steelseries_send_feature_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_DESTINY) { + data[0] =3D 0x00; + data[1] =3D 0xa3; + data[2] =3D value; + ret =3D steelseries_send_feature_report(hdev, data, 64); + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) { + /* Arctis 9 uses seconds */ + u32 seconds =3D value * 60; + + data[0] =3D 0x04; + data[1] =3D 0x00; + data[2] =3D (seconds >> 8) & 0xff; + data[3] =3D seconds & 0xff; + ret =3D steelseries_send_feature_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x90; + data[1] =3D 0x00; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_PRO) { + /* Pro Wireless uses 10-minute increments */ + u8 increments =3D value / 10; + + data[0] =3D 0x3c; + data[1] =3D 0xAA; + data[2] =3D increments; + ret =3D steelseries_send_feature_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x90; + data[1] =3D 0xAA; + steelseries_send_feature_report(hdev, data, 31); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X) { + /* Map to specific values */ + u8 mapped; + + if (value >=3D 90) + mapped =3D 90; + else if (value >=3D 75) + mapped =3D 75; + else if (value >=3D 60) + mapped =3D 60; + else if (value >=3D 45) + mapped =3D 45; + else if (value >=3D 30) + mapped =3D 30; + else if (value >=3D 15) + mapped =3D 15; + else if (value >=3D 10) + mapped =3D 10; + else if (value >=3D 5) + mapped =3D 5; + else if (value >=3D 1) + mapped =3D 1; + else + mapped =3D 0; + + data[0] =3D 0xa3; + data[1] =3D mapped; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO_X) { + /* Map to enum values */ + u8 mapped; + + if (value >=3D 45) + mapped =3D 6; + else if (value >=3D 23) + mapped =3D 5; + else if (value >=3D 13) + mapped =3D 4; + else if (value >=3D 8) + mapped =3D 3; + else if (value >=3D 3) + mapped =3D 2; + else if (value > 0) + mapped =3D 1; + else + mapped =3D 0; + + data[0] =3D 0x06; + data[1] =3D 0xc1; + data[2] =3D mapped; + ret =3D steelseries_send_output_report(hdev, data, 31); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 31); + } + } else { + /* Nova 5/7 series */ + data[0] =3D 0x00; + data[1] =3D 0xa3; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + memset(data, 0, sizeof(data)); + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } } =20 - sd =3D hid_get_drvdata(hdev); + return (ret < 0) ? ret : count; +} +static DEVICE_ATTR_RW(inactive_time); =20 - spin_lock_irqsave(&sd->lock, flags); - sd->removed =3D true; - spin_unlock_irqrestore(&sd->lock, flags); +/* ChatMix level attribute (read-only) */ +static ssize_t chatmix_level_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct hid_device *hdev =3D to_hid_device(dev); + struct steelseries_device *sd =3D hid_get_drvdata(hdev); =20 - cancel_delayed_work_sync(&sd->battery_work); + return sysfs_emit(buf, "%d\n", sd->chatmix_level); +} +static DEVICE_ATTR_RO(chatmix_level); =20 - hid_hw_close(hdev); - hid_hw_stop(hdev); +/* Microphone mute LED brightness */ +static ssize_t mic_mute_led_brightness_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, + "Write-only (0-3 or 0-10 depending on device)\n"); } =20 -static const __u8 *steelseries_srws1_report_fixup(struct hid_device *hdev, - __u8 *rdesc, unsigned int *rsize) +static ssize_t mic_mute_led_brightness_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - if (hdev->vendor !=3D USB_VENDOR_ID_STEELSERIES || - hdev->product !=3D USB_DEVICE_ID_STEELSERIES_SRWS1) - return rdesc; + struct hid_device *hdev =3D to_hid_device(dev); + u16 product =3D hdev->product; + unsigned int value; + u8 data[64] =3D { 0 }; + int ret; =20 - if (*rsize >=3D 115 && rdesc[11] =3D=3D 0x02 && rdesc[13] =3D=3D 0xc8 - && rdesc[29] =3D=3D 0xbb && rdesc[40] =3D=3D 0xc5) { - hid_info(hdev, "Fixing up Steelseries SRW-S1 report descriptor\n"); - *rsize =3D sizeof(steelseries_srws1_rdesc_fixed); - return steelseries_srws1_rdesc_fixed; + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + + /* Device-specific validation */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3) { + if (value > 3) + return -EINVAL; + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X) { + if (value > 10) + return -EINVAL; + /* Map special values */ + if (value =3D=3D 2) + value =3D 0x04; + else if (value =3D=3D 3) + value =3D 0x0a; + } else { + if (value > 3) + return -EINVAL; } - return rdesc; + + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3) { + data[0] =3D 0x06; + data[1] =3D 0xae; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X) { + data[0] =3D 0x00; + data[1] =3D 0xae; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + data[0] =3D 0x00; + data[1] =3D 0x35; + data[2] =3D 0x01; + steelseries_send_output_report(hdev, data, 64); + } + } else { + /* Nova 7 series */ + data[0] =3D 0x00; + data[1] =3D 0xae; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + memset(data, 0, sizeof(data)); + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } + + return (ret < 0) ? ret : count; } +static DEVICE_ATTR_RW(mic_mute_led_brightness); =20 -static uint8_t steelseries_headset_map_capacity(uint8_t capacity, uint8_t = min_in, uint8_t max_in) +/* Microphone volume */ +static ssize_t mic_volume_show(struct device *dev, + struct device_attribute *attr, char *buf) { - if (capacity >=3D max_in) - return 100; - if (capacity <=3D min_in) - return 0; - return (capacity - min_in) * 100 / (max_in - min_in); + return sysfs_emit(buf, "Write-only (0-128)\n"); +} + +static ssize_t mic_volume_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct hid_device *hdev =3D to_hid_device(dev); + u16 product =3D hdev->product; + unsigned int value; + u8 data[64] =3D { 0 }; + u8 mapped; + int ret; + + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + if (value > 128) + return -EINVAL; + + /* Map 0-128 to device-specific range */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3) { + /* Map to 0-10 */ + if (value < 13) + mapped =3D 0x00; + else if (value < 25) + mapped =3D 0x01; + else if (value < 37) + mapped =3D 0x02; + else if (value < 49) + mapped =3D 0x03; + else if (value < 61) + mapped =3D 0x04; + else if (value < 73) + mapped =3D 0x05; + else if (value < 85) + mapped =3D 0x06; + else if (value < 97) + mapped =3D 0x07; + else if (value < 109) + mapped =3D 0x08; + else if (value < 121) + mapped =3D 0x09; + else + mapped =3D 0x0a; + + data[0] =3D 0x06; + data[1] =3D 0x37; + data[2] =3D mapped; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x06; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X) { + /* Map to 0-14 */ + mapped =3D (value * 0x0e) / 128; + data[0] =3D 0x37; + data[1] =3D mapped; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X) { + /* Map to 0-15 */ + mapped =3D value / 8; + if (mapped =3D=3D 16) + mapped =3D 15; + + data[0] =3D 0x00; + data[1] =3D 0x37; + data[2] =3D mapped; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + data[0] =3D 0x00; + data[1] =3D 0x35; + data[2] =3D 0x01; + steelseries_send_output_report(hdev, data, 64); + } + } else { + /* Nova 7: map to 0-7 */ + mapped =3D value / 16; + if (mapped =3D=3D 8) + mapped =3D 7; + + data[0] =3D 0x00; + data[1] =3D 0x37; + data[2] =3D mapped; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + memset(data, 0, sizeof(data)); + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } + + return (ret < 0) ? ret : count; +} +static DEVICE_ATTR_RW(mic_volume); + +/* Volume limiter */ +static ssize_t volume_limiter_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "Write-only (0=3Doff, 1=3Don)\n"); +} + +static ssize_t volume_limiter_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev =3D to_hid_device(dev); + u16 product =3D hdev->product; + unsigned int value; + u8 data[64] =3D { 0 }; + int ret; + + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + if (value > 1) + return -EINVAL; + + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X) { + data[0] =3D 0x00; + data[1] =3D 0x27; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + data[0] =3D 0x00; + data[1] =3D 0x35; + data[2] =3D 0x01; + steelseries_send_output_report(hdev, data, 64); + } + } else { + /* Nova 7 series */ + data[0] =3D 0x00; + data[1] =3D 0x3a; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + memset(data, 0, sizeof(data)); + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + } + + return (ret < 0) ? ret : count; } +static DEVICE_ATTR_RW(volume_limiter); =20 -static int steelseries_headset_raw_event(struct hid_device *hdev, - struct hid_report *report, u8 *read_buf, - int size) +/* Bluetooth when powered on */ +static ssize_t bluetooth_on_power_show(struct device *dev, + struct device_attribute *attr, char *buf) { + return sysfs_emit(buf, "Write-only (0=3Doff, 1=3Don)\n"); +} + +static ssize_t bluetooth_on_power_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev =3D to_hid_device(dev); + unsigned int value; + u8 data[64] =3D { 0 }; + int ret; + + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + if (value > 1) + return -EINVAL; + + data[0] =3D 0x00; + data[1] =3D 0xb2; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + if (ret >=3D 0) { + /* Send save state command as output report */ + memset(data, 0, sizeof(data)); + data[0] =3D 0x00; + data[1] =3D 0x09; + steelseries_send_output_report(hdev, data, 64); + } + + return (ret < 0) ? ret : count; +} +static DEVICE_ATTR_RW(bluetooth_on_power); + +/* Bluetooth call volume */ +static ssize_t bluetooth_call_vol_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, + "Write-only (0=3Dnothing, 1=3D-12dB, 2=3Dmute game)\n"); +} + +static ssize_t bluetooth_call_vol_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev =3D to_hid_device(dev); + unsigned int value; + u8 data[64] =3D { 0 }; + int ret; + + if (kstrtouint(buf, 10, &value)) + return -EINVAL; + if (value > 2) + return -EINVAL; + + data[0] =3D 0x00; + data[1] =3D 0xb3; + data[2] =3D value; + ret =3D steelseries_send_output_report(hdev, data, 64); + + return (ret < 0) ? ret : count; +} +static DEVICE_ATTR_RW(bluetooth_call_vol); + +/* Attribute group setup based on capabilities */ +static struct attribute *steelseries_attrs[] =3D { + &dev_attr_sidetone_level.attr, + &dev_attr_inactive_time.attr, + &dev_attr_chatmix_level.attr, + &dev_attr_mic_mute_led_brightness.attr, + &dev_attr_mic_volume.attr, + &dev_attr_volume_limiter.attr, + &dev_attr_bluetooth_on_power.attr, + &dev_attr_bluetooth_call_vol.attr, + NULL +}; + +static umode_t steelseries_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev =3D kobj_to_dev(kobj); + struct hid_device *hdev =3D to_hid_device(dev); struct steelseries_device *sd =3D hid_get_drvdata(hdev); + unsigned long caps =3D sd->info->capabilities; + + if (attr =3D=3D &dev_attr_sidetone_level.attr) + return (caps & SS_CAP_SIDETONE) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_inactive_time.attr) + return (caps & SS_CAP_INACTIVE_TIME) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_chatmix_level.attr) + return (caps & SS_CAP_CHATMIX) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_mic_mute_led_brightness.attr) + return (caps & SS_CAP_MIC_MUTE_LED) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_mic_volume.attr) + return (caps & SS_CAP_MIC_VOLUME) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_volume_limiter.attr) + return (caps & SS_CAP_VOLUME_LIMITER) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_bluetooth_on_power.attr) + return (caps & SS_CAP_BT_POWER_ON) ? attr->mode : 0; + if (attr =3D=3D &dev_attr_bluetooth_call_vol.attr) + return (caps & SS_CAP_BT_CALL_VOL) ? attr->mode : 0; + + return 0; +} + +static const struct attribute_group steelseries_attr_group =3D { + .attrs =3D steelseries_attrs, + .is_visible =3D steelseries_attr_is_visible, +}; + +static int steelseries_arctis_1_request_battery(struct hid_device *hdev) +{ + const u8 data[] =3D { 0x06, 0x12 }; + + return steelseries_send_feature_report(hdev, data, sizeof(data)); +} + +static int steelseries_arctis_7_plus_request_battery(struct hid_device *hd= ev) +{ + const u8 data[] =3D { 0x00, 0xb0 }; + + return steelseries_send_output_report(hdev, data, sizeof(data)); +} + +static int steelseries_arctis_9_request_battery(struct hid_device *hdev) +{ + const u8 data[] =3D { 0x00, 0x20 }; + + return steelseries_send_feature_report(hdev, data, sizeof(data)); +} + +static int steelseries_arctis_nova_request_battery(struct hid_device *hdev) +{ + const u8 data[] =3D { 0x00, 0xb0 }; + + return steelseries_send_output_report(hdev, data, sizeof(data)); +} + +static int steelseries_arctis_nova_3p_request_battery(struct hid_device *h= dev) +{ + const u8 data[] =3D { 0xb0 }; + + return steelseries_send_output_report(hdev, data, sizeof(data)); +} + +static int +steelseries_arctis_pro_wireless_request_battery(struct hid_device *hdev) +{ + /* Request battery - response will arrive asynchronously via raw_event */ + const u8 data[] =3D { 0x40, 0xAA }; + + return steelseries_send_output_report(hdev, data, sizeof(data)); +} + +static int steelseries_raw_event(struct hid_device *hdev, + struct hid_report *report, u8 *data, int size) +{ + struct steelseries_device *sd =3D hid_get_drvdata(hdev); + u16 product =3D hdev->product; int capacity =3D sd->battery_capacity; bool connected =3D sd->headset_connected; bool charging =3D sd->battery_charging; - unsigned long flags; + int chatmix =3D sd->chatmix_level; + unsigned long flags =3D 0; =20 - /* Not a headset */ - if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_SRWS1) + /* Skip SRW-S1 */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_SRWS1) return 0; =20 - if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1) { - hid_dbg(sd->hdev, - "Parsing raw event for Arctis 1 headset (%*ph)\n", size, read_buf); - if (size < ARCTIS_1_BATTERY_RESPONSE_LEN || - memcmp(read_buf, arctis_1_battery_request, sizeof(arctis_1_battery_r= equest))) { - if (!delayed_work_pending(&sd->battery_work)) - goto request_battery; - return 0; + /* Arctis 1 family (Arctis 1, 1X, 7P, 7X) */ + if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_1_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_X) { + if (size < 8) + goto schedule_work; + + if (data[2] =3D=3D 0x01) { + connected =3D false; + capacity =3D 100; + } else { + connected =3D true; + capacity =3D data[3]; + if (capacity > 100) + capacity =3D 100; } - if (read_buf[2] =3D=3D 0x01) { + } + + /* Arctis 7 (original and 2019) */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_GEN2) { + /* Battery response is 8 bytes for Arctis 7 */ + if (size < 8) + goto schedule_work; + + connected =3D true; + charging =3D false; + + /* Battery level is in data[2] */ + capacity =3D data[2]; + if (capacity > 100) + capacity =3D 100; + } + + /* Arctis 7+ family */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_DESTINY) { + if (size < 6) + goto schedule_work; + + /* data[1] =3D=3D 0x01 means HEADSET_OFFLINE */ + if (data[1] =3D=3D 0x01) { connected =3D false; capacity =3D 100; } else { connected =3D true; - capacity =3D read_buf[3]; + /* data[3] =3D=3D 0x01 means charging */ + charging =3D (data[3] =3D=3D 0x01); + /* data[2] contains battery level (0x00-0x04 range) */ + capacity =3D steelseries_map_battery(data[2], 0x00, 0x04); + + /* ChatMix available */ + if (size >=3D 6 && + (sd->info->capabilities & SS_CAP_CHATMIX)) { + /* data[4] is game (0-100), data[5] is chat (0-100) */ + int game =3D (data[4] * 64) / 100; + int chat =3D (data[5] * -64) / 100; + + chatmix =3D 64 - (chat + game); + } } } =20 - if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) { - hid_dbg(sd->hdev, - "Parsing raw event for Arctis 9 headset (%*ph)\n", size, read_buf); - if (size < ARCTIS_9_BATTERY_RESPONSE_LEN) { - if (!delayed_work_pending(&sd->battery_work)) - goto request_battery; - return 0; + /* Arctis 9 */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9) { + if (size < 12) + goto schedule_work; + + connected =3D true; + + charging =3D (data[4] =3D=3D 0x01); + + capacity =3D steelseries_map_battery(data[3], 0x64, 0x9A); + + /* ChatMix: data[9] is game (0-19), data[10] is chat (0-19) */ + if (size >=3D 11 && (sd->info->capabilities & SS_CAP_CHATMIX)) { + int game =3D (data[9] * 64) / 19; + int chat =3D (data[10] * -64) / 19; + + chatmix =3D 64 - (chat + game); } + } =20 - if (read_buf[0] =3D=3D 0xaa && read_buf[1] =3D=3D 0x01) { + /* Arctis Pro Wireless */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_PRO) { + if (size >=3D 2 && (data[0] =3D=3D 0x02 || data[0] =3D=3D 0x04)) { + /* This is a connection status response */ + /* HEADSET_OFFLINE */ + if (data[0] =3D=3D 0x02) { + connected =3D false; + capacity =3D 100; + charging =3D false; + } + /* HEADSET_ONLINE (0x04) */ + else { + connected =3D true; + charging =3D false; + } + } else if (size >=3D 1 && sd->headset_connected) { + /* This is a battery level response (only valid if headset connected) */ + /* Battery range is 0x00-0x04 */ + capacity =3D steelseries_map_battery(data[0], 0x00, 0x04); + } + } + + /* Arctis Nova 3 */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3) { + /* No battery monitoring for wired headset */ + goto schedule_work; + } + + /* Arctis Nova 3P/3X Wireless */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X) { + if (size < 4) + goto schedule_work; + + /* data[1] =3D=3D 0x02 means HEADSET_OFFLINE */ + if (data[1] =3D=3D 0x02) { + connected =3D false; + capacity =3D 100; + } else { connected =3D true; - charging =3D read_buf[4] =3D=3D 0x01; + charging =3D false; + /* data[3] contains battery level (0x00-0x64 range, 0-100) */ + capacity =3D steelseries_map_battery(data[3], 0x00, 0x64); + } + } + + /* Arctis Nova 5/5X */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X) { + if (size < 16) + goto schedule_work; + + /* data[1] =3D=3D 0x02 means HEADSET_OFFLINE */ + if (data[1] =3D=3D 0x02) { + connected =3D false; + capacity =3D 100; + } else { + connected =3D true; + /* data[4] =3D=3D 0x01 means charging */ + charging =3D (data[4] =3D=3D 0x01); + /* data[3] contains battery level (0-100) */ + capacity =3D data[3]; + if (capacity > 100) + capacity =3D 100; + + /* ChatMix available */ + if (size >=3D 7 && + (sd->info->capabilities & SS_CAP_CHATMIX)) { + /* data[5] is game (0-100), data[6] is chat (0-100) */ + int game =3D (data[5] * 64) / 100; + int chat =3D (data[6] * -64) / 100; + + chatmix =3D 64 - (chat + game); + } + } + } =20 - /* - * Found no official documentation about min and max. - * Values defined by testing. - */ - capacity =3D steelseries_headset_map_capacity(read_buf[3], 0x68, 0x9d); + /* Arctis Nova 7 family */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_P || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X_REV2 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_DIABLO || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_WOW || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_GEN2 || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X_GEN2) { + if (size < 8) + goto schedule_work; + + /* data[3] =3D=3D 0x00 means HEADSET_OFFLINE */ + if (data[3] =3D=3D 0x00) { + connected =3D false; + capacity =3D 100; } else { - /* - * Device is off and sends the last known status read_buf[1] =3D=3D 0x0= 3 or - * there is no known status of the device read_buf[0] =3D=3D 0x55 - */ + connected =3D true; + /* data[3] =3D=3D 0x01 means charging */ + charging =3D (data[3] =3D=3D 0x01); + /* data[2] contains battery level (0x00-0x04 range) */ + capacity =3D steelseries_map_battery(data[2], 0x00, 0x04); + + /* ChatMix available */ + if (size >=3D 6 && + (sd->info->capabilities & SS_CAP_CHATMIX)) { + /* data[4] is game (0-100), data[5] is chat (0-100) */ + int game =3D (data[4] * 64) / 100; + int chat =3D (data[5] * -64) / 100; + + chatmix =3D 64 - (chat + game); + } + } + } + + /* Arctis Nova Pro Wireless */ + else if (product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO || + product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO_X) { + if (size < 16) + goto schedule_work; + + /* data[15] contains headset status */ + if (data[15] =3D=3D 0x01) { /* HEADSET_OFFLINE */ connected =3D false; + capacity =3D 100; + } else if (data[15] =3D=3D 0x02) { /* HEADSET_CABLE_CHARGING */ + connected =3D true; + charging =3D true; + /* data[6] contains battery level (0x00-0x08 range) */ + capacity =3D steelseries_map_battery(data[6], 0x00, 0x08); + } else if (data[15] =3D=3D 0x08) { /* HEADSET_ONLINE */ + connected =3D true; charging =3D false; + /* data[6] contains battery level (0x00-0x08 range) */ + capacity =3D steelseries_map_battery(data[6], 0x00, 0x08); + } else { + /* Unknown status */ + goto schedule_work; } } =20 + /* Update state if changed */ + spin_lock_irqsave(&sd->lock, flags); + if (connected !=3D sd->headset_connected) { - hid_dbg(sd->hdev, + hid_dbg(hdev, "Connected status changed from %sconnected to %sconnected\n", sd->headset_connected ? "" : "not ", connected ? "" : "not "); sd->headset_connected =3D connected; + spin_unlock_irqrestore(&sd->lock, flags); steelseries_headset_set_wireless_status(hdev, connected); + spin_lock_irqsave(&sd->lock, flags); } =20 if (capacity !=3D sd->battery_capacity) { - hid_dbg(sd->hdev, - "Battery capacity changed from %d%% to %d%%\n", + hid_dbg(hdev, "Battery capacity changed from %d%% to %d%%\n", sd->battery_capacity, capacity); sd->battery_capacity =3D capacity; + spin_unlock_irqrestore(&sd->lock, flags); power_supply_changed(sd->battery); + spin_lock_irqsave(&sd->lock, flags); } =20 if (charging !=3D sd->battery_charging) { - hid_dbg(sd->hdev, + hid_dbg(hdev, "Battery charging status changed from %scharging to %scharging\n", sd->battery_charging ? "" : "not ", charging ? "" : "not "); sd->battery_charging =3D charging; + spin_unlock_irqrestore(&sd->lock, flags); power_supply_changed(sd->battery); + spin_lock_irqsave(&sd->lock, flags); } =20 -request_battery: - spin_lock_irqsave(&sd->lock, flags); + if (chatmix !=3D sd->chatmix_level) + sd->chatmix_level =3D chatmix; + +schedule_work: if (!sd->removed) - schedule_delayed_work(&sd->battery_work, - msecs_to_jiffies(STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS)); + schedule_delayed_work( + &sd->battery_work, + msecs_to_jiffies( + STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS)); spin_unlock_irqrestore(&sd->lock, flags); =20 return 0; } =20 -static const struct hid_device_id steelseries_devices[] =3D { - { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRW= S1), - .driver_data =3D STEELSERIES_SRWS1 }, +static bool steelseries_is_vendor_usage_page(struct hid_device *hdev, + u8 usage_page) +{ + return hdev->rdesc[0] =3D=3D 0x06 && hdev->rdesc[1] =3D=3D usage_page && + hdev->rdesc[2] =3D=3D 0xff; +} + +static int steelseries_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + struct steelseries_device_info *info =3D + (struct steelseries_device_info *)id->driver_data; + struct steelseries_device *sd; + struct usb_interface *intf; + u8 interface_num; + int ret; + + /* Legacy SRW-S1 handling */ + if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_SRWS1) { +#if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ + (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) + return steelseries_srws1_probe(hdev, id); +#else + return -ENODEV; +#endif + } + + /* Get interface number for binding check */ + if (hid_is_usb(hdev)) { + intf =3D to_usb_interface(hdev->dev.parent); + interface_num =3D intf->cur_altsetting->desc.bInterfaceNumber; + } else { + /* Non-USB devices not supported for modern Arctis */ + return -ENODEV; + } + + /* Interface binding logic */ + if (info->interface_binding_mode =3D=3D 0) { + /* Mode 0: First enumerated (interface 0) */ + if (interface_num !=3D 0) + return -ENODEV; + } else { + /* Mode 1: Check bitmask */ + if (!(info->valid_interfaces & BIT(interface_num))) + return -ENODEV; + } + + sd =3D devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); + if (!sd) + return -ENOMEM; + + sd->hdev =3D hdev; + sd->info =3D info; + hid_set_drvdata(hdev, sd); + + ret =3D hid_parse(hdev); + if (ret) + return ret; + + /* Arctis 9 requires vendor usage page check */ + if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_ARCTIS_9 && + !steelseries_is_vendor_usage_page(hdev, 0xc0)) + return -ENODEV; + + spin_lock_init(&sd->lock); + + ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT); + if (ret) + return ret; + + ret =3D hid_hw_open(hdev); + if (ret) + goto err_stop; + + /* Register battery if supported */ + if (info->capabilities & SS_CAP_BATTERY) { + ret =3D steelseries_battery_register(sd); + if (ret < 0) + hid_warn(hdev, "Failed to register battery: %d\n", ret); + } + + /* Create sysfs attributes */ + ret =3D sysfs_create_group(&hdev->dev.kobj, &steelseries_attr_group); + if (ret) + hid_warn(hdev, "Failed to create sysfs attributes: %d\n", ret); + + hid_info(hdev, "SteelSeries %s initialized\n", info->name); =20 - { /* SteelSeries Arctis 1 Wireless for XBox */ - HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_ARC= TIS_1), - .driver_data =3D STEELSERIES_ARCTIS_1 }, + return 0; =20 - { /* SteelSeries Arctis 9 Wireless for XBox */ - HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_ARC= TIS_9), - .driver_data =3D STEELSERIES_ARCTIS_9 }, +err_stop: + hid_hw_stop(hdev); + return ret; +} =20 - { } +static void steelseries_remove(struct hid_device *hdev) +{ + struct steelseries_device *sd; + unsigned long flags; + + /* Legacy SRW-S1 */ + if (hdev->product =3D=3D USB_DEVICE_ID_STEELSERIES_SRWS1) { +#if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ + (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) + hid_hw_stop(hdev); +#endif + return; + } + + sd =3D hid_get_drvdata(hdev); + + sysfs_remove_group(&hdev->dev.kobj, &steelseries_attr_group); + + spin_lock_irqsave(&sd->lock, flags); + sd->removed =3D true; + spin_unlock_irqrestore(&sd->lock, flags); + + cancel_delayed_work_sync(&sd->battery_work); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +static const struct hid_device_id steelseries_devices[] =3D { + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_SRWS1), + .driver_data =3D STEELSERIES_SRWS1 }, + + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_1), + .driver_data =3D (unsigned long)&arctis_1_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_1_X), + .driver_data =3D (unsigned long)&arctis_1_x_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7), + .driver_data =3D (unsigned long)&arctis_7_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_P), + .driver_data =3D (unsigned long)&arctis_7_p_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_X), + .driver_data =3D (unsigned long)&arctis_7_x_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_GEN2), + .driver_data =3D (unsigned long)&arctis_7_gen2_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS), + .driver_data =3D (unsigned long)&arctis_7_plus_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_P), + .driver_data =3D (unsigned long)&arctis_7_plus_p_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_X), + .driver_data =3D (unsigned long)&arctis_7_plus_x_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_7_PLUS_DESTINY), + .driver_data =3D (unsigned long)&arctis_7_plus_destiny_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_9), + .driver_data =3D (unsigned long)&arctis_9_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_PRO), + .driver_data =3D (unsigned long)&arctis_pro_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3), + .driver_data =3D (unsigned long)&arctis_nova_3_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_P), + .driver_data =3D (unsigned long)&arctis_nova_3_p_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_3_X), + .driver_data =3D (unsigned long)&arctis_nova_3_x_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5), + .driver_data =3D (unsigned long)&arctis_nova_5_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_5_X), + .driver_data =3D (unsigned long)&arctis_nova_5_x_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7), + .driver_data =3D (unsigned long)&arctis_nova_7_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X), + .driver_data =3D (unsigned long)&arctis_nova_7_x_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_P), + .driver_data =3D (unsigned long)&arctis_nova_7_p_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X_REV2), + .driver_data =3D (unsigned long)&arctis_nova_7_x_rev2_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_DIABLO), + .driver_data =3D (unsigned long)&arctis_nova_7_diablo_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_WOW), + .driver_data =3D (unsigned long)&arctis_nova_7_wow_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_GEN2), + .driver_data =3D (unsigned long)&arctis_nova_7_gen2_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_7_X_GEN2), + .driver_data =3D (unsigned long)&arctis_nova_7_x_gen2_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO), + .driver_data =3D (unsigned long)&arctis_nova_pro_info }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, + USB_DEVICE_ID_STEELSERIES_ARCTIS_NOVA_PRO_X), + .driver_data =3D (unsigned long)&arctis_nova_pro_x_info }, + {} }; MODULE_DEVICE_TABLE(hid, steelseries_devices); =20 @@ -742,12 +2160,13 @@ static struct hid_driver steelseries_driver =3D { .probe =3D steelseries_probe, .remove =3D steelseries_remove, .report_fixup =3D steelseries_srws1_report_fixup, - .raw_event =3D steelseries_headset_raw_event, + .raw_event =3D steelseries_raw_event, }; - module_hid_driver(steelseries_driver); -MODULE_DESCRIPTION("HID driver for Steelseries devices"); + +MODULE_DESCRIPTION("HID driver for SteelSeries devices"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Bastien Nocera "); MODULE_AUTHOR("Simon Wood "); MODULE_AUTHOR("Christian Mayer "); +MODULE_AUTHOR("Sriman Achanta "); --=20 2.52.0