Initializing the AD7795

Hello all!

I'm having trouble getting the AD7795 to work in a project.  Here's what I'm trying to do:

The AD7795 will be connected to a Freescale i.MX 6 Ultralite over SPI.  The i.MX6 Ultralite is running Debian with kernel version 3.14.38.  I compiled that kernel with the AD7793 driver per the instructions here:  https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad7793

Once the AD7795 is powered and the i.MX6 Ultralite is started up, there are no entries in the /sys/bus/iio/devices/ path on the i.MX6.

I do realize in the instructions on the wiki page that the AD7795 needs to be explicitly declared in code.  The problem I'm having is where does this code need to be written.  I don't understand what is meant by the "board support file" as the wiki page states.  Do you refer to the board support files as those in the /arch/arm/mach-xxxxx directories? Or is the board support file something I'd need to add as an include in the ad7793.c file before I compile the kernel?

I apologize in advance for these questions...  I'm more familiar with device trees.

Thanks!

  • 0
    •  Analog Employees 
    on Jan 21, 2016 7:04 AM

    Hi,

    The AD7793 driver does not yet support devicetree.

    It requires some pdata pointer to be passed from board info.

    Please see here:

    https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad7793#example_platform_device_initialization

    Without this pointer the driver probe will abort here:

    kernel/git/torvalds/linux.git - Linux kernel source tree

    A quick search indicates that some other imx boards still use the spi_register_board_info().

    dave@HAL9000:~/devel/git/linux-private/arch/arm/mach-imx$ grep -r spi_register_board_info *

    eukrea_mbimxsd25-baseboard.c:   spi_register_board_info(eukrea_mbimxsd25_spi_board_info,

    eukrea_mbimxsd35-baseboard.c:   spi_register_board_info(eukrea_mbimxsd35_spi_board_info,

    mach-mx27_3ds.c:        spi_register_board_info(mx27_3ds_spi_devs,

    mach-mx31_3ds.c:        spi_register_board_info(mx31_3ds_spi_devs,

    mach-mx31lilly.c:       spi_register_board_info(&mc13783_dev, 1);

    mach-mx31lite.c:        spi_register_board_info(&mc13783_spi_dev, 1);

    mach-mx31moboard.c:     spi_register_board_info(moboard_spi_board_info,

    mach-pca100.c:  spi_register_board_info(pca100_spi_board_info,

    mach-pcm037_eet.c:      spi_register_board_info(pcm037_spi_dev, ARRAY_SIZE(pcm037_spi_dev));

    mx31moboard-marxbot.c:  spi_register_board_info(marxbot_spi_board_info,

    dave@HAL9000:~/devel/git/linux-private/arch/arm/mach-imx$

    I guess for your board you can add spi_register_board_info() here:

    https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/arch/arm/mach-imx/mach-imx6q.c?id=refs/tags/v3.4.110#n85

    -Michael

  • Hi,

    chip_select is the pin to which the CS signal of the AD7795 is connected. This depends on your SPI controller and how you connect things. Your board should have some documentation which pin corresponds to which chip_select value.

    irq is typically the IRQ number for a external interrupt pin on your SoC, this is typically a GPIO. You need to connect the DOUT/RDY signal to that pin.

    All the other settings look OK.

    - Lars

  • Michael,

     

    Thanks for the information.  It looks like my thoughts were on the right track to get the AD7795 to initialize.  I’ve made changes to the mach-imx6ul.c source code which I have shown below. It looks like there is an attempt to initialize the AD7795 when I start up the i.MX6 Ultralite, but the AD7795 is still not showing up in /sys/bus/iio/devices

     

    I have some questions regarding the spi_board_info struct.


     

    static struct spi_board_info board_spi_info[] __initdata = {

    #if defined(CONFIG_AD7793) || defined(CONFIG_AD7793_MODULE)

      {

      .modalias = "ad7795”, 

      .max_speed_hz = 1000000,

      .bus_num = 0, // we only have one SPI bus on our Ultralite

      .chip_select = 2, // correct for the AD7795?

      .platform_data = &ad7793_pdata,

      .mode = SPI_MODE_3,  // Does this depend on the Ultralite or does this need to be changed for the AD7795?

      .irq = IRQ_PF6,  // This IRQ should be something defined for the i.MX6, right? The constant IRQ_PF6 isn’t defined in any of the headers mach-imx6ul.c uses.

      },

    #endif

    };


     

     

    static struct ad7793_platform_data ad7793_pdata =  {

      .clock_src = AD7793_CLK_SRC_EXT,

      .unipolar = true,

      .buffered = true,

      .refsel = AD7793_REFSEL_INTERNAL,

    };


     

    static void __init imx6ul_init_machine(void)

    {

      struct device *parent;

     

      mxc_arch_reset_init_dt();

     

      parent = imx_soc_device_init();

      if (parent == NULL)

      pr_warn("failed to initialize soc device\n”);  // this does NOT show up in dmesg

     

      of_platform_populate(NULL, of_default_bus_match_table,

      NULL, parent);

     

      imx6ul_enet_init();

      imx_anatop_init();

      imx6ul_pm_init();

            pr_warn("going to initialize the spi bus for the AD7795”);  // this shows up in dmesg

      spi_register_board_info(board_spi_info, ARRAY_SIZE(board_spi_info));

      pr_warn("done!”);  // this shows up in dmesg

    }


     

    Matt

  • Hi,

    Error 22 is EINVAL, which means an invalid value was passed as the input. The only place where this can happen in the ad7795 driver is in ad7793_check_platform_data() as far as I can see. But look at your platform data I can't see why it would be reject.

    Can you add a few printks to track down where the error originates?

    - Lars

  • Hi Lars.

     

    Thanks for the information — we’ve gotten further!

     

    The AD7795 is still not initializing yet.  In our dmesg we have this:

     

     

    [    2.409380] ad7793 : probe of spi3.2 failed with error -22


    It looks like spi3.2 was registered okay:

     

    [    0.993012] spi_imx 2014000.ecspi: registered master spi3

    [    0.993301] spi spi3.2: spi_imx_setup: mode 3, 8 bpw, 100000 hz

    [    0.993332] spi spi3.2: setup mode 3, 8 bits/w, 100000 Hz max --> 0

    [    0.993614] spi_imx 2014000.ecspi: registered child spi3.2

    [    0.993639] spi_imx 2014000.ecspi: probed

    So I guess the question is with the error 22, does this mean there is something missing in the spi_board_info struct when registering the AD7795?  Here’s the struct I’m passing in now:

    static struct spi_board_info board_spi_info[] __initdata = {

    #if defined(CONFIG_AD7793) || defined(CONFIG_AD7793_MODULE)

            {

                    .modalias = "ad7795",

                    .max_speed_hz = 100000,

                    .bus_num = 3,

                    .chip_select = 2,

                    .platform_data = &ad7793_pdata,

                    .mode = SPI_MODE_3,

                    .irq = 4,

            },

    #endif

    };

     

    We’ve also modified the device tree for the i.MX 6 Ultralite.  I’ll direct questions on that elsewhere if need be…

    Also, I did not disclose this before, but we’re using the evaluation board for the AD7795.  My apologies if this makes a huge difference!

    Thanks.

    Matt