@@ -440,6 +440,8 @@ static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
440
440
#define MTOUCHUSB_RESET 7
441
441
#define MTOUCHUSB_REQ_CTRLLR_ID 10
442
442
443
+ #define MTOUCHUSB_REQ_CTRLLR_ID_LEN 16
444
+
443
445
static int mtouch_read_data (struct usbtouch_usb * dev , unsigned char * pkt )
444
446
{
445
447
if (hwcalib_xy ) {
@@ -454,11 +456,93 @@ static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
454
456
return 1 ;
455
457
}
456
458
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
+
457
537
static int mtouch_init (struct usbtouch_usb * usbtouch )
458
538
{
459
539
int ret , i ;
460
540
struct usb_device * udev = interface_to_usbdev (usbtouch -> interface );
461
541
542
+ ret = mtouch_get_fw_revision (usbtouch );
543
+ if (ret )
544
+ return ret ;
545
+
462
546
ret = usb_control_msg (udev , usb_rcvctrlpipe (udev , 0 ),
463
547
MTOUCHUSB_RESET ,
464
548
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE ,
@@ -492,6 +576,14 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
492
576
493
577
return 0 ;
494
578
}
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
+ }
495
587
#endif
496
588
497
589
@@ -1119,7 +1211,9 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
1119
1211
.max_yc = 0x4000 ,
1120
1212
.rept_size = 11 ,
1121
1213
.read_data = mtouch_read_data ,
1214
+ .alloc = mtouch_alloc ,
1122
1215
.init = mtouch_init ,
1216
+ .exit = mtouch_exit ,
1123
1217
},
1124
1218
#endif
1125
1219
0 commit comments