SlideShare a Scribd company logo
ELC, May 2014
What’s going on with SPI?
• Hardware overview
• Framework overview
• Recent enhancements
• Future plans
Overview
Simple bidirectional serial bus with four signals:
• Master Out Slave In (MOSI)
• Master In Slave Out (MISO)
• Clock
• Chip select
• Little endian byte ordering for words
What is SPI?
Comparable with I2C:
• Four wires instead of two
• Typically 1-2 orders of magnitude faster
• Full duplex
• Very simple implementation
Applications
• Flash
• Mixed signal ICs
• DSPs
What is SPI?
• No support at all, using GPIOs
• Very slow and inefficient
• Commonly used for chip select
Controller hardware
• PIO based FIFOs
• Less slow
• Requires CPU access every word
• DMA based FIFOs
• Less work for CPU
• Higher setup overhead
• Faster for large blocks of data
• Dual and quad mode
• Extra data lines, mainly used with flash (v3.12)
● Specialised flash controllers
• No support at all, using GPIOs
• Very slow and inefficient
• Commonly used for chip select
• PIO based FIFOs
• Less slow
• Requires CPU access every word
• DMA based FIFOs
• Less work for CPU
• Higher setup overhead
• Faster for large blocks of data
• Dual and quad mode
• Extra data lines, mainly used with flash (v3.12)
• Specialised flash controllers
Controller hardware
Originally contributed by David Brownell
• Merged in 2.6.16 (released March 2006)
• Largely unchanged until recently
Standard device model bus:
• Controllers and devices
• Device registration via machine driver/firmware
Basic software stack
Simple message based interface for devices
• List of transfers, for scatter/gather and mixed read/write
• Some settings can change per transfer/message
• Optionally asynchronous
Device interface
struct spi_transfer {
const void*tx_buf;
void *rx_buf;
unsigned len;
};
void spi_message_init(struct spi_message *m);
void spi_message_add_tail(struct spi_transfer *t,
struct spi_message *m);
int spi_async(struct spi_device *spi, struct
spi_message *message);
int spi_sync(struct spi_device *spi,
struct spi_message *message);
Device interface
Very basic:
int (*transfer)(struct spi_device *spi,
struct spi_message *mesg);
Basic driver interface
Executes in atomic context!
Not just for bitbanging:
int (*setup_transfer)(struct spi_device *spi,
struct spi_transfer *t);
void (*chipselect)(struct spi_device *spi, int is_on);
int (*txrx_bufs)(struct spi_device *spi,
struct spi_transfer *t);
• Factors out logic to do with transfer list
• Can even support DMA
“Bitbang” driver framework
• No code reuse outside of bitbang
• Lots of wheels of varying shapes
• Good ideas need to be copied
What’s missing?
Many ways of specifying/validation same information
• Selecting a transfer speed
• Bits per word settings
• Overriding these per transfer
• Validating buffer sizes
Standard parameter checking and handling
int (*prepare_transfer_hardware)(struct spi_master *m);
int (*transfer_one_message)(struct spi_master *m,
struct spi_message *m);
int (*unprepare_transfer_hardware)(struct spi_master *m);
• Factors out code
• Standard synchronisation with suspend
• Standard runtime PM implementation
• Standard support for managing priority of pump
Contributed by Linus Walleij, merged in v3.4 (May 2012)
Message queue
Moves more logic from spi_bitbang into core:
int (*prepare_message)(struct spi_master *master,
struct spi_message *message);
int (*unprepare_message)(struct spi_master *master,
struct spi_message *message);
void (*set_cs)(struct spi_device *spi, bool enable);
int (*transfer_one)(struct spi_master *master,
struct spi_device *spi,
struct spi_transfer *transfer);
Merged in v3.13
Standard message parsing
Most drivers only handled some cases:
• Buffers need to be mapped before DMA
• Buffers may not be physically contiguous
• vmalloc()ed addresses need different mapping
Drivers provide a callback to check for DMA:
bool (*can_dma)(struct spi_master *master,
struct spi_device *spi,
struct spi_transfer *xfer);
If true passed sg_lists instead of buffers
Standard DMA mapping
• Extra data lines for higher speed
• Capability set when registering device
• Enabled per-transfer by device drivers
Contributed by Wang Yuhang, merged in v3.12
Dual and quad modes
What’s next?
• Handling controller chip select
• Standard way to set in DT
Standard GPIO chip select
Latency - spi_sync()
Device driver SPI thread Hardware/IRQ
Queue transfer
Start transfer
Wait...
Wait...
Start transfer
Wait...
Wake SPI
Schedule
Wake driver
Schedule
Return
Schedule
Latency - spi_async()
Device driver SPI thread Hardware/IRQ
Queue transfer
Start transfer
Wait...
Wait...
Start transfer
Wait...
Wake SPI
Schedule
Wake driver
Schedule
Return
Schedule
Start transfer Start transfer
Latency - complete in IRQ
Device driver SPI thread Hardware/IRQ
Queue transfer
Start transfer
Wait...
Wait...
Start transfer
Wait...
Wake driver
Schedule
Return
Schedule
Schedule
Latency - start immediately
Device driver SPI thread Hardware/IRQ
Queue transfer
Wait...
Start transfer
Wait...
Wake SPI
Wake driver
Schedule
Return
Start transfer
• Do DMA mapping while prior transfer runs
• Coalesce transfers and use hardware scatter/gather
Latency
• Messages validated once and used several times
• Saves iterating and checking
• Allows drivers to keep buffers DMA mapped
• Mainly for very high bandwidth applications
Work being done by Martin Sperl
Pre-validated messages
• Use DMA transfers to set chip select and parameters
• Requires dmaengine and gpiolib enhancements
• Extremely low CPU overhead, runs from interrupt
Work being done by Martin Sperl
Fully DMA driven queues
• Simple bus, not so simple software
• Much more active development recently
• New hardware
• More demanding performance requirements
Summary
More about Linaro: http://www.linaro.org/about/
More about Linaro engineering: http://www.linaro.org/engineering/
How to join: http://www.linaro.org/about/how-to-join
Linaro members: www.linaro.org/members

