Lines Matching full:haptic
3 * HID Haptic support for Linux
11 #include "hid-haptic.h"
14 struct hid_haptic_device *haptic, in hid_haptic_feature_mapping() argument
30 haptic->default_auto_trigger = in hid_haptic_feature_mapping()
32 haptic->auto_trigger_report = field->report; in hid_haptic_feature_mapping()
37 if (usage_hid > haptic->max_waveform_id) in hid_haptic_feature_mapping()
38 haptic->max_waveform_id = usage_hid; in hid_haptic_feature_mapping()
41 if (usage_hid > haptic->max_duration_id) in hid_haptic_feature_mapping()
42 haptic->max_duration_id = usage_hid; in hid_haptic_feature_mapping()
51 bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic, in hid_haptic_check_pressure_unit() argument
55 haptic->force_logical_minimum = field->logical_minimum; in hid_haptic_check_pressure_unit()
56 haptic->force_physical_minimum = field->physical_minimum; in hid_haptic_check_pressure_unit()
57 haptic->force_resolution = input_abs_get_res(hi->input, in hid_haptic_check_pressure_unit()
66 struct hid_haptic_device *haptic, in hid_haptic_input_mapping() argument
72 haptic->manual_trigger_report = field->report; in hid_haptic_input_mapping()
82 struct hid_haptic_device *haptic, in hid_haptic_input_configured() argument
87 if (haptic->auto_trigger_report && in hid_haptic_input_configured()
88 haptic->manual_trigger_report) { in hid_haptic_input_configured()
98 static void parse_auto_trigger_field(struct hid_haptic_device *haptic, in parse_auto_trigger_field() argument
111 haptic->hid_usage_map[usage_hid] = field->value[n]; in parse_auto_trigger_field()
114 haptic->press_ordinal = usage_hid; in parse_auto_trigger_field()
117 haptic->release_ordinal = usage_hid; in parse_auto_trigger_field()
121 haptic->duration_map[usage_hid] = in parse_auto_trigger_field()
131 haptic->vendor_id = field->value[n]; in parse_auto_trigger_field()
134 haptic->vendor_page = field->value[n]; in parse_auto_trigger_field()
147 static void fill_effect_buf(struct hid_haptic_device *haptic, in fill_effect_buf() argument
152 struct hid_report *rep = haptic->manual_trigger_report; in fill_effect_buf()
159 mutex_lock(&haptic->manual_trigger_mutex); in fill_effect_buf()
198 mutex_unlock(&haptic->manual_trigger_mutex); in fill_effect_buf()
201 static void switch_mode(struct hid_device *hdev, struct hid_haptic_device *haptic, in switch_mode() argument
204 struct hid_report *rep = haptic->auto_trigger_report; in switch_mode()
212 value = haptic->default_auto_trigger; in switch_mode()
214 mutex_lock(&haptic->auto_trigger_mutex); in switch_mode()
229 mutex_unlock(&haptic->auto_trigger_mutex); in switch_mode()
230 haptic->mode = mode; in switch_mode()
238 struct hid_haptic_device *haptic = ff->private; in hid_haptic_upload_effect() local
243 if (effect->u.haptic.hid_usage >= (HID_HP_VENDORWAVEFORMMIN & HID_USAGE) && in hid_haptic_upload_effect()
244 effect->u.haptic.hid_usage <= (HID_HP_VENDORWAVEFORMMAX & HID_USAGE) && in hid_haptic_upload_effect()
245 (effect->u.haptic.vendor_id != haptic->vendor_id || in hid_haptic_upload_effect()
246 effect->u.haptic.vendor_waveform_page != haptic->vendor_page)) in hid_haptic_upload_effect()
250 for (i = 1; i <= haptic->max_waveform_id; i++) { in hid_haptic_upload_effect()
251 if (haptic->hid_usage_map[i] == effect->u.haptic.hid_usage) { in hid_haptic_upload_effect()
260 fill_effect_buf(haptic, &effect->u.haptic, &haptic->effect[effect->id], in hid_haptic_upload_effect()
263 if (effect->u.haptic.hid_usage == (HID_HP_WAVEFORMPRESS & HID_USAGE) || in hid_haptic_upload_effect()
264 effect->u.haptic.hid_usage == (HID_HP_WAVEFORMRELEASE & HID_USAGE)) in hid_haptic_upload_effect()
270 if (switch_modes && haptic->mode == HID_HAPTIC_MODE_DEVICE) in hid_haptic_upload_effect()
271 switch_mode(hdev, haptic, HID_HAPTIC_MODE_HOST); in hid_haptic_upload_effect()
276 static int play_effect(struct hid_device *hdev, struct hid_haptic_device *haptic, in play_effect() argument
282 haptic->manual_trigger_report_len); in play_effect()
285 haptic->manual_trigger_report->id, in play_effect()
287 haptic->manual_trigger_report_len, in play_effect()
302 struct hid_haptic_device *haptic = dev->ff->private; in haptic_work_handler() local
304 mutex_lock(&haptic->manual_trigger_mutex); in haptic_work_handler()
305 if (effect != &haptic->stop_effect) in haptic_work_handler()
306 play_effect(hdev, haptic, &haptic->stop_effect); in haptic_work_handler()
308 play_effect(hdev, haptic, effect); in haptic_work_handler()
309 mutex_unlock(&haptic->manual_trigger_mutex); in haptic_work_handler()
315 struct hid_haptic_device *haptic = dev->ff->private; in hid_haptic_playback() local
318 queue_work(haptic->wq, &haptic->effect[effect_id].work); in hid_haptic_playback()
320 queue_work(haptic->wq, &haptic->stop_effect.work); in hid_haptic_playback()
329 effect->u.haptic.hid_usage = HID_HP_WAVEFORMNONE & HID_USAGE; in effect_set_default()
330 effect->u.haptic.intensity = 100; in effect_set_default()
331 effect->u.haptic.retrigger_period = 0; in effect_set_default()
332 effect->u.haptic.repeat_count = 0; in effect_set_default()
337 struct hid_haptic_device *haptic = dev->ff->private; in hid_haptic_erase() local
344 if (effect.u.haptic.hid_usage == (HID_HP_WAVEFORMRELEASE & HID_USAGE)) { in hid_haptic_erase()
345 ordinal = haptic->release_ordinal; in hid_haptic_erase()
348 if (haptic->mode == HID_HAPTIC_MODE_HOST) in hid_haptic_erase()
349 switch_mode(hdev, haptic, HID_HAPTIC_MODE_DEVICE); in hid_haptic_erase()
351 effect.u.haptic.hid_usage = HID_HP_WAVEFORMRELEASE & HID_USAGE; in hid_haptic_erase()
353 fill_effect_buf(haptic, &effect.u.haptic, &haptic->effect[effect_id], in hid_haptic_erase()
355 } else if (effect.u.haptic.hid_usage == (HID_HP_WAVEFORMPRESS & HID_USAGE)) { in hid_haptic_erase()
356 ordinal = haptic->press_ordinal; in hid_haptic_erase()
359 if (haptic->mode == HID_HAPTIC_MODE_HOST) in hid_haptic_erase()
360 switch_mode(hdev, haptic, HID_HAPTIC_MODE_DEVICE); in hid_haptic_erase()
363 effect.u.haptic.hid_usage = HID_HP_WAVEFORMPRESS & HID_USAGE; in hid_haptic_erase()
365 fill_effect_buf(haptic, &effect.u.haptic, &haptic->effect[effect_id], in hid_haptic_erase()
374 struct hid_haptic_device *haptic = ff->private; in hid_haptic_destroy() local
375 struct hid_device *hdev = haptic->hdev; in hid_haptic_destroy()
381 kfree(haptic->stop_effect.report_buf); in hid_haptic_destroy()
382 haptic->stop_effect.report_buf = NULL; in hid_haptic_destroy()
384 if (haptic->effect) { in hid_haptic_destroy()
386 kfree(haptic->effect[r].report_buf); in hid_haptic_destroy()
387 kfree(haptic->effect); in hid_haptic_destroy()
389 haptic->effect = NULL; in hid_haptic_destroy()
391 destroy_workqueue(haptic->wq); in hid_haptic_destroy()
392 haptic->wq = NULL; in hid_haptic_destroy()
394 kfree(haptic->duration_map); in hid_haptic_destroy()
395 haptic->duration_map = NULL; in hid_haptic_destroy()
397 kfree(haptic->hid_usage_map); in hid_haptic_destroy()
398 haptic->hid_usage_map = NULL; in hid_haptic_destroy()
406 struct hid_haptic_device *haptic = *haptic_ptr; in hid_haptic_init() local
414 const char *prefix = "hid-haptic"; in hid_haptic_init()
419 haptic->hdev = hdev; in hid_haptic_init()
420 haptic->max_waveform_id = max(2u, haptic->max_waveform_id); in hid_haptic_init()
421 haptic->max_duration_id = max(2u, haptic->max_duration_id); in hid_haptic_init()
423 haptic->hid_usage_map = kcalloc(haptic->max_waveform_id + 1, in hid_haptic_init()
425 if (!haptic->hid_usage_map) { in hid_haptic_init()
429 haptic->duration_map = kcalloc(haptic->max_duration_id + 1, in hid_haptic_init()
431 if (!haptic->duration_map) { in hid_haptic_init()
436 if (haptic->max_waveform_id != haptic->max_duration_id) in hid_haptic_init()
438 "Haptic duration and waveform lists have different max id (%u and %u).\n", in hid_haptic_init()
439 haptic->max_duration_id, haptic->max_waveform_id); in hid_haptic_init()
441 haptic->hid_usage_map[HID_HAPTIC_ORDINAL_WAVEFORMNONE] = in hid_haptic_init()
443 haptic->hid_usage_map[HID_HAPTIC_ORDINAL_WAVEFORMSTOP] = in hid_haptic_init()
446 mutex_init(&haptic->auto_trigger_mutex); in hid_haptic_init()
447 for (r = 0; r < haptic->auto_trigger_report->maxfield; r++) in hid_haptic_init()
448 parse_auto_trigger_field(haptic, haptic->auto_trigger_report->field[r]); in hid_haptic_init()
463 haptic->input_dev = dev; in hid_haptic_init()
464 haptic->manual_trigger_report_len = in hid_haptic_init()
465 hid_report_len(haptic->manual_trigger_report); in hid_haptic_init()
466 mutex_init(&haptic->manual_trigger_mutex); in hid_haptic_init()
470 haptic->wq = create_singlethread_workqueue(name); in hid_haptic_init()
473 if (!haptic->wq) { in hid_haptic_init()
477 haptic->effect = kzalloc_objs(struct hid_haptic_effect, FF_MAX_EFFECTS); in hid_haptic_init()
478 if (!haptic->effect) { in hid_haptic_init()
483 haptic->effect[r].report_buf = in hid_haptic_init()
484 hid_alloc_report_buf(haptic->manual_trigger_report, in hid_haptic_init()
486 if (!haptic->effect[r].report_buf) { in hid_haptic_init()
492 haptic->effect[r].input_dev = dev; in hid_haptic_init()
493 INIT_WORK(&haptic->effect[r].work, haptic_work_handler); in hid_haptic_init()
495 haptic->stop_effect.report_buf = in hid_haptic_init()
496 hid_alloc_report_buf(haptic->manual_trigger_report, in hid_haptic_init()
498 if (!haptic->stop_effect.report_buf) { in hid_haptic_init()
504 haptic->stop_effect.input_dev = dev; in hid_haptic_init()
505 INIT_WORK(&haptic->stop_effect.work, haptic_work_handler); in hid_haptic_init()
506 fill_effect_buf(haptic, &stop_effect, &haptic->stop_effect, in hid_haptic_init()
520 ff->private = haptic; in hid_haptic_init()
547 kfree(haptic->stop_effect.report_buf); in hid_haptic_init()
548 haptic->stop_effect.report_buf = NULL; in hid_haptic_init()
551 kfree(haptic->effect[r].report_buf); in hid_haptic_init()
552 kfree(haptic->effect); in hid_haptic_init()
553 haptic->effect = NULL; in hid_haptic_init()
555 destroy_workqueue(haptic->wq); in hid_haptic_init()
556 haptic->wq = NULL; in hid_haptic_init()
558 kfree(haptic->duration_map); in hid_haptic_init()
559 haptic->duration_map = NULL; in hid_haptic_init()
561 kfree(haptic->hid_usage_map); in hid_haptic_init()
562 haptic->hid_usage_map = NULL; in hid_haptic_init()
568 void hid_haptic_pressure_reset(struct hid_haptic_device *haptic) in hid_haptic_pressure_reset() argument
570 haptic->pressure_sum = 0; in hid_haptic_pressure_reset()
574 void hid_haptic_pressure_increase(struct hid_haptic_device *haptic, in hid_haptic_pressure_increase() argument
577 haptic->pressure_sum += pressure; in hid_haptic_pressure_increase()