Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: wacom - integrate resolution calculation

Reviewed-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Ping Cheng <pingc@wacom.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Ping Cheng and committed by
Dmitry Torokhov
401d7d10 7bf2a98a

+41 -57
+37 -42
drivers/input/tablet/wacom_sys.c
··· 221 221 return logical_extents / physical_extents; 222 222 } 223 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 - /* 245 - * Static values for max X/Y and resolution of Pen interface is stored in 246 - * features. This mean physical size of active area can be computed. 247 - * This is useful to do when Pen and Touch have same active area of tablet. 248 - * This means for Touch device, we only need to find max X/Y value and we 249 - * have enough information to compute resolution of touch. 250 - */ 251 - static void wacom_set_phy_from_res(struct wacom_features *features) 252 - { 253 - features->x_phy = (features->x_max * 100) / features->x_resolution; 254 - features->y_phy = (features->y_max * 100) / features->y_resolution; 255 - } 256 - 257 224 static int wacom_parse_logical_collection(unsigned char *report, 258 225 struct wacom_features *features) 259 226 { ··· 231 264 /* Logical collection is only used by 3rd gen Bamboo Touch */ 232 265 features->pktlen = WACOM_PKGLEN_BBTOUCH3; 233 266 features->device_type = BTN_TOOL_FINGER; 234 - 235 - wacom_set_phy_from_res(features); 236 267 237 268 features->x_max = features->y_max = 238 269 get_unaligned_le16(&report[10]); ··· 605 640 } 606 641 } 607 642 error = wacom_parse_hid(intf, hid_desc, features); 608 - if (error) 609 - goto out; 610 - wacom_fix_phy_from_hid(features); 611 643 612 644 out: 613 645 return error; ··· 1190 1228 *((struct wacom_features *)id->driver_info); 1191 1229 wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3; 1192 1230 wacom_wac2->features.device_type = BTN_TOOL_FINGER; 1193 - wacom_set_phy_from_res(&wacom_wac2->features); 1194 1231 wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096; 1195 1232 error = wacom_register_input(wacom2); 1196 1233 if (error) ··· 1210 1249 wacom_wac1->input = NULL; 1211 1250 fail1: 1212 1251 return; 1252 + } 1253 + 1254 + /* 1255 + * Not all devices report physical dimensions from HID. 1256 + * Compute the default from hardcoded logical dimension 1257 + * and resolution before driver overwrites them. 1258 + */ 1259 + static void wacom_set_default_phy(struct wacom_features *features) 1260 + { 1261 + if (features->x_resolution) { 1262 + features->x_phy = (features->x_max * 100) / 1263 + features->x_resolution; 1264 + features->y_phy = (features->y_max * 100) / 1265 + features->y_resolution; 1266 + } 1267 + } 1268 + 1269 + static void wacom_calculate_res(struct wacom_features *features) 1270 + { 1271 + features->x_resolution = wacom_calc_hid_res(features->x_max, 1272 + features->x_phy, 1273 + features->unit, 1274 + features->unitExpo); 1275 + features->y_resolution = wacom_calc_hid_res(features->y_max, 1276 + features->y_phy, 1277 + features->unit, 1278 + features->unitExpo); 1213 1279 } 1214 1280 1215 1281 static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) ··· 1285 1297 1286 1298 endpoint = &intf->cur_altsetting->endpoint[0].desc; 1287 1299 1300 + /* set the default size in case we do not get them from hid */ 1301 + wacom_set_default_phy(features); 1302 + 1288 1303 /* Retrieve the physical and logical size for touch devices */ 1289 1304 error = wacom_retrieve_hid_descriptor(intf, features); 1290 1305 if (error) ··· 1303 1312 features->device_type = BTN_TOOL_FINGER; 1304 1313 features->pktlen = WACOM_PKGLEN_BBTOUCH3; 1305 1314 1306 - wacom_set_phy_from_res(features); 1307 - 1308 1315 features->x_max = 4096; 1309 1316 features->y_max = 4096; 1310 1317 } else { ··· 1311 1322 } 1312 1323 1313 1324 wacom_setup_device_quirks(features); 1325 + 1326 + /* set unit to "100th of a mm" for devices not reported by HID */ 1327 + if (!features->unit) { 1328 + features->unit = 0x11; 1329 + features->unitExpo = 16 - 3; 1330 + } 1331 + wacom_calculate_res(features); 1314 1332 1315 1333 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); 1316 1334 ··· 1329 1333 features->device_type == BTN_TOOL_PEN ? 1330 1334 " Pen" : " Finger", 1331 1335 sizeof(wacom_wac->name)); 1332 - 1333 1336 1334 1337 other_dev = wacom_get_sibling(dev, features->oVid, features->oPid); 1335 1338 if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL)
+4 -15
drivers/input/tablet/wacom_wac.c
··· 1443 1443 } 1444 1444 } 1445 1445 1446 - static unsigned int wacom_calculate_touch_res(unsigned int logical_max, 1447 - unsigned int physical_max) 1448 - { 1449 - /* Touch physical dimensions are in 100th of mm */ 1450 - return (logical_max * 100) / physical_max; 1451 - } 1452 - 1453 1446 static void wacom_abs_set_axis(struct input_dev *input_dev, 1454 1447 struct wacom_wac *wacom_wac) 1455 1448 { ··· 1466 1473 input_set_abs_params(input_dev, ABS_Y, 0, 1467 1474 features->y_max, features->y_fuzz, 0); 1468 1475 input_abs_set_res(input_dev, ABS_X, 1469 - wacom_calculate_touch_res(features->x_max, 1470 - features->x_phy)); 1476 + features->x_resolution); 1471 1477 input_abs_set_res(input_dev, ABS_Y, 1472 - wacom_calculate_touch_res(features->y_max, 1473 - features->y_phy)); 1478 + features->y_resolution); 1474 1479 } 1475 1480 1476 1481 if (features->touch_max > 1) { ··· 1477 1486 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 1478 1487 features->y_max, features->y_fuzz, 0); 1479 1488 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 1480 - wacom_calculate_touch_res(features->x_max, 1481 - features->x_phy)); 1489 + features->x_resolution); 1482 1490 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, 1483 - wacom_calculate_touch_res(features->y_max, 1484 - features->y_phy)); 1491 + features->y_resolution); 1485 1492 } 1486 1493 } 1487 1494 }