mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-11 17:10:13 +00:00
Merge branch 'for-6.19/logitech' into for-linus
- Support for Logitech G Pro X Superlight 2 receiver (Nathan Rossi) - Fix for retry logic in hidpp_send_message_sync() (Mavroudis Chatzilazaridis) - Support for new Lighspeed receiver version (Mavroudis Chatzilazaridis) - Support for Logitech G13 (Leo L. Schwab) - Backlight support improvement for Logitech G510 (Hans de Goede)
This commit is contained in:
commit
4b2dda7374
@ -882,6 +882,7 @@
|
||||
#define USB_DEVICE_ID_LOGITECH_DUAL_ACTION 0xc216
|
||||
#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2 0xc218
|
||||
#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2 0xc219
|
||||
#define USB_DEVICE_ID_LOGITECH_G13 0xc21c
|
||||
#define USB_DEVICE_ID_LOGITECH_G15_LCD 0xc222
|
||||
#define USB_DEVICE_ID_LOGITECH_G11 0xc225
|
||||
#define USB_DEVICE_ID_LOGITECH_G15_V2_LCD 0xc227
|
||||
@ -917,6 +918,8 @@
|
||||
#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1 0xc539
|
||||
#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1 0xc53f
|
||||
#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_2 0xc543
|
||||
#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_3 0xc547
|
||||
#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_4 0xc54d
|
||||
#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY 0xc53a
|
||||
#define USB_DEVICE_ID_LOGITECH_BOLT_RECEIVER 0xc548
|
||||
#define USB_DEVICE_ID_SPACETRAVELLER 0xc623
|
||||
|
||||
@ -26,7 +26,24 @@
|
||||
#define LG_G510_FEATURE_BACKLIGHT_RGB 0x05
|
||||
#define LG_G510_FEATURE_POWER_ON_RGB 0x06
|
||||
|
||||
#define LG_G510_INPUT_MACRO_KEYS 0x03
|
||||
#define LG_G510_INPUT_KBD_BACKLIGHT 0x04
|
||||
|
||||
#define LG_G13_INPUT_REPORT 0x01
|
||||
#define LG_G13_FEATURE_M_KEYS_LEDS 0x05
|
||||
#define LG_G13_FEATURE_BACKLIGHT_RGB 0x07
|
||||
#define LG_G13_BACKLIGHT_HW_ON_BIT 23
|
||||
|
||||
/**
|
||||
* g13_input_report.keybits[] is not 32-bit aligned, so we can't use the bitops macros.
|
||||
*
|
||||
* @ary: Pointer to array of u8s
|
||||
* @b: Bit index into ary, LSB first. Not range checked.
|
||||
*/
|
||||
#define TEST_BIT(ary, b) ((1 << ((b) & 7)) & (ary)[(b) >> 3])
|
||||
|
||||
enum lg_g15_model {
|
||||
LG_G13,
|
||||
LG_G15,
|
||||
LG_G15_V2,
|
||||
LG_G510,
|
||||
@ -45,6 +62,12 @@ enum lg_g15_led_type {
|
||||
LG_G15_LED_MAX
|
||||
};
|
||||
|
||||
struct g13_input_report {
|
||||
u8 report_id; /* Report ID is always set to 1. */
|
||||
u8 joy_x, joy_y;
|
||||
u8 keybits[5];
|
||||
};
|
||||
|
||||
struct lg_g15_led {
|
||||
union {
|
||||
struct led_classdev cdev;
|
||||
@ -63,12 +86,188 @@ struct lg_g15_data {
|
||||
struct mutex mutex;
|
||||
struct work_struct work;
|
||||
struct input_dev *input;
|
||||
struct input_dev *input_js; /* Separate joystick device for G13. */
|
||||
struct hid_device *hdev;
|
||||
enum lg_g15_model model;
|
||||
struct lg_g15_led leds[LG_G15_LED_MAX];
|
||||
bool game_mode_enabled;
|
||||
bool backlight_disabled; /* true == HW backlight toggled *OFF* */
|
||||
};
|
||||
|
||||
/********* G13 LED functions ***********/
|
||||
/*
|
||||
* G13 retains no state across power cycles, and always powers up with the backlight on,
|
||||
* color #5AFF6E, all macro key LEDs off.
|
||||
*/
|
||||
static int lg_g13_get_leds_state(struct lg_g15_data *g15)
|
||||
{
|
||||
u8 * const tbuf = g15->transfer_buf;
|
||||
int ret, high;
|
||||
|
||||
/* RGB backlight. */
|
||||
ret = hid_hw_raw_request(g15->hdev, LG_G13_FEATURE_BACKLIGHT_RGB,
|
||||
tbuf, 5,
|
||||
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
|
||||
if (ret != 5) {
|
||||
hid_err(g15->hdev, "Error getting backlight brightness: %d\n", ret);
|
||||
return (ret < 0) ? ret : -EIO;
|
||||
}
|
||||
|
||||
/* Normalize RGB intensities against the highest component. */
|
||||
high = max3(tbuf[1], tbuf[2], tbuf[3]);
|
||||
if (high) {
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].red =
|
||||
DIV_ROUND_CLOSEST(tbuf[1] * 255, high);
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].green =
|
||||
DIV_ROUND_CLOSEST(tbuf[2] * 255, high);
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].blue =
|
||||
DIV_ROUND_CLOSEST(tbuf[3] * 255, high);
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].brightness = high;
|
||||
} else {
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].red = 255;
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].green = 255;
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].blue = 255;
|
||||
g15->leds[LG_G15_KBD_BRIGHTNESS].brightness = 0;
|
||||
}
|
||||
|
||||
/* Macro LEDs. */
|
||||
ret = hid_hw_raw_request(g15->hdev, LG_G13_FEATURE_M_KEYS_LEDS,
|
||||
tbuf, 5,
|
||||
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
|
||||
if (ret != 5) {
|
||||
hid_err(g15->hdev, "Error getting macro LED brightness: %d\n", ret);
|
||||
return (ret < 0) ? ret : -EIO;
|
||||
}
|
||||
|
||||
for (int i = LG_G15_MACRO_PRESET1; i < LG_G15_LED_MAX; ++i)
|
||||
g15->leds[i].brightness = !!(tbuf[1] & (1 << (i - LG_G15_MACRO_PRESET1)));
|
||||
|
||||
/*
|
||||
* Bit 23 of g13_input_report.keybits[] contains the backlight's
|
||||
* current HW toggle state. Retrieve it from the device.
|
||||
*/
|
||||
ret = hid_hw_raw_request(g15->hdev, LG_G13_INPUT_REPORT,
|
||||
tbuf, sizeof(struct g13_input_report),
|
||||
HID_INPUT_REPORT, HID_REQ_GET_REPORT);
|
||||
if (ret != sizeof(struct g13_input_report)) {
|
||||
hid_err(g15->hdev, "Error getting backlight on/off state: %d\n", ret);
|
||||
return (ret < 0) ? ret : -EIO;
|
||||
}
|
||||
g15->backlight_disabled =
|
||||
!TEST_BIT(((struct g13_input_report *) tbuf)->keybits,
|
||||
LG_G13_BACKLIGHT_HW_ON_BIT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lg_g13_kbd_led_write(struct lg_g15_data *g15,
|
||||
struct lg_g15_led *g15_led,
|
||||
enum led_brightness brightness)
|
||||
{
|
||||
struct mc_subled const * const subleds = g15_led->mcdev.subled_info;
|
||||
u8 * const tbuf = g15->transfer_buf;
|
||||
int ret;
|
||||
|
||||
guard(mutex)(&g15->mutex);
|
||||
|
||||
led_mc_calc_color_components(&g15_led->mcdev, brightness);
|
||||
|
||||
tbuf[0] = 5;
|
||||
tbuf[1] = subleds[0].brightness;
|
||||
tbuf[2] = subleds[1].brightness;
|
||||
tbuf[3] = subleds[2].brightness;
|
||||
tbuf[4] = 0;
|
||||
|
||||
ret = hid_hw_raw_request(g15->hdev, LG_G13_FEATURE_BACKLIGHT_RGB,
|
||||
tbuf, 5,
|
||||
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
|
||||
if (ret != 5) {
|
||||
hid_err(g15->hdev, "Error setting backlight brightness: %d\n", ret);
|
||||
return (ret < 0) ? ret : -EIO;
|
||||
}
|
||||
|
||||
g15_led->brightness = brightness;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lg_g13_kbd_led_set(struct led_classdev *led_cdev, enum led_brightness brightness)
|
||||
{
|
||||
struct led_classdev_mc *mc = lcdev_to_mccdev(led_cdev);
|
||||
struct lg_g15_led *g15_led =
|
||||
container_of(mc, struct lg_g15_led, mcdev);
|
||||
struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
|
||||
|
||||
/* Ignore LED off on unregister / keyboard unplug */
|
||||
if (led_cdev->flags & LED_UNREGISTERING)
|
||||
return 0;
|
||||
|
||||
return lg_g13_kbd_led_write(g15, g15_led, brightness);
|
||||
}
|
||||
|
||||
static enum led_brightness lg_g13_kbd_led_get(struct led_classdev *led_cdev)
|
||||
{
|
||||
struct led_classdev_mc const * const mc = lcdev_to_mccdev(led_cdev);
|
||||
struct lg_g15_led const *g15_led =
|
||||
container_of(mc, struct lg_g15_led, mcdev);
|
||||
|
||||
return g15_led->brightness;
|
||||
}
|
||||
|
||||
static int lg_g13_mkey_led_set(struct led_classdev *led_cdev, enum led_brightness brightness)
|
||||
{
|
||||
struct lg_g15_led *g15_led =
|
||||
container_of(led_cdev, struct lg_g15_led, cdev);
|
||||
struct lg_g15_data *g15 = dev_get_drvdata(led_cdev->dev->parent);
|
||||
int i, ret;
|
||||
u8 * const tbuf = g15->transfer_buf;
|
||||
u8 val, mask = 0;
|
||||
|
||||
/* Ignore LED off on unregister / keyboard unplug */
|
||||
if (led_cdev->flags & LED_UNREGISTERING)
|
||||
return 0;
|
||||
|
||||
guard(mutex)(&g15->mutex);
|
||||
|
||||
for (i = LG_G15_MACRO_PRESET1; i < LG_G15_LED_MAX; ++i) {
|
||||
if (i == g15_led->led)
|
||||
val = brightness;
|
||||
else
|
||||
val = g15->leds[i].brightness;
|
||||
|
||||
if (val)
|
||||
mask |= 1 << (i - LG_G15_MACRO_PRESET1);
|
||||
}
|
||||
|
||||
tbuf[0] = 5;
|
||||
tbuf[1] = mask;
|
||||
tbuf[2] = 0;
|
||||
tbuf[3] = 0;
|
||||
tbuf[4] = 0;
|
||||
|
||||
ret = hid_hw_raw_request(g15->hdev, LG_G13_FEATURE_M_KEYS_LEDS,
|
||||
tbuf, 5,
|
||||
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
|
||||
if (ret != 5) {
|
||||
hid_err(g15->hdev, "Error setting LED brightness: %d\n", ret);
|
||||
return (ret < 0) ? ret : -EIO;
|
||||
}
|
||||
|
||||
g15_led->brightness = brightness;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum led_brightness lg_g13_mkey_led_get(struct led_classdev *led_cdev)
|
||||
{
|
||||
/*
|
||||
* G13 doesn't change macro key LEDs behind our back, so they're
|
||||
* whatever we last set them to.
|
||||
*/
|
||||
struct lg_g15_led *g15_led =
|
||||
container_of(led_cdev, struct lg_g15_led, cdev);
|
||||
|
||||
return g15_led->brightness;
|
||||
}
|
||||
|
||||
/******** G15 and G15 v2 LED functions ********/
|
||||
|
||||
static int lg_g15_update_led_brightness(struct lg_g15_data *g15)
|
||||
@ -227,6 +426,20 @@ static int lg_g510_get_initial_led_brightness(struct lg_g15_data *g15, int i)
|
||||
g15->leds[i].brightness = 0;
|
||||
}
|
||||
|
||||
if (i)
|
||||
return 0;
|
||||
|
||||
ret = hid_hw_raw_request(g15->hdev, LG_G510_INPUT_KBD_BACKLIGHT,
|
||||
g15->transfer_buf, 2,
|
||||
HID_INPUT_REPORT, HID_REQ_GET_REPORT);
|
||||
if (ret != 2) {
|
||||
/* This can happen when a KVM switch is used, so only warn. */
|
||||
hid_warn(g15->hdev, "Error getting backlight state: %d\n", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
g15->backlight_disabled = g15->transfer_buf[1] & 0x04;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -390,6 +603,8 @@ static int lg_g15_get_initial_led_brightness(struct lg_g15_data *g15)
|
||||
int ret;
|
||||
|
||||
switch (g15->model) {
|
||||
case LG_G13:
|
||||
return lg_g13_get_leds_state(g15);
|
||||
case LG_G15:
|
||||
case LG_G15_V2:
|
||||
return lg_g15_update_led_brightness(g15);
|
||||
@ -417,6 +632,108 @@ static int lg_g15_get_initial_led_brightness(struct lg_g15_data *g15)
|
||||
|
||||
/******** Input functions ********/
|
||||
|
||||
/* Table mapping keybits[] bit positions to event codes. */
|
||||
/* Note: Indices are discontinuous to aid readability. */
|
||||
static const u16 g13_keys_for_bits[] = {
|
||||
/* Main keypad - keys G1 - G22 */
|
||||
[0] = KEY_MACRO1,
|
||||
[1] = KEY_MACRO2,
|
||||
[2] = KEY_MACRO3,
|
||||
[3] = KEY_MACRO4,
|
||||
[4] = KEY_MACRO5,
|
||||
[5] = KEY_MACRO6,
|
||||
[6] = KEY_MACRO7,
|
||||
[7] = KEY_MACRO8,
|
||||
[8] = KEY_MACRO9,
|
||||
[9] = KEY_MACRO10,
|
||||
[10] = KEY_MACRO11,
|
||||
[11] = KEY_MACRO12,
|
||||
[12] = KEY_MACRO13,
|
||||
[13] = KEY_MACRO14,
|
||||
[14] = KEY_MACRO15,
|
||||
[15] = KEY_MACRO16,
|
||||
[16] = KEY_MACRO17,
|
||||
[17] = KEY_MACRO18,
|
||||
[18] = KEY_MACRO19,
|
||||
[19] = KEY_MACRO20,
|
||||
[20] = KEY_MACRO21,
|
||||
[21] = KEY_MACRO22,
|
||||
|
||||
/* LCD menu buttons. */
|
||||
[24] = KEY_KBD_LCD_MENU5, /* "Next page" button */
|
||||
[25] = KEY_KBD_LCD_MENU1, /* Left-most */
|
||||
[26] = KEY_KBD_LCD_MENU2,
|
||||
[27] = KEY_KBD_LCD_MENU3,
|
||||
[28] = KEY_KBD_LCD_MENU4, /* Right-most */
|
||||
|
||||
/* Macro preset and record buttons; have red LEDs under them. */
|
||||
[29] = KEY_MACRO_PRESET1,
|
||||
[30] = KEY_MACRO_PRESET2,
|
||||
[31] = KEY_MACRO_PRESET3,
|
||||
[32] = KEY_MACRO_RECORD_START,
|
||||
|
||||
/* 33-35 handled by joystick device. */
|
||||
|
||||
/* Backlight toggle. */
|
||||
[37] = KEY_LIGHTS_TOGGLE,
|
||||
};
|
||||
|
||||
#define G13_JS_KEYBITS_OFFSET 33
|
||||
|
||||
static const u16 g13_keys_for_bits_js[] = {
|
||||
/* Joystick buttons */
|
||||
/* These keybits are at bit indices 33, 34, and 35. */
|
||||
BTN_BASE, /* Left side */
|
||||
BTN_BASE2, /* Bottom side */
|
||||
BTN_THUMB, /* Stick depress */
|
||||
};
|
||||
|
||||
static int lg_g13_event(struct lg_g15_data *g15, u8 const *data)
|
||||
{
|
||||
struct g13_input_report const * const rep = (struct g13_input_report *) data;
|
||||
int i, val;
|
||||
bool backlight_disabled;
|
||||
|
||||
/*
|
||||
* Main macropad and menu keys.
|
||||
* Emit key events defined for each bit position.
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(g13_keys_for_bits); ++i) {
|
||||
if (g13_keys_for_bits[i]) {
|
||||
val = TEST_BIT(rep->keybits, i);
|
||||
input_report_key(g15->input, g13_keys_for_bits[i], val);
|
||||
}
|
||||
}
|
||||
input_sync(g15->input);
|
||||
|
||||
/*
|
||||
* Joystick.
|
||||
* Emit button and deflection events.
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(g13_keys_for_bits_js); ++i) {
|
||||
val = TEST_BIT(rep->keybits, i + G13_JS_KEYBITS_OFFSET);
|
||||
input_report_key(g15->input_js, g13_keys_for_bits_js[i], val);
|
||||
}
|
||||
input_report_abs(g15->input_js, ABS_X, rep->joy_x);
|
||||
input_report_abs(g15->input_js, ABS_Y, rep->joy_y);
|
||||
input_sync(g15->input_js);
|
||||
|
||||
/*
|
||||
* Bit 23 of keybits[] reports the current backlight on/off state. If
|
||||
* it has changed from the last cached value, apply an update.
|
||||
*/
|
||||
backlight_disabled = !TEST_BIT(rep->keybits, LG_G13_BACKLIGHT_HW_ON_BIT);
|
||||
if (backlight_disabled ^ g15->backlight_disabled) {
|
||||
led_classdev_notify_brightness_hw_changed(
|
||||
&g15->leds[LG_G15_KBD_BRIGHTNESS].mcdev.led_cdev,
|
||||
backlight_disabled
|
||||
? 0 : g15->leds[LG_G15_KBD_BRIGHTNESS].brightness);
|
||||
g15->backlight_disabled = backlight_disabled;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* On the G15 Mark I Logitech has been quite creative with which bit is what */
|
||||
static void lg_g15_handle_lcd_menu_keys(struct lg_g15_data *g15, u8 *data)
|
||||
{
|
||||
@ -549,14 +866,24 @@ static int lg_g510_event(struct lg_g15_data *g15, u8 *data)
|
||||
|
||||
static int lg_g510_leds_event(struct lg_g15_data *g15, u8 *data)
|
||||
{
|
||||
struct lg_g15_led *g15_led = &g15->leds[LG_G15_KBD_BRIGHTNESS];
|
||||
bool backlight_disabled;
|
||||
|
||||
backlight_disabled = data[1] & 0x04;
|
||||
if (backlight_disabled == g15->backlight_disabled)
|
||||
return 0;
|
||||
|
||||
led_classdev_notify_brightness_hw_changed(
|
||||
&g15_led->mcdev.led_cdev,
|
||||
backlight_disabled ? 0 : g15_led->brightness);
|
||||
|
||||
g15->backlight_disabled = backlight_disabled;
|
||||
|
||||
/*
|
||||
* The G510 ignores backlight updates when the backlight is turned off
|
||||
* through the light toggle button on the keyboard, to work around this
|
||||
* we queue a workitem to sync values when the backlight is turned on.
|
||||
*/
|
||||
backlight_disabled = data[1] & 0x04;
|
||||
if (!backlight_disabled)
|
||||
schedule_work(&g15->work);
|
||||
|
||||
@ -572,6 +899,10 @@ static int lg_g15_raw_event(struct hid_device *hdev, struct hid_report *report,
|
||||
return 0;
|
||||
|
||||
switch (g15->model) {
|
||||
case LG_G13:
|
||||
if (data[0] == 0x01 && size == sizeof(struct g13_input_report))
|
||||
return lg_g13_event(g15, data);
|
||||
break;
|
||||
case LG_G15:
|
||||
if (data[0] == 0x02 && size == 9)
|
||||
return lg_g15_event(g15, data);
|
||||
@ -588,9 +919,9 @@ static int lg_g15_raw_event(struct hid_device *hdev, struct hid_report *report,
|
||||
break;
|
||||
case LG_G510:
|
||||
case LG_G510_USB_AUDIO:
|
||||
if (data[0] == 0x03 && size == 5)
|
||||
if (data[0] == LG_G510_INPUT_MACRO_KEYS && size == 5)
|
||||
return lg_g510_event(g15, data);
|
||||
if (data[0] == 0x04 && size == 2)
|
||||
if (data[0] == LG_G510_INPUT_KBD_BACKLIGHT && size == 2)
|
||||
return lg_g510_leds_event(g15, data);
|
||||
break;
|
||||
}
|
||||
@ -616,13 +947,24 @@ static void lg_g15_setup_led_rgb(struct lg_g15_data *g15, int index)
|
||||
{
|
||||
int i;
|
||||
struct mc_subled *subled_info;
|
||||
struct lg_g15_led * const gled = &g15->leds[index];
|
||||
|
||||
g15->leds[index].mcdev.led_cdev.brightness_set_blocking =
|
||||
lg_g510_kbd_led_set;
|
||||
g15->leds[index].mcdev.led_cdev.brightness_get =
|
||||
lg_g510_kbd_led_get;
|
||||
g15->leds[index].mcdev.led_cdev.max_brightness = 255;
|
||||
g15->leds[index].mcdev.num_colors = 3;
|
||||
if (g15->model == LG_G13) {
|
||||
gled->mcdev.led_cdev.brightness_set_blocking =
|
||||
lg_g13_kbd_led_set;
|
||||
gled->mcdev.led_cdev.brightness_get =
|
||||
lg_g13_kbd_led_get;
|
||||
gled->mcdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED;
|
||||
} else {
|
||||
gled->mcdev.led_cdev.brightness_set_blocking =
|
||||
lg_g510_kbd_led_set;
|
||||
gled->mcdev.led_cdev.brightness_get =
|
||||
lg_g510_kbd_led_get;
|
||||
if (index == LG_G15_KBD_BRIGHTNESS)
|
||||
g15->leds[index].mcdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED;
|
||||
}
|
||||
gled->mcdev.led_cdev.max_brightness = 255;
|
||||
gled->mcdev.num_colors = 3;
|
||||
|
||||
subled_info = devm_kcalloc(&g15->hdev->dev, 3, sizeof(*subled_info), GFP_KERNEL);
|
||||
if (!subled_info)
|
||||
@ -632,20 +974,20 @@ static void lg_g15_setup_led_rgb(struct lg_g15_data *g15, int index)
|
||||
switch (i + 1) {
|
||||
case LED_COLOR_ID_RED:
|
||||
subled_info[i].color_index = LED_COLOR_ID_RED;
|
||||
subled_info[i].intensity = g15->leds[index].red;
|
||||
subled_info[i].intensity = gled->red;
|
||||
break;
|
||||
case LED_COLOR_ID_GREEN:
|
||||
subled_info[i].color_index = LED_COLOR_ID_GREEN;
|
||||
subled_info[i].intensity = g15->leds[index].green;
|
||||
subled_info[i].intensity = gled->green;
|
||||
break;
|
||||
case LED_COLOR_ID_BLUE:
|
||||
subled_info[i].color_index = LED_COLOR_ID_BLUE;
|
||||
subled_info[i].intensity = g15->leds[index].blue;
|
||||
subled_info[i].intensity = gled->blue;
|
||||
break;
|
||||
}
|
||||
subled_info[i].channel = i;
|
||||
}
|
||||
g15->leds[index].mcdev.subled_info = subled_info;
|
||||
gled->mcdev.subled_info = subled_info;
|
||||
}
|
||||
|
||||
static int lg_g15_register_led(struct lg_g15_data *g15, int i, const char *name)
|
||||
@ -656,6 +998,23 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i, const char *name)
|
||||
g15->leds[i].cdev.name = name;
|
||||
|
||||
switch (g15->model) {
|
||||
case LG_G13:
|
||||
if (i < LG_G15_BRIGHTNESS_MAX) {
|
||||
/* RGB backlight. */
|
||||
lg_g15_setup_led_rgb(g15, i);
|
||||
ret = devm_led_classdev_multicolor_register_ext(&g15->hdev->dev,
|
||||
&g15->leds[i].mcdev,
|
||||
NULL);
|
||||
} else {
|
||||
/* Macro keys */
|
||||
g15->leds[i].cdev.brightness_set_blocking = lg_g13_mkey_led_set;
|
||||
g15->leds[i].cdev.brightness_get = lg_g13_mkey_led_get;
|
||||
g15->leds[i].cdev.max_brightness = 1;
|
||||
|
||||
ret = devm_led_classdev_register(&g15->hdev->dev,
|
||||
&g15->leds[i].cdev);
|
||||
}
|
||||
break;
|
||||
case LG_G15:
|
||||
case LG_G15_V2:
|
||||
g15->leds[i].cdev.brightness_get = lg_g15_led_get;
|
||||
@ -702,11 +1061,9 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i, const char *name)
|
||||
}
|
||||
|
||||
/* Common input device init code shared between keyboards and Z-10 speaker handling */
|
||||
static void lg_g15_init_input_dev(struct hid_device *hdev, struct input_dev *input,
|
||||
const char *name)
|
||||
static void lg_g15_init_input_dev_core(struct hid_device *hdev, struct input_dev *input,
|
||||
char const *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
input->name = name;
|
||||
input->phys = hdev->phys;
|
||||
input->uniq = hdev->uniq;
|
||||
@ -717,12 +1074,42 @@ static void lg_g15_init_input_dev(struct hid_device *hdev, struct input_dev *inp
|
||||
input->dev.parent = &hdev->dev;
|
||||
input->open = lg_g15_input_open;
|
||||
input->close = lg_g15_input_close;
|
||||
}
|
||||
|
||||
static void lg_g15_init_input_dev(struct hid_device *hdev, struct input_dev *input,
|
||||
const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
lg_g15_init_input_dev_core(hdev, input, name);
|
||||
|
||||
/* Keys below the LCD, intended for controlling a menu on the LCD */
|
||||
for (i = 0; i < 5; i++)
|
||||
input_set_capability(input, EV_KEY, KEY_KBD_LCD_MENU1 + i);
|
||||
}
|
||||
|
||||
static void lg_g13_init_input_dev(struct hid_device *hdev,
|
||||
struct input_dev *input, const char *name,
|
||||
struct input_dev *input_js, const char *name_js)
|
||||
{
|
||||
/* Macropad. */
|
||||
lg_g15_init_input_dev_core(hdev, input, name);
|
||||
for (int i = 0; i < ARRAY_SIZE(g13_keys_for_bits); ++i) {
|
||||
if (g13_keys_for_bits[i])
|
||||
input_set_capability(input, EV_KEY, g13_keys_for_bits[i]);
|
||||
}
|
||||
|
||||
/* OBTW, we're a joystick, too... */
|
||||
lg_g15_init_input_dev_core(hdev, input_js, name_js);
|
||||
for (int i = 0; i < ARRAY_SIZE(g13_keys_for_bits_js); ++i)
|
||||
input_set_capability(input_js, EV_KEY, g13_keys_for_bits_js[i]);
|
||||
|
||||
input_set_capability(input_js, EV_ABS, ABS_X);
|
||||
input_set_abs_params(input_js, ABS_X, 0, 255, 0, 0);
|
||||
input_set_capability(input_js, EV_ABS, ABS_Y);
|
||||
input_set_abs_params(input_js, ABS_Y, 0, 255, 0, 0);
|
||||
}
|
||||
|
||||
static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
||||
{
|
||||
static const char * const led_names[] = {
|
||||
@ -739,7 +1126,7 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
||||
unsigned int connect_mask = 0;
|
||||
bool has_ff000000 = false;
|
||||
struct lg_g15_data *g15;
|
||||
struct input_dev *input;
|
||||
struct input_dev *input, *input_js;
|
||||
struct hid_report *rep;
|
||||
int ret, i, gkeys = 0;
|
||||
|
||||
@ -778,6 +1165,25 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
||||
hid_set_drvdata(hdev, (void *)g15);
|
||||
|
||||
switch (g15->model) {
|
||||
case LG_G13:
|
||||
/*
|
||||
* The G13 has an analog thumbstick with nearby buttons. Some
|
||||
* libraries and applications are known to ignore devices that
|
||||
* don't "look like" a joystick, and a device with two ABS axes
|
||||
* and 25+ macro keys would confuse them.
|
||||
*
|
||||
* Create an additional input device dedicated to appear as a
|
||||
* simplified joystick (two ABS axes, three BTN buttons).
|
||||
*/
|
||||
input_js = devm_input_allocate_device(&hdev->dev);
|
||||
if (!input_js)
|
||||
return -ENOMEM;
|
||||
g15->input_js = input_js;
|
||||
input_set_drvdata(input_js, hdev);
|
||||
|
||||
connect_mask = HID_CONNECT_HIDRAW;
|
||||
gkeys = 25;
|
||||
break;
|
||||
case LG_G15:
|
||||
INIT_WORK(&g15->work, lg_g15_leds_changed_work);
|
||||
/*
|
||||
@ -859,6 +1265,38 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
||||
goto error_hw_stop;
|
||||
|
||||
return 0; /* All done */
|
||||
} else if (g15->model == LG_G13) {
|
||||
static char const * const g13_led_names[] = {
|
||||
/* Backlight is shared between LCD and keys. */
|
||||
"g13:rgb:kbd_backlight",
|
||||
NULL, /* Keep in sync with led_type enum */
|
||||
"g13:red:macro_preset_1",
|
||||
"g13:red:macro_preset_2",
|
||||
"g13:red:macro_preset_3",
|
||||
"g13:red:macro_record",
|
||||
};
|
||||
lg_g13_init_input_dev(hdev,
|
||||
input, "Logitech G13 Gaming Keypad",
|
||||
input_js, "Logitech G13 Thumbstick");
|
||||
ret = input_register_device(input);
|
||||
if (ret)
|
||||
goto error_hw_stop;
|
||||
ret = input_register_device(input_js);
|
||||
if (ret)
|
||||
goto error_hw_stop;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(g13_led_names); ++i) {
|
||||
if (g13_led_names[i]) {
|
||||
ret = lg_g15_register_led(g15, i, g13_led_names[i]);
|
||||
if (ret)
|
||||
goto error_hw_stop;
|
||||
}
|
||||
}
|
||||
led_classdev_notify_brightness_hw_changed(
|
||||
&g15->leds[LG_G15_KBD_BRIGHTNESS].mcdev.led_cdev,
|
||||
g15->backlight_disabled
|
||||
? 0 : g15->leds[LG_G15_KBD_BRIGHTNESS].brightness);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Setup and register input device */
|
||||
@ -903,6 +1341,13 @@ error_hw_stop:
|
||||
}
|
||||
|
||||
static const struct hid_device_id lg_g15_devices[] = {
|
||||
/*
|
||||
* The G13 is a macropad-only device with an LCD, LED backlighing,
|
||||
* and joystick.
|
||||
*/
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
|
||||
USB_DEVICE_ID_LOGITECH_G13),
|
||||
.driver_data = LG_G13 },
|
||||
/* The G11 is a G15 without the LCD, treat it as a G15 */
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
|
||||
USB_DEVICE_ID_LOGITECH_G11),
|
||||
|
||||
@ -116,6 +116,7 @@ enum recvr_type {
|
||||
recvr_type_dj,
|
||||
recvr_type_hidpp,
|
||||
recvr_type_gaming_hidpp,
|
||||
recvr_type_gaming_hidpp_ls_1_3,
|
||||
recvr_type_mouse_only,
|
||||
recvr_type_27mhz,
|
||||
recvr_type_bluetooth,
|
||||
@ -212,6 +213,44 @@ static const char kbd_descriptor[] = {
|
||||
0xC0
|
||||
};
|
||||
|
||||
/* Gaming Keyboard descriptor (1) */
|
||||
static const char kbd_lightspeed_1_3_descriptor[] = {
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x06, /* Usage (Keyboard) */
|
||||
0xA1, 0x01, /* Collection (Application) */
|
||||
0x85, 0x01, /* Report ID (1) */
|
||||
0x05, 0x07, /* Usage Page (Kbrd/Keypad) */
|
||||
0x19, 0xE0, /* Usage Minimum (0xE0) */
|
||||
0x29, 0xE7, /* Usage Maximum (0xE7) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x95, 0x08, /* Report Count (8) */
|
||||
0x81, 0x02, /* Input (Data,Var) */
|
||||
0x95, 0x70, /* Report Count (112) */
|
||||
0x19, 0x04, /* Usage Minimum (0x04) */
|
||||
0x29, 0x73, /* Usage Maximum (0x73) */
|
||||
0x81, 0x02, /* Input (Data,Var,Abs) */
|
||||
0x95, 0x05, /* Report Count (5) */
|
||||
0x19, 0x87, /* Usage Minimum (0x87) */
|
||||
0x29, 0x8B, /* Usage Maximum (0x8B) */
|
||||
0x81, 0x02, /* Input (Data,Var,Abs) */
|
||||
0x95, 0x03, /* Report Count (3) */
|
||||
0x19, 0x90, /* Usage Minimum (0x90) */
|
||||
0x29, 0x92, /* Usage Maximum (0x92) */
|
||||
0x81, 0x02, /* Input (Data,Var,Abs) */
|
||||
0x95, 0x05, /* Report Count (5) */
|
||||
0x85, 0x0E, /* Report ID (14) */
|
||||
0x05, 0x08, /* Usage Page (LEDs) */
|
||||
0x19, 0x01, /* Usage Minimum (Num Lock) */
|
||||
0x29, 0x05, /* Usage Maximum (Kana) */
|
||||
0x91, 0x02, /* Output (Data,Var,Abs) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x03, /* Report Size (3) */
|
||||
0x91, 0x03, /* Output (Const,Var,Abs) */
|
||||
0xC0, /* End Collection */
|
||||
};
|
||||
|
||||
/* Mouse descriptor (2) */
|
||||
static const char mse_descriptor[] = {
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
|
||||
@ -416,6 +455,51 @@ static const char mse_high_res_descriptor[] = {
|
||||
0xC0, /* END_COLLECTION */
|
||||
};
|
||||
|
||||
/* Gaming Mouse descriptor with vendor data (2) */
|
||||
static const char mse_high_res_ls_1_3_descriptor[] = {
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x02, /* Usage (Mouse) */
|
||||
0xA1, 0x01, /* Collection (Application) */
|
||||
0x85, 0x02, /* Report ID (2) */
|
||||
0x09, 0x01, /* Usage (Pointer) */
|
||||
0xA1, 0x00, /* Collection (Physical) */
|
||||
0x95, 0x10, /* Report Count (16) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x05, 0x09, /* Usage Page (Button) */
|
||||
0x19, 0x01, /* Usage Minimum (0x01) */
|
||||
0x29, 0x10, /* Usage Maximum (0x10) */
|
||||
0x81, 0x02, /* Input (Data,Var,Abs) */
|
||||
0x95, 0x02, /* Report Count (2) */
|
||||
0x75, 0x10, /* Report Size (16) */
|
||||
0x16, 0x01, 0x80, /* Logical Minimum (-32767) */
|
||||
0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x30, /* Usage (X) */
|
||||
0x09, 0x31, /* Usage (Y) */
|
||||
0x81, 0x06, /* Input (Data,Var,Rel) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x15, 0x81, /* Logical Minimum (-127) */
|
||||
0x25, 0x7F, /* Logical Maximum (127) */
|
||||
0x09, 0x38, /* Usage (Wheel) */
|
||||
0x81, 0x06, /* Input (Data,Var,Rel) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x05, 0x0C, /* Usage Page (Consumer) */
|
||||
0x0A, 0x38, 0x02, /* Usage (AC Pan) */
|
||||
0x81, 0x06, /* Input (Data,Var,Rel) */
|
||||
0xC0, /* End Collection */
|
||||
0x06, 0x00, 0xFF, /* Usage Page (Vendor Defined 0xFF00) */
|
||||
0x09, 0xF1, /* Usage (0xF1) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x95, 0x05, /* Report Count (5) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x26, 0xFF, 0x00, /* Logical Maximum (255) */
|
||||
0x81, 0x00, /* Input (Data,Array,Abs) */
|
||||
0xC0, /* End Collection */
|
||||
};
|
||||
|
||||
/* Consumer Control descriptor (3) */
|
||||
static const char consumer_descriptor[] = {
|
||||
0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
|
||||
@ -521,9 +605,9 @@ static const char hidpp_descriptor[] = {
|
||||
/* Maximum size of all defined hid reports in bytes (including report id) */
|
||||
#define MAX_REPORT_SIZE 8
|
||||
|
||||
/* Make sure all descriptors are present here */
|
||||
/* Make sure the largest of each descriptor type is present here */
|
||||
#define MAX_RDESC_SIZE \
|
||||
(sizeof(kbd_descriptor) + \
|
||||
(sizeof(kbd_lightspeed_1_3_descriptor) +\
|
||||
sizeof(mse_bluetooth_descriptor) + \
|
||||
sizeof(mse5_bluetooth_descriptor) + \
|
||||
sizeof(consumer_descriptor) + \
|
||||
@ -1387,12 +1471,19 @@ static int logi_dj_ll_raw_request(struct hid_device *hid,
|
||||
return -EINVAL;
|
||||
|
||||
if (djrcv_dev->type != recvr_type_dj && count >= 2) {
|
||||
unsigned char led_report_id = 0;
|
||||
|
||||
if (!djrcv_dev->keyboard) {
|
||||
hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This Lightspeed receiver expects LED reports with report ID 1 */
|
||||
if (djrcv_dev->type == recvr_type_gaming_hidpp_ls_1_3)
|
||||
led_report_id = 1;
|
||||
|
||||
/* usbhid overrides the report ID and ignores the first byte */
|
||||
return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count,
|
||||
return hid_hw_raw_request(djrcv_dev->keyboard, led_report_id, buf, count,
|
||||
report_type, reqtype);
|
||||
}
|
||||
|
||||
@ -1439,7 +1530,11 @@ static int logi_dj_ll_parse(struct hid_device *hid)
|
||||
if (djdev->reports_supported & STD_KEYBOARD) {
|
||||
dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n",
|
||||
__func__, djdev->reports_supported);
|
||||
rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
|
||||
if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp_ls_1_3)
|
||||
rdcat(rdesc, &rsize, kbd_lightspeed_1_3_descriptor,
|
||||
sizeof(kbd_lightspeed_1_3_descriptor));
|
||||
else
|
||||
rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
|
||||
}
|
||||
|
||||
if (djdev->reports_supported & STD_MOUSE) {
|
||||
@ -1449,6 +1544,9 @@ static int logi_dj_ll_parse(struct hid_device *hid)
|
||||
djdev->dj_receiver_dev->type == recvr_type_mouse_only)
|
||||
rdcat(rdesc, &rsize, mse_high_res_descriptor,
|
||||
sizeof(mse_high_res_descriptor));
|
||||
else if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp_ls_1_3)
|
||||
rdcat(rdesc, &rsize, mse_high_res_ls_1_3_descriptor,
|
||||
sizeof(mse_high_res_ls_1_3_descriptor));
|
||||
else if (djdev->dj_receiver_dev->type == recvr_type_27mhz)
|
||||
rdcat(rdesc, &rsize, mse_27mhz_descriptor,
|
||||
sizeof(mse_27mhz_descriptor));
|
||||
@ -1708,11 +1806,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
|
||||
}
|
||||
/*
|
||||
* Mouse-only receivers send unnumbered mouse data. The 27 MHz
|
||||
* receiver uses 6 byte packets, the nano receiver 8 bytes.
|
||||
* receiver uses 6 byte packets, the nano receiver 8 bytes,
|
||||
* the lightspeed receiver (Pro X Superlight) 13 bytes.
|
||||
*/
|
||||
if (djrcv_dev->unnumbered_application == HID_GD_MOUSE &&
|
||||
size <= 8) {
|
||||
u8 mouse_report[9];
|
||||
size <= 13){
|
||||
u8 mouse_report[14];
|
||||
|
||||
/* Prepend report id */
|
||||
mouse_report[0] = REPORT_TYPE_MOUSE;
|
||||
@ -1789,6 +1888,7 @@ static int logi_dj_probe(struct hid_device *hdev,
|
||||
case recvr_type_dj: no_dj_interfaces = 3; break;
|
||||
case recvr_type_hidpp: no_dj_interfaces = 2; break;
|
||||
case recvr_type_gaming_hidpp: no_dj_interfaces = 3; break;
|
||||
case recvr_type_gaming_hidpp_ls_1_3: no_dj_interfaces = 3; break;
|
||||
case recvr_type_mouse_only: no_dj_interfaces = 2; break;
|
||||
case recvr_type_27mhz: no_dj_interfaces = 2; break;
|
||||
case recvr_type_bluetooth: no_dj_interfaces = 2; break;
|
||||
@ -1985,6 +2085,14 @@ static const struct hid_device_id logi_dj_receivers[] = {
|
||||
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
|
||||
USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_2),
|
||||
.driver_data = recvr_type_gaming_hidpp},
|
||||
{ /* Logitech lightspeed receiver (0xc547) */
|
||||
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
|
||||
USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_3),
|
||||
.driver_data = recvr_type_gaming_hidpp_ls_1_3},
|
||||
{ /* Logitech lightspeed receiver (0xc54d) */
|
||||
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
|
||||
USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_4),
|
||||
.driver_data = recvr_type_gaming_hidpp_ls_1_3},
|
||||
|
||||
{ /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */
|
||||
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
|
||||
|
||||
@ -352,10 +352,15 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
|
||||
|
||||
do {
|
||||
ret = __do_hidpp_send_message_sync(hidpp, message, response);
|
||||
if (ret != HIDPP20_ERROR_BUSY)
|
||||
if (response->report_id == REPORT_ID_HIDPP_SHORT &&
|
||||
ret != HIDPP_ERROR_BUSY)
|
||||
break;
|
||||
if ((response->report_id == REPORT_ID_HIDPP_LONG ||
|
||||
response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
|
||||
ret != HIDPP20_ERROR_BUSY)
|
||||
break;
|
||||
|
||||
dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);
|
||||
dbg_hid("%s:got busy hidpp error %02X, retrying\n", __func__, ret);
|
||||
} while (--max_retries);
|
||||
|
||||
mutex_unlock(&hidpp->send_mutex);
|
||||
@ -971,7 +976,8 @@ static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
|
||||
}
|
||||
|
||||
/* the device might not be connected */
|
||||
if (ret == HIDPP_ERROR_RESOURCE_ERROR)
|
||||
if (ret == HIDPP_ERROR_RESOURCE_ERROR ||
|
||||
ret == HIDPP_ERROR_UNKNOWN_DEVICE)
|
||||
return -EIO;
|
||||
|
||||
if (ret > 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user