diff mbox

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

Message ID 1409067268-956-13-git-send-email-thierry.reding@gmail.com
State Rejected
Delegated to: Heiko Schocher
Headers show

Commit Message

Thierry Reding Aug. 26, 2014, 3:34 p.m. UTC
From: Thierry Reding <treding@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@nvidia.com>
---
 drivers/i2c/i2c_core.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
diff mbox

Patch

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 */