diff mbox

[U-Boot,v2,4/5] I2C: mvi2c: add multi bus support

Message ID 1300160443-12552-5-git-send-email-leiwen@marvell.com
State Superseded
Headers show

Commit Message

Lei Wen March 15, 2011, 3:40 a.m. UTC
Signed-off-by: Lei Wen <leiwen@marvell.com>
---
 drivers/i2c/mvi2c.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

Comments

Heiko Schocher March 15, 2011, 7:01 a.m. UTC | #1
Hello Lei,

Lei Wen wrote:
> Signed-off-by: Lei Wen <leiwen@marvell.com>
> ---
>  drivers/i2c/mvi2c.c |   37 ++++++++++++++++++++++++++++++++++++-
>  1 files changed, 36 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/i2c/mvi2c.c b/drivers/i2c/mvi2c.c
> index 0e37417..ca1add8 100644
> --- a/drivers/i2c/mvi2c.c
> +++ b/drivers/i2c/mvi2c.c
> @@ -131,9 +131,38 @@ struct pxa_i2c {
>  	u32 isar;
>  };
>  
> -static struct pxa_i2c *base = (struct pxa_i2c *)CONFIG_PXA_I2C_REG;
>  #define PXAI2C_AND(reg, val)	writel(readl(reg) & val, reg)
>  #define PXAI2C_OR(reg, val)	writel(readl(reg) | val, reg)
> +static struct pxa_i2c *base;
> +
> +#ifdef CONFIG_I2C_MULTI_BUS
> +static u32 i2c_regs[CONFIG_PXA_I2C_NUM] = CONFIG_PXA_I2C_REG;
> +static unsigned int bus_initialized[CONFIG_PXA_I2C_NUM];
> +static unsigned int current_bus = 0;
> +
> +int i2c_set_bus_num(unsigned int bus)
> +{
> +	if ((bus < 0) || (bus >= CONFIG_PXA_I2C_NUM)) {
> +		printf("Bad bus: %d\n", bus);
> +		return -1;
> +	}
> +
> +	base = (struct pxa_i2c *)i2c_regs[bus];
> +	current_bus = bus;
> +
> +	if(!bus_initialized[current_bus]) {
          ^
          add a space here, thanks

> +		i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
> +		bus_initialized[current_bus] = 1;
> +	}
> +
> +	return 0;
> +}
> +
> +unsigned int i2c_get_bus_num(void)
> +{
> +	return current_bus;
> +}
> +#endif
>  
>  /**
>   * i2c_pxa_reset: - reset the host controller
> @@ -311,6 +340,12 @@ i2c_transfer_finish:
>  
>  void i2c_init(int speed, int slaveaddr)
>  {
> +#ifdef CONFIG_I2C_MULTI_BUS
> +	base = (struct pxa_i2c *)i2c_regs[current_bus];
> +#else
> +	base = (struct pxa_i2c *)CONFIG_PXA_I2C_REG;
> +#endif
> +
>  #ifdef CONFIG_SYS_I2C_INIT_BOARD
>  	u32 icr;
>  	/* call board specific i2c bus reset routine before accessing the   */

beside of that, your patch looks good.

bye,
Heiko
diff mbox

Patch

diff --git a/drivers/i2c/mvi2c.c b/drivers/i2c/mvi2c.c
index 0e37417..ca1add8 100644
--- a/drivers/i2c/mvi2c.c
+++ b/drivers/i2c/mvi2c.c
@@ -131,9 +131,38 @@  struct pxa_i2c {
 	u32 isar;
 };
 
-static struct pxa_i2c *base = (struct pxa_i2c *)CONFIG_PXA_I2C_REG;
 #define PXAI2C_AND(reg, val)	writel(readl(reg) & val, reg)
 #define PXAI2C_OR(reg, val)	writel(readl(reg) | val, reg)
+static struct pxa_i2c *base;
+
+#ifdef CONFIG_I2C_MULTI_BUS
+static u32 i2c_regs[CONFIG_PXA_I2C_NUM] = CONFIG_PXA_I2C_REG;
+static unsigned int bus_initialized[CONFIG_PXA_I2C_NUM];
+static unsigned int current_bus = 0;
+
+int i2c_set_bus_num(unsigned int bus)
+{
+	if ((bus < 0) || (bus >= CONFIG_PXA_I2C_NUM)) {
+		printf("Bad bus: %d\n", bus);
+		return -1;
+	}
+
+	base = (struct pxa_i2c *)i2c_regs[bus];
+	current_bus = bus;
+
+	if(!bus_initialized[current_bus]) {
+		i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+		bus_initialized[current_bus] = 1;
+	}
+
+	return 0;
+}
+
+unsigned int i2c_get_bus_num(void)
+{
+	return current_bus;
+}
+#endif
 
 /**
  * i2c_pxa_reset: - reset the host controller
@@ -311,6 +340,12 @@  i2c_transfer_finish:
 
 void i2c_init(int speed, int slaveaddr)
 {
+#ifdef CONFIG_I2C_MULTI_BUS
+	base = (struct pxa_i2c *)i2c_regs[current_bus];
+#else
+	base = (struct pxa_i2c *)CONFIG_PXA_I2C_REG;
+#endif
+
 #ifdef CONFIG_SYS_I2C_INIT_BOARD
 	u32 icr;
 	/* call board specific i2c bus reset routine before accessing the   */