msm 模拟i2c使用过程分析
//配置原有i2为GPIO模式
--- a/arch/arm/mach-msm/board-msm7x27a.c +++ b/arch/arm/mach-msm/board-msm7x27a.c @@ -4569,9 +4569,9 @@ static void __init msm_device_i2c_init(void) gpio_tlmm_config(GPIO_CFG(I2C0_SCL, 0, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_8MA),GPIO_CFG_ENABLE); gpio_tlmm_config(GPIO_CFG(I2C1_SDA, 0, GPIO_CFG_OUTPUT, - GPIO_CFG_PULL_UP, GPIO_CFG_8MA),GPIO_CFG_ENABLE); + GPIO_CFG_PULL_UP, GPIO_CFG_6MA),GPIO_CFG_ENABLE); gpio_tlmm_config(GPIO_CFG(I2C1_SCL, 0, GPIO_CFG_OUTPUT, - GPIO_CFG_PULL_UP, GPIO_CFG_8MA),GPIO_CFG_ENABLE); + GPIO_CFG_PULL_UP, GPIO_CFG_6MA),GPIO_CFG_ENABLE); #else msm_gsbi0_qup_i2c_device.dev.platform_data = &msm_gsbi0_qup_i2c_pdata; msm_gsbi1_qup_i2c_device.dev.platform_data = &msm_gsbi1_qup_i2c_pdata;
由于硬件设计问题.硬件i2c不稳定,导致FM打开时而失败.
现在采用把原来的硬件i2c改成模拟i2c控制
高通模拟GPIO的GPIO配置, 因为板子在8MA的情况 i2c非常不稳定, 改到6ma改善很大.所以目前采用6ma的大小.
--- a/arch/arm/mach-msm/Kconfig +++ b/arch/arm/mach-msm/Kconfig @@ -1708,4 +1708,11 @@ config MSM_L2_SPM Enabling this driver allows configuring L2 SPM for low power modes on supported chipsets. +config HY_I2C_DEVICE_USE_GPIO + bool "HY_I2C_DEVICE_USE_GPIO" + depends on I2C_GPIO + default n + help + This is the macro all i2c devices use i2c-gpio mode. +
--- a/arch/arm/mach-msm/board-msm7x27a.c +++ b/arch/arm/mach-msm/board-msm7x27a.c @@ -96,6 +96,43 @@ #define FM_GPIO 83 #define GPIO_INVALID NR_MSM_GPIOS +#ifdef CONFIG_HY_I2C_DEVICE_USE_GPIO +#include <linux/i2c-gpio.h> // ynn add +#define I2C0_SCL 60 +#define I2C0_SDA 61 +#define I2C1_SCL 131 +#define I2C1_SDA 132
//创建i2c 平台设备相关结构体 +struct i2c_gpio_platform_data platform_data_gpio_i2c1 = { + .scl_pin = I2C1_SCL, + .sda_pin = I2C1_SDA, + .udelay =2, + // .scl_is_output_only=0, +}; + +struct platform_device msm_device_gpio_i2c1 = { + .name = "i2c-gpio", + .id = MSM_GSBI1_QUP_I2C_BUS_ID,//1, + .dev = { + .platform_data = &platform_data_gpio_i2c1, + } +}; + +struct i2c_gpio_platform_data platform_data_gpio_i2c0 = { + .scl_pin = I2C0_SCL, + .sda_pin = I2C0_SDA, + .udelay =2, +}; + +struct platform_device msm_device_gpio_i2c0 = { // for camera + .name = "i2c-gpio", + .id = MSM_GSBI0_QUP_I2C_BUS_ID,//0, + .dev = { + .platform_data = &platform_data_gpio_i2c0, + } +}; +#endif
// 注册i2c adapter 设备
@@ -4089,8 +4126,13 @@ static struct platform_device *rumi_sim_devices[] __initdata = { &msm_device_uart1, &msm_device_nand, &msm_device_uart_dm1, +#ifdef CONFIG_HY_I2C_DEVICE_USE_GPIO + &msm_device_gpio_i2c0, + &msm_device_gpio_i2c1, +#else
&msm_gsbi0_qup_i2c_device, &msm_gsbi1_qup_i2c_device, +#endif
驱动采用ls drivers/i2c/busses/i2c-gpio.c