19
19
*/
20
20
#include <linux/kernel.h>
21
21
#include <linux/module.h>
22
+ #include <linux/hrtimer.h>
22
23
#include <linux/interrupt.h>
23
24
#include <linux/irq.h>
24
25
#include <linux/gpio.h>
@@ -64,6 +65,7 @@ struct at86rf230_state_change {
64
65
struct at86rf230_local * lp ;
65
66
int irq ;
66
67
68
+ struct hrtimer timer ;
67
69
struct spi_message msg ;
68
70
struct spi_transfer trx ;
69
71
u8 buf [AT86RF2XX_MAX_BUF ];
@@ -548,6 +550,19 @@ at86rf230_async_state_assert(void *context)
548
550
ctx -> complete (context );
549
551
}
550
552
553
+ static enum hrtimer_restart at86rf230_async_state_timer (struct hrtimer * timer )
554
+ {
555
+ struct at86rf230_state_change * ctx =
556
+ container_of (timer , struct at86rf230_state_change , timer );
557
+ struct at86rf230_local * lp = ctx -> lp ;
558
+
559
+ at86rf230_async_read_reg (lp , RG_TRX_STATUS , ctx ,
560
+ at86rf230_async_state_assert ,
561
+ ctx -> irq_enable );
562
+
563
+ return HRTIMER_NORESTART ;
564
+ }
565
+
551
566
/* Do state change timing delay. */
552
567
static void
553
568
at86rf230_async_state_delay (void * context )
@@ -556,6 +571,7 @@ at86rf230_async_state_delay(void *context)
556
571
struct at86rf230_local * lp = ctx -> lp ;
557
572
struct at86rf2xx_chip_data * c = lp -> data ;
558
573
bool force = false;
574
+ ktime_t tim ;
559
575
560
576
/* The force state changes are will show as normal states in the
561
577
* state status subregister. We change the to_state to the
@@ -579,11 +595,10 @@ at86rf230_async_state_delay(void *context)
579
595
case STATE_TRX_OFF :
580
596
switch (ctx -> to_state ) {
581
597
case STATE_RX_AACK_ON :
582
- usleep_range ( c -> t_off_to_aack , c -> t_off_to_aack + 10 );
598
+ tim = ktime_set ( 0 , c -> t_off_to_aack * NSEC_PER_USEC );
583
599
goto change ;
584
600
case STATE_TX_ON :
585
- usleep_range (c -> t_off_to_tx_on ,
586
- c -> t_off_to_tx_on + 10 );
601
+ tim = ktime_set (0 , c -> t_off_to_tx_on * NSEC_PER_USEC );
587
602
goto change ;
588
603
default :
589
604
break ;
@@ -597,8 +612,8 @@ at86rf230_async_state_delay(void *context)
597
612
* to TX_ON.
598
613
*/
599
614
if (!force ) {
600
- usleep_range ( c -> t_frame + c -> t_p_ack ,
601
- c -> t_frame + c -> t_p_ack + 1000 );
615
+ tim = ktime_set ( 0 , ( c -> t_frame + c -> t_p_ack ) *
616
+ NSEC_PER_USEC );
602
617
goto change ;
603
618
}
604
619
break ;
@@ -610,7 +625,7 @@ at86rf230_async_state_delay(void *context)
610
625
case STATE_P_ON :
611
626
switch (ctx -> to_state ) {
612
627
case STATE_TRX_OFF :
613
- usleep_range ( c -> t_reset_to_off , c -> t_reset_to_off + 10 );
628
+ tim = ktime_set ( 0 , c -> t_reset_to_off * NSEC_PER_USEC );
614
629
goto change ;
615
630
default :
616
631
break ;
@@ -621,12 +636,10 @@ at86rf230_async_state_delay(void *context)
621
636
}
622
637
623
638
/* Default delay is 1us in the most cases */
624
- udelay ( 1 );
639
+ tim = ktime_set ( 0 , NSEC_PER_USEC );
625
640
626
641
change :
627
- at86rf230_async_read_reg (lp , RG_TRX_STATUS , ctx ,
628
- at86rf230_async_state_assert ,
629
- ctx -> irq_enable );
642
+ hrtimer_start (& ctx -> timer , tim , HRTIMER_MODE_REL );
630
643
}
631
644
632
645
static void
@@ -1546,6 +1559,8 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
1546
1559
lp -> state .trx .tx_buf = lp -> state .buf ;
1547
1560
lp -> state .trx .rx_buf = lp -> state .buf ;
1548
1561
spi_message_add_tail (& lp -> state .trx , & lp -> state .msg );
1562
+ hrtimer_init (& lp -> state .timer , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
1563
+ lp -> state .timer .function = at86rf230_async_state_timer ;
1549
1564
1550
1565
lp -> irq .lp = lp ;
1551
1566
lp -> irq .irq = lp -> spi -> irq ;
@@ -1555,6 +1570,8 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
1555
1570
lp -> irq .trx .tx_buf = lp -> irq .buf ;
1556
1571
lp -> irq .trx .rx_buf = lp -> irq .buf ;
1557
1572
spi_message_add_tail (& lp -> irq .trx , & lp -> irq .msg );
1573
+ hrtimer_init (& lp -> irq .timer , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
1574
+ lp -> irq .timer .function = at86rf230_async_state_timer ;
1558
1575
1559
1576
lp -> tx .lp = lp ;
1560
1577
lp -> tx .irq = lp -> spi -> irq ;
@@ -1564,6 +1581,8 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
1564
1581
lp -> tx .trx .tx_buf = lp -> tx .buf ;
1565
1582
lp -> tx .trx .rx_buf = lp -> tx .buf ;
1566
1583
spi_message_add_tail (& lp -> tx .trx , & lp -> tx .msg );
1584
+ hrtimer_init (& lp -> tx .timer , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
1585
+ lp -> tx .timer .function = at86rf230_async_state_timer ;
1567
1586
}
1568
1587
1569
1588
static int at86rf230_probe (struct spi_device * spi )
0 commit comments