diff options
-rw-r--r-- | drivers/hid/hid-ntrig.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 43e95dee9290..69169efa1e16 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c | |||
@@ -90,6 +90,55 @@ struct ntrig_data { | |||
90 | }; | 90 | }; |
91 | 91 | ||
92 | 92 | ||
93 | /* | ||
94 | * This function converts the 4 byte raw firmware code into | ||
95 | * a string containing 5 comma separated numbers. | ||
96 | */ | ||
97 | static int ntrig_version_string(unsigned char *raw, char *buf) | ||
98 | { | ||
99 | __u8 a = (raw[1] & 0x0e) >> 1; | ||
100 | __u8 b = (raw[0] & 0x3c) >> 2; | ||
101 | __u8 c = ((raw[0] & 0x03) << 3) | ((raw[3] & 0xe0) >> 5); | ||
102 | __u8 d = ((raw[3] & 0x07) << 3) | ((raw[2] & 0xe0) >> 5); | ||
103 | __u8 e = raw[2] & 0x07; | ||
104 | |||
105 | /* | ||
106 | * As yet unmapped bits: | ||
107 | * 0b11000000 0b11110001 0b00011000 0b00011000 | ||
108 | */ | ||
109 | |||
110 | return sprintf(buf, "%u.%u.%u.%u.%u", a, b, c, d, e); | ||
111 | } | ||
112 | |||
113 | static void ntrig_report_version(struct hid_device *hdev) | ||
114 | { | ||
115 | int ret; | ||
116 | char buf[20]; | ||
117 | struct usb_device *usb_dev = hid_to_usb_dev(hdev); | ||
118 | unsigned char *data = kmalloc(8, GFP_KERNEL); | ||
119 | |||
120 | if (!data) | ||
121 | goto err_free; | ||
122 | |||
123 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | ||
124 | USB_REQ_CLEAR_FEATURE, | ||
125 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | | ||
126 | USB_DIR_IN, | ||
127 | 0x30c, 1, data, 8, | ||
128 | USB_CTRL_SET_TIMEOUT); | ||
129 | |||
130 | if (ret == 8) { | ||
131 | ret = ntrig_version_string(&data[2], buf); | ||
132 | |||
133 | dev_info(&hdev->dev, | ||
134 | "Firmware version: %s (%02x%02x %02x%02x)\n", | ||
135 | buf, data[2], data[3], data[4], data[5]); | ||
136 | } | ||
137 | |||
138 | err_free: | ||
139 | kfree(data); | ||
140 | } | ||
141 | |||
93 | static ssize_t show_phys_width(struct device *dev, | 142 | static ssize_t show_phys_width(struct device *dev, |
94 | struct device_attribute *attr, | 143 | struct device_attribute *attr, |
95 | char *buf) | 144 | char *buf) |
@@ -848,6 +897,8 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
848 | if (report) | 897 | if (report) |
849 | usbhid_submit_report(hdev, report, USB_DIR_OUT); | 898 | usbhid_submit_report(hdev, report, USB_DIR_OUT); |
850 | 899 | ||
900 | ntrig_report_version(hdev); | ||
901 | |||
851 | ret = sysfs_create_group(&hdev->dev.kobj, | 902 | ret = sysfs_create_group(&hdev->dev.kobj, |
852 | &ntrig_attribute_group); | 903 | &ntrig_attribute_group); |
853 | 904 | ||