2010-05-28 13:56:44     using bfin_sport_spi from the kernel space

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

2010-05-28 13:56:44     using bfin_sport_spi from the kernel space

Dimitar Penev (BULGARIA)

Message: 89964   

 

Hello,

 

I would like to interface bfin_sport_spi device driver from another kernel module.

Is there a unified way to interface this driver from the kernel space?

 

Thank you.

Dimitar

QuoteReplyEditDelete

 

 

2010-05-28 14:05:47     Re: using bfin_sport_spi from the kernel space

Mike Frysinger (UNITED STATES)

Message: 89966   

 

sorry, i thought you said bfin_sport_uart, not _spi.  please read the documentation for how to write kernel SPI drivers:

  docs.blackfin.uclinux.org/doku.php?id=spi

 

no driver accesses the SPI master drivers directly.  everything goes through the SPI core.

QuoteReplyEditDelete

 

 

2010-05-28 14:20:55     Re: using bfin_sport_spi from the kernel space

Dimitar Penev (BULGARIA)

Message: 89967   

 

Hi Mike,

 

Thank you for the answer. I think I am missing the main idea behind the spi linux framework.

 

If I have to access SPI chip thru the Blackfin SPORT from my own kernel module should I re-implement the whole code  available in  bfin_sport_spi.c ?

 

Is this the best I can do in case I really want to use it in the kernel space.

 

Thanks.

Dimitar

QuoteReplyEditDelete

 

 

2010-05-28 14:31:26     Re: using bfin_sport_spi from the kernel space

Mike Frysinger (UNITED STATES)

Message: 89968   

 

if you want to use SPI, you use the SPI framework.  use the board resources to bind specific SPI clients to specific SPI busses.  but everything else goes through the SPI API.

 

there is no need to write your own SPI master driver and copy & paste the existing driver.  simply use the existing API correctly.

QuoteReplyEditDelete

 

 

2010-05-28 14:56:20     Re: using bfin_sport_spi from the kernel space

Dimitar Penev (BULGARIA)

Message: 89969   

 

Hi Mike,

 

OK just to be sure that I am on the right track.

 

So I can use the API as defined in (include/linux/spi/spi.h) Let say I need only synchronous read/write

static inline int spi_read(struct spi_device *spi, u8 *buf, size_t len)

static inline int spi_write(struct spi_device *spi, const u8 *buf, size_t len)

 

To get properly the 'struct spi_device *spi'  (in my module ) however I need to define my kernel module as SPI platform driver (in the board definition file) so I get the above pointer in the probe function inside my module.

Or can I get the above pointer properly using some simpler way?

 

Thanks

Dimitar

QuoteReplyEditDelete

 

 

2010-05-28 15:07:12     Re: using bfin_sport_spi from the kernel space

Mike Frysinger (UNITED STATES)

Message: 89970   

 

only SPI drivers may access SPI busses.  it doesnt make sense any other way.

 

QuoteReplyEditDelete

 

 

2010-05-28 15:21:03     Re: using bfin_sport_spi from the kernel space

Dimitar Penev (BULGARIA)

Message: 89971   

 

Thank you Mike

Dimitar

QuoteReplyEditDelete

 

 

2010-05-31 11:08:10     Re: using bfin_sport_spi from the kernel space

Dimitar Penev (BULGARIA)

Message: 90021   

 

Hi Cliff,

 

As you have recommended I am writing in the forum.

 

So I have spent some time tring to make bfin_sport_spi working.

I would like to use SPORT1 and I want to use PF8 to select my SPI chip.

 

This is what I have in my board file (it is BF532 based board):

 

...

#if defined(CONFIG_SPI_BFIN_SPORT) || defined(CONFIG_SPI_BFIN_SPORT_MODULE)

static struct bfin5xx_spi_master bfin_sport_spi1_info = {

 

        .num_chipselect = 2, /* master supports two devices */

        .enable_dma = 0,  /* master don't support DMA */

        .pin_req = {P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_DRPRI,

                P_SPORT1_RSCLK, P_SPORT1_TFS, P_SPORT1_RFS, 0},

};

 

static struct resource bfin_sport_spi1_resource[] = {

        [0] = {

                .start = SPORT1_TCR1,

                .end   = SPORT1_TCR1 + 0xFF,

                .flags = IORESOURCE_MEM,

                },

        [1] = {

                .start = IRQ_SPORT1_ERROR,

                .end   = IRQ_SPORT1_ERROR,

                .flags = IORESOURCE_IRQ,

                },

};

 

