aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2017-08-30 18:13:26 -0400
committerJiri Kosina <jkosina@suse.cz>2017-09-06 05:01:19 -0400
commitd252f4a10fb9c8f7187c6c936ff530039f8cb799 (patch)
treec728c8d48a39d9030547daaa5d77e4b254300772
parentb63c4c2718d641ba9bec888994f0cb0c23a1ef45 (diff)
HID: wacom: Correct coordinate system of touchring and pen twist
The MobileStudio Pro, Cintiq Pro, and 2nd-gen Intuos Pro devices use a different coordinate system for their touchring and pen twist than prior devices. Prior devices had zero aligned to the tablet's left and would increase clockwise. Userspace expects data from the kernel to be in this old coordinate space, so adjustments are necessary. While the coordinate system for pen twist is formally defined by the HID standard, no such definition existed for the touchring at the time these tablets were introduced. Future tablets are expected to report touchring data using the same "zero-up clockwise-increasing" coordinate system defined for twist. Fixes: 50066a042d ("HID: wacom: generic: Add support for height, tilt, and twist usages") Fixes: 4922cd26f0 ("HID: wacom: Support 2nd-gen Intuos Pro's Bluetooth classic interface") Fixes: 60a2218698 ("HID: wacom: generic: add support for touchring") Cc: stable@vger.kernel.org # 4.10, 4.11 Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com> Reviewed-by: Ping Cheng <ping.cheng@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/wacom_wac.c73
1 files changed, 68 insertions, 5 deletions
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 1d9e32d2bc63..78d0398904dc 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1227,11 +1227,17 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1227 continue; 1227 continue;
1228 1228
1229 if (range) { 1229 if (range) {
1230 /* Fix rotation alignment: userspace expects zero at left */
1231 int16_t rotation = (int16_t)get_unaligned_le16(&frame[9]);
1232 rotation += 1800/4;
1233 if (rotation > 899)
1234 rotation -= 1800;
1235
1230 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1])); 1236 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
1231 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3])); 1237 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
1232 input_report_abs(pen_input, ABS_TILT_X, (char)frame[7]); 1238 input_report_abs(pen_input, ABS_TILT_X, (char)frame[7]);
1233 input_report_abs(pen_input, ABS_TILT_Y, (char)frame[8]); 1239 input_report_abs(pen_input, ABS_TILT_Y, (char)frame[8]);
1234 input_report_abs(pen_input, ABS_Z, (int16_t)get_unaligned_le16(&frame[9])); 1240 input_report_abs(pen_input, ABS_Z, rotation);
1235 input_report_abs(pen_input, ABS_WHEEL, get_unaligned_le16(&frame[11])); 1241 input_report_abs(pen_input, ABS_WHEEL, get_unaligned_le16(&frame[11]));
1236 } 1242 }
1237 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5])); 1243 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
@@ -1319,12 +1325,19 @@ static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
1319 unsigned char *data = wacom->data; 1325 unsigned char *data = wacom->data;
1320 1326
1321 int buttons = (data[282] << 1) | ((data[281] >> 6) & 0x01); 1327 int buttons = (data[282] << 1) | ((data[281] >> 6) & 0x01);
1322 int ring = data[285]; 1328 int ring = data[285] & 0x7F;
1323 int prox = buttons | (ring & 0x80); 1329 bool ringstatus = data[285] & 0x80;
1330 bool prox = buttons || ringstatus;
1331
1332 /* Fix touchring data: userspace expects 0 at left and increasing clockwise */
1333 ring = 71 - ring;
1334 ring += 3*72/16;
1335 if (ring > 71)
1336 ring -= 72;
1324 1337
1325 wacom_report_numbered_buttons(pad_input, 9, buttons); 1338 wacom_report_numbered_buttons(pad_input, 9, buttons);
1326 1339
1327 input_report_abs(pad_input, ABS_WHEEL, (ring & 0x80) ? (ring & 0x7f) : 0); 1340 input_report_abs(pad_input, ABS_WHEEL, ringstatus ? ring : 0);
1328 1341
1329 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0); 1342 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
1330 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0); 1343 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
@@ -1616,6 +1629,20 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1616 return 0; 1629 return 0;
1617} 1630}
1618 1631
1632static int wacom_offset_rotation(struct input_dev *input, struct hid_usage *usage,
1633 int value, int num, int denom)
1634{
1635 struct input_absinfo *abs = &input->absinfo[usage->code];
1636 int range = (abs->maximum - abs->minimum + 1);
1637
1638 value += num*range/denom;
1639 if (value > abs->maximum)
1640 value -= range;
1641 else if (value < abs->minimum)
1642 value += range;
1643 return value;
1644}
1645
1619int wacom_equivalent_usage(int usage) 1646int wacom_equivalent_usage(int usage)
1620{ 1647{
1621 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) { 1648 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
@@ -1898,6 +1925,7 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
1898 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); 1925 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1899 int i; 1926 int i;
1900 bool is_touch_on = value; 1927 bool is_touch_on = value;
1928 bool do_report = false;
1901 1929
1902 /* 1930 /*
1903 * Avoid reporting this event and setting inrange_state if this usage 1931 * Avoid reporting this event and setting inrange_state if this usage
@@ -1912,6 +1940,29 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
1912 } 1940 }
1913 1941
1914 switch (equivalent_usage) { 1942 switch (equivalent_usage) {
1943 case WACOM_HID_WD_TOUCHRING:
1944 /*
1945 * Userspace expects touchrings to increase in value with
1946 * clockwise gestures and have their zero point at the
1947 * tablet's left. HID events "should" be clockwise-
1948 * increasing and zero at top, though the MobileStudio
1949 * Pro and 2nd-gen Intuos Pro don't do this...
1950 */
1951 if (hdev->vendor == 0x56a &&
1952 (hdev->product == 0x34d || hdev->product == 0x34e || /* MobileStudio Pro */
1953 hdev->product == 0x357 || hdev->product == 0x358)) { /* Intuos Pro 2 */
1954 value = (field->logical_maximum - value);
1955
1956 if (hdev->product == 0x357 || hdev->product == 0x358)
1957 value = wacom_offset_rotation(input, usage, value, 3, 16);
1958 else if (hdev->product == 0x34d || hdev->product == 0x34e)
1959 value = wacom_offset_rotation(input, usage, value, 1, 2);
1960 }
1961 else {
1962 value = wacom_offset_rotation(input, usage, value, 1, 4);
1963 }
1964 do_report = true;
1965 break;
1915 case WACOM_HID_WD_TOUCHRINGSTATUS: 1966 case WACOM_HID_WD_TOUCHRINGSTATUS:
1916 if (!value) 1967 if (!value)
1917 input_event(input, usage->type, usage->code, 0); 1968 input_event(input, usage->type, usage->code, 0);
@@ -1945,10 +1996,14 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
1945 value, i); 1996 value, i);
1946 /* fall through*/ 1997 /* fall through*/
1947 default: 1998 default:
1999 do_report = true;
2000 break;
2001 }
2002
2003 if (do_report) {
1948 input_event(input, usage->type, usage->code, value); 2004 input_event(input, usage->type, usage->code, value);
1949 if (value) 2005 if (value)
1950 wacom_wac->hid_data.pad_input_event_flag = true; 2006 wacom_wac->hid_data.pad_input_event_flag = true;
1951 break;
1952 } 2007 }
1953} 2008}
1954 2009
@@ -2089,6 +2144,14 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field
2089 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL); 2144 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
2090 wacom_wac->serial[0] |= (__u32)value; 2145 wacom_wac->serial[0] |= (__u32)value;
2091 return; 2146 return;
2147 case HID_DG_TWIST:
2148 /*
2149 * Userspace expects pen twist to have its zero point when
2150 * the buttons/finger is on the tablet's left. HID values
2151 * are zero when buttons are toward the top.
2152 */
2153 value = wacom_offset_rotation(input, usage, value, 1, 4);
2154 break;
2092 case WACOM_HID_WD_SENSE: 2155 case WACOM_HID_WD_SENSE:
2093 wacom_wac->hid_data.sense_state = value; 2156 wacom_wac->hid_data.sense_state = value;
2094 return; 2157 return;