diff options
author | Stefan Achatz <stefan_achatz@web.de> | 2012-11-11 00:20:58 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2012-11-12 09:30:27 -0500 |
commit | be34380ef818c182860c06f048cbea821203f9b7 (patch) | |
tree | cf9283ac8ebe6594103e7cf91dc80accdd0d45f1 /drivers/hid/hid-roccat-pyra.c | |
parent | 94a8fcf9a1a816199efc29546040172aa1383be0 (diff) |
HID: roccat: cleanup of pyra module
Partially removed unneeded informations and data caching.
Moved code nearer to format of newer drivers.
Added "info" sysfs attribute to support device reset and deprecate
"firmware_version" attribute.
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 | 340 |
1 files changed, 144 insertions, 196 deletions
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index 1317c177a3e2..76199fa727ed 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c | |||
@@ -66,48 +66,14 @@ static int pyra_get_profile_settings(struct usb_device *usb_dev, | |||
66 | if (retval) | 66 | if (retval) |
67 | return retval; | 67 | return retval; |
68 | return roccat_common2_receive(usb_dev, PYRA_COMMAND_PROFILE_SETTINGS, | 68 | return roccat_common2_receive(usb_dev, PYRA_COMMAND_PROFILE_SETTINGS, |
69 | buf, sizeof(struct pyra_profile_settings)); | 69 | buf, PYRA_SIZE_PROFILE_SETTINGS); |
70 | } | ||
71 | |||
72 | static int pyra_get_profile_buttons(struct usb_device *usb_dev, | ||
73 | struct pyra_profile_buttons *buf, int number) | ||
74 | { | ||
75 | int retval; | ||
76 | retval = pyra_send_control(usb_dev, number, | ||
77 | PYRA_CONTROL_REQUEST_PROFILE_BUTTONS); | ||
78 | if (retval) | ||
79 | return retval; | ||
80 | return roccat_common2_receive(usb_dev, PYRA_COMMAND_PROFILE_BUTTONS, | ||
81 | buf, sizeof(struct pyra_profile_buttons)); | ||
82 | } | 70 | } |
83 | 71 | ||
84 | static int pyra_get_settings(struct usb_device *usb_dev, | 72 | static int pyra_get_settings(struct usb_device *usb_dev, |
85 | struct pyra_settings *buf) | 73 | struct pyra_settings *buf) |
86 | { | 74 | { |
87 | return roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS, | 75 | return roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS, |
88 | buf, sizeof(struct pyra_settings)); | 76 | buf, PYRA_SIZE_SETTINGS); |
89 | } | ||
90 | |||
91 | static int pyra_get_info(struct usb_device *usb_dev, struct pyra_info *buf) | ||
92 | { | ||
93 | return roccat_common2_receive(usb_dev, PYRA_COMMAND_INFO, | ||
94 | buf, sizeof(struct pyra_info)); | ||
95 | } | ||
96 | |||
97 | static int pyra_set_profile_settings(struct usb_device *usb_dev, | ||
98 | struct pyra_profile_settings const *settings) | ||
99 | { | ||
100 | return roccat_common2_send_with_status(usb_dev, | ||
101 | PYRA_COMMAND_PROFILE_SETTINGS, settings, | ||
102 | sizeof(struct pyra_profile_settings)); | ||
103 | } | ||
104 | |||
105 | static int pyra_set_profile_buttons(struct usb_device *usb_dev, | ||
106 | struct pyra_profile_buttons const *buttons) | ||
107 | { | ||
108 | return roccat_common2_send_with_status(usb_dev, | ||
109 | PYRA_COMMAND_PROFILE_BUTTONS, buttons, | ||
110 | sizeof(struct pyra_profile_buttons)); | ||
111 | } | 77 | } |
112 | 78 | ||
113 | static int pyra_set_settings(struct usb_device *usb_dev, | 79 | static int pyra_set_settings(struct usb_device *usb_dev, |
@@ -115,146 +81,143 @@ static int pyra_set_settings(struct usb_device *usb_dev, | |||
115 | { | 81 | { |
116 | return roccat_common2_send_with_status(usb_dev, | 82 | return roccat_common2_send_with_status(usb_dev, |
117 | PYRA_COMMAND_SETTINGS, settings, | 83 | PYRA_COMMAND_SETTINGS, settings, |
118 | sizeof(struct pyra_settings)); | 84 | PYRA_SIZE_SETTINGS); |
119 | } | 85 | } |
120 | 86 | ||
121 | static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, | 87 | static ssize_t pyra_sysfs_read(struct file *fp, struct kobject *kobj, |
122 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 88 | char *buf, loff_t off, size_t count, |
123 | loff_t off, size_t count) | 89 | size_t real_size, uint command) |
124 | { | 90 | { |
125 | struct device *dev = | 91 | struct device *dev = |
126 | container_of(kobj, struct device, kobj)->parent->parent; | 92 | container_of(kobj, struct device, kobj)->parent->parent; |
127 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | 93 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
94 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | ||
95 | int retval; | ||
128 | 96 | ||
129 | if (off >= sizeof(struct pyra_profile_settings)) | 97 | if (off >= real_size) |
130 | return 0; | 98 | return 0; |
131 | 99 | ||
132 | if (off + count > sizeof(struct pyra_profile_settings)) | 100 | if (off != 0 || count != real_size) |
133 | count = sizeof(struct pyra_profile_settings) - off; | 101 | return -EINVAL; |
134 | 102 | ||
135 | mutex_lock(&pyra->pyra_lock); | 103 | mutex_lock(&pyra->pyra_lock); |
136 | memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off, | 104 | retval = roccat_common2_receive(usb_dev, command, buf, real_size); |
137 | count); | ||
138 | mutex_unlock(&pyra->pyra_lock); | 105 | mutex_unlock(&pyra->pyra_lock); |
139 | 106 | ||
140 | return count; | 107 | if (retval) |
108 | return retval; | ||
109 | |||
110 | return real_size; | ||
141 | } | 111 | } |
142 | 112 | ||
143 | static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, | 113 | static ssize_t pyra_sysfs_write(struct file *fp, struct kobject *kobj, |
144 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 114 | void const *buf, loff_t off, size_t count, |
145 | loff_t off, size_t count) | 115 | size_t real_size, uint command) |
146 | { | 116 | { |
147 | struct device *dev = | 117 | struct device *dev = |
148 | container_of(kobj, struct device, kobj)->parent->parent; | 118 | container_of(kobj, struct device, kobj)->parent->parent; |
149 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | 119 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
120 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | ||
121 | int retval; | ||
150 | 122 | ||
151 | if (off >= sizeof(struct pyra_profile_buttons)) | 123 | if (off != 0 || count != real_size) |
152 | return 0; | 124 | return -EINVAL; |
153 | |||
154 | if (off + count > sizeof(struct pyra_profile_buttons)) | ||
155 | count = sizeof(struct pyra_profile_buttons) - off; | ||
156 | 125 | ||
157 | mutex_lock(&pyra->pyra_lock); | 126 | mutex_lock(&pyra->pyra_lock); |
158 | memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off, | 127 | retval = roccat_common2_send_with_status(usb_dev, command, (void *)buf, real_size); |
159 | count); | ||
160 | mutex_unlock(&pyra->pyra_lock); | 128 | mutex_unlock(&pyra->pyra_lock); |
161 | 129 | ||
162 | return count; | 130 | if (retval) |
131 | return retval; | ||
132 | |||
133 | return real_size; | ||
163 | } | 134 | } |
164 | 135 | ||
165 | static ssize_t pyra_sysfs_write_profile_settings(struct file *fp, | 136 | #define PYRA_SYSFS_W(thingy, THINGY) \ |
166 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 137 | static ssize_t pyra_sysfs_write_ ## thingy(struct file *fp, \ |
167 | loff_t off, size_t count) | 138 | struct kobject *kobj, struct bin_attribute *attr, char *buf, \ |
168 | { | 139 | loff_t off, size_t count) \ |
169 | struct device *dev = | 140 | { \ |
170 | container_of(kobj, struct device, kobj)->parent->parent; | 141 | return pyra_sysfs_write(fp, kobj, buf, off, count, \ |
171 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | 142 | PYRA_SIZE_ ## THINGY, PYRA_COMMAND_ ## THINGY); \ |
172 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 143 | } |
173 | int retval = 0; | ||
174 | int difference; | ||
175 | int profile_number; | ||
176 | struct pyra_profile_settings *profile_settings; | ||
177 | 144 | ||
178 | if (off != 0 || count != sizeof(struct pyra_profile_settings)) | 145 | #define PYRA_SYSFS_R(thingy, THINGY) \ |
179 | return -EINVAL; | 146 | static ssize_t pyra_sysfs_read_ ## thingy(struct file *fp, \ |
147 | struct kobject *kobj, struct bin_attribute *attr, char *buf, \ | ||
148 | loff_t off, size_t count) \ | ||
149 | { \ | ||
150 | return pyra_sysfs_read(fp, kobj, buf, off, count, \ | ||
151 | PYRA_SIZE_ ## THINGY, PYRA_COMMAND_ ## THINGY); \ | ||
152 | } | ||
180 | 153 | ||
181 | profile_number = ((struct pyra_profile_settings const *)buf)->number; | 154 | #define PYRA_SYSFS_RW(thingy, THINGY) \ |
182 | profile_settings = &pyra->profile_settings[profile_number]; | 155 | PYRA_SYSFS_W(thingy, THINGY) \ |
156 | PYRA_SYSFS_R(thingy, THINGY) | ||
183 | 157 | ||
184 | mutex_lock(&pyra->pyra_lock); | 158 | #define PYRA_BIN_ATTRIBUTE_RW(thingy, THINGY) \ |
185 | difference = memcmp(buf, profile_settings, | 159 | { \ |
186 | sizeof(struct pyra_profile_settings)); | 160 | .attr = { .name = #thingy, .mode = 0660 }, \ |
187 | if (difference) { | 161 | .size = PYRA_SIZE_ ## THINGY, \ |
188 | retval = pyra_set_profile_settings(usb_dev, | 162 | .read = pyra_sysfs_read_ ## thingy, \ |
189 | (struct pyra_profile_settings const *)buf); | 163 | .write = pyra_sysfs_write_ ## thingy \ |
190 | if (!retval) | 164 | } |
191 | memcpy(profile_settings, buf, | ||
192 | sizeof(struct pyra_profile_settings)); | ||
193 | } | ||
194 | mutex_unlock(&pyra->pyra_lock); | ||
195 | 165 | ||
196 | if (retval) | 166 | #define PYRA_BIN_ATTRIBUTE_R(thingy, THINGY) \ |
197 | return retval; | 167 | { \ |
168 | .attr = { .name = #thingy, .mode = 0440 }, \ | ||
169 | .size = PYRA_SIZE_ ## THINGY, \ | ||
170 | .read = pyra_sysfs_read_ ## thingy, \ | ||
171 | } | ||
198 | 172 | ||
199 | return sizeof(struct pyra_profile_settings); | 173 | #define PYRA_BIN_ATTRIBUTE_W(thingy, THINGY) \ |
174 | { \ | ||
175 | .attr = { .name = #thingy, .mode = 0220 }, \ | ||
176 | .size = PYRA_SIZE_ ## THINGY, \ | ||
177 | .write = pyra_sysfs_write_ ## thingy \ | ||
200 | } | 178 | } |
201 | 179 | ||
202 | static ssize_t pyra_sysfs_write_profile_buttons(struct file *fp, | 180 | PYRA_SYSFS_RW(info, INFO) |
181 | PYRA_SYSFS_W(profile_settings, PROFILE_SETTINGS) | ||
182 | PYRA_SYSFS_W(profile_buttons, PROFILE_BUTTONS) | ||
183 | PYRA_SYSFS_R(settings, SETTINGS) | ||
184 | |||
185 | static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, | ||
203 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 186 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
204 | loff_t off, size_t count) | 187 | loff_t off, size_t count) |
205 | { | 188 | { |
206 | struct device *dev = | 189 | struct device *dev = |
207 | container_of(kobj, struct device, kobj)->parent->parent; | 190 | container_of(kobj, struct device, kobj)->parent->parent; |
208 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | ||
209 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 191 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
210 | int retval = 0; | 192 | ssize_t retval; |
211 | int difference; | ||
212 | int profile_number; | ||
213 | struct pyra_profile_buttons *profile_buttons; | ||
214 | |||
215 | if (off != 0 || count != sizeof(struct pyra_profile_buttons)) | ||
216 | return -EINVAL; | ||
217 | |||
218 | profile_number = ((struct pyra_profile_buttons const *)buf)->number; | ||
219 | profile_buttons = &pyra->profile_buttons[profile_number]; | ||
220 | |||
221 | mutex_lock(&pyra->pyra_lock); | ||
222 | difference = memcmp(buf, profile_buttons, | ||
223 | sizeof(struct pyra_profile_buttons)); | ||
224 | if (difference) { | ||
225 | retval = pyra_set_profile_buttons(usb_dev, | ||
226 | (struct pyra_profile_buttons const *)buf); | ||
227 | if (!retval) | ||
228 | memcpy(profile_buttons, buf, | ||
229 | sizeof(struct pyra_profile_buttons)); | ||
230 | } | ||
231 | mutex_unlock(&pyra->pyra_lock); | ||
232 | 193 | ||
194 | retval = pyra_send_control(usb_dev, *(uint *)(attr->private), | ||
195 | PYRA_CONTROL_REQUEST_PROFILE_SETTINGS); | ||
233 | if (retval) | 196 | if (retval) |
234 | return retval; | 197 | return retval; |
235 | 198 | ||
236 | return sizeof(struct pyra_profile_buttons); | 199 | return pyra_sysfs_read(fp, kobj, buf, off, count, |
200 | PYRA_SIZE_PROFILE_SETTINGS, | ||
201 | PYRA_COMMAND_PROFILE_SETTINGS); | ||
237 | } | 202 | } |
238 | 203 | ||
239 | static ssize_t pyra_sysfs_read_settings(struct file *fp, | 204 | static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, |
240 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 205 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
241 | loff_t off, size_t count) | 206 | loff_t off, size_t count) |
242 | { | 207 | { |
243 | struct device *dev = | 208 | struct device *dev = |
244 | container_of(kobj, struct device, kobj)->parent->parent; | 209 | container_of(kobj, struct device, kobj)->parent->parent; |
245 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | 210 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
246 | 211 | ssize_t retval; | |
247 | if (off >= sizeof(struct pyra_settings)) | ||
248 | return 0; | ||
249 | |||
250 | if (off + count > sizeof(struct pyra_settings)) | ||
251 | count = sizeof(struct pyra_settings) - off; | ||
252 | 212 | ||
253 | mutex_lock(&pyra->pyra_lock); | 213 | retval = pyra_send_control(usb_dev, *(uint *)(attr->private), |
254 | memcpy(buf, ((char const *)&pyra->settings) + off, count); | 214 | PYRA_CONTROL_REQUEST_PROFILE_BUTTONS); |
255 | mutex_unlock(&pyra->pyra_lock); | 215 | if (retval) |
216 | return retval; | ||
256 | 217 | ||
257 | return count; | 218 | return pyra_sysfs_read(fp, kobj, buf, off, count, |
219 | PYRA_SIZE_PROFILE_BUTTONS, | ||
220 | PYRA_COMMAND_PROFILE_BUTTONS); | ||
258 | } | 221 | } |
259 | 222 | ||
260 | static ssize_t pyra_sysfs_write_settings(struct file *fp, | 223 | static ssize_t pyra_sysfs_write_settings(struct file *fp, |
@@ -266,35 +229,32 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp, | |||
266 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); | 229 | struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
267 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); | 230 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
268 | int retval = 0; | 231 | int retval = 0; |
269 | int difference; | ||
270 | struct pyra_roccat_report roccat_report; | 232 | struct pyra_roccat_report roccat_report; |
233 | struct pyra_settings const *settings; | ||
271 | 234 | ||
272 | if (off != 0 || count != sizeof(struct pyra_settings)) | 235 | if (off != 0 || count != PYRA_SIZE_SETTINGS) |
273 | return -EINVAL; | 236 | return -EINVAL; |
274 | 237 | ||
275 | mutex_lock(&pyra->pyra_lock); | 238 | mutex_lock(&pyra->pyra_lock); |
276 | difference = memcmp(buf, &pyra->settings, sizeof(struct pyra_settings)); | ||
277 | if (difference) { | ||
278 | retval = pyra_set_settings(usb_dev, | ||
279 | (struct pyra_settings const *)buf); | ||
280 | if (retval) { | ||
281 | mutex_unlock(&pyra->pyra_lock); | ||
282 | return retval; | ||
283 | } | ||
284 | |||
285 | memcpy(&pyra->settings, buf, | ||
286 | sizeof(struct pyra_settings)); | ||
287 | 239 | ||
288 | profile_activated(pyra, pyra->settings.startup_profile); | 240 | settings = (struct pyra_settings const *)buf; |
289 | 241 | ||
290 | roccat_report.type = PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2; | 242 | retval = pyra_set_settings(usb_dev, settings); |
291 | roccat_report.value = pyra->settings.startup_profile + 1; | 243 | if (retval) { |
292 | roccat_report.key = 0; | 244 | mutex_unlock(&pyra->pyra_lock); |
293 | roccat_report_event(pyra->chrdev_minor, | 245 | return retval; |
294 | (uint8_t const *)&roccat_report); | ||
295 | } | 246 | } |
247 | |||
248 | profile_activated(pyra, settings->startup_profile); | ||
249 | |||
250 | roccat_report.type = PYRA_MOUSE_EVENT_BUTTON_TYPE_PROFILE_2; | ||
251 | roccat_report.value = settings->startup_profile + 1; | ||
252 | roccat_report.key = 0; | ||
253 | roccat_report_event(pyra->chrdev_minor, | ||
254 | (uint8_t const *)&roccat_report); | ||
255 | |||
296 | mutex_unlock(&pyra->pyra_lock); | 256 | mutex_unlock(&pyra->pyra_lock); |
297 | return sizeof(struct pyra_settings); | 257 | return PYRA_SIZE_SETTINGS; |
298 | } | 258 | } |
299 | 259 | ||
300 | 260 | ||
@@ -311,23 +271,34 @@ static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, | |||
311 | { | 271 | { |
312 | struct pyra_device *pyra = | 272 | struct pyra_device *pyra = |
313 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | 273 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); |
314 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_profile); | 274 | struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
275 | struct pyra_settings settings; | ||
276 | |||
277 | mutex_lock(&pyra->pyra_lock); | ||
278 | roccat_common2_receive(usb_dev, PYRA_COMMAND_SETTINGS, | ||
279 | &settings, PYRA_SIZE_SETTINGS); | ||
280 | mutex_unlock(&pyra->pyra_lock); | ||
281 | |||
282 | return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile); | ||
315 | } | 283 | } |
316 | 284 | ||
317 | static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, | 285 | static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, |
318 | struct device_attribute *attr, char *buf) | 286 | struct device_attribute *attr, char *buf) |
319 | { | 287 | { |
320 | struct pyra_device *pyra = | 288 | struct pyra_device *pyra; |
321 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | 289 | struct usb_device *usb_dev; |
322 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->firmware_version); | 290 | struct pyra_info info; |
323 | } | ||
324 | 291 | ||
325 | static ssize_t pyra_sysfs_show_startup_profile(struct device *dev, | 292 | dev = dev->parent->parent; |
326 | struct device_attribute *attr, char *buf) | 293 | pyra = hid_get_drvdata(dev_get_drvdata(dev)); |
327 | { | 294 | usb_dev = interface_to_usbdev(to_usb_interface(dev)); |
328 | struct pyra_device *pyra = | 295 | |
329 | hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); | 296 | mutex_lock(&pyra->pyra_lock); |
330 | return snprintf(buf, PAGE_SIZE, "%d\n", pyra->settings.startup_profile); | 297 | roccat_common2_receive(usb_dev, PYRA_COMMAND_INFO, |
298 | &info, PYRA_SIZE_INFO); | ||
299 | mutex_unlock(&pyra->pyra_lock); | ||
300 | |||
301 | return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); | ||
331 | } | 302 | } |
332 | 303 | ||
333 | static struct device_attribute pyra_attributes[] = { | 304 | static struct device_attribute pyra_attributes[] = { |
@@ -336,105 +307,87 @@ static struct device_attribute pyra_attributes[] = { | |||
336 | __ATTR(firmware_version, 0440, | 307 | __ATTR(firmware_version, 0440, |
337 | pyra_sysfs_show_firmware_version, NULL), | 308 | pyra_sysfs_show_firmware_version, NULL), |
338 | __ATTR(startup_profile, 0440, | 309 | __ATTR(startup_profile, 0440, |
339 | pyra_sysfs_show_startup_profile, NULL), | 310 | pyra_sysfs_show_actual_profile, NULL), |
340 | __ATTR_NULL | 311 | __ATTR_NULL |
341 | }; | 312 | }; |
342 | 313 | ||
343 | static struct bin_attribute pyra_bin_attributes[] = { | 314 | static struct bin_attribute pyra_bin_attributes[] = { |
344 | { | 315 | PYRA_BIN_ATTRIBUTE_RW(info, INFO), |
345 | .attr = { .name = "profile_settings", .mode = 0220 }, | 316 | PYRA_BIN_ATTRIBUTE_W(profile_settings, PROFILE_SETTINGS), |
346 | .size = sizeof(struct pyra_profile_settings), | 317 | PYRA_BIN_ATTRIBUTE_W(profile_buttons, PROFILE_BUTTONS), |
347 | .write = pyra_sysfs_write_profile_settings | 318 | PYRA_BIN_ATTRIBUTE_RW(settings, SETTINGS), |
348 | }, | ||
349 | { | 319 | { |
350 | .attr = { .name = "profile1_settings", .mode = 0440 }, | 320 | .attr = { .name = "profile1_settings", .mode = 0440 }, |
351 | .size = sizeof(struct pyra_profile_settings), | 321 | .size = PYRA_SIZE_PROFILE_SETTINGS, |
352 | .read = pyra_sysfs_read_profilex_settings, | 322 | .read = pyra_sysfs_read_profilex_settings, |
353 | .private = &profile_numbers[0] | 323 | .private = &profile_numbers[0] |
354 | }, | 324 | }, |
355 | { | 325 | { |
356 | .attr = { .name = "profile2_settings", .mode = 0440 }, | 326 | .attr = { .name = "profile2_settings", .mode = 0440 }, |
357 | .size = sizeof(struct pyra_profile_settings), | 327 | .size = PYRA_SIZE_PROFILE_SETTINGS, |
358 | .read = pyra_sysfs_read_profilex_settings, | 328 | .read = pyra_sysfs_read_profilex_settings, |
359 | .private = &profile_numbers[1] | 329 | .private = &profile_numbers[1] |
360 | }, | 330 | }, |
361 | { | 331 | { |
362 | .attr = { .name = "profile3_settings", .mode = 0440 }, | 332 | .attr = { .name = "profile3_settings", .mode = 0440 }, |
363 | .size = sizeof(struct pyra_profile_settings), | 333 | .size = PYRA_SIZE_PROFILE_SETTINGS, |
364 | .read = pyra_sysfs_read_profilex_settings, | 334 | .read = pyra_sysfs_read_profilex_settings, |
365 | .private = &profile_numbers[2] | 335 | .private = &profile_numbers[2] |
366 | }, | 336 | }, |
367 | { | 337 | { |
368 | .attr = { .name = "profile4_settings", .mode = 0440 }, | 338 | .attr = { .name = "profile4_settings", .mode = 0440 }, |
369 | .size = sizeof(struct pyra_profile_settings), | 339 | .size = PYRA_SIZE_PROFILE_SETTINGS, |
370 | .read = pyra_sysfs_read_profilex_settings, | 340 | .read = pyra_sysfs_read_profilex_settings, |
371 | .private = &profile_numbers[3] | 341 | .private = &profile_numbers[3] |
372 | }, | 342 | }, |
373 | { | 343 | { |
374 | .attr = { .name = "profile5_settings", .mode = 0440 }, | 344 | .attr = { .name = "profile5_settings", .mode = 0440 }, |
375 | .size = sizeof(struct pyra_profile_settings), | 345 | .size = PYRA_SIZE_PROFILE_SETTINGS, |
376 | .read = pyra_sysfs_read_profilex_settings, | 346 | .read = pyra_sysfs_read_profilex_settings, |
377 | .private = &profile_numbers[4] | 347 | .private = &profile_numbers[4] |
378 | }, | 348 | }, |
379 | { | 349 | { |
380 | .attr = { .name = "profile_buttons", .mode = 0220 }, | ||
381 | .size = sizeof(struct pyra_profile_buttons), | ||
382 | .write = pyra_sysfs_write_profile_buttons | ||
383 | }, | ||
384 | { | ||
385 | .attr = { .name = "profile1_buttons", .mode = 0440 }, | 350 | .attr = { .name = "profile1_buttons", .mode = 0440 }, |
386 | .size = sizeof(struct pyra_profile_buttons), | 351 | .size = PYRA_SIZE_PROFILE_BUTTONS, |
387 | .read = pyra_sysfs_read_profilex_buttons, | 352 | .read = pyra_sysfs_read_profilex_buttons, |
388 | .private = &profile_numbers[0] | 353 | .private = &profile_numbers[0] |
389 | }, | 354 | }, |
390 | { | 355 | { |
391 | .attr = { .name = "profile2_buttons", .mode = 0440 }, | 356 | .attr = { .name = "profile2_buttons", .mode = 0440 }, |
392 | .size = sizeof(struct pyra_profile_buttons), | 357 | .size = PYRA_SIZE_PROFILE_BUTTONS, |
393 | .read = pyra_sysfs_read_profilex_buttons, | 358 | .read = pyra_sysfs_read_profilex_buttons, |
394 | .private = &profile_numbers[1] | 359 | .private = &profile_numbers[1] |
395 | }, | 360 | }, |
396 | { | 361 | { |
397 | .attr = { .name = "profile3_buttons", .mode = 0440 }, | 362 | .attr = { .name = "profile3_buttons", .mode = 0440 }, |
398 | .size = sizeof(struct pyra_profile_buttons), | 363 | .size = PYRA_SIZE_PROFILE_BUTTONS, |
399 | .read = pyra_sysfs_read_profilex_buttons, | 364 | .read = pyra_sysfs_read_profilex_buttons, |
400 | .private = &profile_numbers[2] | 365 | .private = &profile_numbers[2] |
401 | }, | 366 | }, |
402 | { | 367 | { |
403 | .attr = { .name = "profile4_buttons", .mode = 0440 }, | 368 | .attr = { .name = "profile4_buttons", .mode = 0440 }, |
404 | .size = sizeof(struct pyra_profile_buttons), | 369 | .size = PYRA_SIZE_PROFILE_BUTTONS, |
405 | .read = pyra_sysfs_read_profilex_buttons, | 370 | .read = pyra_sysfs_read_profilex_buttons, |
406 | .private = &profile_numbers[3] | 371 | .private = &profile_numbers[3] |
407 | }, | 372 | }, |
408 | { | 373 | { |
409 | .attr = { .name = "profile5_buttons", .mode = 0440 }, | 374 | .attr = { .name = "profile5_buttons", .mode = 0440 }, |
410 | .size = sizeof(struct pyra_profile_buttons), | 375 | .size = PYRA_SIZE_PROFILE_BUTTONS, |
411 | .read = pyra_sysfs_read_profilex_buttons, | 376 | .read = pyra_sysfs_read_profilex_buttons, |
412 | .private = &profile_numbers[4] | 377 | .private = &profile_numbers[4] |
413 | }, | 378 | }, |
414 | { | ||
415 | .attr = { .name = "settings", .mode = 0660 }, | ||
416 | .size = sizeof(struct pyra_settings), | ||
417 | .read = pyra_sysfs_read_settings, | ||
418 | .write = pyra_sysfs_write_settings | ||
419 | }, | ||
420 | __ATTR_NULL | 379 | __ATTR_NULL |
421 | }; | 380 | }; |
422 | 381 | ||
423 | static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, | 382 | static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, |
424 | struct pyra_device *pyra) | 383 | struct pyra_device *pyra) |
425 | { | 384 | { |
426 | struct pyra_info info; | 385 | struct pyra_settings settings; |
427 | int retval, i; | 386 | int retval, i; |
428 | 387 | ||
429 | mutex_init(&pyra->pyra_lock); | 388 | mutex_init(&pyra->pyra_lock); |
430 | 389 | ||
431 | retval = pyra_get_info(usb_dev, &info); | 390 | retval = pyra_get_settings(usb_dev, &settings); |
432 | if (retval) | ||
433 | return retval; | ||
434 | |||
435 | pyra->firmware_version = info.firmware_version; | ||
436 | |||
437 | retval = pyra_get_settings(usb_dev, &pyra->settings); | ||
438 | if (retval) | 391 | if (retval) |
439 | return retval; | 392 | return retval; |
440 | 393 | ||
@@ -443,14 +396,9 @@ static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, | |||
443 | &pyra->profile_settings[i], i); | 396 | &pyra->profile_settings[i], i); |
444 | if (retval) | 397 | if (retval) |
445 | return retval; | 398 | return retval; |
446 | |||
447 | retval = pyra_get_profile_buttons(usb_dev, | ||
448 | &pyra->profile_buttons[i], i); | ||
449 | if (retval) | ||
450 | return retval; | ||
451 | } | 399 | } |
452 | 400 | ||
453 | profile_activated(pyra, pyra->settings.startup_profile); | 401 | profile_activated(pyra, settings.startup_profile); |
454 | 402 | ||
455 | return 0; | 403 | return 0; |
456 | } | 404 | } |