6/22/2012

How to add GPIO bit-bang i2c device to Linux kernel?

1. Check Kernel configuration
#define CONFIG_I2C_GPIO y
#define CONFIG_I2C_MSM y


2. Configure GPIOs at Modem side for general purpose, in/out...
You should edit TLMMBsp.c at modem side.


*3. ~ 7. You should add/modify "kernel/arch/arm/mach-msm/board-xxxxx.c"

3. Make i2c_gpio_platform_data
static struct i2c_gpio_platform_data ALRAN_i2c_gpio_data = {
.sda_pin = 91, // GPIO pin number for SDA
.scl_pin = 90, // GPIO pin number for SCL
};


4. Make platform_device
static struct platform_device ALRAN_i2c_gpio_device = {
.name = "i2c-gpio",
.id = 3, // do not be same with the another i2c_gpio_device
.dev = {
.platform_data = &ALRAN_i2c_gpio_data, // You have made it at step 3.
},
};


5. Add devices array for initdata
static struct platform_device *devices[] __initdata = {
<snip>
&ALRAN_i2c_gpio_device,
<snip>



6. Add i2c client information
static struct i2c_board_info ALRAN_i2c_devices[] = {
{
I2C_BOARD_INFO("ALRAN",0x4A>>1), // 0x4A should be changed with your device address
},
};


7. Register i2c client to board_init function
static void __init msm7x2x_init(void)
{
<snip>
i2c_register_board_info(3, ALRAN_i2c_devices, ARRAY_SIZE(ALRAN_i2c_devices));
<snip>
}
It's just for i2c client board.

No comments:

Post a Comment