SlideShare une entreprise Scribd logo
1  sur  95
Linux I2C
Kaiden Yu
1
Overview
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
2
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
3
Introduction to I2C ─ Basics
• I2C(Inter-Intergradted Circuit Bus):published by Philip,with licensed
trademark and patent (not any more)
• inter-chip communication
• wires
• SCL(Serial Clock Line)
• SDA(Serial Data Line)
• with pull-up resistors
• master/slave hierarchy
• bus speed
• 100KHz/ 400KHz/ 1MHz/ 3.4MHz/ 5MHz
4
Introduction to I2C ─ Basics
• Signal
5
Introduction to I2C ─ Basics
• Address
• 7 bits
• 10 bits
6
Introduction to I2C ─ Basics
• TWI(Two-Wire Interface):introduced by Atmel to avoid conflicts with
trademark issues related to I²C
• SMBus(System Management Bus):defined by Intel
• with tighter constraints (100KHz, timeout, format)
• I2C adapters can support most SMBus protocol, but not the other way around
• SCCB(Serial Camera Control Bus):developed by OmniVision
• three kind of transaction
• 3 Phase write
• 2 Phase read
• 2 Phase write
• Don’t care bit
7
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
8
Introduction to I2C ─ I2C/SMBus Protocol
• I2C protocol
• S (1 bit) : Start bit
• Sr (1 bit) : Repeated start bit
• Addr (7 bits): I2C 7 bit address
• Rd/Wr (1 bit) : Read/Write bit
• A, NA (1 bit) : ACK/NACK bit
• Data (8 bits)
• P (1 bit) : Stop bit
9
Introduction to I2C ─ I2C/SMBus Protocol
• Simple send transaction
• S Addr Wr [A] Data [A] Data [A] … [A] Data [A] P
• Simple receive transaction
• S Addr Rd [A] [Data] A [Data] A … A [Data] NA P
• Combined transactions
• S Addr Wr [A] Data [A] Sr Addr Rd [A] [Data] NA P
• ...
10
Introduction to I2C ─ I2C/SMBus Protocol
• SMBus protocol
• S (1 bit) : Start bit
• Sr (1 bit) : Repeated start bit
• Addr (7 bits): I2C 7 bit address
• Rd/Wr (1 bit) : Read/Write bit.
• A, NA (1 bit) : ACK/NACK bit
• Comm (8 bits): Command byte, a data byte which often selects a register on
the device.
• Data (8 bits): A plain data byte
• Count (8 bits): A data byte containing the length of a block operation.
• P (1 bit) : Stop bit
11
Introduction to I2C ─ I2C/SMBus Protocol
• SMBus Quick Command
• S Addr Rd/Wr [A] P
• SMBus Receive Byte
• S Addr Rd [A] [Data] NA P
• SMBus Send Byte
• S Addr Wr [A] Data [A] P
• SMBus Read Byte
• S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Data] NA P
• SMBus Read Word
• S Addr Wr [A] Comm [A] Sr Addr Rd [A] [DataLow] A [DataHigh] NA P
• SMBus Write Byte
• S Addr Wr [A] Comm [A] Data [A] P
• SMBus Write Word
• S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
• SMBus Process Call
• S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] Sr Addr Rd [A]
[DataLow] A [DataHigh] NA P
• SMBus Block Read
• S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Count] A [Data] A [Data]
A … A [Data] NA P
• reads a block of up to 32 bytes from a device
• SMBus Block Write
• S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] … [A] Data
[A] P
• SMBus Block Write - Block Read Process Call
• S Addr Wr [A] Comm [A] Count [A] Data [A] ... Sr Addr Rd [A]
[Count] A [Data] ... A P
• sned then read 31 bytes
• I2C Block Read
• S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Data] A [Data] A … A
[Data] NA P
• I2C Block Write
• S Addr Wr [A] Comm [A] Data [A] Data [A] … [A] Data [A] P
12
Introduction to I2C ─ I2C/SMBus Protocol
• Check the datasheet of the slave device for its protocol
13
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
14
Linux I2C ─ Linux I2C Subsystem
15
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
16
Linux I2C ─ I2C Bus Driver
• The bus driver:i2c-core (i2c-core-*.c)、i2c.h
• creates and registers the bus_type structure -> i2c_bus_type
• provides API to
• register and implement I2C adapter drivers
• register and implement I2C device drivers
• matches the device drivers against the devieces detected by the adapter driver
• define driver and device specific structures
• struct i2c_adapter
• struct i2c_algorithm
• struct i2c_client
• struct i2c_driver
• …
17
Linux I2C ─ I2C Bus Driver
• API for I2C transaction
• i2c_master_send()
• i2c_transfer_buffer_flags()
• i2c_transfer()
• i2c_master_recv()
• i2c_transfer_buffer_flags()
• i2c_transfer()
• i2c_transfer()
• __i2c_transfer()
• adap->algo->master_xfer()
18
Linux I2C ─ I2C Bus Driver
• API for Smbus transaction ─ PartI
• i2c_smbus_read_byte()
• i2c_smbus_write_byte()
• i2c_smbus_read_byte_data()
• i2c_smbus_read_word_data()
• i2c_smbus_write_byte_data()
• i2c_smbus_write_word_data()
• i2c_smbus_xfer()
• adapter->algo->smbus_xfer()
• i2c_smbus_xfer_emulated()
• i2c_transfer()
call
19
Linux I2C ─ I2C Bus Driver
• API for Smbus transaction ─ PartII
• i2c_smbus_read_block_data()
• i2c_smbus_write_block_data()
• i2c_smbus_read_i2c_block_data()
• i2c_smbus_write_i2c_block_data()
• i2c_smbus_xfer()
• adapter->algo->smbus_xfer()
• i2c_smbus_xfer_emulated()
• i2c_transfer()
call
20
Linux I2C ─ I2C Bus Driver
• Structures for I2C and SMBus transaction messages
data buffer 21
Linux I2C ─ I2C Bus Driver
• Functionalities
combinations
What about I2C_FUNC_SMBUS_READ_BLOCK_DATA?
22
Linux I2C ─ I2C Bus Driver
• Device Model data structures
• Adapter
• Bus:struct bus_type platform_bus_type
• Driver:struct platform_driver
• Device:struct i2c_adapter
• Struct i2c_algorithm
• Client
• Bus:struct bus_type i2c_bus_type
• Driver:Struct i2c_driver
• Device:Struct i2c_client
※ Adapter could belong to other device driver
• module_usb_driver(/drivers/i2c/busses/i2c-robotfuzz-
osif.c )
• module_acpi_driver(/drivers/i2c/busses/i2c-scmi.c)
• module_serio_driver(/i2c/busses/i2c-taos-evm.c)
• isa_driver(/drivers/i2c/busses/i2c-elektor.c)
23
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
24
Linux I2C ─ I2C Adapter Driver
• Adapter driver(/drivers/i2c/busses/i2c-cadence.c)
struct cdns_i2c
struct i2c_algorithm cdns_i2c_algo
cdns_i2c_probe()
cdns_i2c_remove()
struct platform_driver cdns_i2c_drv
module_platform_driver(cdns_i2c_drv)
25
Linux I2C ─ I2C Adapter Driver
• i2c_adapter structure
26
Linux I2C ─ I2C Adapter Driver
• i2c_algorithm structure
• master_xfer
 i2c access
 can emulate Smbus
