SPI: CS GPIO not working

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI: CS GPIO not working

2,852 Views
santoshvoonna
Contributor I

I am using board with freescale SOC and kernel. I have SPI having three slaves and all of them are controlled by CS GPIOs. The CS GPIOs are configured in DTS with cs-gpios=<>, <>, <>. In my driver source, I am properly using "chipslect to use". Device is getting created and spi_setup succeeds.

But when I call spi_write() I don't see the chipselect being toggled. I believe the CS-GPIO should be automatically toggled when we call spi_write(). Please give me pointers to troubleshoot this issue.

0 Kudos
6 Replies

2,146 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Santosh,

Can you please specify what MCU are you using?

Best regards,

Tomas

0 Kudos

2,146 Views
santoshvoonna
Contributor I

It is IMX6SX running freescale kernel with version 4.1.15

0 Kudos

2,146 Views
skrap
Contributor IV

Santosh —

Did you find a solution to this problem?  I just ran into the same thing on the 4.9 kernel.  Same hardware works fine on v4.1 kernel.

I checked the pinmux.  It seemed fine.  I traced through the code, but couldn't see a bug.

0 Kudos

2,146 Views
lukasz_plachno
Contributor I

I observe similiar problem on i.mx6ul.

When I am using pin from GPIO4 group as CS it is working fine, however pin from GPIO2 group is broken.

My traces are showing that during spi_bitbang_start CS pin is set as output and toggled and later it is acquired from pinmux with devm_gpio_request.

Other driver from NXP: spi-fsl-lpspi.c have this sequence correct (allocate pin and then toggling).

How you can check if this is the same problem for you:

Add following printk in bgpio_set_set in your kernel code in gpio-mimo.c:

    printk("%s called: base: %08x, gpio: %d, gc->reg_dir: %08x, gc->bgpio_dir: %08x\n", __func__, gc->base, gpio, gc->read_reg(gc->reg_dir), gc->bgpio_dir);

in case you will see mismatch between gc->reg_dir and gc->bgpio_dir it means you have similiar issue.

Here is my log:

bgpio_set_set called: base: 00000020, gpio: 15, gc->reg_dir: 00000000, gc->bgpio_dir: 00008000

Best Regards,

Łukasz Płachno

0 Kudos

2,146 Views
skrap
Contributor IV

Hello!

I came to a similar conclusion, although I forgot to reply to the thread.  I ended up moving the gpio-requesting block of code in spi_imx_probe to a spot before the bitbang_master initialization.

nb = of_gpio_named_count(np, "cs-gpios");
for (i = 0; i < nb; i++) {
        int gpio = of_get_named_gpio(np, "cs-gpios", i);
        if (!gpio_is_valid(gpio))
                continue;
        ret = devm_gpio_request(&pdev->dev, gpio, DRIVER_NAME);
        if (ret) {
                dev_err(&pdev->dev, "Can't get CS GPIO %i\n", gpio);
                goto out_master_put;
        }
}

I reported this issue to the kernel spi list.  Seems like a lot of drivers may be in a similar situation.

Thanks for circling back on this issue.

0 Kudos

2,146 Views
igorpadykov
NXP Employee
NXP Employee

Hi Santosh

one can debug it in linux/drivers/spi/spi-imx.c

spi-imx.c\spi\drivers - linux-imx - i.MX Linux kernel 

spidev on wandboard dual lite 

spidev on sabrelite 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos