20 #include <linux/device.h>
21 #include <linux/input.h>
22 #include <linux/hid.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
30 static uint profile_numbers[5] = {0, 1, 2, 3, 4};
33 static struct class *pyra_class;
35 static void profile_activated(
struct pyra_device *pyra,
36 unsigned int new_profile)
42 static int pyra_send_control(
struct usb_device *usb_dev,
int value,
49 (value < 0 || value > 4))
60 static int pyra_get_profile_settings(
struct usb_device *usb_dev,
64 retval = pyra_send_control(usb_dev, number,
72 static int pyra_get_profile_buttons(
struct usb_device *usb_dev,
76 retval = pyra_send_control(usb_dev, number,
84 static int pyra_get_settings(
struct usb_device *usb_dev,
91 static int pyra_get_info(
struct usb_device *usb_dev,
struct pyra_info *buf)
97 static int pyra_set_profile_settings(
struct usb_device *usb_dev,
105 static int pyra_set_profile_buttons(
struct usb_device *usb_dev,
113 static int pyra_set_settings(
struct usb_device *usb_dev,
121 static ssize_t pyra_sysfs_read_profilex_settings(
struct file *
fp,
123 loff_t off,
size_t count)
143 static ssize_t pyra_sysfs_read_profilex_buttons(
struct file *fp,
145 loff_t off,
size_t count)
165 static ssize_t pyra_sysfs_write_profile_settings(
struct file *fp,
167 loff_t off,
size_t count)
172 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
185 difference =
memcmp(buf, profile_settings,
188 retval = pyra_set_profile_settings(usb_dev,
191 memcpy(profile_settings, buf,
202 static ssize_t pyra_sysfs_write_profile_buttons(
struct file *fp,
204 loff_t off,
size_t count)
209 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
222 difference =
memcmp(buf, profile_buttons,
225 retval = pyra_set_profile_buttons(usb_dev,
228 memcpy(profile_buttons, buf,
239 static ssize_t pyra_sysfs_read_settings(
struct file *fp,
241 loff_t off,
size_t count)
260 static ssize_t pyra_sysfs_write_settings(
struct file *fp,
262 loff_t off,
size_t count)
267 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
278 retval = pyra_set_settings(usb_dev,
288 profile_activated(pyra, pyra->
settings.startup_profile);
301 static ssize_t pyra_sysfs_show_actual_cpi(
struct device *dev,
309 static ssize_t pyra_sysfs_show_actual_profile(
struct device *dev,
317 static ssize_t pyra_sysfs_show_firmware_version(
struct device *dev,
325 static ssize_t pyra_sysfs_show_startup_profile(
struct device *dev,
334 __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi,
NULL),
337 pyra_sysfs_show_firmware_version,
NULL),
339 pyra_sysfs_show_startup_profile,
NULL),
345 .attr = { .name =
"profile_settings", .mode = 0220 },
347 .
write = pyra_sysfs_write_profile_settings
350 .attr = { .name =
"profile1_settings", .mode = 0440 },
352 .
read = pyra_sysfs_read_profilex_settings,
353 .private = &profile_numbers[0]
356 .attr = { .name =
"profile2_settings", .mode = 0440 },
358 .
read = pyra_sysfs_read_profilex_settings,
359 .private = &profile_numbers[1]
362 .attr = { .name =
"profile3_settings", .mode = 0440 },
364 .
read = pyra_sysfs_read_profilex_settings,
365 .private = &profile_numbers[2]
368 .attr = { .name =
"profile4_settings", .mode = 0440 },
370 .
read = pyra_sysfs_read_profilex_settings,
371 .private = &profile_numbers[3]
374 .attr = { .name =
"profile5_settings", .mode = 0440 },
376 .
read = pyra_sysfs_read_profilex_settings,
377 .private = &profile_numbers[4]
380 .attr = { .name =
"profile_buttons", .mode = 0220 },
382 .
write = pyra_sysfs_write_profile_buttons
385 .attr = { .name =
"profile1_buttons", .mode = 0440 },
387 .
read = pyra_sysfs_read_profilex_buttons,
388 .private = &profile_numbers[0]
391 .attr = { .name =
"profile2_buttons", .mode = 0440 },
393 .
read = pyra_sysfs_read_profilex_buttons,
394 .private = &profile_numbers[1]
397 .attr = { .name =
"profile3_buttons", .mode = 0440 },
399 .
read = pyra_sysfs_read_profilex_buttons,
400 .private = &profile_numbers[2]
403 .attr = { .name =
"profile4_buttons", .mode = 0440 },
405 .
read = pyra_sysfs_read_profilex_buttons,
406 .private = &profile_numbers[3]
409 .attr = { .name =
"profile5_buttons", .mode = 0440 },
411 .
read = pyra_sysfs_read_profilex_buttons,
412 .private = &profile_numbers[4]
415 .attr = { .name =
"settings", .mode = 0660 },
417 .
read = pyra_sysfs_read_settings,
418 .write = pyra_sysfs_write_settings
423 static int pyra_init_pyra_device_struct(
struct usb_device *usb_dev,
431 retval = pyra_get_info(usb_dev, &
info);
437 retval = pyra_get_settings(usb_dev, &pyra->
settings);
441 for (i = 0; i < 5; ++
i) {
442 retval = pyra_get_profile_settings(usb_dev,
447 retval = pyra_get_profile_buttons(usb_dev,
453 profile_activated(pyra, pyra->
settings.startup_profile);
458 static int pyra_init_specials(
struct hid_device *hdev)
461 struct usb_device *usb_dev = interface_to_usbdev(intf);
465 if (intf->cur_altsetting->desc.bInterfaceProtocol
470 hid_err(hdev,
"can't alloc device descriptor\n");
473 hid_set_drvdata(hdev, pyra);
475 retval = pyra_init_pyra_device_struct(usb_dev, pyra);
477 hid_err(hdev,
"couldn't init struct pyra_device\n");
484 hid_err(hdev,
"couldn't init char dev\n");
490 hid_set_drvdata(hdev,
NULL);
499 static void pyra_remove_specials(
struct hid_device *hdev)
504 if (intf->cur_altsetting->desc.bInterfaceProtocol
506 pyra = hid_get_drvdata(hdev);
509 kfree(hid_get_drvdata(hdev));
517 retval = hid_parse(hdev);
519 hid_err(hdev,
"parse failed\n");
525 hid_err(hdev,
"hw start failed\n");
529 retval = pyra_init_specials(hdev);
531 hid_err(hdev,
"couldn't install mouse\n");
542 static void pyra_remove(
struct hid_device *hdev)
544 pyra_remove_specials(hdev);
548 static void pyra_keep_values_up_to_date(
struct pyra_device *pyra,
556 switch (button_event->
type) {
558 profile_activated(pyra, button_event->
data1 - 1);
568 static void pyra_report_to_chrdev(
struct pyra_device const *pyra,
579 switch (button_event->
type) {
612 if (intf->cur_altsetting->desc.bInterfaceProtocol
619 pyra_keep_values_up_to_date(pyra, data);
622 pyra_report_to_chrdev(pyra, data);
639 .id_table = pyra_devices,
641 .remove = pyra_remove,
642 .raw_event = pyra_raw_event
645 static int __init pyra_init(
void)
651 if (IS_ERR(pyra_class))
652 return PTR_ERR(pyra_class);
662 static void __exit pyra_exit(
void)