Compilation of I2C device drivers, struct i2c_device_id, struct i2c_driver, i2c_add_driver, i2c_register_board_info

Source: Internet
Author: User

My philosophy: simple and practical. Don't get a bunch of source code. The result is that people don't know how to use it after reading it. view me:

1. Add I2C information to the ARCH/ARM/Mach-xxx/platform file, which is named i2c_board_info.

For example:

Static struct i2c_board_info _ initdata xxxi2c_board_info [] = {
{
I2c_board_info ("ABCD1", 0x20),/* string to match with the following, 0x20 is from the device address */
. Platform_data = 0,
},
{
I2c_board_info ("abcd2", 0x21 ),
. Platform_data = 0,
},
};

Then call i2c_register_board_info (1, xxxi2c_board_info, array_size (xxxi2c_board_info ));

The first parameter is 0 or 1. I do not know yet :-(

2. Call i2c_add_driver () in the form of module_init (func_init () in another device driver file, there are several definitions:

Static const struct i2c_device_id xxx_led_id [] = {
{"ABCD1", 0},/* The name must match board_info to call the probe function */
{"Abcd2", 0 },
{}
};
Module_device_table (I2C, xxx_led_id );

Static struct i2c_driver xxx_led_driver = {
. Driver = {
. Name = "yourname",/* This name does not need to match any other name */
. Owner = this_module,
},
. Probe = xxx_led_probe,
. Remove = xxx_remove,
. Id_table = xxx_led_id,
};

See it. After the string in struct i2c_device_id matches the string in i2c_board_info, xxx_led_probe will be called.

If you do not want to use the same probe, write a struct i2c_device_id and struct i2c_driver.

How do I know what the process and each struct are?

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.