Skip to content

Commit eb3b435

Browse files
alexaringholtmann
authored andcommitted
at86rf230: replace state change sleeps with hrtimer
This patch replace the state change timing relevant sleeps with hrtimers. Currently the sleeps are done in the complete handler of spi_async. The relation of doing the state change timing sleep with a timer will get the sleep functionality out of spi_async complete handler context. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent e372174 commit eb3b435

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

drivers/net/ieee802154/at86rf230.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#include <linux/kernel.h>
2121
#include <linux/module.h>
22+
#include <linux/hrtimer.h>
2223
#include <linux/interrupt.h>
2324
#include <linux/irq.h>
2425
#include <linux/gpio.h>
@@ -64,6 +65,7 @@ struct at86rf230_state_change {
6465
struct at86rf230_local *lp;
6566
int irq;
6667

68+
struct hrtimer timer;
6769
struct spi_message msg;
6870
struct spi_transfer trx;
6971
u8 buf[AT86RF2XX_MAX_BUF];
@@ -548,6 +550,19 @@ at86rf230_async_state_assert(void *context)
548550
ctx->complete(context);
549551
}
550552

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+
551566
/* Do state change timing delay. */
552567
static void
553568
at86rf230_async_state_delay(void *context)
@@ -556,6 +571,7 @@ at86rf230_async_state_delay(void *context)
556571
struct at86rf230_local *lp = ctx->lp;
557572
struct at86rf2xx_chip_data *c = lp->data;
558573
bool force = false;
574+
ktime_t tim;
559575

560576
/* The force state changes are will show as normal states in the
561577
* state status subregister. We change the to_state to the
@@ -579,11 +595,10 @@ at86rf230_async_state_delay(void *context)
579595
case STATE_TRX_OFF:
580596
switch (ctx->to_state) {
581597
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);
583599
goto change;
584600
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);
587602
goto change;
588603
default:
589604
break;
@@ -597,8 +612,8 @@ at86rf230_async_state_delay(void *context)
597612
* to TX_ON.
598613
*/
599614
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);
602617
goto change;
603618
}
604619
break;
@@ -610,7 +625,7 @@ at86rf230_async_state_delay(void *context)
610625
case STATE_P_ON:
611626
switch (ctx->to_state) {
612627
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);
614629
goto change;
615630
default:
616631
break;
@@ -621,12 +636,10 @@ at86rf230_async_state_delay(void *context)
621636
}
622637

623638
/* Default delay is 1us in the most cases */
624-
udelay(1);
639+
tim = ktime_set(0, NSEC_PER_USEC);
625640

626641
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);
630643
}
631644

632645
static void
@@ -1546,6 +1559,8 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
15461559
lp->state.trx.tx_buf = lp->state.buf;
15471560
lp->state.trx.rx_buf = lp->state.buf;
15481561
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;
15491564

15501565
lp->irq.lp = lp;
15511566
lp->irq.irq = lp->spi->irq;
@@ -1555,6 +1570,8 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
15551570
lp->irq.trx.tx_buf = lp->irq.buf;
15561571
lp->irq.trx.rx_buf = lp->irq.buf;
15571572
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;
15581575

15591576
lp->tx.lp = lp;
15601577
lp->tx.irq = lp->spi->irq;
@@ -1564,6 +1581,8 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
15641581
lp->tx.trx.tx_buf = lp->tx.buf;
15651582
lp->tx.trx.rx_buf = lp->tx.buf;
15661583
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;
15671586
}
15681587

15691588
static int at86rf230_probe(struct spi_device *spi)

0 commit comments

Comments
 (0)