2010-03-29 10:36:47     trouble getting spidev to work in 16 bit mode

Document created by Aaronwu Employee on Aug 21, 2013
Version 1Show Document
  • View in full screen mode

2010-03-29 10:36:47     trouble getting spidev to work in 16 bit mode

Ashish Gupta (INDIA)

Message: 87797   

 

Hi,

 

I am not able to get the spidev driver to work in the 16 bit mode. I have attached the test app code and following is the platform file entry for spidev: -

 

#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)

static struct bfin5xx_spi_chip spidev_chip_info = {

    .enable_dma = 0,

    .bits_per_word = 8,

};

 

and the following entry in the bfin_spi_board_info[] __initdata structure: -

 

#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)

    {

        .modalias = "spidev",

        .max_speed_hz = 10000000,     /* max spi clock (SCK) speed in HZ */

        .bus_num = 0,

        .chip_select = 4,

        .controller_data = &spidev_chip_info,

    },

 

1. )  Theoretically I should be able to set the 16 bits mode by issuing following ioctl command: -

 

ioctl(Device,SPI_IOC_WR_BITS_PER_WORD,&SPIBits);

 

But after running my app (writes 16 bit word in an infinite loop) in background mode, I checked the state of the SPI_CTL MMR using the blackifn debug MMRs fucntionality ("cat /sys/kernel/debug/blackfin/SPI/SPI_CTL").  It gave 0x1c01. The SPI_MODE was set to mode 3 hence CPHA/CPOL were set correctly but the SIZE bit was still low.

 

2. ) I know we can change the platform file setting and make it 16 bits there but we want to be able to change this setting from the user application at runtime hence we used spidev.

 

Eclosed: test app src and waveform captured (it clearly shows that SPI controller is set in 8 bit data mode as it treats 0x0AAF as two separate words of 8 bit each 0x0A and 0xAF.)

 

spidev_test.c

W0AAF_16.bmp

QuoteReplyEditDelete

 

 

2010-03-29 13:27:33     Re: trouble getting spidev to work in 16 bit mode

Mike Frysinger (UNITED STATES)

Message: 87801   

 

it's probably already fixed in trunk

QuoteReplyEditDelete

 

 

2010-03-29 23:58:57     Re: trouble getting spidev to work in 16 bit mode

Barry Song (CHINA)

Message: 87809   

 

We should have this bug:

 

static int bfin_spi_setup(struct spi_device *spi)

{

        ...

 

        /* Let people set non-standard bits directly */

        bfin_ctl_reg = BIT_CTL_OPENDRAIN | BIT_CTL_EMISO |

                BIT_CTL_PSSE | BIT_CTL_GM | BIT_CTL_SZ;

 

        /* chip_info isn't always needed */

        if (chip_info) {

               ...

                chip->enable_dma = chip_info->enable_dma != 0

                    && drv_data->master_info->enable_dma;

                chip->ctl_reg = chip_info->ctl_reg;

                chip->cs_chg_udelay = chip_info->cs_chg_udelay;

                chip->idle_tx_val = chip_info->idle_tx_val;

                chip->pio_interrupt = chip_info->pio_interrupt;

                spi->bits_per_word = chip_info->bits_per_word;

        } else {

                /* force a default base state */

                chip->ctl_reg &= bfin_ctl_reg;

        }

 

        ...

}

 

In fact, user setting will always be rewritten  by chip_info. I will have a look about the fixing.

 

-barry

QuoteReplyEditDelete

 

 

2010-03-30 00:27:36     Re: trouble getting spidev to work in 16 bit mode

Mike Frysinger (UNITED STATES)

Message: 87811   

 

no it doesnt.  please re-read the function -- spi_info is only consulted on initial setup.

 

there were some bugs here in 2009R1.1 and older, but i fixed them in trunk.

QuoteReplyEditDelete

 

 

2010-03-30 00:56:30     Re: trouble getting spidev to work in 16 bit mode

Hugh Shane (UNITED STATES)

Message: 87812   

 

Ashish,

 

I'm trying to get spidev to work at all! What other steps have you taken besides modifying your platform file as you describe above? In particular, what changes did you make to your build configuration?

 

Thanks,

 

Hugh

QuoteReplyEditDelete

 

 

2010-03-30 01:09:13     Re: trouble getting spidev to work in 16 bit mode

Barry Song (CHINA)

Message: 87813   

 

Yes. I have re-read it. Mike is right. It has been fixed in trunk.

 

-barry

QuoteReplyEditDelete

 

 

2010-03-30 07:38:53     Re: trouble getting spidev to work in 16 bit mode

Ashish Gupta (INDIA)

Message: 87852   

 

@Hugh

 

I am using the userspace spi driver - spidev.c This is a generic spi driver that can be used for communicating with devices for which a dedicated chip driver does not exist. You can see the info and further links here: -

 

  docs.blackfin.uclinux.org/doku.php?id=spi&s[]=spidev#userspace_driver

 

You already have the platform file settings I did. Apart from this I enabled this driver using 'make menuconfig'

 

Linux Kernel Configuration --->

                                          Device Drivers --->

                                                                 <*> SPI Support --->  

                                                                                           <*> User mode SPI device driver support

 

regards

 

Ashish

QuoteReplyEditDelete

 

 

2010-04-02 12:03:06     Re: trouble getting spidev to work in 16 bit mode

Hugh Shane (UNITED STATES)

Message: 88042   

 

Hi Ashish.

 

Thanks for your earlier reply. I'm now seeing activity on the SPI bus using the user space spi driver. In fact, when I hook up my oscilloscope I see the same waveform as in the file you attached earlier. Now I'm exploring the possibility of building a kernel using the trunk code as suggested eariler in this thread but have run into problems building a working kernel. Have you made a similar attempt? If so, how is it working for you?

 

Thanks,

 

Hugh

Attachments

Outcomes