On Monday 31 March 2008 14:55:48 Bernd Büttner wrote:
> Bongani Hlope schrieb:
> > On Monday 31 March 2008 13:47:23 Bernd Büttner wrote:
> >> Bongani Hlope schrieb:
> >
> > 8<
> >
> >>> You really shouldn't be doing that in a module, that is why those
> >>> symbols are not exported. But if you really insist on reading/writing a
> >>> file in a kernel module look here:
> >>> http://www.linuxjournal.com/article/8110 it has both the lengthy
> >>> warning and examples of how to do it if you insist on doing the "wrong"
> >>> thing
> >>
> >> Thank you for the hint.
> >> I read the article and understand the problems.
> >> But I don't want to read from a file. I just want to read and write
> >> single bytes from and to a qspi-device. If I don't want to rewrite the
> >> qspi functions I have to call the qspi-driver.
> >> So what I'm searching for is a way to read/write a qspi-device from
> >> kernel mode without the indirection through user-mode.
> >
> > What device does you module drive?
>
> I have a device driver which handles digital and analog i/o. Most of them
> are located at pins of the coldfire cpu, some of them are behind the qspi
> bus. All data-ports are scanned in a settable time intervall and
> represented to user-space as a data field. User-space doesn't know whether
> data are located behind qspi or not. The hardware is flexible (no
> hotplugging), so the driver has a configuration area which is loaded from a
> flash device during startup, this is the reason for loadable modules.

What makes this setup difficult is the lack of a SPI salve-device in Linux... 
Your module needs to be both the Digital-Analog I/O driver and SPI driver. 
The SPI part will communicate with the coldfire qspi-driver:

e.g.

struct adio {
 struct spi_device *spi;
 struct my_device_type *device_type;
...
};


static int __devinit adio_probe(struct spi_device *spi)
{
 struct adio *ad;
 struct my_device_type *type_dev;
 struct spi_message *msg;
 struct spi_transfer *tx;
 int err;

 /* setup spi device*/
 spi->bits_per_word = 8;
 spi->mode = SPI_MODE_0;
 err = spi_setup(spi);
 if(err < 0)
   return err;

 ad = kzalloc(sizeof(struct adio), GFP_KERNEL)
 type_dev = /* allocate ram for you device, e.g. input_allocate_device() or 
kzalloc*/

if(!ad || !type_dev) {
 err = -ENOMEM;
 goto err_free_mem;
}
dev_set_drvdata(&spi->dev, ad); //SPI driver_data point's keeps track of your 
driver
ad->spi = spi;
ad->device_type = type_dev;

 /* setup the Digital-Analog IO device*/
 ...
 return 0;

err_free_mem:
 /*free your device memory e.g. input_free_device or kfree*/
 kfree(ad);
 return err;
}  

static int __devexit adio_remove(struct spi_device *spi)
{
  struct adio *ad = dev_get_drvdata(&spi->dev);
  /*un-register your device e.g. input_unregister_device(ad->device_type)*/
 kfree(ad);
 return 0;
}

static struct spi_driver adio_driver = {
 .driver = {
     .name  = "DigAnalogIO",
     .bus     = &spi_bus_tyep,
     .owner = THID_MODULE,
 },
 .probe      = adio_probe,
 .remove   = adio_remove,
};

static int __init  adio_init(void)
{
  return spi_register_driver(&adio_driver);
}
module_init(adio_init);

static void __exit adio_exit(void)
{
  spi_unregister_driver(&adio_driver);
}

Then on the current receiving end do the following

static in adio_rx(void *adio)
{
 struct spi_message *msg;
 ....
/* build your message here */
spi_sync(msg); //send

 

-- 
This message is subject to the CSIR's copyright terms and conditions, e-mail 
legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at 
http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their 
support.

_______________________________________________
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

Reply via email to