aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-roccat-pyra.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/hid-roccat-pyra.c')
-rw-r--r--drivers/hid/hid-roccat-pyra.c158
1 files changed, 73 insertions, 85 deletions
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index d4f1e3bee590..5a6dbbeee790 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -156,7 +156,8 @@ PYRA_SYSFS_W(thingy, THINGY) \
156PYRA_SYSFS_R(thingy, THINGY) 156PYRA_SYSFS_R(thingy, THINGY)
157 157
158#define PYRA_BIN_ATTRIBUTE_RW(thingy, THINGY) \ 158#define PYRA_BIN_ATTRIBUTE_RW(thingy, THINGY) \
159{ \ 159PYRA_SYSFS_RW(thingy, THINGY); \
160static struct bin_attribute bin_attr_##thingy = { \
160 .attr = { .name = #thingy, .mode = 0660 }, \ 161 .attr = { .name = #thingy, .mode = 0660 }, \
161 .size = PYRA_SIZE_ ## THINGY, \ 162 .size = PYRA_SIZE_ ## THINGY, \
162 .read = pyra_sysfs_read_ ## thingy, \ 163 .read = pyra_sysfs_read_ ## thingy, \
@@ -164,24 +165,25 @@ PYRA_SYSFS_R(thingy, THINGY)
164} 165}
165 166
166#define PYRA_BIN_ATTRIBUTE_R(thingy, THINGY) \ 167#define PYRA_BIN_ATTRIBUTE_R(thingy, THINGY) \
167{ \ 168PYRA_SYSFS_R(thingy, THINGY); \
169static struct bin_attribute bin_attr_##thingy = { \
168 .attr = { .name = #thingy, .mode = 0440 }, \ 170 .attr = { .name = #thingy, .mode = 0440 }, \
169 .size = PYRA_SIZE_ ## THINGY, \ 171 .size = PYRA_SIZE_ ## THINGY, \
170 .read = pyra_sysfs_read_ ## thingy, \ 172 .read = pyra_sysfs_read_ ## thingy, \
171} 173}
172 174
173#define PYRA_BIN_ATTRIBUTE_W(thingy, THINGY) \ 175#define PYRA_BIN_ATTRIBUTE_W(thingy, THINGY) \
174{ \ 176PYRA_SYSFS_W(thingy, THINGY); \
177static struct bin_attribute bin_attr_##thingy = { \
175 .attr = { .name = #thingy, .mode = 0220 }, \ 178 .attr = { .name = #thingy, .mode = 0220 }, \
176 .size = PYRA_SIZE_ ## THINGY, \ 179 .size = PYRA_SIZE_ ## THINGY, \
177 .write = pyra_sysfs_write_ ## thingy \ 180 .write = pyra_sysfs_write_ ## thingy \
178} 181}
179 182
180PYRA_SYSFS_W(control, CONTROL) 183PYRA_BIN_ATTRIBUTE_W(control, CONTROL);
181PYRA_SYSFS_RW(info, INFO) 184PYRA_BIN_ATTRIBUTE_RW(info, INFO);
182PYRA_SYSFS_RW(profile_settings, PROFILE_SETTINGS) 185PYRA_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
183PYRA_SYSFS_RW(profile_buttons, PROFILE_BUTTONS) 186PYRA_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
184PYRA_SYSFS_R(settings, SETTINGS)
185 187
186static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, 188static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
187 struct kobject *kobj, struct bin_attribute *attr, char *buf, 189 struct kobject *kobj, struct bin_attribute *attr, char *buf,
@@ -221,6 +223,25 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
221 PYRA_COMMAND_PROFILE_BUTTONS); 223 PYRA_COMMAND_PROFILE_BUTTONS);
222} 224}
223 225
226#define PROFILE_ATTR(number) \
227static struct bin_attribute bin_attr_profile##number##_settings = { \
228 .attr = { .name = "profile##number##_settings", .mode = 0440 }, \
229 .size = PYRA_SIZE_PROFILE_SETTINGS, \
230 .read = pyra_sysfs_read_profilex_settings, \
231 .private = &profile_numbers[number-1], \
232}; \
233static struct bin_attribute bin_attr_profile##number##_buttons = { \
234 .attr = { .name = "profile##number##_buttons", .mode = 0440 }, \
235 .size = PYRA_SIZE_PROFILE_BUTTONS, \
236 .read = pyra_sysfs_read_profilex_buttons, \
237 .private = &profile_numbers[number-1], \
238};
239PROFILE_ATTR(1);
240PROFILE_ATTR(2);
241PROFILE_ATTR(3);
242PROFILE_ATTR(4);
243PROFILE_ATTR(5);
244
224static ssize_t pyra_sysfs_write_settings(struct file *fp, 245static ssize_t pyra_sysfs_write_settings(struct file *fp,
225 struct kobject *kobj, struct bin_attribute *attr, char *buf, 246 struct kobject *kobj, struct bin_attribute *attr, char *buf,
226 loff_t off, size_t count) 247 loff_t off, size_t count)
@@ -258,6 +279,11 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
258 return PYRA_SIZE_SETTINGS; 279 return PYRA_SIZE_SETTINGS;
259} 280}
260 281
282PYRA_SYSFS_R(settings, SETTINGS);
283static struct bin_attribute bin_attr_settings =
284 __BIN_ATTR(settings, (S_IWUSR | S_IRUGO),
285 pyra_sysfs_read_settings, pyra_sysfs_write_settings,
286 PYRA_SIZE_SETTINGS);
261 287
262static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev, 288static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
263 struct device_attribute *attr, char *buf) 289 struct device_attribute *attr, char *buf)
@@ -266,6 +292,7 @@ static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
266 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 292 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
267 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); 293 return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
268} 294}
295static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL);
269 296
270static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, 297static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
271 struct device_attribute *attr, char *buf) 298 struct device_attribute *attr, char *buf)
@@ -282,6 +309,8 @@ static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
282 309
283 return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile); 310 return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile);
284} 311}
312static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL);
313static DEVICE_ATTR(startup_profile, 0440, pyra_sysfs_show_actual_profile, NULL);
285 314
286static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, 315static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
287 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
@@ -301,84 +330,44 @@ static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
301 330
302 return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); 331 return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
303} 332}
333static DEVICE_ATTR(firmware_version, 0440, pyra_sysfs_show_firmware_version,
334 NULL);
335
336static struct attribute *pyra_attrs[] = {
337 &dev_attr_actual_cpi.attr,
338 &dev_attr_actual_profile.attr,
339 &dev_attr_firmware_version.attr,
340 &dev_attr_startup_profile.attr,
341 NULL,
342};
343
344static struct bin_attribute *pyra_bin_attributes[] = {
345 &bin_attr_control,
346 &bin_attr_info,
347 &bin_attr_profile_settings,
348 &bin_attr_profile_buttons,
349 &bin_attr_settings,
350 &bin_attr_profile1_settings,
351 &bin_attr_profile2_settings,
352 &bin_attr_profile3_settings,
353 &bin_attr_profile4_settings,
354 &bin_attr_profile5_settings,
355 &bin_attr_profile1_buttons,
356 &bin_attr_profile2_buttons,
357 &bin_attr_profile3_buttons,
358 &bin_attr_profile4_buttons,
359 &bin_attr_profile5_buttons,
360 NULL,
361};
304 362
305static struct device_attribute pyra_attributes[] = { 363static const struct attribute_group pyra_group = {
306 __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL), 364 .attrs = pyra_attrs,
307 __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL), 365 .bin_attrs = pyra_bin_attributes,
308 __ATTR(firmware_version, 0440,
309 pyra_sysfs_show_firmware_version, NULL),
310 __ATTR(startup_profile, 0440,
311 pyra_sysfs_show_actual_profile, NULL),
312 __ATTR_NULL
313}; 366};
314 367
315static struct bin_attribute pyra_bin_attributes[] = { 368static const struct attribute_group *pyra_groups[] = {
316 PYRA_BIN_ATTRIBUTE_W(control, CONTROL), 369 &pyra_group,
317 PYRA_BIN_ATTRIBUTE_RW(info, INFO), 370 NULL,
318 PYRA_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS),
319 PYRA_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS),
320 PYRA_BIN_ATTRIBUTE_RW(settings, SETTINGS),
321 {
322 .attr = { .name = "profile1_settings", .mode = 0440 },
323 .size = PYRA_SIZE_PROFILE_SETTINGS,
324 .read = pyra_sysfs_read_profilex_settings,
325 .private = &profile_numbers[0]
326 },
327 {
328 .attr = { .name = "profile2_settings", .mode = 0440 },
329 .size = PYRA_SIZE_PROFILE_SETTINGS,
330 .read = pyra_sysfs_read_profilex_settings,
331 .private = &profile_numbers[1]
332 },
333 {
334 .attr = { .name = "profile3_settings", .mode = 0440 },
335 .size = PYRA_SIZE_PROFILE_SETTINGS,
336 .read = pyra_sysfs_read_profilex_settings,
337 .private = &profile_numbers[2]
338 },
339 {
340 .attr = { .name = "profile4_settings", .mode = 0440 },
341 .size = PYRA_SIZE_PROFILE_SETTINGS,
342 .read = pyra_sysfs_read_profilex_settings,
343 .private = &profile_numbers[3]
344 },
345 {
346 .attr = { .name = "profile5_settings", .mode = 0440 },
347 .size = PYRA_SIZE_PROFILE_SETTINGS,
348 .read = pyra_sysfs_read_profilex_settings,
349 .private = &profile_numbers[4]
350 },
351 {
352 .attr = { .name = "profile1_buttons", .mode = 0440 },
353 .size = PYRA_SIZE_PROFILE_BUTTONS,
354 .read = pyra_sysfs_read_profilex_buttons,
355 .private = &profile_numbers[0]
356 },
357 {
358 .attr = { .name = "profile2_buttons", .mode = 0440 },
359 .size = PYRA_SIZE_PROFILE_BUTTONS,
360 .read = pyra_sysfs_read_profilex_buttons,
361 .private = &profile_numbers[1]
362 },
363 {
364 .attr = { .name = "profile3_buttons", .mode = 0440 },
365 .size = PYRA_SIZE_PROFILE_BUTTONS,
366 .read = pyra_sysfs_read_profilex_buttons,
367 .private = &profile_numbers[2]
368 },
369 {
370 .attr = { .name = "profile4_buttons", .mode = 0440 },
371 .size = PYRA_SIZE_PROFILE_BUTTONS,
372 .read = pyra_sysfs_read_profilex_buttons,
373 .private = &profile_numbers[3]
374 },
375 {
376 .attr = { .name = "profile5_buttons", .mode = 0440 },
377 .size = PYRA_SIZE_PROFILE_BUTTONS,
378 .read = pyra_sysfs_read_profilex_buttons,
379 .private = &profile_numbers[4]
380 },
381 __ATTR_NULL
382}; 371};
383 372
384static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, 373static int pyra_init_pyra_device_struct(struct usb_device *usb_dev,
@@ -600,8 +589,7 @@ static int __init pyra_init(void)
600 pyra_class = class_create(THIS_MODULE, "pyra"); 589 pyra_class = class_create(THIS_MODULE, "pyra");
601 if (IS_ERR(pyra_class)) 590 if (IS_ERR(pyra_class))
602 return PTR_ERR(pyra_class); 591 return PTR_ERR(pyra_class);
603 pyra_class->dev_attrs = pyra_attributes; 592 pyra_class->dev_groups = pyra_groups;
604 pyra_class->dev_bin_attrs = pyra_bin_attributes;
605 593
606 retval = hid_register_driver(&pyra_driver); 594 retval = hid_register_driver(&pyra_driver);
607 if (retval) 595 if (retval)