aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/tablet/wacom_sys.c
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2014-07-24 16:03:05 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-07-25 21:53:55 -0400
commit198fdee2829547ec4ff29bb56ea668790d23bc4b (patch)
tree9a054b2cd421e7f4451ffb96b3eef5e19fd49aef /drivers/input/tablet/wacom_sys.c
parentc669fb2b9ac47682b53f0a97d55c7ae4f2f3eaee (diff)
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: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: Jason Gerecke <killertofu@gmail.com> Tested-by: Jason Gerecke <killertofu@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/tablet/wacom_sys.c')
-rw-r--r--drivers/input/tablet/wacom_sys.c48
1 files changed, 9 insertions, 39 deletions
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index ed27e7da5444..06e304b3bbfd 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -85,49 +85,19 @@ static void wacom_close(struct input_dev *dev)
85} 85}
86 86
87/* 87/*
88 * Calculate the resolution of the X or Y axis, given appropriate HID data. 88 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
89 * This function is little more than hidinput_calc_abs_res stripped down.
90 */ 89 */
91static int wacom_calc_hid_res(int logical_extents, int physical_extents, 90static int wacom_calc_hid_res(int logical_extents, int physical_extents,
92 unsigned unit, int exponent) 91 unsigned unit, int exponent)
93{ 92{
94 int prev; 93 struct hid_field field = {
95 int unit_exponent = exponent; 94 .logical_maximum = logical_extents,
96 95 .physical_maximum = physical_extents,
97 /* Check if the extents are sane */ 96 .unit = unit,
98 if (logical_extents <= 0 || physical_extents <= 0) 97 .unit_exponent = exponent,
99 return 0; 98 };
100 99
101 /* Convert physical_extents to millimeters */ 100 return hidinput_calc_abs_res(&field, ABS_X);
102 if (unit == 0x11) { /* If centimeters */
103 unit_exponent += 1;
104 } else if (unit == 0x13) { /* If inches */
105 prev = physical_extents;
106 physical_extents *= 254;
107 if (physical_extents < prev)
108 return 0;
109 unit_exponent -= 1;
110 } else {
111 return 0;
112 }
113
114 /* Apply negative unit exponent */
115 for (; unit_exponent < 0; unit_exponent++) {
116 prev = logical_extents;
117 logical_extents *= 10;
118 if (logical_extents < prev)
119 return 0;
120 }
121 /* Apply positive unit exponent */
122 for (; unit_exponent > 0; unit_exponent--) {
123 prev = physical_extents;
124 physical_extents *= 10;
125 if (physical_extents < prev)
126 return 0;
127 }
128
129 /* Calculate resolution */
130 return logical_extents / physical_extents;
131} 101}
132 102
133static void wacom_feature_mapping(struct hid_device *hdev, 103static void wacom_feature_mapping(struct hid_device *hdev,