SlideShare a Scribd company logo
1 of 20
© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Serial Peripheral Interface (SPI) Drivers
2© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
SPI Prologue
SPI Framework
SPI Framework Components
SPI Client Driver
3© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Prologue
Suitable for small slow devices
SPI is a 4-wire protocol unlike I2
C
Apart from Serial Clock, Data Lines are 2
And an additional Chip Select
4© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Protocol
Memory Memory
0 1 2 3 5 6 7 0 1 2 3 5 6 7
SCLK
MISO
MOSI
CS
Master Slave
5© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Character Driver Framework
User Space
/dev/spi0
cat, echo
my_open() my_read() my_write()
Char Driver
Low Level
SPI Driver
spi_rw() test.c, s1.c
App
open(), read(), write()
6© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
AM335X Registers
Module Control Register
For configuring the SPI interface
Single / Multi channel, Master / Slave, Chip select pins
Channel Configuration Register
Used to configure the SPI channel (0-3)
Clock Divider, FIFO for Rx / TX, Pins for TX / RX, DMA RX / TX, SPI Mode (Full
Duplex, Half Duplex), Word Length, SPI Mode
Channel Status Register
Status information for channel (0–3)
RX / TX FIFO Full / Empty
Channel Control Register
Enabling / Disabling the channel
7© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
AM335X SPI APIs
omap2_mcspi_set_enable(struct omap2_mcspi *, int enable)
Enable / Disable the channel
int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned
long bit)
Wait for register bit to set
__raw_writel(ch, tx_reg)
For writing into tx_reg
char ch = __raw_readl(rx_reg)
For reading rx_reg
8© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Framework
spi.c – Implements the SPI core layer
include/linux/spi/spi.h
spidev.c – Provides the char interface for spi
devices
include/linux/spi/spidev.h
spi-omap2-mcspi – Controller driver for omap
based chips
9© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Framework
SPI Core
driver/spi/spi.c
mcp320x.c
drivers/iio/adc
SPI based ADC
driver
SPI Client Driver
m25p80.c
drivers/mtd/
SPI based Flash
driver
spi-omap2-mcspi.c
omap SPI Adapter
Driver
atmel-spi.c
Atmel SPI Adapter
Driver
spi-imx.c
IMX SPI Adapter
Driver
spidev.c
drivers/spi
Char driver for
SPI
Industrial IO
Framework
rtc-ds1505.c
drivers/rtc
SPI based RTC
driver
MTD
Framework
RTC
Framework
Char Driver
Framework
spi-altera.c
Altera SPI Adapter
Driver
10© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Framework Components
SPI Master
Bus controller which handles the low level h/w transactions
struct spi_master
dev – device interface to this driver
list – linked with global spi_master list
Board specific bus number
min_speed_hz
max_speed_hz
setup – updates the device mode and clock
transfer – adds a message to the controller’s transfer queue
cleanup – frees up controller specific state
transfer_one_message – the subsystem calls the driver
spi_register_master(spi_master)
11© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Framework Components ...
SPI Device
Represents the SPI Slave in the Kernel
struct spi_device
dev – device interface to this driver
master – SPI controller used with the device
max_speed_hz – Maximum clock rate to be used with this device
mode – Defines how the data is clocked out and in
bits_per_word
controller_state – Controller’s runtime state
controller_data – Board specific definitions for controller such as FIFO
modalias – name of the driver to use with this device
cs_gpio – gpio signal used for chip select line
12© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Client Driver
Host side protocol driver
struct spi_driver
probe – Binds the driver to SPI device
remove – unbinds the driver from the SPI device
id_table – List of SPI devices supported by this driver
driver – name of this driver. This will be used to bind
with SPI slaves
13© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Client Driver ...
Register probe() & remove() with SPI Core
Optionally, register suspend() & resume()
Header: <linux/spi/spi.h>
API
int spi_register_driver(struct spi_driver *);
void spi_unregister_driver(struct spi_driver *);
module_spi_driver()
Device Access APIs
spi_sync(struct spi_device *, struct spi_message *);
spi_async(struct spi_device *, struct spi_message *);
14© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Device Access
/* struct spi_device *spi – obtained through probe */
struct spi_transfer xfer;
struct spi_message sm;
u8 *cmd_buf;
int len;
… /* Ready the cmd_buf & its len */ ...
spi_message_init(&sm);
xfer.tx_buf = cmd_buf;
xfer.len = len;
spi_message_add_tail(&xfer, &sm);
spi_sync(spi, &sm); /* Blocking transfer request */
spi_transfer_del(&xfer);
15© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Master Registration Flow
16© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
spi_sync flow
17© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
DTB changes for MCP3008
mcp3x0x@0 {
compatible = "mcp3208";
reg = <0>;
spi-max-frequency = <1000000>;
};
18© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
SPI Driver Example
Driver: ADC (drivers/iio/adc/mcp320x.c)
Path: <kernel_source>/drivers/spi
Browse & Discuss
19© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
SPI Prologue
SPI Framework
SPI Framework Components
SPI Client Driver
20© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

What's hot (20)

Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
Character drivers
Character driversCharacter drivers
Character drivers
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
BeagleBoard-xM Booting Process
BeagleBoard-xM Booting ProcessBeagleBoard-xM Booting Process
BeagleBoard-xM Booting Process
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
CCNA Lab Guide
CCNA Lab GuideCCNA Lab Guide
CCNA Lab Guide
 
IOS Cisco - Cheat sheets
IOS Cisco - Cheat sheetsIOS Cisco - Cheat sheets
IOS Cisco - Cheat sheets
 
Ccna Commands In 10 Minutes
Ccna Commands In 10 MinutesCcna Commands In 10 Minutes
Ccna Commands In 10 Minutes
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 

Similar to SPI Drivers

Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...Cisco Russia
 
Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...
Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...
Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...jaxLondonConference
 
Ae01 system overview
Ae01 system overviewAe01 system overview
Ae01 system overviewconfidencial
 
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PROIDEA
 
Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000
Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000
Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000Cisco Russia
 
1 familia simatic s7
1 familia simatic s71 familia simatic s7
1 familia simatic s7Fercho Oe
 
Experiences with Oracle SPARC S7-2 Server
Experiences with Oracle SPARC S7-2 ServerExperiences with Oracle SPARC S7-2 Server
Experiences with Oracle SPARC S7-2 ServerJomaSoft
 
[Unite Seoul 2019] Mali GPU Architecture and Mobile Studio
[Unite Seoul 2019] Mali GPU Architecture and Mobile Studio [Unite Seoul 2019] Mali GPU Architecture and Mobile Studio
[Unite Seoul 2019] Mali GPU Architecture and Mobile Studio Owen Wu
 
OpenChain AutomotiveWG(OSS license tools()
OpenChain AutomotiveWG(OSS license tools()OpenChain AutomotiveWG(OSS license tools()
OpenChain AutomotiveWG(OSS license tools()Yuichi Kusakabe
 
CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4Nil Menon
 

Similar to SPI Drivers (20)

PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
 
Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...
Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...
Do You Like Coffee with Your dessert? Java and the Raspberry Pi - Simon Ritte...
 
I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Embedded I/O Management
Embedded I/O ManagementEmbedded I/O Management
Embedded I/O Management
 
Advanced Topics in IP Multicast Deployment
Advanced Topics in IP Multicast DeploymentAdvanced Topics in IP Multicast Deployment
Advanced Topics in IP Multicast Deployment
 
Ae01 system overview
Ae01 system overviewAe01 system overview
Ae01 system overview
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000
Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000
Особенности архитектуры и траблшутинга маршрутизаторов серии ASR1000
 
1 familia simatic s7
1 familia simatic s71 familia simatic s7
1 familia simatic s7
 
Experiences with Oracle SPARC S7-2 Server
Experiences with Oracle SPARC S7-2 ServerExperiences with Oracle SPARC S7-2 Server
Experiences with Oracle SPARC S7-2 Server
 
CCNA CHAPTER 5 BY jetarvind kumar madhukar
CCNA CHAPTER 5 BY jetarvind kumar madhukarCCNA CHAPTER 5 BY jetarvind kumar madhukar
CCNA CHAPTER 5 BY jetarvind kumar madhukar
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 
[Unite Seoul 2019] Mali GPU Architecture and Mobile Studio
[Unite Seoul 2019] Mali GPU Architecture and Mobile Studio [Unite Seoul 2019] Mali GPU Architecture and Mobile Studio
[Unite Seoul 2019] Mali GPU Architecture and Mobile Studio
 
OpenChain AutomotiveWG(OSS license tools()
OpenChain AutomotiveWG(OSS license tools()OpenChain AutomotiveWG(OSS license tools()
OpenChain AutomotiveWG(OSS license tools()
 
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
 
CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4
 

More from SysPlay eLearning Academy for You (13)

Linux Internals Part - 3
Linux Internals Part - 3Linux Internals Part - 3
Linux Internals Part - 3
 
Linux Internals Part - 2
Linux Internals Part - 2Linux Internals Part - 2
Linux Internals Part - 2
 
Linux Internals Part - 1
Linux Internals Part - 1Linux Internals Part - 1
Linux Internals Part - 1
 
Kernel Timing Management
Kernel Timing ManagementKernel Timing Management
Kernel Timing Management
 
Understanding the BBB
Understanding the BBBUnderstanding the BBB
Understanding the BBB
 
POSIX Threads
POSIX ThreadsPOSIX Threads
POSIX Threads
 
Linux DMA Engine
Linux DMA EngineLinux DMA Engine
Linux DMA Engine
 
Cache Management
Cache ManagementCache Management
Cache Management
 
Introduction to BeagleBone Black
Introduction to BeagleBone BlackIntroduction to BeagleBone Black
Introduction to BeagleBone Black
 
Introduction to BeagleBoard-xM
Introduction to BeagleBoard-xMIntroduction to BeagleBoard-xM
Introduction to BeagleBoard-xM
 
BeagleBone Black Booting Process
BeagleBone Black Booting ProcessBeagleBone Black Booting Process
BeagleBone Black Booting Process
 
BeagleBoard-xM Bootloaders
BeagleBoard-xM BootloadersBeagleBoard-xM Bootloaders
BeagleBoard-xM Bootloaders
 
Linux System
Linux SystemLinux System
Linux System
 

Recently uploaded

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

SPI Drivers

  • 1. © 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Serial Peripheral Interface (SPI) Drivers
  • 2. 2© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? SPI Prologue SPI Framework SPI Framework Components SPI Client Driver
  • 3. 3© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Prologue Suitable for small slow devices SPI is a 4-wire protocol unlike I2 C Apart from Serial Clock, Data Lines are 2 And an additional Chip Select
  • 4. 4© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Protocol Memory Memory 0 1 2 3 5 6 7 0 1 2 3 5 6 7 SCLK MISO MOSI CS Master Slave
  • 5. 5© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Character Driver Framework User Space /dev/spi0 cat, echo my_open() my_read() my_write() Char Driver Low Level SPI Driver spi_rw() test.c, s1.c App open(), read(), write()
  • 6. 6© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. AM335X Registers Module Control Register For configuring the SPI interface Single / Multi channel, Master / Slave, Chip select pins Channel Configuration Register Used to configure the SPI channel (0-3) Clock Divider, FIFO for Rx / TX, Pins for TX / RX, DMA RX / TX, SPI Mode (Full Duplex, Half Duplex), Word Length, SPI Mode Channel Status Register Status information for channel (0–3) RX / TX FIFO Full / Empty Channel Control Register Enabling / Disabling the channel
  • 7. 7© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. AM335X SPI APIs omap2_mcspi_set_enable(struct omap2_mcspi *, int enable) Enable / Disable the channel int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit) Wait for register bit to set __raw_writel(ch, tx_reg) For writing into tx_reg char ch = __raw_readl(rx_reg) For reading rx_reg
  • 8. 8© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Framework spi.c – Implements the SPI core layer include/linux/spi/spi.h spidev.c – Provides the char interface for spi devices include/linux/spi/spidev.h spi-omap2-mcspi – Controller driver for omap based chips
  • 9. 9© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Framework SPI Core driver/spi/spi.c mcp320x.c drivers/iio/adc SPI based ADC driver SPI Client Driver m25p80.c drivers/mtd/ SPI based Flash driver spi-omap2-mcspi.c omap SPI Adapter Driver atmel-spi.c Atmel SPI Adapter Driver spi-imx.c IMX SPI Adapter Driver spidev.c drivers/spi Char driver for SPI Industrial IO Framework rtc-ds1505.c drivers/rtc SPI based RTC driver MTD Framework RTC Framework Char Driver Framework spi-altera.c Altera SPI Adapter Driver
  • 10. 10© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Framework Components SPI Master Bus controller which handles the low level h/w transactions struct spi_master dev – device interface to this driver list – linked with global spi_master list Board specific bus number min_speed_hz max_speed_hz setup – updates the device mode and clock transfer – adds a message to the controller’s transfer queue cleanup – frees up controller specific state transfer_one_message – the subsystem calls the driver spi_register_master(spi_master)
  • 11. 11© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Framework Components ... SPI Device Represents the SPI Slave in the Kernel struct spi_device dev – device interface to this driver master – SPI controller used with the device max_speed_hz – Maximum clock rate to be used with this device mode – Defines how the data is clocked out and in bits_per_word controller_state – Controller’s runtime state controller_data – Board specific definitions for controller such as FIFO modalias – name of the driver to use with this device cs_gpio – gpio signal used for chip select line
  • 12. 12© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Client Driver Host side protocol driver struct spi_driver probe – Binds the driver to SPI device remove – unbinds the driver from the SPI device id_table – List of SPI devices supported by this driver driver – name of this driver. This will be used to bind with SPI slaves
  • 13. 13© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Client Driver ... Register probe() & remove() with SPI Core Optionally, register suspend() & resume() Header: <linux/spi/spi.h> API int spi_register_driver(struct spi_driver *); void spi_unregister_driver(struct spi_driver *); module_spi_driver() Device Access APIs spi_sync(struct spi_device *, struct spi_message *); spi_async(struct spi_device *, struct spi_message *);
  • 14. 14© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Device Access /* struct spi_device *spi – obtained through probe */ struct spi_transfer xfer; struct spi_message sm; u8 *cmd_buf; int len; … /* Ready the cmd_buf & its len */ ... spi_message_init(&sm); xfer.tx_buf = cmd_buf; xfer.len = len; spi_message_add_tail(&xfer, &sm); spi_sync(spi, &sm); /* Blocking transfer request */ spi_transfer_del(&xfer);
  • 15. 15© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Master Registration Flow
  • 16. 16© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. spi_sync flow
  • 17. 17© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. DTB changes for MCP3008 mcp3x0x@0 { compatible = "mcp3208"; reg = <0>; spi-max-frequency = <1000000>; };
  • 18. 18© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. SPI Driver Example Driver: ADC (drivers/iio/adc/mcp320x.c) Path: <kernel_source>/drivers/spi Browse & Discuss
  • 19. 19© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? SPI Prologue SPI Framework SPI Framework Components SPI Client Driver
  • 20. 20© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?