Post Go back to editing

AD9371: Driver support for TX LO Leakage External

Hello all,

I have AD9371 IC with Zynq ultrascale plus MPSoC on the custom board.

I want to enable TX LO Leakage external calibration not during boot time as my PA is not ON. After boot-up, we need to run scripts for PA ON.

Kindly tell me how can i do TX LO External Calibration.

Regards

Mahima

  • Please tell 

    What function will be called from ad9371.c file when we run this following line

    echo 1 > /sys/kernel/debug/iio/iio\:device2/initialize

    Kindly reply

  • Please reply as this is urgent for my current project.

  • What function will be called from ad9371.c file when we run this following line

    echo 1 > /sys/kernel/debug/iio/iio\:device2/initialize

    Analog Devices is currently observing our annual shutdown, so responses will be delayed.

    You can enable some init calibration via the advanced plugin. 

    https://wiki.analog.com/resources/tools-software/linux-software/ad9371_advanced_plugin#calibrations

    Or via the debugfs or devicetree:

    https://wiki.analog.com/resources/tools-software/linux-drivers/iio-transceiver/ad9371-customization

    Writing initialize to one will reconfigure the device from reset with the updated settings from debugfs. (please see here: https://github.com/analogdevicesinc/linux/blob/master/drivers/iio/adc/ad9371.c#L2789)

    Ideally you use the regular IIO API by writing the device attribute 

    calibrate_tx_lol_ext_en

    followed by the calibrate attribute. Please see here:

    1. https://github.com/analogdevicesinc/linux/blob/master/drivers/iio/adc/ad9371.c#L1297
    2. https://github.com/analogdevicesinc/linux/blob/master/drivers/iio/adc/ad9371.c#L1186
    3. https://github.com/analogdevicesinc/linux/blob/master/drivers/iio/adc/ad9371.c#L562

    -Michael

  • Thanks Michael.

    I will check all the above mentioned links.

  • For AD9371 LO Leakage External Calibration, I have updated the driver and enable the TX_LO_LEAKAGE_EXTERNAL. Following changes are done:

    I have used this function -> ret = ad9371_init_cal(phy, TX_LO_LEAKAGE_EXTERNAL);

    and I have changed this obsRxChannelsEnable ->

    AD9371_OF_PROP("adi,obs-settings-obs-rx-channels-enable", &phy->mykDevice->obsRx->obsRxChannelsEnable, MYK_ORX2);

    After running on custom board, the error is:

    [  489.983666] ERROR: 364: MYKONOS_waitArmCmdStatus() exited due to ARM error for the
    desired ARM opcode
    [  490.003988] ERROR: 282: Unknown error was encountered.
    [  490.020026] ad9371 spi1.1: calsDoneLifetime 0x5DFF, calsDoneLastRun 0x0, calsMinimum
    0x4F, initErrCal 0x9, initErrCode 0x7
    [  490.051824] ad9371 spi1.1: initCalsCompleted 0x0
    [  490.056586] ad9371 spi1.1: errorWord 0x2, statusWord 0x0
    [  490.061912] ad9371 spi1.1: ArmCmdStatusByte 0xE

    Please check.

  • The above error got corrected by using this function MYKONOS_setObsRxPathSource(mykDevice, OBS_RX2_TXLO);

    I have used MYKONOS_getTxLolStatus also.

    Log details are:

    ERROR: 364: MYKONOS_waitArmCmdStatus() exited due to ARM error for the desired ARM opcode [ 129.073024]

    ERROR: 283: MYKONOS_waitInitCals() returned an ARM error

    [ 129.088077] ad9371 spi1.0: calsDoneLifetime 0x5DFF, calsDoneLastRun 0x5DFF, calsMinimum 0x4F, initErrCal 0x0, initErrCode 0x0

    [ 129.131846] ad9371 spi1.0: initCalsCompleted 0x5DFF [ 129.136903] ad9371 spi1.0: errorWord 0x2, statusWord 0x0

    [ 129.142248] ad9371 spi1.0: ArmCmdStatusByte 0x4

    [ 129.156600] ad9371 spi1.0: TX_LO_LEAKAGE_EXTERNAL : (200)

    [ 129.184231] ad9371 spi1.0: Checking MYKONOS_getTxLolStatus ret value : (0)

    [ 129.191102] ad9371 spi1.0: ad9371_setup_cal_ms: error code (2063315820)

    [ 129.197720] ad9371 spi1.0: ad9371_setup_cal_ms: percentComplete (2063315824)

    [ 129.204761] ad9371 spi1.0: ad9371_setup_cal_ms: performanceMetric (2063315828)

    [ 129.211975] ad9371 spi1.0: ad9371_setup_cal_ms: iterCount (2063315832)

    [ 129.218494] ad9371 spi1.0: ad9371_setup_cal_ms: updateCount (2063315836)

    From the above logs, initErrCal is coming as 0x0. This means " Tx baseband filter calibartion " error.

    initErrCode is coming as 0x0. This means " No error".

    While running TX_LO_LEAKAGE_EXTERNAL calibration, I am getting above error. Please reply.

  • Hi,

    I have no idea why you needed to patch the driver?

    I guess you're using some very old version?

    You can run TX LOL External from the OSC GUI.

    You can also run it by exercising the IIO device attributes.

    I added some additional debug prints:

    diff --git a/drivers/iio/adc/ad9371.c b/drivers/iio/adc/ad9371.c
    index adad04e0b11e..40e49fd2f50d 100644
    --- a/drivers/iio/adc/ad9371.c
    +++ b/drivers/iio/adc/ad9371.c
    @@ -575,10 +575,20 @@ static int ad9371_init_cal(struct ad9371_rf_phy *phy, uint32_t initCalMask)
            /*** Mykonos ARM Initialization Calibrations       ***/
            /*****************************************************/
     
    +       pr_err("%s:%d initCalMask %x\n", __func__, __LINE__, initCalMask);
    +
            mykError = MYKONOS_runInitCals(phy->mykDevice, initCalMask);
    +       pr_err("%s:%d Run mykError %x\n", __func__, __LINE__, mykError);
    +
            mykError = MYKONOS_waitInitCals(phy->mykDevice, 60000, &errorFlag, &errorCode);
    +       pr_err("%s:%d Wait mykError %x\n", __func__, __LINE__, mykError);
    +
    +       MYKONOS_getInitCalStatus(phy->mykDevice, &initCalStatus);
    +
    +       pr_err("%s:%d initCalStatus %x\n", __func__, __LINE__, initCalStatus);
     
            if ((errorFlag != 0) || (errorCode != 0)) {
    +               pr_err("%s:%d\n", __func__, __LINE__);
                    mykError = MYKONOS_getInitCalStatus(phy->mykDevice, &initCalStatus);
                    if(mykError) {
                            dev_err(&phy->spi->dev, "%s (%d)",
    

    root@analog:~# iio_attr -d ad9371-phy calibrate_tx_lol_ext_en 1
    1
    root@analog:~# iio_attr -d ad9371-phy calibrate 1
    ad9371_init_cal:578 initCalMask 200
    ad9371_init_cal:581 Run mykError 0
    ad9371_init_cal:584 Wait mykError 0
    ad9371_init_cal:588 initCalStatus 200

    It works for me without any errors. (Please update you driver and sources)

    The ERROR: Input/output error (5) when writing calibrate using iio_attr can be ignored, it's caused by calibrate being a write only attribute.

    -Michael

  • Thanks Michael,

    I will try to add these debugs mentioned by you.

    I did not understand "The ERROR: Input/output error (5) when writing calibrate using iio_attr can be ignored, it's caused by calibrate being a write only attribute."

    As i am working on custom board and Observation path is connected to only ORX2, so I have changed this obsRxChannelsEnable ->

    AD9371_OF_PROP("adi,obs-settings-obs-rx-channels-enable", &phy->mykDevice->obsRx->obsRxChannelsEnable, MYK_ORX2);

    -Mahima

  • I did not understand "The ERROR: Input/output error (5) when writing calibrate using iio_attr can be ignored, it's caused by calibrate being a write only attribute."

    The iio_attr tool always tries to read what it has just written. However the calibration attribute returns an error when it is read. So you can ignore this error when you use iio_attr.

    You can alter adi,obs-settings-obs-rx-channels-enable either via OSC advanced plugin or by using the debugfs or devicetree interface.

    I tried with only MYK_ORX1 enabled and it works. However MYK_ORX2 causes this error below. 

    ad9371_init_cal:578 initCalMask 200
    ad9371_init_cal:581 Run mykError 0
    ERROR: 364: MYKONOS_waitArmCmdStatus() exited due to ARM error for the desired ARM opcode
    ERROR: 282: Unknown error was encountered.
    ad9371_init_cal:584 Wait mykError 11a
    ad9371_init_cal:588 initCalStatus 0
    ad9371_init_cal:591
    ad9371 spi0.1: calsDoneLifetime 0x5DFF, calsDoneLastRun 0x0, calsMinimum 0x4F, initErrCal 0x9, initErrCode 0x7
    ad9371 spi0.1: initCalsCompleted 0x0
    ad9371 spi0.1: errorWord 0x2, statusWord 0x0
    ad9371 spi0.1: ArmCmdStatusByte 0xE

    I guess you should be using ORX1 if you need to calibrate both TX1_TX2. It might be related with the JESD Framer M=2 parameter. If you change it to M=4 and then use only MYK_ORX2, the JESD link breaks, but the calibration succeeds.

    Maybe you should ask for further help here:

     (Missing Group) 

    -Michael

  • Hi Michael,

    Earlier i was also getting this error " initErrCal 0x9, initErrCode 0x7 "

    It is removed by using this function MYKONOS_setObsRxPathSource(mykDevice, OBS_RX2_TXLO); before calling callibration function for TX_LO_LEAKAGE_EXTERNAL.

    Now error is " initErrCal 0x0, initErrCode 0x0" . How TX LO LEAKAGE EXTERNAL Calibration is related to TX baseband filter calibration.