Patchwork [U-Boot,V6,4/5] I2C: mv_i2c: add multi bus support

login
register
mail settings
Submitter Lei Wen
Date March 31, 2011, 8:37 a.m.
Message ID <1301560649-16127-5-git-send-email-leiwen@marvell.com>
Download mbox | patch
Permalink /patch/89038/
State Superseded
Headers show

Comments

Lei Wen - March 31, 2011, 8:37 a.m.
Add the ability to support multiple i2c bus for mv_i2c

Signed-off-by: Lei Wen <leiwen@marvell.com>
---
Changelog:
V2:
NO CHANGE

V3:
clean code style issue

V4:
V5:
V6:
NO CHANGE

 drivers/i2c/mv_i2c.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)
Prafulla Wadaskar - April 1, 2011, 6:36 p.m.
> -----Original Message-----
> From: Lei Wen [mailto:leiwen@marvell.com]
> Sent: Thursday, March 31, 2011 2:07 PM
> To: Heiko Schocher; Prafulla Wadaskar; Wolfgang Denk; u-
> boot@lists.denx.de; Marek Vasut; Ashish Karkare; Prabhanjan Sarnaik; Yu
> Tang; adrian.wenl@gmail.com
> Subject: [PATCH V6 4/5] I2C: mv_i2c: add multi bus support
> 
> Add the ability to support multiple i2c bus for mv_i2c
> 
> Signed-off-by: Lei Wen <leiwen@marvell.com>
> ---
> Changelog:
> V2:
> NO CHANGE
> 
> V3:
> clean code style issue
> 
> V4:
> V5:
> V6:
> NO CHANGE
> 
>  drivers/i2c/mv_i2c.c |   36 +++++++++++++++++++++++++++++++++++-
>  1 files changed, 35 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/i2c/mv_i2c.c b/drivers/i2c/mv_i2c.c
> index 3f145de..3a3f7d7 100644
> --- a/drivers/i2c/mv_i2c.c
> +++ b/drivers/i2c/mv_i2c.c
> @@ -66,7 +66,35 @@ struct pxa_i2c {
>  	u32 isar;
>  };
> 
> -static struct pxa_i2c *base = (struct pxa_i2c *)CONFIG_PXA_I2C_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;
> +
> +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
> @@ -235,6 +263,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
> */

Ack, except s/PXA/MV/g

Regards..
Prafulla . .

> --
> 1.7.0.4

Patch

diff --git a/drivers/i2c/mv_i2c.c b/drivers/i2c/mv_i2c.c
index 3f145de..3a3f7d7 100644
--- a/drivers/i2c/mv_i2c.c
+++ b/drivers/i2c/mv_i2c.c
@@ -66,7 +66,35 @@  struct pxa_i2c {
 	u32 isar;
 };
 
-static struct pxa_i2c *base = (struct pxa_i2c *)CONFIG_PXA_I2C_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;
+
+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
@@ -235,6 +263,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   */