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