2007-03-01 11:57:22     Any simple spi example?

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

2007-03-01 11:57:22     Any simple spi example?

Matias HEnttunen (SWEDEN)

Message: 22872    Hi,

Is there any simple spi driver that I can study ?

I looked at bfin_spi_adc but it's not commented so a bit hard to understand...

for instance where/how do I get a struct spi_device *spi handle ?

in the adc driver in open() there is a memset to clear spi_adc structure

and in write spi_adc.spidev is used, which should be a null pointer ?

 

cheers

QuoteReplyEditDelete

 

 

2007-03-01 13:07:47     Re: Any simple spi example?

Mike Frysinger (UNITED STATES)

Message: 22875    have you tried this page ?

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

QuoteReplyEditDelete

 

 

2007-03-02 05:29:03     Re: Any simple spi example?

Matias HEnttunen (SWEDEN)

Message: 22915    I did yes...

that page would be perfect if it had a "download complete example"

 

QuoteReplyEditDelete

 

 

2007-03-02 06:36:10     Re: Any simple spi example?

Matias HEnttunen (SWEDEN)

Message: 22917    I followed the example.

and compiled my driver, however probe is never called?

I'll attatch my code bellow if anyone cares to have a look (very short as at the moment)

rtc_drv.c

QuoteReplyEditDelete

 

 

2007-03-02 09:11:11     Re: Any simple spi example?

Jason Holden (UNITED STATES)

Message: 22924    Probe only gets called if you have set up a corresponding device in arch/blackfin/mach-bf5XX/boards/stamp.c

-Jason

QuoteReplyEditDelete

 

 

2007-03-02 09:18:01     Re: Any simple spi example?

Matias HEnttunen (SWEDEN)

Message: 22925    well I did that...

/* SPI RTC chip */

static struct bfin5xx_spi_chip spi_rtc_chip_info = {

    .ctl_reg = 0x1000| SPI_MODE_1,

    .enable_dma = 1,         /* use dma transfer with this chip*/

    .bits_per_word = 16,

};

 

/* Notice: for blackfin, the speed_hz is the value of register

* SPI_BAUD, not the real baudrate */

static struct spi_board_info bfin_spi_board_info[] __initdata = {

    {

        .modalias = "rtc-spi",

        .max_speed_hz = 16,

        .bus_num = 1,

        .chip_select = 0xff,

        .platform_data = NULL,

        .controller_data = &spi_rtc_chip_info,

        .mode     = SPI_MODE_1,

    },

};

 

/* SPI controller data */

static struct bfin5xx_spi_master spi_bfin_master_info = {

    .num_chipselect = 8,

    .enable_dma = 1,  /* master has the ability to do dma transfer */

};

 

static struct platform_device spi_bfin_master_device = {

    .name = "bfin-spi-master",

    .id = 1, /* Bus number */

    .dev = {

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

    },

};

static struct platform_device *imaster_devices[] __initdata = {

    &smc91x_device,

    &spi_bfin_master_device

};

 

static int __init imaster_init(void)

{

    int retv=0;

    printk("%s(): registering device resources\n", __FUNCTION__);

    platform_add_devices(imaster_devices, ARRAY_SIZE(imaster_devices));

    retv=spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));

    if( retv < 0 ) {

        printk("spi_register_board_info() failed?\n");

    } else printk("SPI register board info succeded\n");

    return 0;

}

 

 

 

 

 

How do I get (or setup) a struct spi_device handler

wich is used by all spi functions (read/write) ?

QuoteReplyEditDelete

 

 

2007-03-02 23:11:04     Re: Any simple spi example?

Mike Frysinger (UNITED STATES)

Message: 22944    i cant even guess what you mean by "download complete example"

 

the SPI bus has transactions, not "downloads"

QuoteReplyEditDelete

 

 

2007-03-02 23:14:29     Re: Any simple spi example?

Mike Frysinger (UNITED STATES)

Message: 22945    the SPI driver probe function will not be called if the SPI master driver is not loaded ... make sure that it is enabled

QuoteReplyEditDelete

 

 

2008-12-08 05:29:50     Re: Any simple spi example?

Filip Vanalme (BELGIUM)

Message: 66497   

 

I have the same kind of problem as you had at that time....

I'm developing for a BF-561 board with Kernel version 2.6.16.11 (2006R1).

 

