Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  HID driver for Steelseries SRW-S1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) 2013 Simon Wood
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)     (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define SRWS1_NUMBER_LEDS 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct steelseries_srws1_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	__u16 led_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	/* the last element is used for setting all leds simultaneously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct led_classdev *led[SRWS1_NUMBER_LEDS + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* Fixed report descriptor for Steelseries SRW-S1 wheel controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * The original descriptor hides the sensitivity and assists dials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * a custom vendor usage page. This inserts a patch to make them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * appear in the 'Generic Desktop' usage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static __u8 steelseries_srws1_rdesc_fixed[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 0x05, 0x01,         /*  Usage Page (Desktop)                */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 0x09, 0x08,         /*  Usage (MultiAxis), Changed          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 0xA1, 0x01,         /*  Collection (Application),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 0xA1, 0x02,         /*      Collection (Logical),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 0x95, 0x01,         /*          Report Count (1),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 0x05, 0x01,         /* Changed  Usage Page (Desktop),       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 0x09, 0x30,         /* Changed  Usage (X),                  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 0x16, 0xF8, 0xF8,   /*          Logical Minimum (-1800),    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 0x26, 0x08, 0x07,   /*          Logical Maximum (1800),     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 0x65, 0x14,         /*          Unit (Degrees),             */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 0x55, 0x0F,         /*          Unit Exponent (15),         */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 0x75, 0x10,         /*          Report Size (16),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 0x09, 0x31,         /* Changed  Usage (Y),                  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 0x15, 0x00,         /*          Logical Minimum (0),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 0x75, 0x0C,         /*          Report Size (12),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 0x09, 0x32,         /* Changed  Usage (Z),                  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 0x15, 0x00,         /*          Logical Minimum (0),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 0x75, 0x0C,         /*          Report Size (12),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 0x05, 0x01,         /*          Usage Page (Desktop),       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 0x09, 0x39,         /*          Usage (Hat Switch),         */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 0x25, 0x07,         /*          Logical Maximum (7),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 0x35, 0x00,         /*          Physical Minimum (0),       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 0x46, 0x3B, 0x01,   /*          Physical Maximum (315),     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 0x65, 0x14,         /*          Unit (Degrees),             */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 0x75, 0x04,         /*          Report Size (4),            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 0x95, 0x01,         /*          Report Count (1),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 0x25, 0x01,         /*          Logical Maximum (1),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 0x45, 0x01,         /*          Physical Maximum (1),       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 0x65, 0x00,         /*          Unit,                       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 0x75, 0x01,         /*          Report Size (1),            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 0x95, 0x03,         /*          Report Count (3),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 0x81, 0x01,         /*          Input (Constant),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 0x05, 0x09,         /*          Usage Page (Button),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 0x19, 0x01,         /*          Usage Minimum (01h),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 0x29, 0x11,         /*          Usage Maximum (11h),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 0x95, 0x11,         /*          Report Count (17),          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)                     /*   ---- Dial patch starts here ----   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 0x05, 0x01,         /*          Usage Page (Desktop),       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 0x09, 0x33,         /*          Usage (RX),                 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 0x75, 0x04,         /*          Report Size (4),            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 0x95, 0x02,         /*          Report Count (2),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 0x15, 0x00,         /*          Logical Minimum (0),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 0x25, 0x0b,         /*          Logical Maximum (b),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 0x09, 0x35,         /*          Usage (RZ),                 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 0x75, 0x04,         /*          Report Size (4),            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 0x95, 0x01,         /*          Report Count (1),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 0x25, 0x03,         /*          Logical Maximum (3),        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)                     /*    ---- Dial patch ends here ----    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 0x06, 0x00, 0xFF,   /*          Usage Page (FF00h),         */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 0x09, 0x01,         /*          Usage (01h),                */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 0x75, 0x04,         /* Changed  Report Size (4),            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 0x95, 0x0D,         /* Changed  Report Count (13),          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 0x81, 0x02,         /*          Input (Variable),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 0xC0,               /*      End Collection,                 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 0xA1, 0x02,         /*      Collection (Logical),           */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 0x09, 0x02,         /*          Usage (02h),                */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 0x75, 0x08,         /*          Report Size (8),            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 0x95, 0x10,         /*          Report Count (16),          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 0x91, 0x02,         /*          Output (Variable),          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 0xC0,               /*      End Collection,                 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 0xC0                /*  End Collection                      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)     (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static void steelseries_srws1_set_leds(struct hid_device *hdev, __u16 leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct list_head *report_list = &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	__s32 *value = report->field[0]->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	value[0] = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	value[1] = leds & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	value[2] = leds >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	value[3] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	value[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	value[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	value[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	value[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	value[8] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	value[9] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	value[10] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	value[11] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	value[12] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	value[13] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	value[14] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	value[15] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	/* Note: LED change does not show on device until the device is read/polled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void steelseries_srws1_led_all_set_brightness(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct device *dev = led_cdev->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct hid_device *hid = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct steelseries_srws1_data *drv_data = hid_get_drvdata(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		hid_err(hid, "Device data not found.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (value == LED_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		drv_data->led_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		drv_data->led_state = (1 << (SRWS1_NUMBER_LEDS + 1)) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	steelseries_srws1_set_leds(hid, drv_data->led_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static enum led_brightness steelseries_srws1_led_all_get_brightness(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct device *dev = led_cdev->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct hid_device *hid = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct steelseries_srws1_data *drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	drv_data = hid_get_drvdata(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		hid_err(hid, "Device data not found.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return (drv_data->led_state >> SRWS1_NUMBER_LEDS) ? LED_FULL : LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static void steelseries_srws1_led_set_brightness(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct device *dev = led_cdev->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct hid_device *hid = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct steelseries_srws1_data *drv_data = hid_get_drvdata(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	int i, state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		hid_err(hid, "Device data not found.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	for (i = 0; i < SRWS1_NUMBER_LEDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (led_cdev != drv_data->led[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		state = (drv_data->led_state >> i) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (value == LED_OFF && state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			drv_data->led_state &= ~(1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			steelseries_srws1_set_leds(hid, drv_data->led_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		} else if (value != LED_OFF && !state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			drv_data->led_state |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			steelseries_srws1_set_leds(hid, drv_data->led_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static enum led_brightness steelseries_srws1_led_get_brightness(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct device *dev = led_cdev->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct hid_device *hid = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct steelseries_srws1_data *drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	int i, value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	drv_data = hid_get_drvdata(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		hid_err(hid, "Device data not found.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	for (i = 0; i < SRWS1_NUMBER_LEDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (led_cdev == drv_data->led[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			value = (drv_data->led_state >> i) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return value ? LED_FULL : LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int steelseries_srws1_probe(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct led_classdev *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	size_t name_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct steelseries_srws1_data *drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (drv_data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		hid_err(hdev, "can't alloc SRW-S1 memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	hid_set_drvdata(hdev, drv_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* register led subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	drv_data->led_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	for (i = 0; i < SRWS1_NUMBER_LEDS + 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		drv_data->led[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	steelseries_srws1_set_leds(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	name_sz = strlen(hdev->uniq) + 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* 'ALL', for setting all LEDs simultaneously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!led) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		hid_err(hdev, "can't allocate memory for LED ALL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		goto err_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	name = (void *)(&led[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	snprintf(name, name_sz, "SRWS1::%s::RPMALL", hdev->uniq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	led->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	led->brightness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	led->max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	led->brightness_get = steelseries_srws1_led_all_get_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	led->brightness_set = steelseries_srws1_led_all_set_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	drv_data->led[SRWS1_NUMBER_LEDS] = led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	ret = led_classdev_register(&hdev->dev, led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		goto err_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* Each individual LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	for (i = 0; i < SRWS1_NUMBER_LEDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (!led) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			hid_err(hdev, "can't allocate memory for LED %d\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			goto err_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		name = (void *)(&led[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		snprintf(name, name_sz, "SRWS1::%s::RPM%d", hdev->uniq, i+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		led->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		led->brightness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		led->max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		led->brightness_get = steelseries_srws1_led_get_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		led->brightness_set = steelseries_srws1_led_set_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		drv_data->led[i] = led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		ret = led_classdev_register(&hdev->dev, led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			hid_err(hdev, "failed to register LED %d. Aborting.\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) err_led:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			/* Deregister all LEDs (if any) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			for (i = 0; i < SRWS1_NUMBER_LEDS + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 				led = drv_data->led[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				drv_data->led[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 				if (!led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				led_classdev_unregister(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				kfree(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			goto out;	/* but let the driver continue without LEDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	kfree(drv_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static void steelseries_srws1_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct led_classdev *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	struct steelseries_srws1_data *drv_data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		/* Deregister LEDs (if any) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		for (i = 0; i < SRWS1_NUMBER_LEDS + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			led = drv_data->led[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			drv_data->led[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			if (!led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			led_classdev_unregister(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			kfree(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	kfree(drv_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static __u8 *steelseries_srws1_report_fixup(struct hid_device *hdev, __u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (*rsize >= 115 && rdesc[11] == 0x02 && rdesc[13] == 0xc8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			&& rdesc[29] == 0xbb && rdesc[40] == 0xc5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		hid_info(hdev, "Fixing up Steelseries SRW-S1 report descriptor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		rdesc = steelseries_srws1_rdesc_fixed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		*rsize = sizeof(steelseries_srws1_rdesc_fixed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static const struct hid_device_id steelseries_srws1_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	{ HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) MODULE_DEVICE_TABLE(hid, steelseries_srws1_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static struct hid_driver steelseries_srws1_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.name = "steelseries_srws1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	.id_table = steelseries_srws1_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)     (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.probe = steelseries_srws1_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	.remove = steelseries_srws1_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	.report_fixup = steelseries_srws1_report_fixup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) module_hid_driver(steelseries_srws1_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) MODULE_LICENSE("GPL");