diff mbox

[v2] Input: usbtouchscreen - add sysfs attribute for 3M MTouch firmware rev

Message ID 20180503214734.27141-1-nick@shmanahar.org (mailing list archive)
State New, archived
Headers show

Commit Message

Nick Dyer May 3, 2018, 9:47 p.m. UTC
[v2: output fw rev on probe]

Signed-off-by: Nick Dyer <nick@shmanahar.org>
---
 drivers/input/touchscreen/usbtouchscreen.c | 90 ++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

Comments

Nikita Yushchenko May 7, 2018, 2:29 p.m. UTC | #1
> [v2: output fw rev on probe]
> 
> Signed-off-by: Nick Dyer <nick@shmanahar.org>

Tested on ZII RDU2 platform.

Boot message:

usbtouchscreen 1-1.2:1.0: 3M Microtouch firmware revision: 4.10

Sysfs attribute:

# cat /sys/bus/usb/devices/1-1.2:1.0/firmware_rev
4.10

Tested-By: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov May 10, 2018, 12:27 a.m. UTC | #2
Hi Nick,

On Thu, May 03, 2018 at 10:47:34PM +0100, Nick Dyer wrote:
> [v2: output fw rev on probe]

I'd rather we did not as we have sysfs if you need to see it.

Also:

> @@ -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;

->init() is called from ->reset_resume(), you do not want to create
sysfs attributes in init.

Thanks.
Nick Dyer May 10, 2018, 7:27 p.m. UTC | #3
On Mon, May 07, 2018 at 05:29:34PM +0300, Nikita Yushchenko wrote:
> > [v2: output fw rev on probe]
> > 
> > Signed-off-by: Nick Dyer <nick@shmanahar.org>
> 
> Tested on ZII RDU2 platform.
> 
> Boot message:
> 
> usbtouchscreen 1-1.2:1.0: 3M Microtouch firmware revision: 4.10
> 
> Sysfs attribute:
> 
> # cat /sys/bus/usb/devices/1-1.2:1.0/firmware_rev
> 4.10
> 
> Tested-By: Nikita Yushchenko <nikita.yoush@cogentembedded.com>

Thanks!

N
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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