From patchwork Tue Jul 3 20:47:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Dyer X-Patchwork-Id: 10505177 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 E99E3601D3 for ; Tue, 3 Jul 2018 20:55:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D612B28CE0 for ; Tue, 3 Jul 2018 20:55:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5B7528CE2; Tue, 3 Jul 2018 20:55:16 +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 0F14228CE0 for ; Tue, 3 Jul 2018 20:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752789AbeGCUzP (ORCPT ); Tue, 3 Jul 2018 16:55:15 -0400 Received: from avasout06.plus.net ([212.159.14.18]:60300 "EHLO avasout06.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752664AbeGCUzO (ORCPT ); Tue, 3 Jul 2018 16:55:14 -0400 X-Greylist: delayed 450 seconds by postgrey-1.27 at vger.kernel.org; Tue, 03 Jul 2018 16:55:14 EDT Received: from hairyalien ([80.229.148.18]) by smtp with SMTP id aSD6fpP6EWLW2aSD7fuE8Z; Tue, 03 Jul 2018 21:47:43 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=fJUXI6Se 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); Tue, 03 Jul 2018 21:47:40 +0100 From: Nick Dyer To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, Chris Healy , Nikita Yushchenko , Aleksander Morgado , Nick Dyer Subject: [PATCH v2] Input: usbtouchscreen - add strays output via sysfs Date: Tue, 3 Jul 2018 21:47:29 +0100 Message-Id: <20180703204729.14986-1-nick@shmanahar.org> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfNnkbcoElbeBmcRGSJAAIekVvfuLOdLX6Hk0gMzypeSHtsdyd7dnKEmxxzlvsTpQdFrrKLh5hdLIVrouQq6w9f3YkGLDmOcJT/ToZvTMETMyjCeWYbXw cbcociUWNa2GSuNeIu1+uVamaBMmHq8k9SjVuazlrwKHPShCh9WDxlO0CKbSeLsNyF2PX1GcmL7eEw== 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 Tested-by: Aleksander Morgado --- Changes in v2: - Values read from device must be treated as signed 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..af8fb1ab3a67 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++) { + s64 a, b; + + a = (s32)get_unaligned_le32(&sbuf->data[i*2]); + b = (s32)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);