From 069d46d7f4995b7a34c62735c9cd6adc7790aeca Mon Sep 17 00:00:00 2001 From: kfx Date: Thu, 23 Aug 2012 18:50:44 +0800 Subject: [PATCH] i2c: rk2928&rk3066b: add check_idle --- arch/arm/mach-rk2928/devices.c | 198 +++++++-------- arch/arm/mach-rk30/devices.c | 340 ++++++++++++-------------- arch/arm/plat-rk/include/plat/board.h | 2 +- drivers/i2c/busses/i2c-rk30-adapter.c | 4 +- drivers/i2c/busses/i2c-rk30.h | 4 +- 5 files changed, 251 insertions(+), 297 deletions(-) diff --git a/arch/arm/mach-rk2928/devices.c b/arch/arm/mach-rk2928/devices.c index eeac110dc483..225266270eca 100755 --- a/arch/arm/mach-rk2928/devices.c +++ b/arch/arm/mach-rk2928/devices.c @@ -235,6 +235,7 @@ static struct platform_device device_lcdc = { #endif // i2c +#ifdef CONFIG_I2C_RK30 #ifdef CONFIG_I2C0_CONTROLLER_RK29 #define I2C0_ADAP_TYPE I2C_RK29_ADAP #define I2C0_START RK2928_I2C0_PHYS @@ -279,28 +280,91 @@ static struct platform_device device_lcdc = { #define I2C3_END RK2928_RKI2C3_PHYS + RK2928_RKI2C3_SIZE - 1 #endif -#ifdef CONFIG_I2C0_RK30 -static int i2c0_check_idle(void) +struct i2c_iomux{ + int scl_pin; + char *scl_name; + unsigned int scl_i2c_mode; + unsigned int scl_gpio_mode; + + int sda_pin; + char *sda_name; + unsigned int sda_i2c_mode; + unsigned int sda_gpio_mode; + + char *req_name; +}; +static struct i2c_iomux iomux[] = { + { + .scl_pin = RK2928_PIN0_PA0, + .scl_name = GPIO0A0_I2C0_SCL_NAME, + .scl_i2c_mode = GPIO0A_I2C0_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK2928_PIN0_PA1, + .sda_name = GPIO0A1_I2C0_SDA_NAME, + .sda_i2c_mode = GPIO0A_I2C0_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.0", + }, + { + .scl_pin = RK2928_PIN0_PA2, + .scl_name = GPIO0A2_I2C1_SCL_NAME, + .scl_i2c_mode = GPIO0A_I2C1_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK2928_PIN0_PA3, + .sda_name = GPIO0A3_I2C1_SDA_NAME, + .sda_i2c_mode = GPIO0A_I2C1_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.1", + }, + { + .scl_pin = RK2928_PIN2_PC5, + .scl_name = GPIO2C5_LCDC0_D19_LCDC1_D19_I2C2_SCL_NAME, + .scl_i2c_mode = GPIO2C_I2C2_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK2928_PIN2_PC4, + .sda_name = GPIO2C4_LCDC0_D18_LCDC1_D18_I2C2_SDA_NAME, + .sda_i2c_mode = GPIO2C_I2C2_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.2", + }, + { + .scl_pin = RK2928_PIN0_PA6, + .scl_name = GPIO0A6_I2C3_SCL_HDMI_DDCSCL_NAME, + .scl_i2c_mode = GPIO0A_I2C3_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK2928_PIN0_PA7, + .sda_name = GPIO0A7_I2C3_SDA_HDMI_DDCSDA_NAME, + .sda_i2c_mode = GPIO0A_I2C3_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.3", + }, +}; +static int i2c_check_idle(int id) { int sda_level, scl_level; - rk30_mux_api_set(GPIO0A0_I2C0_SCL_NAME, GPIO0A_GPIO0A0); - rk30_mux_api_set(GPIO0A1_I2C0_SDA_NAME, GPIO0A_GPIO0A1); - - gpio_request(RK2928_PIN0_PA0, "i2c.0"); - gpio_request(RK2928_PIN0_PA1, "i2c.0"); - gpio_direction_input(RK2928_PIN0_PA0); - gpio_direction_input(RK2928_PIN0_PA1); + if(id < 0 || id > 3){ + printk("Error: id: %d\n", id); + } - scl_level = gpio_get_value(RK2928_PIN0_PA0); - sda_level = gpio_get_value(RK2928_PIN0_PA1); + rk30_mux_api_set(iomux[id].scl_name, iomux[id].scl_gpio_mode); + rk30_mux_api_set(iomux[id].sda_name, iomux[id].sda_gpio_mode); + + gpio_request(iomux[id].scl_pin, iomux[id].req_name); + gpio_request(iomux[id].sda_pin, iomux[id].req_name); + + gpio_direction_input(iomux[id].scl_pin); + gpio_direction_input(iomux[id].sda_pin); - gpio_free(RK2928_PIN0_PA0); - gpio_free(RK2928_PIN0_PA1); + scl_level = gpio_get_value(iomux[id].scl_pin); + sda_level = gpio_get_value(iomux[id].sda_pin); - rk30_mux_api_set(GPIO0A0_I2C0_SCL_NAME, GPIO0A_I2C0_SCL); - rk30_mux_api_set(GPIO0A1_I2C0_SDA_NAME, GPIO0A_I2C0_SDA); + gpio_free(iomux[id].scl_pin); + gpio_free(iomux[id].sda_pin); + rk30_mux_api_set(iomux[id].scl_name, iomux[id].scl_i2c_mode); + rk30_mux_api_set(iomux[id].sda_name, iomux[id].sda_i2c_mode); + if(sda_level == 1 && scl_level == 1) return I2C_IDLE; else if(sda_level == 0 && scl_level == 1) @@ -311,11 +375,12 @@ static int i2c0_check_idle(void) return BOTH_LOW; } +#ifdef CONFIG_I2C2_RK30 static struct rk30_i2c_platform_data default_i2c0_data = { .bus_num = 0, .is_div_from_arm = 1, .adap_type = I2C0_ADAP_TYPE, - .check_idle = &i2c0_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c0[] = { @@ -343,42 +408,11 @@ static struct platform_device device_i2c0 = { #endif #ifdef CONFIG_I2C1_RK30 -static int i2c1_check_idle(void) -{ - int sda_level, scl_level; - rk30_mux_api_set(GPIO0A2_I2C1_SCL_NAME, GPIO0A_GPIO0A2); - rk30_mux_api_set(GPIO0A3_I2C1_SDA_NAME, GPIO0A_GPIO0A3); - - gpio_request(RK2928_PIN0_PA2, "i2c.1"); - gpio_request(RK2928_PIN0_PA3, "i2c.1"); - - gpio_direction_input(RK2928_PIN0_PA2); - gpio_direction_input(RK2928_PIN0_PA3); - - scl_level = gpio_get_value(RK2928_PIN0_PA2); - sda_level = gpio_get_value(RK2928_PIN0_PA3); - - gpio_free(RK2928_PIN0_PA2); - gpio_free(RK2928_PIN0_PA3); - - rk30_mux_api_set(GPIO0A2_I2C1_SCL_NAME, GPIO0A_I2C1_SCL); - rk30_mux_api_set(GPIO0A3_I2C1_SDA_NAME, GPIO0A_I2C1_SDA); - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - static struct rk30_i2c_platform_data default_i2c1_data = { .bus_num = 1, .is_div_from_arm = 1, .adap_type = I2C1_ADAP_TYPE, - .check_idle = &i2c1_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c1[] = { @@ -406,42 +440,11 @@ static struct platform_device device_i2c1 = { #endif #ifdef CONFIG_I2C2_RK30 -static int i2c2_check_idle(void) -{ - int sda_level, scl_level; - rk30_mux_api_set(GPIO2C4_LCDC0_D18_LCDC1_D18_I2C2_SDA_NAME, GPIO2C_GPIO2C4); - rk30_mux_api_set(GPIO2C5_LCDC0_D19_LCDC1_D19_I2C2_SCL_NAME, GPIO2C_GPIO2C5); - - gpio_request(RK2928_PIN2_PC4, "i2c.2"); - gpio_request(RK2928_PIN2_PC5, "i2c.2"); - - gpio_direction_input(RK2928_PIN2_PC4); - gpio_direction_input(RK2928_PIN2_PC5); - - scl_level = gpio_get_value(RK2928_PIN2_PC4); - sda_level = gpio_get_value(RK2928_PIN2_PC5); - - gpio_free(RK2928_PIN2_PC4); - gpio_free(RK2928_PIN2_PC5); - - rk30_mux_api_set(GPIO2C4_LCDC0_D18_LCDC1_D18_I2C2_SDA_NAME, GPIO2C_I2C2_SDA); - rk30_mux_api_set(GPIO2C5_LCDC0_D19_LCDC1_D19_I2C2_SCL_NAME, GPIO2C_I2C2_SCL); - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - static struct rk30_i2c_platform_data default_i2c2_data = { .bus_num = 2, .is_div_from_arm = 0, .adap_type = I2C2_ADAP_TYPE, - .check_idle = &i2c2_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c2[] = { @@ -469,42 +472,11 @@ static struct platform_device device_i2c2 = { #endif #ifdef CONFIG_I2C3_RK30 -static int i2c3_check_idle(void) -{ - int sda_level, scl_level; - rk30_mux_api_set(GPIO0A6_I2C3_SCL_HDMI_DDCSCL_NAME, GPIO0A_GPIO0A6); - rk30_mux_api_set(GPIO0A7_I2C3_SDA_HDMI_DDCSDA_NAME, GPIO0A_GPIO0A7); - - gpio_request(RK2928_PIN0_PA6, "i2c.3"); - gpio_request(RK2928_PIN0_PA7, "i2c.3"); - - gpio_direction_input(RK2928_PIN0_PA6); - gpio_direction_input(RK2928_PIN0_PA7); - - scl_level = gpio_get_value(RK2928_PIN0_PA6); - sda_level = gpio_get_value(RK2928_PIN0_PA7); - - gpio_free(RK2928_PIN0_PA6); - gpio_free(RK2928_PIN0_PA7); - - rk30_mux_api_set(GPIO0A6_I2C3_SCL_HDMI_DDCSCL_NAME, GPIO0A_I2C3_SCL); - rk30_mux_api_set(GPIO0A7_I2C3_SDA_HDMI_DDCSDA_NAME, GPIO0A_I2C3_SDA); - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - static struct rk30_i2c_platform_data default_i2c3_data = { .bus_num = 3, .is_div_from_arm = 0, .adap_type = I2C3_ADAP_TYPE, - .check_idle = &i2c3_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c3[] = { @@ -559,7 +531,7 @@ static void __init rk2928_init_i2c(void) platform_device_register(&device_i2c_gpio); #endif } -//end of i2c +#endif//end of i2c #if defined(CONFIG_SPIM0_RK29) || defined(CONFIG_SPIM1_RK29) /***************************************************************************************** diff --git a/arch/arm/mach-rk30/devices.c b/arch/arm/mach-rk30/devices.c index b770f0246167..8d0315a70510 100755 --- a/arch/arm/mach-rk30/devices.c +++ b/arch/arm/mach-rk30/devices.c @@ -314,6 +314,8 @@ static void __init rk30_init_uart(void) } // i2c +#ifdef CONFIG_I2C_RK30 + #ifdef CONFIG_I2C0_CONTROLLER_RK29 #define I2C0_ADAP_TYPE I2C_RK29_ADAP #define I2C0_START RK30_I2C0_PHYS @@ -369,35 +371,163 @@ static void __init rk30_init_uart(void) #define I2C4_END RK30_I2C4_PHYS + SZ_16K - 1 #endif -#ifdef CONFIG_I2C0_RK30 -static int i2c0_check_idle(void) +struct i2c_iomux{ + int scl_pin; + char *scl_name; + unsigned int scl_i2c_mode; + unsigned int scl_gpio_mode; + + int sda_pin; + char *sda_name; + unsigned int sda_i2c_mode; + unsigned int sda_gpio_mode; + + char *req_name; +}; +#ifdef CONFIG_ARCH_RK3066B +static struct i2c_iomux iomux[] = { + { + .scl_pin = RK30_PIN1_PD1, + .scl_name = GPIO1D1_I2C0SCL_NAME, + .scl_i2c_mode = GPIO1D_I2C0SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN1_PD0, + .sda_name = GPIO1D0_I2C0SDA_NAME, + .sda_i2c_mode = GPIO1D_I2C0SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.0", + }, + { + .scl_pin = RK30_PIN1_PD3, + .scl_name = GPIO1D3_I2C1SCL_NAME, + .scl_i2c_mode = GPIO1D_I2C1SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN1_PD2, + .sda_name = GPIO1D2_I2C1SDA_NAME, + .sda_i2c_mode = GPIO1D_I2C1SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.1", + }, + { + .scl_pin = RK30_PIN1_PD5, + .scl_name = GPIO1D5_I2C2SCL_NAME, + .scl_i2c_mode = GPIO1D_I2C2SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN1_PD4, + .sda_name = GPIO1D4_I2C2SDA_NAME, + .sda_i2c_mode = GPIO1D_I2C2SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.2", + }, + { + .scl_pin = RK30_PIN3_PB7, + .scl_name = GPIO3B7_CIFDATA11_I2C3SCL_NAME, + .scl_i2c_mode = GPIO3B_I2C3SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN3_PB6, + .sda_name = GPIO3B6_CIFDATA10_I2C3SDA_NAME, + .sda_i2c_mode = GPIO3B_I2C3SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.3", + }, + { + .scl_pin = RK30_PIN1_PD7, + .scl_name = GPIO1D7_I2C4SCL_NAME, + .scl_i2c_mode = GPIO1D_I2C4SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN1_PD6, + .sda_name = GPIO1D6_I2C4SDA_NAME, + .sda_i2c_mode = GPIO1D_I2C4SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.4", + }, +}; +#else +static struct i2c_iomux iomux[] = { + { + .scl_pin = RK30_PIN2_PD5, + .scl_name = GPIO2D5_I2C0SCL_NAME, + .scl_i2c_mode = GPIO2D_I2C0_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN2_PD4, + .sda_name = GPIO2D4_I2C0SDA_NAME, + .sda_i2c_mode = GPIO2D_I2C0_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.0", + }, + { + .scl_pin = RK30_PIN2_PD7, + .scl_name = GPIO2D7_I2C1SCL_NAME, + .scl_i2c_mode = GPIO2D_I2C1_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN2_PD6, + .sda_name = GPIO2D6_I2C1SDA_NAME, + .sda_i2c_mode = GPIO2D_I2C1_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.1", + }, + { + .scl_pin = RK30_PIN3_PA1, + .scl_name = GPIO3A1_I2C2SCL_NAME, + .scl_i2c_mode = GPIO3A_I2C2_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN3_PA0, + .sda_name = GPIO3A0_I2C2SDA_NAME, + .sda_i2c_mode = GPIO3A_I2C2_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.2", + }, + { + .scl_pin = RK30_PIN3_PA3, + .scl_name = GPIO3A3_I2C3SCL_NAME, + .scl_i2c_mode = GPIO3A_I2C3_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN3_PA2, + .sda_name = GPIO3A2_I2C3SDA_NAME, + .sda_i2c_mode = GPIO3A_I2C3_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.3", + }, + { + .scl_pin = RK30_PIN3_PA5, + .scl_name = GPIO3A5_I2C4SCL_NAME, + .scl_i2c_mode = GPIO3A_I2C4_SCL, + .scl_gpio_mode = 0, + .sda_pin = RK30_PIN3_PA4, + .sda_name = GPIO3A4_I2C4SDA_NAME, + .sda_i2c_mode = GPIO3A_I2C4_SDA, + .sda_gpio_mode = 0, + .req_name = "i2c.4", + }, +}; +#endif +static int i2c_check_idle(int id) { int sda_level, scl_level; -#if defined(CONFIG_ARCH_RK3066B) -#warning fix i2c0_check_idle - scl_level = 1; - sda_level = 1; -#else - rk30_mux_api_set(GPIO2D5_I2C0SCL_NAME, GPIO2D_GPIO2D5); - rk30_mux_api_set(GPIO2D4_I2C0SDA_NAME, GPIO2D_GPIO2D4); + if(id < 0 || id > 4){ + printk("Error: id: %d\n", id); + return -1; + } - gpio_request(RK30_PIN2_PD5, "i2c.0"); - gpio_request(RK30_PIN2_PD4, "i2c.0"); - - gpio_direction_input(RK30_PIN2_PD5); - gpio_direction_input(RK30_PIN2_PD4); + rk30_mux_api_set(iomux[id].scl_name, iomux[id].scl_gpio_mode); + rk30_mux_api_set(iomux[id].sda_name, iomux[id].sda_gpio_mode); - scl_level = gpio_get_value(RK30_PIN2_PD5); - sda_level = gpio_get_value(RK30_PIN2_PD4); + gpio_request(iomux[id].scl_pin, iomux[id].req_name); + gpio_request(iomux[id].sda_pin, iomux[id].req_name); + + gpio_direction_input(iomux[id].scl_pin); + gpio_direction_input(iomux[id].sda_pin); - gpio_free(RK30_PIN2_PD5); - gpio_free(RK30_PIN2_PD4); + scl_level = gpio_get_value(iomux[id].scl_pin); + sda_level = gpio_get_value(iomux[id].sda_pin); - rk30_mux_api_set(GPIO2D5_I2C0SCL_NAME, GPIO2D_I2C0_SCL); - rk30_mux_api_set(GPIO2D4_I2C0SDA_NAME, GPIO2D_I2C0_SDA); -#endif + gpio_free(iomux[id].scl_pin); + gpio_free(iomux[id].sda_pin); + rk30_mux_api_set(iomux[id].scl_name, iomux[id].scl_i2c_mode); + rk30_mux_api_set(iomux[id].sda_name, iomux[id].sda_i2c_mode); + if(sda_level == 1 && scl_level == 1) return I2C_IDLE; else if(sda_level == 0 && scl_level == 1) @@ -408,11 +538,12 @@ static int i2c0_check_idle(void) return BOTH_LOW; } +#ifdef CONFIG_I2C0_RK30 static struct rk30_i2c_platform_data default_i2c0_data = { .bus_num = 0, .is_div_from_arm = 1, .adap_type = I2C0_ADAP_TYPE, - .check_idle = &i2c0_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c0[] = { @@ -440,49 +571,11 @@ static struct platform_device device_i2c0 = { #endif #ifdef CONFIG_I2C1_RK30 -static int i2c1_check_idle(void) -{ - int sda_level, scl_level; - -#if defined(CONFIG_ARCH_RK3066B) -#warning fix i2c1_check_idle - scl_level = 1; - sda_level = 1; -#else - rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7); - rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6); - - gpio_request(RK30_PIN2_PD7, "i2c.1"); - gpio_request(RK30_PIN2_PD6, "i2c.1"); - - gpio_direction_input(RK30_PIN2_PD7); - gpio_direction_input(RK30_PIN2_PD6); - - sda_level = gpio_get_value(RK30_PIN2_PD7); - scl_level = gpio_get_value(RK30_PIN2_PD6); - - gpio_free(RK30_PIN2_PD7); - gpio_free(RK30_PIN2_PD6); - - rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_I2C1_SCL); - rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_I2C1_SDA); -#endif - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - static struct rk30_i2c_platform_data default_i2c1_data = { .bus_num = 1, .is_div_from_arm = 1, .adap_type = I2C1_ADAP_TYPE, - .check_idle = &i2c1_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c1[] = { @@ -510,50 +603,11 @@ static struct platform_device device_i2c1 = { #endif #ifdef CONFIG_I2C2_RK30 -static int i2c2_check_idle(void) -{ - int sda_level, scl_level; - -#if defined(CONFIG_ARCH_RK3066B) -#warning fix i2c2_check_idle - scl_level = 1; - sda_level = 1; -#else - rk30_mux_api_set(GPIO3A1_I2C2SCL_NAME, GPIO3A_GPIO3A1); - rk30_mux_api_set(GPIO3A0_I2C2SDA_NAME, GPIO3A_GPIO3A0); - - gpio_request(RK30_PIN3_PA1, "i2c.2"); - gpio_request(RK30_PIN3_PA0, "i2c.2"); - - gpio_direction_input(RK30_PIN3_PA1); - gpio_direction_input(RK30_PIN3_PA0); - - sda_level = gpio_get_value(RK30_PIN3_PA1); - scl_level = gpio_get_value(RK30_PIN3_PA0); - - gpio_free(RK30_PIN3_PA1); - gpio_free(RK30_PIN3_PA0); - - rk30_mux_api_set(GPIO3A1_I2C2SCL_NAME, GPIO3A_I2C2_SCL); - rk30_mux_api_set(GPIO3A0_I2C2SDA_NAME, GPIO3A_I2C2_SDA); -#endif - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - - static struct rk30_i2c_platform_data default_i2c2_data = { .bus_num = 2, .is_div_from_arm = 0, .adap_type = I2C2_ADAP_TYPE, - .check_idle = &i2c2_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c2[] = { @@ -581,50 +635,11 @@ static struct platform_device device_i2c2 = { #endif #ifdef CONFIG_I2C3_RK30 -static int i2c3_check_idle(void) -{ - int sda_level, scl_level; - -#if defined(CONFIG_ARCH_RK3066B) -#warning fix i2c3_check_idle - scl_level = 1; - sda_level = 1; -#else - rk30_mux_api_set(GPIO3A3_I2C3SCL_NAME, GPIO3A_GPIO3A3); - rk30_mux_api_set(GPIO3A2_I2C3SDA_NAME, GPIO3A_GPIO3A2); - - gpio_request(RK30_PIN3_PA3, "i2c.3"); - gpio_request(RK30_PIN3_PA2, "i2c.3"); - - gpio_direction_input(RK30_PIN3_PA3); - gpio_direction_input(RK30_PIN3_PA2); - - sda_level = gpio_get_value(RK30_PIN3_PA3); - scl_level = gpio_get_value(RK30_PIN3_PA2); - - gpio_free(RK30_PIN3_PA3); - gpio_free(RK30_PIN3_PA2); - - rk30_mux_api_set(GPIO3A3_I2C3SCL_NAME, GPIO3A_I2C3_SCL); - rk30_mux_api_set(GPIO3A2_I2C3SDA_NAME, GPIO3A_I2C3_SDA); -#endif - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - - static struct rk30_i2c_platform_data default_i2c3_data = { .bus_num = 3, .is_div_from_arm = 0, .adap_type = I2C3_ADAP_TYPE, - .check_idle = &i2c3_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c3[] = { @@ -652,49 +667,11 @@ static struct platform_device device_i2c3 = { #endif #ifdef CONFIG_I2C4_RK30 -static int i2c4_check_idle(void) -{ - int sda_level, scl_level; - -#if defined(CONFIG_ARCH_RK3066B) -#warning fix i2c4_check_idle - scl_level = 1; - sda_level = 1; -#else - rk30_mux_api_set(GPIO3A5_I2C4SCL_NAME, GPIO3A_GPIO3A5); - rk30_mux_api_set(GPIO3A4_I2C4SDA_NAME, GPIO3A_GPIO3A4); - - gpio_request(RK30_PIN3_PA5, "i2c.4"); - gpio_request(RK30_PIN3_PA4, "i2c.4"); - - gpio_direction_input(RK30_PIN3_PA5); - gpio_direction_input(RK30_PIN3_PA4); - - scl_level = gpio_get_value(RK30_PIN3_PA5); - sda_level = gpio_get_value(RK30_PIN3_PA4); - - gpio_free(RK30_PIN3_PA5); - gpio_free(RK30_PIN3_PA4); - - rk30_mux_api_set(GPIO3A5_I2C4SCL_NAME, GPIO3A_I2C4_SCL); - rk30_mux_api_set(GPIO3A4_I2C4SDA_NAME, GPIO3A_I2C4_SDA); -#endif - - if(sda_level == 1 && scl_level == 1) - return I2C_IDLE; - else if(sda_level == 0 && scl_level == 1) - return I2C_SDA_LOW; - else if(sda_level == 1 && scl_level == 0) - return I2C_SCL_LOW; - else - return BOTH_LOW; -} - static struct rk30_i2c_platform_data default_i2c4_data = { .bus_num = 4, .is_div_from_arm = 0, .adap_type = I2C4_ADAP_TYPE, - .check_idle = &i2c4_check_idle, + .check_idle = &i2c_check_idle, }; static struct resource resources_i2c4[] = { @@ -752,7 +729,8 @@ static void __init rk30_init_i2c(void) platform_device_register(&device_i2c_gpio); #endif } -//end of i2c + +#endif//end of i2c #if defined(CONFIG_SPIM0_RK29) || defined(CONFIG_SPIM1_RK29) /***************************************************************************************** diff --git a/arch/arm/plat-rk/include/plat/board.h b/arch/arm/plat-rk/include/plat/board.h index 4a97fe415e9a..b232873ed3dc 100755 --- a/arch/arm/plat-rk/include/plat/board.h +++ b/arch/arm/plat-rk/include/plat/board.h @@ -22,7 +22,7 @@ struct rk30_i2c_platform_data { u32 flags; int (*io_init)(void); int (*io_deinit)(void); - int (*check_idle)(void); + int (*check_idle)(int); }; struct spi_cs_gpio { diff --git a/drivers/i2c/busses/i2c-rk30-adapter.c b/drivers/i2c/busses/i2c-rk30-adapter.c index eab8a54a18c0..d55eede52145 100755 --- a/drivers/i2c/busses/i2c-rk30-adapter.c +++ b/drivers/i2c/busses/i2c-rk30-adapter.c @@ -536,13 +536,15 @@ static int rk30_i2c_xfer(struct i2c_adapter *adap, struct rk30_i2c *i2c = (struct rk30_i2c *)adap->algo_data; clk_enable(i2c->clk); - while(retry-- && ((state = i2c->check_idle()) != I2C_IDLE)){ +#ifdef I2C_CHECK_IDLE + while(retry-- && ((state = i2c->check_idle(i2c->adap.nr)) != I2C_IDLE)){ msleep(10); } if(retry == 0){ dev_err(i2c->dev, "i2c is not in idle(state = %d)\n", state); return -EIO; } +#endif if(msgs[0].scl_rate <= 400000 && msgs[0].scl_rate >= 10000) scl_rate = msgs[0].scl_rate; diff --git a/drivers/i2c/busses/i2c-rk30.h b/drivers/i2c/busses/i2c-rk30.h index e6b0bbb37b9b..5e4e48fac2e3 100755 --- a/drivers/i2c/busses/i2c-rk30.h +++ b/drivers/i2c/busses/i2c-rk30.h @@ -31,6 +31,8 @@ #define i2c_dbg(dev, format, arg...) #endif +#define I2C_CHECK_IDLE + #define i2c_writel writel_relaxed #define i2c_readl readl_relaxed @@ -105,7 +107,7 @@ struct rk30_i2c { void (*i2c_init_hw)(struct rk30_i2c *, unsigned long scl_rate); void (*i2c_set_clk)(struct rk30_i2c *, unsigned long); - int (*check_idle)(void); + int (*check_idle)(int); irqreturn_t (*i2c_irq)(int, void *); }; void i2c_adap_sel(struct rk30_i2c *i2c, int nr, int adap_type); -- 2.34.1