From 5ed98fdb2206087ca6b078212dbeb343dea8eefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sun, 15 Dec 2019 17:05:50 +0000 Subject: [PATCH] hidpp20: only enable 0x8070 or 0x8071 if 0x8100 is present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- src/driver-hidpp20.c | 54 ++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 86d3b8cb..28da82be 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -1179,6 +1179,38 @@ hidpp20drv_read_profile_8100(struct ratbag_profile *profile) ratbag_profile_set_report_rate(profile, p->report_rate); } +static int +hidpp20drv_init_leds_8070_8071(struct ratbag_device *device) +{ + struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device); + struct ratbag *ratbag = device->ratbag; + + /* we only support 0x8070/0x8071 via 0x8100 */ + if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)) { + if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070) { + log_debug(ratbag, "disabling 0x8070 (Color Leds Effects) feature because the device doesn't have 0x8100 (Onboard Memory Profiles)\n"); + drv_data->capabilities &= !HIDPP_CAP_COLOR_LED_EFFECTS_8070; + } + + if (drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) { + log_debug(ratbag, "disabling 0x8071 (RGB Effects) feature because the device doesn't have 0x8100 (Onboard Memory Profiles)\n"); + drv_data->capabilities &= !HIDPP_CAP_RGB_EFFECTS_8071; + } + } + + if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070 || + drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) { + /* we read the profile once to get the correct number of + * supported leds. */ + if (hidpp20drv_read_color_leds(device)) + return 0; + + device->num_leds = drv_data->num_leds; + } + + return 0; +} + static int hidpp20drv_init_profile_8100(struct ratbag_device *device) { @@ -1341,25 +1373,11 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) log_debug(ratbag, "device has color effects\n"); drv_data->capabilities |= HIDPP_CAP_COLOR_LED_EFFECTS_8070; - - /* we read the profile once to get the correct number of - * supported leds. */ - if (hidpp20drv_read_color_leds(device)) - return 0; - - device->num_leds = drv_data->num_leds; break; } case HIDPP_PAGE_RGB_EFFECTS: { log_debug(ratbag, "device has color effects\n"); drv_data->capabilities |= HIDPP_CAP_RGB_EFFECTS_8071; - - /* we read the profile once to get the correct number of - * supported leds. */ - if (hidpp20drv_read_color_leds(device)) - return 0; - - device->num_leds = drv_data->num_leds; break; } case HIDPP_PAGE_LED_SW_CONTROL: { @@ -1489,6 +1507,13 @@ hidpp20drv_20_probe(struct ratbag_device *device) } /* initializations that depend on other features */ + if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070 || + drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) { + rc = hidpp20drv_init_leds_8070_8071(device); + if (rc < 0) + return rc; + } + if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) { rc = hidpp20drv_init_profile_8100(device); if (rc < 0) @@ -1496,7 +1521,6 @@ hidpp20drv_20_probe(struct ratbag_device *device) } return 0; - } static int