protocol
• smbus_xfer
• smbus access
27
Linux I2C ─ I2C Adapter Driver
• Algorithm
28
Linux I2C ─ I2C Adapter Driver
• Transaction
• static int cdns_i2c_master_xfer()
• cdns_i2c_process_msg()
• cdns_i2c_mrecv()
• cdns_i2c_readreg()
• cdns_i2c_writereg()
• cdns_i2c_msend()
• cdns_i2c_readreg()
• cdns_i2c_writereg()
29
Linux I2C ─ I2C Adapter Driver
• Memory-mapped I/O access
30
Linux I2C ─ I2C Adapter Driver
• register offsets and bit mask definitions
31
Linux I2C ─ I2C Adapter Driver
• Probe / remove
32
Linux I2C ─ I2C Adapter Driver
• Get/set driver data
33
Linux I2C ─ I2C Adapter Driver
• i2c_add_adapter() / i2c_del_adapter()
• i2c_add_adapter()
• i2c_register_adapter()
• device_register(&adap->dev)
• device_add()
• of_i2c_register_devices()
• of_i2c_register_device()
• i2c_new_device()
• device_register(&client->dev)
• device_add()
• i2c_del_adapter()
• i2c_unregister_device(client)
• device_unregister(&client->dev)
• device_del()
• device_unregister(&adap->dev)
• device_del()
34
Linux I2C ─ I2C Adapter Driver
• Matching /arch/arm64/boot/dts/xilinx/zynqmp.dtsi
35
Linux I2C ─ I2C Adapter Driver
• Device driver structure
36
Linux I2C ─ I2C Adapter Driver
• Driver registration/unregistration
37
Linux I2C ─ I2C Adapter Driver
• platform_driver_register() / platrom_driver_unregister()
38
Linux I2C ─ I2C Adapter Driver
• driver_register()
• bus_add_driver()
• driver_attach()
• __driver_attach()
• driver_probe_device()
• really_probe()
probe not assigned in Platform_bus_type
so drv->probe will be called
39
Linux I2C ─ I2C Adapter Driver
• driver_unregister()
• Bus_remove_driver()
• Driver_detach()
• Device_release_driver_internal()
• __device_release_driver()
remove not assigned in platform_bus_type
so drv->remove will be called
40
Linux I2C ─ I2C Adapter Driver
• platform_drv_probe() / platform_drv_remove()
41
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
42
Linux I2C ─ I2C-Dev Driver
• I2c-dev.c
• i2cdev_read()
• i2cdev_write()
• I2cdev_ioctl()
• I2cdev_open()
• I2cdev_release()
• Struct file_operations i2cdev_fops
• i2c_dev_init()
• i2c_dev_exit()
43
Linux I2C ─ I2C-Dev Driver
• i2cdev_open()
• i2c_get_adapter()
• idr_find()
• try_module_get()
• get_device()
• creates an anonymous i2c_client
• can be pointed to address using
I2C_SLAVE or I2C_SLAVE_FORCE
• assign file->private_data to client
44
Linux I2C ─ I2C-Dev Driver
• i2cdev_release()
• i2c_put_adapter()
• put_device()
• module_put()
• kfree client
• assign file->private_data to NULL
45
Linux I2C ─ I2C-Dev Driver
• i2cdev_write()
• medup_user()
• copy_from_user()
• i2c_master_send()
• i2c_transfer_buffer_flasgs(…, 0)
• i2c_transfer()
• __i2c_transfer()
• adap->algo->master_xfer()
• i2cdev_read()
• i2c_master_recv()
• i2c_transfer_buffer_flags(..., I2C_M_RD)
• i2c_transfer()
• __i2c_transfer()
• adap->algo->master_xfer()
• copy_to_user()
eventually calls algo->master_xfer()
which means SMBus adapters won’t support
these functions 46
Linux I2C ─ I2C-Dev Driver
• i2cdev_ioctl() ─ set slave address
• if cmd==I2C_SLAVE_FORCE,
i2cdev_check_addr won’t
be called
• i2cdev_check_addr()
• i2cdev_check()
• busy if driver bound to it
47
Linux I2C ─ I2C-Dev Driver
• i2cdev_ioctl() ─ ten bit address
48
Linux I2C ─ I2C-Dev Driver
• i2cdev_ioctl() ─ get functionality
49
Linux I2C ─ I2C-Dev Driver
• i2cdev_ioctl() ─ I2C transaction
• copy i2c_rdwr_ioctl_data
• copy i2c_msg
• i2cdev_ioctl_rdwr()
50
Linux I2C ─ I2C-Dev Driver
• copy i2c_msg buf
• i2c_transfer()
• copy to user if I2C_M_RD is set
• i2cdev_ioctl() ─ I2C transaction
51
Linux I2C ─ I2C-Dev Driver
• Structures for I2C transaction
data buffer
52
Linux I2C ─ I2C-Dev Driver
• copy i2c_smbus_ioctl_data
• i2cdev_ioctl_smbus()
• SMBus protocol transaction
53
Linux I2C ─ I2C-Dev Driver
• copy i2c_smbus_data data
• i2c_smbus_xfer()
• copy to user if I2C_SMBUS_READ or
PROC_CALL is set
• SMBus protocol transaction
54
Linux I2C ─ I2C-Dev Driver
• Structures for SMBus transaction
55
Linux I2C ─ I2C-Dev Driver
• struct file_operations i2cdev_fops
Userspace
• read()
• write()
• Ioctl()
• open()
• close()
56
Linux I2C ─ I2C-Dev Driver
• register major number(89) and
minor numbers
• create class structure
• call i2c_attach_adapter for every
adapter
• create cdev structure
• add character device to system
• create device (/dev/i2c-%d)
• i2c_dev_init()
57
Linux I2C ─ I2C-Dev Driver
• i2c_dev_exit()
• call i2c_detach_adapter() for
every adapter
• destroy class structure
• unregister major number(89) and
minor numbers
• create cdev structure
• destroy device
58
Linux I2C ─ I2C-Dev Driver
59
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
60
Linux I2C ─ I2C-Tools
• I2C-tools
i2cdetect
i2cdump
i2cset
i2cget
i2ctransfer
• By “apt-get install i2c-tools”
this executable won’t be included
61
Linux I2C ─ I2C-Tools
• i2cdetect:show all the adapter(bus) info
62
Linux I2C ─ I2C-Tools
• i2cdetect:check funtionality
63
Linux I2C ─ I2C-Tools
• i2cdetect:check slave devices attach to a certain adapter
64
Linux I2C ─ I2C-Tools
• i2cdump:show the values of all the registers within a slave device
65
Linux I2C ─ I2C-Tools
• i2cget/i2cset:SMBus transaction
• i2ctransfer:I2C transaction
I2C transaction not supported by a SMBus adapter
66
Linux I2C ─ I2C-Tools
• i2cget/i2cset:SMBus transaction
• i2ctransfer:I2C transaction
both kinds of transaction work well on a I2C adatper67
Linux I2C ─ I2C-Tools
• I2C-tools source code:tools/i2cbusses.c
68
Linux I2C ─ I2C-Tools
• I2C-tools source code:lib/smbus.c
69
Linux I2C ─ I2C-Tools
• i2c-tools source code:tools/i2ctransfer.c
70
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
71
Linux I2C ─ I2C-Stub Driver
• I2C-stub driver: a fake I2C/SMBus driver
72
Linux I2C ─ I2C-Stub Driver
• I2C-stub adapter funtionality
73
Linux I2C ─ I2C-Stub Driver
• chip_addr:slave address of virtual client
74
Linux I2C ─ I2C-Stub Driver
• I2C-stub adapter works as a real adapter (can do SMBus transfer)
75
Linux I2C ─ I2C-Stub Driver
• I2C driver testing with i2c-stub adapter
• addresses of eeprom device are between 0x50~ 0x57
• with chip_addr=0x50, device will be bound after modprobe eeprom driver
76
Linux I2C ─ I2C-Stub Driver
• I2C driver testing with i2c-stub adapter
• with chip_addr=0x70, device won’t be detected after modprobe eeprom
driver -> file “new_device” comes to the rescue
77
Linux I2C ─ I2C-Stub Driver
• I2C driver testing with i2c-stub adapter
• devices:new_device/delete_device
78
Linux I2C ─ I2C-Stub Driver
• I2C driver testing with i2c-stub adapter
• drivers:bind/unbind
79
• Introduction to I2C
• Basics
• I2C/SMBus Protocol
• Linux I2C
• Linux I2C Subsystem
• I2C Bus Driver
• I2C Adapter Driver
• I2C-Dev Driver
• I2C-Tools
• I2C-Stub Driver
• I2C Client Driver
80
Linux I2C ─ I2C Client Driver
• Client driver (/drivers/mfd/tps65086.c)
tps65086_probe()
tps65086_remove()
struct i2c_driver tps65086_driver
module_i2c_driver(tps65086_driver)
81
Linux I2C ─ I2C Client Driver
• Probe / remove
82
Linux I2C ─ I2C Client Driver
• i2c_get_clientdata() / i2c_set_clientdata()
83
Linux I2C ─ I2C Client Driver
• devmem_regmap_init_i2c()
• __regmap_lockdep_wrapper()
• __regmap_init_i2c()
• regmap_get_i2c_bus()
• i2c_check_functionality()
• return
• __regmap_init()
&regmap_i2c
&regmap_i2c_smbus_i2c_block
&regmap_smbus_word_swapped
&regmap_smbus_word
&regmap_smbus_byte
84
Linux I2C ─ I2C Client Driver
• regmap_i2c
85
Linux I2C ─ I2C Client Driver
• mfd_add_devices()
• mfd_add_device()
• platform_device_add()
• device_add()
86
Linux I2C ─ I2C Client Driver
• Matching /arch/arm64/boot/dts/xilinx/zynqmp-zcu100-recvC.dts
87
Linux I2C ─ I2C Client Driver
• Device driver structure
88
Linux I2C ─ I2C Client Driver
• Driver registration/unregistration
89
Linux I2C ─ I2C Client Driver
• i2c_add_driver() / i2c_del_driver()
90
Linux I2C ─ I2C Client Driver
• driver_register()
• bus_add_driver()
• driver_attach()
• __driver_attach()
• driver_probe_device()
• really_probe()
probe is assigned in i2_bus_type
so bus->probe will be called
91
Linux I2C ─ I2C Client Driver
• driver_unregister()
• Bus_remove_driver()
• Driver_detach()
• Device_release_driver_internal()
• __device_release_driver()
92
Linux I2C ─ I2C Client Driver
• i2c_device_probe() / i2c_device_remove()
93
Linux I2C ─ I2C Client Driver
• __process_new_driver()
• i2c_do_add_adapter()
• i2c_detect()
• i2c_detect_address()
• i2c_default_probe()
• i2c_check_functionality()
• i2c_smbus_xfer()
• driver->detect()
• i2c_new_device()
• device_register(&client->dev)
• device_add()
• driver->attach_adapter()
• __process_removed_driver()
• i2c_do_del_adapter()
• i2c_unregister_device()
• device_unregister(&client->dev)
• device_del()
94
Thank you for your patience
95

Contenu connexe

Tendances

U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
Macpaul Lin
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
Houcheng Lin
 

Tendances (20)

用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 
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 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)
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Kernel Process Management
Kernel Process ManagementKernel Process Management
Kernel Process Management
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 

Similaire à Linux I2C

SIMD inside and outside oracle 12c
SIMD inside and outside oracle 12cSIMD inside and outside oracle 12c
SIMD inside and outside oracle 12c
Laurent Leturgez
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
Techvilla
 

Similaire à Linux I2C (20)

Electric Imp - Hackathon Intro
Electric Imp - Hackathon IntroElectric Imp - Hackathon Intro
Electric Imp - Hackathon Intro
 
Introduction to Hardware Design Using KiCAD
Introduction to Hardware Design Using KiCADIntroduction to Hardware Design Using KiCAD
Introduction to Hardware Design Using KiCAD
 
SIMD inside and outside oracle 12c
SIMD inside and outside oracle 12cSIMD inside and outside oracle 12c
SIMD inside and outside oracle 12c
 
Serial Busses.pptx
Serial Busses.pptxSerial Busses.pptx
Serial Busses.pptx
 
ch11_031102.ppt
ch11_031102.pptch11_031102.ppt
ch11_031102.ppt
 
serial_busses_i2c.pptx
serial_busses_i2c.pptxserial_busses_i2c.pptx
serial_busses_i2c.pptx
 
