33 * Force feedback driver for USB HID PID compliant devices
44 *
55 * Copyright (c) 2005, 2006 Anssi Hannula <[email protected] > 6+ * Upgraded 2025 by Oleg Makarenko and Tomasz Pakuła
67 */
78
8- /*
9- */
10-
11- /* #define DEBUG */
12-
139#define pr_fmt (fmt ) KBUILD_MODNAME ": " fmt
1410
1511#include "hid-pidff.h"
2521
2622/* Linux Force Feedback API uses miliseconds as time unit */
2723#define FF_TIME_EXPONENT -3
24+ #define FF_INFINITE 0
2825
2926/* Report usage table used to put reports into an array */
30-
3127#define PID_SET_EFFECT 0
3228#define PID_EFFECT_OPERATION 1
3329#define PID_DEVICE_GAIN 2
@@ -48,20 +44,19 @@ static const u8 pidff_reports[] = {
4844 0x21 , 0x77 , 0x7d , 0x7f , 0x89 , 0x90 , 0x96 , 0xab ,
4945 0x5a , 0x5f , 0x6e , 0x73 , 0x74
5046};
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+ */
5451
5552/* PID special fields */
56-
5753#define PID_EFFECT_TYPE 0x25
5854#define PID_DIRECTION 0x57
5955#define PID_EFFECT_OPERATION_ARRAY 0x78
6056#define PID_BLOCK_LOAD_STATUS 0x8b
6157#define PID_DEVICE_CONTROL_ARRAY 0x96
6258
6359/* Value usage tables used to put fields and values into arrays */
64-
6560#define PID_EFFECT_BLOCK_INDEX 0
6661
6762#define PID_DURATION 1
@@ -119,7 +114,6 @@ static const u8 pidff_device_gain[] = { 0x7e };
119114static const u8 pidff_pool [] = { 0x80 , 0x83 , 0xa9 };
120115
121116/* Special field key tables used to put special field keys into arrays */
122-
123117#define PID_ENABLE_ACTUATORS 0
124118#define PID_DISABLE_ACTUATORS 1
125119#define PID_STOP_ALL_EFFECTS 2
@@ -176,8 +170,10 @@ struct pidff_device {
176170 struct pidff_usage effect_operation [sizeof (pidff_effect_operation )];
177171 struct pidff_usage block_free [sizeof (pidff_block_free )];
178172
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+ */
181177
182178 /* Special field in create_new_effect */
183179 struct hid_field * create_new_effect_type ;
@@ -222,7 +218,7 @@ static s32 pidff_clamp(s32 i, struct hid_field *field)
222218static int pidff_rescale (int i , int max , struct hid_field * field )
223219{
224220 return i * (field -> logical_maximum - field -> logical_minimum ) / max +
225- field -> logical_minimum ;
221+ field -> logical_minimum ;
226222}
227223
228224/*
@@ -282,9 +278,8 @@ static void pidff_set_time(struct pidff_usage *usage, u16 time)
282278
283279static void pidff_set_duration (struct pidff_usage * usage , u16 duration )
284280{
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 )
288283 duration = PID_INFINITE ;
289284
290285 if (duration == PID_INFINITE ) {
@@ -302,16 +297,16 @@ static void pidff_set_envelope_report(struct pidff_device *pidff,
302297 struct ff_envelope * envelope )
303298{
304299 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 ];
306301
307302 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 );
311306 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 );
315310
316311 pidff_set_time (& pidff -> set_envelope [PID_ATTACK_TIME ],
317312 envelope -> attack_length );
@@ -702,9 +697,7 @@ static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
702697static int pidff_playback (struct input_dev * dev , int effect_id , int value )
703698{
704699 struct pidff_device * pidff = dev -> ff -> private ;
705-
706700 pidff_playback_pid (pidff , pidff -> pid_id [effect_id ], value );
707-
708701 return 0 ;
709702}
710703
@@ -732,8 +725,11 @@ static int pidff_erase_effect(struct input_dev *dev, int effect_id)
732725
733726 hid_dbg (pidff -> hid , "starting to erase %d/%d\n" ,
734727 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+ */
737733 hid_hw_wait (pidff -> hid );
738734 pidff_playback_pid (pidff , pid_id , 0 );
739735 pidff_erase_pid (pidff , pid_id );
@@ -1239,7 +1235,6 @@ static int pidff_find_effects(struct pidff_device *pidff,
12391235 set_bit (FF_FRICTION , dev -> ffbit );
12401236
12411237 return 0 ;
1242-
12431238}
12441239
12451240#define PIDFF_FIND_FIELDS (name , report , strict ) \
@@ -1370,12 +1365,10 @@ static int pidff_check_autocenter(struct pidff_device *pidff,
13701365 hid_notice (pidff -> hid ,
13711366 "device has unknown autocenter control method\n" );
13721367 }
1373-
13741368 pidff_erase_pid (pidff ,
13751369 pidff -> block_load [PID_EFFECT_BLOCK_INDEX ].value [0 ]);
13761370
13771371 return 0 ;
1378-
13791372}
13801373
13811374/*
0 commit comments