Commit 198fdee2 authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Dmitry Torokhov

Input: wacom - use hidinput_calc_abs_res instead of duplicating its code

This may infer a small difference with the previous implementation
due to the DIV_ROUND_CLOSEST() in the hid implementation.
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: default avatarJason Gerecke <killertofu@gmail.com>
Tested-by: default avatarJason Gerecke <killertofu@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c669fb2b
...@@ -85,49 +85,19 @@ static void wacom_close(struct input_dev *dev) ...@@ -85,49 +85,19 @@ static void wacom_close(struct input_dev *dev)
} }
/* /*
* Calculate the resolution of the X or Y axis, given appropriate HID data. * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
* This function is little more than hidinput_calc_abs_res stripped down.
*/ */
static int wacom_calc_hid_res(int logical_extents, int physical_extents, static int wacom_calc_hid_res(int logical_extents, int physical_extents,
unsigned unit, int exponent) unsigned unit, int exponent)
{ {
int prev; struct hid_field field = {
int unit_exponent = exponent; .logical_maximum = logical_extents,
.physical_maximum = physical_extents,
/* Check if the extents are sane */ .unit = unit,
if (logical_extents <= 0 || physical_extents <= 0) .unit_exponent = exponent,
return 0; };
/* Convert physical_extents to millimeters */ return hidinput_calc_abs_res(&field, ABS_X);
if (unit == 0x11) { /* If centimeters */
unit_exponent += 1;
} else if (unit == 0x13) { /* If inches */
prev = physical_extents;
physical_extents *= 254;
if (physical_extents < prev)
return 0;
unit_exponent -= 1;
} else {
return 0;
}
/* Apply negative unit exponent */
for (; unit_exponent < 0; unit_exponent++) {
prev = logical_extents;
logical_extents *= 10;
if (logical_extents < prev)
return 0;
}
/* Apply positive unit exponent */
for (; unit_exponent > 0; unit_exponent--) {
prev = physical_extents;
physical_extents *= 10;
if (physical_extents < prev)
return 0;
}
/* Calculate resolution */
return logical_extents / physical_extents;
} }
static void wacom_feature_mapping(struct hid_device *hdev, static void wacom_feature_mapping(struct hid_device *hdev,
......
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