SlideShare a Scribd company logo
@ 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?

More Related Content

What's hot

Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
shimosawa
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
艾鍗科技
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
Houcheng Lin
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
RuggedBoardGroup
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
SUSE Labs Taipei
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
艾鍗科技
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
Anil Kumar Pugalia
 
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
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
Satpal Parmar
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoCMacpaul Lin
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
RuggedBoardGroup
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
艾鍗科技
 
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
 
Linux : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
Mr. Vengineer
 
SPI Drivers
SPI DriversSPI Drivers
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_BootingRashila Rr
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
Adrian Huang
 
Linux device drivers
Linux device drivers Linux device drivers
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
Linaro
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Linaro
 

What's hot (20)

Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
USB Drivers
USB DriversUSB Drivers
USB 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
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 
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 : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
 

Similar to Spi drivers

SPI Drivers
SPI DriversSPI 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
 
I2c drivers
I2c driversI2c drivers
I2c drivers
Pradeep Tewani
 
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.pdf
Kondal 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 Server
JomaSoft
 
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
Paul 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 core
anishgoel
 
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
Nil Menon
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016
Chris Simmonds
 
Linxu conj2016 96boards
Linxu conj2016 96boardsLinxu conj2016 96boards
Linxu conj2016 96boards
LF Events
 
Plc operation part 2
Plc operation part 2Plc operation part 2
Plc operation part 2
Sakshi Vashist
 
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 2019
Kondal 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 Kurento
FIWARE
 
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
dgoodell
 

Similar to 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
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
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
 

Recently uploaded

Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 

Recently uploaded (20)

Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 

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?