[v1] leds: trigger: pattern: add support for hrtimer

Message ID 20230522190412.374474-1-mmkurbanov@sberdevices.ru
State New
Headers
Series [v1] leds: trigger: pattern: add support for hrtimer |

Commit Message

Martin Kurbanov May 22, 2023, 7:04 p.m. UTC
  Currently, led pattern trigger uses timer_list to schedule brightness
changing. As we know from timer_list API [1], it's not accurate to
milliseconds and depends on HZ granularity.

Example:
"0 10 0 0 50 10 50 0 100 10 100 0 150 10 150 0 200 10 200 0 250 10 250 0",
we expect it to be 60ms long, but it can actually be up to ~120ms
(add ~10ms for each pattern when HZ == 100).

But sometimes, userspace needs time accurate led patterns to make sure
that pattern will be executed during expected time slot.
To achieve this goal the patch introduces optional hrtimer usage for
led trigger pattern, because hrtimer is microseconds accurate timer.

[1]: kernel/time/timer.c#L104

Signed-off-by: Martin Kurbanov <mmkurbanov@sberdevices.ru>
---
 .../testing/sysfs-class-led-trigger-pattern   |  10 ++
 drivers/leds/trigger/ledtrig-pattern.c        | 123 ++++++++++++++----
 2 files changed, 111 insertions(+), 22 deletions(-)
  

Comments

kernel test robot May 22, 2023, 9:44 p.m. UTC | #1
Hi Martin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on lee-leds/for-leds-next]
[also build test WARNING on wireless-next/main wireless/main linus/master v6.4-rc3 next-20230522]
[cannot apply to pavel-leds/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Martin-Kurbanov/leds-trigger-pattern-add-support-for-hrtimer/20230523-030630
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git for-leds-next
patch link:    https://lore.kernel.org/r/20230522190412.374474-1-mmkurbanov%40sberdevices.ru
patch subject: [PATCH v1] leds: trigger: pattern: add support for hrtimer
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230523/202305230549.ekneaQ89-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/084f274c07fd243e864f73ab80a9eda5e940f024
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Martin-Kurbanov/leds-trigger-pattern-add-support-for-hrtimer/20230523-030630
        git checkout 084f274c07fd243e864f73ab80a9eda5e940f024
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/leds/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202305230549.ekneaQ89-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/leds/trigger/ledtrig-pattern.c: In function 'pattern_init':
>> drivers/leds/trigger/ledtrig-pattern.c:454:74: warning: implicit conversion from 'enum <anonymous>' to 'enum pattern_type' [-Wenum-conversion]
     454 |         err = pattern_trig_store_patterns(led_cdev, NULL, pattern, size, false);
         |                                                                          ^~~~~


vim +454 drivers/leds/trigger/ledtrig-pattern.c

5fd752b6b3a223 Baolin Wang         2018-10-11  438  
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  439  static void pattern_init(struct led_classdev *led_cdev)
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  440  {
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  441  	unsigned int size = 0;
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  442  	u32 *pattern;
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  443  	int err;
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  444  
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  445  	pattern = led_get_default_pattern(led_cdev, &size);
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  446  	if (!pattern)
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  447  		return;
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  448  
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  449  	if (size % 2) {
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  450  		dev_warn(led_cdev->dev, "Expected pattern of tuples\n");
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  451  		goto out;
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  452  	}
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  453  
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09 @454  	err = pattern_trig_store_patterns(led_cdev, NULL, pattern, size, false);
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  455  	if (err < 0)
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  456  		dev_warn(led_cdev->dev,
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  457  			 "Pattern initialization failed with error %d\n", err);
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  458  
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  459  out:
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  460  	kfree(pattern);
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  461  }
aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  462
  
Lee Jones June 1, 2023, 6:51 p.m. UTC | #2
On Tue, 23 May 2023, kernel test robot wrote:

> Hi Martin,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on lee-leds/for-leds-next]
> [also build test WARNING on wireless-next/main wireless/main linus/master v6.4-rc3 next-20230522]
> [cannot apply to pavel-leds/for-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Martin-Kurbanov/leds-trigger-pattern-add-support-for-hrtimer/20230523-030630
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git for-leds-next
> patch link:    https://lore.kernel.org/r/20230522190412.374474-1-mmkurbanov%40sberdevices.ru
> patch subject: [PATCH v1] leds: trigger: pattern: add support for hrtimer
> config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230523/202305230549.ekneaQ89-lkp@intel.com/config)
> compiler: m68k-linux-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/084f274c07fd243e864f73ab80a9eda5e940f024
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Martin-Kurbanov/leds-trigger-pattern-add-support-for-hrtimer/20230523-030630
>         git checkout 084f274c07fd243e864f73ab80a9eda5e940f024
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/leds/
> 
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202305230549.ekneaQ89-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>    drivers/leds/trigger/ledtrig-pattern.c: In function 'pattern_init':
> >> drivers/leds/trigger/ledtrig-pattern.c:454:74: warning: implicit conversion from 'enum <anonymous>' to 'enum pattern_type' [-Wenum-conversion]
>      454 |         err = pattern_trig_store_patterns(led_cdev, NULL, pattern, size, false);
>          |                                                                          ^~~~~
 
