From patchwork Fri Jul 19 23:10:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ping Cheng X-Patchwork-Id: 2830719 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C7B7A9F4D5 for ; Fri, 19 Jul 2013 23:11:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9BB3420173 for ; Fri, 19 Jul 2013 23:11:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5125220161 for ; Fri, 19 Jul 2013 23:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753081Ab3GSXLI (ORCPT ); Fri, 19 Jul 2013 19:11:08 -0400 Received: from mail-pb0-f51.google.com ([209.85.160.51]:64376 "EHLO mail-pb0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752772Ab3GSXLH (ORCPT ); Fri, 19 Jul 2013 19:11:07 -0400 Received: by mail-pb0-f51.google.com with SMTP id um15so4964521pbc.10 for ; Fri, 19 Jul 2013 16:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=hp23xDv9ldhZp+2SnoixE8bu6WqATZDtMQKJf+Y7WtA=; b=nc0Iwy2HQda8Uga7bvknSflE5ZWlALZebWr2CINXthF55jcH0IUffwVTmn+EbxbP5j LvGPdcXkD2dK7QKTBLjdpaCK43STZizz5Zztl3hWUeYwEjx7DXrDhz9h7lmeFbCQcKNo Itw+HKyi9JcJ6FuYfmpYUcv0kLLWlUj5mYySFv6R8zeDzh8PFQGjRe83ttXE7ffpGSAw MBOcCARbCL14GImNDEzfRfMjUNCMZhliOSIvo0zW8PYPvaMZqvBUUtxAbDW7VKsFzOxV 6K6ifqTnwaM8Pjj092fpQ12VTu9dHvwi++E9OLmLbBoaTHHCHJviJd0SlI4bQ3dQpfSP ACIg== X-Received: by 10.68.192.103 with SMTP id hf7mr19468937pbc.168.1374275466732; Fri, 19 Jul 2013 16:11:06 -0700 (PDT) Received: from wacom-XPS-8500.wacom.com ([67.51.163.2]) by mx.google.com with ESMTPSA id bs3sm21654009pbc.42.2013.07.19.16.11.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Jul 2013 16:11:05 -0700 (PDT) From: Ping Cheng To: linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, Ping Cheng Subject: [PATCH] input : wacom - Integrate resolution calculation Date: Fri, 19 Jul 2013 16:10:55 -0700 Message-Id: <1374275455-28465-1-git-send-email-pingc@wacom.com> X-Mailer: git-send-email 1.8.1.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reviewed-by: Jason Gerecke Tested-by: Jason Gerecke Signed-off-by: Ping Cheng --- drivers/input/tablet/wacom_sys.c | 75 ++++++++++++++++++---------------------- drivers/input/tablet/wacom_wac.c | 19 +++------- 2 files changed, 37 insertions(+), 57 deletions(-) diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c index aaf23ae..0ca248a 100644 --- a/drivers/input/tablet/wacom_sys.c +++ b/drivers/input/tablet/wacom_sys.c @@ -221,39 +221,6 @@ static int wacom_calc_hid_res(int logical_extents, int physical_extents, return logical_extents / physical_extents; } -/* - * The physical dimension specified by the HID descriptor is likely not in - * the "100th of a mm" units expected by wacom_calculate_touch_res. This - * function adjusts the value of [xy]_phy based on the unit and exponent - * provided by the HID descriptor. If an error occurs durring conversion - * (e.g. from the unit being left unspecified) [xy]_phy is not modified. - */ -static void wacom_fix_phy_from_hid(struct wacom_features *features) -{ - int xres = wacom_calc_hid_res(features->x_max, features->x_phy, - features->unit, features->unitExpo); - int yres = wacom_calc_hid_res(features->y_max, features->y_phy, - features->unit, features->unitExpo); - - if (xres > 0 && yres > 0) { - features->x_phy = (100 * features->x_max) / xres; - features->y_phy = (100 * features->y_max) / yres; - } -} - -/* - * Static values for max X/Y and resolution of Pen interface is stored in - * features. This mean physical size of active area can be computed. - * This is useful to do when Pen and Touch have same active area of tablet. - * This means for Touch device, we only need to find max X/Y value and we - * have enough information to compute resolution of touch. - */ -static void wacom_set_phy_from_res(struct wacom_features *features) -{ - features->x_phy = (features->x_max * 100) / features->x_resolution; - features->y_phy = (features->y_max * 100) / features->y_resolution; -} - static int wacom_parse_logical_collection(unsigned char *report, struct wacom_features *features) { @@ -265,8 +232,6 @@ static int wacom_parse_logical_collection(unsigned char *report, features->pktlen = WACOM_PKGLEN_BBTOUCH3; features->device_type = BTN_TOOL_FINGER; - wacom_set_phy_from_res(features); - features->x_max = features->y_max = get_unaligned_le16(&report[10]); @@ -640,9 +605,6 @@ static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, } } error = wacom_parse_hid(intf, hid_desc, features); - if (error) - goto out; - wacom_fix_phy_from_hid(features); out: return error; @@ -1228,7 +1190,6 @@ static void wacom_wireless_work(struct work_struct *work) *((struct wacom_features *)id->driver_info); wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3; wacom_wac2->features.device_type = BTN_TOOL_FINGER; - wacom_set_phy_from_res(&wacom_wac2->features); wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096; error = wacom_register_input(wacom2); if (error) @@ -1251,6 +1212,29 @@ fail1: return; } +/* + * Not all devices report physical dimensions from HID. + * Compute the default from hardcoded logical dimension + * and resolution before driver overwrites them. + */ +static void wacom_set_default_phy(struct wacom_features *features) +{ + if (features->x_resolution) { + features->x_phy = (features->x_max * 100) / features->x_resolution; + features->y_phy = (features->y_max * 100) / features->y_resolution; + } +} + +static void wacom_calculate_res(struct wacom_features *features) +{ + features->x_resolution = wacom_calc_hid_res(features->x_max, + features->x_phy, features->unit, + features->unitExpo); + features->y_resolution = wacom_calc_hid_res(features->y_max, + features->y_phy, features->unit, + features->unitExpo); +} + static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *dev = interface_to_usbdev(intf); @@ -1297,6 +1281,9 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i endpoint = &intf->cur_altsetting->endpoint[0].desc; + /* set the default size in case we do not get them from hid */ + wacom_set_default_phy(features); + /* Retrieve the physical and logical size for touch devices */ error = wacom_retrieve_hid_descriptor(intf, features); if (error) @@ -1312,8 +1299,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i features->device_type = BTN_TOOL_FINGER; features->pktlen = WACOM_PKGLEN_BBTOUCH3; - wacom_set_phy_from_res(features); - features->x_max = 4096; features->y_max = 4096; } else { @@ -1323,6 +1308,13 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i wacom_setup_device_quirks(features); + /* set unit to "100th of a mm" for devices not reported by HID */ + if (!features->unit) { + features->unit = 0x11; + features->unitExpo = 16-3; + } + wacom_calculate_res(features); + strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { @@ -1334,7 +1326,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i " Pen" : " Finger", sizeof(wacom_wac->name)); - other_dev = wacom_get_sibling(dev, features->oVid, features->oPid); if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL) other_dev = dev; diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c index 384fbcd..7d691a5 100644 --- a/drivers/input/tablet/wacom_wac.c +++ b/drivers/input/tablet/wacom_wac.c @@ -1445,13 +1445,6 @@ void wacom_setup_device_quirks(struct wacom_features *features) } } -static unsigned int wacom_calculate_touch_res(unsigned int logical_max, - unsigned int physical_max) -{ - /* Touch physical dimensions are in 100th of mm */ - return (logical_max * 100) / physical_max; -} - static void wacom_abs_set_axis(struct input_dev *input_dev, struct wacom_wac *wacom_wac) { @@ -1475,11 +1468,9 @@ static void wacom_abs_set_axis(struct input_dev *input_dev, input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, features->y_fuzz, 0); input_abs_set_res(input_dev, ABS_X, - wacom_calculate_touch_res(features->x_max, - features->x_phy)); + features->x_resolution); input_abs_set_res(input_dev, ABS_Y, - wacom_calculate_touch_res(features->y_max, - features->y_phy)); + features->y_resolution); } if (features->touch_max > 1) { @@ -1488,11 +1479,9 @@ static void wacom_abs_set_axis(struct input_dev *input_dev, input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, features->y_max, features->y_fuzz, 0); input_abs_set_res(input_dev, ABS_MT_POSITION_X, - wacom_calculate_touch_res(features->x_max, - features->x_phy)); + features->x_resolution); input_abs_set_res(input_dev, ABS_MT_POSITION_Y, - wacom_calculate_touch_res(features->y_max, - features->y_phy)); + features->y_resolution); } } }