diff options
Diffstat (limited to 'drivers/hid/hid-roccat-koneplus.c')
-rw-r--r-- | drivers/hid/hid-roccat-koneplus.c | 175 |
1 files changed, 79 insertions, 96 deletions
diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c index 6a48fa3c7da9..db4d8b6a2542 100644 --- a/drivers/hid/hid-roccat-koneplus.c +++ b/drivers/hid/hid-roccat-koneplus.c | |||
@@ -156,7 +156,8 @@ KONEPLUS_SYSFS_W(thingy, THINGY) \ | |||
156 | KONEPLUS_SYSFS_R(thingy, THINGY) | 156 | KONEPLUS_SYSFS_R(thingy, THINGY) |
157 | 157 | ||
158 | #define KONEPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \ | 158 | #define KONEPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \ |
159 | { \ | 159 | KONEPLUS_SYSFS_RW(thingy, THINGY); \ |
160 | static struct bin_attribute bin_attr_##thingy = { \ | ||
160 | .attr = { .name = #thingy, .mode = 0660 }, \ | 161 | .attr = { .name = #thingy, .mode = 0660 }, \ |
161 | .size = KONEPLUS_SIZE_ ## THINGY, \ | 162 | .size = KONEPLUS_SIZE_ ## THINGY, \ |
162 | .read = koneplus_sysfs_read_ ## thingy, \ | 163 | .read = koneplus_sysfs_read_ ## thingy, \ |
@@ -164,28 +165,29 @@ KONEPLUS_SYSFS_R(thingy, THINGY) | |||
164 | } | 165 | } |
165 | 166 | ||
166 | #define KONEPLUS_BIN_ATTRIBUTE_R(thingy, THINGY) \ | 167 | #define KONEPLUS_BIN_ATTRIBUTE_R(thingy, THINGY) \ |
167 | { \ | 168 | KONEPLUS_SYSFS_R(thingy, THINGY); \ |
169 | static struct bin_attribute bin_attr_##thingy = { \ | ||
168 | .attr = { .name = #thingy, .mode = 0440 }, \ | 170 | .attr = { .name = #thingy, .mode = 0440 }, \ |
169 | .size = KONEPLUS_SIZE_ ## THINGY, \ | 171 | .size = KONEPLUS_SIZE_ ## THINGY, \ |
170 | .read = koneplus_sysfs_read_ ## thingy, \ | 172 | .read = koneplus_sysfs_read_ ## thingy, \ |
171 | } | 173 | } |
172 | 174 | ||
173 | #define KONEPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \ | 175 | #define KONEPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \ |
174 | { \ | 176 | KONEPLUS_SYSFS_W(thingy, THINGY); \ |
177 | static struct bin_attribute bin_attr_##thingy = { \ | ||
175 | .attr = { .name = #thingy, .mode = 0220 }, \ | 178 | .attr = { .name = #thingy, .mode = 0220 }, \ |
176 | .size = KONEPLUS_SIZE_ ## THINGY, \ | 179 | .size = KONEPLUS_SIZE_ ## THINGY, \ |
177 | .write = koneplus_sysfs_write_ ## thingy \ | 180 | .write = koneplus_sysfs_write_ ## thingy \ |
178 | } | 181 | } |
179 | 182 | KONEPLUS_BIN_ATTRIBUTE_W(control, CONTROL); | |
180 | KONEPLUS_SYSFS_W(control, CONTROL) | 183 | KONEPLUS_BIN_ATTRIBUTE_W(talk, TALK); |
181 | KONEPLUS_SYSFS_RW(info, INFO) | 184 | KONEPLUS_BIN_ATTRIBUTE_W(macro, MACRO); |
182 | KONEPLUS_SYSFS_W(talk, TALK) | 185 | KONEPLUS_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE); |
183 | KONEPLUS_SYSFS_W(macro, MACRO) | 186 | KONEPLUS_BIN_ATTRIBUTE_RW(info, INFO); |
184 | KONEPLUS_SYSFS_RW(sensor, SENSOR) | 187 | KONEPLUS_BIN_ATTRIBUTE_RW(sensor, SENSOR); |
185 | KONEPLUS_SYSFS_RW(tcu, TCU) | 188 | KONEPLUS_BIN_ATTRIBUTE_RW(tcu, TCU); |
186 | KONEPLUS_SYSFS_R(tcu_image, TCU_IMAGE) | 189 | KONEPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); |
187 | KONEPLUS_SYSFS_RW(profile_settings, PROFILE_SETTINGS) | 190 | KONEPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); |
188 | KONEPLUS_SYSFS_RW(profile_buttons, PROFILE_BUTTONS) | ||
189 | 191 | ||
190 | static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp, | 192 | static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp, |
191 | struct kobject *kobj, struct bin_attribute *attr, char *buf, | 193 | struct kobject *kobj, struct bin_attribute *attr, char *buf, |
@@ -225,6 +227,25 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp, | |||
225 | KONEPLUS_COMMAND_PROFILE_BUTTONS); | 227 | KONEPLUS_COMMAND_PROFILE_BUTTONS); |
226 | } | 228 | } |
227 | 229 | ||
230 | #define PROFILE_ATTR(number) \ | ||
231 | static struct bin_attribute bin_attr_profile##number##_settings = { \ | ||
232 | .attr = { .name = "profile##number##_settings", .mode = 0440 }, \ | ||
233 | .size = KONEPLUS_SIZE_PROFILE_SETTINGS, \ | ||
234 | .read = koneplus_sysfs_read_profilex_settings, \ | ||
235 | .private = &profile_numbers[number-1], \ | ||
236 | }; \ | ||
237 | static struct bin_attribute bin_attr_profile##number##_buttons = { \ | ||
238 | .attr = { .name = "profile##number##_buttons", .mode = 0440 }, \ | ||
239 | .size = KONEPLUS_SIZE_PROFILE_BUTTONS, \ | ||
240 | .read = koneplus_sysfs_read_profilex_buttons, \ | ||
241 | .private = &profile_numbers[number-1], \ | ||
242 | }; | ||
243 | PROFILE_ATTR(1); | ||
244 | PROFILE_ATTR(2); | ||
245 | PROFILE_ATTR(3); | ||
246 | PROFILE_ATTR(4); | ||
247 | PROFILE_ATTR(5); | ||
248 | |||
228 | static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev, | 249 | static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev, |
229 | struct device_attribute *attr, char *buf) | 250 | struct device_attribute *attr, char *buf) |
230 | { | 251 | { |
@@ -274,6 +295,12 @@ static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev, | |||
274 | 295 | ||
275 | return size; | 296 | return size; |
276 | } | 297 | } |
298 | static DEVICE_ATTR(actual_profile, 0660, | ||
299 | koneplus_sysfs_show_actual_profile, | ||
300 | koneplus_sysfs_set_actual_profile); | ||
301 | static DEVICE_ATTR(startup_profile, 0660, | ||
302 | koneplus_sysfs_show_actual_profile, | ||
303 | koneplus_sysfs_set_actual_profile); | ||
277 | 304 | ||
278 | static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, | 305 | static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, |
279 | struct device_attribute *attr, char *buf) | 306 | struct device_attribute *attr, char *buf) |
@@ -293,90 +320,47 @@ static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, | |||
293 | 320 | ||
294 | return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); | 321 | return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); |
295 | } | 322 | } |
323 | static DEVICE_ATTR(firmware_version, 0440, | ||
324 | koneplus_sysfs_show_firmware_version, NULL); | ||
325 | |||
326 | static struct attribute *koneplus_attrs[] = { | ||
327 | &dev_attr_actual_profile.attr, | ||
328 | &dev_attr_startup_profile.attr, | ||
329 | &dev_attr_firmware_version.attr, | ||
330 | NULL, | ||
331 | }; | ||
332 | |||
333 | static struct bin_attribute *koneplus_bin_attributes[] = { | ||
334 | &bin_attr_control, | ||
335 | &bin_attr_talk, | ||
336 | &bin_attr_macro, | ||
337 | &bin_attr_tcu_image, | ||
338 | &bin_attr_info, | ||
339 | &bin_attr_sensor, | ||
340 | &bin_attr_tcu, | ||
341 | &bin_attr_profile_settings, | ||
342 | &bin_attr_profile_buttons, | ||
343 | &bin_attr_profile1_settings, | ||
344 | &bin_attr_profile2_settings, | ||
345 | &bin_attr_profile3_settings, | ||
346 | &bin_attr_profile4_settings, | ||
347 | &bin_attr_profile5_settings, | ||
348 | &bin_attr_profile1_buttons, | ||
349 | &bin_attr_profile2_buttons, | ||
350 | &bin_attr_profile3_buttons, | ||
351 | &bin_attr_profile4_buttons, | ||
352 | &bin_attr_profile5_buttons, | ||
353 | NULL, | ||
354 | }; | ||
296 | 355 | ||
297 | static struct device_attribute koneplus_attributes[] = { | 356 | static const struct attribute_group koneplus_group = { |
298 | __ATTR(actual_profile, 0660, | 357 | .attrs = koneplus_attrs, |
299 | koneplus_sysfs_show_actual_profile, | 358 | .bin_attrs = koneplus_bin_attributes, |
300 | koneplus_sysfs_set_actual_profile), | ||
301 | __ATTR(startup_profile, 0660, | ||
302 | koneplus_sysfs_show_actual_profile, | ||
303 | koneplus_sysfs_set_actual_profile), | ||
304 | __ATTR(firmware_version, 0440, | ||
305 | koneplus_sysfs_show_firmware_version, NULL), | ||
306 | __ATTR_NULL | ||
307 | }; | 359 | }; |
308 | 360 | ||
309 | static struct bin_attribute koneplus_bin_attributes[] = { | 361 | static const struct attribute_group *koneplus_groups[] = { |
310 | KONEPLUS_BIN_ATTRIBUTE_W(control, CONTROL), | 362 | &koneplus_group, |
311 | KONEPLUS_BIN_ATTRIBUTE_RW(info, INFO), | 363 | NULL, |
312 | KONEPLUS_BIN_ATTRIBUTE_W(talk, TALK), | ||
313 | KONEPLUS_BIN_ATTRIBUTE_W(macro, MACRO), | ||
314 | KONEPLUS_BIN_ATTRIBUTE_RW(sensor, SENSOR), | ||
315 | KONEPLUS_BIN_ATTRIBUTE_RW(tcu, TCU), | ||
316 | KONEPLUS_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE), | ||
317 | KONEPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS), | ||
318 | KONEPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS), | ||
319 | { | ||
320 | .attr = { .name = "profile1_settings", .mode = 0440 }, | ||
321 | .size = KONEPLUS_SIZE_PROFILE_SETTINGS, | ||
322 | .read = koneplus_sysfs_read_profilex_settings, | ||
323 | .private = &profile_numbers[0] | ||
324 | }, | ||
325 | { | ||
326 | .attr = { .name = "profile2_settings", .mode = 0440 }, | ||
327 | .size = KONEPLUS_SIZE_PROFILE_SETTINGS, | ||
328 | .read = koneplus_sysfs_read_profilex_settings, | ||
329 | .private = &profile_numbers[1] | ||
330 | }, | ||
331 | { | ||
332 | .attr = { .name = "profile3_settings", .mode = 0440 }, | ||
333 | .size = KONEPLUS_SIZE_PROFILE_SETTINGS, | ||
334 | .read = koneplus_sysfs_read_profilex_settings, | ||
335 | .private = &profile_numbers[2] | ||
336 | }, | ||
337 | { | ||
338 | .attr = { .name = "profile4_settings", .mode = 0440 }, | ||
339 | .size = KONEPLUS_SIZE_PROFILE_SETTINGS, | ||
340 | .read = koneplus_sysfs_read_profilex_settings, | ||
341 | .private = &profile_numbers[3] | ||
342 | }, | ||
343 | { | ||
344 | .attr = { .name = "profile5_settings", .mode = 0440 }, | ||
345 | .size = KONEPLUS_SIZE_PROFILE_SETTINGS, | ||
346 | .read = koneplus_sysfs_read_profilex_settings, | ||
347 | .private = &profile_numbers[4] | ||
348 | }, | ||
349 | { | ||
350 | .attr = { .name = "profile1_buttons", .mode = 0440 }, | ||
351 | .size = KONEPLUS_SIZE_PROFILE_BUTTONS, | ||
352 | .read = koneplus_sysfs_read_profilex_buttons, | ||
353 | .private = &profile_numbers[0] | ||
354 | }, | ||
355 | { | ||
356 | .attr = { .name = "profile2_buttons", .mode = 0440 }, | ||
357 | .size = KONEPLUS_SIZE_PROFILE_BUTTONS, | ||
358 | .read = koneplus_sysfs_read_profilex_buttons, | ||
359 | .private = &profile_numbers[1] | ||
360 | }, | ||
361 | { | ||
362 | .attr = { .name = "profile3_buttons", .mode = 0440 }, | ||
363 | .size = KONEPLUS_SIZE_PROFILE_BUTTONS, | ||
364 | .read = koneplus_sysfs_read_profilex_buttons, | ||
365 | .private = &profile_numbers[2] | ||
366 | }, | ||
367 | { | ||
368 | .attr = { .name = "profile4_buttons", .mode = 0440 }, | ||
369 | .size = KONEPLUS_SIZE_PROFILE_BUTTONS, | ||
370 | .read = koneplus_sysfs_read_profilex_buttons, | ||
371 | .private = &profile_numbers[3] | ||
372 | }, | ||
373 | { | ||
374 | .attr = { .name = "profile5_buttons", .mode = 0440 }, | ||
375 | .size = KONEPLUS_SIZE_PROFILE_BUTTONS, | ||
376 | .read = koneplus_sysfs_read_profilex_buttons, | ||
377 | .private = &profile_numbers[4] | ||
378 | }, | ||
379 | __ATTR_NULL | ||
380 | }; | 364 | }; |
381 | 365 | ||
382 | static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev, | 366 | static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev, |
@@ -572,8 +556,7 @@ static int __init koneplus_init(void) | |||
572 | koneplus_class = class_create(THIS_MODULE, "koneplus"); | 556 | koneplus_class = class_create(THIS_MODULE, "koneplus"); |
573 | if (IS_ERR(koneplus_class)) | 557 | if (IS_ERR(koneplus_class)) |
574 | return PTR_ERR(koneplus_class); | 558 | return PTR_ERR(koneplus_class); |
575 | koneplus_class->dev_attrs = koneplus_attributes; | 559 | koneplus_class->dev_groups = koneplus_groups; |
576 | koneplus_class->dev_bin_attrs = koneplus_bin_attributes; | ||
577 | 560 | ||
578 | retval = hid_register_driver(&koneplus_driver); | 561 | retval = hid_register_driver(&koneplus_driver); |
579 | if (retval) | 562 | if (retval) |