More Related Content

PDF
PX4 Setup Workshop
PDF
Autonomous Drones Architecture - Initial proposal
PDF
My Multirotor Projects
PDF
BKK16-303 96Boards - TV Platform
PPTX
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
PDF
PX4 Seminar 02
PPTX
Peripherals and interfacing
PDF
Q4.11: ARM Technology Update Plenary
PX4 Setup Workshop
Autonomous Drones Architecture - Initial proposal
My Multirotor Projects
BKK16-303 96Boards - TV Platform
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
PX4 Seminar 02
Peripherals and interfacing
Q4.11: ARM Technology Update Plenary

What's hot (20)

PDF
MIPI DevCon 2016: Accelerating UFS and MIPI UniPro Interoperability Testing
PPTX
Serial connectors, Protocols , USB (universal serial bus)
PDF
PX4 Seminar 01
PPTX
Block ciphers & public key cryptography
PDF
Kernel Recipes 2015: Greybus
PDF
LAS16-TR06: Remoteproc & rpmsg development
PPT
07 input output
PDF
LAS16-400: Mini Conference 3 AOSP (Session 1)
PDF
Communication Protocols (UART, SPI,I2C)
PPT
Embedded c & working with avr studio
PPTX
TMS320DM8148 Embedded Linux
PPTX
NXP IMX6 Processor - Embedded Linux
PPT
17 registers
PPTX
Computer arch
PDF
Lecture 04 branch call and time delay
PPTX
PPT
I2C Protocol
PPTX
TMS20DM8148 Embedded Linux Session II
PDF
Linux on ARM 64-bit Architecture
PPT
MIPI DevCon 2016: Accelerating UFS and MIPI UniPro Interoperability Testing
Serial connectors, Protocols , USB (universal serial bus)
PX4 Seminar 01
Block ciphers & public key cryptography
Kernel Recipes 2015: Greybus
LAS16-TR06: Remoteproc & rpmsg development
07 input output
LAS16-400: Mini Conference 3 AOSP (Session 1)
Communication Protocols (UART, SPI,I2C)
Embedded c & working with avr studio
TMS320DM8148 Embedded Linux
NXP IMX6 Processor - Embedded Linux
17 registers
Computer arch
Lecture 04 branch call and time delay
I2C Protocol
TMS20DM8148 Embedded Linux Session II
Linux on ARM 64-bit Architecture
Ad

