Hi Ramon,
There is a few other things you need to add in order to get your device
working.
1) you need to register your driver with a device
ret=register_chrdev(MAJOR_DEVICE, DEVICE_NAME, &pio48_fops);
if (ret<0)
{
printk(" Failed to get major id for pio48 device\n");
return ret;
}
else
{
printk("Installed '%s' as device major %d\n", DEVICE_NAME,
MAJOR_DEVICE);
}
you also need to unregister your device when you are
closing/uninstalling the driver.
unregister_chrdev(MAJOR_DEVICE, DEVICE_NAME);
This also assume you have created your device with mknod.
This then should ket you get to the point where your test program should
work.
2) If this is through a PCI/ISA/whatever interface make sure this is
setup and allocated properly. This will then allow you to get to the
physical memory address of your chip. ( this step may not be needed
depending on how your hardware is constructed.
3) If your going to write yet another spi driver (there are a lot out
there which you could potentially use) make sure you allocate/reserve
the physical memory address used by the chip
also try reading
http://lwn.net/Kernel/LDD3/
Mark Phillips
Automated Test Systems
On Fri, 2007-06-22 at 12:46 +0200, rflores wrote:
> Hi all,
>
>
>
> I’m writing a char driver, my platform is an arm nommu (AT91).
>
>
>
> The init function executes correctly in the uClinux startup. In the
> application the device is opened and closed correctly, but when I try
> to use the write function, the kernel doesn’t execute my write
> function and the function write in the application returns -1.
>
>
>
> The code in the driver side is:
>
>
>
> static int openflag_spi = 0;
>
>
>
> static struct file_operations swspi_fops = {
>
> read: spi_read,
>
> write: spi_write,
>
> open: spi_open,
>
> release: spi_release,
>
> }
>
>
>
> static ssize_t spi_write (struct file *filp, const char *buf, ssize_t
> count, loff_t *f_pos)
>
> {
>
> printk(“spi_write: %s\n”,buf);
>
> return(count);
>
> }
>
>
>
> static int spi_open (struct inode *inode,struct file *filp)
>
> {
>
> if (openflag_spi )
>
> return –EBUSY;
>
>
>
> MOD_INC_USE_COUNT;
>
> printk(“SWSPI: Open\n”);
>
> openflag_spi = 1;
>
> return 0;
>
> }
>
>
>
> static int spi_release (struct inode *inode,struct file *filp)
>
> {
>
> printk(“SWSPI: Close\n”);
>
> openflag_spi = 0;
>
> MOD_DEC_USE_COUNT;
>
> return 0;
>
> }
>
>
>
> The code in the application side is:
>
>
>
> int fd;
>
> char buf[80];
>
> fd = open (“/dev/swspi”,”rw”);
>
> if (fd == -1){
>
> printf(“\nUnable to open device\n”);
>
> return (-1);
>
> }
>
> printf(“\nSpi device descriptor = %d\n”,fd);
>
> strcpy(buf,”\nSWPI write function\n”);
>
> printf(“write return = %d”,write(fd,buf,sizeof(buf)));
>
>
>
>
>
> And the execution is:
>
>
>
> Sash command shell (version 1.1.1)
>
> />
>
> />
>
> /> llaccess test
>
> SWSPI: Open
>
>
>
> Spi device descriptor = 3
>
>
>
> write return = -1
>
> SWSPI: Close
>
> />
>
>
>
> Where is the problem? Why doesn’t the kernel call to spi_write when
> the application invokes the write function?
>
>
>
> Thanks in advance
>
>
>
> Ramón Flores
>
>
>
>
> _______________________________________________
> uClinux-dev mailing list
> [email protected]
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by [email protected]
> To unsubscribe see:
> http://mailman.uclinux.org/mailman/options/uclinux-dev
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev