3
3
* Force feedback driver for USB HID PID compliant devices
4
4
*
5
5
* Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com>
6
+ * Upgraded 2025 by Oleg Makarenko and Tomasz Pakuła
6
7
*/
7
8
8
- /*
9
- */
10
-
11
- /* #define DEBUG */
12
-
13
9
#define pr_fmt (fmt ) KBUILD_MODNAME ": " fmt
14
10
15
11
#include "hid-pidff.h"
25
21
26
22
/* Linux Force Feedback API uses miliseconds as time unit */
27
23
#define FF_TIME_EXPONENT -3
24
+ #define FF_INFINITE 0
28
25
29
26
/* Report usage table used to put reports into an array */
30
-
31
27
#define PID_SET_EFFECT 0
32
28
#define PID_EFFECT_OPERATION 1
33
29
#define PID_DEVICE_GAIN 2
@@ -48,20 +44,19 @@ static const u8 pidff_reports[] = {
48
44
0x21 , 0x77 , 0x7d , 0x7f , 0x89 , 0x90 , 0x96 , 0xab ,
49
45
0x5a , 0x5f , 0x6e , 0x73 , 0x74
50
46
};
51
-
52
- /* device_control is really 0x95, but 0x96 specified as it is the usage of
53
- the only field in that report */
47
+ /*
48
+ * device_control is really 0x95, but 0x96 specified
49
+ * as it is the usage of the only field in that report.
50
+ */
54
51
55
52
/* PID special fields */
56
-
57
53
#define PID_EFFECT_TYPE 0x25
58
54
#define PID_DIRECTION 0x57
59
55
#define PID_EFFECT_OPERATION_ARRAY 0x78
60
56
#define PID_BLOCK_LOAD_STATUS 0x8b
61
57
#define PID_DEVICE_CONTROL_ARRAY 0x96
62
58
63
59
/* Value usage tables used to put fields and values into arrays */
64
-
65
60
#define PID_EFFECT_BLOCK_INDEX 0
66
61
67
62
#define PID_DURATION 1
@@ -119,7 +114,6 @@ static const u8 pidff_device_gain[] = { 0x7e };
119
114
static const u8 pidff_pool [] = { 0x80 , 0x83 , 0xa9 };
120
115
121
116
/* Special field key tables used to put special field keys into arrays */
122
-
123
117
#define PID_ENABLE_ACTUATORS 0
124
118
#define PID_DISABLE_ACTUATORS 1
125
119
#define PID_STOP_ALL_EFFECTS 2
@@ -176,8 +170,10 @@ struct pidff_device {
176
170
struct pidff_usage effect_operation [sizeof (pidff_effect_operation )];
177
171
struct pidff_usage block_free [sizeof (pidff_block_free )];
178
172
179
- /* Special field is a field that is not composed of
180
- usage<->value pairs that pidff_usage values are */
173
+ /*
174
+ * Special field is a field that is not composed of
175
+ * usage<->value pairs that pidff_usage values are
176
+ */
181
177
182
178
/* Special field in create_new_effect */
183
179
struct hid_field * create_new_effect_type ;
@@ -222,7 +218,7 @@ static s32 pidff_clamp(s32 i, struct hid_field *field)
222
218
static int pidff_rescale (int i , int max , struct hid_field * field )
223
219
{
224
220
return i * (field -> logical_maximum - field -> logical_minimum ) / max +
225
- field -> logical_minimum ;
221
+ field -> logical_minimum ;
226
222
}
227
223
228
224
/*
@@ -282,9 +278,8 @@ static void pidff_set_time(struct pidff_usage *usage, u16 time)
282
278
283
279
static void pidff_set_duration (struct pidff_usage * usage , u16 duration )
284
280
{
285
- /* Convert infinite length from Linux API (0)
286
- to PID standard (NULL) if needed */
287
- if (duration == 0 )
281
+ /* Infinite value conversion from Linux API -> PID */
282
+ if (duration == FF_INFINITE )
288
283
duration = PID_INFINITE ;
289
284
290
285
if (duration == PID_INFINITE ) {
@@ -302,16 +297,16 @@ static void pidff_set_envelope_report(struct pidff_device *pidff,
302
297
struct ff_envelope * envelope )
303
298
{
304
299
pidff -> set_envelope [PID_EFFECT_BLOCK_INDEX ].value [0 ] =
305
- pidff -> block_load [PID_EFFECT_BLOCK_INDEX ].value [0 ];
300
+ pidff -> block_load [PID_EFFECT_BLOCK_INDEX ].value [0 ];
306
301
307
302
pidff -> set_envelope [PID_ATTACK_LEVEL ].value [0 ] =
308
- pidff_rescale (envelope -> attack_level >
309
- S16_MAX ? S16_MAX : envelope -> attack_level , S16_MAX ,
310
- pidff -> set_envelope [PID_ATTACK_LEVEL ].field );
303
+ pidff_rescale (envelope -> attack_level >
304
+ S16_MAX ? S16_MAX : envelope -> attack_level , S16_MAX ,
305
+ pidff -> set_envelope [PID_ATTACK_LEVEL ].field );
311
306
pidff -> set_envelope [PID_FADE_LEVEL ].value [0 ] =
312
- pidff_rescale (envelope -> fade_level >
313
- S16_MAX ? S16_MAX : envelope -> fade_level , S16_MAX ,
314
- pidff -> set_envelope [PID_FADE_LEVEL ].field );
307
+ pidff_rescale (envelope -> fade_level >
308
+ S16_MAX ? S16_MAX : envelope -> fade_level , S16_MAX ,
309
+ pidff -> set_envelope [PID_FADE_LEVEL ].field );
315
310
316
311
pidff_set_time (& pidff -> set_envelope [PID_ATTACK_TIME ],
317
312
envelope -> attack_length );
@@ -702,9 +697,7 @@ static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
702
697
static int pidff_playback (struct input_dev * dev , int effect_id , int value )
703
698
{
704
699
struct pidff_device * pidff = dev -> ff -> private ;
705
-
706
700
pidff_playback_pid (pidff , pidff -> pid_id [effect_id ], value );
707
-
708
701
return 0 ;
709
702
}
710
703
@@ -732,8 +725,11 @@ static int pidff_erase_effect(struct input_dev *dev, int effect_id)
732
725
733
726
hid_dbg (pidff -> hid , "starting to erase %d/%d\n" ,
734
727
effect_id , pidff -> pid_id [effect_id ]);
735
- /* Wait for the queue to clear. We do not want a full fifo to
736
- prevent the effect removal. */
728
+
729
+ /*
730
+ * Wait for the queue to clear. We do not want
731
+ * a full fifo to prevent the effect removal.
732
+ */
737
733
hid_hw_wait (pidff -> hid );
738
734
pidff_playback_pid (pidff , pid_id , 0 );
739
735
pidff_erase_pid (pidff , pid_id );
@@ -1239,7 +1235,6 @@ static int pidff_find_effects(struct pidff_device *pidff,
1239
1235
set_bit (FF_FRICTION , dev -> ffbit );
1240
1236
1241
1237
return 0 ;
1242
-
1243
1238
}
1244
1239
1245
1240
#define PIDFF_FIND_FIELDS (name , report , strict ) \
@@ -1370,12 +1365,10 @@ static int pidff_check_autocenter(struct pidff_device *pidff,
1370
1365
hid_notice (pidff -> hid ,
1371
1366
"device has unknown autocenter control method\n" );
1372
1367
}
1373
-
1374
1368
pidff_erase_pid (pidff ,
1375
1369
pidff -> block_load [PID_EFFECT_BLOCK_INDEX ].value [0 ]);
1376
1370
1377
1371
return 0 ;
1378
-
1379
1372
}
1380
1373
1381
1374
/*
0 commit comments