Skip to content

Commit 89f84b8

Browse files
ndyerdtor
authored andcommitted
Input: usbtouchscreen - add sysfs attribute for 3M MTouch firmware rev
Allow querying of the firmware revision of the device example: 4.10 Tested on ZII RDU2 platform and on Intel x86_64 PC. Signed-off-by: Nick Dyer <[email protected]> Tested-by: Nikita Yushchenko <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent ff7242a commit 89f84b8

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

drivers/input/touchscreen/usbtouchscreen.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
440440
#define MTOUCHUSB_RESET 7
441441
#define MTOUCHUSB_REQ_CTRLLR_ID 10
442442

443+
#define MTOUCHUSB_REQ_CTRLLR_ID_LEN 16
444+
443445
static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
444446
{
445447
if (hwcalib_xy) {
@@ -454,11 +456,93 @@ static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
454456
return 1;
455457
}
456458

459+
struct mtouch_priv {
460+
u8 fw_rev_major;
461+
u8 fw_rev_minor;
462+
};
463+
464+
static ssize_t mtouch_firmware_rev_show(struct device *dev,
465+
struct device_attribute *attr, char *output)
466+
{
467+
struct usb_interface *intf = to_usb_interface(dev);
468+
struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
469+
struct mtouch_priv *priv = usbtouch->priv;
470+
471+
return scnprintf(output, PAGE_SIZE, "%1x.%1x\n",
472+
priv->fw_rev_major, priv->fw_rev_minor);
473+
}
474+
static DEVICE_ATTR(firmware_rev, 0444, mtouch_firmware_rev_show, NULL);
475+
476+
static struct attribute *mtouch_attrs[] = {
477+
&dev_attr_firmware_rev.attr,
478+
NULL
479+
};
480+
481+
static const struct attribute_group mtouch_attr_group = {
482+
.attrs = mtouch_attrs,
483+
};
484+
485+
static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch)
486+
{
487+
struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
488+
struct mtouch_priv *priv = usbtouch->priv;
489+
u8 *buf;
490+
int ret;
491+
492+
buf = kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN, GFP_NOIO);
493+
if (!buf)
494+
return -ENOMEM;
495+
496+
ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
497+
MTOUCHUSB_REQ_CTRLLR_ID,
498+
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
499+
0, 0, buf, MTOUCHUSB_REQ_CTRLLR_ID_LEN,
500+
USB_CTRL_SET_TIMEOUT);
501+
if (ret != MTOUCHUSB_REQ_CTRLLR_ID_LEN) {
502+
dev_warn(&usbtouch->interface->dev,
503+
"Failed to read FW rev: %d\n", ret);
504+
ret = ret < 0 ? ret : -EIO;
505+
goto free;
506+
}
507+
508+
priv->fw_rev_major = buf[3];
509+
priv->fw_rev_minor = buf[4];
510+
511+
ret = 0;
512+
513+
free:
514+
kfree(buf);
515+
return ret;
516+
}
517+
518+
static int mtouch_alloc(struct usbtouch_usb *usbtouch)
519+
{
520+
int ret;
521+
522+
usbtouch->priv = kmalloc(sizeof(struct mtouch_priv), GFP_KERNEL);
523+
if (!usbtouch->priv)
524+
return -ENOMEM;
525+
526+
ret = sysfs_create_group(&usbtouch->interface->dev.kobj,
527+
&mtouch_attr_group);
528+
if (ret) {
529+
kfree(usbtouch->priv);
530+
usbtouch->priv = NULL;
531+
return ret;
532+
}
533+
534+
return 0;
535+
}
536+
457537
static int mtouch_init(struct usbtouch_usb *usbtouch)
458538
{
459539
int ret, i;
460540
struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
461541

542+
ret = mtouch_get_fw_revision(usbtouch);
543+
if (ret)
544+
return ret;
545+
462546
ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
463547
MTOUCHUSB_RESET,
464548
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
@@ -492,6 +576,14 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
492576

493577
return 0;
494578
}
579+
580+
static void mtouch_exit(struct usbtouch_usb *usbtouch)
581+
{
582+
struct mtouch_priv *priv = usbtouch->priv;
583+
584+
sysfs_remove_group(&usbtouch->interface->dev.kobj, &mtouch_attr_group);
585+
kfree(priv);
586+
}
495587
#endif
496588

497589

@@ -1119,7 +1211,9 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
11191211
.max_yc = 0x4000,
11201212
.rept_size = 11,
11211213
.read_data = mtouch_read_data,
1214+
.alloc = mtouch_alloc,
11221215
.init = mtouch_init,
1216+
.exit = mtouch_exit,
11231217
},
11241218
#endif
11251219

0 commit comments

Comments
 (0)