2008-01-09 22:32:12     How to use SPI port in blackfin uclinux ?

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

2008-01-09 22:32:12     How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49422   

 

Hi all,

 

In my blackfin uclinux project, I want to use spi port to operate serveral spi device, how can I correctly use it in uclinux? Would some one give me some advices or example? Thank you in advance !

QuoteReplyEditDelete

 

 

2008-01-09 23:53:31     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49424    when looking for new things, you should start at our wiki ... please review this document:

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

QuoteReplyEditDelete

 

 

2008-01-10 16:16:28     Re: How to use SPI port in blackfin uclinux ?

Alex Stewart (UNITED STATES)

Message: 49457    While that is true, the SPI documentation is NOT in sync with the current release. The "User space driver" section references spidev devices which are not in the current release (they are in the SVN trunk, but not the current release)

QuoteReplyEditDelete

 

 

2008-01-10 18:04:13     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49460    it certainly is in sync.  everything documented there (except for the spidev userspace interface) is in the last release.  the spidev userspace interface is explicitly labeled as not in the last release.

 

since you didnt explicitly state what you were trying to do (all you said was "use the SPI device"), we easily come to the logical conclusions:

- do it all in the kernel using the aforementioned documentation

- do it all in userspace.  if using the last release, you will need to write the glue yourself between the kernel and userspace.  if you you're using a new enough version of the kernel, you can simply use the already written driver using the aforementioned documentation.

 

afaict, everything you're looking for has been accounted.

QuoteReplyEditDelete

 

 

2008-01-11 07:42:55     Re: How to use SPI port in blackfin uclinux ?

Alex Stewart (UNITED STATES)

Message: 49498    Sorry Mike! I read that section again and you are correct. Must have missed it, it is in sync. My goof.

QuoteReplyEditDelete

 

 

2008-01-17 01:44:33     Re: How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49714   

 

Hi all,

 

I have read the spi documents,but there is a question:

 

in your example code , there is :                         struct ad5304_data  *data;

 

I can not find where it is defined.

 

can this struct define by myself or there are some instructions on how to define it?

QuoteReplyEditDelete

 

 

2008-01-17 02:10:04     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49715    it isnt defined on purpose -- it isnt relevant to the SPI usage.  it is a purely arbitrary driver-specific structure that the driver uses for its own purpose.

QuoteReplyEditDelete

 

 

2008-01-17 02:22:55     Re: How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49716   

 

Thanks very much Mike !

 

I have write a spi driver and put it in  /drivers/char, also add information in    arch/blackfin/mach-bf537/.../stamp.c

 

I use spi_register_driver,but the device was not registered. Would some one give some help?

 

Thanks in advance!

QuoteReplyEditDelete

 

 

2008-01-17 02:34:08     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49717    i cant really guess with the description you've posted

 

please post the actual file you added to drivers/char/, the changes you made to drivers/char/{Kconfig,Makefile}, and the changes you made to arch/blackfin/mach-bf537/stamp.c.

QuoteReplyEditDelete

 

 

2008-01-17 03:06:24     Re: How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49718   

 

OK

 

first in            stamp.c

 

static struct bfin5xx_spi_chip myspidev_chip_info =

{

//      .cs_change_per_word = 1,

        .ctl_reg = 0x1000,

        .enable_dma = 0,

        .bits_per_word = 16,

};

 

static const struct ads7846_platform_data myspide_info = {

        .model                  = 7846,

        .vref_delay_usecs       = 50,   /* internal, no capacitor */

        .x_plate_ohms           = 580,

        .y_plate_ohms           = 416,

//      .pressure_max           = 1000,

//      .pressure_min           = 0,

};

 

 

 

static struct spi_board_info bfin_spi_board_info[] __initdata = {

 

{

 

...............................

{

        .modalias               ="spidev",

        .platform_data          = &myspidev_info,

        .irq                    = IRQ_PG11,

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

        .bus_num        = 1,

        .chip_select  = 2,

        .controller_data = &myspidev_chip_info,

        .mode = SPI_MODE_0,

},

 

..............................

 

}

 

in my driver.c

 

static struct spi_driver myspidev_driver =

{

    .driver =

    {

        .name  = "spidev",

 

        .bus   = &spi_bus_type,

        .owner = THIS_MODULE,

    },

    .probe  = myspidev_probe,

    .remove = __devexit_p(myspidev_remove),

};

 

static int __init myspidev_init(void)

{

    printk("SPI device register starting.....\n");

    return spi_register_driver(&myspidev_driver);

}

static void __exit  myspidev_exit(void)

{

    return spi_unregister_driver(&myspidev_driver);

}

module_init(myspidev_init);

module_exit(myspidev_exit);

 

SPI device register starting..... is showed when the system is booting ,

 

it means that myspidev_init was called

 

but I can not find node  that : spidev0.2 in /dev  as what your said in the documents

 

 

 

 

 

 

 

 

 

 

 

 

QuoteReplyEditDelete

 

 

2008-01-17 04:37:51     Re: How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49722   

 

I have read spi documents, but I can not find :

 

How to use spi device in user program, how to open it and get data from it. read /write.

 

for example , if I open it , I need first write a 8 bit command and then read 12 bit data or 16 bit data, how could I do.

 

In your spi document, the Utilize SPI device section, it did not give enough information on how to hook the function.

 

How can I implement read write function in both driver and user

 

 

QuoteReplyEditDelete

 

 

2008-01-17 04:50:53     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49723    the "spidev" name is reserved, you cannot use that.

 

what kernel version are you using ?  the spidev driver is not available in the 2007R1 release.

QuoteReplyEditDelete

 

 

2008-01-17 04:53:43     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49725    the document states:

Just like the kernel driver, you need to declare the SPI device resources in your board file. See the Device Resources section above but for the .modalias field, use spidev.

 

that means you *only* add the information to the board resources file, you do not write any other driver code in the kernel.  the spidev device driver creates and manages the device nodes and user/kernel interface for you.

 

the document goes on to tell you that for half-duplex transactions, there is no special API.

 

for full-duplex, you need to read the spidev file which the document tells you to

QuoteReplyEditDelete

 

 

2008-01-17 05:12:22     Re: How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49727   

 

Hi Mike,

 

Thanks!

 

I can not find spidev in the Documents/spi now,

 

I still have some questions:

 

How can I use my device in Userspace driver, Just open it  and then read? I can find my spi device in /sys/bus/spi/ spidev and I can not find it in /dev directory.

 

And another question is there are serveral read operation in the spi subsystem: such as read_then_write, w8r16 and things like that , how can I point the mothod?

QuoteReplyEditDelete

 

 

2008-01-17 05:23:11     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49730    you did not say what kernel version you are using ...

QuoteReplyEditDelete

 

 

2008-01-17 19:56:01     Re: How to use SPI port in blackfin uclinux ?

DAVID ZHOU (CHINA)

Message: 49765    Thanks Mike!

I use the release version,not the svn version!

QuoteReplyEditDelete

 

 

2008-01-17 20:29:47     Re: How to use SPI port in blackfin uclinux ?

Mike Frysinger (UNITED STATES)

Message: 49766    then, as the SPI document states, the 2007R1 release does not have the spidev device driver

 

you will need to write the kernel/userspace interface yourself if you wish to use 2007R1

Attachments

    Outcomes