Linux I2C core, bus and device drivers

  
 

The I2C bus uses only two signal lines, SCL and SDA, to implement data interaction between devices, greatly simplifying the occupation of hardware resources and PCB board layout space. Therefore, the I2C bus is widely used in interfaces between devices such as EEPROMs, real clocks, and small LCDs and CPUs.

Linux defines the system's I2C driver architecture. In Linux systems, the I2C driver consists of three parts, namely the I2C core, the I2C bus driver, and the I2C device driver. These three parts work together to form a very versatile and adaptable I2C framework.

The first section of this chapter will analyze the Linux I2C architecture and explain the functions and interconnections of the three components.

Section 2 will analyze the Linux I2C core and explain the functions of the i2c-core.c file and the implementation of the main functions.

Sections 3 and 4 will detail the I2C bus driver and I2C device driver writing methods, respectively, and give a design template for reference.

Sections 5 and 6 will be based on the design templates given in Sections 3 and 4, explaining the S3C2410 ARM processor I2C bus driver and the SAA7113H video analog/digital converter chip device mounted on it. Write a method.

15.1 Linux I2C Architecture

The Linux I2C architecture is divided into three components:

? I2C Core

I2C Core provides I2C bus Driver and device driver registration, logout method, I2C communication method (ie, "algorithm", I believe that literal translation is "calculation method" is not appropriate, in order to avoid misunderstanding, the following will directly use the "algorithm" The code that is not related to the specific adapter, the detection device, the upper layer code of the detection device address, and the like.

? I2C Bus Driver

The I2C bus driver is an implementation of the adapter side of the I2C hardware architecture. The adapter can be controlled by the CPU or even directly integrated into the CPU.

The I2C bus driver mainly includes the I2C adapter data structure i2c_adapter, the I2C adapter's algorithm data structure i2c_algorithm, and a function that controls the I2C adapter to generate communication signals.

The code driven by the I2C bus allows us to control the I2C adapter to generate the start bit, stop bit, read and write cycle, and read and write, generate ACK, etc. in slave mode.

? I2C device driver

I2C device driver is the implementation of the device side in the I2C hardware architecture. The device is generally attached to the CPU-controlled I2C adapter and exchanges data with the CPU through the I2C adapter. .

The I2C device driver mainly includes the data structures i2c_driver and i2c_client. We need to implement the member functions according to the specific device.


Figure 15.1 Linux I2C Architecture

In the Linux 2.6 kernel, all I2C devices are displayed in the sysfs file system and exist in /sys/bus/I2c/directory, listed in the form of adapter address and chip address, such as:

$ tree /sys/bus/i2c/

/sys/bus/i2c/

Copyright © Windows knowledge All Rights Reserved