This patch removes the current synchron state change function and add a new function for a state assert. Change the start and stop callbacks to use this new synchron state change behaviour.
Signed-off-by: Alexander Aring <alex.ar...@gmail.com> --- drivers/net/ieee802154/at86rf2xx.c | 69 ++++++++++++++------------------------ 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/drivers/net/ieee802154/at86rf2xx.c b/drivers/net/ieee802154/at86rf2xx.c index f891f3c..596d243 100644 --- a/drivers/net/ieee802154/at86rf2xx.c +++ b/drivers/net/ieee802154/at86rf2xx.c @@ -47,6 +47,8 @@ struct at86rf2xx_chip_data { u16 t_tx_on; u16 t_tx_aret_on; u16 t_rx_aack_on; + u16 t_off_to_aack; + u16 t_trx_off; /* short interframe spacing time */ u16 t_sifs; /* long interframe spacing time */ @@ -760,72 +762,45 @@ at86rf2xx_ed(struct ieee802154_dev *dev, u8 *level) } static int -at86rf2xx_state(struct ieee802154_dev *dev, int state) +at86rf2xx_sync_state_assert(struct at86rf2xx_local *lp, + unsigned int state, u16 t_state) { - struct at86rf2xx_local *lp = dev->priv; + unsigned int trx_state; int rc; - unsigned int val; - u8 desired_status; - - might_sleep(); - - if (state == STATE_FORCE_TX_ON) - desired_status = STATE_TX_ON; - else if (state == STATE_FORCE_TRX_OFF) - desired_status = STATE_TRX_OFF; - else - desired_status = state; do { - rc = at86rf2xx_read_subreg(lp, SR_TRX_STATUS, &val); - if (rc) - goto err; - } while (val == STATE_TRANSITION_IN_PROGRESS); - - if (val == desired_status) - return 0; - - /* state is equal to phy states */ - rc = at86rf2xx_write_subreg(lp, SR_TRX_CMD, state); - if (rc) - goto err; + udelay(t_state); - do { - rc = at86rf2xx_read_subreg(lp, SR_TRX_STATUS, &val); + rc = at86rf2xx_read_subreg(lp, SR_TRX_STATUS, &trx_state); if (rc) - goto err; - } while (val == STATE_TRANSITION_IN_PROGRESS); - - - if (val == desired_status || - (desired_status == STATE_RX_ON && val == STATE_BUSY_RX) || - (desired_status == STATE_RX_AACK_ON && val == STATE_BUSY_RX_AACK)) - return 0; - - pr_err("unexpected state change: %d, asked for %d\n", val, state); - return -EBUSY; + return rc; + } while (trx_state != state); -err: - pr_err("error: %d\n", rc); return rc; } static int at86rf2xx_start(struct ieee802154_dev *dev) { - u8 rc; + struct at86rf2xx_local *lp = dev->priv; + int rc; - rc = at86rf2xx_state(dev, STATE_TX_ON); + rc = __at86rf2xx_write(lp, RG_TRX_STATE, STATE_RX_AACK_ON); if (rc) return rc; - return at86rf2xx_state(dev, STATE_RX_AACK_ON); + return at86rf2xx_sync_state_assert(lp, STATE_RX_AACK_ON, + lp->data->t_off_to_aack); } static void at86rf2xx_stop(struct ieee802154_dev *dev) { - at86rf2xx_state(dev, STATE_FORCE_TRX_OFF); + struct at86rf2xx_local *lp = dev->priv; + + __at86rf2xx_write(lp, RG_TRX_STATE, STATE_FORCE_TRX_OFF); + at86rf2xx_sync_state_assert(lp, STATE_TRX_OFF, + lp->data->t_trx_off); } static int @@ -1048,6 +1023,8 @@ static struct at86rf2xx_chip_data at86rf233_data = { .t_tx_on = 1, .t_tx_aret_on = 1, .t_rx_aack_on = 1, + .t_off_to_aack = 80, + .t_trx_off = 1, .t_sifs = 192, .t_lifs = 480, .t_tx_timeout = 2000, @@ -1060,6 +1037,8 @@ static struct at86rf2xx_chip_data at86rf231_data = { .t_tx_on = 1, .t_tx_aret_on = 1, .t_rx_aack_on = 1, + .t_off_to_aack = 110, + .t_trx_off = 1, .t_sifs = 192, .t_lifs = 480, .t_tx_timeout = 2000, @@ -1072,6 +1051,8 @@ static struct at86rf2xx_chip_data at86rf212_data = { .t_tx_on = 1, .t_tx_aret_on = 1, .t_rx_aack_on = 1, + .t_off_to_aack = 200, + .t_trx_off = 1, .t_sifs = 192, .t_lifs = 480, .t_tx_timeout = 2000, -- 2.0.0 ------------------------------------------------------------------------------ HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing & Easy Data Exploration http://p.sf.net/sfu/hpccsystems _______________________________________________ Linux-zigbee-devel mailing list Linux-zigbee-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel