SlideShare una empresa de Scribd logo
1 de 29
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Inter Integrated Circuit (I2C) Drivers
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
What to Expect
● I2C Overview
● I2C Conditions & Transactions
● I2C Subsystem in Linux – I2C Adapter & I2C
Client
● I2C Client Driver
● I2C Device Registration (Non DT and DT)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Overview
● Originally developed by Phillips
● Suitable for small slow devices
● I2C is a 2-wire protocol
– One Serial Clock Line
– One Data Line
● Popular in Desktops & Embedded Systems
● Used for accessing
– EEPROMs
– RTCs
– ADCs
– ....
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Conditions
● Start Condition
– Master signals this condition to initiate the transfer
on the bus
● Stop Condition
– Master signals this condition to stop the transfer
● ACK Condition
– Master or Slave signals this to acknowledge the
succesful receipt of byte
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Transactions
● Master begins the communication by issuing
the start condition.
● Sends a 7/10 bit slave address followed by
read/write bit
● The addressed slave ACKs the transfer
● Transmitter transmits a byte of data and
receiver issues ACK on successful receipt
● Master issues a STOP condition to conclude
the transaction
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Transactions...
Start Data 1
SLA + W
Slave
ACK
Data 2 Data N
Slave
ACK
Slave
ACK
Stop
Master Write
Slave
ACK
Start Addr. 1
SLA +
W
Slave
ACK
Repeat
Start
Data
1
Slave
ACK
SLA +
R
Stop
Master
ACK
Data
N
Master
NACK
Master Read
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Character Driver Framework
User Space
i2c_app.c,
i2c_intr.c
Char Driver (i2c_char.c)
Low Level I2
C Driver
(low_level_driver.c)
App
open(), read(),
write()
/dev/i2c_drv0
my_open() my_read() my_write()
i2c_receive() i2c_transmit()
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
AM335X I2C Initialization
● Get the virtual address for the I2C-0 registers base address
● Set up the I2C speed
– Set the pre-scalar register to generate the I2C module
internal clock from the functional clock
– Set the scl low time & scl high time registers
● Enable the events
– Update the ‘Interrupt Enable Set’ register to enable various
events such as XRDY, RRDY and so on
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
AM335x I2C Registers
● I2C_SA_REGISTER (Slave Address Register)
● I2C_CON_REGISTER (Configuration Register)
– Bits for enabling / disabling the I2C module
– Selecting the Fast / Standard mode of operation
– Selecting the Master / Slave config
– Sending the Start / Stop conditions on the bus
● I2C_DATA (RX/TX Data Register)
● I2C_BUF (FIFO Thresholds, DMA configuration)
● I2C_CNT (Bytes in I2C data payload)
● I2C_IRQ_STATUS_REG
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
AM335X I2C APIs
● #include “i2c_char.h”
● u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int
reg)
● void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
int reg, u16 val)
● u16 wait_for_event(struct omap_i2c_dev *dev)
● void omap_i2c_ack_stat(struct omap_i2c_dev, u16 stat)
● val = omap_i2c_read_reg(dev, OMAP_I2C_BUF_REG)
● val |= OMAP_I2C_BUF_TXFIF
● omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, val)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Accessing EEPROM
0XAA
0x0060
EEPROM
I2C Slave Address 0X50
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Writing to EEPROM
● For writing at EEPROM offset 0x0060
● Send the start condition
● Send the slave address of EEPROM (0X50), followed
by direction (Read/Write)
● Send the EEPROM offset higher byte, followed by
lower byte
● Send the actual data to be written
● Send the Stop condition
● START->0x50->0x00(offset high)->0x60 (offset low)-
>0X99(Data)->STOP
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Reading From EEPROM
● Write the EEPROM offset say 0x0060 (read offset)
– START->0x50->0x00(offset high)->0x60 (offset
low)->STOP
● Read the EEPROM data
– Send the start condition
– Send the slave address of EEPROM (0X50),
followed by direction (Read)
– Read the data
– Send the stop condition
– START->0x50->Data (RX)->Data (RX)->STOP
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Need for Linux Device Model
● Maximize the code re-usability across the platforms
– Same device drivers on different platforms
● To achieve this
– Decouple device drivers from controller drivers
– Decouple hardware description from the drivers
● In addition to above
– Information about how the system is put together
● Effective power management
– Communication with user space
– Hotpluggable devices
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Device Drivers in Linux
Application
System Call
Interface
Framework
Driver
Bus
Infrastructure
Hardware
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Device model data structures
● struct bus_type
– Represents the bus such as USB, PCI, I2C etc
● struct device_driver
– Represents the driver capable of handling certain
devices
● struct device
– Represents the device connected to the bus
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Linux I2C Subsystem
● I2C subsystem provides
– API to implement I2C controller driver
– API to implement I2C device driver in kernel space
– An abstraction to implement the client drivers
independent of adapter drivers
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Linux I2C Subsystem ...
User Space
Kernel Space
I2C Device
(i2c_client)
I2C Host
Controller
(i2c_adapter)
Hardware Space
/sys, /dev
User Applications
User Mode I2C
Device Driver
I2C Core
i2c-dev
Vertical: Character
I2C Client Driver
I2C Bus
I2C Adapter (platform_driver) / Algo Driver (i2c_algorithm)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Subsystem Details
● i2c-adapter / i2c-algo
– Controller-specific I2C host controller / adapter
– Also called as the I2C bus drivers
● i2c-core
– Hides the adapter details from the layers above
– By providing the generic I2C APIs
● i2c-dev
– Provides device access in user space through /sys
– Enables implementation of User Mode Drivers
● i2c-client
– Driver specific to an I2C device
– Implemented using i2c-core APIs
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Client Driver
● Typically a character driver vertical - /dev or
/sys exposed
● But actually depends on the device category
● Registers with I2C Core (in the init function)
● Unregisters from I2C Core (in the cleanup
function)
● And uses the generic function from I2C Core for
data transfers
– int i2c_transfer(struct i2c_adapter *adap, struct
i2c_msg *msgs, int num)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Client Driver init & cleanup
● Registering to the I2C Core using
– int i2c_add_driver(struct i2c_driver *)
– struct i2c_driver contains
● probe function – called on device detection
● remove function – called on device shutdown
● id_table – Table of device identifiers
● Unregistering from the I2C Core using
– void i2c_del_driver(struct i2c_driver *)
● Common bare-bone of init & cleanup
– Just use module_i2c_driver(struct i2c_driver)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Client Driver Registration
● struct i2c_driver dummy_driver = {
driver = {
name = “dummy_client”,
owner = THIS_MODULE,
},
.probe = dummy_probe,
.remove = dummy_remove,
.id_table = dummy_ids,
}
● static const struct i2c_device_id dummy_ids = {
{ “dummy_device”, 0},
{}
}
●
i2c_add_driver(dummy_driver)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Adapter Driver (Un)Registeration
● Registering to the I2C Core using
– int i2c_add_numbered_adapter(struct i2c_adapter
*);
– Registered in the platform driver probe
● Unregistering from the I2C Core using
– void i2c_del_adapter(struct i2c_driver *);
– In platform driver remove functions
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
I2C Client Driver Examples
● Path: <kernel_source>/drivers/
– I2C EEPROM: AT24
● misc/eeprom/at24.c
– I2C RTC: DS1307
● rtc/rtc-ds1307.c
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Registering the I2C Client (Non DT)
● On non-DT platforms, the struct i2c_board_info
describes how device is connected to a board
● Defined with I2C_BOARD_INFO helper macro
– Takes as the arguments, the device name and the
slave address of the device on the bus
● An array of such structures is registered on per
bus basis using the i2c_register_board_info
during the platform initialization
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Registering the I2C Client (Non DT)..
● static struct i2c_board_info my_i2c_devices [] = {
{
I2C_BOARD_INFO (“my_device”, 0 x1D ),
. irq = 70,
.platform_data = &my_data
},
}
● i2c_register_board_info(0, my_i2c_devices,
ARRAY_SIZE (my_i2c_devices))
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Registering an I2C Client (DT)
● In the device tree, the I2C devices on the bus
are described as children of the I2C controller
node
● reg property gives the I2C slave address on the
bus
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
Registering an I2C Client (DT) ...
● i2c@49607899 {
compatible = "dummy_adap";
clock-frequency = <0x186a0>;
#address-cells = <0x1>;
#size-cells = <0x0>;
my_dummy@0 {
compatible = "dummy_device";
reg = <0x40>;
};
};
● Registered internally by i2c_core based on info from DTB
● i2c_new_device(struct i2c_adapter *, struct i2c_board_info *)
@ 2021-22 Embitude Trainings <info@embitude.in>
All Rights Reserved
What all did we learn?
● I2C Overview
● I2C Conditions & Transactions
● I2C Subsystem in Linux – I2C Adapter & I2C
Client
● I2C Client Driver
● I2C Device Registration (Non DT and DT)

Más contenido relacionado

La actualidad más candente

Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)RuggedBoardGroup
 
linux device driver
linux device driverlinux device driver
linux device driverRahul Batra
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchlinuxlab_conf
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelSUSE Labs Taipei
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New HardwareRuggedBoardGroup
 
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 KernelDivye Kapoor
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLinaro
 

La actualidad más candente (20)

Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
U boot-boot-flow
U boot-boot-flowU boot-boot-flow
U boot-boot-flow
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux Kernel
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 
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 Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted Firmware
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 

Similar a I2c drivers

Как «вправить» автомобилю «мозги»
Как «вправить» автомобилю «мозги»Как «вправить» автомобилю «мозги»
Как «вправить» автомобилю «мозги»Positive Hack Days
 
An Entire Concept of Embedded systems
An Entire Concept of Embedded systems An Entire Concept of Embedded systems
An Entire Concept of Embedded systems Prabhakar Captain
 
An entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptAn entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptPrabhakar Captain
 
FPGA Verilog Processor Design
FPGA Verilog Processor DesignFPGA Verilog Processor Design
FPGA Verilog Processor DesignArchana Udaranga
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and RoboticsNIT Raipur
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxMeghdeepSingh
 
Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Ahmed Elsayed
 
Design and Development of a prototype of AGV
Design and Development of a prototype of AGVDesign and Development of a prototype of AGV
Design and Development of a prototype of AGVKUNJBIHARISINGH5
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Rodrigo Almeida
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics Felipe Prado
 
