Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 2 | #ifndef __HID_ROCCAT_COMMON_H |
| 3 | #define __HID_ROCCAT_COMMON_H |
| 4 | |
| 5 | /* |
| 6 | * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net> |
| 7 | */ |
| 8 | |
| 9 | /* |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/usb.h> |
| 13 | #include <linux/types.h> |
| 14 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 15 | enum roccat_common2_commands { |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 16 | ROCCAT_COMMON_COMMAND_CONTROL = 0x4, |
| 17 | }; |
| 18 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 19 | struct roccat_common2_control { |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 20 | uint8_t command; |
| 21 | uint8_t value; |
| 22 | uint8_t request; /* always 0 on requesting write check */ |
| 23 | } __packed; |
| 24 | |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 25 | int roccat_common2_receive(struct usb_device *usb_dev, uint report_id, |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 26 | void *data, uint size); |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 27 | int roccat_common2_send(struct usb_device *usb_dev, uint report_id, |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 28 | void const *data, uint size); |
Stefan Achatz | 7392d73 | 2012-05-20 22:45:04 +0200 | [diff] [blame] | 29 | int roccat_common2_send_with_status(struct usb_device *usb_dev, |
Stefan Achatz | 4728f2d | 2012-05-20 22:44:59 +0200 | [diff] [blame] | 30 | uint command, void const *buf, uint size); |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 31 | |
Stefan Achatz | 71304f5 | 2013-10-28 18:52:05 +0100 | [diff] [blame] | 32 | struct roccat_common2_device { |
| 33 | int roccat_claimed; |
| 34 | int chrdev_minor; |
| 35 | struct mutex lock; |
| 36 | }; |
| 37 | |
| 38 | int roccat_common2_device_init_struct(struct usb_device *usb_dev, |
| 39 | struct roccat_common2_device *dev); |
| 40 | ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj, |
| 41 | char *buf, loff_t off, size_t count, |
| 42 | size_t real_size, uint command); |
| 43 | ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj, |
| 44 | void const *buf, loff_t off, size_t count, |
| 45 | size_t real_size, uint command); |
| 46 | |
| 47 | #define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \ |
| 48 | static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \ |
| 49 | struct kobject *kobj, struct bin_attribute *attr, char *buf, \ |
| 50 | loff_t off, size_t count) \ |
| 51 | { \ |
| 52 | return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \ |
| 53 | SIZE, COMMAND); \ |
| 54 | } |
| 55 | |
| 56 | #define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \ |
| 57 | static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \ |
| 58 | struct kobject *kobj, struct bin_attribute *attr, char *buf, \ |
| 59 | loff_t off, size_t count) \ |
| 60 | { \ |
| 61 | return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \ |
| 62 | SIZE, COMMAND); \ |
| 63 | } |
| 64 | |
| 65 | #define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \ |
| 66 | ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \ |
| 67 | ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) |
| 68 | |
| 69 | #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \ |
| 70 | ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \ |
| 71 | static struct bin_attribute bin_attr_ ## thingy = { \ |
| 72 | .attr = { .name = #thingy, .mode = 0660 }, \ |
| 73 | .size = SIZE, \ |
| 74 | .read = roccat_common2_sysfs_read_ ## thingy, \ |
| 75 | .write = roccat_common2_sysfs_write_ ## thingy \ |
| 76 | } |
| 77 | |
| 78 | #define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \ |
| 79 | ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \ |
| 80 | static struct bin_attribute bin_attr_ ## thingy = { \ |
| 81 | .attr = { .name = #thingy, .mode = 0440 }, \ |
| 82 | .size = SIZE, \ |
| 83 | .read = roccat_common2_sysfs_read_ ## thingy, \ |
| 84 | } |
| 85 | |
| 86 | #define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \ |
| 87 | ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \ |
| 88 | static struct bin_attribute bin_attr_ ## thingy = { \ |
| 89 | .attr = { .name = #thingy, .mode = 0220 }, \ |
| 90 | .size = SIZE, \ |
| 91 | .write = roccat_common2_sysfs_write_ ## thingy \ |
| 92 | } |
| 93 | |
Stefan Achatz | 5772f63 | 2011-01-30 13:38:23 +0100 | [diff] [blame] | 94 | #endif |