18 #include <linux/device.h>
19 #include <linux/input.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
28 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
30 static struct class *kovaplus_class;
34 return (value == 7 ? 4 : (value == 4 ? 3 : value));
37 static void kovaplus_profile_activated(
struct kovaplus_device *kovaplus,
38 uint new_profile_index)
46 static int kovaplus_send_control(
struct usb_device *usb_dev,
uint value,
67 static int kovaplus_select_profile(
struct usb_device *usb_dev,
uint number,
70 return kovaplus_send_control(usb_dev, number, request);
73 static int kovaplus_get_info(
struct usb_device *usb_dev,
80 static int kovaplus_get_profile_settings(
struct usb_device *usb_dev,
85 retval = kovaplus_select_profile(usb_dev, number,
94 static int kovaplus_set_profile_settings(
struct usb_device *usb_dev,
102 static int kovaplus_get_profile_buttons(
struct usb_device *usb_dev,
107 retval = kovaplus_select_profile(usb_dev, number,
116 static int kovaplus_set_profile_buttons(
struct usb_device *usb_dev,
125 static int kovaplus_get_actual_profile(
struct usb_device *usb_dev)
133 return retval ? retval : buf.actual_profile;
136 static int kovaplus_set_actual_profile(
struct usb_device *usb_dev,
143 buf.actual_profile = new_profile;
150 static ssize_t kovaplus_sysfs_read_profilex_settings(
struct file *
fp,
152 loff_t off,
size_t count)
172 static ssize_t kovaplus_sysfs_write_profile_settings(
struct file *fp,
174 loff_t off,
size_t count)
179 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
192 difference =
memcmp(buf, profile_settings,
195 retval = kovaplus_set_profile_settings(usb_dev,
198 memcpy(profile_settings, buf,
209 static ssize_t kovaplus_sysfs_read_profilex_buttons(
struct file *fp,
211 loff_t off,
size_t count)
231 static ssize_t kovaplus_sysfs_write_profile_buttons(
struct file *fp,
233 loff_t off,
size_t count)
238 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
251 difference =
memcmp(buf, profile_buttons,
254 retval = kovaplus_set_profile_buttons(usb_dev,
257 memcpy(profile_buttons, buf,
268 static ssize_t kovaplus_sysfs_show_actual_profile(
struct device *dev,
276 static ssize_t kovaplus_sysfs_set_actual_profile(
struct device *dev,
280 struct usb_device *usb_dev;
285 dev = dev->
parent->parent;
287 usb_dev = interface_to_usbdev(to_usb_interface(dev));
297 retval = kovaplus_set_actual_profile(usb_dev, profile);
303 kovaplus_profile_activated(kovaplus, profile);
318 static ssize_t kovaplus_sysfs_show_actual_cpi(
struct device *dev,
326 static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(
struct device *dev,
334 static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(
struct device *dev,
342 static ssize_t kovaplus_sysfs_show_firmware_version(
struct device *dev,
352 kovaplus_sysfs_show_actual_cpi,
NULL),
354 kovaplus_sysfs_show_firmware_version,
NULL),
356 kovaplus_sysfs_show_actual_profile,
357 kovaplus_sysfs_set_actual_profile),
358 __ATTR(actual_sensitivity_x, 0440,
359 kovaplus_sysfs_show_actual_sensitivity_x,
NULL),
360 __ATTR(actual_sensitivity_y, 0440,
361 kovaplus_sysfs_show_actual_sensitivity_y,
NULL),
367 .attr = { .name =
"profile_settings", .mode = 0220 },
369 .
write = kovaplus_sysfs_write_profile_settings
372 .attr = { .name =
"profile1_settings", .mode = 0440 },
374 .
read = kovaplus_sysfs_read_profilex_settings,
375 .private = &profile_numbers[0]
378 .attr = { .name =
"profile2_settings", .mode = 0440 },
380 .
read = kovaplus_sysfs_read_profilex_settings,
381 .private = &profile_numbers[1]
384 .attr = { .name =
"profile3_settings", .mode = 0440 },
386 .
read = kovaplus_sysfs_read_profilex_settings,
387 .private = &profile_numbers[2]
390 .attr = { .name =
"profile4_settings", .mode = 0440 },
392 .
read = kovaplus_sysfs_read_profilex_settings,
393 .private = &profile_numbers[3]
396 .attr = { .name =
"profile5_settings", .mode = 0440 },
398 .
read = kovaplus_sysfs_read_profilex_settings,
399 .private = &profile_numbers[4]
402 .attr = { .name =
"profile_buttons", .mode = 0220 },
404 .
write = kovaplus_sysfs_write_profile_buttons
407 .attr = { .name =
"profile1_buttons", .mode = 0440 },
409 .
read = kovaplus_sysfs_read_profilex_buttons,
410 .private = &profile_numbers[0]
413 .attr = { .name =
"profile2_buttons", .mode = 0440 },
415 .
read = kovaplus_sysfs_read_profilex_buttons,
416 .private = &profile_numbers[1]
419 .attr = { .name =
"profile3_buttons", .mode = 0440 },
421 .
read = kovaplus_sysfs_read_profilex_buttons,
422 .private = &profile_numbers[2]
425 .attr = { .name =
"profile4_buttons", .mode = 0440 },
427 .
read = kovaplus_sysfs_read_profilex_buttons,
428 .private = &profile_numbers[3]
431 .attr = { .name =
"profile5_buttons", .mode = 0440 },
433 .
read = kovaplus_sysfs_read_profilex_buttons,
434 .private = &profile_numbers[4]
439 static int kovaplus_init_kovaplus_device_struct(
struct usb_device *usb_dev,
447 retval = kovaplus_get_info(usb_dev, &kovaplus->
info);
451 for (i = 0; i < 5; ++
i) {
453 retval = kovaplus_get_profile_settings(usb_dev,
459 retval = kovaplus_get_profile_buttons(usb_dev,
466 retval = kovaplus_get_actual_profile(usb_dev);
469 kovaplus_profile_activated(kovaplus, retval);
474 static int kovaplus_init_specials(
struct hid_device *hdev)
477 struct usb_device *usb_dev = interface_to_usbdev(intf);
481 if (intf->cur_altsetting->desc.bInterfaceProtocol
484 kovaplus = kzalloc(
sizeof(*kovaplus),
GFP_KERNEL);
486 hid_err(hdev,
"can't alloc device descriptor\n");
489 hid_set_drvdata(hdev, kovaplus);
491 retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus);
493 hid_err(hdev,
"couldn't init struct kovaplus_device\n");
500 hid_err(hdev,
"couldn't init char dev\n");
507 hid_set_drvdata(hdev,
NULL);
516 static void kovaplus_remove_specials(
struct hid_device *hdev)
521 if (intf->cur_altsetting->desc.bInterfaceProtocol
523 kovaplus = hid_get_drvdata(hdev);
530 static int kovaplus_probe(
struct hid_device *hdev,
535 retval = hid_parse(hdev);
537 hid_err(hdev,
"parse failed\n");
543 hid_err(hdev,
"hw start failed\n");
547 retval = kovaplus_init_specials(hdev);
549 hid_err(hdev,
"couldn't install mouse\n");
561 static void kovaplus_remove(
struct hid_device *hdev)
563 kovaplus_remove_specials(hdev);
567 static void kovaplus_keep_values_up_to_date(
struct kovaplus_device *kovaplus,
577 switch (button_report->
type) {
579 kovaplus_profile_activated(kovaplus, button_report->
data1 - 1);
582 kovaplus->
actual_cpi = kovaplus_convert_event_cpi(button_report->
data1);
589 static void kovaplus_report_to_chrdev(
struct kovaplus_device const *kovaplus,
625 static int kovaplus_raw_event(
struct hid_device *hdev,
631 if (intf->cur_altsetting->desc.bInterfaceProtocol
635 if (kovaplus ==
NULL)
638 kovaplus_keep_values_up_to_date(kovaplus, data);
641 kovaplus_report_to_chrdev(kovaplus, data);
655 .id_table = kovaplus_devices,
656 .probe = kovaplus_probe,
657 .remove = kovaplus_remove,
658 .raw_event = kovaplus_raw_event
661 static int __init kovaplus_init(
void)
666 if (IS_ERR(kovaplus_class))
667 return PTR_ERR(kovaplus_class);
668 kovaplus_class->
dev_attrs = kovaplus_attributes;
677 static void __exit kovaplus_exit(
void)