SIMATIC manager سيماتك منجر سيمنز
SIMATIC manager سيماتك منجر سيمنزSIMATIC manager سيماتك منجر سيمنز
SIMATIC manager سيماتك منجر سيمنزEssosElectronic
 
Microcontroller from basic_to_advanced
Microcontroller from basic_to_advancedMicrocontroller from basic_to_advanced
Microcontroller from basic_to_advancedImran Sheikh
 
Real Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAReal Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAMafaz Ahmed
 
Tft touch screen manufacturers
Tft touch screen manufacturersTft touch screen manufacturers
Tft touch screen manufacturersKeatonParker2
 

Similar a I2c drivers (20)

Как «вправить» автомобилю «мозги»
Как «вправить» автомобилю «мозги»Как «вправить» автомобилю «мозги»
Как «вправить» автомобилю «мозги»
 
Intel Quark HSUART
Intel Quark HSUARTIntel Quark HSUART
Intel Quark HSUART
 
An Entire Concept of Embedded systems
An Entire Concept of Embedded systems An Entire Concept of Embedded systems
An Entire Concept of Embedded systems
 
An entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptAn entire concept of embedded systems entire ppt
An entire concept of embedded systems entire ppt
 
An hemmanur
An hemmanurAn hemmanur
An hemmanur
 
Ch09 system administration
Ch09 system administration Ch09 system administration
Ch09 system administration
 
FPGA Verilog Processor Design
FPGA Verilog Processor DesignFPGA Verilog Processor Design
FPGA Verilog Processor Design
 
UNIT-III ES.ppt
UNIT-III ES.pptUNIT-III ES.ppt
UNIT-III ES.ppt
 
project 3 full report
project 3 full reportproject 3 full report
project 3 full report
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and Robotics
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
 
My i2c
My i2cMy i2c
My i2c
 
Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200
 
Design and Development of a prototype of AGV
Design and Development of a prototype of AGVDesign and Development of a prototype of AGV
Design and Development of a prototype of AGV
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
 
SIMATIC manager سيماتك منجر سيمنز
SIMATIC manager سيماتك منجر سيمنزSIMATIC manager سيماتك منجر سيمنز
SIMATIC manager سيماتك منجر سيمنز
 
Microcontroller from basic_to_advanced
Microcontroller from basic_to_advancedMicrocontroller from basic_to_advanced
Microcontroller from basic_to_advanced
 
Real Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAReal Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGA
 
Tft touch screen manufacturers
Tft touch screen manufacturersTft touch screen manufacturers
Tft touch screen manufacturers
 

