summaryrefslogtreecommitdiff
path: root/drivers/leds/led-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/leds/led-core.c')
-rw-r--r--drivers/leds/led-core.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index f2cea4e094f6..001c290bc07b 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -8,6 +8,7 @@
*/
#include <linux/kernel.h>
+#include <linux/led-class-multicolor.h>
#include <linux/leds.h>
#include <linux/list.h>
#include <linux/module.h>
@@ -121,15 +122,22 @@ static void led_timer_function(struct timer_list *t)
static void set_brightness_delayed_set_brightness(struct led_classdev *led_cdev,
unsigned int value)
{
- int ret = 0;
+ int ret;
ret = __led_set_brightness(led_cdev, value);
- if (ret == -ENOTSUPP)
+ if (ret == -ENOTSUPP) {
ret = __led_set_brightness_blocking(led_cdev, value);
- if (ret < 0 &&
- /* LED HW might have been unplugged, therefore don't warn */
- !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) &&
- (led_cdev->flags & LED_HW_PLUGGABLE)))
+ if (ret == -ENOTSUPP)
+ /* No back-end support to set a fixed brightness value */
+ return;
+ }
+
+ /* LED HW might have been unplugged, therefore don't warn */
+ if (ret == -ENODEV && led_cdev->flags & LED_UNREGISTERING &&
+ led_cdev->flags & LED_HW_PLUGGABLE)
+ return;
+
+ if (ret < 0)
dev_err(led_cdev->dev,
"Setting an LED's brightness failed (%d)\n", ret);
}
@@ -361,6 +369,36 @@ int led_set_brightness_sync(struct led_classdev *led_cdev, unsigned int value)
}
EXPORT_SYMBOL_GPL(led_set_brightness_sync);
+/*
+ * This is a led-core function because just like led_set_brightness()
+ * it is used in the kernel by e.g. triggers.
+ */
+void led_mc_set_brightness(struct led_classdev *led_cdev,
+ unsigned int *intensity_value, unsigned int num_colors,
+ unsigned int brightness)
+{
+ struct led_classdev_mc *mcled_cdev;
+ unsigned int i;
+
+ if (!(led_cdev->flags & LED_MULTI_COLOR)) {
+ dev_err_once(led_cdev->dev, "error not a multi-color LED\n");
+ return;
+ }
+
+ mcled_cdev = lcdev_to_mccdev(led_cdev);
+ if (num_colors != mcled_cdev->num_colors) {
+ dev_err_once(led_cdev->dev, "error num_colors mismatch %u != %u\n",
+ num_colors, mcled_cdev->num_colors);
+ return;
+ }
+
+ for (i = 0; i < mcled_cdev->num_colors; i++)
+ mcled_cdev->subled_info[i].intensity = intensity_value[i];
+
+ led_set_brightness(led_cdev, brightness);
+}
+EXPORT_SYMBOL_GPL(led_mc_set_brightness);
+
int led_update_brightness(struct led_classdev *led_cdev)
{
int ret;