Example 1
1, kernel \ arch \ Arm \ Mach-PXA \ board-test.c added
/* I2C */
Static struct i2c_gpio_platform_data i2c_bus_data = {
. Sda_pin = viper_rtc_i2c_sda_gpio,
. Scl_pin = viper_rtc_i2c_scl_gpio,
. Udelay = 10,
. Timeout = 100,
};
Static struct platform_device i2c_bus_device = {
. Name = "i2c-gpio ",
. ID = 1,/* pxa2xx-i2c is bus 0, so start at 1 */
. Dev = {
. Platform_data = & i2c_bus_data,
}
};
Static struct i2c_board_info _ initdata viper_i2c_devices [] = {
{
I2c_board_info ("ds1338", 0x68 ),
},
};
In the first struct, sda_pin and scl_pin are the gpio ports (data and clock lines) corresponding to the Development Board, and udelay are parameters related to the specific chip clock. For details, see datasheet. The two open_drain below indicate whether the two pins are open-leakage paths. If so, enter 1; otherwise, enter 0. In the following body, note that the name should be filled in the i2c-gpio, And the ID should be set to 2, because there are already two I2C devices in the system.
Add the required header file: # include <Linux/i2c-gpio.h>. In the header file devices. H, add the device struct statement, extern struct platform_device gpio_device_i2c;
Then place gpio_device_i2c in the array devices of the board-XXXX.c. For the form, see other devices in the array.
Static struct platform_device * viper_devs [] _ initdata = {
& Smc91x_device,
& I2c_bus_device, //////////////////////////////////////// ///
& Serial_device,
& Isppolicx_device,
& Viper_mtd_devices [0],
& Viper_mtd_devices [1],
& Viper_backlight_device,
};
Static void _ init viper_init (void)
『
;
;
;
I2c_register_board_info (1, array_and_size (viper_i2c_devices ));
;
}
Then use i2c_register_board_info to register it:
I2c_register_board_info (2, i2c_gpio_devices, array_size (i2c_gpio_devices ));
In this way, the simulation steps are completed. You can directly register and read/write the device using the system I2C-related registration methods.
Example 2
Static struct i2c_gpio_platform_data ep93xx_i2c_data = {
. Sda_pin = ep93xx_gpio_line_eedat,
. Sda_is_open_drain = 0,
. Scl_pin = ep93xx_gpio_line_eeclk,
. Scl_is_open_drain = 0,
. Udelay = 2,
};
Static struct platform_device ep93xx_i2c_device = {
. Name = "i2c-gpio ",
. ID = 0,
. Dev. platform_data = & ep93xx_i2c_data,
};
Void _ init ep93xx_register_i2c (struct i2c_board_info * devices, int num)
{
I2c_register_board_info (0, devices, num );
Platform_device_register (& ep93xx_i2c_device );
}
This article from the Linux community website (www.linuxidc.com) original link: http://www.linuxidc.com/Linux/2011-03/33762p3.htm