Lines Matching defs:pidff
25 #define debug(format, arg...) pr_debug("hid-pidff: " format "\n" , ## arg)
244 static void pidff_set_envelope_report(struct pidff_device *pidff,
247 pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] =
248 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
250 pidff->set_envelope[PID_ATTACK_LEVEL].value[0] =
253 pidff->set_envelope[PID_ATTACK_LEVEL].field);
254 pidff->set_envelope[PID_FADE_LEVEL].value[0] =
257 pidff->set_envelope[PID_FADE_LEVEL].field);
259 pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
260 pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
263 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
265 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
284 static void pidff_set_constant_force_report(struct pidff_device *pidff,
287 pidff->set_constant[PID_EFFECT_BLOCK_INDEX].value[0] =
288 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
289 pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE],
292 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONSTANT],
308 static void pidff_set_effect_report(struct pidff_device *pidff,
311 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
312 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
313 pidff->set_effect_type->value[0] =
314 pidff->create_new_effect_type->value[0];
315 pidff->set_effect[PID_DURATION].value[0] = effect->replay.length;
316 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button;
317 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] =
319 pidff->set_effect[PID_GAIN].value[0] =
320 pidff->set_effect[PID_GAIN].field->logical_maximum;
321 pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
322 pidff->effect_direction->value[0] =
324 pidff->effect_direction);
325 pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay;
327 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
347 static void pidff_set_periodic_report(struct pidff_device *pidff,
350 pidff->set_periodic[PID_EFFECT_BLOCK_INDEX].value[0] =
351 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
352 pidff_set_signed(&pidff->set_periodic[PID_MAGNITUDE],
354 pidff_set_signed(&pidff->set_periodic[PID_OFFSET],
356 pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
357 pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
359 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_PERIODIC],
379 static void pidff_set_condition_report(struct pidff_device *pidff,
384 pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] =
385 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
388 pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i;
389 pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET],
391 pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT],
393 pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT],
395 pidff_set(&pidff->set_condition[PID_POS_SATURATION],
397 pidff_set(&pidff->set_condition[PID_NEG_SATURATION],
399 pidff_set(&pidff->set_condition[PID_DEAD_BAND],
401 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION],
433 static void pidff_set_ramp_force_report(struct pidff_device *pidff,
436 pidff->set_ramp[PID_EFFECT_BLOCK_INDEX].value[0] =
437 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
438 pidff_set_signed(&pidff->set_ramp[PID_RAMP_START],
440 pidff_set_signed(&pidff->set_ramp[PID_RAMP_END],
442 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_RAMP],
462 static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
466 pidff->create_new_effect_type->value[0] = efnum;
467 usbhid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
471 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
472 pidff->block_load_status->value[0] = 0;
473 usbhid_wait_io(pidff->hid);
477 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
479 usbhid_wait_io(pidff->hid);
480 if (pidff->block_load_status->value[0] ==
481 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
483 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
484 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
487 if (pidff->block_load_status->value[0] ==
488 pidff->status_id[PID_BLOCK_LOAD_FULL]) {
490 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
491 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
495 printk(KERN_ERR "hid-pidff: pid_block_load failed 60 times\n");
502 static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
504 pidff->effect_operation[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
507 pidff->effect_operation_status->value[0] =
508 pidff->operation_id[PID_EFFECT_STOP];
510 pidff->effect_operation_status->value[0] =
511 pidff->operation_id[PID_EFFECT_START];
512 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
515 usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
524 struct pidff_device *pidff = dev->ff->private;
526 pidff_playback_pid(pidff, pidff->pid_id[effect_id], value);
534 static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
536 pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
537 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_FREE],
546 struct pidff_device *pidff = dev->ff->private;
547 int pid_id = pidff->pid_id[effect_id];
549 debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]);
552 usbhid_wait_io(pidff->hid);
553 pidff_playback_pid(pidff, pid_id, 0);
554 pidff_erase_pid(pidff, pid_id);
565 struct pidff_device *pidff = dev->ff->private;
572 error = pidff_request_effect_upload(pidff,
573 pidff->type_id[PID_CONSTANT]);
578 pidff_set_effect_report(pidff, effect);
580 pidff_set_constant_force_report(pidff, effect);
584 pidff_set_envelope_report(pidff,
608 "hid-pidff: invalid waveform\n");
612 error = pidff_request_effect_upload(pidff,
613 pidff->type_id[type_id]);
618 pidff_set_effect_report(pidff, effect);
620 pidff_set_periodic_report(pidff, effect);
624 pidff_set_envelope_report(pidff,
630 error = pidff_request_effect_upload(pidff,
631 pidff->type_id[PID_RAMP]);
636 pidff_set_effect_report(pidff, effect);
638 pidff_set_ramp_force_report(pidff, effect);
642 pidff_set_envelope_report(pidff,
648 error = pidff_request_effect_upload(pidff,
649 pidff->type_id[PID_SPRING]);
654 pidff_set_effect_report(pidff, effect);
656 pidff_set_condition_report(pidff, effect);
661 error = pidff_request_effect_upload(pidff,
662 pidff->type_id[PID_FRICTION]);
667 pidff_set_effect_report(pidff, effect);
669 pidff_set_condition_report(pidff, effect);
674 error = pidff_request_effect_upload(pidff,
675 pidff->type_id[PID_DAMPER]);
680 pidff_set_effect_report(pidff, effect);
682 pidff_set_condition_report(pidff, effect);
687 error = pidff_request_effect_upload(pidff,
688 pidff->type_id[PID_INERTIA]);
693 pidff_set_effect_report(pidff, effect);
695 pidff_set_condition_report(pidff, effect);
699 printk(KERN_ERR "hid-pidff: invalid type\n");
704 pidff->pid_id[effect->id] =
705 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
717 struct pidff_device *pidff = dev->ff->private;
719 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
720 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
724 static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
727 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field;
730 pidff_playback_pid(pidff, field->logical_minimum, 0);
734 pidff_playback_pid(pidff, field->logical_minimum, 1);
736 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
737 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum;
738 pidff->set_effect_type->value[0] = pidff->type_id[PID_SPRING];
739 pidff->set_effect[PID_DURATION].value[0] = 0;
740 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0;
741 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0;
742 pidff_set(&pidff->set_effect[PID_GAIN], magnitude);
743 pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
744 pidff->set_effect[PID_START_DELAY].value[0] = 0;
746 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
755 struct pidff_device *pidff = dev->ff->private;
757 pidff_autocenter(pidff, magnitude);
814 * Find the reports and fill pidff->reports[]
818 struct pidff_device *pidff)
831 pidff->reports[ret] = report;
847 if (ret != -1 && !pidff->reports[ret]) {
850 pidff->reports[ret] = report;
858 static int pidff_reports_ok(struct pidff_device *pidff)
863 if (!pidff->reports[i]) {
887 printk(KERN_ERR "hid-pidff: logical_minimum "
897 * Fill a pidff->*_id struct table
919 pidff_find_special_keys(pidff->keys, pidff->field, pidff_ ## name, \
925 static int pidff_find_special_fields(struct pidff_device *pidff)
929 pidff->create_new_effect_type =
930 pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT],
932 pidff->set_effect_type =
933 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
935 pidff->effect_direction =
936 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
938 pidff->device_control =
939 pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL],
941 pidff->block_load_status =
942 pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD],
944 pidff->effect_operation_status =
945 pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION],
950 if (!pidff->create_new_effect_type || !pidff->set_effect_type) {
951 printk(KERN_ERR "hid-pidff: effect lists not found\n");
955 if (!pidff->effect_direction) {
956 printk(KERN_ERR "hid-pidff: direction field not found\n");
960 if (!pidff->device_control) {
961 printk(KERN_ERR "hid-pidff: device control field not found\n");
965 if (!pidff->block_load_status) {
967 "hid-pidff: block load status field not found\n");
971 if (!pidff->effect_operation_status) {
973 "hid-pidff: effect operation field not found\n");
977 pidff_find_special_keys(pidff->control_id, pidff->device_control,
985 printk(KERN_ERR "hid-pidff: no effect types found\n");
1011 static int pidff_find_effects(struct pidff_device *pidff,
1017 int pidff_type = pidff->type_id[i];
1018 if (pidff->set_effect_type->usage[pidff_type].hid !=
1019 pidff->create_new_effect_type->usage[pidff_type].hid) {
1020 printk(KERN_ERR "hid-pidff: "
1026 if (pidff->type_id[PID_CONSTANT])
1028 if (pidff->type_id[PID_RAMP])
1030 if (pidff->type_id[PID_SQUARE]) {
1034 if (pidff->type_id[PID_SINE]) {
1038 if (pidff->type_id[PID_TRIANGLE]) {
1042 if (pidff->type_id[PID_SAW_UP]) {
1046 if (pidff->type_id[PID_SAW_DOWN]) {
1050 if (pidff->type_id[PID_SPRING])
1052 if (pidff->type_id[PID_DAMPER])
1054 if (pidff->type_id[PID_INERTIA])
1056 if (pidff->type_id[PID_FRICTION])
1064 pidff_find_fields(pidff->name, pidff_ ## name, \
1065 pidff->reports[report], \
1071 static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1077 "hid-pidff: unknown set_effect report layout\n");
1082 if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
1084 "hid-pidff: unknown pid_block_load report layout\n");
1090 "hid-pidff: unknown effect_operation report layout\n");
1096 "hid-pidff: unknown pid_block_free report layout\n");
1103 if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev))
1108 printk(KERN_WARNING "hid-pidff: "
1111 printk(KERN_WARNING "hid-pidff: "
1115 printk(KERN_WARNING "hid-pidff: "
1122 "hid-pidff: unknown constant effect layout\n");
1128 printk(KERN_WARNING "hid-pidff: unknown ramp effect layout\n");
1138 "hid-pidff: unknown condition effect layout\n");
1148 "hid-pidff: unknown periodic effect layout\n");
1163 static void pidff_reset(struct pidff_device *pidff)
1165 struct hid_device *hid = pidff->hid;
1168 pidff->device_control->value[0] = pidff->control_id[PID_RESET];
1170 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1172 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1175 pidff->device_control->value[0] =
1176 pidff->control_id[PID_ENABLE_ACTUATORS];
1177 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1181 usbhid_submit_report(hid, pidff->reports[PID_POOL], USB_DIR_IN);
1184 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
1185 while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
1187 printk(KERN_WARNING "hid-pidff: device reports "
1189 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1193 usbhid_submit_report(hid, pidff->reports[PID_POOL],
1203 static int pidff_check_autocenter(struct pidff_device *pidff,
1216 error = pidff_request_effect_upload(pidff, 1);
1218 printk(KERN_ERR "hid-pidff: upload request failed\n");
1222 if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] ==
1223 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) {
1224 pidff_autocenter(pidff, 0xffff);
1227 printk(KERN_NOTICE "hid-pidff: "
1231 pidff_erase_pid(pidff,
1232 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]);
1243 struct pidff_device *pidff;
1258 pidff = kzalloc(sizeof(*pidff), GFP_KERNEL);
1259 if (!pidff)
1262 pidff->hid = hid;
1264 pidff_find_reports(hid, HID_OUTPUT_REPORT, pidff);
1265 pidff_find_reports(hid, HID_FEATURE_REPORT, pidff);
1267 if (!pidff_reports_ok(pidff)) {
1273 error = pidff_init_fields(pidff, dev);
1277 pidff_reset(pidff);
1280 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1281 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
1285 error = pidff_check_autocenter(pidff, dev);
1290 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum -
1291 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum +
1298 if (pidff->pool[PID_SIMULTANEOUS_MAX].value)
1300 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1302 if (pidff->pool[PID_RAM_POOL_SIZE].value)
1304 pidff->pool[PID_RAM_POOL_SIZE].value[0]);
1306 if (pidff->pool[PID_DEVICE_MANAGED_POOL].value &&
1307 pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) {
1308 printk(KERN_NOTICE "hid-pidff: "
1318 ff->private = pidff;
1331 kfree(pidff);