SlideShare uma empresa Scribd logo
1 de 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…

Mais conteúdo relacionado

Mais procurados (20)

Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 
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)
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Linux SD/MMC Driver Stack
Linux SD/MMC Driver Stack Linux SD/MMC Driver Stack
Linux SD/MMC Driver Stack
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
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
 
Qemu Pcie
Qemu PcieQemu Pcie
Qemu Pcie
 
Kernel Recipes 2015: Representing device-tree peripherals in ACPI
Kernel Recipes 2015: Representing device-tree peripherals in ACPIKernel Recipes 2015: Representing device-tree peripherals in ACPI
Kernel Recipes 2015: Representing device-tree peripherals in ACPI
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver艾鍗科技
 
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
 

Semelhante a 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
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver
 
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
 

Último

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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
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
 
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
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Último (20)

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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
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
 
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
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

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