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 <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2015-10-20 15:55:08 -04:00
parent 65888eedd4
commit 8ffa2f9b96
3 changed files with 17 additions and 13 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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);