Commit fb3d7691 authored by Jacek Anaszewski's avatar Jacek Anaszewski Committed by Jacek Anaszewski

leds: ledtrig-heartbeat: Make top brightness adjustable

LED class heartbeat trigger allowed only for blinking with max_brightness
value. This patch adds more flexibility by exploiting part of LED core
software blink infrastructure.
Signed-off-by: default avatarJacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
parent ae347323
...@@ -43,6 +43,9 @@ static void led_heartbeat_function(unsigned long data) ...@@ -43,6 +43,9 @@ static void led_heartbeat_function(unsigned long data)
return; return;
} }
if (test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE, &led_cdev->work_flags))
led_cdev->blink_brightness = led_cdev->new_blink_brightness;
/* acts like an actual heart beat -- ie thump-thump-pause... */ /* acts like an actual heart beat -- ie thump-thump-pause... */
switch (heartbeat_data->phase) { switch (heartbeat_data->phase) {
case 0: case 0:
...@@ -59,26 +62,26 @@ static void led_heartbeat_function(unsigned long data) ...@@ -59,26 +62,26 @@ static void led_heartbeat_function(unsigned long data)
delay = msecs_to_jiffies(70); delay = msecs_to_jiffies(70);
heartbeat_data->phase++; heartbeat_data->phase++;
if (!heartbeat_data->invert) if (!heartbeat_data->invert)
brightness = led_cdev->max_brightness; brightness = led_cdev->blink_brightness;
break; break;
case 1: case 1:
delay = heartbeat_data->period / 4 - msecs_to_jiffies(70); delay = heartbeat_data->period / 4 - msecs_to_jiffies(70);
heartbeat_data->phase++; heartbeat_data->phase++;
if (heartbeat_data->invert) if (heartbeat_data->invert)
brightness = led_cdev->max_brightness; brightness = led_cdev->blink_brightness;
break; break;
case 2: case 2:
delay = msecs_to_jiffies(70); delay = msecs_to_jiffies(70);
heartbeat_data->phase++; heartbeat_data->phase++;
if (!heartbeat_data->invert) if (!heartbeat_data->invert)
brightness = led_cdev->max_brightness; brightness = led_cdev->blink_brightness;
break; break;
default: default:
delay = heartbeat_data->period - heartbeat_data->period / 4 - delay = heartbeat_data->period - heartbeat_data->period / 4 -
msecs_to_jiffies(70); msecs_to_jiffies(70);
heartbeat_data->phase = 0; heartbeat_data->phase = 0;
if (heartbeat_data->invert) if (heartbeat_data->invert)
brightness = led_cdev->max_brightness; brightness = led_cdev->blink_brightness;
break; break;
} }
...@@ -133,7 +136,10 @@ static void heartbeat_trig_activate(struct led_classdev *led_cdev) ...@@ -133,7 +136,10 @@ static void heartbeat_trig_activate(struct led_classdev *led_cdev)
setup_timer(&heartbeat_data->timer, setup_timer(&heartbeat_data->timer,
led_heartbeat_function, (unsigned long) led_cdev); led_heartbeat_function, (unsigned long) led_cdev);
heartbeat_data->phase = 0; heartbeat_data->phase = 0;
if (!led_cdev->blink_brightness)
led_cdev->blink_brightness = led_cdev->max_brightness;
led_heartbeat_function(heartbeat_data->timer.data); led_heartbeat_function(heartbeat_data->timer.data);
set_bit(LED_BLINK_SW, &led_cdev->work_flags);
led_cdev->activated = true; led_cdev->activated = true;
} }
...@@ -145,6 +151,7 @@ static void heartbeat_trig_deactivate(struct led_classdev *led_cdev) ...@@ -145,6 +151,7 @@ static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
del_timer_sync(&heartbeat_data->timer); del_timer_sync(&heartbeat_data->timer);
device_remove_file(led_cdev->dev, &dev_attr_invert); device_remove_file(led_cdev->dev, &dev_attr_invert);
kfree(heartbeat_data); kfree(heartbeat_data);
clear_bit(LED_BLINK_SW, &led_cdev->work_flags);
led_cdev->activated = false; led_cdev->activated = false;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment