SlideShare a Scribd company logo
1 of 15
I2C Subsystem
      In
 Linux 2.6.24

          Author:
          Varun Mahajan
          <varunmahajan06@gmail.com>
Contents
 ●
   Data structures representing I2C bus, device, driver, etc
 ●
   How to add an I2C device to the kernel
 ●
   What happens when a new instance of I2C bus is recognized by the
 kernel
 ●
   How to add an I2C device driver to the kernel
 ●
   Device ↔ Driver binding
Data Structures
                                                                                I2C



                                     Bus                                                                               Device



Driver                                                   Adapter                               Driver                                         Client


                                           struct i2c_adapter                         struct i2c_driver                         struct i2c_client


struct bus_type                            nr /*bus no*/                              (*probe) (i2c_client *)                   addr /*device address*/
                                                                                      (*remove) (i2c_client *)
                                           /*algorithm to access the bus*/                                                      *adapter
*name = “i2c”                              *algo                                      (*shutdown) (i2c_client *)                *driver
                                                                                      (*suspend) (i2c_client*, mesg)            driver_name
(*match) (device*, device_driver*)         (*client_register) (i2c_client*)           (*resume) (i2c_client *)                  irq
                                           (*client_unregister) (i2c_client*)
(*probe) (device *)
(*remove) (device *)                       /*list of clients*/
                                                                                                                                   struct device
                                           list_head clients                             struct device_driver
(*shutdown) (device *)
(*suspend) (device *, mesg)
(*resume) (device *)                                                                                                               *parent
                                                                                         *name                                     *driver
                                              struct device                              *bus                                      *bus
klist_devices
klist_drivers
                                                                                         kobj                                      /*driver/platform specific*/
                                                                                         klist_devices                             *driver_data
                                                                                         knode_bus                                 *platform_data

                                                                                                                                   kobj
                                                                                                                                   knode_bus
                                                                                                                                   knode_driver
Data Structures


             i2c_driver_1                  i2c_driver_2


             i2c_client_1                  i2c_client_2



                  D1                         D2



 I2C Bus 1                                                i2c_adapter_1

                                                                          I2C Bus Driver   bus_type

 I2C Bus 2                                                i2c_adapter_2



                                 D3



                            i2c_driver_3


                            i2c_client_3
How to add an I2C device to the Kernel
 Populate the __i2c_board_list in the board specific initialization code




          __i2c_board_list     List of struct i2c_devinfo



                             struct i2c_devinfo

                             busnum                         BUS_NO

                               struct
                                                            “KXSD9_driver”
                               i2c_board_info

                               driver_name
                                                            KXSD9_I2C_ADDR
                               addr

                               irq
                                                            KXSD9_IRQ
                               *platform_data

                                                             PLATFORM_DATA
When a new I2C Bus instance is recognized by Kernel

  1. A structure i2c_adapter is instantiated for the new bus instance




            struct i2c_adapter


            nr /*bus no*/                        BUS_NO

            /*algorithm to access the bus*/
            *algo

            (*client_register) (i2c_client*)
            (*client_unregister) (i2c_client*)

            /*list of clients*/
            list_head clients




               struct device
When a new I2C Bus instance is recognized by Kernel

  2. For this new adapter, the __i2c_board_list is scanned to check for
  devices whose bus nos match with the adapter’s bus no. If there is a
  match then a new i2c_client structure is created for that device



             struct i2c_client
                                                             struct i2c_devinfo
                                                BUS_NO
             addr /*device address*/
                                                             busnum
             *adapter
             *driver                   KXSD9_I2C_ADDR
             driver_name                                       struct
             irq                                               i2c_board_info
               struct device
                                                               driver_name
                                            “KXSD9_driver”

               *parent                                         addr
               *driver
               *bus                                            irq
                                            KXSD9_IRQ
               /*driver/platform                               *platform_data
               specific*/
               *driver_data
               *platform_data
                                            PLATFORM_DATA
               kobj
               knode_bus
               knode_driver
When a new I2C Bus instance is recognized by Kernel

  3. The Data structures are linked as shown below

         struct i2c_client                               struct i2c_adapter


         addr /*device address*/                         nr /*bus no*/

         *adapter                                        /*algorithm to access the bus*/
         *driver                   KXSD9_I2C_ADDR        *algo
         driver_name
         irq                                             (*client_register) (i2c_client*)
                                              BUS_NO     (*client_unregister) (i2c_client*)
           struct device
                                                         /*list of clients*/
                                        “KXSD9_driver”
                                                         list_head clients
           *parent
           *driver                                         struct device
           *bus
                                        KXSD9_IRQ
           /*driver/platform
           specific*/
           *driver_data                                    struct bus_type
           *platform_data

           kobj                                            *name = “i2c”

           knode_bus                                       (*match) (device*,
                                                           device_driver*)
           knode_driver
                                                           (*probe) (device *)
                                                           (*remove) (device *)

                                                           (*shutdown) (device *)
                                                           (*suspend) (device *, mesg)
                                                           (*resume) (device *)

                                                           klist_devices

                                                           klist_drivers
How to add an I2C device driver to the Kernel
  Populate the i2c_driver structure and define the relevant functions.
  Add this driver to the kernel through i2c_add_driver()




                struct i2c_driver
                                                   KXSD9_probe ( i2c_client *)
                (*probe) (i2c_client *)
                                                 KXSD9_remove ( i2c_client *)
                (*remove) (i2c_client *)
                                                 KXSD9_shutdown ( i2c_client *)
                (*shutdown) (i2c_client *)
                (*suspend) (i2c_client*, mesg)   KXSD9_suspend ( i2c_client *)
                (*resume) (i2c_client *)
                                                 KXSD9_resume ( i2c_client *)


                  struct device_driver


                  *name                            “I2C_driver”
                  *bus

                  kobj
                  klist_devices
                  knode_bus
Code Flow after i2c_add_driver()
Device ↔ Driver Binding
 • For this new i2c_driver the kernel scans the klist_devices of the
 i2c_bus_type structure. If an existing device’s i2c_client’s
 driver_name matches with the i2c_driver.driver’s name, then it calls
 i2c_bus_type.probe() for this matched device. I2c_bus_type.probe()
 internally calls the i2c_driver.probe(). If i2c_driver.probe() succeeds,
 the i2c_driver.driver is added to the klist_drivers of i2c_bus_type and
 the device<->driver are bound


 • i2c_driver.probe ( i2c_client * )
     – Store a reference to i2c_client* for future use
     – Initialize the device
struct i2c_client

                                KXSD9_I2C_ADDR
addr /*device address*/

*adapter
*driver                                                struct i2c_adapter
driver_name
irq                                 BUS_NO
                                                       nr /*bus no*/
  struct device
                                                       /*algorithm to access the bus*/
                                  “KXSD9_driver”       *algo
  *parent
  *driver                                              (*client_register) (i2c_client*)
  *bus                                                 (*client_unregister) (i2c_client*)

                                  KXSD9_IRQ            /*list of clients*/
  /*driver/platform
  specific*/                                           list_head clients
  *driver_data
  *platform_data                                            struct device

  kobj

  knode_bus
                                MATCH

  knode_driver                                     struct i2c_driver


                                                   (*probe) (i2c_client *)
                                                   (*remove) (i2c_client *)
  struct bus_type
                                                   (*shutdown) (i2c_client *)
                                                   (*suspend) (i2c_client*, mesg)
  *name = “i2c”                                    (*resume) (i2c_client *)

  (*match) (device*,
  device_driver*)                                    struct device_driver

  (*probe) (device *)
  (*remove) (device *)          “KXSD9_driver”       *name
                                                     *bus
  (*shutdown) (device *)
  (*suspend) (device *, mesg)                        kobj
  (*resume) (device *)
                                                     klist_devices
  klist_devices
                                                     knode_bus
  klist_drivers
struct i2c_client

                                KXSD9_I2C_ADDR
addr /*device address*/

*adapter
*driver                                               struct i2c_adapter
driver_name
irq                                BUS_NO
                                                      nr /*bus no*/
  struct device
                                                      /*algorithm to access the bus*/
                                 “KXSD9_driver”       *algo
  *parent
  *driver                                             (*client_register) (i2c_client*)
  *bus                                                (*client_unregister) (i2c_client*)

                                 KXSD9_IRQ            /*list of clients*/
  /*driver/platform
  specific*/                                          list_head clients
  *driver_data
  *platform_data                                           struct device

  kobj

  knode_bus

  knode_driver                                    struct i2c_driver


                                                  (*probe) (i2c_client *)
                                                  (*remove) (i2c_client *)
  struct bus_type
                                                  (*shutdown) (i2c_client *)
                                                  (*suspend) (i2c_client*, mesg)
  *name = “i2c”                                   (*resume) (i2c_client *)

  (*match) (device*,
  device_driver*)                                   struct device_driver

  (*probe) (device *)
  (*remove) (device *)                              *name                               “KXSD9_driver”
                                                    *bus
  (*shutdown) (device *)
  (*suspend) (device *, mesg)                       kobj
  (*resume) (device *)
                                                    klist_devices
  klist_devices
                                                    knode_bus
  klist_drivers
References
 ●
     Linux Kernel 2.6.24 Source Code
 ●
     I2C Bus Specification version 2.1 January 2000
END…

More Related Content

What's hot

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 driversHoucheng Lin
 
linux device driver
linux device driverlinux device driver
linux device driverRahul Batra
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver艾鍗科技
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network InterfacesKernel TLV
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver艾鍗科技
 
Understanding a kernel oops and a kernel panic
Understanding a kernel oops and a kernel panicUnderstanding a kernel oops and a kernel panic
Understanding a kernel oops and a kernel panicJoseph Lu
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver艾鍗科技
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsHisaki Ohara
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013Wave Digitech
 

What's hot (20)

Character drivers
Character driversCharacter drivers
Character drivers
 
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
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network Interfaces
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
Dpdk performance
Dpdk performanceDpdk performance
Dpdk performance
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Understanding a kernel oops and a kernel panic
Understanding a kernel oops and a kernel panicUnderstanding a kernel oops and a kernel panic
Understanding a kernel oops and a kernel panic
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
Linux dma engine
Linux dma engineLinux dma engine
Linux dma engine
 
wifi aware
 wifi aware wifi aware
wifi aware
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 

Viewers also liked

I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 
PR_ALT_28072015_SiConTech_acquisition
PR_ALT_28072015_SiConTech_acquisitionPR_ALT_28072015_SiConTech_acquisition
PR_ALT_28072015_SiConTech_acquisitionAkhil Srivastava
 
I2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolI2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolAnkur Soni
 
S3 Group on Code Management - RDK Users Conference 2014
S3 Group on Code Management - RDK Users Conference 2014S3 Group on Code Management - RDK Users Conference 2014
S3 Group on Code Management - RDK Users Conference 2014S3 Group | TV Technology
 
HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...
HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...
HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...Linaro
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
I2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoI2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoMike Ochtman
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern11prasoon
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
IoT - IT 423 ppt
IoT - IT 423 pptIoT - IT 423 ppt
IoT - IT 423 pptMhae Lyn
 

Viewers also liked (14)

I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
I2 c bus
I2 c busI2 c bus
I2 c bus
 
PR_ALT_28072015_SiConTech_acquisition
PR_ALT_28072015_SiConTech_acquisitionPR_ALT_28072015_SiConTech_acquisition
PR_ALT_28072015_SiConTech_acquisition
 
I2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolI2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication Protocol
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
S3 Group on Code Management - RDK Users Conference 2014
S3 Group on Code Management - RDK Users Conference 2014S3 Group on Code Management - RDK Users Conference 2014
S3 Group on Code Management - RDK Users Conference 2014
 
HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...
HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...
HKG15-506: Comcast - Lessons learned from migrating the RDK code base to the ...
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
I2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduinoI2c interfacing raspberry pi to arduino
I2c interfacing raspberry pi to arduino
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
I2C
I2CI2C
I2C
 
IoT - IT 423 ppt
IoT - IT 423 pptIoT - IT 423 ppt
IoT - IT 423 ppt
 

Similar to I2C Subsystem In Linux-2.6.24

Introduction to Android G Sensor I²C Driver on Android
Introduction to Android G Sensor I²C Driver on AndroidIntroduction to Android G Sensor I²C Driver on Android
Introduction to Android G Sensor I²C Driver on AndroidBo-Yi Wu
 
Sdk For Firmware Development
Sdk For Firmware DevelopmentSdk For Firmware Development
Sdk For Firmware DevelopmentRamesh Prasad
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2ytoshima
 
Projet d'accès aux résultats des étudiant via client mobile
Projet d'accès aux résultats des étudiant via client mobile Projet d'accès aux résultats des étudiant via client mobile
Projet d'accès aux résultats des étudiant via client mobile Patrick Bashizi
 
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...VMworld
 
Android security model
Android security modelAndroid security model
Android security modelrrand1
 
Exploit access root to kernel 2.6.32 2.6.36 privilege escalation exploit
Exploit access root to kernel 2.6.32 2.6.36   privilege escalation exploitExploit access root to kernel 2.6.32 2.6.36   privilege escalation exploit
Exploit access root to kernel 2.6.32 2.6.36 privilege escalation exploitCarlos Eduardo
 
introduction to CUDA_C.pptx it is widely used
introduction to CUDA_C.pptx it is widely usedintroduction to CUDA_C.pptx it is widely used
introduction to CUDA_C.pptx it is widely usedHimanshu577858
 
Project ACRN I2C mediator introduction
Project ACRN I2C mediator introductionProject ACRN I2C mediator introduction
Project ACRN I2C mediator introductionProject ACRN
 
Testing CAN network with help of CANToolz
Testing CAN network with help of CANToolzTesting CAN network with help of CANToolz
Testing CAN network with help of CANToolzAlexey Sintsov
 
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack FirmwareSimen Li
 
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with QtICS
 
Attacking Windows NDIS Drivers
Attacking Windows NDIS DriversAttacking Windows NDIS Drivers
Attacking Windows NDIS DriversKique Nissim
 
IoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT DevkitIoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT DevkitVasily Ryzhonkov
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale Subbu Allamaraju
 
CUDA lab's slides of "parallel programming" course
CUDA lab's slides of "parallel programming" courseCUDA lab's slides of "parallel programming" course
CUDA lab's slides of "parallel programming" courseShuai Yuan
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab workJIGAR MAKHIJA
 
Wtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_publicWtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_publicJaime Blasco
 
Jaime Blasco & Pablo Rincón - Lost in translation: WTF is happening inside m...
Jaime Blasco & Pablo Rincón -  Lost in translation: WTF is happening inside m...Jaime Blasco & Pablo Rincón -  Lost in translation: WTF is happening inside m...
Jaime Blasco & Pablo Rincón - Lost in translation: WTF is happening inside m...RootedCON
 

Similar to I2C Subsystem In Linux-2.6.24 (20)

Introduction to Android G Sensor I²C Driver on Android
Introduction to Android G Sensor I²C Driver on AndroidIntroduction to Android G Sensor I²C Driver on Android
Introduction to Android G Sensor I²C Driver on Android
 
Sdk For Firmware Development
Sdk For Firmware DevelopmentSdk For Firmware Development
Sdk For Firmware Development
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
Deep Learning Edge
Deep Learning Edge Deep Learning Edge
Deep Learning Edge
 
Projet d'accès aux résultats des étudiant via client mobile
Projet d'accès aux résultats des étudiant via client mobile Projet d'accès aux résultats des étudiant via client mobile
Projet d'accès aux résultats des étudiant via client mobile
 
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
 
Android security model
Android security modelAndroid security model
Android security model
 
Exploit access root to kernel 2.6.32 2.6.36 privilege escalation exploit
Exploit access root to kernel 2.6.32 2.6.36   privilege escalation exploitExploit access root to kernel 2.6.32 2.6.36   privilege escalation exploit
Exploit access root to kernel 2.6.32 2.6.36 privilege escalation exploit
 
introduction to CUDA_C.pptx it is widely used
introduction to CUDA_C.pptx it is widely usedintroduction to CUDA_C.pptx it is widely used
introduction to CUDA_C.pptx it is widely used
 
Project ACRN I2C mediator introduction
Project ACRN I2C mediator introductionProject ACRN I2C mediator introduction
Project ACRN I2C mediator introduction
 
