[U-Boot] [PATCH 11/18] board: freescale: sys_eeprom: Add i2c DM support

ying.zhang22455 at nxp.com ying.zhang22455 at nxp.com
Thu Aug 23 01:14:58 UTC 2018


From: Zhang Ying-22455 <ying.zhang22455 at nxp.com>

Add DM capable code into the sys_eeprom driver. The legacy
non-DM, non-DT support is retained as there are still
systems in the tree which are not DM or DT capable.

Signed-off-by: Zhang Ying-22455 <ying.zhang22455 at nxp.com>
---
 board/freescale/common/sys_eeprom.c | 68 +++++++++++++++++++++++++++++++++++--
 drivers/i2c/mxc_i2c.c               |  8 +++++
 2 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/board/freescale/common/sys_eeprom.c b/board/freescale/common/sys_eeprom.c
index ab0fe0b..932b711 100644
--- a/board/freescale/common/sys_eeprom.c
+++ b/board/freescale/common/sys_eeprom.c
@@ -10,6 +10,7 @@
 #include <command.h>
 #include <i2c.h>
 #include <linux/ctype.h>
+#include <dm.h>
 
 #ifdef CONFIG_SYS_I2C_EEPROM_CCID
 #include "../common/eeprom.h"
@@ -154,13 +155,33 @@ static int read_eeprom(void)
 	if (has_been_read)
 		return 0;
 
+#ifdef CONFIG_DM_I2C
+	struct udevice *dev, *udev;
+
+	if (uclass_get_device_by_name(UCLASS_I2C,
+				      FSL_I2C_EEPROM_DM_NAME, &udev)) {
+		puts("Cannot find EEPROM bus\n");
+		return false;
+	}
+
+	ret = i2c_get_chip(udev, CONFIG_SYS_I2C_EEPROM_ADDR, 1, &dev);
+	if (ret) {
+		puts("Cannot get EEPROM chip\n");
+		return false;
+	}
+#endif
+
 #ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	bus = i2c_get_bus_num();
 	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
 #endif
 
+#ifdef CONFIG_DM_I2C
+	ret = dm_i2c_read(dev, 0, (void *)&e, sizeof(e));
+#else
 	ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
 		(void *)&e, sizeof(e));
+#endif
 
 #ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	i2c_set_bus_num(bus);
@@ -210,6 +231,21 @@ static int prog_eeprom(void)
 #endif
 	update_crc();
 
+#ifdef CONFIG_DM_I2C
+	struct udevice *dev, *udev;
+
+	if (uclass_get_device_by_name(UCLASS_I2C,
+				      FSL_I2C_EEPROM_DM_NAME, &udev)) {
+		puts("Cannot find EEPROM bus\n");
+		return false;
+	}
+
+	ret = i2c_get_chip(udev, CONFIG_SYS_I2C_EEPROM_ADDR, 1, &dev);
+	if (ret) {
+		puts("Cannot get EEPROM chip\n");
+		return false;
+	}
+#endif
 #ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	bus = i2c_get_bus_num();
 	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
@@ -221,8 +257,13 @@ static int prog_eeprom(void)
 	 * complete a given write.
 	 */
 	for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
-		ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
+#ifdef CONFIG_DM_I2C
+		ret = dm_i2c_write(dev, i, p, 8);
+#else
+		ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i,
+				CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
 				p, min((int)(sizeof(e) - i), 8));
+#endif
 		if (ret)
 			break;
 		udelay(5000);	/* 5ms write cycle timing */
@@ -231,9 +272,12 @@ static int prog_eeprom(void)
 	if (!ret) {
 		/* Verify the write by reading back the EEPROM and comparing */
 		struct eeprom e2;
-
+#ifdef CONFIG_DM_I2C
+		ret = dm_i2c_read(dev, 0, (void *)&e2, sizeof(e2));
+#else
 		ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
 			CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (void *)&e2, sizeof(e2));
+#endif
 		if (!ret && memcmp(&e, &e2, sizeof(e)))
 			ret = -1;
 	}
@@ -528,9 +572,27 @@ unsigned int get_cpu_board_revision(void)
 		u8 minor;         /* 0x05        Board revision, minor */
 	} be;
 
+#ifdef CONFIG_DM_I2C
+	struct udevice *dev, *udev;
+
+	if (uclass_get_device_by_name(UCLASS_I2C,
+				      FSL_I2C_EEPROM_DM_NAME, &udev)) {
+		puts("Cannot find EEPROM bus\n");
+	return false;
+	}
+
+	ret = i2c_get_chip(udev, CONFIG_SYS_I2C_EEPROM_ADDR, 1, &dev);
+	if (ret) {
+		puts("Cannot get EEPROM chip\n");
+		return false;
+	}
+
+	dm_i2c_read(dev, 0, (void *)&be, sizeof(be));
+#else
+
 	i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
 		(void *)&be, sizeof(be));
-
+#endif
 	if (be.id != (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
 		return MPC85XX_CPU_BOARD_REV(0, 0);
 
diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index 9999d9f..9bf8984 100644
--- a/drivers/i2c/mxc_i2c.c
+++ b/drivers/i2c/mxc_i2c.c
@@ -795,6 +795,14 @@ U_BOOT_I2C_ADAP_COMPLETE(mxc7, mxc_i2c_init, mxc_i2c_probe,
 
 #else
 
+int __enable_i2c_clk(unsigned char enable, unsigned int i2c_num)
+{
+	return 1;
+}
+
+int enable_i2c_clk(unsigned char enable, unsigned int i2c_num)
+	__attribute__((weak, alias("__enable_i2c_clk")));
+
 static int mxc_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
 {
 	struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
-- 
2.7.4



More information about the U-Boot mailing list