28
28
MODULE_DESCRIPTION (DRIVER_DESC );
29
29
MODULE_LICENSE ("GPL" );
30
30
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
-
35
31
/*
36
32
* Option parsing.
37
33
*/
@@ -110,7 +106,6 @@ struct analog_port {
110
106
char cooked ;
111
107
int bads ;
112
108
int reads ;
113
- int speed ;
114
109
int loop ;
115
110
int fuzz ;
116
111
int axes [4 ];
@@ -119,66 +114,6 @@ struct analog_port {
119
114
int axtime ;
120
115
};
121
116
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
-
182
117
/*
183
118
* analog_decode() decodes analog joystick data and reports input events.
184
119
*/
@@ -234,18 +169,18 @@ static void analog_decode(struct analog *analog, int *axes, int *initial, int bu
234
169
static int analog_cooked_read (struct analog_port * port )
235
170
{
236
171
struct gameport * gameport = port -> gameport ;
237
- u64 time [4 ], start , loop , now ;
172
+ ktime_t time [4 ], start , loop , now ;
238
173
unsigned int loopout , timeout ;
239
174
unsigned char data [4 ], this , last ;
240
175
unsigned long flags ;
241
176
int i , j ;
242
177
243
178
loopout = (ANALOG_LOOP_TIME * port -> loop ) / 1000 ;
244
- timeout = ANALOG_MAX_TIME * port -> speed ;
179
+ timeout = ANALOG_MAX_TIME * NSEC_PER_MSEC ;
245
180
246
181
local_irq_save (flags );
247
182
gameport_trigger (gameport );
248
- now = get_time ();
183
+ now = ktime_get ();
249
184
local_irq_restore (flags );
250
185
251
186
start = now ;
@@ -258,24 +193,24 @@ static int analog_cooked_read(struct analog_port *port)
258
193
259
194
local_irq_disable ();
260
195
this = gameport_read (gameport ) & port -> mask ;
261
- now = get_time ();
196
+ now = ktime_get ();
262
197
local_irq_restore (flags );
263
198
264
- if ((last ^ this ) && (delta ( loop , now ) < loopout )) {
199
+ if ((last ^ this ) && (ktime_sub ( now , loop ) < loopout )) {
265
200
data [i ] = last ^ this ;
266
201
time [i ] = now ;
267
202
i ++ ;
268
203
}
269
204
270
- } while (this && (i < 4 ) && (delta ( start , now ) < timeout ));
205
+ } while (this && (i < 4 ) && (ktime_sub ( now , start ) < timeout ));
271
206
272
207
this <<= 4 ;
273
208
274
209
for (-- i ; i >= 0 ; i -- ) {
275
210
this |= data [i ];
276
211
for (j = 0 ; j < 4 ; j ++ )
277
212
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 ;
279
214
}
280
215
281
216
return - (this != port -> mask );
@@ -375,38 +310,22 @@ static void analog_calibrate_timer(struct analog_port *port)
375
310
{
376
311
struct gameport * gameport = port -> gameport ;
377
312
unsigned int i , t , tx ;
378
- u64 t1 , t2 , t3 ;
313
+ ktime_t t1 , t2 , t3 ;
379
314
unsigned long flags ;
380
315
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
-
397
316
tx = ~0 ;
398
317
399
318
for (i = 0 ; i < 50 ; i ++ ) {
400
319
local_irq_save (flags );
401
- t1 = get_time ();
320
+ t1 = ktime_get ();
402
321
for (t = 0 ; t < 50 ; t ++ ) {
403
322
gameport_read (gameport );
404
- t2 = get_time ();
323
+ t2 = ktime_get ();
405
324
}
406
- t3 = get_time ();
325
+ t3 = ktime_get ();
407
326
local_irq_restore (flags );
408
327
udelay (i );
409
- t = delta ( t1 , t2 ) - delta ( t2 , t3 );
328
+ t = ktime_sub ( t2 , t1 ) - ktime_sub ( t3 , t2 );
410
329
if (t < tx ) tx = t ;
411
330
}
412
331
@@ -611,7 +530,7 @@ static int analog_init_port(struct gameport *gameport, struct gameport_driver *d
611
530
t = gameport_read (gameport );
612
531
msleep (ANALOG_MAX_TIME );
613
532
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 ;
615
534
616
535
for (i = 0 ; i < ANALOG_INIT_RETRIES ; i ++ ) {
617
536
if (!analog_cooked_read (port ))
0 commit comments