blob: 839ddfd931f076a2c3c2ab3a6d8186004273f2e1 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Stefan Achatz5772f632011-01-30 13:38:23 +01002#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 Achatz5772f632011-01-30 13:38:23 +010010 */
11
12#include <linux/usb.h>
13#include <linux/types.h>
14
Stefan Achatz7392d732012-05-20 22:45:04 +020015enum roccat_common2_commands {
Stefan Achatz4728f2d2012-05-20 22:44:59 +020016 ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
17};
18
Stefan Achatz7392d732012-05-20 22:45:04 +020019struct roccat_common2_control {
Stefan Achatz4728f2d2012-05-20 22:44:59 +020020 uint8_t command;
21 uint8_t value;
22 uint8_t request; /* always 0 on requesting write check */
23} __packed;
24
Stefan Achatz7392d732012-05-20 22:45:04 +020025int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
Stefan Achatz5772f632011-01-30 13:38:23 +010026 void *data, uint size);
Stefan Achatz7392d732012-05-20 22:45:04 +020027int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
Stefan Achatz5772f632011-01-30 13:38:23 +010028 void const *data, uint size);
Stefan Achatz7392d732012-05-20 22:45:04 +020029int roccat_common2_send_with_status(struct usb_device *usb_dev,
Stefan Achatz4728f2d2012-05-20 22:44:59 +020030 uint command, void const *buf, uint size);
Stefan Achatz5772f632011-01-30 13:38:23 +010031
Stefan Achatz71304f52013-10-28 18:52:05 +010032struct 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
Stefan Achatz5772f632011-01-30 13:38:23 +010094#endif