hid-roccat-common.h 2.88 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2 3 4 5 6 7 8 9 10 11 12 13 14
#ifndef __HID_ROCCAT_COMMON_H
#define __HID_ROCCAT_COMMON_H

/*
 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
 */

/*
 */

#include <linux/usb.h>
#include <linux/types.h>

15
enum roccat_common2_commands {
16 17 18
	ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
};

19
struct roccat_common2_control {
20 21 22 23 24
	uint8_t command;
	uint8_t value;
	uint8_t request; /* always 0 on requesting write check */
} __packed;

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
struct roccat_common2_device {
	int roccat_claimed;
	int chrdev_minor;
	struct mutex lock;
};

int roccat_common2_device_init_struct(struct usb_device *usb_dev,
		struct roccat_common2_device *dev);
ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
		char *buf, loff_t off, size_t count,
		size_t real_size, uint command);
ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
		void const *buf, loff_t off, size_t count,
		size_t real_size, uint command);

#define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
		struct kobject *kobj, struct bin_attribute *attr, char *buf, \
		loff_t off, size_t count) \
{ \
	return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
			SIZE, COMMAND); \
}

#define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
		struct kobject *kobj, struct bin_attribute *attr, char *buf, \
		loff_t off, size_t count) \
{ \
	return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
			SIZE, COMMAND); \
}

#define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \
ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)

#define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
static struct bin_attribute bin_attr_ ## thingy = { \
	.attr = { .name = #thingy, .mode = 0660 }, \
	.size = SIZE, \
	.read = roccat_common2_sysfs_read_ ## thingy, \
	.write = roccat_common2_sysfs_write_ ## thingy \
}

#define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
static struct bin_attribute bin_attr_ ## thingy = { \
	.attr = { .name = #thingy, .mode = 0440 }, \
	.size = SIZE, \
	.read = roccat_common2_sysfs_read_ ## thingy, \
}

#define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
static struct bin_attribute bin_attr_ ## thingy = { \
	.attr = { .name = #thingy, .mode = 0220 }, \
	.size = SIZE, \
	.write = roccat_common2_sysfs_write_ ## thingy \
}

94
#endif