Webinar mdc i_kan_20170417 final
Webinar mdc i_kan_20170417 finalWebinar mdc i_kan_20170417 final
Webinar mdc i_kan_20170417 final
 
REDA services
REDA servicesREDA services
REDA services
 
[Advantech] PAC SW Multiprog Tutorial step by step
[Advantech] PAC SW Multiprog Tutorial step by step [Advantech] PAC SW Multiprog Tutorial step by step
[Advantech] PAC SW Multiprog Tutorial step by step
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
 
L5-Sockets.pptx
L5-Sockets.pptxL5-Sockets.pptx
L5-Sockets.pptx
 
Ch6 030702
Ch6 030702Ch6 030702
Ch6 030702
 
S2C China ICCAD 2010 Presentation
S2C China ICCAD 2010 PresentationS2C China ICCAD 2010 Presentation
S2C China ICCAD 2010 Presentation
 
Skillwise cics part 1
Skillwise cics part 1Skillwise cics part 1
Skillwise cics part 1
 
Emeded coder
Emeded coderEmeded coder
Emeded coder
 
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
 
A2 e overview
A2 e overviewA2 e overview
A2 e overview
 
Basics of Network Layer and Transport Layer
Basics of Network Layer and Transport LayerBasics of Network Layer and Transport Layer
Basics of Network Layer and Transport Layer
 
IBM IoT Architecture and Capabilities at the Edge and Cloud
IBM IoT Architecture and Capabilities at the Edge and Cloud IBM IoT Architecture and Capabilities at the Edge and Cloud
IBM IoT Architecture and Capabilities at the Edge and Cloud
 
Processors selection
Processors selectionProcessors selection
Processors selection
 

Dernier

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 

Dernier (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
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...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
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 Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 

Linux I2C

  • 2. Overview • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 2
  • 3. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 3
  • 4. Introduction to I2C ─ Basics • I2C(Inter-Intergradted Circuit Bus):published by Philip,with licensed trademark and patent (not any more) • inter-chip communication • wires • SCL(Serial Clock Line) • SDA(Serial Data Line) • with pull-up resistors • master/slave hierarchy • bus speed • 100KHz/ 400KHz/ 1MHz/ 3.4MHz/ 5MHz 4
  • 5. Introduction to I2C ─ Basics • Signal 5
  • 6. Introduction to I2C ─ Basics • Address • 7 bits • 10 bits 6
  • 7. Introduction to I2C ─ Basics • TWI(Two-Wire Interface):introduced by Atmel to avoid conflicts with trademark issues related to I²C • SMBus(System Management Bus):defined by Intel • with tighter constraints (100KHz, timeout, format) • I2C adapters can support most SMBus protocol, but not the other way around • SCCB(Serial Camera Control Bus):developed by OmniVision • three kind of transaction • 3 Phase write • 2 Phase read • 2 Phase write • Don’t care bit 7
  • 8. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 8
  • 9. Introduction to I2C ─ I2C/SMBus Protocol • I2C protocol • S (1 bit) : Start bit • Sr (1 bit) : Repeated start bit • Addr (7 bits): I2C 7 bit address • Rd/Wr (1 bit) : Read/Write bit • A, NA (1 bit) : ACK/NACK bit • Data (8 bits) • P (1 bit) : Stop bit 9
  • 10. Introduction to I2C ─ I2C/SMBus Protocol • Simple send transaction • S Addr Wr [A] Data [A] Data [A] … [A] Data [A] P • Simple receive transaction • S Addr Rd [A] [Data] A [Data] A … A [Data] NA P • Combined transactions • S Addr Wr [A] Data [A] Sr Addr Rd [A] [Data] NA P • ... 10
  • 11. Introduction to I2C ─ I2C/SMBus Protocol • SMBus protocol • S (1 bit) : Start bit • Sr (1 bit) : Repeated start bit • Addr (7 bits): I2C 7 bit address • Rd/Wr (1 bit) : Read/Write bit. • A, NA (1 bit) : ACK/NACK bit • Comm (8 bits): Command byte, a data byte which often selects a register on the device. • Data (8 bits): A plain data byte • Count (8 bits): A data byte containing the length of a block operation. • P (1 bit) : Stop bit 11
  • 12. Introduction to I2C ─ I2C/SMBus Protocol • SMBus Quick Command • S Addr Rd/Wr [A] P • SMBus Receive Byte • S Addr Rd [A] [Data] NA P • SMBus Send Byte • S Addr Wr [A] Data [A] P • SMBus Read Byte • S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Data] NA P • SMBus Read Word • S Addr Wr [A] Comm [A] Sr Addr Rd [A] [DataLow] A [DataHigh] NA P • SMBus Write Byte • S Addr Wr [A] Comm [A] Data [A] P • SMBus Write Word • S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P • SMBus Process Call • S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] Sr Addr Rd [A] [DataLow] A [DataHigh] NA P • SMBus Block Read • S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Count] A [Data] A [Data] A … A [Data] NA P • reads a block of up to 32 bytes from a device • SMBus Block Write • S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] … [A] Data [A] P • SMBus Block Write - Block Read Process Call • S Addr Wr [A] Comm [A] Count [A] Data [A] ... Sr Addr Rd [A] [Count] A [Data] ... A P • sned then read 31 bytes • I2C Block Read • S Addr Wr [A] Comm [A] Sr Addr Rd [A] [Data] A [Data] A … A [Data] NA P • I2C Block Write • S Addr Wr [A] Comm [A] Data [A] Data [A] … [A] Data [A] P 12
  • 13. Introduction to I2C ─ I2C/SMBus Protocol • Check the datasheet of the slave device for its protocol 13
  • 14. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 14
  • 15. Linux I2C ─ Linux I2C Subsystem 15
  • 16. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 16
  • 17. Linux I2C ─ I2C Bus Driver • The bus driver:i2c-core (i2c-core-*.c)、i2c.h • creates and registers the bus_type structure -> i2c_bus_type • provides API to • register and implement I2C adapter drivers • register and implement I2C device drivers • matches the device drivers against the devieces detected by the adapter driver • define driver and device specific structures • struct i2c_adapter • struct i2c_algorithm • struct i2c_client • struct i2c_driver • … 17
  • 18. Linux I2C ─ I2C Bus Driver • API for I2C transaction • i2c_master_send() • i2c_transfer_buffer_flags() • i2c_transfer() • i2c_master_recv() • i2c_transfer_buffer_flags() • i2c_transfer() • i2c_transfer() • __i2c_transfer() • adap->algo->master_xfer() 18
  • 19. Linux I2C ─ I2C Bus Driver • API for Smbus transaction ─ PartI • i2c_smbus_read_byte() • i2c_smbus_write_byte() • i2c_smbus_read_byte_data() • i2c_smbus_read_word_data() • i2c_smbus_write_byte_data() • i2c_smbus_write_word_data() • i2c_smbus_xfer() • adapter->algo->smbus_xfer() • i2c_smbus_xfer_emulated() • i2c_transfer() call 19
  • 20. Linux I2C ─ I2C Bus Driver • API for Smbus transaction ─ PartII • i2c_smbus_read_block_data() • i2c_smbus_write_block_data() • i2c_smbus_read_i2c_block_data() • i2c_smbus_write_i2c_block_data() • i2c_smbus_xfer() • adapter->algo->smbus_xfer() • i2c_smbus_xfer_emulated() • i2c_transfer() call 20
  • 21. Linux I2C ─ I2C Bus Driver • Structures for I2C and SMBus transaction messages data buffer 21
  • 22. Linux I2C ─ I2C Bus Driver • Functionalities combinations What about I2C_FUNC_SMBUS_READ_BLOCK_DATA? 22
  • 23. Linux I2C ─ I2C Bus Driver • Device Model data structures • Adapter • Bus:struct bus_type platform_bus_type • Driver:struct platform_driver • Device:struct i2c_adapter • Struct i2c_algorithm • Client • Bus:struct bus_type i2c_bus_type • Driver:Struct i2c_driver • Device:Struct i2c_client ※ Adapter could belong to other device driver • module_usb_driver(/drivers/i2c/busses/i2c-robotfuzz- osif.c ) • module_acpi_driver(/drivers/i2c/busses/i2c-scmi.c) • module_serio_driver(/i2c/busses/i2c-taos-evm.c) • isa_driver(/drivers/i2c/busses/i2c-elektor.c) 23
  • 24. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 24
  • 25. Linux I2C ─ I2C Adapter Driver • Adapter driver(/drivers/i2c/busses/i2c-cadence.c) struct cdns_i2c struct i2c_algorithm cdns_i2c_algo cdns_i2c_probe() cdns_i2c_remove() struct platform_driver cdns_i2c_drv module_platform_driver(cdns_i2c_drv) 25
  • 26. Linux I2C ─ I2C Adapter Driver • i2c_adapter structure 26
  • 27. Linux I2C ─ I2C Adapter Driver • i2c_algorithm structure • master_xfer  i2c access  can emulate Smbus protocol • smbus_xfer • smbus access 27
  • 28. Linux I2C ─ I2C Adapter Driver • Algorithm 28
  • 29. Linux I2C ─ I2C Adapter Driver • Transaction • static int cdns_i2c_master_xfer() • cdns_i2c_process_msg() • cdns_i2c_mrecv() • cdns_i2c_readreg() • cdns_i2c_writereg() • cdns_i2c_msend() • cdns_i2c_readreg() • cdns_i2c_writereg() 29
  • 30. Linux I2C ─ I2C Adapter Driver • Memory-mapped I/O access 30
  • 31. Linux I2C ─ I2C Adapter Driver • register offsets and bit mask definitions 31
  • 32. Linux I2C ─ I2C Adapter Driver • Probe / remove 32
  • 33. Linux I2C ─ I2C Adapter Driver • Get/set driver data 33
  • 34. Linux I2C ─ I2C Adapter Driver • i2c_add_adapter() / i2c_del_adapter() • i2c_add_adapter() • i2c_register_adapter() • device_register(&adap->dev) • device_add() • of_i2c_register_devices() • of_i2c_register_device() • i2c_new_device() • device_register(&client->dev) • device_add() • i2c_del_adapter() • i2c_unregister_device(client) • device_unregister(&client->dev) • device_del() • device_unregister(&adap->dev) • device_del() 34
  • 35. Linux I2C ─ I2C Adapter Driver • Matching /arch/arm64/boot/dts/xilinx/zynqmp.dtsi 35
  • 36. Linux I2C ─ I2C Adapter Driver • Device driver structure 36
  • 37. Linux I2C ─ I2C Adapter Driver • Driver registration/unregistration 37
  • 38. Linux I2C ─ I2C Adapter Driver • platform_driver_register() / platrom_driver_unregister() 38
  • 39. Linux I2C ─ I2C Adapter Driver • driver_register() • bus_add_driver() • driver_attach() • __driver_attach() • driver_probe_device() • really_probe() probe not assigned in Platform_bus_type so drv->probe will be called 39
  • 40. Linux I2C ─ I2C Adapter Driver • driver_unregister() • Bus_remove_driver() • Driver_detach() • Device_release_driver_internal() • __device_release_driver() remove not assigned in platform_bus_type so drv->remove will be called 40
  • 41. Linux I2C ─ I2C Adapter Driver • platform_drv_probe() / platform_drv_remove() 41
  • 42. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 42
  • 43. Linux I2C ─ I2C-Dev Driver • I2c-dev.c • i2cdev_read() • i2cdev_write() • I2cdev_ioctl() • I2cdev_open() • I2cdev_release() • Struct file_operations i2cdev_fops • i2c_dev_init() • i2c_dev_exit() 43
  • 44. Linux I2C ─ I2C-Dev Driver • i2cdev_open() • i2c_get_adapter() • idr_find() • try_module_get() • get_device() • creates an anonymous i2c_client • can be pointed to address using I2C_SLAVE or I2C_SLAVE_FORCE • assign file->private_data to client 44
  • 45. Linux I2C ─ I2C-Dev Driver • i2cdev_release() • i2c_put_adapter() • put_device() • module_put() • kfree client • assign file->private_data to NULL 45
  • 46. Linux I2C ─ I2C-Dev Driver • i2cdev_write() • medup_user() • copy_from_user() • i2c_master_send() • i2c_transfer_buffer_flasgs(…, 0) • i2c_transfer() • __i2c_transfer() • adap->algo->master_xfer() • i2cdev_read() • i2c_master_recv() • i2c_transfer_buffer_flags(..., I2C_M_RD) • i2c_transfer() • __i2c_transfer() • adap->algo->master_xfer() • copy_to_user() eventually calls algo->master_xfer() which means SMBus adapters won’t support these functions 46
  • 47. Linux I2C ─ I2C-Dev Driver • i2cdev_ioctl() ─ set slave address • if cmd==I2C_SLAVE_FORCE, i2cdev_check_addr won’t be called • i2cdev_check_addr() • i2cdev_check() • busy if driver bound to it 47
  • 48. Linux I2C ─ I2C-Dev Driver • i2cdev_ioctl() ─ ten bit address 48
  • 49. Linux I2C ─ I2C-Dev Driver • i2cdev_ioctl() ─ get functionality 49
  • 50. Linux I2C ─ I2C-Dev Driver • i2cdev_ioctl() ─ I2C transaction • copy i2c_rdwr_ioctl_data • copy i2c_msg • i2cdev_ioctl_rdwr() 50
  • 51. Linux I2C ─ I2C-Dev Driver • copy i2c_msg buf • i2c_transfer() • copy to user if I2C_M_RD is set • i2cdev_ioctl() ─ I2C transaction 51
  • 52. Linux I2C ─ I2C-Dev Driver • Structures for I2C transaction data buffer 52
  • 53. Linux I2C ─ I2C-Dev Driver • copy i2c_smbus_ioctl_data • i2cdev_ioctl_smbus() • SMBus protocol transaction 53
  • 54. Linux I2C ─ I2C-Dev Driver • copy i2c_smbus_data data • i2c_smbus_xfer() • copy to user if I2C_SMBUS_READ or PROC_CALL is set • SMBus protocol transaction 54
  • 55. Linux I2C ─ I2C-Dev Driver • Structures for SMBus transaction 55
  • 56. Linux I2C ─ I2C-Dev Driver • struct file_operations i2cdev_fops Userspace • read() • write() • Ioctl() • open() • close() 56
  • 57. Linux I2C ─ I2C-Dev Driver • register major number(89) and minor numbers • create class structure • call i2c_attach_adapter for every adapter • create cdev structure • add character device to system • create device (/dev/i2c-%d) • i2c_dev_init() 57
  • 58. Linux I2C ─ I2C-Dev Driver • i2c_dev_exit() • call i2c_detach_adapter() for every adapter • destroy class structure • unregister major number(89) and minor numbers • create cdev structure • destroy device 58
  • 59. Linux I2C ─ I2C-Dev Driver 59
  • 60. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 60
  • 61. Linux I2C ─ I2C-Tools • I2C-tools i2cdetect i2cdump i2cset i2cget i2ctransfer • By “apt-get install i2c-tools” this executable won’t be included 61
  • 62. Linux I2C ─ I2C-Tools • i2cdetect:show all the adapter(bus) info 62
  • 63. Linux I2C ─ I2C-Tools • i2cdetect:check funtionality 63
  • 64. Linux I2C ─ I2C-Tools • i2cdetect:check slave devices attach to a certain adapter 64
  • 65. Linux I2C ─ I2C-Tools • i2cdump:show the values of all the registers within a slave device 65
  • 66. Linux I2C ─ I2C-Tools • i2cget/i2cset:SMBus transaction • i2ctransfer:I2C transaction I2C transaction not supported by a SMBus adapter 66
  • 67. Linux I2C ─ I2C-Tools • i2cget/i2cset:SMBus transaction • i2ctransfer:I2C transaction both kinds of transaction work well on a I2C adatper67
  • 68. Linux I2C ─ I2C-Tools • I2C-tools source code:tools/i2cbusses.c 68
  • 69. Linux I2C ─ I2C-Tools • I2C-tools source code:lib/smbus.c 69
  • 70. Linux I2C ─ I2C-Tools • i2c-tools source code:tools/i2ctransfer.c 70
  • 71. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 71
  • 72. Linux I2C ─ I2C-Stub Driver • I2C-stub driver: a fake I2C/SMBus driver 72
  • 73. Linux I2C ─ I2C-Stub Driver • I2C-stub adapter funtionality 73
  • 74. Linux I2C ─ I2C-Stub Driver • chip_addr:slave address of virtual client 74
  • 75. Linux I2C ─ I2C-Stub Driver • I2C-stub adapter works as a real adapter (can do SMBus transfer) 75
  • 76. Linux I2C ─ I2C-Stub Driver • I2C driver testing with i2c-stub adapter • addresses of eeprom device are between 0x50~ 0x57 • with chip_addr=0x50, device will be bound after modprobe eeprom driver 76
  • 77. Linux I2C ─ I2C-Stub Driver • I2C driver testing with i2c-stub adapter • with chip_addr=0x70, device won’t be detected after modprobe eeprom driver -> file “new_device” comes to the rescue 77
  • 78. Linux I2C ─ I2C-Stub Driver • I2C driver testing with i2c-stub adapter • devices:new_device/delete_device 78
  • 79. Linux I2C ─ I2C-Stub Driver • I2C driver testing with i2c-stub adapter • drivers:bind/unbind 79
  • 80. • Introduction to I2C • Basics • I2C/SMBus Protocol • Linux I2C • Linux I2C Subsystem • I2C Bus Driver • I2C Adapter Driver • I2C-Dev Driver • I2C-Tools • I2C-Stub Driver • I2C Client Driver 80
  • 81. Linux I2C ─ I2C Client Driver • Client driver (/drivers/mfd/tps65086.c) tps65086_probe() tps65086_remove() struct i2c_driver tps65086_driver module_i2c_driver(tps65086_driver) 81
  • 82. Linux I2C ─ I2C Client Driver • Probe / remove 82
  • 83. Linux I2C ─ I2C Client Driver • i2c_get_clientdata() / i2c_set_clientdata() 83
  • 84. Linux I2C ─ I2C Client Driver • devmem_regmap_init_i2c() • __regmap_lockdep_wrapper() • __regmap_init_i2c() • regmap_get_i2c_bus() • i2c_check_functionality() • return • __regmap_init() &regmap_i2c &regmap_i2c_smbus_i2c_block &regmap_smbus_word_swapped &regmap_smbus_word &regmap_smbus_byte 84
  • 85. Linux I2C ─ I2C Client Driver • regmap_i2c 85
  • 86. Linux I2C ─ I2C Client Driver • mfd_add_devices() • mfd_add_device() • platform_device_add() • device_add() 86
  • 87. Linux I2C ─ I2C Client Driver • Matching /arch/arm64/boot/dts/xilinx/zynqmp-zcu100-recvC.dts 87
  • 88. Linux I2C ─ I2C Client Driver • Device driver structure 88
  • 89. Linux I2C ─ I2C Client Driver • Driver registration/unregistration 89
  • 90. Linux I2C ─ I2C Client Driver • i2c_add_driver() / i2c_del_driver() 90
  • 91. Linux I2C ─ I2C Client Driver • driver_register() • bus_add_driver() • driver_attach() • __driver_attach() • driver_probe_device() • really_probe() probe is assigned in i2_bus_type so bus->probe will be called 91
  • 92. Linux I2C ─ I2C Client Driver • driver_unregister() • Bus_remove_driver() • Driver_detach() • Device_release_driver_internal() • __device_release_driver() 92
  • 93. Linux I2C ─ I2C Client Driver • i2c_device_probe() / i2c_device_remove() 93
  • 94. Linux I2C ─ I2C Client Driver • __process_new_driver() • i2c_do_add_adapter() • i2c_detect() • i2c_detect_address() • i2c_default_probe() • i2c_check_functionality() • i2c_smbus_xfer() • driver->detect() • i2c_new_device() • device_register(&client->dev) • device_add() • driver->attach_adapter() • __process_removed_driver() • i2c_do_del_adapter() • i2c_unregister_device() • device_unregister(&client->dev) • device_del() 94
  • 95. Thank you for your patience 95