spi: Add support for the OpenCores SPI controller.
PATCH 1/1 spi: Add support for the OpenCores SPI controller.
This patch adds a platform device driver that supports the OpenCores SPI controller.
The driver expects two resources: an IORESOURCE_MEM resource defining the core's memory-mapped registers and an IORESOURCE_IRQ for the associated interrupt. It also requires a clock, "spi-master-clk", used to compute the clock divider.
--- drivers/spi/Kconfig | 5 + drivers/spi/Makefile | 1 + drivers/spi/spioc.c | 528 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spioc.h | 25 +++ 4 files changed, 559 insertions(+), 0 deletions(-)
drivers/spi/Kconfig +5 -0
@@ -151,6 +151,11 @@ config SPI_MPC83xx technology. This driver uses a simple set of shift registers for data (opposed to the CPM based descriptor model). +config SPI_OCORES + tristate "OpenCores SPI Controller" + help + This enables using the OpenCores SPI controller. + config SPI_OMAP_UWIRE tristate "OMAP1 MicroWire" depends on ARCH_OMAP1
drivers/spi/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o obj-$(CONFIG_SPI_TXX9) += spi_txx9.o obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.o +obj-$(CONFIG_SPI_OCORES) += spioc.o # ... add above this line ... # SPI protocol drivers (device/link on bus)
drivers/spi/spioc.c new file +528 -0
528 lines not on this page · raw message
include/linux/spi/spioc.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* linux/include/linux/spi/spioc.h +* +* Copyright (C) 2007-2008 Avionic Design Development GmbH +* Copyright (C) 2008-2009 Avionic Design GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* Written by Thierry Reding <[email protected]> +*/ + +#ifndef LINUX_SPI_SPIOC_H +#define LINUX_SPI_SPIOC_H + +#include <linux/spi/spi.h> + +struct spioc_info { +s16 bus_num; +u16 num_chipselect; +}; + +#endif /* !LINUX_SPI_SPIOC_H */ +
Signature · 1 line
tg: (cb7b158..) adx/spi/spioc (depends on: adx/master)
Hi Thierry,
Le Thursday 26 March 2009 09:07:53 Thierry Reding, vous avez écrit :
Quoted 7 lines
This patch adds a platform device driver that supports the OpenCores SPI controller.
The driver expects two resources: an
IORESOURCE_MEMresource defining the core's memory-mapped registers and anIORESOURCE_IRQfor the associated interrupt. It also requires a clock, "spi-master-clk", used to compute the clock divider.
Thanks again for submitting this ;)
Quoted 2 lines
Signed-off-by Thierry Reding <[email protected]>
Signature · 4 lines
Best regards, Florian Fainelli Email : [email protected] http://openwrt.org -------------------------------
Hmm ... Open Hardware, Free Software. Sounds like a good match!
This driver has some all-too-common failings though:
(a) doesn't correctly reject invalid device configurations in the setup() method
(b) doesn't correctly reject unsupported per-message options in the transfer() method
(c) the setup() method will trash concurrent transfers, since it wrongly assumes there's only one device
There are other minor nits too.
drivers/spi/spioc.c line 52
Quoted 3 lines · Thierry Reding
drivers/spi/spioc.c new file +3
-0+struct spioc { +struct spi_master *master; +struct spioc_info *info;
Nothing in "info" is really needed after probe(); no point in recording it here.
Quoted 1 line
static void
process_transfers(unsigned long data)
... buggy (by inference), see below
Review
Quoted 2 lines
(quoted diff) +2
-0+static int spioc_setup(struct spi_device *spi) +{
Hmm, you seem to have disregarded the Documentation/spi/spi-summary text describing what this does:
Unless each SPI slave has its own configuration registers, don't change them right away ... otherwise drivers could corrupt I/O that's in progress for other SPI devices.
Because:
drivers/spi/spioc.c line 205
Quoted 3 lines
drivers/spi/spioc.c new file +3
-0+struct spioc *spioc =spi_master_get_devdata (spi->master); +unsigned long clkdiv =0x0000ffff ; +u32 ctrl =spioc_read (spioc,SPIOC_CTRL );
CTRL is a controller-global register, not a per-chipselect one ...
Quoted 20 lines
drivers/spi/spioc.c new file +20
-0+ +/* make sure we're not busy */ + ctrl &= ~CTRL_BUSY ; + +if (!spi->bits_per_word) + spi->bits_per_word =8 ; + +if (spi->mode &SPI_LSB_FIRST ) + ctrl |=CTRL_LSB ; +else + ctrl &= ~CTRL_LSB ; + +/* adapt to clock polarity and phase */ +if (spi->mode &SPI_CPOL ) { +if (spi->mode &SPI_CPHA ) { + ctrl |=CTRL_TXNEG ; + ctrl &= ~CTRL_RXNEG ; + }else { + ctrl &= ~CTRL_TXNEG ; + ctrl |=CTRL_RXNEG ;
drivers/spi/spioc.c line 235
Quoted 10 lines
drivers/spi/spioc.c new file +10
-0+ } + }else { +if (spi->mode &SPI_CPHA ) { + ctrl &= ~CTRL_TXNEG ; + ctrl |=CTRL_RXNEG ; + }else { + ctrl |=CTRL_TXNEG ; + ctrl &= ~CTRL_RXNEG ; + } + }
Notice how you're accepting *all* spi->mode bits, instead of insisting that the only bits set there be ones you support.
Best that you do something along the lines of
/* mask of all SPI options this driver currently handles */ #define MODEBITS (SPI_CPOL|SPI_CPHA|SPI_LSB_FIRST)
if (spi->mode & ~MODEBITS) return -EINVAL;
near the top of this routine.
drivers/spi/spioc.c line 243
Quoted 8 lines
drivers/spi/spioc.c new file +8
-0+ +/* set the clock divider */ +if (spi->max_speed_hz) + clkdiv =DIV_ROUND_UP (clk_get_rate (spioc->clk), +2 * spi->max_speed_hz) -1 ; + +if (clkdiv >0x0000ffff ) + clkdiv =0x0000ffff ;
Shouldn't you just be failing setup() if the slowest clock rate you support is still too fast for this peripheral?
drivers/spi/spioc.c line 246
Quoted 3 lines
drivers/spi/spioc.c new file +3
-0+ +spioc_write (spioc,SPIOC_DIV , clkdiv); +spioc_write (spioc,SPIOC_CTRL , ctrl);
... here you reprogram parameters in use by the current transfer.
Probably what you should do instead is compute the values to be used for those two registers, and save them in a struct referenced through spi_device.controller_state before you start any individual transfer.
However, your process_transfers() currently seems to presume a global setup model; that will need to change. Minimally you should set the transfer parameters for the current device.
And it will need to cope with per-transfer overrides for the word size and bitrate, unless you reject them when messages get submitted.
drivers/spi/spioc.c line 258
Quoted 12 lines
drivers/spi/spioc.c new file +12
-0+ +/* deassert chip-select */ +spioc_chipselect (spioc,NULL ); + +return 0 ; +} + +static int spioc_transfer (struct spi_device *spi,struct spi_message *message) +{ +struct spi_master *master = spi->master; +struct spioc *spioc =spi_master_get_devdata (master); +unsigned long flags;
Here you're accepting all messages, even ones that rely on mechanisms you don't support. You should either implement the per-transfer wordsize, bitrate, and chipselect overrides; or else scan the transfer list of this message to make sure that no transfer requires them.
drivers/spi/spioc.c line 270
Quoted 12 lines
drivers/spi/spioc.c new file +12
-0+ +spin_lock_irqsave (&spioc->lock, flags); + +list_add_tail (&message->queue, &spioc->queue); +queue_work (spioc->workqueue, &spioc->process_messages); + +spin_unlock_irqrestore (&spioc->lock, flags); +return 0 ; +} + +static void spioc_cleanup (struct spi_device *spi) +{
This would be where you should kfree() the struct holding per-device register settings that your setup() should allocate.
Having such NOP methods should be a sign that something is wrong...
drivers/spi/spioc.c line 366
Quoted 9 lines
drivers/spi/spioc.c new file +7
-0+} +static int __devinit spioc_probe (struct platform_device *pdev) +{ + ... + + res =request_mem_region (res->start, res->end - res->start +1 , + res->name);
I think resource_size(resource) should be used here and in the ioremap call below.
Quoted 14 lines
drivers/spi/spioc.c new file +12
-0+if (!res) { +dev_err (&pdev->dev,"unable to request memory region\n" ); +return -ENXIO ; + } + + mmio =ioremap_nocache (res->start, res->end - res->start +1 ); +if (!mmio) { +dev_err (&pdev->dev,"can't remap I/O region\n" ); + retval = -ENXIO ; + goto release; + } + ...
drivers/spi/spioc.c line 395
Quoted 10 lines
drivers/spi/spioc.c new file +10
-0+#ifdef CONFIG_PM +static int spioc_suspend (struct platform_device *pdev,pm_message_t state) +{ +return -ENOSYS ; +} + +static int spioc_resume (struct platform_device *pdev) +{ +return -ENOSYS ; +}
Why are you aborting system suspend transitions instead of just not supporting PM? Better IMO to depend on !PM if this is trying to prevent nasty stuff from happening.
include/linux/spi/spioc.h line 20
Quoted 3 lines
include/linux/spi/spioc.h new file +3
-0+ +struct spioc_info { +s16 bus_num;
Better IMO to just use platform_device.id for this.
include/linux/spi/spioc.h line 25
Quoted 6 lines
include/linux/spi/spioc.h new file +5
-0+ u16 num_chipselect; +}; + +#endif /* !LINUX_SPI_SPIOC_H */ +
------------------------------------------------------------------------------
PATCH v2 1/1 spi: Add support for the OpenCores SPI controller.
This patch adds a platform device driver that supports the OpenCores SPI controller.
The driver expects two resources: an IORESOURCE_MEM resource defining the core's memory-mapped registers and an IORESOURCE_IRQ for the associated interrupt. It also requires a clock, "spi-master-clk", used to compute the clock divider.
--- drivers/spi/Kconfig | 5 + drivers/spi/Makefile | 1 + drivers/spi/spioc.c | 633 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 639 insertions(+), 0 deletions(-)
drivers/spi/Kconfig +5 -0
@@ -151,6 +151,11 @@ config SPI_MPC83xx technology. This driver uses a simple set of shift registers for data (opposed to the CPM based descriptor model). +config SPI_OCORES + tristate "OpenCores SPI Controller" + help + This enables using the OpenCores SPI controller. + config SPI_OMAP_UWIRE tristate "OMAP1 MicroWire" depends on ARCH_OMAP1
drivers/spi/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o obj-$(CONFIG_SPI_TXX9) += spi_txx9.o obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.o +obj-$(CONFIG_SPI_OCORES) += spioc.o # ... add above this line ... # SPI protocol drivers (device/link on bus)
drivers/spi/spioc.c new file +633 -0
633 lines not on this page · raw message
Signature · 1 line
tg: (f2deb5b..) adx/spi/spioc (depends on: adx/master)
Quoted 9 lines · Thierry Reding
This patch adds a platform device driver that supports the OpenCores SPI controller.
The driver expects two resources: an
IORESOURCE_MEMresource defining the core's memory-mapped registers and anIORESOURCE_IRQfor the associated interrupt. It also requires a clock, "spi-master-clk", used to compute the clock divider.Signed-off-by Thierry Reding <[email protected]>
[snip]
This second version is pretty much a rewrite. Some notes about the most important changes:
* uses per-chip states to allow more slaves to use the controller concurrently
* rejects invalid device configurations during setup
* rejects invalid per-message and per-transfer options
* queues messages so that they can be processed one after another
- this also provides for a way to handle power-management
* omits the spioc.h (and with it the platform data structure):
- uses the platform_device.id for the bus number
- always uses 8 chipselects because that's the maximum that the core supports
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Thierry
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
Quoted 1 line · Thierry Reding
This second version is pretty much a rewrite.
That happens sometimes...
Quoted 13 lines
Some notes about the most
important changes:* uses per-chip states to allow more slaves to use the controller concurrently
* rejects invalid device configurations during setup
* rejects invalid per-message and per-transfer options
* queues messages so that they can be processed one after another
- this also provides for a way to handle power-management
* omits thespioc.h(and with it the platform data structure):
- uses the platform_device.id for the bus number
- always uses 8 chipselects because that's the maximum that the core supports
All that sounds good.
Quoted 3 lines
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Is this the http://www.opencores.org/?do=project&who=spi core? Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
Quoted 20 lines · David Brownell
Quoted 1 line · Thierry Reding
This second version is pretty much a rewrite.
That happens sometimes...
Quoted 13 lines
Some notes about the most
important changes:* uses per-chip states to allow more slaves to use the controller concurrently
* rejects invalid device configurations during setup
* rejects invalid per-message and per-transfer options
* queues messages so that they can be processed one after another
- this also provides for a way to handle power-management
* omits thespioc.h(and with it the platform data structure):
- uses the platform_device.id for the bus number
- always uses 8 chipselects because that's the maximum that the core supports
Quoted 8 lines
All that sounds good.
Quoted 3 lines
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
That summary seems out-dated. The variable length of transfer word is actually the maximum length of a single transfer and is 128 bits in the latest version. So you get 4 registers, each 32 bits wide into which you program the data you want to transfer. Then you set the number of bits of that transfer so the core knows which registers and what bits of those registers to shift out serially.
I'm not sure whether this is supposed to be the same as the word size. If it is it would mean that a single transfer can always only transfer one word. Which is kind of inefficient, I would think.
Thierry
Le Tuesday 28 April 2009 14:20:11 Thierry Reding, vous avez écrit :
Quoted 22 lines · David Brownell
Quoted 21 lines · Thierry Reding
Quoted 1 line
This second version is pretty much a rewrite.
That happens sometimes...
Quoted 13 lines
Some notes about the most
important changes:* uses per-chip states to allow more slaves to use the controller concurrently
* rejects invalid device configurations during setup
* rejects invalid per-message and per-transfer options
* queues messages so that they can be processed one after another
- this also provides for a way to handle power-management
* omits thespioc.h(and with it the platform data structure):
- uses the platform_device.id for the bus number
- always uses 8 chipselects because that's the maximum that the core supportsAll that sounds good.
Quoted 12 lines
Quoted 6 lines
Quoted 4 lines
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
This is indeed configured at synthesis time.
Quoted 7 lines
That summary seems out-dated. The variable length of transfer word is actually the maximum length of a single transfer and is 128 bits in the latest version. So you get 4 registers, each 32 bits wide into which you program the data you want to transfer. Then you set the number of bits of that transfer so the core knows which registers and what bits of those registers to shift out serially.
Signature · 4 lines
Best regards, Florian Fainelli Email : [email protected] http://openwrt.org -------------------------------
Quoted 9 lines · Florian Fainelli
Quoted 7 lines
Quoted 1 line
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
This is indeed configured at synthesis time.
Now I'm confused again. Thierry says (below) that the number of bits can be set per-"transfer".
Now, I can easily understand that a *maximum* would be configured at synthesis time ... if there's a 32-bit CPU or DMA engine, it'd make very limited sense to interact using 128-bit I/O words.
Is there both a configurable maximum, *and* a word-size setting that can be changed on the fly? That's what I would expect; it's what most other designs do. The only time I've seen fixed "you must use N-bit words" designs is on cost-eradicated 8-bit microcontrollers.
- Dave
Quoted 6 lines
Quoted 6 lines
That summary seems out-dated. The variable length of transfer word is actually the maximum length of a single transfer and is 128 bits in the latest version. So you get 4 registers, each 32 bits wide into which you program the data you want to transfer. Then you set the number of bits of that transfer so the core knows which registers and what bits of those registers to shift out serially.
Quoted 8 lines · Thierry Reding
Quoted 5 lines
Quoted 3 lines
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 7 lines
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
That summary seems out-dated. The variable length of transfer word is actually the maximum length of a single transfer and is 128 bits in the latest version.
So long as they don't couple "transfer" with chipselect activation and then de-activation, that's normal.
128 bits is pretty big, but it should make no difference to the slave whether the host thinks of its data as one 128-bit word, sixteen 8-bit words, one 9-bit word followed by a 119-bit one, or whatever.
Unless the design is broken, so that you can't send words without flapping the chipselect. That would surprise me.
Quoted 3 lines
I'm not sure whether this is supposed to be the same as the word size. If it is it would mean that a single transfer can always only transfer one word. Which is kind of inefficient, I would think.
A "struct spi_transfer" should include a arbitrary number of such words. If the word size is over 8 bits, all the usual byte ordering concerns come into play. You may optimize the register I/O however you like, so long as the bits on the wire come out in the right sequence.
Ignoring clock options, the canonical SPI transfer starts by activating a chip select, then clocking out an arbitrary number of bits (clocking *in* one bit for each one clocked out), and then de-activating chipselect. Those bits are usually viewed as a sequence of various-size words ... not necesarily all the same size. Example, some LCD controllers use 9-bit command words followed by pixel data encoded in bytes.
Now, how the bits get to/from the controller is an area where silicon can optimize. For example, it's common to offload that work to a DMA controller that can do burst operations to keep the data bus efficiency high ... and to have a FIFO in there, so those bursts can be bigger than the word size.
- Dave
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
Quoted 8 lines · Thierry Reding
Quoted 5 lines
Quoted 3 lines
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 7 lines
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
That summary seems out-dated. The variable length of transfer word is actually the maximum length of a single transfer and is 128 bits in the latest version.
So long as they don't couple "transfer" with chipselect activation and then de-activation, that's normal.
128 bits is pretty big, but it should make no difference to the slave whether the host thinks of its data as one 128-bit word, sixteen 8-bit words, one 9-bit word followed by a 119-bit one, or whatever.
Unless the design is broken, so that you can't send words without flapping the chipselect. That would surprise me.
Quoted 3 lines
I'm not sure whether this is supposed to be the same as the word size. If it is it would mean that a single transfer can always only transfer one word. Which is kind of inefficient, I would think.
A "struct spi_transfer" should include a arbitrary number of such words. If the word size is over 8 bits, all the usual byte ordering concerns come into play. You may optimize the register I/O however you like, so long as the bits on the wire come out in the right sequence.
Ignoring clock options, the canonical SPI transfer starts by activating a chip select, then clocking out an arbitrary number of bits (clocking *in* one bit for each one clocked out), and then de-activating chipselect. Those bits are usually viewed as a sequence of various-size words ... not necesarily all the same size. Example, some LCD controllers use 9-bit command words followed by pixel data encoded in bytes.
Now, how the bits get to/from the controller is an area where silicon can optimize. For example, it's common to offload that work to a DMA controller that can do burst operations to keep the data bus efficiency high ... and to have a FIFO in there, so those bursts can be bigger than the word size.
- Dave
Quoted 20 lines · David Brownell
Quoted 8 lines · Thierry Reding
Quoted 5 lines
Quoted 3 lines
I couldn't really find a way to implement per-transfer overrides for the word size because the controller simply has no concept of word sizes. Is it in such cases still necessary to hardwire the word size to 8 bits?
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 7 lines
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
That summary seems out-dated. The variable length of transfer word is actually the maximum length of a single transfer and is 128 bits in the latest version.
So long as they don't couple "transfer" with chipselect activation and then de-activation, that's normal.
Quoted 6 lines
128 bits is pretty big, but it should make no difference to the slave whether the host thinks of its data as one 128-bit word, sixteen 8-bit words, one 9-bit word followed by a 119-bit one, or whatever.
Unless the design is broken, so that you can't send words without flapping the chipselect. That would surprise me.
So far, what I've been doing is just copy the transmission buffer in blocks of 16 bytes byte-by-byte to the transmission registers (concatenating groups of four bytes), then start the transfer. After the transfer I copy the bytes back in the same manner to the receive buffer. I was assuming that the buffers would be in the correct byte order at that point anyway.
This core actually allows manually setting the chipselect. It also has a mode that automatically sets or clears the chipselect for each single "transfer" (meaning up to those 128 bits). But as you say, that wouldn't be normal behavior and breaks things.
Quoted 9 lines
Quoted 3 lines
I'm not sure whether this is supposed to be the same as the word size. If it is it would mean that a single transfer can always only transfer one word. Which is kind of inefficient, I would think.
A "struct
spi_transfer" should include a arbitrary number of such words. If the word size is over 8 bits, all the usual byte ordering concerns come into play. You may optimize the register I/O however you like, so long as the bits on the wire come out in the right sequence.
What byte ordering are the transmit and receive buffers supposed to be in, then? Native? Always big endian?
Quoted 8 lines
Ignoring clock options, the canonical SPI transfer starts by activating a chip select, then clocking out an arbitrary number of bits (clocking *in* one bit for each one clocked out), and then de-activating chipselect. Those bits are usually viewed as a sequence of various-size words ... not necesarily all the same size. Example, some LCD controllers use 9-bit command words followed by pixel data encoded in bytes.
Quoted 5 lines
Now, how the bits get to/from the controller is an area where silicon can optimize. For example, it's common to offload that work to a DMA controller that can do burst operations to keep the data bus efficiency high ... and to have a FIFO in there, so those bursts can be bigger than the word size.
I haven't experimented with using DMA transfers to this particular core because there's currently no support for the generic DMA API on the CPU we use.
Quoted 1 line
- Dave
Thierry
Quoted 9 lines · David Brownell
Quoted 8 lines · Florian Fainelli
Quoted 7 lines
Quoted 1 line
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
Quoted 8 lines
Quoted 1 line
This is indeed configured at synthesis time.
Now I'm confused again. Thierry says (below) that the number of bits can be set per-"transfer".
Now, I can easily understand that a *maximum* would be configured at synthesis time ... if there's a 32-bit CPU or DMA engine, it'd make very limited sense to interact using 128-bit I/O words.
I can't really comment on the synthesis because I'm not involved with that part. What I was saying that the core provides a field in the control register which defines the number of bits to transfer from/to the transmit/receive registers. The maximum number of bits that can be specified in this way is 128.
Quoted 4 lines
Is there both a configurable maximum, *and* a word-size setting that can be changed on the fly? That's what I would expect; it's what most other designs do. The only time I've seen fixed "you must use N-bit words" designs is on cost-eradicated 8-bit microcontrollers.
Perhaps that maximum number of bits that can be set through the control register is what can be configured at synthesis time.
Quoted 1 line
- Dave
Thierry
Le Wednesday 29 April 2009 08:31:04 Thierry Reding, vous avez écrit :
Quoted 10 lines · David Brownell
Quoted 9 lines · Florian Fainelli
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Is this the http://www.opencores.org/?do=project&who=spi core?
Yes, it is.
Quoted 3 lines
Its summary says "Variable length of transfer word up to 32 bits"; does that mean "configurable when core is synthesized" instead of truly "variable"?
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
This is indeed configured at synthesis time.
Now I'm confused again. Thierry says (below) that the number of bits can be set per-"transfer".
Now, I can easily understand that a *maximum* would be configured at synthesis time ... if there's a 32-bit CPU or DMA engine, it'd make very limited sense to interact using 128-bit I/O words.
The maximum size of the FIFO is configured at synthesis time should have made this clear before, sorry for the confusion.
Quoted 6 lines
I can't really comment on the synthesis because I'm not involved with that part. What I was saying that the core provides a field in the control register which defines the number of bits to transfer from/to the transmit/receive registers. The maximum number of bits that can be specified in this way is 128.
Yes, which matches the FIFO size configured in the IP at synthesis time.
Quoted 8 lines
Quoted 5 lines
Is there both a configurable maximum, *and* a word-size setting that can be changed on the fly? That's what I would expect; it's what most other designs do. The only time I've seen fixed "you must use N-bit words" designs is on cost-eradicated 8-bit microcontrollers.
Perhaps that maximum number of bits that can be set through the control register is what can be configured at synthesis time.
Provided that your FIFO is 128-bits, you can of course ask the core to do up to the FIFO-size transfers for instance provided that you do not exceed the size of the FIFO. The later can obviously not be changed on-the-fly since physical resources of the FPGA for this should be reserved at synthesis time. Of course, one could use partial reconfiguration to increase the size, but that's slightly off-topic ;)
Signature · 4 lines
Best regards, Florian Fainelli Email : [email protected] http://openwrt.org -------------------------------