aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-roccat-common.c
diff options
context:
space:
mode:
authorStefan Achatz <erazor_de@users.sourceforge.net>2012-05-20 16:44:59 -0400
committerJiri Kosina <jkosina@suse.cz>2012-06-28 04:34:01 -0400
commit4728f2dc9f8e32ce898223fb863316ed7fa2d224 (patch)
treec8f2df1b448db340d556bf1be42b35cb96d4f0ab /drivers/hid/hid-roccat-common.c
parent6a2a6390cf098b899a30146ef5c1fb85c9fefb3c (diff)
HID: roccat: move functionality to roccat-common
Reduced code duplication by moving functions from individual drivers to roccat-common module. Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-roccat-common.c')
-rw-r--r--drivers/hid/hid-roccat-common.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/hid/hid-roccat-common.c b/drivers/hid/hid-roccat-common.c
index a6d93992c75a..291414eac279 100644
--- a/drivers/hid/hid-roccat-common.c
+++ b/drivers/hid/hid-roccat-common.c
@@ -64,6 +64,64 @@ int roccat_common_send(struct usb_device *usb_dev, uint report_id,
64} 64}
65EXPORT_SYMBOL_GPL(roccat_common_send); 65EXPORT_SYMBOL_GPL(roccat_common_send);
66 66
67enum roccat_common_control_states {
68 ROCCAT_COMMON_CONTROL_STATUS_OVERLOAD = 0,
69 ROCCAT_COMMON_CONTROL_STATUS_OK = 1,
70 ROCCAT_COMMON_CONTROL_STATUS_INVALID = 2,
71 ROCCAT_COMMON_CONTROL_STATUS_WAIT = 3,
72};
73
74static int roccat_common_receive_control_status(struct usb_device *usb_dev)
75{
76 int retval;
77 struct roccat_common_control control;
78
79 do {
80 msleep(50);
81 retval = roccat_common_receive(usb_dev,
82 ROCCAT_COMMON_COMMAND_CONTROL,
83 &control, sizeof(struct roccat_common_control));
84
85 if (retval)
86 return retval;
87
88 switch (control.value) {
89 case ROCCAT_COMMON_CONTROL_STATUS_OK:
90 return 0;
91 case ROCCAT_COMMON_CONTROL_STATUS_WAIT:
92 msleep(500);
93 continue;
94 case ROCCAT_COMMON_CONTROL_STATUS_INVALID:
95
96 case ROCCAT_COMMON_CONTROL_STATUS_OVERLOAD:
97 /* seems to be critical - replug necessary */
98 return -EINVAL;
99 default:
100 dev_err(&usb_dev->dev,
101 "roccat_common_receive_control_status: "
102 "unknown response value 0x%x\n",
103 control.value);
104 return -EINVAL;
105 }
106
107 } while (1);
108}
109
110int roccat_common_send_with_status(struct usb_device *usb_dev,
111 uint command, void const *buf, uint size)
112{
113 int retval;
114
115 retval = roccat_common_send(usb_dev, command, buf, size);
116 if (retval)
117 return retval;
118
119 msleep(100);
120
121 return roccat_common_receive_control_status(usb_dev);
122}
123EXPORT_SYMBOL_GPL(roccat_common_send_with_status);
124
67MODULE_AUTHOR("Stefan Achatz"); 125MODULE_AUTHOR("Stefan Achatz");
68MODULE_DESCRIPTION("USB Roccat common driver"); 126MODULE_DESCRIPTION("USB Roccat common driver");
69MODULE_LICENSE("GPL v2"); 127MODULE_LICENSE("GPL v2");