diff options
author | Stefan Achatz <erazor_de@users.sourceforge.net> | 2011-01-30 07:38:23 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-02-03 10:37:27 -0500 |
commit | 5772f63613ce0a6777e82a7e8fb553e49da27719 (patch) | |
tree | 83c066e175d38323bccd4fd511c45dada6ba8ec0 /drivers/hid/hid-roccat-pyra.c | |
parent | a28764ef80dd5aef657f810a9c295ccda421c823 (diff) |
HID: roccat: Introduce module hid-roccat-common
Module hid-roccat-common contains functions used by roccat device driver
modules to reduce code duplication.
At the moment it contains just two wrapper methods for usb_control_msg
that ensure that the buffer used for transfer is dma capable which wasn't
the case before.
The kconfig option is not visible to the user but will be selected by the
device specific drivers.
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-pyra.c')
-rw-r--r-- | drivers/hid/hid-roccat-pyra.c | 161 |
1 files changed, 43 insertions, 118 deletions
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index 02c58e015bee..abe77d3e6d8b 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c | |||
@@ -20,11 +20,11 @@ | |||
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/input.h> | 21 | #include <linux/input.h> |
22 | #include <linux/hid.h> | 22 | #include <linux/hid.h> |
23 | #include <linux/usb.h> | ||
24 | #include <linux/module.h> | 23 | #include <linux/module.h> |
25 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
26 | #include "hid-ids.h" | 25 | #include "hid-ids.h" |
27 | #include "hid-roccat.h" | 26 | #include "hid-roccat.h" |
27 | #include "hid-roccat-common.h" | ||
28 | #include "hid-roccat-pyra.h" | 28 | #include "hid-roccat-pyra.h" |
29 | 29 | ||
30 | static uint profile_numbers[5] = {0, 1, 2, 3, 4}; | 30 | static uint profile_numbers[5] = {0, 1, 2, 3, 4}; |
@@ -42,7 +42,6 @@ static void profile_activated(struct pyra_device *pyra, | |||
42 | static int pyra_send_control(struct usb_device *usb_dev, int value, | 42 | static int pyra_send_control(struct usb_device *usb_dev, int value, |
43 | enum pyra_control_requests request) | 43 | enum pyra_control_requests request) |
44 | { | 44 | { |
45 | int len; | ||
46 | struct pyra_control control; | 45 | struct pyra_control control; |
47 | 46 | ||
48 | if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS || | 47 | if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS || |
@@ -54,47 +53,31 @@ static int pyra_send_control(struct usb_device *usb_dev, int value, | |||
54 | control.value = value; | 53 | control.value = value; |
55 | control.request = request; | 54 | control.request = request; |
56 | 55 | ||
57 | len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 56 | return roccat_common_send(usb_dev, PYRA_USB_COMMAND_CONTROL, |
58 | USB_REQ_SET_CONFIGURATION, | 57 | &control, sizeof(struct pyra_control)); |
59 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, | ||
60 | PYRA_USB_COMMAND_CONTROL, 0, (char *)&control, | ||
61 | sizeof(struct pyra_control), | ||
62 | USB_CTRL_SET_TIMEOUT); | ||
63 | |||
64 | if (len != sizeof(struct pyra_control)) | ||
65 | return len; | ||
66 | |||
67 | return 0; | ||
68 | } | 58 | } |
69 | 59 | ||
70 | static int pyra_receive_control_status(struct usb_device *usb_dev) | 60 | static int pyra_receive_control_status(struct usb_device *usb_dev) |
71 | { | 61 | { |
72 | int len; | 62 | int retval; |
73 | struct pyra_control control; | 63 | struct pyra_control control; |
74 | 64 | ||
75 | do { | 65 | do { |
76 | msleep(10); | 66 | msleep(10); |
77 | 67 | retval = roccat_common_receive(usb_dev, PYRA_USB_COMMAND_CONTROL, | |
78 | len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | 68 | &control, sizeof(struct pyra_control)); |
79 | USB_REQ_CLEAR_FEATURE, | ||
80 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | | ||
81 | USB_DIR_IN, | ||
82 | PYRA_USB_COMMAND_CONTROL, 0, (char *)&control, | ||
83 | sizeof(struct pyra_control), | ||
84 | USB_CTRL_SET_TIMEOUT); | ||
85 | 69 | ||
86 | /* requested too early, try again */ | 70 | /* requested too early, try again */ |
87 | } while (len == -EPROTO); | 71 | } while (retval == -EPROTO); |
88 | 72 | ||
89 | if (len == sizeof(struct pyra_control) && | 73 | if (!retval && control.command == PYRA_COMMAND_CONTROL && |
90 | control.command == PYRA_COMMAND_CONTROL && | ||
91 | control.request == PYRA_CONTROL_REQUEST_STATUS && | 74 | control.request == PYRA_CONTROL_REQUEST_STATUS && |
92 | control.value == 1) | 75 | control.value == 1) |
93 | return 0; | 76 | return 0; |
94 | else { | 77 | else { |
95 | hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n", | 78 | hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n", |
96 | control.request, control.value); | 79 | control.request, control.value); |
97 | return -EINVAL; | 80 | return retval ? retval : -EINVAL; |
98 | } | 81 | } |
99 | } | 82 | } |
100 | 83 | ||
@@ -102,125 +85,72 @@ static int pyra_get_profile_settings(struct usb_device *usb_dev, | |||
102 | struct pyra_profile_settings *buf, int number) | 85 | struct pyra_profile_settings *buf, int number) |
103 | { | 86 | { |
104 | int retval; | 87 | int retval; |
105 | |||
106 | retval = pyra_send_control(usb_dev, number, | 88 | retval = pyra_send_control(usb_dev, number, |
107 | PYRA_CONTROL_REQUEST_PROFILE_SETTINGS); | 89 | PYRA_CONTROL_REQUEST_PROFILE_SETTINGS); |
108 | |||
109 | if (retval) | 90 | if (retval) |
110 | return retval; | 91 | return retval; |
111 | 92 | return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_PROFILE_SETTINGS, | |
112 | retval = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | 93 | buf, sizeof(struct pyra_profile_settings)); |
113 | USB_REQ_CLEAR_FEATURE, | ||
114 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
115 | PYRA_USB_COMMAND_PROFILE_SETTINGS, 0, (char *)buf, | ||
116 | sizeof(struct pyra_profile_settings), | ||
117 | USB_CTRL_SET_TIMEOUT); | ||
118 | |||
119 | if (retval != sizeof(struct pyra_profile_settings)) | ||
120 | return retval; | ||
121 | |||
122 | return 0; | ||
123 | } | 94 | } |
124 | 95 | ||
125 | static int pyra_get_profile_buttons(struct usb_device *usb_dev, | 96 | static int pyra_get_profile_buttons(struct usb_device *usb_dev, |
126 | struct pyra_profile_buttons *buf, int number) | 97 | struct pyra_profile_buttons *buf, int number) |
127 | { | 98 | { |
128 | int retval; | 99 | int retval; |
129 | |||
130 | retval = pyra_send_control(usb_dev, number, | 100 | retval = pyra_send_control(usb_dev, number, |
131 | PYRA_CONTROL_REQUEST_PROFILE_BUTTONS); | 101 | PYRA_CONTROL_REQUEST_PROFILE_BUTTONS); |
132 | |||
133 | if (retval) | 102 | if (retval) |
134 | return retval; | 103 | return retval; |
135 | 104 | return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_PROFILE_BUTTONS, | |
136 | retval = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | 105 | buf, sizeof(struct pyra_profile_buttons)); |
137 | USB_REQ_CLEAR_FEATURE, | ||
138 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
139 | PYRA_USB_COMMAND_PROFILE_BUTTONS, 0, (char *)buf, | ||
140 | sizeof(struct pyra_profile_buttons), | ||
141 | USB_CTRL_SET_TIMEOUT); | ||
142 | |||
143 | if (retval != sizeof(struct pyra_profile_buttons)) | ||
144 | return retval; | ||
145 | |||
146 | return 0; | ||
147 | } | 106 | } |
148 | 107 | ||
149 | static int pyra_get_settings(struct usb_device *usb_dev, | 108 | static int pyra_get_settings(struct usb_device *usb_dev, |
150 | struct pyra_settings *buf) | 109 | struct pyra_settings *buf) |
151 | { | 110 | { |
152 | int len; | 111 | return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_SETTINGS, |
153 | len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | 112 | buf, sizeof(struct pyra_settings)); |
154 | USB_REQ_CLEAR_FEATURE, | ||
155 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
156 | PYRA_USB_COMMAND_SETTINGS, 0, buf, | ||
157 | sizeof(struct pyra_settings), USB_CTRL_SET_TIMEOUT); | ||
158 | if (len != sizeof(struct pyra_settings)) | ||
159 | return -EIO; | ||
160 | return 0; | ||
161 | } | 113 | } |
162 | 114 | ||
163 | static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf) | 115 | static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf) |
164 | { | 116 | { |
165 | int len; | 117 | return roccat_common_receive(usb_dev, PYRA_USB_COMMAND_INFO, |
166 | len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | 118 | buf, sizeof(struct pyra_info)); |
167 | USB_REQ_CLEAR_FEATURE, | 119 | } |
168 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | 120 | |
169 | PYRA_USB_COMMAND_INFO, 0, buf, | 121 | static int pyra_send(struct usb_device *usb_dev, uint command, |
170 | sizeof(struct pyra_info), USB_CTRL_SET_TIMEOUT); | 122 | void const *buf, uint size) |
171 | if (len != sizeof(struct pyra_info)) | 123 | { |
172 | return -EIO; | 124 | int retval; |
173 | return 0; | 125 | retval = roccat_common_send(usb_dev, command, buf, size); |
126 | if (retval) | ||
127 | return retval; | ||
128 | return pyra_receive_control_status(usb_dev); | ||
174 | } | 129 | } |
175 | 130 | ||
176 | static int pyra_set_profile_settings(struct usb_device *usb_dev, | 131 | static int pyra_set_profile_settings(struct usb_device *usb_dev, |
177 | struct pyra_profile_settings const *settings) | 132 | struct pyra_profile_settings const *settings) |
178 | { | 133 | { |
179 | int len; | 134 | return pyra_send(usb_dev, PYRA_USB_COMMAND_PROFILE_SETTINGS, settings, |
180 | len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 135 | sizeof(struct pyra_profile_settings)); |
181 | USB_REQ_SET_CONFIGURATION, | ||
182 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, | ||
183 | PYRA_USB_COMMAND_PROFILE_SETTINGS, 0, (char *)settings, | ||
184 | sizeof(struct pyra_profile_settings), | ||
185 | USB_CTRL_SET_TIMEOUT); | ||
186 | if (len != sizeof(struct pyra_profile_settings)) | ||
187 | return -EIO; | ||
188 | if (pyra_receive_control_status(usb_dev)) | ||
189 | return -EIO; | ||
190 | return 0; | ||
191 | } | 136 | } |
192 | 137 | ||
193 | static int pyra_set_profile_buttons(struct usb_device *usb_dev, | 138 | static int pyra_set_profile_buttons(struct usb_device *usb_dev, |
194 | struct pyra_profile_buttons const *buttons) | 139 | struct pyra_profile_buttons const *buttons) |
195 | { | 140 | { |
196 | int len; | 141 | return pyra_send(usb_dev, PYRA_USB_COMMAND_PROFILE_BUTTONS, buttons, |
197 | len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 142 | sizeof(struct pyra_profile_buttons)); |
198 | USB_REQ_SET_CONFIGURATION, | ||
199 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, | ||
200 | PYRA_USB_COMMAND_PROFILE_BUTTONS, 0, (char *)buttons, | ||
201 | sizeof(struct pyra_profile_buttons), | ||
202 | USB_CTRL_SET_TIMEOUT); | ||
203 | if (len != sizeof(struct pyra_profile_buttons)) | ||
204 | return -EIO; | ||
205 | if (pyra_receive_control_status(usb_dev)) | ||
206 | return -EIO; | ||
207 | return 0; | ||
208 | } | 143 | } |
209 | 144 | ||
210 | static int pyra_set_settings(struct usb_device *usb_dev, | 145 | static int pyra_set_settings(struct usb_device *usb_dev, |
211 | struct pyra_settings const *settings) | 146 | struct pyra_settings const *settings) |
212 | { | 147 | { |
213 | int len; | 148 | int retval; |
214 | len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | 149 | retval = roccat_common_send(usb_dev, PYRA_USB_COMMAND_SETTINGS, settings, |
215 | USB_REQ_SET_CONFIGURATION, | 150 | sizeof(struct pyra_settings)); |
216 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, | 151 | if (retval) |
217 | PYRA_USB_COMMAND_SETTINGS, 0, (char *)settings, | 152 | return retval; |
218 | sizeof(struct pyra_settings), USB_CTRL_SET_TIMEOUT); | 153 | return pyra_receive_control_status(usb_dev); |
219 | if (len != sizeof(struct pyra_settings)) | ||
220 | return -EIO; | ||
221 | if (pyra_receive_control_status(usb_dev)) | ||
222 | return -EIO; | ||
223 | return 0; | ||
224 | } | 154 | } |
225 | 155 | ||
226 | static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, | 156 | static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, |
@@ -521,21 +451,16 @@ static struct bin_attribute pyra_bin_attributes[] = { | |||
521 | static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, | 451 | static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, |
522 | struct pyra_device *pyra) | 452 | struct pyra_device *pyra) |
523 | { | 453 | { |
524 | struct pyra_info *info; | 454 | struct pyra_info info; |
525 | int retval, i; | 455 | int retval, i; |
526 | 456 | ||
527 | mutex_init(&pyra->pyra_lock); | 457 | mutex_init(&pyra->pyra_lock); |
528 | 458 | ||
529 | info = kmalloc(sizeof(struct pyra_info), GFP_KERNEL); | 459 | retval = pyra_get_info(usb_dev, &info); |
530 | if (!info) | 460 | if (retval) |
531 | return -ENOMEM; | ||
532 | retval = pyra_get_info(usb_dev, info); | ||
533 | if (retval) { | ||
534 | kfree(info); | ||
535 | return retval; | 461 | return retval; |
536 | } | 462 | |
537 | pyra->firmware_version = info->firmware_version; | 463 | pyra->firmware_version = info.firmware_version; |
538 | kfree(info); | ||
539 | 464 | ||
540 | retval = pyra_get_settings(usb_dev, &pyra->settings); | 465 | retval = pyra_get_settings(usb_dev, &pyra->settings); |
541 | if (retval) | 466 | if (retval) |