Similar to What's going on with SPI (20)

DOCX
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
PPT
Serial Peripheral Interface(SPI)
PPTX
SPI introduction(Serial Peripheral Interface)
PPTX
Spi in arm7(lpc2148)
PPTX
Serial Peripheral Interface (SPI).pptx
PPTX
Serial Peripheral Interface
PDF
Serial Peripheral Interface Design for Advanced Microcontroller Bus Architect...
PPTX
Designing of fifo and serial peripheral interface protocol using Verilog HDL
PPTX
LPC2148 SPI (Serial Peripheral Interface).pptx
PPT
Spi (1)
PDF
Serial Peripheral Interface
PDF
SPI Protocol
PPT
SPI.ppt
PDF
This Document gives a complete understanding of the I3C protocol which is int...
PPTX
Serial Communication - Serial Peripheral Interface
PPTX
Serial peripheral Interface - Embedded System Protocol
PDF
Spi drivers
PPT
Overview Study on PIC32MX3XX / 4XX 32-Bit Controller
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
Serial Peripheral Interface(SPI)
SPI introduction(Serial Peripheral Interface)
Spi in arm7(lpc2148)
Serial Peripheral Interface (SPI).pptx
Serial Peripheral Interface
Serial Peripheral Interface Design for Advanced Microcontroller Bus Architect...
Designing of fifo and serial peripheral interface protocol using Verilog HDL
LPC2148 SPI (Serial Peripheral Interface).pptx
Spi (1)
Serial Peripheral Interface
SPI Protocol
SPI.ppt
This Document gives a complete understanding of the I3C protocol which is int...
Serial Communication - Serial Peripheral Interface
Serial peripheral Interface - Embedded System Protocol
Spi drivers
Overview Study on PIC32MX3XX / 4XX 32-Bit Controller
Ad

More from Mark Brown (6)

PDF
Kernelci.org needs you!
PDF
Regulators learning to play with others
PDF
LCU13: Linaro Stable Kernel
PDF
LSK 13.07
PDF
Linux audio for smartphones
PDF
regmap: The power of subsystems and abstractions
Kernelci.org needs you!
Regulators learning to play with others
LCU13: Linaro Stable Kernel
LSK 13.07
Linux audio for smartphones
regmap: The power of subsystems and abstractions

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Understanding_Digital_Forensics_Presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf

What's going on with SPI

  • 1. ELC, May 2014 What’s going on with SPI?
  • 2. • Hardware overview • Framework overview • Recent enhancements • Future plans Overview
  • 3. Simple bidirectional serial bus with four signals: • Master Out Slave In (MOSI) • Master In Slave Out (MISO) • Clock • Chip select • Little endian byte ordering for words What is SPI?
  • 4. Comparable with I2C: • Four wires instead of two • Typically 1-2 orders of magnitude faster • Full duplex • Very simple implementation Applications • Flash • Mixed signal ICs • DSPs What is SPI?
  • 5. • No support at all, using GPIOs • Very slow and inefficient • Commonly used for chip select Controller hardware • PIO based FIFOs • Less slow • Requires CPU access every word • DMA based FIFOs • Less work for CPU • Higher setup overhead • Faster for large blocks of data • Dual and quad mode • Extra data lines, mainly used with flash (v3.12) ● Specialised flash controllers
  • 6. • No support at all, using GPIOs • Very slow and inefficient • Commonly used for chip select • PIO based FIFOs • Less slow • Requires CPU access every word • DMA based FIFOs • Less work for CPU • Higher setup overhead • Faster for large blocks of data • Dual and quad mode • Extra data lines, mainly used with flash (v3.12) • Specialised flash controllers Controller hardware
  • 7. Originally contributed by David Brownell • Merged in 2.6.16 (released March 2006) • Largely unchanged until recently Standard device model bus: • Controllers and devices • Device registration via machine driver/firmware Basic software stack
  • 8. Simple message based interface for devices • List of transfers, for scatter/gather and mixed read/write • Some settings can change per transfer/message • Optionally asynchronous Device interface
  • 9. struct spi_transfer { const void*tx_buf; void *rx_buf; unsigned len; }; void spi_message_init(struct spi_message *m); void spi_message_add_tail(struct spi_transfer *t, struct spi_message *m); int spi_async(struct spi_device *spi, struct spi_message *message); int spi_sync(struct spi_device *spi, struct spi_message *message); Device interface
  • 10. Very basic: int (*transfer)(struct spi_device *spi, struct spi_message *mesg); Basic driver interface Executes in atomic context!
  • 11. Not just for bitbanging: int (*setup_transfer)(struct spi_device *spi, struct spi_transfer *t); void (*chipselect)(struct spi_device *spi, int is_on); int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t); • Factors out logic to do with transfer list • Can even support DMA “Bitbang” driver framework
  • 12. • No code reuse outside of bitbang • Lots of wheels of varying shapes • Good ideas need to be copied What’s missing?
  • 13. Many ways of specifying/validation same information • Selecting a transfer speed • Bits per word settings • Overriding these per transfer • Validating buffer sizes Standard parameter checking and handling
  • 14. int (*prepare_transfer_hardware)(struct spi_master *m); int (*transfer_one_message)(struct spi_master *m, struct spi_message *m); int (*unprepare_transfer_hardware)(struct spi_master *m); • Factors out code • Standard synchronisation with suspend • Standard runtime PM implementation • Standard support for managing priority of pump Contributed by Linus Walleij, merged in v3.4 (May 2012) Message queue
  • 15. Moves more logic from spi_bitbang into core: int (*prepare_message)(struct spi_master *master, struct spi_message *message); int (*unprepare_message)(struct spi_master *master, struct spi_message *message); void (*set_cs)(struct spi_device *spi, bool enable); int (*transfer_one)(struct spi_master *master, struct spi_device *spi, struct spi_transfer *transfer); Merged in v3.13 Standard message parsing
  • 16. Most drivers only handled some cases: • Buffers need to be mapped before DMA • Buffers may not be physically contiguous • vmalloc()ed addresses need different mapping Drivers provide a callback to check for DMA: bool (*can_dma)(struct spi_master *master, struct spi_device *spi, struct spi_transfer *xfer); If true passed sg_lists instead of buffers Standard DMA mapping
  • 17. • Extra data lines for higher speed • Capability set when registering device • Enabled per-transfer by device drivers Contributed by Wang Yuhang, merged in v3.12 Dual and quad modes
  • 19. • Handling controller chip select • Standard way to set in DT Standard GPIO chip select
  • 20. Latency - spi_sync() Device driver SPI thread Hardware/IRQ Queue transfer Start transfer Wait... Wait... Start transfer Wait... Wake SPI Schedule Wake driver Schedule Return Schedule
  • 21. Latency - spi_async() Device driver SPI thread Hardware/IRQ Queue transfer Start transfer Wait... Wait... Start transfer Wait... Wake SPI Schedule Wake driver Schedule Return Schedule Start transfer Start transfer
  • 22. Latency - complete in IRQ Device driver SPI thread Hardware/IRQ Queue transfer Start transfer Wait... Wait... Start transfer Wait... Wake driver Schedule Return Schedule Schedule
  • 23. Latency - start immediately Device driver SPI thread Hardware/IRQ Queue transfer Wait... Start transfer Wait... Wake SPI Wake driver Schedule Return Start transfer
  • 24. • Do DMA mapping while prior transfer runs • Coalesce transfers and use hardware scatter/gather Latency
  • 25. • Messages validated once and used several times • Saves iterating and checking • Allows drivers to keep buffers DMA mapped • Mainly for very high bandwidth applications Work being done by Martin Sperl Pre-validated messages
  • 26. • Use DMA transfers to set chip select and parameters • Requires dmaengine and gpiolib enhancements • Extremely low CPU overhead, runs from interrupt Work being done by Martin Sperl Fully DMA driven queues
  • 27. • Simple bus, not so simple software • Much more active development recently • New hardware • More demanding performance requirements Summary
  • 28. More about Linaro: http://www.linaro.org/about/ More about Linaro engineering: http://www.linaro.org/engineering/ How to join: http://www.linaro.org/about/how-to-join Linaro members: www.linaro.org/members