15
15
#include <linux/ioport.h>
16
16
#include <linux/delay.h>
17
17
#include <linux/i2c.h>
18
- #include <linux/timer.h>
19
18
#include <linux/completion.h>
20
19
#include <linux/platform_device.h>
21
20
#include <linux/io.h>
@@ -32,7 +31,6 @@ struct i2c_pnx_mif {
32
31
int ret ; /* Return value */
33
32
int mode ; /* Interface mode */
34
33
struct completion complete ; /* I/O completion */
35
- struct timer_list timer ; /* Timeout */
36
34
u8 * buf ; /* Data buffer */
37
35
int len ; /* Length of data buffer */
38
36
int order ; /* RX Bytes to order via TX */
@@ -117,24 +115,6 @@ static inline int wait_reset(struct i2c_pnx_algo_data *data)
117
115
return (timeout <= 0 );
118
116
}
119
117
120
- static inline void i2c_pnx_arm_timer (struct i2c_pnx_algo_data * alg_data )
121
- {
122
- struct timer_list * timer = & alg_data -> mif .timer ;
123
- unsigned long expires = msecs_to_jiffies (alg_data -> timeout );
124
-
125
- if (expires <= 1 )
126
- expires = 2 ;
127
-
128
- del_timer_sync (timer );
129
-
130
- dev_dbg (& alg_data -> adapter .dev , "Timer armed at %lu plus %lu jiffies.\n" ,
131
- jiffies , expires );
132
-
133
- timer -> expires = jiffies + expires ;
134
-
135
- add_timer (timer );
136
- }
137
-
138
118
/**
139
119
* i2c_pnx_start - start a device
140
120
* @slave_addr: slave address
@@ -259,8 +239,6 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)
259
239
~(mcntrl_afie | mcntrl_naie | mcntrl_drmie ),
260
240
I2C_REG_CTL (alg_data ));
261
241
262
- del_timer_sync (& alg_data -> mif .timer );
263
-
264
242
dev_dbg (& alg_data -> adapter .dev ,
265
243
"%s(): Waking up xfer routine.\n" ,
266
244
__func__ );
@@ -276,8 +254,6 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)
276
254
~(mcntrl_afie | mcntrl_naie | mcntrl_drmie ),
277
255
I2C_REG_CTL (alg_data ));
278
256
279
- /* Stop timer. */
280
- del_timer_sync (& alg_data -> mif .timer );
281
257
dev_dbg (& alg_data -> adapter .dev ,
282
258
"%s(): Waking up xfer routine after zero-xfer.\n" ,
283
259
__func__ );
@@ -364,8 +340,6 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)
364
340
mcntrl_drmie | mcntrl_daie );
365
341
iowrite32 (ctl , I2C_REG_CTL (alg_data ));
366
342
367
- /* Kill timer. */
368
- del_timer_sync (& alg_data -> mif .timer );
369
343
complete (& alg_data -> mif .complete );
370
344
}
371
345
}
@@ -400,8 +374,6 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
400
374
mcntrl_drmie );
401
375
iowrite32 (ctl , I2C_REG_CTL (alg_data ));
402
376
403
- /* Stop timer, to prevent timeout. */
404
- del_timer_sync (& alg_data -> mif .timer );
405
377
complete (& alg_data -> mif .complete );
406
378
} else if (stat & mstatus_nai ) {
407
379
/* Slave did not acknowledge, generate a STOP */
@@ -419,8 +391,6 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
419
391
/* Our return value. */
420
392
alg_data -> mif .ret = - EIO ;
421
393
422
- /* Stop timer, to prevent timeout. */
423
- del_timer_sync (& alg_data -> mif .timer );
424
394
complete (& alg_data -> mif .complete );
425
395
} else {
426
396
/*
@@ -453,9 +423,8 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
453
423
return IRQ_HANDLED ;
454
424
}
455
425
456
- static void i2c_pnx_timeout (struct timer_list * t )
426
+ static void i2c_pnx_timeout (struct i2c_pnx_algo_data * alg_data )
457
427
{
458
- struct i2c_pnx_algo_data * alg_data = from_timer (alg_data , t , mif .timer );
459
428
u32 ctl ;
460
429
461
430
dev_err (& alg_data -> adapter .dev ,
@@ -472,7 +441,6 @@ static void i2c_pnx_timeout(struct timer_list *t)
472
441
iowrite32 (ctl , I2C_REG_CTL (alg_data ));
473
442
wait_reset (alg_data );
474
443
alg_data -> mif .ret = - EIO ;
475
- complete (& alg_data -> mif .complete );
476
444
}
477
445
478
446
static inline void bus_reset_if_active (struct i2c_pnx_algo_data * alg_data )
@@ -514,6 +482,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
514
482
struct i2c_msg * pmsg ;
515
483
int rc = 0 , completed = 0 , i ;
516
484
struct i2c_pnx_algo_data * alg_data = adap -> algo_data ;
485
+ unsigned long time_left ;
517
486
u32 stat ;
518
487
519
488
dev_dbg (& alg_data -> adapter .dev ,
@@ -548,7 +517,6 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
548
517
dev_dbg (& alg_data -> adapter .dev , "%s(): mode %d, %d bytes\n" ,
549
518
__func__ , alg_data -> mif .mode , alg_data -> mif .len );
550
519
551
- i2c_pnx_arm_timer (alg_data );
552
520
553
521
/* initialize the completion var */
554
522
init_completion (& alg_data -> mif .complete );
@@ -564,7 +532,10 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
564
532
break ;
565
533
566
534
/* Wait for completion */
567
- wait_for_completion (& alg_data -> mif .complete );
535
+ time_left = wait_for_completion_timeout (& alg_data -> mif .complete ,
536
+ alg_data -> timeout );
537
+ if (time_left == 0 )
538
+ i2c_pnx_timeout (alg_data );
568
539
569
540
if (!(rc = alg_data -> mif .ret ))
570
541
completed ++ ;
@@ -653,7 +624,10 @@ static int i2c_pnx_probe(struct platform_device *pdev)
653
624
alg_data -> adapter .algo_data = alg_data ;
654
625
alg_data -> adapter .nr = pdev -> id ;
655
626
656
- alg_data -> timeout = I2C_PNX_TIMEOUT_DEFAULT ;
627
+ alg_data -> timeout = msecs_to_jiffies (I2C_PNX_TIMEOUT_DEFAULT );
628
+ if (alg_data -> timeout <= 1 )
629
+ alg_data -> timeout = 2 ;
630
+
657
631
#ifdef CONFIG_OF
658
632
alg_data -> adapter .dev .of_node = of_node_get (pdev -> dev .of_node );
659
633
if (pdev -> dev .of_node ) {
@@ -673,8 +647,6 @@ static int i2c_pnx_probe(struct platform_device *pdev)
673
647
if (IS_ERR (alg_data -> clk ))
674
648
return PTR_ERR (alg_data -> clk );
675
649
676
- timer_setup (& alg_data -> mif .timer , i2c_pnx_timeout , 0 );
677
-
678
650
snprintf (alg_data -> adapter .name , sizeof (alg_data -> adapter .name ),
679
651
"%s" , pdev -> name );
680
652
0 commit comments