20
20
#include <linux/serial.h>
21
21
#include <linux/clk.h>
22
22
#include <linux/delay.h>
23
+ #include <linux/ktime.h>
23
24
#include <linux/pinctrl/consumer.h>
24
25
#include <linux/rational.h>
25
26
#include <linux/slab.h>
@@ -233,9 +234,8 @@ struct imx_port {
233
234
bool context_saved ;
234
235
235
236
enum imx_tx_state tx_state ;
236
- unsigned long tx_state_next_change ;
237
- struct timer_list trigger_start_tx ;
238
- struct timer_list trigger_stop_tx ;
237
+ struct hrtimer trigger_start_tx ;
238
+ struct hrtimer trigger_stop_tx ;
239
239
};
240
240
241
241
struct imx_port_ucrs {
@@ -412,6 +412,15 @@ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2)
412
412
mctrl_gpio_set (sport -> gpios , sport -> port .mctrl );
413
413
}
414
414
415
+ static void start_hrtimer_ms (struct hrtimer * hrt , unsigned long msec )
416
+ {
417
+ long sec = msec / MSEC_PER_SEC ;
418
+ long nsec = (msec % MSEC_PER_SEC ) * 1000000 ;
419
+ ktime_t t = ktime_set (sec , nsec );
420
+
421
+ hrtimer_start (hrt , t , HRTIMER_MODE_REL );
422
+ }
423
+
415
424
/* called with port.lock taken and irqs off */
416
425
static void imx_uart_start_rx (struct uart_port * port )
417
426
{
@@ -468,16 +477,16 @@ static void imx_uart_stop_tx(struct uart_port *port)
468
477
if (port -> rs485 .flags & SER_RS485_ENABLED ) {
469
478
if (sport -> tx_state == SEND ) {
470
479
sport -> tx_state = WAIT_AFTER_SEND ;
471
- sport -> tx_state_next_change =
472
- jiffies + DIV_ROUND_UP (port -> rs485 .delay_rts_after_send * HZ , 1000 );
480
+ start_hrtimer_ms (& sport -> trigger_stop_tx ,
481
+ port -> rs485 .delay_rts_after_send );
482
+ return ;
473
483
}
474
484
475
485
if (sport -> tx_state == WAIT_AFTER_RTS ||
476
- (sport -> tx_state == WAIT_AFTER_SEND &&
477
- time_after_eq (jiffies , sport -> tx_state_next_change ))) {
486
+ sport -> tx_state == WAIT_AFTER_SEND ) {
478
487
u32 ucr2 ;
479
488
480
- del_timer (& sport -> trigger_start_tx );
489
+ hrtimer_try_to_cancel (& sport -> trigger_start_tx );
481
490
482
491
ucr2 = imx_uart_readl (sport , UCR2 );
483
492
if (port -> rs485 .flags & SER_RS485_RTS_AFTER_SEND )
@@ -489,8 +498,6 @@ static void imx_uart_stop_tx(struct uart_port *port)
489
498
imx_uart_start_rx (port );
490
499
491
500
sport -> tx_state = OFF ;
492
- } else if (sport -> tx_state == WAIT_AFTER_SEND ) {
493
- mod_timer (& sport -> trigger_stop_tx , sport -> tx_state_next_change );
494
501
}
495
502
} else {
496
503
sport -> tx_state = OFF ;
@@ -710,15 +717,16 @@ static void imx_uart_start_tx(struct uart_port *port)
710
717
imx_uart_stop_rx (port );
711
718
712
719
sport -> tx_state = WAIT_AFTER_RTS ;
713
- sport -> tx_state_next_change =
714
- jiffies + DIV_ROUND_UP (port -> rs485 .delay_rts_before_send * HZ , 1000 );
720
+ start_hrtimer_ms (& sport -> trigger_start_tx ,
721
+ port -> rs485 .delay_rts_before_send );
722
+ return ;
715
723
}
716
724
717
- if (sport -> tx_state == WAIT_AFTER_SEND ||
718
- (sport -> tx_state == WAIT_AFTER_RTS &&
719
- time_after_eq (jiffies , sport -> tx_state_next_change ))) {
725
+ if (sport -> tx_state == WAIT_AFTER_SEND
726
+ || sport -> tx_state == WAIT_AFTER_RTS ) {
727
+
728
+ hrtimer_try_to_cancel (& sport -> trigger_stop_tx );
720
729
721
- del_timer (& sport -> trigger_stop_tx );
722
730
/*
723
731
* Enable transmitter and shifter empty irq only if DMA
724
732
* is off. In the DMA case this is done in the
@@ -731,10 +739,6 @@ static void imx_uart_start_tx(struct uart_port *port)
731
739
}
732
740
733
741
sport -> tx_state = SEND ;
734
-
735
- } else if (sport -> tx_state == WAIT_AFTER_RTS ) {
736
- mod_timer (& sport -> trigger_start_tx , sport -> tx_state_next_change );
737
- return ;
738
742
}
739
743
} else {
740
744
sport -> tx_state = SEND ;
@@ -2283,26 +2287,30 @@ static void imx_uart_probe_pdata(struct imx_port *sport,
2283
2287
sport -> have_rtscts = 1 ;
2284
2288
}
2285
2289
2286
- static void imx_trigger_start_tx (struct timer_list * t )
2290
+ static enum hrtimer_restart imx_trigger_start_tx (struct hrtimer * t )
2287
2291
{
2288
- struct imx_port * sport = from_timer ( sport , t , trigger_start_tx );
2292
+ struct imx_port * sport = container_of ( t , struct imx_port , trigger_start_tx );
2289
2293
unsigned long flags ;
2290
2294
2291
2295
spin_lock_irqsave (& sport -> port .lock , flags );
2292
2296
if (sport -> tx_state == WAIT_AFTER_RTS )
2293
2297
imx_uart_start_tx (& sport -> port );
2294
2298
spin_unlock_irqrestore (& sport -> port .lock , flags );
2299
+
2300
+ return HRTIMER_NORESTART ;
2295
2301
}
2296
2302
2297
- static void imx_trigger_stop_tx (struct timer_list * t )
2303
+ static enum hrtimer_restart imx_trigger_stop_tx (struct hrtimer * t )
2298
2304
{
2299
- struct imx_port * sport = from_timer ( sport , t , trigger_stop_tx );
2305
+ struct imx_port * sport = container_of ( t , struct imx_port , trigger_stop_tx );
2300
2306
unsigned long flags ;
2301
2307
2302
2308
spin_lock_irqsave (& sport -> port .lock , flags );
2303
2309
if (sport -> tx_state == WAIT_AFTER_SEND )
2304
2310
imx_uart_stop_tx (& sport -> port );
2305
2311
spin_unlock_irqrestore (& sport -> port .lock , flags );
2312
+
2313
+ return HRTIMER_NORESTART ;
2306
2314
}
2307
2315
2308
2316
static int imx_uart_probe (struct platform_device * pdev )
@@ -2451,8 +2459,10 @@ static int imx_uart_probe(struct platform_device *pdev)
2451
2459
2452
2460
clk_disable_unprepare (sport -> clk_ipg );
2453
2461
2454
- timer_setup (& sport -> trigger_start_tx , imx_trigger_start_tx , 0 );
2455
- timer_setup (& sport -> trigger_stop_tx , imx_trigger_stop_tx , 0 );
2462
+ hrtimer_init (& sport -> trigger_start_tx , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
2463
+ hrtimer_init (& sport -> trigger_stop_tx , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
2464
+ sport -> trigger_start_tx .function = imx_trigger_start_tx ;
2465
+ sport -> trigger_stop_tx .function = imx_trigger_stop_tx ;
2456
2466
2457
2467
/*
2458
2468
* Allocate the IRQ(s) i.MX1 has three interrupts whereas later
0 commit comments