Lines Matching refs:data
39 static void pattern_trig_update_patterns(struct pattern_trig_data *data) in pattern_trig_update_patterns() argument
41 data->curr = data->next; in pattern_trig_update_patterns()
42 if (!data->is_indefinite && data->curr == data->patterns) in pattern_trig_update_patterns()
43 data->repeat--; in pattern_trig_update_patterns()
45 if (data->next == data->patterns + data->npatterns - 1) in pattern_trig_update_patterns()
46 data->next = data->patterns; in pattern_trig_update_patterns()
48 data->next++; in pattern_trig_update_patterns()
50 data->delta_t = 0; in pattern_trig_update_patterns()
53 static int pattern_trig_compute_brightness(struct pattern_trig_data *data) in pattern_trig_compute_brightness() argument
62 if (data->delta_t == 0 || data->curr->delta_t < UPDATE_INTERVAL) in pattern_trig_compute_brightness()
63 return data->curr->brightness; in pattern_trig_compute_brightness()
65 step_brightness = abs(data->next->brightness - data->curr->brightness); in pattern_trig_compute_brightness()
66 step_brightness = data->delta_t * step_brightness / data->curr->delta_t; in pattern_trig_compute_brightness()
68 if (data->next->brightness > data->curr->brightness) in pattern_trig_compute_brightness()
69 return data->curr->brightness + step_brightness; in pattern_trig_compute_brightness()
71 return data->curr->brightness - step_brightness; in pattern_trig_compute_brightness()
76 struct pattern_trig_data *data = from_timer(data, t, timer); in pattern_trig_timer_function() local
79 if (!data->is_indefinite && !data->repeat) in pattern_trig_timer_function()
82 if (data->curr->brightness == data->next->brightness) { in pattern_trig_timer_function()
84 led_set_brightness(data->led_cdev, in pattern_trig_timer_function()
85 data->curr->brightness); in pattern_trig_timer_function()
86 mod_timer(&data->timer, in pattern_trig_timer_function()
87 jiffies + msecs_to_jiffies(data->curr->delta_t)); in pattern_trig_timer_function()
88 if (!data->next->delta_t) { in pattern_trig_timer_function()
90 pattern_trig_update_patterns(data); in pattern_trig_timer_function()
93 pattern_trig_update_patterns(data); in pattern_trig_timer_function()
102 if (data->delta_t > data->curr->delta_t) { in pattern_trig_timer_function()
103 pattern_trig_update_patterns(data); in pattern_trig_timer_function()
107 led_set_brightness(data->led_cdev, in pattern_trig_timer_function()
108 pattern_trig_compute_brightness(data)); in pattern_trig_timer_function()
109 mod_timer(&data->timer, in pattern_trig_timer_function()
113 data->delta_t += UPDATE_INTERVAL; in pattern_trig_timer_function()
122 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_trig_start_pattern() local
124 if (!data->npatterns) in pattern_trig_start_pattern()
127 if (data->is_hw_pattern) { in pattern_trig_start_pattern()
128 return led_cdev->pattern_set(led_cdev, data->patterns, in pattern_trig_start_pattern()
129 data->npatterns, data->repeat); in pattern_trig_start_pattern()
133 if (data->npatterns < 2) in pattern_trig_start_pattern()
136 data->delta_t = 0; in pattern_trig_start_pattern()
137 data->curr = data->patterns; in pattern_trig_start_pattern()
138 data->next = data->patterns + 1; in pattern_trig_start_pattern()
139 data->timer.expires = jiffies; in pattern_trig_start_pattern()
140 add_timer(&data->timer); in pattern_trig_start_pattern()
149 struct pattern_trig_data *data = led_cdev->trigger_data; in repeat_show() local
152 mutex_lock(&data->lock); in repeat_show()
154 repeat = data->last_repeat; in repeat_show()
156 mutex_unlock(&data->lock); in repeat_show()
165 struct pattern_trig_data *data = led_cdev->trigger_data; in repeat_store() local
176 mutex_lock(&data->lock); in repeat_store()
178 del_timer_sync(&data->timer); in repeat_store()
180 if (data->is_hw_pattern) in repeat_store()
183 data->last_repeat = data->repeat = res; in repeat_store()
185 if (data->repeat == -1) in repeat_store()
186 data->is_indefinite = true; in repeat_store()
188 data->is_indefinite = false; in repeat_store()
192 mutex_unlock(&data->lock); in repeat_store()
198 static ssize_t pattern_trig_show_patterns(struct pattern_trig_data *data, in pattern_trig_show_patterns() argument
204 mutex_lock(&data->lock); in pattern_trig_show_patterns()
206 if (!data->npatterns || (data->is_hw_pattern ^ hw_pattern)) in pattern_trig_show_patterns()
209 for (i = 0; i < data->npatterns; i++) { in pattern_trig_show_patterns()
212 data->patterns[i].brightness, in pattern_trig_show_patterns()
213 data->patterns[i].delta_t); in pattern_trig_show_patterns()
219 mutex_unlock(&data->lock); in pattern_trig_show_patterns()
223 static int pattern_trig_store_patterns_string(struct pattern_trig_data *data, in pattern_trig_store_patterns_string() argument
228 while (offset < count - 1 && data->npatterns < MAX_PATTERNS) { in pattern_trig_store_patterns_string()
231 &data->patterns[data->npatterns].brightness, in pattern_trig_store_patterns_string()
232 &data->patterns[data->npatterns].delta_t, &cr); in pattern_trig_store_patterns_string()
235 data->patterns[data->npatterns].brightness > data->led_cdev->max_brightness) { in pattern_trig_store_patterns_string()
236 data->npatterns = 0; in pattern_trig_store_patterns_string()
241 data->npatterns++; in pattern_trig_store_patterns_string()
247 static int pattern_trig_store_patterns_int(struct pattern_trig_data *data, in pattern_trig_store_patterns_int() argument
253 data->patterns[data->npatterns].brightness = buf[i]; in pattern_trig_store_patterns_int()
254 data->patterns[data->npatterns].delta_t = buf[i + 1]; in pattern_trig_store_patterns_int()
255 data->npatterns++; in pattern_trig_store_patterns_int()
265 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_trig_store_patterns() local
268 mutex_lock(&data->lock); in pattern_trig_store_patterns()
270 del_timer_sync(&data->timer); in pattern_trig_store_patterns()
272 if (data->is_hw_pattern) in pattern_trig_store_patterns()
275 data->is_hw_pattern = hw_pattern; in pattern_trig_store_patterns()
276 data->npatterns = 0; in pattern_trig_store_patterns()
279 err = pattern_trig_store_patterns_string(data, buf, count); in pattern_trig_store_patterns()
281 err = pattern_trig_store_patterns_int(data, buf_int, count); in pattern_trig_store_patterns()
287 data->npatterns = 0; in pattern_trig_store_patterns()
290 mutex_unlock(&data->lock); in pattern_trig_store_patterns()
298 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_show() local
300 return pattern_trig_show_patterns(data, buf, false); in pattern_show()
317 struct pattern_trig_data *data = led_cdev->trigger_data; in hw_pattern_show() local
319 return pattern_trig_show_patterns(data, buf, true); in hw_pattern_show()
390 struct pattern_trig_data *data; in pattern_trig_activate() local
392 data = kzalloc(sizeof(*data), GFP_KERNEL); in pattern_trig_activate()
393 if (!data) in pattern_trig_activate()
403 data->is_indefinite = true; in pattern_trig_activate()
404 data->last_repeat = -1; in pattern_trig_activate()
405 mutex_init(&data->lock); in pattern_trig_activate()
406 data->led_cdev = led_cdev; in pattern_trig_activate()
407 led_set_trigger_data(led_cdev, data); in pattern_trig_activate()
408 timer_setup(&data->timer, pattern_trig_timer_function, 0); in pattern_trig_activate()
425 struct pattern_trig_data *data = led_cdev->trigger_data; in pattern_trig_deactivate() local
433 timer_shutdown_sync(&data->timer); in pattern_trig_deactivate()
436 kfree(data); in pattern_trig_deactivate()