From 55b11681fa71c364e8c431cf8584d6f7bb4c064b Mon Sep 17 00:00:00 2001 From: kfx Date: Fri, 13 Apr 2012 11:14:32 +0800 Subject: [PATCH] rk30: i2c: gpio i2c support --- arch/arm/mach-rk30/board-rk30-sdk.c | 26 +++++++++++++++++++++++++ arch/arm/mach-rk30/devices.c | 13 +++++++++++++ arch/arm/mach-rk30/include/mach/board.h | 5 +++++ drivers/i2c/busses/Kconfig | 4 ++++ drivers/i2c/busses/i2c-rk30.c | 7 ++----- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-rk30/board-rk30-sdk.c b/arch/arm/mach-rk30/board-rk30-sdk.c index f3409c635c6e..b846d405a793 100755 --- a/arch/arm/mach-rk30/board-rk30-sdk.c +++ b/arch/arm/mach-rk30/board-rk30-sdk.c @@ -1283,6 +1283,29 @@ static struct i2c_board_info __initdata i2c4_info[] = { }; #endif +#ifdef CONFIG_I2C_GPIO_RK30 +#define I2C_SDA_PIN INVALID_GPIO// RK30_PIN2_PD6 //set sda_pin here +#define I2C_SCL_PIN INVALID_GPIO//RK30_PIN2_PD7 //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[] = { +}; +#endif + static void __init rk30_i2c_register_board_info(void) { #ifdef CONFIG_I2C0_RK30 @@ -1300,6 +1323,9 @@ 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/arch/arm/mach-rk30/devices.c b/arch/arm/mach-rk30/devices.c index dc0677036f61..2fa28801e199 100755 --- a/arch/arm/mach-rk30/devices.c +++ b/arch/arm/mach-rk30/devices.c @@ -522,6 +522,16 @@ static struct platform_device device_i2c4 = { }; #endif +#ifdef CONFIG_I2C_GPIO_RK30 +struct platform_device device_i2c_gpio = { + .name = "i2c-gpio", + .id = 5, + .dev = { + .platform_data = &default_i2c_gpio_data, + }, +}; +#endif + static void __init rk30_init_i2c(void) { #ifdef CONFIG_I2C0_RK30 @@ -539,6 +549,9 @@ static void __init rk30_init_i2c(void) #ifdef CONFIG_I2C4_RK30 platform_device_register(&device_i2c4); #endif +#ifdef CONFIG_I2C_GPIO_RK30 + platform_device_register(&device_i2c_gpio); +#endif } //end of i2c diff --git a/arch/arm/mach-rk30/include/mach/board.h b/arch/arm/mach-rk30/include/mach/board.h index a8140d58a837..8fd9495712b1 100755 --- a/arch/arm/mach-rk30/include/mach/board.h +++ b/arch/arm/mach-rk30/include/mach/board.h @@ -10,6 +10,7 @@ #include #include #include +#include struct rk30_i2c_platform_data { char *name; @@ -36,6 +37,10 @@ struct wifi_platform_data { extern struct rk29_sdmmc_platform_data default_sdmmc0_data; extern struct rk29_sdmmc_platform_data default_sdmmc1_data; +#ifdef CONFIG_I2C_ALGOBIT +extern struct i2c_gpio_platform_data default_i2c_gpio_data; +#endif + void __init rk30_map_common_io(void); void __init rk30_init_irq(void); void __init rk30_map_io(void); diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 8c8b36f2b216..018fad3a83d3 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -919,6 +919,10 @@ if I2C_RK30 bool "With RK30 I2C Controller" endchoice endif + config I2C_GPIO_RK30 + bool "Simulation with GPIO" + default n + select I2C_GPIO endif config I2C_RK29 tristate "RK29 i2c interface (I2C)" diff --git a/drivers/i2c/busses/i2c-rk30.c b/drivers/i2c/busses/i2c-rk30.c index 63dd362af514..1438279ecf3b 100755 --- a/drivers/i2c/busses/i2c-rk30.c +++ b/drivers/i2c/busses/i2c-rk30.c @@ -17,11 +17,8 @@ #define TX_SETUP 1 //unit us void i2c_adap_sel(struct rk30_i2c *i2c, int nr, int adap_type) { - unsigned int p = readl(i2c->con_base); - - p = rk30_set_bit(p, adap_type, I2C_ADAP_SEL_BIT(nr)); - p = rk30_set_bit(p, adap_type, I2C_ADAP_SEL_MASK(nr)); - writel(p, i2c->con_base); + writel((1 << I2C_ADAP_SEL_BIT(nr)) | (1 << I2C_ADAP_SEL_MASK(nr)) , + i2c->con_base); } #ifdef CONFIG_CPU_FREQ -- 2.34.1