Linux 2.6.10 on MCF54785EVB. SPI usage...

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

Linux 2.6.10 on MCF54785EVB. SPI usage...

3,151 Views
jkimble
Contributor III

The hardware I'm working on is a custom board based on the MCF5485 and most things are the same. One of the things that differs is the video chip and the touchscreen. I've got the video going via frame buffer. We have a touch screen LCD with a resistive mask that's driving an AtoD that's attached to the SPI device. I'm looking at the SPI drivers and Linux indicates that  the SPI device driver is loaded in the system log:
                                     :
                                     :
MCF547x/8x DSPI device driver installed
Coldfire DSPI driver is loaded
ColdFire internal UART serial driver version 1.00
ttyS0 at 0xe0008600 (irq = 99) is a builtin ColdFire UART
ttyS1 at 0xe0008700 (irq = 98) is a builtin ColdFire UART
                                     :
                                     :

However I don't know how to work with it and I have no examples of where to start. I see the driver and the code shows the valid  commands for the device but when I go to open /dev/qspi the command fails. If the driver is loading I'm not sure why qspi isn't available (unless that's the wrong device). I'm, sort of, starting at ground 0 here (again).

Any help/docs/examples would be much appreciated.

Labels (1)
0 Kudos
9 Replies

743 Views
SteveJoiner
Contributor I
Look in the kernel source under drivers/char/dspi.  You'll find the code there.  It's pretty straightforward:  you open the device, use ioctls to set up the parameters, then read/write the device for data.

One disadvantage of the DSPI driver in the Freescale BSP is that it is not using DMA, so it's performance is lacking.

We modified the DSPI driver to use DMA.  I'm attaching our code -- maybe you'll find it useful.  If you find any bugs or make any improvements, please let me know.

Thanks,
Steve

0 Kudos

743 Views
jkimble
Contributor III
 
 
Thanks for your help.
 
I did look at the driver and see the commands. I just can't open /dev/qspi.
 
Thanks for the dma version of the driver. I'll probably try to use that once I figure out how to use the original one.
 
James
 
0 Kudos

743 Views
SteveJoiner
Contributor I
On my BSP (I'm using the latest LTIB I think), it's /dev/dspi not /dev/qspi.  This is basically how we're opening it:

int fd = open("/dev/dspi", O_RDWR, 0);

-Steve

0 Kudos

743 Views
jkimble
Contributor III
 
The distribution I have (from Freescale, ltib w/ v2.6.10 kernel) didn't have a dspi device in the /dev directory. After looking at the driver a little more closely it obviously needs that device file so I just created one and that seems to work. I did put the driver you posted into my build tree so hopefully that will head off any problems I'd have had with the original driver.
 
Thanks again,
 
James
0 Kudos

743 Views
SteveJoiner
Contributor I
You're right.  I ran into that so long ago that I had forgotten about it.  You've probably already found a way to add it permanently, but if not, here area couple ideas.  You can add a "mknod /dev/dspi ..." command to an init script, or you can edit bin/device_table.txt in the ltib directory to have it automatically created when you generate the filesystem.

Good luck!

-Steve

0 Kudos

743 Views
jkimble
Contributor III

Steve,

If you've worked with this driver you must have some samples of configuring and reading and writing to it. Could you please share that with me. I'm really struggling to write an application to use the dspi device. I can open it but I can't even get the ioctl calls to work.

I could really use an example. Anything you've got would be much appreciated.

James

0 Kudos

743 Views
SteveJoiner
Contributor I
James,

I wish I could send you my code that uses the DSPI driver.  Unfortunately, it is part of a proprietary part of our code.

Have you seen the dspi-tools example in ltib?  If not, run this command in the ltib directory:  ltib -m prep -p dspi.spec.  Then look in rpm/BUILD/dspi-1.1.  The examples are pretty basic, but may be enough to get you started.

If not, let me know, and I'll see if I can strip out the proprietary parts out of my code and send you an example.

-Steve

0 Kudos

743 Views
jkimble
Contributor III

Thanks Steve. That's all I needed!

0 Kudos

743 Views
jkimble
Contributor III

I've compiled the two tests and the write program works but perror reports an "illegal seek" when I try to read SPI. Tried a bunch of stuff but I'm still getting it. The example looks like this:

===================================================================================
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <asm/mcf5485_dspi_ioctl.h>

#define BUF 10


int main()
{

        int f, k, num;
        char c[BUF];

        f = open("/dev/dspi", O_RDONLY, 0);

        if(f < 0)
        {
                printf("error of the opening\n");
                exit(0);
        }

        ioctl(f, DSPIIOCS_MSTR, 1);
        ioctl(f, DSPIIOCS_CSIS0, 1);

        for (num = 0; num < BUF:smileywink:
        {
                k = read(f, &c[num], BUF - num);
                perror("read");

                if (k < 0)
                {
                        printf("error of the reading\n");
                        break;
                }
                num += k;
        }

        for(k = 0; k < BUF; ++k)
                printf("%i ", c[k]);
        printf("\n");

        close(f);
        exit(0);
}

Any idea where I could be going wrong on such a simple program.....?

James

0 Kudos