From 8ffa2f9b9605188a7a5f4431d6eafecf525810e6 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 20 Oct 2015 15:55:08 -0400 Subject: [PATCH] hidpp20: retrieve the protocol version in hidpp20.c We need hidpp20 to handle the list of available features. So we need to be sure in hidpp20 that we are talking to a hidpp20 device. Move the version retrieval in hidpp20 where it makes sense. Signed-off-by: Benjamin Tissoires --- src/driver-hidpp20.c | 15 ++------------- src/hidpp20.c | 13 +++++++++++++ src/hidpp20.h | 2 ++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index ed889edb..a84f5496 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -54,8 +54,6 @@ struct hidpp20drv_data { struct hidpp20_device *dev; - unsigned proto_major; - unsigned proto_minor; unsigned long capabilities; unsigned num_sensors; struct hidpp20_sensor *sensors; @@ -496,19 +494,10 @@ hidpp20drv_probe(struct ratbag_device *device) } drv_data->dev = dev; - drv_data->proto_major = 1; - drv_data->proto_minor = 0; - rc = hidpp20_root_get_protocol_version(drv_data->dev, &drv_data->proto_major, &drv_data->proto_minor); - if (rc) { - /* communication error, best to ignore the device */ - rc = -EINVAL; - goto err; - } + log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), dev->proto_major, dev->proto_minor); - log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), drv_data->proto_major, drv_data->proto_minor); - - if (drv_data->proto_major >= 2) { + if (dev->proto_major >= 2) { rc = hidpp20drv_20_probe(device); if (rc) goto err; diff --git a/src/hidpp20.c b/src/hidpp20.c index 954704cc..f02aa704 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -915,13 +915,26 @@ struct hidpp20_device * hidpp20_device_new(const struct hidpp_device *base, unsigned int idx) { struct hidpp20_device *dev; + int rc; dev = zalloc(sizeof(*dev)); dev->index = idx; dev->base = *base; + dev->proto_major = 1; + dev->proto_minor = 0; + + rc = hidpp20_root_get_protocol_version(dev, &dev->proto_major, &dev->proto_minor); + if (rc) { + /* communication error, best to ignore the device */ + goto err; + } + return dev; +err: + free(dev); + return NULL; } void diff --git a/src/hidpp20.h b/src/hidpp20.h index ccab08dd..2abc41bc 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -49,6 +49,8 @@ union hidpp20_message { struct hidpp20_device { struct hidpp_device base; unsigned int index; + unsigned proto_major; + unsigned proto_minor; }; int hidpp20_request_command(struct hidpp20_device *dev, union hidpp20_message *msg);