Loading...
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
15enum roccat_common2_commands {
16 ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
17};
18
19struct roccat_common2_control {
20 uint8_t command;
21 uint8_t value;
22 uint8_t request; /* always 0 on requesting write check */
23} __packed;
24
25int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
26 void *data, uint size);
27int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
28 void const *data, uint size);
29int roccat_common2_send_with_status(struct usb_device *usb_dev,
30 uint command, void const *buf, uint size);
31
32struct roccat_common2_device {
33 int roccat_claimed;
34 int chrdev_minor;
35 struct mutex lock;
36};
37
38int roccat_common2_device_init_struct(struct usb_device *usb_dev,
39 struct roccat_common2_device *dev);
40ssize_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);
43ssize_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) \
48static 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) \
57static 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) \
66ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
67ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
68
69#define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
70ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
71static 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) \
79ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
80static 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) \
87ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
88static 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
1#ifndef __HID_ROCCAT_COMMON_H
2#define __HID_ROCCAT_COMMON_H
3
4/*
5 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/usb.h>
16#include <linux/types.h>
17
18enum roccat_common2_commands {
19 ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
20};
21
22struct roccat_common2_control {
23 uint8_t command;
24 uint8_t value;
25 uint8_t request; /* always 0 on requesting write check */
26} __packed;
27
28int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
29 void *data, uint size);
30int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
31 void const *data, uint size);
32int roccat_common2_send_with_status(struct usb_device *usb_dev,
33 uint command, void const *buf, uint size);
34
35struct roccat_common2_device {
36 int roccat_claimed;
37 int chrdev_minor;
38 struct mutex lock;
39};
40
41int roccat_common2_device_init_struct(struct usb_device *usb_dev,
42 struct roccat_common2_device *dev);
43ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
44 char *buf, loff_t off, size_t count,
45 size_t real_size, uint command);
46ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
47 void const *buf, loff_t off, size_t count,
48 size_t real_size, uint command);
49
50#define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
51static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
52 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
53 loff_t off, size_t count) \
54{ \
55 return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
56 SIZE, COMMAND); \
57}
58
59#define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
60static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
61 struct kobject *kobj, struct bin_attribute *attr, char *buf, \
62 loff_t off, size_t count) \
63{ \
64 return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
65 SIZE, COMMAND); \
66}
67
68#define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \
69ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
70ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
71
72#define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
73ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
74static struct bin_attribute bin_attr_ ## thingy = { \
75 .attr = { .name = #thingy, .mode = 0660 }, \
76 .size = SIZE, \
77 .read = roccat_common2_sysfs_read_ ## thingy, \
78 .write = roccat_common2_sysfs_write_ ## thingy \
79}
80
81#define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
82ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
83static struct bin_attribute bin_attr_ ## thingy = { \
84 .attr = { .name = #thingy, .mode = 0440 }, \
85 .size = SIZE, \
86 .read = roccat_common2_sysfs_read_ ## thingy, \
87}
88
89#define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
90ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
91static struct bin_attribute bin_attr_ ## thingy = { \
92 .attr = { .name = #thingy, .mode = 0220 }, \
93 .size = SIZE, \
94 .write = roccat_common2_sysfs_write_ ## thingy \
95}
96
97#endif