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+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  HID driver for gaming keys on Logitech gaming keyboards (such as the G15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) 2019 Hans de Goede <hdegoede@redhat.com>
^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) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define LG_G15_TRANSFER_BUF_SIZE	20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define LG_G15_FEATURE_REPORT		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define LG_G510_FEATURE_M_KEYS_LEDS	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define LG_G510_FEATURE_BACKLIGHT_RGB	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define LG_G510_FEATURE_POWER_ON_RGB	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) enum lg_g15_model {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	LG_G15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	LG_G15_V2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	LG_G510,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	LG_G510_USB_AUDIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) enum lg_g15_led_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	LG_G15_KBD_BRIGHTNESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	LG_G15_LCD_BRIGHTNESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	LG_G15_BRIGHTNESS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	LG_G15_MACRO_PRESET1 = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	LG_G15_MACRO_PRESET2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	LG_G15_MACRO_PRESET3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	LG_G15_MACRO_RECORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	LG_G15_LED_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) struct lg_g15_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct led_classdev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	enum led_brightness brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	enum lg_g15_led_type led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u8 red, green, blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) struct lg_g15_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* Must be first for proper dma alignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u8 transfer_buf[LG_G15_TRANSFER_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* Protects the transfer_buf and led brightness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct hid_device *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	enum lg_g15_model model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct lg_g15_led leds[LG_G15_LED_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	bool game_mode_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /******** G15 and G15 v2 LED functions ********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int lg_g15_update_led_brightness(struct lg_g15_data *g15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	ret = hid_hw_raw_request(g15->hdev, LG_G15_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 				 g15->transfer_buf, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (ret != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		hid_err(g15->hdev, "Error getting LED brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return (ret < 0) ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	g15->leds[LG_G15_KBD_BRIGHTNESS].brightness = g15->transfer_buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	g15->leds[LG_G15_LCD_BRIGHTNESS].brightness = g15->transfer_buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	g15->leds[LG_G15_MACRO_PRESET1].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		!(g15->transfer_buf[3] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	g15->leds[LG_G15_MACRO_PRESET2].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		!(g15->transfer_buf[3] & 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	g15->leds[LG_G15_MACRO_PRESET3].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		!(g15->transfer_buf[3] & 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	g15->leds[LG_G15_MACRO_RECORD].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		!(g15->transfer_buf[3] & 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static enum led_brightness lg_g15_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	enum led_brightness brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	lg_g15_update_led_brightness(g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	brightness = g15->leds[g15_led->led].brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int lg_g15_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			  enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	u8 val, mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* Ignore LED off on unregister / keyboard unplug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (led_cdev->flags & LED_UNREGISTERING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	g15->transfer_buf[0] = LG_G15_FEATURE_REPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	g15->transfer_buf[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (g15_led->led < LG_G15_BRIGHTNESS_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		g15->transfer_buf[1] = g15_led->led + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		g15->transfer_buf[2] = brightness << (g15_led->led * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		for (i = LG_G15_MACRO_PRESET1; i < LG_G15_LED_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			if (i == g15_led->led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				val = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				val = g15->leds[i].brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				mask |= 1 << (i - LG_G15_MACRO_PRESET1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		g15->transfer_buf[1] = 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		g15->transfer_buf[2] = ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	ret = hid_hw_raw_request(g15->hdev, LG_G15_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				 g15->transfer_buf, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (ret == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		/* Success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		g15_led->brightness = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		hid_err(g15->hdev, "Error setting LED brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		ret = (ret < 0) ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void lg_g15_leds_changed_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct lg_g15_data *g15 = container_of(work, struct lg_g15_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	enum led_brightness old_brightness[LG_G15_BRIGHTNESS_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	enum led_brightness brightness[LG_G15_BRIGHTNESS_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	for (i = 0; i < LG_G15_BRIGHTNESS_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		old_brightness[i] = g15->leds[i].brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ret = lg_g15_update_led_brightness(g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	for (i = 0; i < LG_G15_BRIGHTNESS_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		brightness[i] = g15->leds[i].brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	for (i = 0; i < LG_G15_BRIGHTNESS_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		if (brightness[i] == old_brightness[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		led_classdev_notify_brightness_hw_changed(&g15->leds[i].cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 							  brightness[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /******** G510 LED functions ********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int lg_g510_get_initial_led_brightness(struct lg_g15_data *g15, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int ret, high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	ret = hid_hw_raw_request(g15->hdev, LG_G510_FEATURE_BACKLIGHT_RGB + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				 g15->transfer_buf, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (ret != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		hid_err(g15->hdev, "Error getting LED brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return (ret < 0) ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	high = max3(g15->transfer_buf[1], g15->transfer_buf[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		    g15->transfer_buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (high) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		g15->leds[i].red =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			DIV_ROUND_CLOSEST(g15->transfer_buf[1] * 255, high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		g15->leds[i].green =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			DIV_ROUND_CLOSEST(g15->transfer_buf[2] * 255, high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		g15->leds[i].blue =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			DIV_ROUND_CLOSEST(g15->transfer_buf[3] * 255, high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		g15->leds[i].brightness = high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		g15->leds[i].red   = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		g15->leds[i].green = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		g15->leds[i].blue  = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		g15->leds[i].brightness = 0;
^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 0;
^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) /* Must be called with g15->mutex locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int lg_g510_kbd_led_write(struct lg_g15_data *g15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				 struct lg_g15_led *g15_led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				 enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	g15->transfer_buf[0] = 5 + g15_led->led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	g15->transfer_buf[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		DIV_ROUND_CLOSEST(g15_led->red * brightness, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	g15->transfer_buf[2] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		DIV_ROUND_CLOSEST(g15_led->green * brightness, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	g15->transfer_buf[3] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		DIV_ROUND_CLOSEST(g15_led->blue * brightness, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	ret = hid_hw_raw_request(g15->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				 LG_G510_FEATURE_BACKLIGHT_RGB + g15_led->led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				 g15->transfer_buf, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (ret == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		/* Success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		g15_led->brightness = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		hid_err(g15->hdev, "Error setting LED brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		ret = (ret < 0) ? ret : -EIO;
^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) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int lg_g510_kbd_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			       enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	/* Ignore LED off on unregister / keyboard unplug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (led_cdev->flags & LED_UNREGISTERING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	ret = lg_g510_kbd_led_write(g15, g15_led, brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return ret;
^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) static enum led_brightness lg_g510_kbd_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return g15_led->brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static ssize_t color_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (count < 7 || (count == 8 && buf[7] != '\n') || count > 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (buf[0] != '#')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	ret = kstrtoul(buf + 1, 16, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	g15_led->red   = (value & 0xff0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	g15_led->green = (value & 0x00ff00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	g15_led->blue  = (value & 0x0000ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	ret = lg_g510_kbd_led_write(g15, g15_led, g15_led->brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return (ret < 0) ? ret : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static ssize_t color_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	ret = sprintf(buf, "#%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		      g15_led->red, g15_led->green, g15_led->blue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static DEVICE_ATTR_RW(color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static struct attribute *lg_g510_kbd_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	&dev_attr_color.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static const struct attribute_group lg_g510_kbd_led_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	.attrs = lg_g510_kbd_led_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static const struct attribute_group *lg_g510_kbd_led_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	&lg_g510_kbd_led_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static void lg_g510_leds_sync_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct lg_g15_data *g15 = container_of(work, struct lg_g15_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	lg_g510_kbd_led_write(g15, &g15->leds[LG_G15_KBD_BRIGHTNESS],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			      g15->leds[LG_G15_KBD_BRIGHTNESS].brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int lg_g510_update_mkey_led_brightness(struct lg_g15_data *g15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	ret = hid_hw_raw_request(g15->hdev, LG_G510_FEATURE_M_KEYS_LEDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				 g15->transfer_buf, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (ret != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		hid_err(g15->hdev, "Error getting LED brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		ret = (ret < 0) ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	g15->leds[LG_G15_MACRO_PRESET1].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		!!(g15->transfer_buf[1] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	g15->leds[LG_G15_MACRO_PRESET2].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		!!(g15->transfer_buf[1] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	g15->leds[LG_G15_MACRO_PRESET3].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		!!(g15->transfer_buf[1] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	g15->leds[LG_G15_MACRO_RECORD].brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		!!(g15->transfer_buf[1] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static enum led_brightness lg_g510_mkey_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	enum led_brightness brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	lg_g510_update_mkey_led_brightness(g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	brightness = g15->leds[g15_led->led].brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static int lg_g510_mkey_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct lg_g15_led *g15_led =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		container_of(led_cdev, struct lg_g15_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	u8 val, mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	/* Ignore LED off on unregister / keyboard unplug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (led_cdev->flags & LED_UNREGISTERING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	mutex_lock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	for (i = LG_G15_MACRO_PRESET1; i < LG_G15_LED_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		if (i == g15_led->led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			val = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			val = g15->leds[i].brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			mask |= 0x80 >> (i - LG_G15_MACRO_PRESET1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	g15->transfer_buf[0] = LG_G510_FEATURE_M_KEYS_LEDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	g15->transfer_buf[1] = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	ret = hid_hw_raw_request(g15->hdev, LG_G510_FEATURE_M_KEYS_LEDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 				 g15->transfer_buf, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	if (ret == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		/* Success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		g15_led->brightness = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		hid_err(g15->hdev, "Error setting LED brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		ret = (ret < 0) ? ret : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	mutex_unlock(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /******** Generic LED functions ********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static int lg_g15_get_initial_led_brightness(struct lg_g15_data *g15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	switch (g15->model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	case LG_G15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	case LG_G15_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		return lg_g15_update_led_brightness(g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	case LG_G510:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	case LG_G510_USB_AUDIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		ret = lg_g510_get_initial_led_brightness(g15, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		ret = lg_g510_get_initial_led_brightness(g15, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		return lg_g510_update_mkey_led_brightness(g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	return -EINVAL; /* Never reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /******** Input functions ********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* On the G15 Mark I Logitech has been quite creative with which bit is what */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static int lg_g15_event(struct lg_g15_data *g15, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	int i, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* G1 - G6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	for (i = 0; i < 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		val = data[i + 1] & (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		input_report_key(g15->input, KEY_MACRO1 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	/* G7 - G12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	for (i = 0; i < 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		val = data[i + 2] & (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		input_report_key(g15->input, KEY_MACRO7 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	/* G13 - G17 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	for (i = 0; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		val = data[i + 1] & (4 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		input_report_key(g15->input, KEY_MACRO13 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	/* G18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	input_report_key(g15->input, KEY_MACRO18, data[8] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/* M1 - M3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		val = data[i + 6] & (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		input_report_key(g15->input, KEY_MACRO_PRESET1 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	/* MR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	input_report_key(g15->input, KEY_MACRO_RECORD_START, data[7] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	/* Most left (round) button below the LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	input_report_key(g15->input, KEY_KBD_LCD_MENU1, data[8] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/* 4 other buttons below the LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		val = data[i + 2] & 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		input_report_key(g15->input, KEY_KBD_LCD_MENU2 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	/* Backlight cycle button pressed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (data[1] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		schedule_work(&g15->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	input_sync(g15->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static int lg_g15_v2_event(struct lg_g15_data *g15, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	int i, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	/* G1 - G6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	for (i = 0; i < 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		val = data[1] & (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		input_report_key(g15->input, KEY_MACRO1 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	/* M1 - M3 + MR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	input_report_key(g15->input, KEY_MACRO_PRESET1, data[1] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	input_report_key(g15->input, KEY_MACRO_PRESET2, data[1] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	input_report_key(g15->input, KEY_MACRO_PRESET3, data[2] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	input_report_key(g15->input, KEY_MACRO_RECORD_START, data[2] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	/* Round button to the left of the LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	input_report_key(g15->input, KEY_KBD_LCD_MENU1, data[2] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	/* 4 buttons below the LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		val = data[2] & (2 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		input_report_key(g15->input, KEY_KBD_LCD_MENU2 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	/* Backlight cycle button pressed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (data[2] & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		schedule_work(&g15->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	input_sync(g15->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static int lg_g510_event(struct lg_g15_data *g15, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	bool game_mode_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	int i, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	/* G1 - G18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	for (i = 0; i < 18; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		val = data[i / 8 + 1] & (1 << (i % 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		input_report_key(g15->input, KEY_MACRO1 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	/* Game mode on/off slider */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	game_mode_enabled = data[3] & 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	if (game_mode_enabled != g15->game_mode_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		if (game_mode_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			hid_info(g15->hdev, "Game Mode enabled, Windows (super) key is disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			hid_info(g15->hdev, "Game Mode disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		g15->game_mode_enabled = game_mode_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	/* M1 - M3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		val = data[3] & (0x10 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		input_report_key(g15->input, KEY_MACRO_PRESET1 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	/* MR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	input_report_key(g15->input, KEY_MACRO_RECORD_START, data[3] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	/* LCD menu keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	for (i = 0; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		val = data[4] & (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		input_report_key(g15->input, KEY_KBD_LCD_MENU1 + i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	/* Headphone Mute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	input_report_key(g15->input, KEY_MUTE, data[4] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	/* Microphone Mute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	input_report_key(g15->input, KEY_F20, data[4] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	input_sync(g15->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int lg_g510_leds_event(struct lg_g15_data *g15, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	bool backlight_disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	 * The G510 ignores backlight updates when the backlight is turned off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	 * through the light toggle button on the keyboard, to work around this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	 * we queue a workitem to sync values when the backlight is turned on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	backlight_disabled = data[1] & 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	if (!backlight_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		schedule_work(&g15->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static int lg_g15_raw_event(struct hid_device *hdev, struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 			    u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	struct lg_g15_data *g15 = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (!g15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	switch (g15->model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	case LG_G15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		if (data[0] == 0x02 && size == 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 			return lg_g15_event(g15, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	case LG_G15_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		if (data[0] == 0x02 && size == 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 			return lg_g15_v2_event(g15, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	case LG_G510:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	case LG_G510_USB_AUDIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		if (data[0] == 0x03 && size == 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 			return lg_g510_event(g15, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		if (data[0] == 0x04 && size == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 			return lg_g510_leds_event(g15, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static int lg_g15_input_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	struct hid_device *hdev = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	return hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static void lg_g15_input_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	struct hid_device *hdev = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static int lg_g15_register_led(struct lg_g15_data *g15, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	const char * const led_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		"g15::kbd_backlight",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		"g15::lcd_backlight",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		"g15::macro_preset1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		"g15::macro_preset2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		"g15::macro_preset3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		"g15::macro_record",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	g15->leds[i].led = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	g15->leds[i].cdev.name = led_names[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	switch (g15->model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	case LG_G15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	case LG_G15_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		g15->leds[i].cdev.brightness_set_blocking = lg_g15_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		g15->leds[i].cdev.brightness_get = lg_g15_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		if (i < LG_G15_BRIGHTNESS_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 			g15->leds[i].cdev.flags = LED_BRIGHT_HW_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 			g15->leds[i].cdev.max_brightness = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			g15->leds[i].cdev.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	case LG_G510:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	case LG_G510_USB_AUDIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		case LG_G15_LCD_BRIGHTNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 			 * The G510 does not have a separate LCD brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 			 * but it does have a separate power-on (reset) value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 			g15->leds[i].cdev.name = "g15::power_on_backlight_val";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		case LG_G15_KBD_BRIGHTNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 			g15->leds[i].cdev.brightness_set_blocking =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 				lg_g510_kbd_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 			g15->leds[i].cdev.brightness_get =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 				lg_g510_kbd_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 			g15->leds[i].cdev.max_brightness = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 			g15->leds[i].cdev.groups = lg_g510_kbd_led_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 			g15->leds[i].cdev.brightness_set_blocking =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 				lg_g510_mkey_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 			g15->leds[i].cdev.brightness_get =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 				lg_g510_mkey_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 			g15->leds[i].cdev.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	return devm_led_classdev_register(&g15->hdev->dev, &g15->leds[i].cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	u8 gkeys_settings_output_report = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	u8 gkeys_settings_feature_report = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	struct hid_report_enum *rep_enum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	unsigned int connect_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	bool has_ff000000 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	struct lg_g15_data *g15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	struct hid_report *rep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	int ret, i, gkeys = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	 * Some models have multiple interfaces, we want the interface with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	 * with the f000.0000 application input report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	list_for_each_entry(rep, &rep_enum->report_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		if (rep->application == 0xff000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 			has_ff000000 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	if (!has_ff000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	g15 = devm_kzalloc(&hdev->dev, sizeof(*g15), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	if (!g15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	mutex_init(&g15->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	input = devm_input_allocate_device(&hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	g15->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	g15->model = id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	hid_set_drvdata(hdev, (void *)g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	switch (g15->model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	case LG_G15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		INIT_WORK(&g15->work, lg_g15_leds_changed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 		 * The G15 and G15 v2 use a separate usb-device (on a builtin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		 * hub) which emulates a keyboard for the F1 - F12 emulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		 * on the G-keys, which we disable, rendering the emulated kbd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		 * non-functional, so we do not let hid-input connect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 		connect_mask = HID_CONNECT_HIDRAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		gkeys_settings_output_report = 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		gkeys = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	case LG_G15_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 		INIT_WORK(&g15->work, lg_g15_leds_changed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		connect_mask = HID_CONNECT_HIDRAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		gkeys_settings_output_report = 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		gkeys = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	case LG_G510:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	case LG_G510_USB_AUDIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 		INIT_WORK(&g15->work, lg_g510_leds_sync_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		connect_mask = HID_CONNECT_HIDINPUT | HID_CONNECT_HIDRAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		gkeys_settings_feature_report = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		gkeys = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	ret = hid_hw_start(hdev, connect_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	/* Tell the keyboard to stop sending F1-F12 + 1-6 for G1 - G18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	if (gkeys_settings_output_report) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 		g15->transfer_buf[0] = gkeys_settings_output_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		memset(g15->transfer_buf + 1, 0, gkeys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 		 * The kbd ignores our output report if we do not queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		 * an URB on the USB input endpoint first...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 		ret = hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 			goto error_hw_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		ret = hid_hw_output_report(hdev, g15->transfer_buf, gkeys + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 		hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	if (gkeys_settings_feature_report) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 		g15->transfer_buf[0] = gkeys_settings_feature_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 		memset(g15->transfer_buf + 1, 0, gkeys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 		ret = hid_hw_raw_request(g15->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 				gkeys_settings_feature_report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 				g15->transfer_buf, gkeys + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 				HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 		hid_err(hdev, "Error %d disabling keyboard emulation for the G-keys, falling back to generic hid-input driver\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		hid_set_drvdata(hdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	/* Get initial brightness levels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	ret = lg_g15_get_initial_led_brightness(g15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		goto error_hw_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	/* Setup and register input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	input->name = "Logitech Gaming Keyboard Gaming Keys";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	input->phys = hdev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	input->uniq = hdev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	input->id.bustype = hdev->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	input->id.vendor  = hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	input->id.product = hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	input->id.version = hdev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	input->dev.parent = &hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	input->open = lg_g15_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	input->close = lg_g15_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	/* G-keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	for (i = 0; i < gkeys; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		input_set_capability(input, EV_KEY, KEY_MACRO1 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	/* M1 - M3 and MR keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		input_set_capability(input, EV_KEY, KEY_MACRO_PRESET1 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	input_set_capability(input, EV_KEY, KEY_MACRO_RECORD_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	/* Keys below the LCD, intended for controlling a menu on the LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	for (i = 0; i < 5; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		input_set_capability(input, EV_KEY, KEY_KBD_LCD_MENU1 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	 * On the G510 only report headphone and mic mute keys when *not* using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	 * the builtin USB audio device. When the builtin audio is used these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	 * keys directly toggle mute (and the LEDs) on/off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	if (g15->model == LG_G510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		input_set_capability(input, EV_KEY, KEY_MUTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 		/* Userspace expects F20 for micmute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 		input_set_capability(input, EV_KEY, KEY_F20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	g15->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	input_set_drvdata(input, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	ret = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 		goto error_hw_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	/* Register LED devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	for (i = 0; i < LG_G15_LED_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		ret = lg_g15_register_led(g15, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 			goto error_hw_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) error_hw_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) static const struct hid_device_id lg_g15_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 	/* The G11 is a G15 without the LCD, treat it as a G15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		USB_DEVICE_ID_LOGITECH_G11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 		.driver_data = LG_G15 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 			 USB_DEVICE_ID_LOGITECH_G15_LCD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 		.driver_data = LG_G15 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 			 USB_DEVICE_ID_LOGITECH_G15_V2_LCD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 		.driver_data = LG_G15_V2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	/* G510 without a headset plugged in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 			 USB_DEVICE_ID_LOGITECH_G510),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 		.driver_data = LG_G510 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 	/* G510 with headset plugged in / with extra USB audio interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 			 USB_DEVICE_ID_LOGITECH_G510_USB_AUDIO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 		.driver_data = LG_G510_USB_AUDIO },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) MODULE_DEVICE_TABLE(hid, lg_g15_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static struct hid_driver lg_g15_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	.name			= "lg-g15",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	.id_table		= lg_g15_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	.raw_event		= lg_g15_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	.probe			= lg_g15_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) module_hid_driver(lg_g15_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) MODULE_LICENSE("GPL");