aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorJanne Kanniainen <janne.kanniainen@gmail.com>2014-07-03 13:17:09 -0400
committerBryan Wu <cooloney@gmail.com>2014-07-03 14:14:11 -0400
commit6522fe1c39a79d4753e37d912876315720119f82 (patch)
tree3e69fb69925e67b9c6629eee0a4880ff0ab3122f /drivers/hid
parentc3883ae918c8754f7c251564d63211e1d5648b08 (diff)
HID: gt683r: move mode attribute to led-class devices
Move led_mode attribute from HID device to led-class devices and rename it mode. This will also fix race condition by using attribute-groups. (cooloney@gmai.com: fix a typo in commit message) Signed-off-by: Janne Kanniainen <janne.kanniainen@gmail.com> Reviewed-by: Johan Hovold <johan@kernel.org> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-gt683r.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/drivers/hid/hid-gt683r.c b/drivers/hid/hid-gt683r.c
index 073bd80ec839..0d6f135e266c 100644
--- a/drivers/hid/hid-gt683r.c
+++ b/drivers/hid/hid-gt683r.c
@@ -84,12 +84,13 @@ static void gt683r_brightness_set(struct led_classdev *led_cdev,
84 } 84 }
85} 85}
86 86
87static ssize_t leds_mode_show(struct device *dev, 87static ssize_t mode_show(struct device *dev,
88 struct device_attribute *attr, 88 struct device_attribute *attr,
89 char *buf) 89 char *buf)
90{ 90{
91 u8 sysfs_mode; 91 u8 sysfs_mode;
92 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 92 struct hid_device *hdev = container_of(dev->parent,
93 struct hid_device, dev);
93 struct gt683r_led *led = hid_get_drvdata(hdev); 94 struct gt683r_led *led = hid_get_drvdata(hdev);
94 95
95 if (led->mode == GT683R_LED_NORMAL) 96 if (led->mode == GT683R_LED_NORMAL)
@@ -102,12 +103,13 @@ static ssize_t leds_mode_show(struct device *dev,
102 return scnprintf(buf, PAGE_SIZE, "%u\n", sysfs_mode); 103 return scnprintf(buf, PAGE_SIZE, "%u\n", sysfs_mode);
103} 104}
104 105
105static ssize_t leds_mode_store(struct device *dev, 106static ssize_t mode_store(struct device *dev,
106 struct device_attribute *attr, 107 struct device_attribute *attr,
107 const char *buf, size_t count) 108 const char *buf, size_t count)
108{ 109{
109 u8 sysfs_mode; 110 u8 sysfs_mode;
110 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 111 struct hid_device *hdev = container_of(dev->parent,
112 struct hid_device, dev);
111 struct gt683r_led *led = hid_get_drvdata(hdev); 113 struct gt683r_led *led = hid_get_drvdata(hdev);
112 114
113 115
@@ -212,7 +214,22 @@ fail:
212 mutex_unlock(&led->lock); 214 mutex_unlock(&led->lock);
213} 215}
214 216
215static DEVICE_ATTR_RW(leds_mode); 217static DEVICE_ATTR_RW(mode);
218
219static struct attribute *gt683r_led_attrs[] = {
220 &dev_attr_mode.attr,
221 NULL
222};
223
224static const struct attribute_group gt683r_led_group = {
225 .name = "gt683r",
226 .attrs = gt683r_led_attrs,
227};
228
229static const struct attribute_group *gt683r_led_groups[] = {
230 &gt683r_led_group,
231 NULL
232};
216 233
217static int gt683r_led_probe(struct hid_device *hdev, 234static int gt683r_led_probe(struct hid_device *hdev,
218 const struct hid_device_id *id) 235 const struct hid_device_id *id)
@@ -261,6 +278,8 @@ static int gt683r_led_probe(struct hid_device *hdev,
261 led->led_devs[i].name = name; 278 led->led_devs[i].name = name;
262 led->led_devs[i].max_brightness = 1; 279 led->led_devs[i].max_brightness = 1;
263 led->led_devs[i].brightness_set = gt683r_brightness_set; 280 led->led_devs[i].brightness_set = gt683r_brightness_set;
281 led->led_devs[i].groups = gt683r_led_groups;
282
264 ret = led_classdev_register(&hdev->dev, &led->led_devs[i]); 283 ret = led_classdev_register(&hdev->dev, &led->led_devs[i]);
265 if (ret) { 284 if (ret) {
266 hid_err(hdev, "could not register led device\n"); 285 hid_err(hdev, "could not register led device\n");
@@ -268,12 +287,6 @@ static int gt683r_led_probe(struct hid_device *hdev,
268 } 287 }
269 } 288 }
270 289
271 ret = device_create_file(&led->hdev->dev, &dev_attr_leds_mode);
272 if (ret) {
273 hid_err(hdev, "could not make mode attribute file\n");
274 goto fail;
275 }
276
277 return 0; 290 return 0;
278 291
279fail: 292fail:
@@ -288,7 +301,6 @@ static void gt683r_led_remove(struct hid_device *hdev)
288 int i; 301 int i;
289 struct gt683r_led *led = hid_get_drvdata(hdev); 302 struct gt683r_led *led = hid_get_drvdata(hdev);
290 303
291 device_remove_file(&hdev->dev, &dev_attr_leds_mode);
292 for (i = 0; i < GT683R_LED_COUNT; i++) 304 for (i = 0; i < GT683R_LED_COUNT; i++)
293 led_classdev_unregister(&led->led_devs[i]); 305 led_classdev_unregister(&led->led_devs[i]);
294 flush_work(&led->work); 306 flush_work(&led->work);