Lines Matching refs:data

47 static void pattern_trig_update_patterns(struct pattern_trig_data *data)  in pattern_trig_update_patterns()  argument
49 data->curr = data->next; in pattern_trig_update_patterns()
50 if (!data->is_indefinite && data->curr == data->patterns) in pattern_trig_update_patterns()
51 data->repeat--; in pattern_trig_update_patterns()
53 if (data->next == data->patterns + data->npatterns - 1) in pattern_trig_update_patterns()
54 data->next = data->patterns; in pattern_trig_update_patterns()
56 data->next++; in pattern_trig_update_patterns()
58 data->delta_t = 0; in pattern_trig_update_patterns()
61 static int pattern_trig_compute_brightness(struct pattern_trig_data *data) in pattern_trig_compute_brightness() argument
70 if (data->delta_t == 0 || data->curr->delta_t < UPDATE_INTERVAL) in pattern_trig_compute_brightness()
71 return data->curr->brightness; in pattern_trig_compute_brightness()
73 step_brightness = abs(data->next->brightness - data->curr->brightness); in pattern_trig_compute_brightness()
74 step_brightness = data->delta_t * step_brightness / data->curr->delta_t; in pattern_trig_compute_brightness()
76 if (data->next->brightness > data->curr->brightness) in pattern_trig_compute_brightness()
77 return data->curr->brightness + step_brightness; in pattern_trig_compute_brightness()
79 return data->curr->brightness - step_brightness; in pattern_trig_compute_brightness()
82 static void pattern_trig_timer_start(struct pattern_trig_data *data) in pattern_trig_timer_start() argument
84 if (data->type == PATTERN_TYPE_HR) { in pattern_trig_timer_start()
85 hrtimer_start(&data->hrtimer, ns_to_ktime(0), HRTIMER_MODE_REL); in pattern_trig_timer_start()
87 data->timer.expires = jiffies; in pattern_trig_timer_start()
88 add_timer(&data->timer); in pattern_trig_timer_start()
92 static void pattern_trig_timer_cancel(struct pattern_trig_data *data) in pattern_trig_timer_cancel() argument
94 if (data->type == PATTERN_TYPE_HR) in pattern_trig_timer_cancel()
95 hrtimer_cancel(&data->hrtimer); in pattern_trig_timer_cancel()
97 del_timer_sync(&data->timer); in pattern_trig_timer_cancel()
100 static void pattern_trig_timer_restart(struct pattern_trig_data *data, in pattern_trig_timer_restart() argument
103 if (data->type == PATTERN_TYPE_HR) in pattern_trig_timer_restart()
104 hrtimer_forward_now(&data->hrtimer, ms_to_ktime(interval)); in pattern_trig_timer_restart()
106 mod_timer(&data->timer, jiffies + msecs_to_jiffies(interval)); in pattern_trig_timer_restart()
109 static void pattern_trig_timer_common_function(struct pattern_trig_data *data) in pattern_trig_timer_common_function() argument
112 if (!data->is_indefinite && !data->repeat) in pattern_trig_timer_common_function()
115 if (data->curr->brightness == data->next->brightness) { in pattern_trig_timer_common_function()
117 led_set_brightness(data->led_cdev, in pattern_trig_timer_common_function()
118 data->curr->brightness); in pattern_trig_timer_common_function()
119 pattern_trig_timer_restart(data, data->curr->delta_t); in pattern_trig_timer_common_function()
120 if (!data->next->delta_t) { in pattern_trig_timer_common_function()
122 pattern_trig_update_patterns(data); in pattern_trig_timer_common_function()
125 pattern_trig_update_patterns(data); in pattern_trig_timer_common_function()
134 if (data->delta_t > data->curr->delta_t) { in pattern_trig_timer_common_function()
135 pattern_trig_update_patterns(data); in pattern_trig_timer_common_function()
139 led_set_brightness(data->led_cdev, in pattern_trig_timer_common_function()
140 pattern_trig_compute_brightness(data)); in pattern_trig_timer_common_function()
141 pattern_trig_timer_restart(data, UPDATE_INTERVAL); in pattern_trig_timer_common_function()
144 data->delta_t += UPDATE_INTERVAL; in pattern_trig_timer_common_function()
153 struct pattern_trig_data *data = from_timer(data, t, timer); in pattern_trig_timer_function() local
155 return pattern_trig_timer_common_function(data); in pattern_trig_timer_function()
160 struct pattern_trig_data *data = in pattern_trig_hrtimer_function() local
163 pattern_trig_timer_common_function(data); in pattern_trig_hrtimer_function()
164 if (!data->is_indefinite && !data->repeat) in pattern_trig_hrtimer_function()
172 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_trig_start_pattern() local
174 if (!data->npatterns) in pattern_trig_start_pattern()
177 if (data->type == PATTERN_TYPE_HW) { in pattern_trig_start_pattern()
178 return led_cdev->pattern_set(led_cdev, data->patterns, in pattern_trig_start_pattern()
179 data->npatterns, data->repeat); in pattern_trig_start_pattern()
183 if (data->npatterns < 2) in pattern_trig_start_pattern()
186 data->delta_t = 0; in pattern_trig_start_pattern()
187 data->curr = data->patterns; in pattern_trig_start_pattern()
188 data->next = data->patterns + 1; in pattern_trig_start_pattern()
189 pattern_trig_timer_start(data); in pattern_trig_start_pattern()
198 struct pattern_trig_data *data = led_cdev->trigger_data; in repeat_show() local
201 mutex_lock(&data->lock); in repeat_show()
203 repeat = data->last_repeat; in repeat_show()
205 mutex_unlock(&data->lock); in repeat_show()
214 struct pattern_trig_data *data = led_cdev->trigger_data; in repeat_store() local
225 mutex_lock(&data->lock); in repeat_store()
227 pattern_trig_timer_cancel(data); in repeat_store()
229 if (data->type == PATTERN_TYPE_HW) in repeat_store()
232 data->last_repeat = data->repeat = res; in repeat_store()
234 if (data->repeat == -1) in repeat_store()
235 data->is_indefinite = true; in repeat_store()
237 data->is_indefinite = false; in repeat_store()
241 mutex_unlock(&data->lock); in repeat_store()
247 static ssize_t pattern_trig_show_patterns(struct pattern_trig_data *data, in pattern_trig_show_patterns() argument
253 mutex_lock(&data->lock); in pattern_trig_show_patterns()
255 if (!data->npatterns || data->type != type) in pattern_trig_show_patterns()
258 for (i = 0; i < data->npatterns; i++) { in pattern_trig_show_patterns()
261 data->patterns[i].brightness, in pattern_trig_show_patterns()
262 data->patterns[i].delta_t); in pattern_trig_show_patterns()
268 mutex_unlock(&data->lock); in pattern_trig_show_patterns()
272 static int pattern_trig_store_patterns_string(struct pattern_trig_data *data, in pattern_trig_store_patterns_string() argument
277 while (offset < count - 1 && data->npatterns < MAX_PATTERNS) { in pattern_trig_store_patterns_string()
280 &data->patterns[data->npatterns].brightness, in pattern_trig_store_patterns_string()
281 &data->patterns[data->npatterns].delta_t, &cr); in pattern_trig_store_patterns_string()
284 data->patterns[data->npatterns].brightness > data->led_cdev->max_brightness) { in pattern_trig_store_patterns_string()
285 data->npatterns = 0; in pattern_trig_store_patterns_string()
290 data->npatterns++; in pattern_trig_store_patterns_string()
296 static int pattern_trig_store_patterns_int(struct pattern_trig_data *data, in pattern_trig_store_patterns_int() argument
302 data->patterns[data->npatterns].brightness = buf[i]; in pattern_trig_store_patterns_int()
303 data->patterns[data->npatterns].delta_t = buf[i + 1]; in pattern_trig_store_patterns_int()
304 data->npatterns++; in pattern_trig_store_patterns_int()
314 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_trig_store_patterns() local
317 mutex_lock(&data->lock); in pattern_trig_store_patterns()
319 pattern_trig_timer_cancel(data); in pattern_trig_store_patterns()
321 if (data->type == PATTERN_TYPE_HW) in pattern_trig_store_patterns()
324 data->type = type; in pattern_trig_store_patterns()
325 data->npatterns = 0; in pattern_trig_store_patterns()
328 err = pattern_trig_store_patterns_string(data, buf, count); in pattern_trig_store_patterns()
330 err = pattern_trig_store_patterns_int(data, buf_int, count); in pattern_trig_store_patterns()
336 data->npatterns = 0; in pattern_trig_store_patterns()
339 mutex_unlock(&data->lock); in pattern_trig_store_patterns()
347 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_show() local
349 return pattern_trig_show_patterns(data, buf, PATTERN_TYPE_SW); in pattern_show()
367 struct pattern_trig_data *data = led_cdev->trigger_data; in hw_pattern_show() local
369 return pattern_trig_show_patterns(data, buf, PATTERN_TYPE_HW); in hw_pattern_show()
388 struct pattern_trig_data *data = led_cdev->trigger_data; in hr_pattern_show() local
390 return pattern_trig_show_patterns(data, buf, PATTERN_TYPE_HR); in hr_pattern_show()
466 struct pattern_trig_data *data; in pattern_trig_activate() local
468 data = kzalloc(sizeof(*data), GFP_KERNEL); in pattern_trig_activate()
469 if (!data) in pattern_trig_activate()
479 data->type = PATTERN_TYPE_SW; in pattern_trig_activate()
480 data->is_indefinite = true; in pattern_trig_activate()
481 data->last_repeat = -1; in pattern_trig_activate()
482 mutex_init(&data->lock); in pattern_trig_activate()
483 data->led_cdev = led_cdev; in pattern_trig_activate()
484 led_set_trigger_data(led_cdev, data); in pattern_trig_activate()
485 timer_setup(&data->timer, pattern_trig_timer_function, 0); in pattern_trig_activate()
486 hrtimer_init(&data->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in pattern_trig_activate()
487 data->hrtimer.function = pattern_trig_hrtimer_function; in pattern_trig_activate()
504 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_trig_deactivate() local
512 timer_shutdown_sync(&data->timer); in pattern_trig_deactivate()
513 hrtimer_cancel(&data->hrtimer); in pattern_trig_deactivate()
516 kfree(data); in pattern_trig_deactivate()