aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-roccat-kone.c
diff options
context:
space:
mode:
authorStefan Achatz <erazor_de@users.sourceforge.net>2010-11-26 14:57:38 -0500
committerJiri Kosina <jkosina@suse.cz>2011-01-07 19:11:33 -0500
commit14a057f80f0c4d45a9e68009f8bcb6b246e87ca0 (patch)
tree1adbc9becbf3362b69891c5b096d494749e73852 /drivers/hid/hid-roccat-kone.c
parentbd3a2b96631dd86b06dca96aef00790084a11e15 (diff)
HID: roccat: reduce number of functions in kone and pyra drivers
The profile number is now passed via bin_attribute->private instead of function parameter to reduce number of functions. Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-roccat-kone.c')
-rw-r--r--drivers/hid/hid-roccat-kone.c106
1 files changed, 27 insertions, 79 deletions
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
index 648d28e5f3f0..cbd8cc42e75a 100644
--- a/drivers/hid/hid-roccat-kone.c
+++ b/drivers/hid/hid-roccat-kone.c
@@ -35,6 +35,8 @@
35#include "hid-roccat.h" 35#include "hid-roccat.h"
36#include "hid-roccat-kone.h" 36#include "hid-roccat-kone.h"
37 37
38static uint profile_numbers[5] = {0, 1, 2, 3, 4};
39
38/* kone_class is used for creating sysfs attributes via roccat char device */ 40/* kone_class is used for creating sysfs attributes via roccat char device */
39static struct class *kone_class; 41static struct class *kone_class;
40 42
@@ -323,9 +325,9 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
323 return sizeof(struct kone_settings); 325 return sizeof(struct kone_settings);
324} 326}
325 327
326static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, 328static ssize_t kone_sysfs_read_profilex(struct file *fp,
327 struct bin_attribute *attr, char *buf, 329 struct kobject *kobj, struct bin_attribute *attr,
328 loff_t off, size_t count, int number) { 330 char *buf, loff_t off, size_t count) {
329 struct device *dev = 331 struct device *dev =
330 container_of(kobj, struct device, kobj)->parent->parent; 332 container_of(kobj, struct device, kobj)->parent->parent;
331 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 333 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
@@ -337,46 +339,16 @@ static ssize_t kone_sysfs_read_profilex(struct kobject *kobj,
337 count = sizeof(struct kone_profile) - off; 339 count = sizeof(struct kone_profile) - off;
338 340
339 mutex_lock(&kone->kone_lock); 341 mutex_lock(&kone->kone_lock);
340 memcpy(buf, ((char const *)&kone->profiles[number - 1]) + off, count); 342 memcpy(buf, ((char const *)&kone->profiles[*(uint *)(attr->private)]) + off, count);
341 mutex_unlock(&kone->kone_lock); 343 mutex_unlock(&kone->kone_lock);
342 344
343 return count; 345 return count;
344} 346}
345 347
346static ssize_t kone_sysfs_read_profile1(struct file *fp, struct kobject *kobj,
347 struct bin_attribute *attr, char *buf,
348 loff_t off, size_t count) {
349 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 1);
350}
351
352static ssize_t kone_sysfs_read_profile2(struct file *fp, struct kobject *kobj,
353 struct bin_attribute *attr, char *buf,
354 loff_t off, size_t count) {
355 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 2);
356}
357
358static ssize_t kone_sysfs_read_profile3(struct file *fp, struct kobject *kobj,
359 struct bin_attribute *attr, char *buf,
360 loff_t off, size_t count) {
361 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 3);
362}
363
364static ssize_t kone_sysfs_read_profile4(struct file *fp, struct kobject *kobj,
365 struct bin_attribute *attr, char *buf,
366 loff_t off, size_t count) {
367 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 4);
368}
369
370static ssize_t kone_sysfs_read_profile5(struct file *fp, struct kobject *kobj,
371 struct bin_attribute *attr, char *buf,
372 loff_t off, size_t count) {
373 return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 5);
374}
375
376/* Writes data only if different to stored data */ 348/* Writes data only if different to stored data */
377static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, 349static ssize_t kone_sysfs_write_profilex(struct file *fp,
378 struct bin_attribute *attr, char *buf, 350 struct kobject *kobj, struct bin_attribute *attr,
379 loff_t off, size_t count, int number) { 351 char *buf, loff_t off, size_t count) {
380 struct device *dev = 352 struct device *dev =
381 container_of(kobj, struct device, kobj)->parent->parent; 353 container_of(kobj, struct device, kobj)->parent->parent;
382 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); 354 struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
@@ -388,13 +360,14 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,
388 if (off != 0 || count != sizeof(struct kone_profile)) 360 if (off != 0 || count != sizeof(struct kone_profile))
389 return -EINVAL; 361 return -EINVAL;
390 362
391 profile = &kone->profiles[number - 1]; 363 profile = &kone->profiles[*(uint *)(attr->private)];
392 364
393 mutex_lock(&kone->kone_lock); 365 mutex_lock(&kone->kone_lock);
394 difference = memcmp(buf, profile, sizeof(struct kone_profile)); 366 difference = memcmp(buf, profile, sizeof(struct kone_profile));
395 if (difference) { 367 if (difference) {
396 retval = kone_set_profile(usb_dev, 368 retval = kone_set_profile(usb_dev,
397 (struct kone_profile const *)buf, number); 369 (struct kone_profile const *)buf,
370 *(uint *)(attr->private) + 1);
398 if (!retval) 371 if (!retval)
399 memcpy(profile, buf, sizeof(struct kone_profile)); 372 memcpy(profile, buf, sizeof(struct kone_profile));
400 } 373 }
@@ -406,36 +379,6 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,
406 return sizeof(struct kone_profile); 379 return sizeof(struct kone_profile);
407} 380}
408 381
409static ssize_t kone_sysfs_write_profile1(struct file *fp, struct kobject *kobj,
410 struct bin_attribute *attr, char *buf,
411 loff_t off, size_t count) {
412 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 1);
413}
414
415static ssize_t kone_sysfs_write_profile2(struct file *fp, struct kobject *kobj,
416 struct bin_attribute *attr, char *buf,
417 loff_t off, size_t count) {
418 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 2);
419}
420
421static ssize_t kone_sysfs_write_profile3(struct file *fp, struct kobject *kobj,
422 struct bin_attribute *attr, char *buf,
423 loff_t off, size_t count) {
424 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 3);
425}
426
427static ssize_t kone_sysfs_write_profile4(struct file *fp, struct kobject *kobj,
428 struct bin_attribute *attr, char *buf,
429 loff_t off, size_t count) {
430 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 4);
431}
432
433static ssize_t kone_sysfs_write_profile5(struct file *fp, struct kobject *kobj,
434 struct bin_attribute *attr, char *buf,
435 loff_t off, size_t count) {
436 return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 5);
437}
438
439static ssize_t kone_sysfs_show_actual_profile(struct device *dev, 382static ssize_t kone_sysfs_show_actual_profile(struct device *dev,
440 struct device_attribute *attr, char *buf) 383 struct device_attribute *attr, char *buf)
441{ 384{
@@ -691,32 +634,37 @@ static struct bin_attribute kone_bin_attributes[] = {
691 { 634 {
692 .attr = { .name = "profile1", .mode = 0660 }, 635 .attr = { .name = "profile1", .mode = 0660 },
693 .size = sizeof(struct kone_profile), 636 .size = sizeof(struct kone_profile),
694 .read = kone_sysfs_read_profile1, 637 .read = kone_sysfs_read_profilex,
695 .write = kone_sysfs_write_profile1 638 .write = kone_sysfs_write_profilex,
639 .private = &profile_numbers[0]
696 }, 640 },
697 { 641 {
698 .attr = { .name = "profile2", .mode = 0660 }, 642 .attr = { .name = "profile2", .mode = 0660 },
699 .size = sizeof(struct kone_profile), 643 .size = sizeof(struct kone_profile),
700 .read = kone_sysfs_read_profile2, 644 .read = kone_sysfs_read_profilex,
701 .write = kone_sysfs_write_profile2 645 .write = kone_sysfs_write_profilex,
646 .private = &profile_numbers[1]
702 }, 647 },
703 { 648 {
704 .attr = { .name = "profile3", .mode = 0660 }, 649 .attr = { .name = "profile3", .mode = 0660 },
705 .size = sizeof(struct kone_profile), 650 .size = sizeof(struct kone_profile),
706 .read = kone_sysfs_read_profile3, 651 .read = kone_sysfs_read_profilex,
707 .write = kone_sysfs_write_profile3 652 .write = kone_sysfs_write_profilex,
653 .private = &profile_numbers[2]
708 }, 654 },
709 { 655 {
710 .attr = { .name = "profile4", .mode = 0660 }, 656 .attr = { .name = "profile4", .mode = 0660 },
711 .size = sizeof(struct kone_profile), 657 .size = sizeof(struct kone_profile),
712 .read = kone_sysfs_read_profile4, 658 .read = kone_sysfs_read_profilex,
713 .write = kone_sysfs_write_profile4 659 .write = kone_sysfs_write_profilex,
660 .private = &profile_numbers[3]
714 }, 661 },
715 { 662 {
716 .attr = { .name = "profile5", .mode = 0660 }, 663 .attr = { .name = "profile5", .mode = 0660 },
717 .size = sizeof(struct kone_profile), 664 .size = sizeof(struct kone_profile),
718 .read = kone_sysfs_read_profile5, 665 .read = kone_sysfs_read_profilex,
719 .write = kone_sysfs_write_profile5 666 .write = kone_sysfs_write_profilex,
667 .private = &profile_numbers[4]
720 }, 668 },
721 __ATTR_NULL 669 __ATTR_NULL
722}; 670};