diff options
author | Stefan Achatz <erazor_de@users.sourceforge.net> | 2012-05-20 16:44:59 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2012-06-28 04:34:01 -0400 |
commit | 4728f2dc9f8e32ce898223fb863316ed7fa2d224 (patch) | |
tree | c8f2df1b448db340d556bf1be42b35cb96d4f0ab /drivers/hid/hid-roccat-kovaplus.c | |
parent | 6a2a6390cf098b899a30146ef5c1fb85c9fefb3c (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-kovaplus.c')
-rw-r--r-- | drivers/hid/hid-roccat-kovaplus.c | 63 |
1 files changed, 10 insertions, 53 deletions
diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c index 112d934132c8..c219cff91555 100644 --- a/drivers/hid/hid-roccat-kovaplus.c +++ b/drivers/hid/hid-roccat-kovaplus.c | |||
@@ -47,69 +47,23 @@ static int kovaplus_send_control(struct usb_device *usb_dev, uint value, | |||
47 | enum kovaplus_control_requests request) | 47 | enum kovaplus_control_requests request) |
48 | { | 48 | { |
49 | int retval; | 49 | int retval; |
50 | struct kovaplus_control control; | 50 | struct roccat_common_control control; |
51 | 51 | ||
52 | if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS || | 52 | if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS || |
53 | request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) && | 53 | request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) && |
54 | value > 4) | 54 | value > 4) |
55 | return -EINVAL; | 55 | return -EINVAL; |
56 | 56 | ||
57 | control.command = KOVAPLUS_COMMAND_CONTROL; | 57 | control.command = ROCCAT_COMMON_COMMAND_CONTROL; |
58 | control.value = value; | 58 | control.value = value; |
59 | control.request = request; | 59 | control.request = request; |
60 | 60 | ||
61 | retval = roccat_common_send(usb_dev, KOVAPLUS_COMMAND_CONTROL, | 61 | retval = roccat_common_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL, |
62 | &control, sizeof(struct kovaplus_control)); | 62 | &control, sizeof(struct roccat_common_control)); |
63 | 63 | ||
64 | return retval; | 64 | return retval; |
65 | } | 65 | } |
66 | 66 | ||
67 | static int kovaplus_receive_control_status(struct usb_device *usb_dev) | ||
68 | { | ||
69 | int retval; | ||
70 | struct kovaplus_control control; | ||
71 | |||
72 | do { | ||
73 | retval = roccat_common_receive(usb_dev, KOVAPLUS_COMMAND_CONTROL, | ||
74 | &control, sizeof(struct kovaplus_control)); | ||
75 | |||
76 | /* check if we get a completely wrong answer */ | ||
77 | if (retval) | ||
78 | return retval; | ||
79 | |||
80 | if (control.value == KOVAPLUS_CONTROL_REQUEST_STATUS_OK) | ||
81 | return 0; | ||
82 | |||
83 | /* indicates that hardware needs some more time to complete action */ | ||
84 | if (control.value == KOVAPLUS_CONTROL_REQUEST_STATUS_WAIT) { | ||
85 | msleep(500); /* windows driver uses 1000 */ | ||
86 | continue; | ||
87 | } | ||
88 | |||
89 | /* seems to be critical - replug necessary */ | ||
90 | if (control.value == KOVAPLUS_CONTROL_REQUEST_STATUS_OVERLOAD) | ||
91 | return -EINVAL; | ||
92 | |||
93 | hid_err(usb_dev, "roccat_common_receive_control_status: " | ||
94 | "unknown response value 0x%x\n", control.value); | ||
95 | return -EINVAL; | ||
96 | } while (1); | ||
97 | } | ||
98 | |||
99 | static int kovaplus_send(struct usb_device *usb_dev, uint command, | ||
100 | void const *buf, uint size) | ||
101 | { | ||
102 | int retval; | ||
103 | |||
104 | retval = roccat_common_send(usb_dev, command, buf, size); | ||
105 | if (retval) | ||
106 | return retval; | ||
107 | |||
108 | msleep(100); | ||
109 | |||
110 | return kovaplus_receive_control_status(usb_dev); | ||
111 | } | ||
112 | |||
113 | static int kovaplus_select_profile(struct usb_device *usb_dev, uint number, | 67 | static int kovaplus_select_profile(struct usb_device *usb_dev, uint number, |
114 | enum kovaplus_control_requests request) | 68 | enum kovaplus_control_requests request) |
115 | { | 69 | { |
@@ -140,7 +94,8 @@ static int kovaplus_get_profile_settings(struct usb_device *usb_dev, | |||
140 | static int kovaplus_set_profile_settings(struct usb_device *usb_dev, | 94 | static int kovaplus_set_profile_settings(struct usb_device *usb_dev, |
141 | struct kovaplus_profile_settings const *settings) | 95 | struct kovaplus_profile_settings const *settings) |
142 | { | 96 | { |
143 | return kovaplus_send(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS, | 97 | return roccat_common_send_with_status(usb_dev, |
98 | KOVAPLUS_COMMAND_PROFILE_SETTINGS, | ||
144 | settings, sizeof(struct kovaplus_profile_settings)); | 99 | settings, sizeof(struct kovaplus_profile_settings)); |
145 | } | 100 | } |
146 | 101 | ||
@@ -161,7 +116,8 @@ static int kovaplus_get_profile_buttons(struct usb_device *usb_dev, | |||
161 | static int kovaplus_set_profile_buttons(struct usb_device *usb_dev, | 116 | static int kovaplus_set_profile_buttons(struct usb_device *usb_dev, |
162 | struct kovaplus_profile_buttons const *buttons) | 117 | struct kovaplus_profile_buttons const *buttons) |
163 | { | 118 | { |
164 | return kovaplus_send(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS, | 119 | return roccat_common_send_with_status(usb_dev, |
120 | KOVAPLUS_COMMAND_PROFILE_BUTTONS, | ||
165 | buttons, sizeof(struct kovaplus_profile_buttons)); | 121 | buttons, sizeof(struct kovaplus_profile_buttons)); |
166 | } | 122 | } |
167 | 123 | ||
@@ -186,7 +142,8 @@ static int kovaplus_set_actual_profile(struct usb_device *usb_dev, | |||
186 | buf.size = sizeof(struct kovaplus_actual_profile); | 142 | buf.size = sizeof(struct kovaplus_actual_profile); |
187 | buf.actual_profile = new_profile; | 143 | buf.actual_profile = new_profile; |
188 | 144 | ||
189 | return kovaplus_send(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE, | 145 | return roccat_common_send_with_status(usb_dev, |
146 | KOVAPLUS_COMMAND_ACTUAL_PROFILE, | ||
190 | &buf, sizeof(struct kovaplus_actual_profile)); | 147 | &buf, sizeof(struct kovaplus_actual_profile)); |
191 | } | 148 | } |
192 | 149 | ||