Testing CAN network with help of CANToolz
Testing CAN network with help of CANToolzTesting CAN network with help of CANToolz
Testing CAN network with help of CANToolz
 
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
 
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
 
Attacking Windows NDIS Drivers
Attacking Windows NDIS DriversAttacking Windows NDIS Drivers
Attacking Windows NDIS Drivers
 
IoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT DevkitIoT Getting Started with Intel® IoT Devkit
IoT Getting Started with Intel® IoT Devkit
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale
 
CUDA lab's slides of "parallel programming" course
CUDA lab's slides of "parallel programming" courseCUDA lab's slides of "parallel programming" course
CUDA lab's slides of "parallel programming" course
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
 
Wtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_publicWtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_public
 
Jaime Blasco & Pablo Rincón - Lost in translation: WTF is happening inside m...
Jaime Blasco & Pablo Rincón -  Lost in translation: WTF is happening inside m...Jaime Blasco & Pablo Rincón -  Lost in translation: WTF is happening inside m...
Jaime Blasco & Pablo Rincón - Lost in translation: WTF is happening inside m...
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

I2C Subsystem In Linux-2.6.24

  • 1. I2C Subsystem In Linux 2.6.24 Author: Varun Mahajan <varunmahajan06@gmail.com>
  • 2. Contents ● Data structures representing I2C bus, device, driver, etc ● How to add an I2C device to the kernel ● What happens when a new instance of I2C bus is recognized by the kernel ● How to add an I2C device driver to the kernel ● Device ↔ Driver binding
  • 3. Data Structures I2C Bus Device Driver Adapter Driver Client struct i2c_adapter struct i2c_driver struct i2c_client struct bus_type nr /*bus no*/ (*probe) (i2c_client *) addr /*device address*/ (*remove) (i2c_client *) /*algorithm to access the bus*/ *adapter *name = “i2c” *algo (*shutdown) (i2c_client *) *driver (*suspend) (i2c_client*, mesg) driver_name (*match) (device*, device_driver*) (*client_register) (i2c_client*) (*resume) (i2c_client *) irq (*client_unregister) (i2c_client*) (*probe) (device *) (*remove) (device *) /*list of clients*/ struct device list_head clients struct device_driver (*shutdown) (device *) (*suspend) (device *, mesg) (*resume) (device *) *parent *name *driver struct device *bus *bus klist_devices klist_drivers kobj /*driver/platform specific*/ klist_devices *driver_data knode_bus *platform_data kobj knode_bus knode_driver
  • 4. Data Structures i2c_driver_1 i2c_driver_2 i2c_client_1 i2c_client_2 D1 D2 I2C Bus 1 i2c_adapter_1 I2C Bus Driver bus_type I2C Bus 2 i2c_adapter_2 D3 i2c_driver_3 i2c_client_3
  • 5. How to add an I2C device to the Kernel Populate the __i2c_board_list in the board specific initialization code __i2c_board_list List of struct i2c_devinfo struct i2c_devinfo busnum BUS_NO struct “KXSD9_driver” i2c_board_info driver_name KXSD9_I2C_ADDR addr irq KXSD9_IRQ *platform_data PLATFORM_DATA
  • 6. When a new I2C Bus instance is recognized by Kernel 1. A structure i2c_adapter is instantiated for the new bus instance struct i2c_adapter nr /*bus no*/ BUS_NO /*algorithm to access the bus*/ *algo (*client_register) (i2c_client*) (*client_unregister) (i2c_client*) /*list of clients*/ list_head clients struct device
  • 7. When a new I2C Bus instance is recognized by Kernel 2. For this new adapter, the __i2c_board_list is scanned to check for devices whose bus nos match with the adapter’s bus no. If there is a match then a new i2c_client structure is created for that device struct i2c_client struct i2c_devinfo BUS_NO addr /*device address*/ busnum *adapter *driver KXSD9_I2C_ADDR driver_name struct irq i2c_board_info struct device driver_name “KXSD9_driver” *parent addr *driver *bus irq KXSD9_IRQ /*driver/platform *platform_data specific*/ *driver_data *platform_data PLATFORM_DATA kobj knode_bus knode_driver
  • 8. When a new I2C Bus instance is recognized by Kernel 3. The Data structures are linked as shown below struct i2c_client struct i2c_adapter addr /*device address*/ nr /*bus no*/ *adapter /*algorithm to access the bus*/ *driver KXSD9_I2C_ADDR *algo driver_name irq (*client_register) (i2c_client*) BUS_NO (*client_unregister) (i2c_client*) struct device /*list of clients*/ “KXSD9_driver” list_head clients *parent *driver struct device *bus KXSD9_IRQ /*driver/platform specific*/ *driver_data struct bus_type *platform_data kobj *name = “i2c” knode_bus (*match) (device*, device_driver*) knode_driver (*probe) (device *) (*remove) (device *) (*shutdown) (device *) (*suspend) (device *, mesg) (*resume) (device *) klist_devices klist_drivers
  • 9. How to add an I2C device driver to the Kernel Populate the i2c_driver structure and define the relevant functions. Add this driver to the kernel through i2c_add_driver() struct i2c_driver KXSD9_probe ( i2c_client *) (*probe) (i2c_client *) KXSD9_remove ( i2c_client *) (*remove) (i2c_client *) KXSD9_shutdown ( i2c_client *) (*shutdown) (i2c_client *) (*suspend) (i2c_client*, mesg) KXSD9_suspend ( i2c_client *) (*resume) (i2c_client *) KXSD9_resume ( i2c_client *) struct device_driver *name “I2C_driver” *bus kobj klist_devices knode_bus
  • 10. Code Flow after i2c_add_driver()
  • 11. Device ↔ Driver Binding • For this new i2c_driver the kernel scans the klist_devices of the i2c_bus_type structure. If an existing device’s i2c_client’s driver_name matches with the i2c_driver.driver’s name, then it calls i2c_bus_type.probe() for this matched device. I2c_bus_type.probe() internally calls the i2c_driver.probe(). If i2c_driver.probe() succeeds, the i2c_driver.driver is added to the klist_drivers of i2c_bus_type and the device<->driver are bound • i2c_driver.probe ( i2c_client * ) – Store a reference to i2c_client* for future use – Initialize the device
  • 12. struct i2c_client KXSD9_I2C_ADDR addr /*device address*/ *adapter *driver struct i2c_adapter driver_name irq BUS_NO nr /*bus no*/ struct device /*algorithm to access the bus*/ “KXSD9_driver” *algo *parent *driver (*client_register) (i2c_client*) *bus (*client_unregister) (i2c_client*) KXSD9_IRQ /*list of clients*/ /*driver/platform specific*/ list_head clients *driver_data *platform_data struct device kobj knode_bus MATCH knode_driver struct i2c_driver (*probe) (i2c_client *) (*remove) (i2c_client *) struct bus_type (*shutdown) (i2c_client *) (*suspend) (i2c_client*, mesg) *name = “i2c” (*resume) (i2c_client *) (*match) (device*, device_driver*) struct device_driver (*probe) (device *) (*remove) (device *) “KXSD9_driver” *name *bus (*shutdown) (device *) (*suspend) (device *, mesg) kobj (*resume) (device *) klist_devices klist_devices knode_bus klist_drivers
  • 13. struct i2c_client KXSD9_I2C_ADDR addr /*device address*/ *adapter *driver struct i2c_adapter driver_name irq BUS_NO nr /*bus no*/ struct device /*algorithm to access the bus*/ “KXSD9_driver” *algo *parent *driver (*client_register) (i2c_client*) *bus (*client_unregister) (i2c_client*) KXSD9_IRQ /*list of clients*/ /*driver/platform specific*/ list_head clients *driver_data *platform_data struct device kobj knode_bus knode_driver struct i2c_driver (*probe) (i2c_client *) (*remove) (i2c_client *) struct bus_type (*shutdown) (i2c_client *) (*suspend) (i2c_client*, mesg) *name = “i2c” (*resume) (i2c_client *) (*match) (device*, device_driver*) struct device_driver (*probe) (device *) (*remove) (device *) *name “KXSD9_driver” *bus (*shutdown) (device *) (*suspend) (device *, mesg) kobj (*resume) (device *) klist_devices klist_devices knode_bus klist_drivers
  • 14. References ● Linux Kernel 2.6.24 Source Code ● I2C Bus Specification version 2.1 January 2000