From patchwork Mon Jul 2 20:38:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Dyer X-Patchwork-Id: 10502373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 186EA60362 for ; Mon, 2 Jul 2018 20:46:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1F3728DFA for ; Mon, 2 Jul 2018 20:46:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFE5F28DF0; Mon, 2 Jul 2018 20:46:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 346F228D64 for ; Mon, 2 Jul 2018 20:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbeGBUqA (ORCPT ); Mon, 2 Jul 2018 16:46:00 -0400 Received: from avasout05.plus.net ([84.93.230.250]:58551 "EHLO avasout05.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752437AbeGBUqA (ORCPT ); Mon, 2 Jul 2018 16:46:00 -0400 X-Greylist: delayed 450 seconds by postgrey-1.27 at vger.kernel.org; Mon, 02 Jul 2018 16:45:59 EDT Received: from hairyalien ([80.229.148.18]) by smtp with SMTP id a5abfdGKK05ija5acf685f; Mon, 02 Jul 2018 21:38:28 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=QJJGuDDL c=1 sm=1 tr=0 a=o7Djd4SkmPXITDn8qH+ssQ==:117 a=o7Djd4SkmPXITDn8qH+ssQ==:17 a=R9QF1RCXAYgA:10 a=beXlt2xKAAAA:8 a=7EL00SUna8D0a4yJQBIA:9 a=gcY2M4Ci8LIz02MwfSIM:22 Received: by hairyalien (sSMTP sendmail emulation); Mon, 02 Jul 2018 21:38:25 +0100 From: Nick Dyer To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, Chris Healy , Nikita Yushchenko , Aleksander Morgado , Nick Dyer Subject: [PATCH v1] Input: usbtouchscreen - add strays output via sysfs Date: Mon, 2 Jul 2018 21:38:13 +0100 Message-Id: <20180702203813.5795-1-nick@shmanahar.org> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfCO8voq+uUN0Pe7EEGvG3d3lPZ+jgu2KW2Wv4nxoBQ/rukoYo3iq/FNU7H43fPRUl9Yx4MbkZ2CLWNc217VUauBHewaAjQ0RikGOeBYtCO5b2+cJTDr9 JDvXtJQ9vmcMavbMVXKT5t4lytcGWQhN4qJplQ8kNsJG1E3WnjVwauEtjiIjMo3N3IKrcXtG69TDgA== Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With surface capacitance touchscreens the capacitance is measured through readings obtained from measurements taken at the four corners of the glass. These measurements are accessible in the I/Q modulation format from the the controller which becomes meaningful data when converted to an absolute value using the pythagorean theorem. Signed-off-by: Nick Dyer --- drivers/input/touchscreen/usbtouchscreen.c | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c index d61570d64ee7..742abd158b08 100644 --- a/drivers/input/touchscreen/usbtouchscreen.c +++ b/drivers/input/touchscreen/usbtouchscreen.c @@ -55,6 +55,7 @@ #include #include #include +#include static bool swap_xy; module_param(swap_xy, bool, 0644); @@ -437,11 +438,18 @@ static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt) #ifdef CONFIG_TOUCHSCREEN_USB_3M #define MTOUCHUSB_ASYNC_REPORT 1 +#define MTOUCHUSB_GET_BLOCK 2 +#define MTOUCHUSB_STRAYS_BLOCK_CMD 3 #define MTOUCHUSB_RESET 7 #define MTOUCHUSB_REQ_CTRLLR_ID 10 #define MTOUCHUSB_REQ_CTRLLR_ID_LEN 16 +struct mtouch_strays { + u8 hdr[3]; + __le32 data[8]; +} __attribute__ ((packed)); + static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) { if (hwcalib_xy) { @@ -459,8 +467,22 @@ static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) struct mtouch_priv { u8 fw_rev_major; u8 fw_rev_minor; + u64 strays[4]; }; +static ssize_t mtouch_strays_show(struct device *dev, + struct device_attribute *attr, char *output) +{ + struct usb_interface *intf = to_usb_interface(dev); + struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); + struct mtouch_priv *priv = usbtouch->priv; + + return scnprintf(output, PAGE_SIZE, "ul=%llu ur=%llu ll=%llu lr=%llu\n", + priv->strays[0], priv->strays[1], + priv->strays[2], priv->strays[3]); +} +static DEVICE_ATTR(strays, 0444, mtouch_strays_show, NULL); + static ssize_t mtouch_firmware_rev_show(struct device *dev, struct device_attribute *attr, char *output) { @@ -475,6 +497,7 @@ static DEVICE_ATTR(firmware_rev, 0444, mtouch_firmware_rev_show, NULL); static struct attribute *mtouch_attrs[] = { &dev_attr_firmware_rev.attr, + &dev_attr_strays.attr, NULL }; @@ -482,6 +505,39 @@ static const struct attribute_group mtouch_attr_group = { .attrs = mtouch_attrs, }; +static void mtouch_get_strays_report(struct usbtouch_usb *usbtouch) +{ + struct usb_device *udev = interface_to_usbdev(usbtouch->interface); + struct mtouch_priv *priv = usbtouch->priv; + struct mtouch_strays *sbuf; + int ret; + int i; + + sbuf = kzalloc(sizeof(struct mtouch_strays), GFP_NOIO); + if (!sbuf) + return; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + MTOUCHUSB_GET_BLOCK, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + MTOUCHUSB_STRAYS_BLOCK_CMD, + 0, sbuf, sizeof(struct mtouch_strays), + USB_CTRL_SET_TIMEOUT); + if (ret != sizeof(struct mtouch_strays)) + goto out_free; + + for (i = 0; i < 4; i++) { + u64 a, b; + + a = get_unaligned_le32(&sbuf->data[i*2]); + b = get_unaligned_le32(&sbuf->data[i*2 + 1]); + priv->strays[i] = int_sqrt64(a * a + b * b); + } + +out_free: + kfree(sbuf); +} + static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch) { struct usb_device *udev = interface_to_usbdev(usbtouch->interface); @@ -568,6 +624,8 @@ static int mtouch_init(struct usbtouch_usb *usbtouch) return ret; } + mtouch_get_strays_report(usbtouch); + /* Default min/max xy are the raw values, override if using hw-calib */ if (hwcalib_xy) { input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);