@@ -28,10 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
2828MODULE_DESCRIPTION (DRIVER_DESC );
2929MODULE_LICENSE ("GPL" );
3030
31- static bool use_ktime = true;
32- module_param (use_ktime , bool , 0400 );
33- MODULE_PARM_DESC (use_ktime , "Use ktime for measuring I/O speed" );
34-
3531/*
3632 * Option parsing.
3733 */
@@ -110,7 +106,6 @@ struct analog_port {
110106 char cooked ;
111107 int bads ;
112108 int reads ;
113- int speed ;
114109 int loop ;
115110 int fuzz ;
116111 int axes [4 ];
@@ -119,66 +114,6 @@ struct analog_port {
119114 int axtime ;
120115};
121116
122- /*
123- * Time macros.
124- */
125-
126- #ifdef __i386__
127-
128- #include <linux/i8253.h>
129-
130- #define GET_TIME (x ) do { if (boot_cpu_has(X86_FEATURE_TSC)) x = (unsigned int)rdtsc(); else x = get_time_pit(); } while (0)
131- #define DELTA (x ,y ) (boot_cpu_has(X86_FEATURE_TSC) ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TICK_RATE / HZ : 0)))
132- #define TIME_NAME (boot_cpu_has(X86_FEATURE_TSC)?"TSC":"PIT")
133- static unsigned int get_time_pit (void )
134- {
135- unsigned long flags ;
136- unsigned int count ;
137-
138- raw_spin_lock_irqsave (& i8253_lock , flags );
139- outb_p (0x00 , 0x43 );
140- count = inb_p (0x40 );
141- count |= inb_p (0x40 ) << 8 ;
142- raw_spin_unlock_irqrestore (& i8253_lock , flags );
143-
144- return count ;
145- }
146- #elif defined(__x86_64__ )
147- #define GET_TIME (x ) do { x = (unsigned int)rdtsc(); } while (0)
148- #define DELTA (x ,y ) ((y)-(x))
149- #define TIME_NAME "TSC"
150- #elif defined(__alpha__ ) || defined(CONFIG_ARM ) || defined(CONFIG_ARM64 ) || defined(CONFIG_PPC ) || defined(CONFIG_RISCV )
151- #define GET_TIME (x ) do { x = get_cycles(); } while (0)
152- #define DELTA (x ,y ) ((y)-(x))
153- #define TIME_NAME "get_cycles"
154- #else
155- #define FAKE_TIME
156- static unsigned long analog_faketime = 0 ;
157- #define GET_TIME (x ) do { x = analog_faketime++; } while(0)
158- #define DELTA (x ,y ) ((y)-(x))
159- #define TIME_NAME "Unreliable"
160- #warning Precise timer not defined for this architecture.
161- #endif
162-
163- static inline u64 get_time (void )
164- {
165- if (use_ktime ) {
166- return ktime_get_ns ();
167- } else {
168- unsigned int x ;
169- GET_TIME (x );
170- return x ;
171- }
172- }
173-
174- static inline unsigned int delta (u64 x , u64 y )
175- {
176- if (use_ktime )
177- return y - x ;
178- else
179- return DELTA ((unsigned int )x , (unsigned int )y );
180- }
181-
182117/*
183118 * analog_decode() decodes analog joystick data and reports input events.
184119 */
@@ -234,18 +169,18 @@ static void analog_decode(struct analog *analog, int *axes, int *initial, int bu
234169static int analog_cooked_read (struct analog_port * port )
235170{
236171 struct gameport * gameport = port -> gameport ;
237- u64 time [4 ], start , loop , now ;
172+ ktime_t time [4 ], start , loop , now ;
238173 unsigned int loopout , timeout ;
239174 unsigned char data [4 ], this , last ;
240175 unsigned long flags ;
241176 int i , j ;
242177
243178 loopout = (ANALOG_LOOP_TIME * port -> loop ) / 1000 ;
244- timeout = ANALOG_MAX_TIME * port -> speed ;
179+ timeout = ANALOG_MAX_TIME * NSEC_PER_MSEC ;
245180
246181 local_irq_save (flags );
247182 gameport_trigger (gameport );
248- now = get_time ();
183+ now = ktime_get ();
249184 local_irq_restore (flags );
250185
251186 start = now ;
@@ -258,24 +193,24 @@ static int analog_cooked_read(struct analog_port *port)
258193
259194 local_irq_disable ();
260195 this = gameport_read (gameport ) & port -> mask ;
261- now = get_time ();
196+ now = ktime_get ();
262197 local_irq_restore (flags );
263198
264- if ((last ^ this ) && (delta ( loop , now ) < loopout )) {
199+ if ((last ^ this ) && (ktime_sub ( now , loop ) < loopout )) {
265200 data [i ] = last ^ this ;
266201 time [i ] = now ;
267202 i ++ ;
268203 }
269204
270- } while (this && (i < 4 ) && (delta ( start , now ) < timeout ));
205+ } while (this && (i < 4 ) && (ktime_sub ( now , start ) < timeout ));
271206
272207 this <<= 4 ;
273208
274209 for (-- i ; i >= 0 ; i -- ) {
275210 this |= data [i ];
276211 for (j = 0 ; j < 4 ; j ++ )
277212 if (data [i ] & (1 << j ))
278- port -> axes [j ] = (delta ( start , time [i ]) << ANALOG_FUZZ_BITS ) / port -> loop ;
213+ port -> axes [j ] = (( u32 ) ktime_sub ( time [i ], start ) << ANALOG_FUZZ_BITS ) / port -> loop ;
279214 }
280215
281216 return - (this != port -> mask );
@@ -375,38 +310,22 @@ static void analog_calibrate_timer(struct analog_port *port)
375310{
376311 struct gameport * gameport = port -> gameport ;
377312 unsigned int i , t , tx ;
378- u64 t1 , t2 , t3 ;
313+ ktime_t t1 , t2 , t3 ;
379314 unsigned long flags ;
380315
381- if (use_ktime ) {
382- port -> speed = 1000000 ;
383- } else {
384- local_irq_save (flags );
385- t1 = get_time ();
386- #ifdef FAKE_TIME
387- analog_faketime += 830 ;
388- #endif
389- mdelay (1 );
390- t2 = get_time ();
391- t3 = get_time ();
392- local_irq_restore (flags );
393-
394- port -> speed = delta (t1 , t2 ) - delta (t2 , t3 );
395- }
396-
397316 tx = ~0 ;
398317
399318 for (i = 0 ; i < 50 ; i ++ ) {
400319 local_irq_save (flags );
401- t1 = get_time ();
320+ t1 = ktime_get ();
402321 for (t = 0 ; t < 50 ; t ++ ) {
403322 gameport_read (gameport );
404- t2 = get_time ();
323+ t2 = ktime_get ();
405324 }
406- t3 = get_time ();
325+ t3 = ktime_get ();
407326 local_irq_restore (flags );
408327 udelay (i );
409- t = delta ( t1 , t2 ) - delta ( t2 , t3 );
328+ t = ktime_sub ( t2 , t1 ) - ktime_sub ( t3 , t2 );
410329 if (t < tx ) tx = t ;
411330 }
412331
@@ -611,7 +530,7 @@ static int analog_init_port(struct gameport *gameport, struct gameport_driver *d
611530 t = gameport_read (gameport );
612531 msleep (ANALOG_MAX_TIME );
613532 port -> mask = (gameport_read (gameport ) ^ t ) & t & 0xf ;
614- port -> fuzz = (port -> speed * ANALOG_FUZZ_MAGIC ) / port -> loop / 1000 + ANALOG_FUZZ_BITS ;
533+ port -> fuzz = (NSEC_PER_MSEC * ANALOG_FUZZ_MAGIC ) / port -> loop / 1000 + ANALOG_FUZZ_BITS ;
615534
616535 for (i = 0 ; i < ANALOG_INIT_RETRIES ; i ++ ) {
617536 if (!analog_cooked_read (port ))
0 commit comments