0001
0002 #ifndef __HID_ROCCAT_COMMON_H
0003 #define __HID_ROCCAT_COMMON_H
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/usb.h>
0013 #include <linux/types.h>
0014
0015 enum roccat_common2_commands {
0016 ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
0017 };
0018
0019 struct roccat_common2_control {
0020 uint8_t command;
0021 uint8_t value;
0022 uint8_t request;
0023 } __packed;
0024
0025 int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
0026 void *data, uint size);
0027 int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
0028 void const *data, uint size);
0029 int roccat_common2_send_with_status(struct usb_device *usb_dev,
0030 uint command, void const *buf, uint size);
0031
0032 struct roccat_common2_device {
0033 int roccat_claimed;
0034 int chrdev_minor;
0035 struct mutex lock;
0036 };
0037
0038 int roccat_common2_device_init_struct(struct usb_device *usb_dev,
0039 struct roccat_common2_device *dev);
0040 ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
0041 char *buf, loff_t off, size_t count,
0042 size_t real_size, uint command);
0043 ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
0044 void const *buf, loff_t off, size_t count,
0045 size_t real_size, uint command);
0046
0047 #define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
0048 static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
0049 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
0050 loff_t off, size_t count) \
0051 { \
0052 return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
0053 SIZE, COMMAND); \
0054 }
0055
0056 #define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
0057 static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
0058 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
0059 loff_t off, size_t count) \
0060 { \
0061 return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
0062 SIZE, COMMAND); \
0063 }
0064
0065 #define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \
0066 ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
0067 ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
0068
0069 #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
0070 ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
0071 static struct bin_attribute bin_attr_ ## thingy = { \
0072 .attr = { .name = #thingy, .mode = 0660 }, \
0073 .size = SIZE, \
0074 .read = roccat_common2_sysfs_read_ ## thingy, \
0075 .write = roccat_common2_sysfs_write_ ## thingy \
0076 }
0077
0078 #define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
0079 ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
0080 static struct bin_attribute bin_attr_ ## thingy = { \
0081 .attr = { .name = #thingy, .mode = 0440 }, \
0082 .size = SIZE, \
0083 .read = roccat_common2_sysfs_read_ ## thingy, \
0084 }
0085
0086 #define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
0087 ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
0088 static struct bin_attribute bin_attr_ ## thingy = { \
0089 .attr = { .name = #thingy, .mode = 0220 }, \
0090 .size = SIZE, \
0091 .write = roccat_common2_sysfs_write_ ## thingy \
0092 }
0093
0094 #endif