Did you fix this already? 

I don't see a subsequent submission?
 
> vim +454 drivers/leds/trigger/ledtrig-pattern.c
> 
> 5fd752b6b3a223 Baolin Wang         2018-10-11  438  
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  439  static void pattern_init(struct led_classdev *led_cdev)
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  440  {
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  441  	unsigned int size = 0;
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  442  	u32 *pattern;
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  443  	int err;
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  444  
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  445  	pattern = led_get_default_pattern(led_cdev, &size);
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  446  	if (!pattern)
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  447  		return;
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  448  
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  449  	if (size % 2) {
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  450  		dev_warn(led_cdev->dev, "Expected pattern of tuples\n");
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  451  		goto out;
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  452  	}
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  453  
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09 @454  	err = pattern_trig_store_patterns(led_cdev, NULL, pattern, size, false);
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  455  	if (err < 0)
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  456  		dev_warn(led_cdev->dev,
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  457  			 "Pattern initialization failed with error %d\n", err);
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  458  
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  459  out:
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  460  	kfree(pattern);
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  461  }
> aa6fd10481bdb1 Krzysztof Kozlowski 2019-01-09  462  
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
  
Martin Kurbanov June 2, 2023, 11:03 a.m. UTC | #3
Hello Lee,

On 01.06.2023 21:51, Lee Jones wrote:
>>    drivers/leds/trigger/ledtrig-pattern.c: In function 'pattern_init':
>>>> drivers/leds/trigger/ledtrig-pattern.c:454:74: warning: implicit conversion from 'enum <anonymous>' to 'enum pattern_type' [-Wenum-conversion]
>>      454 |         err = pattern_trig_store_patterns(led_cdev, NULL, pattern, size, false);
>>          |                                                                          ^~~~~
>  
> Did you fix this already? 
> 
> I don't see a subsequent submission?

Sure, I intend to send the updated version very soon (hopefully today).
  

Patch

diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-pattern b/Documentation/ABI/testing/sysfs-class-led-trigger-pattern
index 8c57d2780554..07d0ab35ba9a 100644
--- a/Documentation/ABI/testing/sysfs-class-led-trigger-pattern
+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-pattern
@@ -12,6 +12,16 @@  Description:
 		The exact format is described in:
 		Documentation/devicetree/bindings/leds/leds-trigger-pattern.txt
 
+What:		/sys/class/leds/<led>/hr_pattern
+Date:		May 2023
+Description:
+		Specify a software pattern for the LED, that supports altering
+		the brightness for the specified duration with one software
+		timer. It can do gradual dimming and step change of brightness.
+
+		Unlike the /sys/class/leds/<led>/pattern, this attribute runs
+		a pattern on high-resolution timer (hrtimer).
+
 What:		/sys/class/leds/<led>/hw_pattern
 Date:		September 2018
 KernelVersion:	4.20
diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c
index fadd87dbe993..93d79b912290 100644
--- a/drivers/leds/trigger/ledtrig-pattern.c
+++ b/drivers/leds/trigger/ledtrig-pattern.c
@@ -13,6 +13,7 @@ 
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/timer.h>
+#include <linux/hrtimer.h>
 
 #define MAX_PATTERNS		1024
 /*
@@ -21,6 +22,12 @@ 
  */
 #define UPDATE_INTERVAL		50
 
+enum pattern_type {
+	PATTERN_TYPE_SW, /* Use standard timer for software pattern */
+	PATTERN_TYPE_HR, /* Use hrtimer for software pattern */
+	PATTERN_TYPE_HW, /* Hardware pattern */
+};
+
 struct pattern_trig_data {
 	struct led_classdev *led_cdev;
 	struct led_pattern patterns[MAX_PATTERNS];
@@ -32,8 +39,9 @@  struct pattern_trig_data {
 	int last_repeat;
 	int delta_t;
 	bool is_indefinite;
-	bool is_hw_pattern;
+	enum pattern_type type;
 	struct timer_list timer;
+	struct hrtimer hrtimer;
 };
 
 static void pattern_trig_update_patterns(struct pattern_trig_data *data)
@@ -71,10 +79,35 @@  static int pattern_trig_compute_brightness(struct pattern_trig_data *data)
 		return data->curr->brightness - step_brightness;
 }
 
-static void pattern_trig_timer_function(struct timer_list *t)
+static void pattern_trig_timer_start(struct pattern_trig_data *data)
 {
-	struct pattern_trig_data *data = from_timer(data, t, timer);
+	if (data->type == PATTERN_TYPE_HR) {
+		hrtimer_start(&data->hrtimer, ns_to_ktime(0), HRTIMER_MODE_REL);
+	} else {
+		data->timer.expires = jiffies;
+		add_timer(&data->timer);
+	}
+}
 
