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-pyra.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-pyra.c')
-rw-r--r-- | drivers/hid/hid-roccat-pyra.c | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index df05c1b1064f..440cb1bd70d4 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c | |||
@@ -42,43 +42,19 @@ 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 | struct pyra_control control; | 45 | struct roccat_common_control control; |
46 | 46 | ||
47 | if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS || | 47 | if ((request == PYRA_CONTROL_REQUEST_PROFILE_SETTINGS || |
48 | request == PYRA_CONTROL_REQUEST_PROFILE_BUTTONS) && | 48 | request == PYRA_CONTROL_REQUEST_PROFILE_BUTTONS) && |
49 | (value < 0 || value > 4)) | 49 | (value < 0 || value > 4)) |
50 | return -EINVAL; | 50 | return -EINVAL; |
51 | 51 | ||
52 | control.command = PYRA_COMMAND_CONTROL; | 52 | control.command = ROCCAT_COMMON_COMMAND_CONTROL; |
53 | control.value = value; | 53 | control.value = value; |
54 | control.request = request; | 54 | control.request = request; |
55 | 55 | ||
56 | return roccat_common_send(usb_dev, PYRA_COMMAND_CONTROL, | 56 | return roccat_common_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL, |
57 | &control, sizeof(struct pyra_control)); | 57 | &control, sizeof(struct roccat_common_control)); |
58 | } | ||
59 | |||
60 | static int pyra_receive_control_status(struct usb_device *usb_dev) | ||
61 | { | ||
62 | int retval; | ||
63 | struct pyra_control control; | ||
64 | |||
65 | do { | ||
66 | msleep(10); | ||
67 | retval = roccat_common_receive(usb_dev, PYRA_COMMAND_CONTROL, | ||
68 | &control, sizeof(struct pyra_control)); | ||
69 | |||
70 | /* requested too early, try again */ | ||
71 | } while (retval == -EPROTO); | ||
72 | |||
73 | if (!retval && control.command == PYRA_COMMAND_CONTROL && | ||
74 | control.request == PYRA_CONTROL_REQUEST_STATUS && | ||
75 | control.value == 1) | ||
76 | return 0; | ||
77 | else { | ||
78 | hid_err(usb_dev, "receive control status: unknown response 0x%x 0x%x\n", | ||
79 | control.request, control.value); | ||
80 | return retval ? retval : -EINVAL; | ||
81 | } | ||
82 | } | 58 | } |
83 | 59 | ||
84 | static int pyra_get_profile_settings(struct usb_device *usb_dev, | 60 | static int pyra_get_profile_settings(struct usb_device *usb_dev, |
@@ -118,34 +94,27 @@ static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf) | |||
118 | buf, sizeof(struct pyra_info)); | 94 | buf, sizeof(struct pyra_info)); |
119 | } | 95 | } |
120 | 96 | ||
121 | static int pyra_send(struct usb_device *usb_dev, uint command, | ||
122 | void const *buf, uint size) | ||
123 | { | ||
124 | int retval; | ||
125 | retval = roccat_common_send(usb_dev, command, buf, size); | ||
126 | if (retval) | ||
127 | return retval; | ||
128 | return pyra_receive_control_status(usb_dev); | ||
129 | } | ||
130 | |||
131 | static int pyra_set_profile_settings(struct usb_device *usb_dev, | 97 | static int pyra_set_profile_settings(struct usb_device *usb_dev, |
132 | struct pyra_profile_settings const *settings) | 98 | struct pyra_profile_settings const *settings) |
133 | { | 99 | { |
134 | return pyra_send(usb_dev, PYRA_COMMAND_PROFILE_SETTINGS, settings, | 100 | return roccat_common_send_with_status(usb_dev, |
101 | PYRA_COMMAND_PROFILE_SETTINGS, settings, | ||
135 | sizeof(struct pyra_profile_settings)); | 102 | sizeof(struct pyra_profile_settings)); |
136 | } | 103 | } |
137 | 104 | ||
138 | static int pyra_set_profile_buttons(struct usb_device *usb_dev, | 105 | static int pyra_set_profile_buttons(struct usb_device *usb_dev, |
139 | struct pyra_profile_buttons const *buttons) | 106 | struct pyra_profile_buttons const *buttons) |
140 | { | 107 | { |
141 | return pyra_send(usb_dev, PYRA_COMMAND_PROFILE_BUTTONS, buttons, | 108 | return roccat_common_send_with_status(usb_dev, |
109 | PYRA_COMMAND_PROFILE_BUTTONS, buttons, | ||
142 | sizeof(struct pyra_profile_buttons)); | 110 | sizeof(struct pyra_profile_buttons)); |
143 | } | 111 | } |
144 | 112 | ||
145 | static int pyra_set_settings(struct usb_device *usb_dev, | 113 | static int pyra_set_settings(struct usb_device *usb_dev, |
146 | struct pyra_settings const *settings) | 114 | struct pyra_settings const *settings) |
147 | { | 115 | { |
148 | return pyra_send(usb_dev, PYRA_COMMAND_SETTINGS, settings, | 116 | return roccat_common_send_with_status(usb_dev, |
117 | PYRA_COMMAND_SETTINGS, settings, | ||
149 | sizeof(struct pyra_settings)); | 118 | sizeof(struct pyra_settings)); |
150 | } | 119 | } |
151 | 120 | ||