diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-14 13:07:22 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-14 13:07:22 -0700 |
commit | c07b3682cd12a017f976ec63bbd4758dc4c5100e (patch) | |
tree | d158994137113f31a30feadaae80d3c5d7109a26 /drivers/leds/trigger/ledtrig-activity.c | |
parent | 4d88e3d24905eafa98cef0fc29365649ad8977b5 (diff) | |
parent | 2224f2ff9670b899983ff1b42d85530e889cfea1 (diff) |
Merge tag 'leds-for-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds
Pull LED updates from Jacek Anaszewski:
"LED triggers improvements make the biggest part of this pull request.
The most striking ones, that allowed for nice cleanups in the triggers
are:
- centralized handling of creation and removal of trigger sysfs
attributes via attribute group
- addition of module_led_trigger() helper
The other things that need to be mentioned:
New features and improvements to existing LED class drivers:
- lt3593: add DT support, switch to gpiod interface
- lm3692x: support LED sync configuration, change OF calls to fwnode
calls
- apu: modify PC Engines apu/apu2 driver to support apu3
Change in the drivers/net/can/led.c:
- mark led trigger as broken since it's in the way for the further
cleanups. It implements a subset of the netdev trigger and an Ack
is needed from someone who can actually test and confirm that the
netdev trigger works for can devices"
* tag 'leds-for-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds: (32 commits)
leds: ns2: Change unsigned to unsigned int
usb: simplify usbport trigger
leds: gpio trigger: simplifications from core changes
leds: backlight trigger: simplifications from core changes
leds: activity trigger: simplifications from core changes
leds: default-on trigger: make use of module_led_trigger()
leds: heartbeat trigger: simplifications from core changes
leds: oneshot trigger: simplifications from core changes
leds: transient trigger: simplifications from core changes
leds: timer trigger: simplifications from core changes
leds: netdev trigger: simplifications from core changes
leds: triggers: new function led_set_trigger_data()
leds: triggers: define module_led_trigger helper
leds: triggers: handle .trigger_data and .activated() in the core
leds: triggers: add device attribute support
leds: triggers: let struct led_trigger::activate() return an error code
leds: triggers: make the MODULE_LICENSE string match the actual license
leds: lm3692x: Support LED sync configuration
dt: bindings: lm3692x: Update binding for LED sync control
leds: lm3692x: Change DT calls to fwnode calls
...
Diffstat (limited to 'drivers/leds/trigger/ledtrig-activity.c')
-rw-r--r-- | drivers/leds/trigger/ledtrig-activity.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/drivers/leds/trigger/ledtrig-activity.c b/drivers/leds/trigger/ledtrig-activity.c index 5081894082bd..bcbf41c90c30 100644 --- a/drivers/leds/trigger/ledtrig-activity.c +++ b/drivers/leds/trigger/ledtrig-activity.c @@ -7,8 +7,8 @@ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. - * */ + #include <linux/init.h> #include <linux/kernel.h> #include <linux/kernel_stat.h> @@ -37,7 +37,6 @@ static void led_activity_function(struct timer_list *t) struct activity_data *activity_data = from_timer(activity_data, t, timer); struct led_classdev *led_cdev = activity_data->led_cdev; - struct timespec boot_time; unsigned int target; unsigned int usage; int delay; @@ -57,8 +56,6 @@ static void led_activity_function(struct timer_list *t) return; } - get_monotonic_boottime(&boot_time); - cpus = 0; curr_used = 0; @@ -76,7 +73,7 @@ static void led_activity_function(struct timer_list *t) * down to 16us, ensuring we won't overflow 32-bit computations below * even up to 3k CPUs, while keeping divides cheap on smaller systems. */ - curr_boot = timespec_to_ns(&boot_time) * cpus; + curr_boot = ktime_get_boot_ns() * cpus; diff_boot = (curr_boot - activity_data->last_boot) >> 16; diff_used = (curr_used - activity_data->last_used) >> 16; activity_data->last_boot = curr_boot; @@ -155,8 +152,7 @@ static void led_activity_function(struct timer_list *t) static ssize_t led_invert_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct activity_data *activity_data = led_cdev->trigger_data; + struct activity_data *activity_data = led_trigger_get_drvdata(dev); return sprintf(buf, "%u\n", activity_data->invert); } @@ -165,8 +161,7 @@ static ssize_t led_invert_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct activity_data *activity_data = led_cdev->trigger_data; + struct activity_data *activity_data = led_trigger_get_drvdata(dev); unsigned long state; int ret; @@ -181,21 +176,21 @@ static ssize_t led_invert_store(struct device *dev, static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store); -static void activity_activate(struct led_classdev *led_cdev) +static struct attribute *activity_led_attrs[] = { + &dev_attr_invert.attr, + NULL +}; +ATTRIBUTE_GROUPS(activity_led); + +static int activity_activate(struct led_classdev *led_cdev) { struct activity_data *activity_data; - int rc; activity_data = kzalloc(sizeof(*activity_data), GFP_KERNEL); if (!activity_data) - return; + return -ENOMEM; - led_cdev->trigger_data = activity_data; - rc = device_create_file(led_cdev->dev, &dev_attr_invert); - if (rc) { - kfree(led_cdev->trigger_data); - return; - } + led_set_trigger_data(led_cdev, activity_data); activity_data->led_cdev = led_cdev; timer_setup(&activity_data->timer, led_activity_function, 0); @@ -203,26 +198,24 @@ static void activity_activate(struct led_classdev *led_cdev) led_cdev->blink_brightness = led_cdev->max_brightness; led_activity_function(&activity_data->timer); set_bit(LED_BLINK_SW, &led_cdev->work_flags); - led_cdev->activated = true; + + return 0; } static void activity_deactivate(struct led_classdev *led_cdev) { - struct activity_data *activity_data = led_cdev->trigger_data; - - if (led_cdev->activated) { - del_timer_sync(&activity_data->timer); - device_remove_file(led_cdev->dev, &dev_attr_invert); - kfree(activity_data); - clear_bit(LED_BLINK_SW, &led_cdev->work_flags); - led_cdev->activated = false; - } + struct activity_data *activity_data = led_get_trigger_data(led_cdev); + + del_timer_sync(&activity_data->timer); + kfree(activity_data); + clear_bit(LED_BLINK_SW, &led_cdev->work_flags); } static struct led_trigger activity_led_trigger = { .name = "activity", .activate = activity_activate, .deactivate = activity_deactivate, + .groups = activity_led_groups, }; static int activity_reboot_notifier(struct notifier_block *nb, @@ -272,4 +265,4 @@ module_exit(activity_exit); MODULE_AUTHOR("Willy Tarreau <w@1wt.eu>"); MODULE_DESCRIPTION("Activity LED trigger"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); |