AnsweredAssumed Answered

AD9361 TDD SPI control - fix confirmation

Question asked by matwillis on Oct 14, 2015
Latest reply on Oct 15, 2015 by mhennerich

I have been working on a custom board containing AD9361 and need to change Tx <-> Rx in  TDD mode via SPI.(cannot use FDD independent mode)


The current linux and NoOS code in ad9361.c seems to set TXNRX_SPI_CTRL bit in REG_ENSM_2 as if it 'puts the ad9361 in SPI control mode'. But once this bit is set , setting a new ENSM state (Tx<->Rx) doesnt change any bits.


I have found I need to patch (kernel or NoOS) with code below to have any success, i.e. it treats the TXNRX_SPI_CTRL bit as TX=1 or RX=0. (i.e. like the TXNRX external pin)


Has anyone else managed to use SPI control in TDD modes, without similar changes?

If so, would you share the detailed command sequence (or at least some pointers)?

Can anyone see any gotchas with the proposed change?






--- ad9361.c.ORIG    2015-10-02 18:14:07.000000000 +0100

+++ ad9361.c    2015-10-14 15:33:26.358829249 +0100

@@ -4018,6 +4018,7 @@

     int32_t rc = 0;

     uint32_t val;

     uint32_t tmp;

+    uint32_t ensm_config_2;


     //     if (phy->curr_ensm_state == ensm_state) {

     //         dev_dbg(dev, "Nothing to do, device is already in %d state",

@@ -4028,6 +4029,7 @@

     dev_dbg(dev, "Device is in %x state, moving to %x", phy->curr_ensm_state,



+    ensm_config_2 = ad9361_spi_read(phy->spi, REG_ENSM_CONFIG_2); // if in SPI ctrl mode (NOT pinctrl) we nedd to set this TXNRX bit


     if (phy->curr_ensm_state == ENSM_STATE_SLEEP) {

         ad9361_spi_write(spi, REG_CLOCK_ENABLE,

@@ -4047,6 +4049,7 @@

     switch (ensm_state) {

     case ENSM_STATE_TX:

         val |= FORCE_TX_ON;

+        ensm_config_2 |=  TXNRX_SPI_CTRL; // Set bit for TX

         if (phy->pdata->fdd)

             rc = -EINVAL;

         else if (phy->curr_ensm_state != ENSM_STATE_ALERT)

@@ -4054,6 +4057,7 @@


     case ENSM_STATE_RX:

         val |= FORCE_RX_ON;

+        ensm_config_2 &=  ~TXNRX_SPI_CTRL; // clear bit for RX

         if (phy->pdata->fdd)

             rc = -EINVAL;

         else if (phy->curr_ensm_state != ENSM_STATE_ALERT)

@@ -4097,6 +4101,10 @@

         goto out;



+    if ((!pinctrl) && (phy->pdata->tdd_use_dual_synth==0) && (phy->pdata->fdd==0)) { // only for TDD, Single Synth, NOT pinctrl mode

+        rc = ad9361_spi_write(spi, REG_ENSM_CONFIG_2, ensm_config_2);

+        dev_info(dev, "Extra write for TDD Single_Synth REG_ENSM_CONFIG_2 0x%08x ",ensm_config_2);

+        };

     rc = ad9361_spi_write(spi, REG_ENSM_CONFIG_1, val);

     if (rc)

         dev_err(dev, "Failed to restore state");