-
Notifications
You must be signed in to change notification settings - Fork 7.3k
SPI: Add API support for DDR, Dual, Quad and Octal modes #39991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
46cfc21
to
c25095e
Compare
@teburd interesting, I wrongly assumed that d/q/o modes were somewhat standardized across manufacturers and thus took only one hardware spec as a reference. I fail to see any use case that would require changing modes within the transaction but better be prepared (after all, devices using these modes - spi flash aside - are yet to become a common thing). |
81f9cf7
to
97270b5
Compare
I did not see a flag for data phase number of pin. Is the data phase using the same number of pins as the address phase? |
I looked briefly at the SAM QSPI and it seems the flags match better there. For SAM QSPI a seperate QSPI_IAR (Instruction Address Register) is available which can be used to setup an optional instruction frame before reading/writing data to the QSPI lines. It offers optional fields that may be included for an instruction (8 bits), address (24 or 32 bit), and option (4-8 bits) written using 1 to 4 datalines each followed by reading/writing data in single/dual/quad spi. I'm not entirely sure this supports all the flags but I think at least some subset of the flags here would work. Actually the register set for it looks like a small extension of the normal sam spi IP. |
As per-controller, it does (edit: no it does NOT... ) not have to support all the flags, it's fine. My concern is that the API should enable (most of) all the controllers (to a certain generalization extent).
There are flags for this. See SPI_EM_CMD_STD or SPI_EM_ADDR_STD for instance. It is either one line, or the whole set of lines.
The effort with this PR is to provide dual/quad/octal API exposed by generic SPI controllers, i.e. ones that can be wired to any type of SPI devices. Flash included BUT: I originally added flags for flash specific optimizations but it was not as good as doing a qspi flash driver from performance/flexibility point of view. I am not so sure it's worth the generalization effort to include flash idiosyncrasies, moreover that SPI controllers offers optimizations at different level compared to others. We could perhaps expose something as useful as XIP, but fine tuning options for flash... not sure. |
@tbursztyka can you implement this in a driver and demonstrate its use in an application? |
Sure, I would need to find some time for it. But first, I need to find a platform that has a generic SPI controller capable of supporting dual/quad/octal as well, and a device to make transactions with. |
Can you move this into the draft state until then? |
@tbursztyka - this is a really interesting topic. I wonder if it might even be possible to list some relatively simple SPI peripherals that support each mode, and then maybe we could look into |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
dev-review: @tbursztyka - do you have plans to move forward with this? |
@tbursztyka ping |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Reopening for further investigation related to #65659 |
These modes are present on more advanced and recent SPI controller. Though dual, quand and octal were present on configuration side already, it could not work with the standard command/address/data format which is now addressed via these changes. Also adding a way to make use of hardware optimizations for SPI flash JEDEC devices which seem to be largely present in various SPI controllers. Note, however, that these new SPI API modes are not meant to be used by QSPI flash controllers: for these, a dedicated flash controller driver will still be the preferred solution. Fixes zephyrproject-rtos#17902 Signed-off-by: Tomasz Bursztyka <[email protected]>
97270b5
to
f7c7657
Compare
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
(#20564 could not be reopened, so creating a new one.)
SPI extended modes
DDR: Double Data Rate
Dual: Dual MOSI lines
Quad: Quad MOSI lines
Octal: Octal MOSI lines
DQO: Dual Quand Octal
These modes comprise: DDR, Dual, Quad, Octal and the
specific command/address/data format
Uses cases
Design
Besides the operation attribute of struct spi_config, all goes through
a newly added u16_t attribute in struct spi_buf: flags.
Firts 9 bits are containing config flags, next 2 bits are the command
length (set to 0 if the cmd/addr format is not in use) and the last 5 bits
are the address length (set to 0 if the addr is not present or if the cmd/addr
format is not in use). Command length is a multiple of 4 (4, 8, 12, 16, ...)
and address length is a multiple of 2 factor 4 (4, 8, 16 ...)
The good side of this approach: it does not require changes on any existing SPI controller
drivers nor SPI device drivers.
The drawback: if only one SPI controller can support these modes, it adds up
16bits to each and every struct spi_buf in the system. Hopefully this is still
a relatively small amount of data (looks like uncommon for a driver to use more
than 2 struct spi_buf, and if does it will usually be due to a lack of factorization).
SPI configuration
Basic cmd/addr format transaction usage
Note: 8bits length cmd/addr are used for these examples, but it's trivial to
use other size.
TX only:
RX added
In case no address is given
etc ...