Linux i2c Architecture

Source: Internet
Author: User

The I2C architecture consists of three components:

(1) I2C Core

(2) I2C bus driver

(3) I2C Device Driver

I2C core: Provides the registration and cancellation methods for I2C bus drivers and device drivers, the upper layer of the I2C communication method, code irrelevant to the specific adapter, and probe devices, detects the upper-Layer Code of the device address.

I2C bus driver: The implementation of the adapter in the I2C hardware architecture. The adapter can be controlled by the CPU, or even directly integrated into the CPU. It mainly includes the i2c_adapter data structure of the I2C adapter, the algorithm data structure of the I2C adapter i2c_algorithm and the function that controls the I2C adapter to generate communication signals.

I2C Device Driver: Device implementation in the I2C hardware architecture. devices are generally attached to the I2C adapter controlled by the CPU and exchange data with the CPU through the I2C adapter.

The following describes several key functions of the I2C device driver.

1. There are four struct types in the kernel I2C. h file:

I2c_adapter struct:

333 struct i2c_adapter {
334 struct module * owner;
335 unsigned int ID;
336 unsigned int class;/* classes to allow probing */
337 const struct i2c_algorithm * algo;/* the algorithm to access the bus */
338 void * algo_data;
339
340/* data fields that are valid for all devices */
341 u8 level;/* nesting level for lockdep */
342 struct mutex bus_lock;
343
344 int timeout;/* In jiffies */
345 int retries;
346 struct device dev;/* the adapter device */
347
348 int NR;
349 char name [48];
350 struct completion dev_released;

351 };

I2c_algorithm struct

Struct i2c_algorithm {
313/* If an adapter algorithm can't do I2C-level access, set master_xfer
314 to NULL. If an adapter algorithm can do SMBus access, set
315 smbus_xfer. If set to NULL, the SMBus protocol is simulated
316 using common I2C messages */
317/* master_xfer shoshould return the number of messages successfully
318 processed, or a negative value on error */
319 int (* master_xfer) (struct i2c_adapter * adap, struct i2c_msg * msgs,
320 int num );
321 int (* smbus_xfer) (struct i2c_adapter * adap, 2010addr,
322 unsigned short flags, char read_write,
323 u8 command, int size, union i2c_smbus_data * data );
324
325/* To determine what the adapter supports */
326 u32 (* functionality) (struct i2c_adapter *);

327 };

I2c_driver struct

136 struct i2c_driver {
137 unsigned int class;
138
139/* Notifies the driver that a new bus has appeared or is about to be
140 * removed. You shoshould avoid using this if you can, it will probably
141 * be removed in a near future.
142 */
143 int (* attach_adapter) (struct i2c_adapter *);
144 int (* detach_adapter) (struct i2c_adapter *);
145
146/* Standard driver model interfaces */
147 int (* probe) (struct i2c_client *, const struct i2c_device_id *);
148 int (* remove) (struct i2c_client *);
149
150/* driver model interfaces that don't relate to enumeration */
151 void (* shutdown) (struct i2c_client *);
152 int (* suspend) (struct i2c_client *, pm_message_t mesg );
153 int (* resume) (struct i2c_client *);
154
155/* a ioctl like command that can be used to perform specific functions
156 * with the device.
157 */
158 int (* command) (struct i2c_client * client, unsigned int cmd, void * Arg );
159
160 struct device_driver driver;
161 const struct i2c_device_id * id_table;
162
163/* Device Detection callback for automatic device creation */
164 int (* detect) (struct i2c_client *, int kind, struct i2c_board_info *);
165 const struct i2c_client_address_data * address_data;
166 struct list_head clients;
167 };

I2c_client struct

188 struct i2c_client {
189 unsigned short flags;/* div., see below */
190 unsigned short addr;/* chip address-NOTE: 7bit */
191/* addresses are stored in */
192/* _ LOWER _ 7 bits */
193 char name [I2C_NAME_SIZE];
194 struct i2c_adapter * adapter;/* the adapter we sit on */
195 struct i2c_driver * driver;/* and our access routines */
196 struct device dev;/* the device structure */
197 int irq;/* irq issued by device */
198 struct list_head detected;
199 };

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.