[U-Boot] [PATCH v2 12/40] i2c: Refactor adapter initialization

Thierry Reding thierry.reding at gmail.com
Tue Aug 26 17:34:00 CEST 2014


From: Thierry Reding <treding at nvidia.com>

A subsequent patch will introduce a new API to access I2C adapters
directly rather than going through the bus number and constantly looking
up the same adapter. In order to share the adapter initialization code,
move it into a separate function and make i2c_init_bus() use it to avoid
code duplication.

Signed-off-by: Thierry Reding <treding at nvidia.com>
---
 drivers/i2c/i2c_core.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/i2c_core.c b/drivers/i2c/i2c_core.c
index cca455bc9c63..f6179a16244b 100644
--- a/drivers/i2c/i2c_core.c
+++ b/drivers/i2c/i2c_core.c
@@ -207,6 +207,18 @@ static int i2c_mux_disconnet_all(void)
 }
 #endif
 
+static void i2c_adapter_init(struct i2c_adapter *adapter, unsigned int speed,
+			     unsigned int slaveaddr)
+{
+	adapter->init(adapter, speed, slaveaddr);
+
+	if (gd->flags & GD_FLG_RELOC) {
+		adapter->slaveaddr = slaveaddr;
+		adapter->speed = speed;
+		adapter->init_done = 1;
+	}
+}
+
 /*
  * i2c_init_bus():
  * ---------------
@@ -222,13 +234,7 @@ static void i2c_init_bus(unsigned int bus, int speed, int slaveaddr)
 		return;
 
 	adapter = i2c_get_adapter(I2C_ADAPTER(bus));
-	adapter->init(adapter, speed, slaveaddr);
-
-	if (gd->flags & GD_FLG_RELOC) {
-		adapter->init_done = 1;
-		adapter->speed = speed;
-		adapter->slaveaddr = slaveaddr;
-	}
+	i2c_adapter_init(adapter, speed, slaveaddr);
 }
 
 /* implement possible board specific board init */
-- 
2.0.4



More information about the U-Boot mailing list