hid-roccat-common.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __HID_ROCCAT_COMMON_H
  2. #define __HID_ROCCAT_COMMON_H
  3. /*
  4. * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include <linux/usb.h>
  13. #include <linux/types.h>
  14. enum roccat_common2_commands {
  15. ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
  16. };
  17. struct roccat_common2_control {
  18. uint8_t command;
  19. uint8_t value;
  20. uint8_t request; /* always 0 on requesting write check */
  21. } __packed;
  22. int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
  23. void *data, uint size);
  24. int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
  25. void const *data, uint size);
  26. int roccat_common2_send_with_status(struct usb_device *usb_dev,
  27. uint command, void const *buf, uint size);
  28. struct roccat_common2_device {
  29. int roccat_claimed;
  30. int chrdev_minor;
  31. struct mutex lock;
  32. };
  33. int roccat_common2_device_init_struct(struct usb_device *usb_dev,
  34. struct roccat_common2_device *dev);
  35. ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
  36. char *buf, loff_t off, size_t count,
  37. size_t real_size, uint command);
  38. ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
  39. void const *buf, loff_t off, size_t count,
  40. size_t real_size, uint command);
  41. #define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
  42. static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
  43. struct kobject *kobj, struct bin_attribute *attr, char *buf, \
  44. loff_t off, size_t count) \
  45. { \
  46. return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
  47. SIZE, COMMAND); \
  48. }
  49. #define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
  50. static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
  51. struct kobject *kobj, struct bin_attribute *attr, char *buf, \
  52. loff_t off, size_t count) \
  53. { \
  54. return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
  55. SIZE, COMMAND); \
  56. }
  57. #define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \
  58. ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
  59. ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
  60. #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
  61. ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
  62. static struct bin_attribute bin_attr_ ## thingy = { \
  63. .attr = { .name = #thingy, .mode = 0660 }, \
  64. .size = SIZE, \
  65. .read = roccat_common2_sysfs_read_ ## thingy, \
  66. .write = roccat_common2_sysfs_write_ ## thingy \
  67. }
  68. #define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
  69. ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
  70. static struct bin_attribute bin_attr_ ## thingy = { \
  71. .attr = { .name = #thingy, .mode = 0440 }, \
  72. .size = SIZE, \
  73. .read = roccat_common2_sysfs_read_ ## thingy, \
  74. }
  75. #define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
  76. ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
  77. static struct bin_attribute bin_attr_ ## thingy = { \
  78. .attr = { .name = #thingy, .mode = 0220 }, \
  79. .size = SIZE, \
  80. .write = roccat_common2_sysfs_write_ ## thingy \
  81. }
  82. #endif