static struct platform_device bfin_sport_spi1_device = {

        .name = "bfin-sport-spi",

        .id = 2, /* Bus number */

        .num_resources = ARRAY_SIZE(bfin_sport_spi1_resource),

        .resource = bfin_sport_spi1_resource,

        .dev = {

                .platform_data = &bfin_sport_spi1_info, /* Passed to driver */

        },

};

 

static struct bfin5xx_spi_chip sport_spi_chip_info = {

 

        .ctl_reg        = 0x0,

 

        .enable_dma     = 0,

 

        .bits_per_word  = 8,

 

        .cs_gpio = GPIO_PF8,

 

//        .cs_change_per_word = 1,

 

};

 

#endif  /* sport spi master and devices */

 

...

 

static struct spi_board_info bfin_spi_board_info[]  = {

 

        {

 

                .modalias = "bfin-sport-spi",

 

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

 

                .bus_num = 2,

 

                .chip_select = 0,

 

                .controller_data = &sport_spi_chip_info,

 

                .mode = SPI_MODE_3,

 

        },

 

...

 

}

 

Unfortunately I was not able to get SPI transfer working using the driver. I did some investigation and it seems

the operation stops in the line

while (!(read_STAT(drv_data) & RXNE)) inside bfin_sport_spi_u8_writer() finction

 

So I suspect I need to set  certain value (differnt than 0) in ctl_reg of my  bfin5xx_spi_chip structure.

 

I am using the bfin_sport_spi as included in 2009R1.1-RC4   I saw there are some changes in the trunk.

 

Can you guys advice me which version of this driver I should try and if I have proper data in my board file?

 

Thank you

Dimitar

QuoteReplyEditDelete

 

 

2010-05-31 23:53:58     Re: using bfin_sport_spi from the kernel space

Sonic Zhang (CHINA)

Message: 90031   

 

How do you connect your hardware? Did you follow the guide at   blackfin.uclinux.org/gf/download/frsrelease/438/5907/SPORTUART-SPI-IRDA-ADF70xxDBxv02SchematicPrints.pdf ? You need to add an circuits to make the driver works. For SPI_MODE_3, you may need to connect in (NOT TSCLK) AND (NOT SPI_SSEL).

 

We only tested this driver under SPI_MODE_0, which are connected in (TSCLK AND (NOT SPI_SSEL).

QuoteReplyEditDelete

 

 

2010-06-01 04:31:36     Re: using bfin_sport_spi from the kernel space

Michael Hennerich (GERMANY)

Message: 90041    Do you really need SPI_MODE_3?

Can you also use SPI_MODE_0?

QuoteReplyEditDelete

 

 

2010-06-02 16:34:33     Re: using bfin_sport_spi from the kernel space

Dimitar Penev (BULGARIA)

Message: 90077   

 

Hi Guys,

 

Oh I didn't know about this hardware requirement. I have to try this!

 

Michael based on the timing diagram of the chip I am using it seems I need SPI_MODE_3

 

BTW after some negative result with the driver i decided to test some 'home made'  code based on the work by David Rowe.

(It is actually quite similar with the lowest layer of the bfin_sport_spi.)

The code is working in general but  I am facing another issue.

 

===================================================================================

Definition of the setup

1. BF532 based board

2. SPORT1 is set up like this

- Clock Falling Edge Select (bor both Rx/TX)

-Late TFS & RFS

-Active low TFS & RFS

-Requires TFS/RFS for every data word

-Internal TFS used

-Internal TCLK

-8 bit word

-13.4 MHz sport clock

-the actual reader and writter funstions are exactly the same as the one in bfin_sport_spi

-SSEL is generated with GPIO pin

3.The sport is reading some parametters from the spi chip each 8ms (in workqueue generated by an ISR)

4. In the system there is dm9000 chip  using the  driver  included in R2009R1.1-RC4 (the whole software is based on this distribution)

5.  Under havy ethernet load once per ~ 200MB transfered the dm9000 driver locks and the watchdog restarts the dm9000 driver. The lock is about 5, 6 sec long and I get core dump after which ethernet transfer continues normally. During this lock the sport emulation of the spi is working properly.

6. This is not happening if the sport emulation of spi is not working.

 

Do you guys know what could be wrong.

 

Thank you.

Dimitar

QuoteReplyEditDelete

 

 

2010-06-02 16:44:23     Re: using bfin_sport_spi from the kernel space

Mike Frysinger (UNITED STATES)

Message: 90078   

 

if you want to do SPI over SPORT, use the driver we already wrote

Attachments

    Outcomes