Último

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Último (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

I2c drivers

  • 1. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Inter Integrated Circuit (I2C) Drivers
  • 2. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved What to Expect ● I2C Overview ● I2C Conditions & Transactions ● I2C Subsystem in Linux – I2C Adapter & I2C Client ● I2C Client Driver ● I2C Device Registration (Non DT and DT)
  • 3. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Overview ● Originally developed by Phillips ● Suitable for small slow devices ● I2C is a 2-wire protocol – One Serial Clock Line – One Data Line ● Popular in Desktops & Embedded Systems ● Used for accessing – EEPROMs – RTCs – ADCs – ....
  • 4. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Conditions ● Start Condition – Master signals this condition to initiate the transfer on the bus ● Stop Condition – Master signals this condition to stop the transfer ● ACK Condition – Master or Slave signals this to acknowledge the succesful receipt of byte
  • 5. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Transactions ● Master begins the communication by issuing the start condition. ● Sends a 7/10 bit slave address followed by read/write bit ● The addressed slave ACKs the transfer ● Transmitter transmits a byte of data and receiver issues ACK on successful receipt ● Master issues a STOP condition to conclude the transaction
  • 6. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Transactions... Start Data 1 SLA + W Slave ACK Data 2 Data N Slave ACK Slave ACK Stop Master Write Slave ACK Start Addr. 1 SLA + W Slave ACK Repeat Start Data 1 Slave ACK SLA + R Stop Master ACK Data N Master NACK Master Read
  • 7. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Character Driver Framework User Space i2c_app.c, i2c_intr.c Char Driver (i2c_char.c) Low Level I2 C Driver (low_level_driver.c) App open(), read(), write() /dev/i2c_drv0 my_open() my_read() my_write() i2c_receive() i2c_transmit()
  • 8. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved AM335X I2C Initialization ● Get the virtual address for the I2C-0 registers base address ● Set up the I2C speed – Set the pre-scalar register to generate the I2C module internal clock from the functional clock – Set the scl low time & scl high time registers ● Enable the events – Update the ‘Interrupt Enable Set’ register to enable various events such as XRDY, RRDY and so on
  • 9. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved AM335x I2C Registers ● I2C_SA_REGISTER (Slave Address Register) ● I2C_CON_REGISTER (Configuration Register) – Bits for enabling / disabling the I2C module – Selecting the Fast / Standard mode of operation – Selecting the Master / Slave config – Sending the Start / Stop conditions on the bus ● I2C_DATA (RX/TX Data Register) ● I2C_BUF (FIFO Thresholds, DMA configuration) ● I2C_CNT (Bytes in I2C data payload) ● I2C_IRQ_STATUS_REG
  • 10. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved AM335X I2C APIs ● #include “i2c_char.h” ● u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) ● void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, int reg, u16 val) ● u16 wait_for_event(struct omap_i2c_dev *dev) ● void omap_i2c_ack_stat(struct omap_i2c_dev, u16 stat) ● val = omap_i2c_read_reg(dev, OMAP_I2C_BUF_REG) ● val |= OMAP_I2C_BUF_TXFIF ● omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, val)
  • 11. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Accessing EEPROM 0XAA 0x0060 EEPROM I2C Slave Address 0X50
  • 12. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Writing to EEPROM ● For writing at EEPROM offset 0x0060 ● Send the start condition ● Send the slave address of EEPROM (0X50), followed by direction (Read/Write) ● Send the EEPROM offset higher byte, followed by lower byte ● Send the actual data to be written ● Send the Stop condition ● START->0x50->0x00(offset high)->0x60 (offset low)- >0X99(Data)->STOP
  • 13. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Reading From EEPROM ● Write the EEPROM offset say 0x0060 (read offset) – START->0x50->0x00(offset high)->0x60 (offset low)->STOP ● Read the EEPROM data – Send the start condition – Send the slave address of EEPROM (0X50), followed by direction (Read) – Read the data – Send the stop condition – START->0x50->Data (RX)->Data (RX)->STOP
  • 14. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Need for Linux Device Model ● Maximize the code re-usability across the platforms – Same device drivers on different platforms ● To achieve this – Decouple device drivers from controller drivers – Decouple hardware description from the drivers ● In addition to above – Information about how the system is put together ● Effective power management – Communication with user space – Hotpluggable devices
  • 15. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Device Drivers in Linux Application System Call Interface Framework Driver Bus Infrastructure Hardware
  • 16. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Device model data structures ● struct bus_type – Represents the bus such as USB, PCI, I2C etc ● struct device_driver – Represents the driver capable of handling certain devices ● struct device – Represents the device connected to the bus
  • 17. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Linux I2C Subsystem ● I2C subsystem provides – API to implement I2C controller driver – API to implement I2C device driver in kernel space – An abstraction to implement the client drivers independent of adapter drivers
  • 18. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Linux I2C Subsystem ... User Space Kernel Space I2C Device (i2c_client) I2C Host Controller (i2c_adapter) Hardware Space /sys, /dev User Applications User Mode I2C Device Driver I2C Core i2c-dev Vertical: Character I2C Client Driver I2C Bus I2C Adapter (platform_driver) / Algo Driver (i2c_algorithm)
  • 19. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Subsystem Details ● i2c-adapter / i2c-algo – Controller-specific I2C host controller / adapter – Also called as the I2C bus drivers ● i2c-core – Hides the adapter details from the layers above – By providing the generic I2C APIs ● i2c-dev – Provides device access in user space through /sys – Enables implementation of User Mode Drivers ● i2c-client – Driver specific to an I2C device – Implemented using i2c-core APIs
  • 20. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Client Driver ● Typically a character driver vertical - /dev or /sys exposed ● But actually depends on the device category ● Registers with I2C Core (in the init function) ● Unregisters from I2C Core (in the cleanup function) ● And uses the generic function from I2C Core for data transfers – int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
  • 21. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Client Driver init & cleanup ● Registering to the I2C Core using – int i2c_add_driver(struct i2c_driver *) – struct i2c_driver contains ● probe function – called on device detection ● remove function – called on device shutdown ● id_table – Table of device identifiers ● Unregistering from the I2C Core using – void i2c_del_driver(struct i2c_driver *) ● Common bare-bone of init & cleanup – Just use module_i2c_driver(struct i2c_driver)
  • 22. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Client Driver Registration ● struct i2c_driver dummy_driver = { driver = { name = “dummy_client”, owner = THIS_MODULE, }, .probe = dummy_probe, .remove = dummy_remove, .id_table = dummy_ids, } ● static const struct i2c_device_id dummy_ids = { { “dummy_device”, 0}, {} } ● i2c_add_driver(dummy_driver)
  • 23. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Adapter Driver (Un)Registeration ● Registering to the I2C Core using – int i2c_add_numbered_adapter(struct i2c_adapter *); – Registered in the platform driver probe ● Unregistering from the I2C Core using – void i2c_del_adapter(struct i2c_driver *); – In platform driver remove functions
  • 24. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved I2C Client Driver Examples ● Path: <kernel_source>/drivers/ – I2C EEPROM: AT24 ● misc/eeprom/at24.c – I2C RTC: DS1307 ● rtc/rtc-ds1307.c
  • 25. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Registering the I2C Client (Non DT) ● On non-DT platforms, the struct i2c_board_info describes how device is connected to a board ● Defined with I2C_BOARD_INFO helper macro – Takes as the arguments, the device name and the slave address of the device on the bus ● An array of such structures is registered on per bus basis using the i2c_register_board_info during the platform initialization
  • 26. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Registering the I2C Client (Non DT).. ● static struct i2c_board_info my_i2c_devices [] = { { I2C_BOARD_INFO (“my_device”, 0 x1D ), . irq = 70, .platform_data = &my_data }, } ● i2c_register_board_info(0, my_i2c_devices, ARRAY_SIZE (my_i2c_devices))
  • 27. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Registering an I2C Client (DT) ● In the device tree, the I2C devices on the bus are described as children of the I2C controller node ● reg property gives the I2C slave address on the bus
  • 28. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved Registering an I2C Client (DT) ... ● i2c@49607899 { compatible = "dummy_adap"; clock-frequency = <0x186a0>; #address-cells = <0x1>; #size-cells = <0x0>; my_dummy@0 { compatible = "dummy_device"; reg = <0x40>; }; }; ● Registered internally by i2c_core based on info from DTB ● i2c_new_device(struct i2c_adapter *, struct i2c_board_info *)
  • 29. @ 2021-22 Embitude Trainings <info@embitude.in> All Rights Reserved What all did we learn? ● I2C Overview ● I2C Conditions & Transactions ● I2C Subsystem in Linux – I2C Adapter & I2C Client ● I2C Client Driver ● I2C Device Registration (Non DT and DT)