From patchwork Thu May 3 21:47:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Dyer X-Patchwork-Id: 10379369 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 3CB3F60159 for ; Thu, 3 May 2018 21:47:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DE1D291C4 for ; Thu, 3 May 2018 21:47:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22191292A5; Thu, 3 May 2018 21:47:45 +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 8612B2928C for ; Thu, 3 May 2018 21:47:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751190AbeECVrn (ORCPT ); Thu, 3 May 2018 17:47:43 -0400 Received: from avasout06.plus.net ([212.159.14.18]:45548 "EHLO avasout06.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751178AbeECVrn (ORCPT ); Thu, 3 May 2018 17:47:43 -0400 Received: from hairyalien ([80.229.148.18]) by smtp with SMTP id EM4hftxUFy3jiEM4jf0Nxd; Thu, 03 May 2018 22:47:42 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=fL8XI6Se c=1 sm=1 tr=0 a=o7Djd4SkmPXITDn8qH+ssQ==:117 a=o7Djd4SkmPXITDn8qH+ssQ==:17 a=VUJBJC2UJ8kA:10 a=beXlt2xKAAAA:8 a=7EL00SUna8D0a4yJQBIA:9 a=gcY2M4Ci8LIz02MwfSIM:22 Received: by hairyalien (sSMTP sendmail emulation); Thu, 03 May 2018 22:47:39 +0100 From: Nick Dyer To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, Chris Healy , Nick Dyer Subject: [PATCH v2] Input: usbtouchscreen - add sysfs attribute for 3M MTouch firmware rev Date: Thu, 3 May 2018 22:47:34 +0100 Message-Id: <20180503214734.27141-1-nick@shmanahar.org> X-Mailer: git-send-email 2.14.1 X-CMAE-Envelope: MS4wfB4+ICR3CD8o1jtLIxyUbsHJfmU3/5EQY1+NBaFvFAzHVbRXDZDNQU+EG+k0Pt1sYevyV/igSSra2C4cfhxspPB4uwDlSEXoKDZj6yx2ACRauTudAX8H HW7aOxPMQH6u0eIdAEMCT5yh7RWCL59LwdSCp3XchvTMx8S8n/iovEWC 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 [v2: output fw rev on probe] Signed-off-by: Nick Dyer Tested-By: Nikita Yushchenko --- drivers/input/touchscreen/usbtouchscreen.c | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c index c6cf90868503..6d4e3d5e738e 100644 --- a/drivers/input/touchscreen/usbtouchscreen.c +++ b/drivers/input/touchscreen/usbtouchscreen.c @@ -440,6 +440,8 @@ static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt) #define MTOUCHUSB_RESET 7 #define MTOUCHUSB_REQ_CTRLLR_ID 10 +#define MTOUCHUSB_REQ_CTRLLR_ID_LEN 16 + static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) { if (hwcalib_xy) { @@ -454,11 +456,87 @@ static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) return 1; } +struct mtouch_priv { + u8 fw_rev_major; + u8 fw_rev_minor; +}; + +static ssize_t mtouch_firmware_rev_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, "%1x.%1x\n", + priv->fw_rev_major, priv->fw_rev_minor); +} +static DEVICE_ATTR(firmware_rev, 0444, mtouch_firmware_rev_show, NULL); + +static struct attribute *mtouch_attrs[] = { + &dev_attr_firmware_rev.attr, + NULL +}; + +static const struct attribute_group mtouch_attr_group = { + .attrs = mtouch_attrs, +}; + +static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch) +{ + int ret; + struct usb_device *udev = interface_to_usbdev(usbtouch->interface); + struct mtouch_priv *priv = usbtouch->priv; + u8 *buf; + + buf = kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN, GFP_NOIO); + if (!buf) + return -ENOMEM; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + MTOUCHUSB_REQ_CTRLLR_ID, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 0, 0, buf, MTOUCHUSB_REQ_CTRLLR_ID_LEN, + USB_CTRL_SET_TIMEOUT); + if (ret != MTOUCHUSB_REQ_CTRLLR_ID_LEN) { + dev_warn(&usbtouch->interface->dev, + "Failed to read FW rev: %d\n", ret); + ret = (ret < 0) ? ret : -EIO; + goto free; + } + + priv->fw_rev_major = buf[3]; + priv->fw_rev_minor = buf[4]; + + dev_info(&usbtouch->interface->dev, + "3M Microtouch firmware revision: %1x.%1x\n", + priv->fw_rev_major, priv->fw_rev_minor); + + ret = 0; + +free: + kfree(buf); + return ret; +} + +static int mtouch_alloc(struct usbtouch_usb *usbtouch) +{ + usbtouch->priv = kmalloc(sizeof(struct mtouch_priv), GFP_KERNEL); + if (!usbtouch->priv) + return -ENOMEM; + + return 0; +} + static int mtouch_init(struct usbtouch_usb *usbtouch) { int ret, i; struct usb_device *udev = interface_to_usbdev(usbtouch->interface); + ret = mtouch_get_fw_revision(usbtouch); + if (ret) + return ret; + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), MTOUCHUSB_RESET, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, @@ -490,8 +568,18 @@ static int mtouch_init(struct usbtouch_usb *usbtouch) input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0); } + ret = sysfs_create_group(&usbtouch->interface->dev.kobj, + &mtouch_attr_group); + if (ret) + return ret; + return 0; } + +static void mtouch_exit(struct usbtouch_usb *usbtouch) +{ + sysfs_remove_group(&usbtouch->interface->dev.kobj, &mtouch_attr_group); +} #endif @@ -1119,7 +1207,9 @@ static struct usbtouch_device_info usbtouch_dev_info[] = { .max_yc = 0x4000, .rept_size = 11, .read_data = mtouch_read_data, + .alloc = mtouch_alloc, .init = mtouch_init, + .exit = mtouch_exit, }, #endif