^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Force feedback driver for USB HID PID compliant devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /* #define DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "usbhid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PID_EFFECTS_MAX 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* Report usage table used to put reports into an array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define PID_SET_EFFECT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define PID_EFFECT_OPERATION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define PID_DEVICE_GAIN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define PID_POOL 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define PID_BLOCK_LOAD 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define PID_BLOCK_FREE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define PID_DEVICE_CONTROL 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define PID_CREATE_NEW_EFFECT 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define PID_REQUIRED_REPORTS 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define PID_SET_ENVELOPE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define PID_SET_CONDITION 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define PID_SET_PERIODIC 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define PID_SET_CONSTANT 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define PID_SET_RAMP 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const u8 pidff_reports[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 0x21, 0x77, 0x7d, 0x7f, 0x89, 0x90, 0x96, 0xab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 0x5a, 0x5f, 0x6e, 0x73, 0x74
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* device_control is really 0x95, but 0x96 specified as it is the usage of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) the only field in that report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* Value usage tables used to put fields and values into arrays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define PID_EFFECT_BLOCK_INDEX 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define PID_DURATION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define PID_GAIN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define PID_TRIGGER_BUTTON 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define PID_TRIGGER_REPEAT_INT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define PID_DIRECTION_ENABLE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define PID_START_DELAY 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static const u8 pidff_set_effect[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 0x22, 0x50, 0x52, 0x53, 0x54, 0x56, 0xa7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define PID_ATTACK_LEVEL 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define PID_ATTACK_TIME 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define PID_FADE_LEVEL 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define PID_FADE_TIME 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static const u8 pidff_set_envelope[] = { 0x22, 0x5b, 0x5c, 0x5d, 0x5e };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define PID_PARAM_BLOCK_OFFSET 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define PID_CP_OFFSET 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define PID_POS_COEFFICIENT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define PID_NEG_COEFFICIENT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define PID_POS_SATURATION 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define PID_NEG_SATURATION 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define PID_DEAD_BAND 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static const u8 pidff_set_condition[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 0x22, 0x23, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define PID_MAGNITUDE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define PID_OFFSET 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define PID_PHASE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define PID_PERIOD 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static const u8 pidff_set_periodic[] = { 0x22, 0x70, 0x6f, 0x71, 0x72 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static const u8 pidff_set_constant[] = { 0x22, 0x70 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define PID_RAMP_START 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define PID_RAMP_END 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static const u8 pidff_set_ramp[] = { 0x22, 0x75, 0x76 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define PID_RAM_POOL_AVAILABLE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static const u8 pidff_block_load[] = { 0x22, 0xac };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define PID_LOOP_COUNT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static const u8 pidff_effect_operation[] = { 0x22, 0x7c };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static const u8 pidff_block_free[] = { 0x22 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define PID_DEVICE_GAIN_FIELD 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static const u8 pidff_device_gain[] = { 0x7e };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define PID_RAM_POOL_SIZE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define PID_SIMULTANEOUS_MAX 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define PID_DEVICE_MANAGED_POOL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Special field key tables used to put special field keys into arrays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define PID_ENABLE_ACTUATORS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define PID_RESET 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static const u8 pidff_device_control[] = { 0x97, 0x9a };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define PID_CONSTANT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define PID_RAMP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define PID_SQUARE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define PID_SINE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define PID_TRIANGLE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define PID_SAW_UP 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define PID_SAW_DOWN 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define PID_SPRING 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define PID_DAMPER 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define PID_INERTIA 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define PID_FRICTION 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static const u8 pidff_effect_types[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 0x26, 0x27, 0x30, 0x31, 0x32, 0x33, 0x34,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 0x40, 0x41, 0x42, 0x43
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define PID_BLOCK_LOAD_SUCCESS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define PID_BLOCK_LOAD_FULL 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static const u8 pidff_block_load_status[] = { 0x8c, 0x8d };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define PID_EFFECT_START 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define PID_EFFECT_STOP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct pidff_usage {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct hid_field *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) s32 *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct pidff_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct hid_device *hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct hid_report *reports[sizeof(pidff_reports)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct pidff_usage set_effect[sizeof(pidff_set_effect)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct pidff_usage set_envelope[sizeof(pidff_set_envelope)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct pidff_usage set_condition[sizeof(pidff_set_condition)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct pidff_usage set_periodic[sizeof(pidff_set_periodic)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct pidff_usage set_constant[sizeof(pidff_set_constant)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct pidff_usage set_ramp[sizeof(pidff_set_ramp)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct pidff_usage device_gain[sizeof(pidff_device_gain)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct pidff_usage block_load[sizeof(pidff_block_load)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct pidff_usage pool[sizeof(pidff_pool)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct pidff_usage effect_operation[sizeof(pidff_effect_operation)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct pidff_usage block_free[sizeof(pidff_block_free)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Special field is a field that is not composed of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) usage<->value pairs that pidff_usage values are */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* Special field in create_new_effect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct hid_field *create_new_effect_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Special fields in set_effect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct hid_field *set_effect_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct hid_field *effect_direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Special field in device_control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct hid_field *device_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Special field in block_load */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct hid_field *block_load_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* Special field in effect_operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct hid_field *effect_operation_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int control_id[sizeof(pidff_device_control)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int type_id[sizeof(pidff_effect_types)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int status_id[sizeof(pidff_block_load_status)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int operation_id[sizeof(pidff_effect_operation_status)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int pid_id[PID_EFFECTS_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Scale an unsigned value with range 0..max for the given field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int pidff_rescale(int i, int max, struct hid_field *field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return i * (field->logical_maximum - field->logical_minimum) / max +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) field->logical_minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * Scale a signed value in range -0x8000..0x7fff for the given field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int pidff_rescale_signed(int i, struct hid_field *field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return i == 0 ? 0 : i >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 0 ? i * field->logical_maximum / 0x7fff : i *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) field->logical_minimum / -0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void pidff_set(struct pidff_usage *usage, u16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) usage->value[0] = pidff_rescale(value, 0xffff, usage->field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) pr_debug("calculated from %d to %d\n", value, usage->value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void pidff_set_signed(struct pidff_usage *usage, s16 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (usage->field->logical_minimum < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) usage->value[0] = pidff_rescale_signed(value, usage->field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (value < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) usage->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pidff_rescale(-value, 0x8000, usage->field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) usage->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pidff_rescale(value, 0x7fff, usage->field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pr_debug("calculated from %d to %d\n", value, usage->value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * Send envelope report to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void pidff_set_envelope_report(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct ff_envelope *envelope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pidff->set_envelope[PID_ATTACK_LEVEL].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) pidff_rescale(envelope->attack_level >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 0x7fff ? 0x7fff : envelope->attack_level, 0x7fff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pidff->set_envelope[PID_ATTACK_LEVEL].field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) pidff->set_envelope[PID_FADE_LEVEL].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pidff_rescale(envelope->fade_level >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 0x7fff ? 0x7fff : envelope->fade_level, 0x7fff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) pidff->set_envelope[PID_FADE_LEVEL].field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) hid_dbg(pidff->hid, "attack %u => %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) envelope->attack_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) hid_hw_request(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * Test if the new envelope differs from old one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int pidff_needs_set_envelope(struct ff_envelope *envelope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct ff_envelope *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return envelope->attack_level != old->attack_level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) envelope->fade_level != old->fade_level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) envelope->attack_length != old->attack_length ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) envelope->fade_length != old->fade_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Send constant force report to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static void pidff_set_constant_force_report(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) pidff->set_constant[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) effect->u.constant.level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) hid_hw_request(pidff->hid, pidff->reports[PID_SET_CONSTANT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Test if the constant parameters have changed between effects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int pidff_needs_set_constant(struct ff_effect *effect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return effect->u.constant.level != old->u.constant.level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * Send set effect report to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void pidff_set_effect_report(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) pidff->set_effect_type->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) pidff->create_new_effect_type->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) pidff->set_effect[PID_DURATION].value[0] = effect->replay.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) effect->trigger.interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) pidff->set_effect[PID_GAIN].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) pidff->set_effect[PID_GAIN].field->logical_maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) pidff->effect_direction->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pidff_rescale(effect->direction, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) pidff->effect_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * Test if the values used in set_effect have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int pidff_needs_set_effect(struct ff_effect *effect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return effect->replay.length != old->replay.length ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) effect->trigger.interval != old->trigger.interval ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) effect->trigger.button != old->trigger.button ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) effect->direction != old->direction ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) effect->replay.delay != old->replay.delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * Send periodic effect report to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static void pidff_set_periodic_report(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pidff->set_periodic[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pidff_set_signed(&pidff->set_periodic[PID_MAGNITUDE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) effect->u.periodic.magnitude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) pidff_set_signed(&pidff->set_periodic[PID_OFFSET],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) effect->u.periodic.offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * Test if periodic effect parameters have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int pidff_needs_set_periodic(struct ff_effect *effect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return effect->u.periodic.magnitude != old->u.periodic.magnitude ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) effect->u.periodic.offset != old->u.periodic.offset ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) effect->u.periodic.phase != old->u.periodic.phase ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) effect->u.periodic.period != old->u.periodic.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * Send condition effect reports to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static void pidff_set_condition_report(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) effect->u.condition[i].center);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) effect->u.condition[i].right_coeff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) effect->u.condition[i].left_coeff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) pidff_set(&pidff->set_condition[PID_POS_SATURATION],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) effect->u.condition[i].right_saturation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) pidff_set(&pidff->set_condition[PID_NEG_SATURATION],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) effect->u.condition[i].left_saturation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) pidff_set(&pidff->set_condition[PID_DEAD_BAND],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) effect->u.condition[i].deadband);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) hid_hw_request(pidff->hid, pidff->reports[PID_SET_CONDITION],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * Test if condition effect parameters have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int pidff_needs_set_condition(struct ff_effect *effect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct ff_condition_effect *cond = &effect->u.condition[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct ff_condition_effect *old_cond = &old->u.condition[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) ret |= cond->center != old_cond->center ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) cond->right_coeff != old_cond->right_coeff ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) cond->left_coeff != old_cond->left_coeff ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) cond->right_saturation != old_cond->right_saturation ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) cond->left_saturation != old_cond->left_saturation ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) cond->deadband != old_cond->deadband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * Send ramp force report to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static void pidff_set_ramp_force_report(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) pidff->set_ramp[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) pidff_set_signed(&pidff->set_ramp[PID_RAMP_START],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) effect->u.ramp.start_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) pidff_set_signed(&pidff->set_ramp[PID_RAMP_END],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) effect->u.ramp.end_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) hid_hw_request(pidff->hid, pidff->reports[PID_SET_RAMP],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * Test if ramp force parameters have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return effect->u.ramp.start_level != old->u.ramp.start_level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) effect->u.ramp.end_level != old->u.ramp.end_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * Send a request for effect upload to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * Returns 0 if device reported success, -ENOSPC if the device reported memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * is full. Upon unknown response the function will retry for 60 times, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * still unsuccessful -EIO is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) pidff->create_new_effect_type->value[0] = efnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) hid_hw_request(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) hid_dbg(pidff->hid, "create_new_effect sent, type: %d\n", efnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pidff->block_load_status->value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) hid_hw_wait(pidff->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) for (j = 0; j < 60; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) hid_dbg(pidff->hid, "pid_block_load requested\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) hid_hw_request(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) hid_hw_wait(pidff->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (pidff->block_load_status->value[0] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) hid_dbg(pidff->hid, "device reported free memory: %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (pidff->block_load_status->value[0] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) pidff->status_id[PID_BLOCK_LOAD_FULL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) hid_dbg(pidff->hid, "not enough memory free: %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) hid_err(pidff->hid, "pid_block_load failed 60 times\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * Play the effect with PID id n times
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) pidff->effect_operation[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (n == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) pidff->effect_operation_status->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) pidff->operation_id[PID_EFFECT_STOP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) pidff->effect_operation_status->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) pidff->operation_id[PID_EFFECT_START];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) hid_hw_request(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * Play the effect with effect id @effect_id for @value times
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static int pidff_playback(struct input_dev *dev, int effect_id, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct pidff_device *pidff = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) pidff_playback_pid(pidff, pidff->pid_id[effect_id], value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * Erase effect with PID id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) hid_hw_request(pidff->hid, pidff->reports[PID_BLOCK_FREE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * Stop and erase effect with effect_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static int pidff_erase_effect(struct input_dev *dev, int effect_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct pidff_device *pidff = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int pid_id = pidff->pid_id[effect_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) hid_dbg(pidff->hid, "starting to erase %d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) effect_id, pidff->pid_id[effect_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /* Wait for the queue to clear. We do not want a full fifo to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) prevent the effect removal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) hid_hw_wait(pidff->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) pidff_playback_pid(pidff, pid_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) pidff_erase_pid(pidff, pid_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * Effect upload handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct pidff_device *pidff = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) int type_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) pidff->pid_id[effect->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) switch (effect->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) case FF_CONSTANT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) pidff->type_id[PID_CONSTANT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (!old || pidff_needs_set_constant(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) pidff_set_constant_force_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (!old ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) pidff_needs_set_envelope(&effect->u.constant.envelope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) &old->u.constant.envelope))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) pidff_set_envelope_report(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) &effect->u.constant.envelope);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) case FF_PERIODIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) switch (effect->u.periodic.waveform) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) case FF_SQUARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) type_id = PID_SQUARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) case FF_TRIANGLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) type_id = PID_TRIANGLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) case FF_SINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) type_id = PID_SINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) case FF_SAW_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) type_id = PID_SAW_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) case FF_SAW_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) type_id = PID_SAW_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) hid_err(pidff->hid, "invalid waveform\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) pidff->type_id[type_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (!old || pidff_needs_set_periodic(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) pidff_set_periodic_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!old ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) pidff_needs_set_envelope(&effect->u.periodic.envelope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) &old->u.periodic.envelope))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) pidff_set_envelope_report(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) &effect->u.periodic.envelope);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) case FF_RAMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) pidff->type_id[PID_RAMP]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (!old || pidff_needs_set_ramp(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) pidff_set_ramp_force_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (!old ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) pidff_needs_set_envelope(&effect->u.ramp.envelope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) &old->u.ramp.envelope))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) pidff_set_envelope_report(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) &effect->u.ramp.envelope);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) case FF_SPRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) pidff->type_id[PID_SPRING]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (!old || pidff_needs_set_condition(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) pidff_set_condition_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) case FF_FRICTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) pidff->type_id[PID_FRICTION]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (!old || pidff_needs_set_condition(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) pidff_set_condition_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) case FF_DAMPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) pidff->type_id[PID_DAMPER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (!old || pidff_needs_set_condition(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pidff_set_condition_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) case FF_INERTIA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (!old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) error = pidff_request_effect_upload(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) pidff->type_id[PID_INERTIA]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (!old || pidff_needs_set_effect(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) pidff_set_effect_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (!old || pidff_needs_set_condition(effect, old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) pidff_set_condition_report(pidff, effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) hid_err(pidff->hid, "invalid type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (!old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) pidff->pid_id[effect->id] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) hid_dbg(pidff->hid, "uploaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * set_gain() handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static void pidff_set_gain(struct input_dev *dev, u16 gain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct pidff_device *pidff = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct hid_field *field =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) pidff->block_load[PID_EFFECT_BLOCK_INDEX].field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!magnitude) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) pidff_playback_pid(pidff, field->logical_minimum, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) pidff_playback_pid(pidff, field->logical_minimum, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) pidff->set_effect_type->value[0] = pidff->type_id[PID_SPRING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) pidff->set_effect[PID_DURATION].value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) pidff_set(&pidff->set_effect[PID_GAIN], magnitude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) pidff->set_effect[PID_START_DELAY].value[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) hid_hw_request(pidff->hid, pidff->reports[PID_SET_EFFECT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * pidff_set_autocenter() handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) struct pidff_device *pidff = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) pidff_autocenter(pidff, magnitude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * Find fields from a report and fill a pidff_usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) struct hid_report *report, int count, int strict)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) int i, j, k, found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) for (k = 0; k < count; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) for (i = 0; i < report->maxfield; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (report->field[i]->maxusage !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) report->field[i]->report_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) pr_debug("maxusage and report_count do not match, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) for (j = 0; j < report->field[i]->maxusage; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (report->field[i]->usage[j].hid ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) (HID_UP_PID | table[k])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) pr_debug("found %d at %d->%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) k, i, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) usage[k].field = report->field[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) usage[k].value =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) &report->field[i]->value[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if (found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (!found && strict) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) pr_debug("failed to locate %d\n", k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * Return index into pidff_reports for the given usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) static int pidff_check_usage(int usage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) for (i = 0; i < sizeof(pidff_reports); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (usage == (HID_UP_PID | pidff_reports[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * Find the reports and fill pidff->reports[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * report_type specifies either OUTPUT or FEATURE reports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) static void pidff_find_reports(struct hid_device *hid, int report_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct pidff_device *pidff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) list_for_each_entry(report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) &hid->report_enum[report_type].report_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (report->maxfield < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) ret = pidff_check_usage(report->field[0]->logical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (ret != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) hid_dbg(hid, "found usage 0x%02x from field->logical\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) pidff_reports[ret]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) pidff->reports[ret] = report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * Sometimes logical collections are stacked to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * different usages for the report and the field, in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * case we want the usage of the parent. However, Linux HID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * implementation hides this fact, so we have to dig it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * ourselves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) i = report->field[0]->usage[0].collection_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (i <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) hid->collection[i - 1].type != HID_COLLECTION_LOGICAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) ret = pidff_check_usage(hid->collection[i - 1].usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (ret != -1 && !pidff->reports[ret]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) hid_dbg(hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) "found usage 0x%02x from collection array\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) pidff_reports[ret]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) pidff->reports[ret] = report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * Test if the required reports have been found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) static int pidff_reports_ok(struct pidff_device *pidff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) for (i = 0; i <= PID_REQUIRED_REPORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (!pidff->reports[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) hid_dbg(pidff->hid, "%d missing\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) * Find a field with a specific usage within a report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) static struct hid_field *pidff_find_special_field(struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) int usage, int enforce_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) for (i = 0; i < report->maxfield; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (report->field[i]->logical == (HID_UP_PID | usage) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) report->field[i]->report_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (!enforce_min ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) report->field[i]->logical_minimum == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return report->field[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) pr_err("logical_minimum is not 1 as it should be\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * Fill a pidff->*_id struct table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) static int pidff_find_special_keys(int *keys, struct hid_field *fld,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) const u8 *usagetable, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) for (j = 0; j < fld->maxusage; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (fld->usage[j].hid == (HID_UP_PID | usagetable[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) keys[i] = j + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) #define PIDFF_FIND_SPECIAL_KEYS(keys, field, name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) pidff_find_special_keys(pidff->keys, pidff->field, pidff_ ## name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) sizeof(pidff_ ## name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) * Find and check the special fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) static int pidff_find_special_fields(struct pidff_device *pidff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) hid_dbg(pidff->hid, "finding special fields\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) pidff->create_new_effect_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 0x25, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) pidff->set_effect_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 0x25, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) pidff->effect_direction =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 0x57, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) pidff->device_control =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) 0x96, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) pidff->block_load_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) 0x8b, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) pidff->effect_operation_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 0x78, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) hid_dbg(pidff->hid, "search done\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (!pidff->create_new_effect_type || !pidff->set_effect_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) hid_err(pidff->hid, "effect lists not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (!pidff->effect_direction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) hid_err(pidff->hid, "direction field not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (!pidff->device_control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) hid_err(pidff->hid, "device control field not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (!pidff->block_load_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) hid_err(pidff->hid, "block load status field not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (!pidff->effect_operation_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) hid_err(pidff->hid, "effect operation field not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) pidff_find_special_keys(pidff->control_id, pidff->device_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) pidff_device_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) sizeof(pidff_device_control));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) PIDFF_FIND_SPECIAL_KEYS(control_id, device_control, device_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (!PIDFF_FIND_SPECIAL_KEYS(type_id, create_new_effect_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) effect_types)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) hid_err(pidff->hid, "no effect types found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (PIDFF_FIND_SPECIAL_KEYS(status_id, block_load_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) block_load_status) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) sizeof(pidff_block_load_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) hid_err(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) "block load status identifiers not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) if (PIDFF_FIND_SPECIAL_KEYS(operation_id, effect_operation_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) effect_operation_status) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) sizeof(pidff_effect_operation_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) hid_err(pidff->hid, "effect operation identifiers not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * Find the implemented effect types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static int pidff_find_effects(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) for (i = 0; i < sizeof(pidff_effect_types); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) int pidff_type = pidff->type_id[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (pidff->set_effect_type->usage[pidff_type].hid !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) pidff->create_new_effect_type->usage[pidff_type].hid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) hid_err(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) "effect type number %d is invalid\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (pidff->type_id[PID_CONSTANT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) set_bit(FF_CONSTANT, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (pidff->type_id[PID_RAMP])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) set_bit(FF_RAMP, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) if (pidff->type_id[PID_SQUARE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) set_bit(FF_SQUARE, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) set_bit(FF_PERIODIC, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (pidff->type_id[PID_SINE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) set_bit(FF_SINE, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) set_bit(FF_PERIODIC, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (pidff->type_id[PID_TRIANGLE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) set_bit(FF_TRIANGLE, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) set_bit(FF_PERIODIC, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (pidff->type_id[PID_SAW_UP]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) set_bit(FF_SAW_UP, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) set_bit(FF_PERIODIC, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (pidff->type_id[PID_SAW_DOWN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) set_bit(FF_SAW_DOWN, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) set_bit(FF_PERIODIC, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (pidff->type_id[PID_SPRING])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) set_bit(FF_SPRING, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (pidff->type_id[PID_DAMPER])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) set_bit(FF_DAMPER, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (pidff->type_id[PID_INERTIA])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) set_bit(FF_INERTIA, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (pidff->type_id[PID_FRICTION])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) set_bit(FF_FRICTION, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) #define PIDFF_FIND_FIELDS(name, report, strict) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) pidff_find_fields(pidff->name, pidff_ ## name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) pidff->reports[report], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) sizeof(pidff_ ## name), strict)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * Fill and check the pidff_usages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) int envelope_ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) hid_err(pidff->hid, "unknown set_effect report layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) hid_err(pidff->hid, "unknown pid_block_load report layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (PIDFF_FIND_FIELDS(effect_operation, PID_EFFECT_OPERATION, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) hid_err(pidff->hid, "unknown effect_operation report layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (PIDFF_FIND_FIELDS(block_free, PID_BLOCK_FREE, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) hid_err(pidff->hid, "unknown pid_block_free report layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) envelope_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (!envelope_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (test_and_clear_bit(FF_CONSTANT, dev->ffbit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) hid_warn(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) "has constant effect but no envelope\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (test_and_clear_bit(FF_RAMP, dev->ffbit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) hid_warn(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) "has ramp effect but no envelope\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (test_and_clear_bit(FF_PERIODIC, dev->ffbit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) hid_warn(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) "has periodic effect but no envelope\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (test_bit(FF_CONSTANT, dev->ffbit) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) hid_warn(pidff->hid, "unknown constant effect layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) clear_bit(FF_CONSTANT, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) if (test_bit(FF_RAMP, dev->ffbit) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) hid_warn(pidff->hid, "unknown ramp effect layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) clear_bit(FF_RAMP, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if ((test_bit(FF_SPRING, dev->ffbit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) test_bit(FF_DAMPER, dev->ffbit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) test_bit(FF_FRICTION, dev->ffbit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) test_bit(FF_INERTIA, dev->ffbit)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) hid_warn(pidff->hid, "unknown condition effect layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) clear_bit(FF_SPRING, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) clear_bit(FF_DAMPER, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) clear_bit(FF_FRICTION, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) clear_bit(FF_INERTIA, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (test_bit(FF_PERIODIC, dev->ffbit) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) hid_warn(pidff->hid, "unknown periodic effect layout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) clear_bit(FF_PERIODIC, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) PIDFF_FIND_FIELDS(pool, PID_POOL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (!PIDFF_FIND_FIELDS(device_gain, PID_DEVICE_GAIN, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) set_bit(FF_GAIN, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * Reset the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) static void pidff_reset(struct pidff_device *pidff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) struct hid_device *hid = pidff->hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) pidff->device_control->value[0] = pidff->control_id[PID_RESET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) /* We reset twice as sometimes hid_wait_io isn't waiting long enough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) hid_hw_wait(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) hid_hw_wait(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) pidff->device_control->value[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) pidff->control_id[PID_ENABLE_ACTUATORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) hid_hw_request(hid, pidff->reports[PID_DEVICE_CONTROL], HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) hid_hw_wait(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /* pool report is sometimes messed up, refetch it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) hid_hw_request(hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) hid_hw_wait(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (i++ > 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) hid_warn(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) "device reports %d simultaneous effects\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) hid_dbg(pidff->hid, "pid_pool requested again\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) hid_hw_request(hid, pidff->reports[PID_POOL],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) hid_hw_wait(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) * Test if autocenter modification is using the supported method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) static int pidff_check_autocenter(struct pidff_device *pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) * Let's find out if autocenter modification is supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * Specification doesn't specify anything, so we request an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) * effect upload and cancel it immediately. If the approved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) * effect id was one above the minimum, then we assume the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) * effect id is a built-in spring type effect used for autocenter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) error = pidff_request_effect_upload(pidff, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) hid_err(pidff->hid, "upload request failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) pidff_autocenter(pidff, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) set_bit(FF_AUTOCENTER, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) hid_notice(pidff->hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) "device has unknown autocenter control method\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) pidff_erase_pid(pidff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * Check if the device is PID and initialize it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) int hid_pidff_init(struct hid_device *hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) struct pidff_device *pidff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) struct hid_input *hidinput = list_entry(hid->inputs.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct input_dev *dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) struct ff_device *ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) int max_effects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) hid_dbg(hid, "starting pid init\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) hid_dbg(hid, "not a PID device, no output report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) pidff = kzalloc(sizeof(*pidff), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) if (!pidff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) pidff->hid = hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) hid_device_io_start(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) pidff_find_reports(hid, HID_OUTPUT_REPORT, pidff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) pidff_find_reports(hid, HID_FEATURE_REPORT, pidff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) if (!pidff_reports_ok(pidff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) hid_dbg(hid, "reports not ok, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) error = pidff_init_fields(pidff, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) pidff_reset(pidff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (test_bit(FF_GAIN, dev->ffbit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) error = pidff_check_autocenter(pidff, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) max_effects =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) hid_dbg(hid, "max effects is %d\n", max_effects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) if (max_effects > PID_EFFECTS_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) max_effects = PID_EFFECTS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (pidff->pool[PID_SIMULTANEOUS_MAX].value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) hid_dbg(hid, "max simultaneous effects is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) if (pidff->pool[PID_RAM_POOL_SIZE].value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) hid_dbg(hid, "device memory size is %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) pidff->pool[PID_RAM_POOL_SIZE].value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) if (pidff->pool[PID_DEVICE_MANAGED_POOL].value &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) hid_notice(hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) "device does not support device managed pool\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) error = input_ff_create(dev, max_effects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) ff = dev->ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) ff->private = pidff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) ff->upload = pidff_upload_effect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) ff->erase = pidff_erase_effect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) ff->set_gain = pidff_set_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) ff->set_autocenter = pidff_set_autocenter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) ff->playback = pidff_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) hid_info(dev, "Force feedback for USB HID PID devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) hid_device_io_stop(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) hid_device_io_stop(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) kfree(pidff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) }