]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/hid/hid-roccat-common.h
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / drivers / hid / hid-roccat-common.h
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
18 enum roccat_common2_commands {
19 ROCCAT_COMMON_COMMAND_CONTROL = 0x4,
20 };
21
22 struct roccat_common2_control {
23 uint8_t command;
24 uint8_t value;
25 uint8_t request; /* always 0 on requesting write check */
26 } __packed;
27
28 int roccat_common2_receive(struct usb_device *usb_dev, uint report_id,
29 void *data, uint size);
30 int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
31 void const *data, uint size);
32 int roccat_common2_send_with_status(struct usb_device *usb_dev,
33 uint command, void const *buf, uint size);
34
35 struct roccat_common2_device {
36 int roccat_claimed;
37 int chrdev_minor;
38 struct mutex lock;
39 };
40
41 int roccat_common2_device_init_struct(struct usb_device *usb_dev,
42 struct roccat_common2_device *dev);
43 ssize_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);
46 ssize_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) \
51 static 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) \
60 static 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) \
69 ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
70 ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
71
72 #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
73 ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
74 static 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) \
82 ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
83 static 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) \
90 ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
91 static 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