Lines Matching defs:pidff

232 static void pidff_set_envelope_report(struct pidff_device *pidff,
235 pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] =
236 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
238 pidff->set_envelope[PID_ATTACK_LEVEL].value[0] =
241 pidff->set_envelope[PID_ATTACK_LEVEL].field);
242 pidff->set_envelope[PID_FADE_LEVEL].value[0] =
245 pidff->set_envelope[PID_FADE_LEVEL].field);
247 pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
248 pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
250 hid_dbg(pidff->hid, "attack %u => %d\n",
252 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
254 hid_hw_request(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
273 static void pidff_set_constant_force_report(struct pidff_device *pidff,
276 pidff->set_constant[PID_EFFECT_BLOCK_INDEX].value[0] =
277 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
278 pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE],
281 hid_hw_request(pidff->hid, pidff->reports[PID_SET_CONSTANT],
297 static void pidff_set_effect_report(struct pidff_device *pidff,
300 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
301 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
302 pidff->set_effect_type->value[0] =
303 pidff->create_new_effect_type->value[0];
304 pidff->set_effect[PID_DURATION].value[0] = effect->replay.length;
305 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button;
306 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] =
308 pidff->set_effect[PID_GAIN].value[0] =
309 pidff->set_effect[PID_GAIN].field->logical_maximum;
310 pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
311 pidff->effect_direction->value[0] =
313 pidff->effect_direction);
314 pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay;
316 hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT],
336 static void pidff_set_periodic_report(struct pidff_device *pidff,
339 pidff->set_periodic[PID_EFFECT_BLOCK_INDEX].value[0] =
340 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
341 pidff_set_signed(&pidff->set_periodic[PID_MAGNITUDE],
343 pidff_set_signed(&pidff->set_periodic[PID_OFFSET],
345 pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
346 pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
348 hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC],
368 static void pidff_set_condition_report(struct pidff_device *pidff,
373 pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] =
374 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
377 pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i;
378 pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET],
380 pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT],
382 pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT],
384 pidff_set(&pidff->set_condition[PID_POS_SATURATION],
386 pidff_set(&pidff->set_condition[PID_NEG_SATURATION],
388 pidff_set(&pidff->set_condition[PID_DEAD_BAND],
390 hid_hw_request(pidff->hid, pidff->reports[PID_SET_CONDITION],
422 static void pidff_set_ramp_force_report(struct pidff_device *pidff,
425 pidff->set_ramp[PID_EFFECT_BLOCK_INDEX].value[0] =
426 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
427 pidff_set_signed(&pidff->set_ramp[PID_RAMP_START],
429 pidff_set_signed(&pidff->set_ramp[PID_RAMP_END],
431 hid_hw_request(pidff->hid, pidff->reports[PID_SET_RAMP],
451 static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
455 pidff->create_new_effect_type->value[0] = efnum;
456 hid_hw_request(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
458 hid_dbg(pidff->hid, "create_new_effect sent, type: %d\n", efnum);
460 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
461 pidff->block_load_status->value[0] = 0;
462 hid_hw_wait(pidff->hid);
465 hid_dbg(pidff->hid, "pid_block_load requested\n");
466 hid_hw_request(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
468 hid_hw_wait(pidff->hid);
469 if (pidff->block_load_status->value[0] ==
470 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
471 hid_dbg(pidff->hid, "device reported free memory: %d bytes\n",
472 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
473 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
476 if (pidff->block_load_status->value[0] ==
477 pidff->status_id[PID_BLOCK_LOAD_FULL]) {
478 hid_dbg(pidff->hid, "not enough memory free: %d bytes\n",
479 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
480 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
484 hid_err(pidff->hid, "pid_block_load failed 60 times\n");
491 static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
493 pidff->effect_operation[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
496 pidff->effect_operation_status->value[0] =
497 pidff->operation_id[PID_EFFECT_STOP];
499 pidff->effect_operation_status->value[0] =
500 pidff->operation_id[PID_EFFECT_START];
501 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
504 hid_hw_request(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
513 struct pidff_device *pidff = dev->ff->private;
515 pidff_playback_pid(pidff, pidff->pid_id[effect_id], value);
523 static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
525 pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
526 hid_hw_request(pidff->hid, pidff->reports[PID_BLOCK_FREE],
535 struct pidff_device *pidff = dev->ff->private;
536 int pid_id = pidff->pid_id[effect_id];
538 hid_dbg(pidff->hid, "starting to erase %d/%d\n",
539 effect_id, pidff->pid_id[effect_id]);
542 hid_hw_wait(pidff->hid);
543 pidff_playback_pid(pidff, pid_id, 0);
544 pidff_erase_pid(pidff, pid_id);
555 struct pidff_device *pidff = dev->ff->private;
559 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
561 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] =
562 pidff->pid_id[effect->id];
568 error = pidff_request_effect_upload(pidff,
569 pidff->type_id[PID_CONSTANT]);
574 pidff_set_effect_report(pidff, effect);
576 pidff_set_constant_force_report(pidff, effect);
580 pidff_set_envelope_report(pidff,
603 hid_err(pidff->hid, "invalid waveform\n");
607 error = pidff_request_effect_upload(pidff,
608 pidff->type_id[type_id]);
613 pidff_set_effect_report(pidff, effect);
615 pidff_set_periodic_report(pidff, effect);
619 pidff_set_envelope_report(pidff,
625 error = pidff_request_effect_upload(pidff,
626 pidff->type_id[PID_RAMP]);
631 pidff_set_effect_report(pidff, effect);
633 pidff_set_ramp_force_report(pidff, effect);
637 pidff_set_envelope_report(pidff,
643 error = pidff_request_effect_upload(pidff,
644 pidff->type_id[PID_SPRING]);
649 pidff_set_effect_report(pidff, effect);
651 pidff_set_condition_report(pidff, effect);
656 error = pidff_request_effect_upload(pidff,
657 pidff->type_id[PID_FRICTION]);
662 pidff_set_effect_report(pidff, effect);
664 pidff_set_condition_report(pidff, effect);
669 error = pidff_request_effect_upload(pidff,
670 pidff->type_id[PID_DAMPER]);
675 pidff_set_effect_report(pidff, effect);
677 pidff_set_condition_report(pidff, effect);
682 error = pidff_request_effect_upload(pidff,
683 pidff->type_id[PID_INERTIA]);
688 pidff_set_effect_report(pidff, effect);
690 pidff_set_condition_report(pidff, effect);
694 hid_err(pidff->hid, "invalid type\n");
699 pidff->pid_id[effect->id] =
700 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
702 hid_dbg(pidff->hid, "uploaded\n");
712 struct pidff_device *pidff = dev->ff->private;
714 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
715 hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
719 static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
722 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field;
725 pidff_playback_pid(pidff, field->logical_minimum, 0);
729 pidff_playback_pid(pidff, field->logical_minimum, 1);
731 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
732 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum;
733 pidff->set_effect_type->value[0] = pidff->type_id[PID_SPRING];
734 pidff->set_effect[PID_DURATION].value[0] = 0;
735 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0;
736 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0;
737 pidff_set(&pidff->set_effect[PID_GAIN], magnitude);
738 pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
739 pidff->set_effect[PID_START_DELAY].value[0] = 0;
741 hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT],
750 struct pidff_device *pidff = dev->ff->private;
752 pidff_autocenter(pidff, magnitude);
809 * Find the reports and fill pidff->reports[]
813 struct pidff_device *pidff)
826 pidff->reports[ret] = report;
842 if (ret != -1 && !pidff->reports[ret]) {
846 pidff->reports[ret] = report;
854 static int pidff_reports_ok(struct pidff_device *pidff)
859 if (!pidff->reports[i]) {
860 hid_dbg(pidff->hid, "%d missing\n", i);
892 * Fill a pidff->*_id struct table
914 pidff_find_special_keys(pidff->keys, pidff->field, pidff_ ## name, \
920 static int pidff_find_special_fields(struct pidff_device *pidff)
922 hid_dbg(pidff->hid, "finding special fields\n");
924 pidff->create_new_effect_type =
925 pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT],
927 pidff->set_effect_type =
928 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
930 pidff->effect_direction =
931 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
933 pidff->device_control =
934 pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL],
936 pidff->block_load_status =
937 pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD],
939 pidff->effect_operation_status =
940 pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION],
943 hid_dbg(pidff->hid, "search done\n");
945 if (!pidff->create_new_effect_type || !pidff->set_effect_type) {
946 hid_err(pidff->hid, "effect lists not found\n");
950 if (!pidff->effect_direction) {
951 hid_err(pidff->hid, "direction field not found\n");
955 if (!pidff->device_control) {
956 hid_err(pidff->hid, "device control field not found\n");
960 if (!pidff->block_load_status) {
961 hid_err(pidff->hid, "block load status field not found\n");
965 if (!pidff->effect_operation_status) {
966 hid_err(pidff->hid, "effect operation field not found\n");
970 pidff_find_special_keys(pidff->control_id, pidff->device_control,
978 hid_err(pidff->hid, "no effect types found\n");
985 hid_err(pidff->hid,
993 hid_err(pidff->hid, "effect operation identifiers not found\n");
1003 static int pidff_find_effects(struct pidff_device *pidff,
1009 int pidff_type = pidff->type_id[i];
1010 if (pidff->set_effect_type->usage[pidff_type].hid !=
1011 pidff->create_new_effect_type->usage[pidff_type].hid) {
1012 hid_err(pidff->hid,
1018 if (pidff->type_id[PID_CONSTANT])
1020 if (pidff->type_id[PID_RAMP])
1022 if (pidff->type_id[PID_SQUARE]) {
1026 if (pidff->type_id[PID_SINE]) {
1030 if (pidff->type_id[PID_TRIANGLE]) {
1034 if (pidff->type_id[PID_SAW_UP]) {
1038 if (pidff->type_id[PID_SAW_DOWN]) {
1042 if (pidff->type_id[PID_SPRING])
1044 if (pidff->type_id[PID_DAMPER])
1046 if (pidff->type_id[PID_INERTIA])
1048 if (pidff->type_id[PID_FRICTION])
1056 pidff_find_fields(pidff->name, pidff_ ## name, \
1057 pidff->reports[report], \
1063 static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1068 hid_err(pidff->hid, "unknown set_effect report layout\n");
1073 if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
1074 hid_err(pidff->hid, "unknown pid_block_load report layout\n");
1079 hid_err(pidff->hid, "unknown effect_operation report layout\n");
1084 hid_err(pidff->hid, "unknown pid_block_free report layout\n");
1091 if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev))
1096 hid_warn(pidff->hid,
1099 hid_warn(pidff->hid,
1103 hid_warn(pidff->hid,
1109 hid_warn(pidff->hid, "unknown constant effect layout\n");
1115 hid_warn(pidff->hid, "unknown ramp effect layout\n");
1124 hid_warn(pidff->hid, "unknown condition effect layout\n");
1133 hid_warn(pidff->hid, "unknown periodic effect layout\n");
1148 static void pidff_reset(struct pidff_device *pidff)
1150 struct hid_device *hid = pidff->hid;
1153 pidff->device_control->value[0] = pidff->control_id[PID_RESET];
1155 hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT);
1157 hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT);
1160 pidff->device_control->value[0] =
1161 pidff->control_id[PID_ENABLE_ACTUATORS];
1162 hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT);
1166 hid_hw_request(hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT);
1169 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
1170 while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
1172 hid_warn(pidff->hid,
1174 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1177 hid_dbg(pidff->hid, "pid_pool requested again\n");
1178 hid_hw_request(hid, pidff->reports[PID_POOL],
1188 static int pidff_check_autocenter(struct pidff_device *pidff,
1201 error = pidff_request_effect_upload(pidff, 1);
1203 hid_err(pidff->hid, "upload request failed\n");
1207 if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] ==
1208 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) {
1209 pidff_autocenter(pidff, 0xffff);
1212 hid_notice(pidff->hid,
1216 pidff_erase_pid(pidff,
1217 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]);
1228 struct pidff_device *pidff;
1243 pidff = kzalloc(sizeof(*pidff), GFP_KERNEL);
1244 if (!pidff)
1247 pidff->hid = hid;
1251 pidff_find_reports(hid, HID_OUTPUT_REPORT, pidff);
1252 pidff_find_reports(hid, HID_FEATURE_REPORT, pidff);
1254 if (!pidff_reports_ok(pidff)) {
1260 error = pidff_init_fields(pidff, dev);
1264 pidff_reset(pidff);
1267 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1268 hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN],
1272 error = pidff_check_autocenter(pidff, dev);
1277 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum -
1278 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum +
1285 if (pidff->pool[PID_SIMULTANEOUS_MAX].value)
1287 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1289 if (pidff->pool[PID_RAM_POOL_SIZE].value)
1291 pidff->pool[PID_RAM_POOL_SIZE].value[0]);
1293 if (pidff->pool[PID_DEVICE_MANAGED_POOL].value &&
1294 pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) {
1306 ff->private = pidff;
1322 kfree(pidff);