Commit b79c1aba authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: core: split data fetching from processing in hid_input_field()

This is a preparatory patch for being able to process the usages
out of order. We split the retrieval of the data in a separate function
and also split out the processing of the usages depending if the field
is an array or a variable.

No functional changes from this patch.
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: default avatarPing Cheng <ping.cheng@wacom.com>
Acked-by: default avatarPeter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 74acc277
...@@ -1544,13 +1544,12 @@ static inline int hid_array_value_is_valid(struct hid_field *field, ...@@ -1544,13 +1544,12 @@ static inline int hid_array_value_is_valid(struct hid_field *field,
} }
/* /*
* Analyse a received field, and fetch the data from it. The field * Fetch the field from the data. The field content is stored for next
* content is stored for next report processing (we do differential * report processing (we do differential reporting to the layer).
* reporting to the layer).
*/ */
static void hid_input_fetch_field(struct hid_device *hid,
static void hid_input_field(struct hid_device *hid, struct hid_field *field, struct hid_field *field,
__u8 *data, int interrupt) __u8 *data)
{ {
unsigned n; unsigned n;
unsigned count = field->report_count; unsigned count = field->report_count;
...@@ -1561,6 +1560,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, ...@@ -1561,6 +1560,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
value = field->new_value; value = field->new_value;
memset(value, 0, count * sizeof(__s32)); memset(value, 0, count * sizeof(__s32));
field->ignored = false;
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
...@@ -1572,21 +1572,56 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, ...@@ -1572,21 +1572,56 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
/* Ignore report if ErrorRollOver */ /* Ignore report if ErrorRollOver */
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) && if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
hid_array_value_is_valid(field, value[n]) && hid_array_value_is_valid(field, value[n]) &&
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) {
field->ignored = true;
return; return;
}
} }
}
for (n = 0; n < count; n++) { /*
* Process a received variable field.
*/
if (HID_MAIN_ITEM_VARIABLE & field->flags) { static void hid_input_var_field(struct hid_device *hid,
hid_process_event(hid, struct hid_field *field,
field, int interrupt)
&field->usage[n], {
value[n], unsigned int count = field->report_count;
interrupt); __s32 *value = field->new_value;
continue; unsigned int n;
}
for (n = 0; n < count; n++)
hid_process_event(hid,
field,
&field->usage[n],
value[n],
interrupt);
memcpy(field->value, value, count * sizeof(__s32));
}
/*
* Process a received array field. The field content is stored for
* next report processing (we do differential reporting to the layer).
*/
static void hid_input_array_field(struct hid_device *hid,
struct hid_field *field,
int interrupt)
{
unsigned int n;
unsigned int count = field->report_count;
__s32 min = field->logical_minimum;
__s32 *value;
value = field->new_value;
/* ErrorRollOver */
if (field->ignored)
return;
for (n = 0; n < count; n++) {
if (hid_array_value_is_valid(field, field->value[n]) && if (hid_array_value_is_valid(field, field->value[n]) &&
search(value, field->value[n], count)) search(value, field->value[n], count))
hid_process_event(hid, hid_process_event(hid,
...@@ -1607,6 +1642,31 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, ...@@ -1607,6 +1642,31 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
memcpy(field->value, value, count * sizeof(__s32)); memcpy(field->value, value, count * sizeof(__s32));
} }
/*
* Analyse a received report, and fetch the data from it. The field
* content is stored for next report processing (we do differential
* reporting to the layer).
*/
static void hid_process_report(struct hid_device *hid,
struct hid_report *report,
__u8 *data,
int interrupt)
{
unsigned int a;
struct hid_field *field;
for (a = 0; a < report->maxfield; a++) {
field = report->field[a];
hid_input_fetch_field(hid, field, data);
if (field->flags & HID_MAIN_ITEM_VARIABLE)
hid_input_var_field(hid, field, interrupt);
else
hid_input_array_field(hid, field, interrupt);
}
}
/* /*
* Output the field into the report. * Output the field into the report.
*/ */
...@@ -1768,7 +1828,6 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, ...@@ -1768,7 +1828,6 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
struct hid_report_enum *report_enum = hid->report_enum + type; struct hid_report_enum *report_enum = hid->report_enum + type;
struct hid_report *report; struct hid_report *report;
struct hid_driver *hdrv; struct hid_driver *hdrv;
unsigned int a;
u32 rsize, csize = size; u32 rsize, csize = size;
u8 *cdata = data; u8 *cdata = data;
int ret = 0; int ret = 0;
...@@ -1804,8 +1863,7 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, ...@@ -1804,8 +1863,7 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
} }
if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) { if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) {
for (a = 0; a < report->maxfield; a++) hid_process_report(hid, report, cdata, interrupt);
hid_input_field(hid, report->field[a], cdata, interrupt);
hdrv = hid->driver; hdrv = hid->driver;
if (hdrv && hdrv->report) if (hdrv && hdrv->report)
hdrv->report(hid, report); hdrv->report(hid, report);
......
...@@ -342,7 +342,7 @@ struct hid_item { ...@@ -342,7 +342,7 @@ struct hid_item {
* HID device quirks. * HID device quirks.
*/ */
/* /*
* Increase this if you need to configure more HID quirks at module load time * Increase this if you need to configure more HID quirks at module load time
*/ */
#define MAX_USBHID_BOOT_QUIRKS 4 #define MAX_USBHID_BOOT_QUIRKS 4
...@@ -483,6 +483,7 @@ struct hid_field { ...@@ -483,6 +483,7 @@ struct hid_field {
__s32 physical_maximum; __s32 physical_maximum;
__s32 unit_exponent; __s32 unit_exponent;
unsigned unit; unsigned unit;
bool ignored; /* this field is ignored in this event */
struct hid_report *report; /* associated report */ struct hid_report *report; /* associated report */
unsigned index; /* index into report->field[] */ unsigned index; /* index into report->field[] */
/* hidinput data */ /* hidinput data */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment