SlideShare ist ein Scribd-Unternehmen logo
1 von 20
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Serial Peripheral Interface (SPI) Drivers
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
What to Expect
●
SPI Overview
●
SPI Character Driver Framework
●
Accessing Hardware Registers
●
Linux SPI Framework
●
SPI Framework Components
●
SPI Client Driver
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
SPI Overview
●
Suitable for small slow devices
●
SPI is a 4-wire protocol unlike I2C
●
Apart from Serial Clock, Data Lines are 2
●
And an additional Chip Select.
@ 2021-22 Embitude Trainings <info@embitude.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
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
SPI Character Driver Framework
User Space
/dev/spi0
cat,
echo
Char Driver
spi_char.c
Low Level
SPI Driver
low_level_driver.c
App
open(), read(),
write()
my_open() my_read()
spi_rw()
my_write()
@ 2021-22 Embitude Trainings <info@embitude.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
@ 2021-22 Embitude Trainings <info@embitude.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
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Linux 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
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
SPI Core
drivers/spi/spi.c
Linux SPI Framework ...
SPI Client Drivers
mcp320x.c
drivers/iio/adc
SPI based ADC
driver
m25p80.c
drivers/mtd/
SPI based Flash
driver
rtc-ds1505.c
drivers/rtc
SPI based RTC
driver
spidev.c
drivers/spi
Char driver for
SPI
spi-omap2-
mcspi.c
omap SPI Master
Driver
atmel-spi.c
Atmel SPI Master
Driver
spi-imx.c
IMX SPI Master
Driver
spi-altera.c
Altera SPI Adapter
Driver
Industrial IO
Framework
MTD
Framework
RTC
Framework
Character Driver
Framework
@ 2021-22 Embitude Trainings <info@embitude.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)
@ 2021-22 Embitude Trainings <info@embitude.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
@ 2021-22 Embitude Trainings <info@embitude.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
@ 2021-22 Embitude Trainings <info@embitude.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 *)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
SPI Transfer
●
struct spi_device *spi
●
struct spi_transfer xfer;
●
struct spi_message sm;
●
u8 *cmd_buf;
●
int len;
●
Prepare 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) & spi_async(spi, &sm)
●
spi_transfer_del(&xfer);
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
SPI Master Registration Flow
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
spi_sync flow
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
DTB changes for MCP3008
●
mcp3x0x@0 {
compatible = "mcp3208";
reg = <0>;
spi-max-frequency = <1000000>;
};
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
SPI Driver Example
●
Driver: ADC (drivers/iio/adc/mcp320x.c)
●
Path: <kernel_source>/drivers/spi
●
Browse & Discuss
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
What all have we learnt?
●
SPI Overview
●
SPI Character Driver Framework
●
Accessing Hardware Registers
●
Linux SPI Framework
●
SPI Framework Components
●
SPI Client Driver
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Any Queries?

Weitere ähnliche Inhalte

Was ist angesagt?

LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLinaro
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24Varun Mahajan
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequenceHoucheng Lin
 
Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Macpaul Lin
 
Kernel Process Management
Kernel Process ManagementKernel Process Management
Kernel Process Managementpradeep_tewani
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewLinaro
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...Anne Nicolas
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Thomas Petazzoni
 
/proc/irq/&lt;irq>/smp_affinity
/proc/irq/&lt;irq>/smp_affinity/proc/irq/&lt;irq>/smp_affinity
/proc/irq/&lt;irq>/smp_affinityTakuya ASADA
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoCMacpaul Lin
 

Was ist angesagt? (20)

LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
Kernel Process Management
Kernel Process ManagementKernel Process Management
Kernel Process Management
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
Linux dma engine
Linux dma engineLinux dma engine
Linux dma engine
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
Embedded Recipes 2017 - Introduction to Yocto Project/OpenEmbedded - Mylène J...
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
U boot-boot-flow
U boot-boot-flowU boot-boot-flow
U boot-boot-flow
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 
/proc/irq/&lt;irq>/smp_affinity
/proc/irq/&lt;irq>/smp_affinity/proc/irq/&lt;irq>/smp_affinity
/proc/irq/&lt;irq>/smp_affinity
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 

Ähnlich wie Spi 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 Owen Wu
 
Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)
Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)
Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)Talal Khaliq
 
IDF_Eclipse_Plugin_EclipseCon2020_v2.pdf
IDF_Eclipse_Plugin_EclipseCon2020_v2.pdfIDF_Eclipse_Plugin_EclipseCon2020_v2.pdf
IDF_Eclipse_Plugin_EclipseCon2020_v2.pdfKondal Kolipaka
 
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...Cisco Russia
 
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
 
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdfBuilding PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdfPaul Yang
 
Introduction to Advanced embedded systems course
Introduction to Advanced embedded systems courseIntroduction to Advanced embedded systems course
Introduction to Advanced embedded systems courseanishgoel
 
Nios2 and ip core
Nios2 and ip coreNios2 and ip core
Nios2 and ip coreanishgoel
 
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
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016Chris Simmonds
 
Linxu conj2016 96boards
Linxu conj2016 96boardsLinxu conj2016 96boards
Linxu conj2016 96boardsLF Events
 
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
 
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...ryancox
 
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019
Eclipse Plugin for ESP-IDF -  EclipseCon Europe 2019Eclipse Plugin for ESP-IDF -  EclipseCon Europe 2019
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019Kondal Kolipaka
 
FIWARE Global Summit - Real-time Media Stream Processing Using Kurento
FIWARE Global Summit - Real-time Media Stream Processing Using KurentoFIWARE Global Summit - Real-time Media Stream Processing Using Kurento
FIWARE Global Summit - Real-time Media Stream Processing Using KurentoFIWARE
 
2014/09/02 Cisco UCS HPC @ ANL
2014/09/02 Cisco UCS HPC @ ANL2014/09/02 Cisco UCS HPC @ ANL
2014/09/02 Cisco UCS HPC @ ANLdgoodell
 
Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentCorley S.r.l.
 

Ähnlich wie Spi drivers (20)

SPI Drivers
SPI DriversSPI Drivers
SPI 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
 
Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)
Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)
Design of 32 Bit Processor Using 8051 and Leon3 (Progress Report)
 
IDF_Eclipse_Plugin_EclipseCon2020_v2.pdf
IDF_Eclipse_Plugin_EclipseCon2020_v2.pdfIDF_Eclipse_Plugin_EclipseCon2020_v2.pdf
IDF_Eclipse_Plugin_EclipseCon2020_v2.pdf
 
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
Внутренняя архитектура IOS-XE: средства траблшутинга предачи трафика на ASR1k...
 
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
 
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdfBuilding PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
Building PoC ready ODM Platforms with Arm SystemReady v5.2.pdf
 
Introduction to Advanced embedded systems course
Introduction to Advanced embedded systems courseIntroduction to Advanced embedded systems course
Introduction to Advanced embedded systems course
 
Nios2 and ip core
Nios2 and ip coreNios2 and ip core
Nios2 and ip core
 
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
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016
 
Linxu conj2016 96boards
Linxu conj2016 96boardsLinxu conj2016 96boards
Linxu conj2016 96boards
 
Plc operation part 2
Plc operation part 2Plc operation part 2
Plc operation part 2
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
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...
 
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
 
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019
Eclipse Plugin for ESP-IDF -  EclipseCon Europe 2019Eclipse Plugin for ESP-IDF -  EclipseCon Europe 2019
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019
 
FIWARE Global Summit - Real-time Media Stream Processing Using Kurento
FIWARE Global Summit - Real-time Media Stream Processing Using KurentoFIWARE Global Summit - Real-time Media Stream Processing Using Kurento
FIWARE Global Summit - Real-time Media Stream Processing Using Kurento
 
2014/09/02 Cisco UCS HPC @ ANL
2014/09/02 Cisco UCS HPC @ ANL2014/09/02 Cisco UCS HPC @ ANL
2014/09/02 Cisco UCS HPC @ ANL
 
Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
 

Kürzlich hochgeladen

WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 

Kürzlich hochgeladen (20)

WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

Spi drivers

  • 1. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Serial Peripheral Interface (SPI) Drivers
  • 2. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved What to Expect ● SPI Overview ● SPI Character Driver Framework ● Accessing Hardware Registers ● Linux SPI Framework ● SPI Framework Components ● SPI Client Driver
  • 3. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved SPI Overview ● Suitable for small slow devices ● SPI is a 4-wire protocol unlike I2C ● Apart from Serial Clock, Data Lines are 2 ● And an additional Chip Select.
  • 4. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved SPI Character Driver Framework User Space /dev/spi0 cat, echo Char Driver spi_char.c Low Level SPI Driver low_level_driver.c App open(), read(), write() my_open() my_read() spi_rw() my_write()
  • 6. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Linux 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. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved SPI Core drivers/spi/spi.c Linux SPI Framework ... SPI Client Drivers mcp320x.c drivers/iio/adc SPI based ADC driver m25p80.c drivers/mtd/ SPI based Flash driver rtc-ds1505.c drivers/rtc SPI based RTC driver spidev.c drivers/spi Char driver for SPI spi-omap2- mcspi.c omap SPI Master Driver atmel-spi.c Atmel SPI Master Driver spi-imx.c IMX SPI Master Driver spi-altera.c Altera SPI Adapter Driver Industrial IO Framework MTD Framework RTC Framework Character Driver Framework
  • 10. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.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. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved SPI Transfer ● struct spi_device *spi ● struct spi_transfer xfer; ● struct spi_message sm; ● u8 *cmd_buf; ● int len; ● Prepare 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) & spi_async(spi, &sm) ● spi_transfer_del(&xfer);
  • 15. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved SPI Master Registration Flow
  • 16. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved spi_sync flow
  • 17. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved DTB changes for MCP3008 ● mcp3x0x@0 { compatible = "mcp3208"; reg = <0>; spi-max-frequency = <1000000>; };
  • 18. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved SPI Driver Example ● Driver: ADC (drivers/iio/adc/mcp320x.c) ● Path: <kernel_source>/drivers/spi ● Browse & Discuss
  • 19. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved What all have we learnt? ● SPI Overview ● SPI Character Driver Framework ● Accessing Hardware Registers ● Linux SPI Framework ● SPI Framework Components ● SPI Client Driver
  • 20. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Any Queries?