Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753404AbbD0RLb (ORCPT ); Mon, 27 Apr 2015 13:11:31 -0400 Received: from smtp45.i.mail.ru ([94.100.177.105]:51457 "EHLO smtp45.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753146AbbD0RLa (ORCPT ); Mon, 27 Apr 2015 13:11:30 -0400 Message-ID: <553E6DBD.2080007@list.ru> Date: Mon, 27 Apr 2015 20:11:25 +0300 From: Stas Sergeev User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: linux-leds@vger.kernel.org CC: Linux kernel , Stas Sergeev , Richard Purdie , Bryan Wu Subject: [PATCH 1/3] leds: use hrtimer for blinking References: <553E6CF5.4030601@list.ru> In-Reply-To: <553E6CF5.4030601@list.ru> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam: Not detected X-Mras: Ok Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4479 Lines: 141 Normal timer has a jiffy resolution, usually 10ms. But leds trigger timer control allows to set the delays with 1ms granularity. In order to make this to really work we need to use hrtimer. CC: Bryan Wu CC: Richard Purdie CC: linux-leds@vger.kernel.org CC: linux-kernel@vger.kernel.org Signed-off-by: Stas Sergeev --- drivers/leds/led-class.c | 19 ++++++++++++------- drivers/leds/led-core.c | 9 +++++---- include/linux/leds.h | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 795ec99..f95ce912 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -102,20 +102,21 @@ static const struct attribute_group *led_groups[] = { NULL, }; -static void led_timer_function(unsigned long data) +static enum hrtimer_restart led_timer_function(struct hrtimer *timer) { - struct led_classdev *led_cdev = (void *)data; + struct led_classdev *led_cdev = container_of(timer, + struct led_classdev, blink_timer); unsigned long brightness; unsigned long delay; if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { led_set_brightness_async(led_cdev, LED_OFF); - return; + return HRTIMER_NORESTART; } if (led_cdev->flags & LED_BLINK_ONESHOT_STOP) { led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; - return; + return HRTIMER_NORESTART; } brightness = led_get_brightness(led_cdev); @@ -148,7 +149,10 @@ static void led_timer_function(unsigned long data) } } - mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); + hrtimer_forward(&led_cdev->blink_timer, + hrtimer_get_expires(&led_cdev->blink_timer), + ms_to_ktime(delay)); + return HRTIMER_RESTART; } static void set_brightness_delayed(struct work_struct *ws) @@ -243,8 +247,9 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); - setup_timer(&led_cdev->blink_timer, led_timer_function, - (unsigned long)led_cdev); + hrtimer_init(&led_cdev->blink_timer, CLOCK_MONOTONIC, + HRTIMER_MODE_REL); + led_cdev->blink_timer.function = led_timer_function; #ifdef CONFIG_LEDS_TRIGGERS led_trigger_set_default(led_cdev); diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 9886dac..2937259 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -52,7 +52,8 @@ static void led_set_software_blink(struct led_classdev *led_cdev, return; } - mod_timer(&led_cdev->blink_timer, jiffies + 1); + hrtimer_start(&led_cdev->blink_timer, ktime_set(0, 0), + HRTIMER_MODE_REL); } @@ -76,7 +77,7 @@ void led_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { - del_timer_sync(&led_cdev->blink_timer); + hrtimer_cancel(&led_cdev->blink_timer); led_cdev->flags &= ~LED_BLINK_ONESHOT; led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; @@ -91,7 +92,7 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev, int invert) { if ((led_cdev->flags & LED_BLINK_ONESHOT) && - timer_pending(&led_cdev->blink_timer)) + hrtimer_active(&led_cdev->blink_timer)) return; led_cdev->flags |= LED_BLINK_ONESHOT; @@ -108,7 +109,7 @@ EXPORT_SYMBOL(led_blink_set_oneshot); void led_stop_software_blink(struct led_classdev *led_cdev) { - del_timer_sync(&led_cdev->blink_timer); + hrtimer_cancel(&led_cdev->blink_timer); led_cdev->blink_delay_on = 0; led_cdev->blink_delay_off = 0; } diff --git a/include/linux/leds.h b/include/linux/leds.h index f70f84f..68f5a23 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include struct device; @@ -81,7 +81,7 @@ struct led_classdev { const char *default_trigger; /* Trigger to use */ unsigned long blink_delay_on, blink_delay_off; - struct timer_list blink_timer; + struct hrtimer blink_timer; int blink_brightness; void (*flash_resume)(struct led_classdev *led_cdev); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/