diff options
author | Jason Gerecke <killertofu@gmail.com> | 2012-10-03 20:24:32 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-10-05 02:09:31 -0400 |
commit | 115d5e12a7d5fe62076f9dcc728905196162d709 (patch) | |
tree | f1eafc31bac96610ee6f279ffd66173cfa51c426 /drivers/input | |
parent | 9d336daf3b502f594ce18d26a3a009adb2cf3729 (diff) |
Input: wacom - introduce wacom_fix_phy_from_hid
The Cintiq 24HD touch cannot use wacom_set_phy_from_res to determine
the physical size of the touch sensor since the pen and touch are
on separate USB devices. The physical size is, however, provided in
the HID descriptor, just scaled to a unit we don't use.
This patch introduces the function wacom_fix_phy_from_hid to let
us make use of the unit and exponent data provided by HID to set
the [xy]_phy variables to an appropriate value. This function
relies on a trimmed-down version of hidinput_calc_abs_res from
the hid-input.c.
Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Ping Cheng <pingc@wacom.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/tablet/wacom_sys.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c index 0d3219f29744..b44bba2a60c2 100644 --- a/drivers/input/tablet/wacom_sys.c +++ b/drivers/input/tablet/wacom_sys.c | |||
@@ -172,6 +172,76 @@ static void wacom_close(struct input_dev *dev) | |||
172 | } | 172 | } |
173 | 173 | ||
174 | /* | 174 | /* |
175 | * Calculate the resolution of the X or Y axis, given appropriate HID data. | ||
176 | * This function is little more than hidinput_calc_abs_res stripped down. | ||
177 | */ | ||
178 | static int wacom_calc_hid_res(int logical_extents, int physical_extents, | ||
179 | unsigned char unit, unsigned char exponent) | ||
180 | { | ||
181 | int prev, unit_exponent; | ||
182 | |||
183 | /* Check if the extents are sane */ | ||
184 | if (logical_extents <= 0 || physical_extents <= 0) | ||
185 | return 0; | ||
186 | |||
187 | /* Get signed value of nybble-sized twos-compliment exponent */ | ||
188 | unit_exponent = exponent; | ||
189 | if (unit_exponent > 7) | ||
190 | unit_exponent -= 16; | ||
191 | |||
192 | /* Convert physical_extents to millimeters */ | ||
193 | if (unit == 0x11) { /* If centimeters */ | ||
194 | unit_exponent += 1; | ||
195 | } else if (unit == 0x13) { /* If inches */ | ||
196 | prev = physical_extents; | ||
197 | physical_extents *= 254; | ||
198 | if (physical_extents < prev) | ||
199 | return 0; | ||
200 | unit_exponent -= 1; | ||
201 | } else { | ||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | /* Apply negative unit exponent */ | ||
206 | for (; unit_exponent < 0; unit_exponent++) { | ||
207 | prev = logical_extents; | ||
208 | logical_extents *= 10; | ||
209 | if (logical_extents < prev) | ||
210 | return 0; | ||
211 | } | ||
212 | /* Apply positive unit exponent */ | ||
213 | for (; unit_exponent > 0; unit_exponent--) { | ||
214 | prev = physical_extents; | ||
215 | physical_extents *= 10; | ||
216 | if (physical_extents < prev) | ||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | /* Calculate resolution */ | ||
221 | return logical_extents / physical_extents; | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * The physical dimension specified by the HID descriptor is likely not in | ||
226 | * the "100th of a mm" units expected by wacom_calculate_touch_res. This | ||
227 | * function adjusts the value of [xy]_phy based on the unit and exponent | ||
228 | * provided by the HID descriptor. If an error occurs durring conversion | ||
229 | * (e.g. from the unit being left unspecified) [xy]_phy is not modified. | ||
230 | */ | ||
231 | static void wacom_fix_phy_from_hid(struct wacom_features *features) | ||
232 | { | ||
233 | int xres = wacom_calc_hid_res(features->x_max, features->x_phy, | ||
234 | features->unit, features->unitExpo); | ||
235 | int yres = wacom_calc_hid_res(features->y_max, features->y_phy, | ||
236 | features->unit, features->unitExpo); | ||
237 | |||
238 | if (xres > 0 && yres > 0) { | ||
239 | features->x_phy = (100 * features->x_max) / xres; | ||
240 | features->y_phy = (100 * features->y_max) / yres; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /* | ||
175 | * Static values for max X/Y and resolution of Pen interface is stored in | 245 | * Static values for max X/Y and resolution of Pen interface is stored in |
176 | * features. This mean physical size of active area can be computed. | 246 | * features. This mean physical size of active area can be computed. |
177 | * This is useful to do when Pen and Touch have same active area of tablet. | 247 | * This is useful to do when Pen and Touch have same active area of tablet. |
@@ -531,6 +601,7 @@ static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, | |||
531 | error = wacom_parse_hid(intf, hid_desc, features); | 601 | error = wacom_parse_hid(intf, hid_desc, features); |
532 | if (error) | 602 | if (error) |
533 | goto out; | 603 | goto out; |
604 | wacom_fix_phy_from_hid(features); | ||
534 | 605 | ||
535 | out: | 606 | out: |
536 | return error; | 607 | return error; |