diff options
author | Stefan Achatz <erazor_de@users.sourceforge.net> | 2010-11-26 14:57:38 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-01-07 19:11:33 -0500 |
commit | 14a057f80f0c4d45a9e68009f8bcb6b246e87ca0 (patch) | |
tree | 1adbc9becbf3362b69891c5b096d494749e73852 /drivers/hid/hid-roccat-pyra.c | |
parent | bd3a2b96631dd86b06dca96aef00790084a11e15 (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-pyra.c')
-rw-r--r-- | drivers/hid/hid-roccat-pyra.c | 120 |
1 files changed, 26 insertions, 94 deletions
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index 7273e1e9093d..02c58e015bee 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "hid-roccat.h" | 27 | #include "hid-roccat.h" |
28 | #include "hid-roccat-pyra.h" | 28 | #include "hid-roccat-pyra.h" |
29 | 29 | ||
30 | static uint profile_numbers[5] = {0, 1, 2, 3, 4}; | ||
31 | |||
30 | /* pyra_class is used for creating sysfs attributes via roccat char device */ | 32 | /* pyra_class is used for creating sysfs attributes via roccat char device */ |
31 | static struct class *pyra_class; | 33 | static struct class *pyra_class; |
32 | 34 | ||
@@ -223,7 +225,7 @@ static int pyra_set_settings(struct usb_device *usb_dev, | |||
223 | 225 | ||
224 | static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, | 226 | static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, |
225 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 227 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
226 | loff_t off, size_t count, int number) | 228 | loff_t off, size_t count) |
227 | { | 229 | { |
228 | struct device *dev = | 230 | struct device *dev = |
229 | container_of(kobj, struct device, kobj)->parent->parent; | 231 | container_of(kobj, struct device, kobj)->parent->parent; |
@@ -236,56 +238,16 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, | |||
236 | count = sizeof(struct pyra_profile_settings) - off; | 238 | count = sizeof(struct pyra_profile_settings) - off; |
237 | 239 | ||
238 | mutex_lock(&pyra->pyra_lock); | 240 | mutex_lock(&pyra->pyra_lock); |
239 | memcpy(buf, ((char const *)&pyra->profile_settings[number]) + off, | 241 | memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off, |
240 | count); | 242 | count); |
241 | mutex_unlock(&pyra->pyra_lock); | 243 | mutex_unlock(&pyra->pyra_lock); |
242 | 244 | ||
243 | return count; | 245 | return count; |
244 | } | 246 | } |
245 | 247 | ||
246 | static ssize_t pyra_sysfs_read_profile1_settings(struct file *fp, | ||
247 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
248 | loff_t off, size_t count) | ||
249 | { | ||
250 | return pyra_sysfs_read_profilex_settings(fp, kobj, | ||
251 | attr, buf, off, count, 0); | ||
252 | } | ||
253 | |||
254 | static ssize_t pyra_sysfs_read_profile2_settings(struct file *fp, | ||
255 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
256 | loff_t off, size_t count) | ||
257 | { | ||
258 | return pyra_sysfs_read_profilex_settings(fp, kobj, | ||
259 | attr, buf, off, count, 1); | ||
260 | } | ||
261 | |||
262 | static ssize_t pyra_sysfs_read_profile3_settings(struct file *fp, | ||
263 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
264 | loff_t off, size_t count) | ||
265 | { | ||
266 | return pyra_sysfs_read_profilex_settings(fp, kobj, | ||
267 | attr, buf, off, count, 2); | ||
268 | } | ||
269 | |||
270 | static ssize_t pyra_sysfs_read_profile4_settings(struct file *fp, | ||
271 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
272 | loff_t off, size_t count) | ||
273 | { | ||
274 | return pyra_sysfs_read_profilex_settings(fp, kobj, | ||
275 | attr, buf, off, count, 3); | ||
276 | } | ||
277 | |||
278 | static ssize_t pyra_sysfs_read_profile5_settings(struct file *fp, | ||
279 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
280 | loff_t off, size_t count) | ||
281 | { | ||
282 | return pyra_sysfs_read_profilex_settings(fp, kobj, | ||
283 | attr, buf, off, count, 4); | ||
284 | } | ||
285 | |||
286 | static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, | 248 | static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, |
287 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 249 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
288 | loff_t off, size_t count, int number) | 250 | loff_t off, size_t count) |
289 | { | 251 | { |
290 | struct device *dev = | 252 | struct device *dev = |
291 | container_of(kobj, struct device, kobj)->parent->parent; | 253 | container_of(kobj, struct device, kobj)->parent->parent; |
@@ -298,53 +260,13 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, | |||
298 | count = sizeof(struct pyra_profile_buttons) - off; | 260 | count = sizeof(struct pyra_profile_buttons) - off; |
299 | 261 | ||
300 | mutex_lock(&pyra->pyra_lock); | 262 | mutex_lock(&pyra->pyra_lock); |
301 | memcpy(buf, ((char const *)&pyra->profile_buttons[number]) + off, | 263 | memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off, |
302 | count); | 264 | count); |
303 | mutex_unlock(&pyra->pyra_lock); | 265 | mutex_unlock(&pyra->pyra_lock); |
304 | 266 | ||
305 | return count; | 267 | return count; |
306 | } | 268 | } |
307 | 269 | ||
308 | static ssize_t pyra_sysfs_read_profile1_buttons(struct file *fp, | ||
309 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
310 | loff_t off, size_t count) | ||
311 | { | ||
312 | return pyra_sysfs_read_profilex_buttons(fp, kobj, | ||
313 | attr, buf, off, count, 0); | ||
314 | } | ||
315 | |||
316 | static ssize_t pyra_sysfs_read_profile2_buttons(struct file *fp, | ||
317 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
318 | loff_t off, size_t count) | ||
319 | { | ||
320 | return pyra_sysfs_read_profilex_buttons(fp, kobj, | ||
321 | attr, buf, off, count, 1); | ||
322 | } | ||
323 | |||
324 | static ssize_t pyra_sysfs_read_profile3_buttons(struct file *fp, | ||
325 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
326 | loff_t off, size_t count) | ||
327 | { | ||
328 | return pyra_sysfs_read_profilex_buttons(fp, kobj, | ||
329 | attr, buf, off, count, 2); | ||
330 | } | ||
331 | |||
332 | static ssize_t pyra_sysfs_read_profile4_buttons(struct file *fp, | ||
333 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
334 | loff_t off, size_t count) | ||
335 | { | ||
336 | return pyra_sysfs_read_profilex_buttons(fp, kobj, | ||
337 | attr, buf, off, count, 3); | ||
338 | } | ||
339 | |||
340 | static ssize_t pyra_sysfs_read_profile5_buttons(struct file *fp, | ||
341 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | ||
342 | loff_t off, size_t count) | ||
343 | { | ||
344 | return pyra_sysfs_read_profilex_buttons(fp, kobj, | ||
345 | attr, buf, off, count, 4); | ||
346 | } | ||
347 | |||
348 | static ssize_t pyra_sysfs_write_profile_settings(struct file *fp, | 270 | static ssize_t pyra_sysfs_write_profile_settings(struct file *fp, |
349 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 271 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
350 | loff_t off, size_t count) | 272 | loff_t off, size_t count) |
@@ -525,27 +447,32 @@ static struct bin_attribute pyra_bin_attributes[] = { | |||
525 | { | 447 | { |
526 | .attr = { .name = "profile1_settings", .mode = 0440 }, | 448 | .attr = { .name = "profile1_settings", .mode = 0440 }, |
527 | .size = sizeof(struct pyra_profile_settings), | 449 | .size = sizeof(struct pyra_profile_settings), |
528 | .read = pyra_sysfs_read_profile1_settings | 450 | .read = pyra_sysfs_read_profilex_settings, |
451 | .private = &profile_numbers[0] | ||
529 | }, | 452 | }, |
530 | { | 453 | { |
531 | .attr = { .name = "profile2_settings", .mode = 0440 }, | 454 | .attr = { .name = "profile2_settings", .mode = 0440 }, |
532 | .size = sizeof(struct pyra_profile_settings), | 455 | .size = sizeof(struct pyra_profile_settings), |
533 | .read = pyra_sysfs_read_profile2_settings | 456 | .read = pyra_sysfs_read_profilex_settings, |
457 | .private = &profile_numbers[1] | ||
534 | }, | 458 | }, |
535 | { | 459 | { |
536 | .attr = { .name = "profile3_settings", .mode = 0440 }, | 460 | .attr = { .name = "profile3_settings", .mode = 0440 }, |
537 | .size = sizeof(struct pyra_profile_settings), | 461 | .size = sizeof(struct pyra_profile_settings), |
538 | .read = pyra_sysfs_read_profile3_settings | 462 | .read = pyra_sysfs_read_profilex_settings, |
463 | .private = &profile_numbers[2] | ||
539 | }, | 464 | }, |
540 | { | 465 | { |
541 | .attr = { .name = "profile4_settings", .mode = 0440 }, | 466 | .attr = { .name = "profile4_settings", .mode = 0440 }, |
542 | .size = sizeof(struct pyra_profile_settings), | 467 | .size = sizeof(struct pyra_profile_settings), |
543 | .read = pyra_sysfs_read_profile4_settings | 468 | .read = pyra_sysfs_read_profilex_settings, |
469 | .private = &profile_numbers[3] | ||
544 | }, | 470 | }, |
545 | { | 471 | { |
546 | .attr = { .name = "profile5_settings", .mode = 0440 }, | 472 | .attr = { .name = "profile5_settings", .mode = 0440 }, |
547 | .size = sizeof(struct pyra_profile_settings), | 473 | .size = sizeof(struct pyra_profile_settings), |
548 | .read = pyra_sysfs_read_profile5_settings | 474 | .read = pyra_sysfs_read_profilex_settings, |
475 | .private = &profile_numbers[4] | ||
549 | }, | 476 | }, |
550 | { | 477 | { |
551 | .attr = { .name = "profile_buttons", .mode = 0220 }, | 478 | .attr = { .name = "profile_buttons", .mode = 0220 }, |
@@ -555,27 +482,32 @@ static struct bin_attribute pyra_bin_attributes[] = { | |||
555 | { | 482 | { |
556 | .attr = { .name = "profile1_buttons", .mode = 0440 }, | 483 | .attr = { .name = "profile1_buttons", .mode = 0440 }, |
557 | .size = sizeof(struct pyra_profile_buttons), | 484 | .size = sizeof(struct pyra_profile_buttons), |
558 | .read = pyra_sysfs_read_profile1_buttons | 485 | .read = pyra_sysfs_read_profilex_buttons, |
486 | .private = &profile_numbers[0] | ||
559 | }, | 487 | }, |
560 | { | 488 | { |
561 | .attr = { .name = "profile2_buttons", .mode = 0440 }, | 489 | .attr = { .name = "profile2_buttons", .mode = 0440 }, |
562 | .size = sizeof(struct pyra_profile_buttons), | 490 | .size = sizeof(struct pyra_profile_buttons), |
563 | .read = pyra_sysfs_read_profile2_buttons | 491 | .read = pyra_sysfs_read_profilex_buttons, |
492 | .private = &profile_numbers[1] | ||
564 | }, | 493 | }, |
565 | { | 494 | { |
566 | .attr = { .name = "profile3_buttons", .mode = 0440 }, | 495 | .attr = { .name = "profile3_buttons", .mode = 0440 }, |
567 | .size = sizeof(struct pyra_profile_buttons), | 496 | .size = sizeof(struct pyra_profile_buttons), |
568 | .read = pyra_sysfs_read_profile3_buttons | 497 | .read = pyra_sysfs_read_profilex_buttons, |
498 | .private = &profile_numbers[2] | ||
569 | }, | 499 | }, |
570 | { | 500 | { |
571 | .attr = { .name = "profile4_buttons", .mode = 0440 }, | 501 | .attr = { .name = "profile4_buttons", .mode = 0440 }, |
572 | .size = sizeof(struct pyra_profile_buttons), | 502 | .size = sizeof(struct pyra_profile_buttons), |
573 | .read = pyra_sysfs_read_profile4_buttons | 503 | .read = pyra_sysfs_read_profilex_buttons, |
504 | .private = &profile_numbers[3] | ||
574 | }, | 505 | }, |
575 | { | 506 | { |
576 | .attr = { .name = "profile5_buttons", .mode = 0440 }, | 507 | .attr = { .name = "profile5_buttons", .mode = 0440 }, |
577 | .size = sizeof(struct pyra_profile_buttons), | 508 | .size = sizeof(struct pyra_profile_buttons), |
578 | .read = pyra_sysfs_read_profile5_buttons | 509 | .read = pyra_sysfs_read_profilex_buttons, |
510 | .private = &profile_numbers[4] | ||
579 | }, | 511 | }, |
580 | { | 512 | { |
581 | .attr = { .name = "settings", .mode = 0660 }, | 513 | .attr = { .name = "settings", .mode = 0660 }, |