From 20b6e3deeb43cfe0838dee8db1c313b7856373b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sun, 15 Dec 2019 00:56:07 +0000 Subject: [PATCH] hidpp20: only populate resolutions if the device supports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch moves the 0x8100 initialization routine out of hidpp20drv_init_feature because it needs the capabilities to be processed first. Signed-off-by: Filipe LaĆ­ns --- src/driver-hidpp20.c | 53 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 9d58d385..86d3b8cb 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -1179,6 +1179,34 @@ hidpp20drv_read_profile_8100(struct ratbag_profile *profile) ratbag_profile_set_report_rate(profile, p->report_rate); } +static int +hidpp20drv_init_profile_8100(struct ratbag_device *device) +{ + struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device); + struct ratbag *ratbag = device->ratbag; + int rc; + + log_debug(ratbag, "initializing onboard profiles\n"); + rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles); + if (rc < 0) + return rc; + + rc = hidpp20_onboard_profiles_initialize(drv_data->dev, drv_data->profiles); + if (rc < 0) + return rc; + + drv_data->num_profiles = drv_data->profiles->num_profiles; + drv_data->num_buttons = drv_data->profiles->num_buttons; + + if (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201) + drv_data->num_resolutions = drv_data->profiles->num_modes; + /* We ignore the profile's num_leds and require + * HIDPP_PAGE_COLOR_LED_EFFECTS to succeed instead + */ + + return 0; +} + static void hidpp20drv_read_profile(struct ratbag_profile *profile) { @@ -1349,22 +1377,6 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) case HIDPP_PAGE_ONBOARD_PROFILES: { log_debug(ratbag, "device has onboard profiles\n"); drv_data->capabilities |= HIDPP_CAP_ONBOARD_PROFILES_8100; - - rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles); - if (rc < 0) - return rc; - - rc = hidpp20_onboard_profiles_initialize(drv_data->dev, drv_data->profiles); - if (rc < 0) - return rc; - - drv_data->num_profiles = drv_data->profiles->num_profiles; - drv_data->num_resolutions = drv_data->profiles->num_modes; - drv_data->num_buttons = drv_data->profiles->num_buttons; - /* We ignore the profile's num_leds and require - * HIDPP_PAGE_COLOR_LED_EFFECTS to succeed instead - */ - break; } case HIDPP_PAGE_MOUSE_BUTTON_SPY: { @@ -1476,6 +1488,13 @@ hidpp20drv_20_probe(struct ratbag_device *device) return rc; } + /* initializations that depend on other features */ + if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) { + rc = hidpp20drv_init_profile_8100(device); + if (rc < 0) + return rc; + } + return 0; } @@ -1592,7 +1611,7 @@ hidpp20drv_probe(struct ratbag_device *device) /* add some defaults that will be overwritten by the device */ drv_data->num_profiles = 1; - drv_data->num_resolutions = 1; + drv_data->num_resolutions = 0; drv_data->num_buttons = 8; drv_data->num_leds = 0;