+static void pattern_trig_timer_cancel(struct pattern_trig_data *data)
+{
+	if (data->type == PATTERN_TYPE_HR)
+		hrtimer_cancel(&data->hrtimer);
+	else
+		del_timer_sync(&data->timer);
+}
+
+static void pattern_trig_timer_restart(struct pattern_trig_data *data,
+				       unsigned long interval)
+{
+	if (data->type == PATTERN_TYPE_HR)
+		hrtimer_forward_now(&data->hrtimer, ms_to_ktime(interval));
+	else
+		mod_timer(&data->timer, jiffies + msecs_to_jiffies(interval));
+}
+
+static void pattern_trig_timer_common_function(struct pattern_trig_data *data)
+{
 	for (;;) {
 		if (!data->is_indefinite && !data->repeat)
 			break;
@@ -83,8 +116,7 @@  static void pattern_trig_timer_function(struct timer_list *t)
 			/* Step change of brightness */
 			led_set_brightness(data->led_cdev,
 					   data->curr->brightness);
-			mod_timer(&data->timer,
-				  jiffies + msecs_to_jiffies(data->curr->delta_t));
+			pattern_trig_timer_restart(data, data->curr->delta_t);
 			if (!data->next->delta_t) {
 				/* Skip the tuple with zero duration */
 				pattern_trig_update_patterns(data);
@@ -106,8 +138,7 @@  static void pattern_trig_timer_function(struct timer_list *t)
 
 			led_set_brightness(data->led_cdev,
 					   pattern_trig_compute_brightness(data));
-			mod_timer(&data->timer,
-				  jiffies + msecs_to_jiffies(UPDATE_INTERVAL));
+			pattern_trig_timer_restart(data, UPDATE_INTERVAL);
 
 			/* Accumulate the gradual dimming time */
 			data->delta_t += UPDATE_INTERVAL;
@@ -117,6 +148,25 @@  static void pattern_trig_timer_function(struct timer_list *t)
 	}
 }
 
+static void pattern_trig_timer_function(struct timer_list *t)
+{
+	struct pattern_trig_data *data = from_timer(data, t, timer);
+
+	return pattern_trig_timer_common_function(data);
+}
+
+static enum hrtimer_restart pattern_trig_hrtimer_function(struct hrtimer *t)
+{
+	struct pattern_trig_data *data =
+		container_of(t, struct pattern_trig_data, hrtimer);
+
+	pattern_trig_timer_common_function(data);
+	if (!data->is_indefinite && !data->repeat)
+		return HRTIMER_NORESTART;
+
+	return HRTIMER_RESTART;
+}
+
 static int pattern_trig_start_pattern(struct led_classdev *led_cdev)
 {
 	struct pattern_trig_data *data = led_cdev->trigger_data;
@@ -124,7 +174,7 @@  static int pattern_trig_start_pattern(struct led_classdev *led_cdev)
 	if (!data->npatterns)
 		return 0;
 
-	if (data->is_hw_pattern) {
+	if (data->type == PATTERN_TYPE_HW) {
 		return led_cdev->pattern_set(led_cdev, data->patterns,
 					     data->npatterns, data->repeat);
 	}
@@ -136,8 +186,7 @@  static int pattern_trig_start_pattern(struct led_classdev *led_cdev)
 	data->delta_t = 0;
 	data->curr = data->patterns;
 	data->next = data->patterns + 1;
-	data->timer.expires = jiffies;
-	add_timer(&data->timer);
+	pattern_trig_timer_start(data);
 
 	return 0;
 }
@@ -175,9 +224,9 @@  static ssize_t repeat_store(struct device *dev, struct device_attribute *attr,
 
 	mutex_lock(&data->lock);
 
-	del_timer_sync(&data->timer);
+	pattern_trig_timer_cancel(data);
 
-	if (data->is_hw_pattern)
+	if (data->type == PATTERN_TYPE_HW)
 		led_cdev->pattern_clear(led_cdev);
 
 	data->last_repeat = data->repeat = res;
@@ -196,14 +245,14 @@  static ssize_t repeat_store(struct device *dev, struct device_attribute *attr,
 static DEVICE_ATTR_RW(repeat);
 
 static ssize_t pattern_trig_show_patterns(struct pattern_trig_data *data,
-					  char *buf, bool hw_pattern)
+					  char *buf, enum pattern_type type)
 {
 	ssize_t count = 0;
 	int i;
 
 	mutex_lock(&data->lock);
 
-	if (!data->npatterns || (data->is_hw_pattern ^ hw_pattern))
+	if (!data->npatterns || data->type != type)
 		goto out;
 
 	for (i = 0; i < data->npatterns; i++) {
@@ -260,19 +309,19 @@  static int pattern_trig_store_patterns_int(struct pattern_trig_data *data,
 
 static ssize_t pattern_trig_store_patterns(struct led_classdev *led_cdev,
 					   const char *buf, const u32 *buf_int,
-					   size_t count, bool hw_pattern)
+					   size_t count, enum pattern_type type)
 {
 	struct pattern_trig_data *data = led_cdev->trigger_data;
 	int err = 0;
 
 	mutex_lock(&data->lock);
 
-	del_timer_sync(&data->timer);
+	pattern_trig_timer_cancel(data);
 
-	if (data->is_hw_pattern)
+	if (data->type == PATTERN_TYPE_HW)
 		led_cdev->pattern_clear(led_cdev);
 
-	data->is_hw_pattern = hw_pattern;
+	data->type = type;
 	data->npatterns = 0;
 
 	if (buf)
@@ -297,7 +346,7 @@  static ssize_t pattern_show(struct device *dev, struct device_attribute *attr,
 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
 	struct pattern_trig_data *data = led_cdev->trigger_data;
 
-	return pattern_trig_show_patterns(data, buf, false);
+	return pattern_trig_show_patterns(data, buf, PATTERN_TYPE_SW);
 }
 
 static ssize_t pattern_store(struct device *dev, struct device_attribute *attr,
@@ -305,7 +354,8 @@  static ssize_t pattern_store(struct device *dev, struct device_attribute *attr,
 {
 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
 
-	return pattern_trig_store_patterns(led_cdev, buf, NULL, count, false);
+	return pattern_trig_store_patterns(led_cdev, buf, NULL, count,
+					   PATTERN_TYPE_SW);
 }
 
 static DEVICE_ATTR_RW(pattern);
@@ -316,7 +366,7 @@  static ssize_t hw_pattern_show(struct device *dev,
 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
 	struct pattern_trig_data *data = led_cdev->trigger_data;
 
-	return pattern_trig_show_patterns(data, buf, true);
+	return pattern_trig_show_patterns(data, buf, PATTERN_TYPE_HW);
 }
 
 static ssize_t hw_pattern_store(struct device *dev,
@@ -325,11 +375,33 @@  static ssize_t hw_pattern_store(struct device *dev,
 {
 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
 
-	return pattern_trig_store_patterns(led_cdev, buf, NULL, count, true);
+	return pattern_trig_store_patterns(led_cdev, buf, NULL, count,
+					   PATTERN_TYPE_HW);
 }
 
 static DEVICE_ATTR_RW(hw_pattern);
 
+static ssize_t hr_pattern_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct led_classdev *led_cdev = dev_get_drvdata(dev);
+	struct pattern_trig_data *data = led_cdev->trigger_data;
+
+	return pattern_trig_show_patterns(data, buf, PATTERN_TYPE_HR);
+}
+
+static ssize_t hr_pattern_store(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
+{
+	struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+	return pattern_trig_store_patterns(led_cdev, buf, NULL, count,
+					   PATTERN_TYPE_HR);
+}
+
+static DEVICE_ATTR_RW(hr_pattern);
+
 static umode_t pattern_trig_attrs_mode(struct kobject *kobj,
 				       struct attribute *attr, int index)
 {
@@ -338,6 +410,8 @@  static umode_t pattern_trig_attrs_mode(struct kobject *kobj,
 
 	if (attr == &dev_attr_repeat.attr || attr == &dev_attr_pattern.attr)
 		return attr->mode;
+	else if (attr == &dev_attr_hr_pattern.attr)
+		return attr->mode;
 	else if (attr == &dev_attr_hw_pattern.attr && led_cdev->pattern_set)
 		return attr->mode;
 
@@ -347,6 +421,7 @@  static umode_t pattern_trig_attrs_mode(struct kobject *kobj,
 static struct attribute *pattern_trig_attrs[] = {
 	&dev_attr_pattern.attr,
 	&dev_attr_hw_pattern.attr,
+	&dev_attr_hr_pattern.attr,
 	&dev_attr_repeat.attr,
 	NULL
 };
@@ -400,12 +475,15 @@  static int pattern_trig_activate(struct led_classdev *led_cdev)
 		led_cdev->pattern_clear = NULL;
 	}
 
+	data->type = PATTERN_TYPE_SW;
 	data->is_indefinite = true;
 	data->last_repeat = -1;
 	mutex_init(&data->lock);
 	data->led_cdev = led_cdev;
 	led_set_trigger_data(led_cdev, data);
 	timer_setup(&data->timer, pattern_trig_timer_function, 0);
+	hrtimer_init(&data->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+	data->hrtimer.function = pattern_trig_hrtimer_function;
 	led_cdev->activated = true;
 
 	if (led_cdev->flags & LED_INIT_DEFAULT_TRIGGER) {
@@ -431,6 +509,7 @@  static void pattern_trig_deactivate(struct led_classdev *led_cdev)
 		led_cdev->pattern_clear(led_cdev);
 
 	timer_shutdown_sync(&data->timer);
+	hrtimer_cancel(&data->hrtimer);
 
 	led_set_brightness(led_cdev, LED_OFF);
 	kfree(data);