I followed the instructions in the SPI doc (I have to admit, I'm not an experienced Linux device driver developer...).

 

I adjusted the Kconfig and Makefile of /drivers/spi to include my file :

 

* Kconfig

 

....

config SPI_TLV

   tristate "TLV SPI support"

   depends on SPI_MASTER && EXPERIMENTAL

   help

    Company SPI driver.

....

 

 

* Makefile

 

obj-$(CONFIG_SPI_TLV)           += spi_tlv.o

 

In menuconfig :

 

[*] SPI support

[*]   SPI Master Support

---     SPI Master Controller Drivers

[ ]     Bitbanging SPI master

[*]     TLV SPI support     

---     SPI Protocol Masters

[*]     SPI controller driver for ADI Blackfin5xx

 

I think this is OK because my souce file gets compiled. And spi_bfin5xx was build too.

 

I also adjusted /arch/blackfin/mach-bf561/boards/ezkit.c :

 

...

static struct bfin5xx_spi_chip spi_tlv_chip_info = {

.ctl_reg = 0x1000,

.enable_dma = 0,

.bits_per_word = 16,

};

 

 

/* Notice: for blackfin, the speed_hz is the value of register

   SPI_BAUD, not the real baudrate */

static struct spi_board_info bfin_spi_board_info[] __initdata = {

...

#if defined(CONFIG_SPI_TLV) || defined(CONFIG_SPI_TLV_MODULE)

{

  .modalias = "tlv-spi",

  .max_speed_hz = 16,

  .bus_num = 0,

  .chip_select = 1,

  .platform_data = NULL,

  .controller_data = &spi_tlv_chip_info,

},

...

#endif

 

};

 

/* SPI controller data */

static struct bfin5xx_spi_master spi_bfin_master_info = {

     .num_chipselect = 8,

     .enable_dma = 1,  /* master has the ability to do dma transfer */

};

 

static struct platform_device spi_bfin_master_device = {

     .name = "bfin-spi-master",

     .id = 1, /* Bus number */

     .dev = {

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

     },

};

#endif  /* spi master and devices */

static struct platform_device *ezkit_devices[] __initdata = {

  &uart_16c554_device,

  &smsc911x_device,

  &bfin_gpios_device,

#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)

&spi_bfin_master_device,

#endif

};

 

static int __init ezkit_init(void)

{

  int status;

 

  printk("%s(): registering device resources\n", __FUNCTION__);

  printk("Adding devices\n");

  status = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));

  if (status < 0)

  {

    printk("Error while adding devices : %d", status);

  }

#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)

    printk("Registering board info\n");

    status = spi_register_board_info(bfin_spi_board_info,

                          ARRAY_SIZE(bfin_spi_board_info));

    if (status < 0)

    {

      printk("Error while registering board infor : %d", status);

    }

#endif

  return status;

}

 

arch_initcall(ezkit_init);

 

And this is part of my source file :

 

static int __devinit bfin_spi_tlv_probe(struct spi_device *spi)

{

int ret = 0;

printk("Probing for tlv spi device..");

return ret;

}

 

static struct spi_driver tlv_spi_driver = {

.driver = {

  .name = "tlv-spi",

  .bus = &spi_bus_type,

  .owner = THIS_MODULE,

},

.probe = bfin_spi_tlv_probe,

.remove = __devexit_p(bfin_spi_tlv_remove),

};

 

static int __init bfin_spi_tlv_init(void)

{

int result;

printk("Initiating TLV SPI ...\n");

 

result =  spi_register_driver(&tlv_spi_driver);

if (result < 0)

{

  printk(KERN_WARNING "SPI: can't register driver (%d)\n", result);

  return result;

}

 

 

 

}

 

 

 

 

 

static void __exit bfin_spi_tlv_exit(void)

{

spi_unregister_driver(&tlv_spi_driver);

}

 

module_init(bfin_spi_tlv_init);

module_exit(bfin_spi_tlv_exit);

 

 

 

 

static int __devexit bfin_spi_tlv_remove(struct spi_device *spi)

{

printk(KERN_ALERT "Goodbye SPI\n");

return 0;

}

 

When the kernel starts, I get messages indicating that the init and probe function of spi_bfinxxx.c were called succesfully. I also get an indication that my own init function was called ("Initiating TLV SPI..."). But never an indication of entering the probe function. (And no indication of problems when registering e.g. the driver.)

And when I do a cat  /proc/devices at the root prompt, I don't see any SPI related device. As long as I don't have that device in the list, I don't have to try an open() command, correct ?

 

I'm sure I'm still missing something. You have any idea what ? As your post was quite some time ago, i assume that you meanwhile got the answer to your problem...

 

Thanks!

TranslateQuoteReplyEditDelete

 

 

2008-12-08 07:59:24     Re: Any simple spi example?

Robin Getz (UNITED STATES)

Message: 66503   

 

Filip:

 

New issue == new thread. Don't post the same stuff in more than one place.

Attachments

Outcomes