aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-picolcd.c4
-rw-r--r--drivers/hid/hid-roccat-koneplus.c82
-rw-r--r--drivers/hid/hid-roccat-koneplus.h11
-rw-r--r--drivers/hid/hidraw.c30
-rw-r--r--drivers/hid/usbhid/hiddev.c20
5 files changed, 64 insertions, 83 deletions
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index b2f56a13bcf5..9d8710f8bc79 100644
--- a/drivers/hid/hid-picolcd.c
+++ b/drivers/hid/hid-picolcd.c
@@ -1585,11 +1585,11 @@ static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
1585 memset(raw_data, 0, sizeof(raw_data)); 1585 memset(raw_data, 0, sizeof(raw_data));
1586 raw_data[0] = *off & 0xff; 1586 raw_data[0] = *off & 0xff;
1587 raw_data[1] = (*off >> 8) & 0xff; 1587 raw_data[1] = (*off >> 8) & 0xff;
1588 raw_data[2] = s < 20 ? s : 20; 1588 raw_data[2] = min((size_t)20, s);
1589 if (*off + raw_data[2] > 0xff) 1589 if (*off + raw_data[2] > 0xff)
1590 raw_data[2] = 0x100 - *off; 1590 raw_data[2] = 0x100 - *off;
1591 1591
1592 if (copy_from_user(raw_data+3, u, raw_data[2])) 1592 if (copy_from_user(raw_data+3, u, min((u8)20, raw_data[2])))
1593 return -EFAULT; 1593 return -EFAULT;
1594 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data, 1594 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data,
1595 sizeof(raw_data)); 1595 sizeof(raw_data));
diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c
index 33eec74e0615..5b640a7a15a7 100644
--- a/drivers/hid/hid-roccat-koneplus.c
+++ b/drivers/hid/hid-roccat-koneplus.c
@@ -167,28 +167,28 @@ static int koneplus_set_profile_buttons(struct usb_device *usb_dev,
167} 167}
168 168
169/* retval is 0-4 on success, < 0 on error */ 169/* retval is 0-4 on success, < 0 on error */
170static int koneplus_get_startup_profile(struct usb_device *usb_dev) 170static int koneplus_get_actual_profile(struct usb_device *usb_dev)
171{ 171{
172 struct koneplus_startup_profile buf; 172 struct koneplus_actual_profile buf;
173 int retval; 173 int retval;
174 174
175 retval = roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE, 175 retval = roccat_common_receive(usb_dev, KONEPLUS_USB_COMMAND_ACTUAL_PROFILE,
176 &buf, sizeof(struct koneplus_startup_profile)); 176 &buf, sizeof(struct koneplus_actual_profile));
177 177
178 return retval ? retval : buf.startup_profile; 178 return retval ? retval : buf.actual_profile;
179} 179}
180 180
181static int koneplus_set_startup_profile(struct usb_device *usb_dev, 181static int koneplus_set_actual_profile(struct usb_device *usb_dev,
182 int startup_profile) 182 int new_profile)
183{ 183{
184 struct koneplus_startup_profile buf; 184 struct koneplus_actual_profile buf;
185 185
186 buf.command = KONEPLUS_COMMAND_STARTUP_PROFILE; 186 buf.command = KONEPLUS_COMMAND_ACTUAL_PROFILE;
187 buf.size = sizeof(struct koneplus_startup_profile); 187 buf.size = sizeof(struct koneplus_actual_profile);
188 buf.startup_profile = startup_profile; 188 buf.actual_profile = new_profile;
189 189
190 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_STARTUP_PROFILE, 190 return koneplus_send(usb_dev, KONEPLUS_USB_COMMAND_ACTUAL_PROFILE,
191 &buf, sizeof(struct koneplus_profile_buttons)); 191 &buf, sizeof(struct koneplus_actual_profile));
192} 192}
193 193
194static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj, 194static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj,
@@ -398,21 +398,22 @@ static ssize_t koneplus_sysfs_write_profile_buttons(struct file *fp,
398 return sizeof(struct koneplus_profile_buttons); 398 return sizeof(struct koneplus_profile_buttons);
399} 399}
400 400
401static ssize_t koneplus_sysfs_show_startup_profile(struct device *dev, 401static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev,
402 struct device_attribute *attr, char *buf) 402 struct device_attribute *attr, char *buf)
403{ 403{
404 struct koneplus_device *koneplus = 404 struct koneplus_device *koneplus =
405 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 405 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
406 return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->startup_profile); 406 return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile);
407} 407}
408 408
409static ssize_t koneplus_sysfs_set_startup_profile(struct device *dev, 409static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev,
410 struct device_attribute *attr, char const *buf, size_t size) 410 struct device_attribute *attr, char const *buf, size_t size)
411{ 411{
412 struct koneplus_device *koneplus; 412 struct koneplus_device *koneplus;
413 struct usb_device *usb_dev; 413 struct usb_device *usb_dev;
414 unsigned long profile; 414 unsigned long profile;
415 int retval; 415 int retval;
416 struct koneplus_roccat_report roccat_report;
416 417
417 dev = dev->parent->parent; 418 dev = dev->parent->parent;
418 koneplus = hid_get_drvdata(dev_get_drvdata(dev)); 419 koneplus = hid_get_drvdata(dev_get_drvdata(dev));
@@ -423,20 +424,25 @@ static ssize_t koneplus_sysfs_set_startup_profile(struct device *dev,
423 return retval; 424 return retval;
424 425
425 mutex_lock(&koneplus->koneplus_lock); 426 mutex_lock(&koneplus->koneplus_lock);
426 retval = koneplus_set_startup_profile(usb_dev, profile); 427
427 mutex_unlock(&koneplus->koneplus_lock); 428 retval = koneplus_set_actual_profile(usb_dev, profile);
428 if (retval) 429 if (retval) {
430 mutex_unlock(&koneplus->koneplus_lock);
429 return retval; 431 return retval;
432 }
430 433
431 return size; 434 koneplus->actual_profile = profile;
432}
433 435
434static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev, 436 roccat_report.type = KONEPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE;
435 struct device_attribute *attr, char *buf) 437 roccat_report.data1 = profile + 1;
436{ 438 roccat_report.data2 = 0;
437 struct koneplus_device *koneplus = 439 roccat_report.profile = profile + 1;
438 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 440 roccat_report_event(koneplus->chrdev_minor,
439 return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile); 441 (uint8_t const *)&roccat_report);
442
443 mutex_unlock(&koneplus->koneplus_lock);
444
445 return size;
440} 446}
441 447
442static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, 448static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev,
@@ -448,11 +454,12 @@ static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev,
448} 454}
449 455
450static struct device_attribute koneplus_attributes[] = { 456static struct device_attribute koneplus_attributes[] = {
457 __ATTR(actual_profile, 0660,
458 koneplus_sysfs_show_actual_profile,
459 koneplus_sysfs_set_actual_profile),
451 __ATTR(startup_profile, 0660, 460 __ATTR(startup_profile, 0660,
452 koneplus_sysfs_show_startup_profile, 461 koneplus_sysfs_show_actual_profile,
453 koneplus_sysfs_set_startup_profile), 462 koneplus_sysfs_set_actual_profile),
454 __ATTR(actual_profile, 0440,
455 koneplus_sysfs_show_actual_profile, NULL),
456 __ATTR(firmware_version, 0440, 463 __ATTR(firmware_version, 0440,
457 koneplus_sysfs_show_firmware_version, NULL), 464 koneplus_sysfs_show_firmware_version, NULL),
458 __ATTR_NULL 465 __ATTR_NULL
@@ -557,15 +564,10 @@ static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev,
557 struct koneplus_device *koneplus) 564 struct koneplus_device *koneplus)
558{ 565{
559 int retval, i; 566 int retval, i;
560 static uint wait = 100; /* device will freeze with just 60 */ 567 static uint wait = 200;
561 568
562 mutex_init(&koneplus->koneplus_lock); 569 mutex_init(&koneplus->koneplus_lock);
563 570
564 koneplus->startup_profile = koneplus_get_startup_profile(usb_dev);
565 if (koneplus->startup_profile < 0)
566 return koneplus->startup_profile;
567
568 msleep(wait);
569 retval = koneplus_get_info(usb_dev, &koneplus->info); 571 retval = koneplus_get_info(usb_dev, &koneplus->info);
570 if (retval) 572 if (retval)
571 return retval; 573 return retval;
@@ -584,7 +586,11 @@ static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev,
584 return retval; 586 return retval;
585 } 587 }
586 588
587 koneplus_profile_activated(koneplus, koneplus->startup_profile); 589 msleep(wait);
590 retval = koneplus_get_actual_profile(usb_dev);
591 if (retval < 0)
592 return retval;
593 koneplus_profile_activated(koneplus, retval);
588 594
589 return 0; 595 return 0;
590} 596}
diff --git a/drivers/hid/hid-roccat-koneplus.h b/drivers/hid/hid-roccat-koneplus.h
index 57a5c1ab7b05..c57a376ab8ae 100644
--- a/drivers/hid/hid-roccat-koneplus.h
+++ b/drivers/hid/hid-roccat-koneplus.h
@@ -40,10 +40,10 @@ enum koneplus_control_values {
40 KONEPLUS_CONTROL_REQUEST_STATUS_WAIT = 3, 40 KONEPLUS_CONTROL_REQUEST_STATUS_WAIT = 3,
41}; 41};
42 42
43struct koneplus_startup_profile { 43struct koneplus_actual_profile {
44 uint8_t command; /* KONEPLUS_COMMAND_STARTUP_PROFILE */ 44 uint8_t command; /* KONEPLUS_COMMAND_ACTUAL_PROFILE */
45 uint8_t size; /* always 3 */ 45 uint8_t size; /* always 3 */
46 uint8_t startup_profile; /* Range 0-4! */ 46 uint8_t actual_profile; /* Range 0-4! */
47} __attribute__ ((__packed__)); 47} __attribute__ ((__packed__));
48 48
49struct koneplus_profile_settings { 49struct koneplus_profile_settings {
@@ -132,7 +132,7 @@ struct koneplus_tcu_image {
132 132
133enum koneplus_commands { 133enum koneplus_commands {
134 KONEPLUS_COMMAND_CONTROL = 0x4, 134 KONEPLUS_COMMAND_CONTROL = 0x4,
135 KONEPLUS_COMMAND_STARTUP_PROFILE = 0x5, 135 KONEPLUS_COMMAND_ACTUAL_PROFILE = 0x5,
136 KONEPLUS_COMMAND_PROFILE_SETTINGS = 0x6, 136 KONEPLUS_COMMAND_PROFILE_SETTINGS = 0x6,
137 KONEPLUS_COMMAND_PROFILE_BUTTONS = 0x7, 137 KONEPLUS_COMMAND_PROFILE_BUTTONS = 0x7,
138 KONEPLUS_COMMAND_MACRO = 0x8, 138 KONEPLUS_COMMAND_MACRO = 0x8,
@@ -145,7 +145,7 @@ enum koneplus_commands {
145 145
146enum koneplus_usb_commands { 146enum koneplus_usb_commands {
147 KONEPLUS_USB_COMMAND_CONTROL = 0x304, 147 KONEPLUS_USB_COMMAND_CONTROL = 0x304,
148 KONEPLUS_USB_COMMAND_STARTUP_PROFILE = 0x305, 148 KONEPLUS_USB_COMMAND_ACTUAL_PROFILE = 0x305,
149 KONEPLUS_USB_COMMAND_PROFILE_SETTINGS = 0x306, 149 KONEPLUS_USB_COMMAND_PROFILE_SETTINGS = 0x306,
150 KONEPLUS_USB_COMMAND_PROFILE_BUTTONS = 0x307, 150 KONEPLUS_USB_COMMAND_PROFILE_BUTTONS = 0x307,
151 KONEPLUS_USB_COMMAND_MACRO = 0x308, 151 KONEPLUS_USB_COMMAND_MACRO = 0x308,
@@ -215,7 +215,6 @@ struct koneplus_device {
215 215
216 struct mutex koneplus_lock; 216 struct mutex koneplus_lock;
217 217
218 int startup_profile;
219 struct koneplus_info info; 218 struct koneplus_info info;
220 struct koneplus_profile_settings profile_settings[5]; 219 struct koneplus_profile_settings profile_settings[5];
221 struct koneplus_profile_buttons profile_buttons[5]; 220 struct koneplus_profile_buttons profile_buttons[5];
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 54409cba018c..c79578b5a788 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -101,8 +101,8 @@ out:
101 return ret; 101 return ret;
102} 102}
103 103
104/* the first byte is expected to be a report number */ 104/* The first byte is expected to be a report number.
105/* This function is to be called with the minors_lock mutex held */ 105 * This function is to be called with the minors_lock mutex held */
106static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, size_t count, unsigned char report_type) 106static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, size_t count, unsigned char report_type)
107{ 107{
108 unsigned int minor = iminor(file->f_path.dentry->d_inode); 108 unsigned int minor = iminor(file->f_path.dentry->d_inode);
@@ -166,11 +166,11 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
166 166
167 167
168/* This function performs a Get_Report transfer over the control endpoint 168/* This function performs a Get_Report transfer over the control endpoint
169 per section 7.2.1 of the HID specification, version 1.1. The first byte 169 * per section 7.2.1 of the HID specification, version 1.1. The first byte
170 of buffer is the report number to request, or 0x0 if the defice does not 170 * of buffer is the report number to request, or 0x0 if the defice does not
171 use numbered reports. The report_type parameter can be HID_FEATURE_REPORT 171 * use numbered reports. The report_type parameter can be HID_FEATURE_REPORT
172 or HID_INPUT_REPORT. This function is to be called with the minors_lock 172 * or HID_INPUT_REPORT. This function is to be called with the minors_lock
173 mutex held. */ 173 * mutex held. */
174static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t count, unsigned char report_type) 174static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t count, unsigned char report_type)
175{ 175{
176 unsigned int minor = iminor(file->f_path.dentry->d_inode); 176 unsigned int minor = iminor(file->f_path.dentry->d_inode);
@@ -207,7 +207,7 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t
207 } 207 }
208 208
209 /* Read the first byte from the user. This is the report number, 209 /* Read the first byte from the user. This is the report number,
210 which is passed to dev->hid_get_raw_report(). */ 210 * which is passed to dev->hid_get_raw_report(). */
211 if (copy_from_user(&report_number, buffer, 1)) { 211 if (copy_from_user(&report_number, buffer, 1)) {
212 ret = -EFAULT; 212 ret = -EFAULT;
213 goto out_free; 213 goto out_free;
@@ -395,12 +395,7 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
395 } 395 }
396 396
397 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWNAME(0))) { 397 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWNAME(0))) {
398 int len; 398 int len = strlen(hid->name) + 1;
399 if (!hid->name) {
400 ret = 0;
401 break;
402 }
403 len = strlen(hid->name) + 1;
404 if (len > _IOC_SIZE(cmd)) 399 if (len > _IOC_SIZE(cmd))
405 len = _IOC_SIZE(cmd); 400 len = _IOC_SIZE(cmd);
406 ret = copy_to_user(user_arg, hid->name, len) ? 401 ret = copy_to_user(user_arg, hid->name, len) ?
@@ -409,12 +404,7 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
409 } 404 }
410 405
411 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWPHYS(0))) { 406 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWPHYS(0))) {
412 int len; 407 int len = strlen(hid->phys) + 1;
413 if (!hid->phys) {
414 ret = 0;
415 break;
416 }
417 len = strlen(hid->phys) + 1;
418 if (len > _IOC_SIZE(cmd)) 408 if (len > _IOC_SIZE(cmd))
419 len = _IOC_SIZE(cmd); 409 len = _IOC_SIZE(cmd);
420 ret = copy_to_user(user_arg, hid->phys, len) ? 410 ret = copy_to_user(user_arg, hid->phys, len) ?
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index af0a7c1002af..2baa71e6cc29 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -509,7 +509,7 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd,
509 (uref_multi->num_values > HID_MAX_MULTI_USAGES || 509 (uref_multi->num_values > HID_MAX_MULTI_USAGES ||
510 uref->usage_index + uref_multi->num_values > field->report_count)) 510 uref->usage_index + uref_multi->num_values > field->report_count))
511 goto inval; 511 goto inval;
512 } 512 }
513 513
514 switch (cmd) { 514 switch (cmd) {
515 case HIDIOCGUSAGE: 515 case HIDIOCGUSAGE:
@@ -801,14 +801,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
801 break; 801 break;
802 802
803 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) { 803 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) {
804 int len; 804 int len = strlen(hid->name) + 1;
805
806 if (!hid->name) {
807 r = 0;
808 break;
809 }
810
811 len = strlen(hid->name) + 1;
812 if (len > _IOC_SIZE(cmd)) 805 if (len > _IOC_SIZE(cmd))
813 len = _IOC_SIZE(cmd); 806 len = _IOC_SIZE(cmd);
814 r = copy_to_user(user_arg, hid->name, len) ? 807 r = copy_to_user(user_arg, hid->name, len) ?
@@ -817,14 +810,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
817 } 810 }
818 811
819 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) { 812 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) {
820 int len; 813 int len = strlen(hid->phys) + 1;
821
822 if (!hid->phys) {
823 r = 0;
824 break;
825 }
826
827 len = strlen(hid->phys) + 1;
828 if (len > _IOC_SIZE(cmd)) 814 if (len > _IOC_SIZE(cmd))
829 len = _IOC_SIZE(cmd); 815 len = _IOC_SIZE(cmd);
830 r = copy_to_user(user_arg, hid->phys, len) ? 816 r = copy_to_user(user_arg, hid->phys, len) ?