diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2018-07-02 23:05:27 +0300 |
---|---|---|
committer | Jacek Anaszewski <jacek.anaszewski@gmail.com> | 2018-07-06 00:21:12 +0300 |
commit | 2b7b6d44e29160eb12abd950c374babf21ed83d4 (patch) | |
tree | 16f07445e0a4b37ae7cdb8c823d1e4427443c4a5 /drivers/leds/trigger | |
parent | f8112a1de1a728ffef0dd9f6c3005490c5f79ab1 (diff) | |
download | linux-2b7b6d44e29160eb12abd950c374babf21ed83d4.tar.xz |
leds: timer trigger: simplifications from core changes
The trigger core learned error handling for the activate callback and
can handle device attributes now. This allows simplifying the driver
considerably. Note that .deactivate() is only called when .activate()
succeeded, so the check for .trigger_data being non-NULL can go away.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Diffstat (limited to 'drivers/leds/trigger')
-rw-r--r-- | drivers/leds/trigger/ledtrig-timer.c | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/drivers/leds/trigger/ledtrig-timer.c b/drivers/leds/trigger/ledtrig-timer.c index 527055d815ad..7c14983781ee 100644 --- a/drivers/leds/trigger/ledtrig-timer.c +++ b/drivers/leds/trigger/ledtrig-timer.c @@ -20,7 +20,7 @@ static ssize_t led_delay_on_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev *led_cdev = led_trigger_get_led(dev); return sprintf(buf, "%lu\n", led_cdev->blink_delay_on); } @@ -28,7 +28,7 @@ static ssize_t led_delay_on_show(struct device *dev, static ssize_t led_delay_on_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev *led_cdev = led_trigger_get_led(dev); unsigned long state; ssize_t ret = -EINVAL; @@ -45,7 +45,7 @@ static ssize_t led_delay_on_store(struct device *dev, static ssize_t led_delay_off_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev *led_cdev = led_trigger_get_led(dev); return sprintf(buf, "%lu\n", led_cdev->blink_delay_off); } @@ -53,7 +53,7 @@ static ssize_t led_delay_off_show(struct device *dev, static ssize_t led_delay_off_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev *led_cdev = led_trigger_get_led(dev); unsigned long state; ssize_t ret = -EINVAL; @@ -70,39 +70,23 @@ static ssize_t led_delay_off_store(struct device *dev, static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store); static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store); +static struct attribute *timer_trig_attrs[] = { + &dev_attr_delay_on.attr, + &dev_attr_delay_off.attr, + NULL +}; +ATTRIBUTE_GROUPS(timer_trig); + static int timer_trig_activate(struct led_classdev *led_cdev) { - int rc; - - led_cdev->trigger_data = NULL; - - rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); - if (rc) - return 0; - rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); - if (rc) - goto err_out_delayon; - led_blink_set(led_cdev, &led_cdev->blink_delay_on, &led_cdev->blink_delay_off); - led_cdev->activated = true; - - return 0; - -err_out_delayon: - device_remove_file(led_cdev->dev, &dev_attr_delay_on); return 0; } static void timer_trig_deactivate(struct led_classdev *led_cdev) { - if (led_cdev->activated) { - device_remove_file(led_cdev->dev, &dev_attr_delay_on); - device_remove_file(led_cdev->dev, &dev_attr_delay_off); - led_cdev->activated = false; - } - /* Stop blinking */ led_set_brightness(led_cdev, LED_OFF); } @@ -111,20 +95,9 @@ static struct led_trigger timer_led_trigger = { .name = "timer", .activate = timer_trig_activate, .deactivate = timer_trig_deactivate, + .groups = timer_trig_groups, }; - -static int __init timer_trig_init(void) -{ - return led_trigger_register(&timer_led_trigger); -} - -static void __exit timer_trig_exit(void) -{ - led_trigger_unregister(&timer_led_trigger); -} - -module_init(timer_trig_init); -module_exit(timer_trig_exit); +module_led_trigger(timer_led_trigger); MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); MODULE_DESCRIPTION("Timer LED trigger"); |