hid-roccat-common.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __HID_ROCCAT_COMMON_H
  3. #define __HID_ROCCAT_COMMON_H
  4. /*
  5. * Copyright (c) 2011 Stefan Achatz <[email protected]>
  6. */
  7. /*
  8. */
  9. #include <linux/usb.h>
  10. #include <linux/types.h>
  11. enum roccat_common2_commands {
  12. ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
  13. };
  14. struct roccat_common2_control {
  15. uint8_t command;
  16. uint8_t value;
  17. uint8_t request; /* always 0 on requesting write check */
  18. } __packed;
  19. int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
  20. void *data, uint size);
  21. int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
  22. void const *data, uint size);
  23. int roccat_common2_send_with_status(struct usb_device *usb_dev,
  24. uint command, void const *buf, uint size);
  25. struct roccat_common2_device {
  26. int roccat_claimed;
  27. int chrdev_minor;
  28. struct mutex lock;
  29. };
  30. int roccat_common2_device_init_struct(struct usb_device *usb_dev,
  31. struct roccat_common2_device *dev);
  32. ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
  33. char *buf, loff_t off, size_t count,
  34. size_t real_size, uint command);
  35. ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
  36. void const *buf, loff_t off, size_t count,
  37. size_t real_size, uint command);
  38. #define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
  39. static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
  40. struct kobject *kobj, struct bin_attribute *attr, char *buf, \
  41. loff_t off, size_t count) \
  42. { \
  43. return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
  44. SIZE, COMMAND); \
  45. }
  46. #define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
  47. static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
  48. struct kobject *kobj, struct bin_attribute *attr, char *buf, \
  49. loff_t off, size_t count) \
  50. { \
  51. return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
  52. SIZE, COMMAND); \
  53. }
  54. #define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \
  55. ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
  56. ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
  57. #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
  58. ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
  59. static struct bin_attribute bin_attr_ ## thingy = { \
  60. .attr = { .name = #thingy, .mode = 0660 }, \
  61. .size = SIZE, \
  62. .read = roccat_common2_sysfs_read_ ## thingy, \
  63. .write = roccat_common2_sysfs_write_ ## thingy \
  64. }
  65. #define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
  66. ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
  67. static struct bin_attribute bin_attr_ ## thingy = { \
  68. .attr = { .name = #thingy, .mode = 0440 }, \
  69. .size = SIZE, \
  70. .read = roccat_common2_sysfs_read_ ## thingy, \
  71. }
  72. #define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
  73. ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
  74. static struct bin_attribute bin_attr_ ## thingy = { \
  75. .attr = { .name = #thingy, .mode = 0220 }, \
  76. .size = SIZE, \
  77. .write = roccat_common2_sysfs_write_ ## thingy \
  78. }
  79. #endif