• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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 /*
10  */
11 
12 #include <linux/usb.h>
13 #include <linux/types.h>
14 
15 enum roccat_common2_commands {
16 	ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
17 };
18 
19 struct roccat_common2_control {
20 	uint8_t command;
21 	uint8_t value;
22 	uint8_t request; /* always 0 on requesting write check */
23 } __packed;
24 
25 int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
26 		void *data, uint size);
27 int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
28 		void const *data, uint size);
29 int roccat_common2_send_with_status(struct usb_device *usb_dev,
30 		uint command, void const *buf, uint size);
31 
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 
94 #endif
95