[U-Boot] [PATCH 1/2] i2c:soft:multi: Support for multiple soft I2C buses

Lukasz Majewski l.majewski at samsung.com
Tue Aug 28 10:33:16 CEST 2012


Support for multiple soft I2C buses at soft_i2c.c

This approach defines get_multi_{sda|scl}_pin functions to switch
between multiple "soft" I2C buses.

Up to CONFIG_SYS_MAX_I2C_BUS devices can be utilized.
Common definition of I2C_X I2C buses is provided.

TEST HW:
     Samsung's Exynos4210 evt.0.1 - Trats development board

Signed-off-by: Lukasz Majewski <l.majewski at samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
---
 drivers/i2c/soft_i2c.c |   41 +++++++++++++++++++++++++++++++++++++++++
 include/i2c.h          |   17 +++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c
index 36c6114..7901f04 100644
--- a/drivers/i2c/soft_i2c.c
+++ b/drivers/i2c/soft_i2c.c
@@ -127,6 +127,15 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #if defined(CONFIG_I2C_MULTI_BUS)
 static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = 0;
+const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS] = {
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"soft_i2c_4",
+	"soft_i2c_5",
+	NULL,
+};
 #endif /* CONFIG_I2C_MULTI_BUS */
 
 /*-----------------------------------------------------------------------
@@ -482,3 +491,35 @@ int  i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
 	send_stop();
 	return(failures);
 }
+
+#if defined(CONFIG_I2C_MULTI_BUS)
+/* Handle multiple I2C buses instances */
+int get_multi_scl_pin(void)
+{
+	switch (I2C_GET_BUS()) {
+	case I2C_4:
+		return CONFIG_SOFT_I2C_I2C4_SCL;
+	case I2C_5:
+		return CONFIG_SOFT_I2C_I2C5_SCL;
+	};
+
+	return 0;
+}
+
+int get_multi_sda_pin(void)
+{
+	switch (I2C_GET_BUS()) {
+	case I2C_4:
+		return CONFIG_SOFT_I2C_I2C4_SDA;
+	case I2C_5:
+		return CONFIG_SOFT_I2C_I2C5_SDA;
+	};
+
+	return 0;
+}
+
+int multi_i2c_init(void)
+{
+	return 0;
+}
+#endif /* CONFIG_I2C_MULTI_BUS */
diff --git a/include/i2c.h b/include/i2c.h
index 1f35acf..d563d62 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -250,4 +250,21 @@ static inline void I2C_SET_BUS(unsigned int bus)
 		i2c_set_bus_num(bus);
 }
 
+/* Multi I2C busses handling */
+#if (defined(CONFIG_SOFT_I2C) && defined(CONFIG_I2C_MULTI_BUS))
+enum {
+	I2C_0,
+	I2C_1,
+	I2C_2,
+	I2C_3,
+	I2C_4,
+	I2C_5,
+	I2C_6
+};
+
+extern const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS];
+extern int get_multi_scl_pin(void);
+extern int get_multi_sda_pin(void);
+extern int multi_i2c_init(void);
+#endif
 #endif	/* _I2C_H_ */
-- 
1.7.2.3



More information about the U-Boot mailing list