From 1c29dd0fdfd6f0adcc025b4db2d1c8010364c488 Mon Sep 17 00:00:00 2001 From: lw Date: Fri, 13 Apr 2012 18:24:55 +0800 Subject: [PATCH] rk30 phone:wm831x use gpio i2c and fix kernel death --- arch/arm/configs/rk30_phone_defconfig | 11 +-- arch/arm/mach-rk30/board-rk30-phone-wm831x.c | 2 +- arch/arm/mach-rk30/board-rk30-phone.c | 43 +++++++++- drivers/mfd/wm831x-i2c.c | 2 +- drivers/misc/inv_mpu/mlsl-kernel.c | 90 ++++++++++---------- 5 files changed, 93 insertions(+), 55 deletions(-) diff --git a/arch/arm/configs/rk30_phone_defconfig b/arch/arm/configs/rk30_phone_defconfig index 0ba39a748a61..a498b5ecb272 100644 --- a/arch/arm/configs/rk30_phone_defconfig +++ b/arch/arm/configs/rk30_phone_defconfig @@ -43,14 +43,6 @@ CONFIG_DEFAULT_MMAP_MIN_ADDR=32768 CONFIG_ZBOOT_ROM_TEXT=0x0 CONFIG_ZBOOT_ROM_BSS=0x0 CONFIG_CMDLINE="console=ttyFIQ0 androidboot.console=ttyFIQ0 init=/init" -CONFIG_CPU_FREQ=y -CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE=y -CONFIG_CPU_FREQ_GOV_PERFORMANCE=y -CONFIG_CPU_FREQ_GOV_POWERSAVE=y -CONFIG_CPU_FREQ_GOV_USERSPACE=y -CONFIG_CPU_FREQ_GOV_ONDEMAND=y -CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y -CONFIG_CPU_FREQ_GOV_HOTPLUG=y CONFIG_CPU_IDLE=y CONFIG_VFP=y CONFIG_NEON=y @@ -252,10 +244,11 @@ CONFIG_UART3_CTS_RTS_RK29=y CONFIG_I2C=y # CONFIG_I2C_COMPAT is not set CONFIG_I2C0_CONTROLLER_RK30=y -CONFIG_I2C1_CONTROLLER_RK30=y +# CONFIG_I2C1_RK30 is not set CONFIG_I2C2_CONTROLLER_RK30=y CONFIG_I2C3_CONTROLLER_RK30=y CONFIG_I2C4_CONTROLLER_RK30=y +CONFIG_I2C_GPIO_RK30=y CONFIG_SPI=y CONFIG_SPIM_RK29=y CONFIG_SPIM0_RK29=y diff --git a/arch/arm/mach-rk30/board-rk30-phone-wm831x.c b/arch/arm/mach-rk30/board-rk30-phone-wm831x.c index 47edb073457b..22aaed0eb53d 100755 --- a/arch/arm/mach-rk30/board-rk30-phone-wm831x.c +++ b/arch/arm/mach-rk30/board-rk30-phone-wm831x.c @@ -863,6 +863,6 @@ static struct wm831x_pdata wm831x_platdata = { &wm831x_regulator_init_ldo[10], }, /** ISINK1 = 0 and so on*/ - .isink = {&wm831x_regulator_init_isink[0], &wm831x_regulator_init_isink[1]}, + //.isink = {&wm831x_regulator_init_isink[0], &wm831x_regulator_init_isink[1]}, }; #endif diff --git a/arch/arm/mach-rk30/board-rk30-phone.c b/arch/arm/mach-rk30/board-rk30-phone.c index 6e2265082361..38eead30ce09 100755 --- a/arch/arm/mach-rk30/board-rk30-phone.c +++ b/arch/arm/mach-rk30/board-rk30-phone.c @@ -336,7 +336,7 @@ static struct ili2102_platform_data ili2102_info = { .y_max = 800, .gpio_reset = TOUCH_GPIO_RESET, .gpio_reset_active_low = 1, - .gpio_pendown = TOUCH_GPIO_RESET, + .gpio_pendown = TOUCH_GPIO_INT, .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, .resetpin_iomux_name = GPIO4D0_SMCDATA8_TRACEDATA8_NAME, .pendown_iomux_mode = GPIO4C_GPIO4C2, @@ -1605,6 +1605,7 @@ static struct i2c_board_info __initdata i2c0_info[] = { #endif #ifdef CONFIG_I2C1_RK30 +#if 0 #include "board-rk30-phone-wm831x.c" static struct i2c_board_info __initdata i2c1_info[] = { @@ -1619,6 +1620,7 @@ static struct i2c_board_info __initdata i2c1_info[] = { #endif }; #endif +#endif #ifdef CONFIG_I2C2_RK30 static struct i2c_board_info __initdata i2c2_info[] = { @@ -1664,6 +1666,41 @@ static struct i2c_board_info __initdata i2c4_info[] = { }; #endif +#ifdef CONFIG_I2C_GPIO_RK30 +#include "board-rk30-phone-wm831x.c" + +#define I2C_SDA_PIN RK30_PIN2_PD7 //set sda_pin here +#define I2C_SCL_PIN RK30_PIN2_PD6 //set scl_pin here +static int rk30_i2c_io_init(void) +{ + //set iomux (gpio) here + rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7); + rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6); + + return 0; +} +struct i2c_gpio_platform_data default_i2c_gpio_data = { + .sda_pin = I2C_SDA_PIN, + .scl_pin = I2C_SCL_PIN, + .udelay = 5, // clk = 500/udelay = 100Khz + .timeout = 100,//msecs_to_jiffies(100), + .bus_num = 5, + .io_init = rk30_i2c_io_init, +}; +static struct i2c_board_info __initdata i2c_gpio_info[] = { +#if defined (CONFIG_MFD_WM831X_I2C) + { + .type = "wm8310", + .addr = 0x34, + .flags = 0, + .irq = RK30_PIN6_PA4, + .platform_data = &wm831x_platdata, + }, +#endif +}; +#endif + + static void __init rk30_i2c_register_board_info(void) { #ifdef CONFIG_I2C0_RK30 @@ -1681,6 +1718,10 @@ static void __init rk30_i2c_register_board_info(void) #ifdef CONFIG_I2C4_RK30 i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info)); #endif +#ifdef CONFIG_I2C_GPIO_RK30 + i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info)); +#endif + } //end of i2c diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c index e2807275a9b3..294d9bddb490 100755 --- a/drivers/mfd/wm831x-i2c.c +++ b/drivers/mfd/wm831x-i2c.c @@ -111,7 +111,7 @@ static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg, ret = i2c_transfer(adap, &msg, 1); kfree(tx_buf); - return (ret == 1) ? count : ret; + return (ret == 1) ? 0 : ret; #else struct i2c_client *i2c = wm831x->control_data; unsigned char msg[bytes + 2]; diff --git a/drivers/misc/inv_mpu/mlsl-kernel.c b/drivers/misc/inv_mpu/mlsl-kernel.c index 4a36266bc62b..7fef66f50baa 100755 --- a/drivers/misc/inv_mpu/mlsl-kernel.c +++ b/drivers/misc/inv_mpu/mlsl-kernel.c @@ -40,7 +40,6 @@ static int inv_i2c_write(struct i2c_adapter *i2c_adap, msgs[0].buf = (unsigned char *)data; msgs[0].len = len; msgs[0].scl_rate = MPU_I2C_RATE; - //msgs[0].udelay = 200; res = i2c_transfer(i2c_adap, msgs, 1); if (res == 1) @@ -80,14 +79,12 @@ static int inv_i2c_read(struct i2c_adapter *i2c_adap, msgs[0].buf = ® msgs[0].len = 1; msgs[0].scl_rate = MPU_I2C_RATE; - //msgs[0].udelay = 200; msgs[1].addr = address; msgs[1].flags = I2C_M_RD; msgs[1].buf = data; msgs[1].len = len; msgs[1].scl_rate = MPU_I2C_RATE; - //msgs[1].udelay = 200; res = i2c_transfer(i2c_adap, msgs, 2); if (res == 2) @@ -107,8 +104,7 @@ static int mpu_memory_read(struct i2c_adapter *i2c_adap, unsigned char bank[2]; unsigned char addr[2]; unsigned char buf; - - struct i2c_msg msgs[4]; + struct i2c_msg msgs[2]; int res; if (!data || !i2c_adap) { @@ -130,31 +126,35 @@ static int mpu_memory_read(struct i2c_adapter *i2c_adap, msgs[0].buf = bank; msgs[0].len = sizeof(bank); msgs[0].scl_rate = MPU_I2C_RATE; - //msgs[0].udelay = 200; + + res = i2c_transfer(i2c_adap, msgs, 1); + if (res != 1) + return res; + + msgs[0].addr = mpu_addr; + msgs[0].flags = 0; + msgs[0].buf = addr; + msgs[0].len = sizeof(addr); + msgs[0].scl_rate = MPU_I2C_RATE; + + res = i2c_transfer(i2c_adap, msgs, 1); + if (res != 1) + return res; + + msgs[0].addr = mpu_addr; + msgs[0].flags = 0; + msgs[0].buf = &buf; + msgs[0].len = 1; + msgs[0].scl_rate = MPU_I2C_RATE; msgs[1].addr = mpu_addr; - msgs[1].flags = 0; - msgs[1].buf = addr; - msgs[1].len = sizeof(addr); + msgs[1].flags = I2C_M_RD; + msgs[1].buf = data; + msgs[1].len = len; msgs[1].scl_rate = MPU_I2C_RATE; - //msgs[1].udelay = 200; - - msgs[2].addr = mpu_addr; - msgs[2].flags = 0; - msgs[2].buf = &buf; - msgs[2].len = 1; - msgs[2].scl_rate = MPU_I2C_RATE; - //msgs[2].udelay = 200; - - msgs[3].addr = mpu_addr; - msgs[3].flags = I2C_M_RD; - msgs[3].buf = data; - msgs[3].len = len; - msgs[3].scl_rate = MPU_I2C_RATE; - //msgs[3].udelay = 200; - - res = i2c_transfer(i2c_adap, msgs, 4); - if (res == 4) + + res = i2c_transfer(i2c_adap, msgs, 2); + if (res == 2) return 0; else if(res == 0) return -EBUSY; @@ -171,7 +171,7 @@ static int mpu_memory_write(struct i2c_adapter *i2c_adap, unsigned char addr[2]; unsigned char buf[513]; - struct i2c_msg msgs[3]; + struct i2c_msg msgs[2]; int res; if (!data || !i2c_adap) { @@ -198,24 +198,28 @@ static int mpu_memory_write(struct i2c_adapter *i2c_adap, msgs[0].buf = bank; msgs[0].len = sizeof(bank); msgs[0].scl_rate = MPU_I2C_RATE; - //msgs[0].udelay = 200; - msgs[1].addr = mpu_addr; - msgs[1].flags = 0; - msgs[1].buf = addr; - msgs[1].len = sizeof(addr); - msgs[1].scl_rate = MPU_I2C_RATE; - //msgs[1].udelay = 200; + res = i2c_transfer(i2c_adap, msgs, 1); + if (res != 1) + return res; + + msgs[0].addr = mpu_addr; + msgs[0].flags = 0; + msgs[0].buf = addr; + msgs[0].scl_rate = MPU_I2C_RATE; + + res = i2c_transfer(i2c_adap, msgs, 1); + if (res != 1) + return res; - msgs[2].addr = mpu_addr; - msgs[2].flags = 0; - msgs[2].buf = (unsigned char *)buf; - msgs[2].len = len + 1; - msgs[2].scl_rate = MPU_I2C_RATE; - //msgs[2].udelay = 200; + msgs[0].addr = mpu_addr; + msgs[0].flags = 0; + msgs[0].buf = (unsigned char *)buf; + msgs[0].len = len + 1; + msgs[0].scl_rate = MPU_I2C_RATE; - res = i2c_transfer(i2c_adap, msgs, 3); - if (res == 3) + res = i2c_transfer(i2c_adap, msgs, 1); + if (res == 1) return 0; else if(res == 0) return -EBUSY; -- 2.34.1