Skip to contentSkip to conversation

board: freescale: Refactor NXP common mux code

PATCH Superseded Stephen Carlson 2 participants 2 messages Jun 24, 2021 – Jul 12, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/14 board: freescale: Refactor NXP common mux code

Refactors similar mux code from multiple NXP boards into a common location, and allows it to be disabled in config.

New config: CONFIG_FSL_USE_PCA9547_MUX to enable PCA9547 mux functionality.

---
 board/freescale/common/Kconfig      |  6 +++
 board/freescale/common/Makefile     | 11 ++++++
 board/freescale/common/i2c_common.c | 34 +++++++++++++++++
 board/freescale/common/i2c_common.h | 30 +++++++++++++++
 board/freescale/common/i2c_mux.c    | 40 ++++++++++++++++++++
 board/freescale/common/i2c_mux.h    | 15 ++++++++
 board/freescale/common/vid.c        | 58 ++++++-----------------------
 7 files changed, 148 insertions(+), 46 deletions(-)
 create mode 100644 board/freescale/common/i2c_common.c
 create mode 100644 board/freescale/common/i2c_common.h
 create mode 100644 board/freescale/common/i2c_mux.c
 create mode 100644 board/freescale/common/i2c_mux.h
board/freescale/common/Kconfig +6 -0
index 17db755951..ab9c14ae88 100644
@@ -21,6 +21,12 @@ config CMD_ESBC_VALIDATE
 	    esbc_validate - validate signature using RSA verification
 	    esbc_halt - put the core in spin loop (Secure Boot Only)
 
+config FSL_USE_PCA9547_MUX
+	bool "Enable PCA9547 I2C Mux on Freescale boards"
+	default n
+	help
+	 This option enables the PCA9547 I2C mux on Freescale boards.
+
 config VID
 	depends on DM_I2C
 	bool "Enable Freescale VID"
board/freescale/common/Makefile +11 -0
index 114b7ba8f9..45aaa16ca4 100644
@@ -15,6 +15,15 @@ ifdef MINIMAL
 # necessary to create built-in.o
 obj- := __dummy__.o
 else
+# include i2c_common.o once if either VID or FSL_USE_PCA9547_MUX
+I2C_COMMON=
+ifdef CONFIG_VID
+I2C_COMMON=y
+endif
+ifdef CONFIG_FSL_USE_PCA9547_MUX
+I2C_COMMON=y
+endif
+
 obj-$(CONFIG_FSL_CADMUS)	+= cadmus.o
 obj-$(CONFIG_FSL_VIA)		+= cds_via.o
 obj-$(CONFIG_FMAN_ENET)	+= fman.o
@@ -22,6 +31,8 @@ obj-$(CONFIG_FSL_PIXIS)	+= pixis.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_FSL_NGPIXIS)	+= ngpixis.o
 endif
+obj-$(I2C_COMMON)		+= i2c_common.o
+obj-$(CONFIG_FSL_USE_PCA9547_MUX)		+= i2c_mux.o
 obj-$(CONFIG_VID)		+= vid.o
 obj-$(CONFIG_FSL_QIXIS)	+= qixis.o
 obj-$(CONFIG_PQ_MDS_PIB)	+= pq-mds-pib.o
board/freescale/common/i2c_common.c new file +34 -0
new file mode 100644
index 0000000000..0f09ed7d34
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2020-21 NXP
+ * Copyright 2021 Microsoft Corporation
+ */
+
+#include <common.h>
+#include <i2c.h>
+#include "i2c_common.h"
+
+#ifdef CONFIG_DM_I2C
+
+/* If DM is in use, retrieve the chip for the specified bus number */
+int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev)
+{
+	int ret = i2c_get_chip_for_busnum(bus, address, 1, dev);
+
+	if (ret)
+		printf("I2C: Bus %d has no device with address 0x%02X\n",
+		       bus, address);
+	return ret;
+}
+
+#else
+
+/* Handle is passed directly */
+int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev)
+{
+	*dev = address;
+	return 0;
+}
+
+#endif
board/freescale/common/i2c_common.h new file +30 -0
new file mode 100644
index 0000000000..840ad66183
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2020-21 NXP
+ * Copyright 2021 Microsoft Corporation
+ */
+
+#ifndef __NXP_I2C_COMMON_H__
+#define __NXP_I2C_COMMON_H__
+
+/* Common functionality shared by the I2C drivers for VID and the mux. */
+#ifdef CONFIG_DM_I2C
+#define DEVICE_HANDLE_T struct udevice *
+
+#define I2C_READ(dev, register, data, length) \
+	dm_i2c_read(dev, register, data, length)
+#define I2C_WRITE(dev, register, data, length) \
+	dm_i2c_write(dev, register, data, length)
+#else
+#define DEVICE_HANDLE_T int
+
+#define I2C_READ(dev, register, data, length) \
+	i2c_read(dev, register, 1, data, length)
+#define I2C_WRITE(dev, register, data, length) \
+	i2c_write(dev, register, 1, data, length)
+#endif
+
+int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev);
+
+#endif
board/freescale/common/i2c_mux.c new file +40 -0
new file mode 100644
index 0000000000..54f89e2576
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2020-21 NXP
+ * Copyright 2021 Microsoft Corporation
+ */
+
+#include <common.h>
+#include <i2c.h>
+#include "i2c_common.h"
+#include "i2c_mux.h"
+
+/*
+ * A new Kconfig option for something that used to always be built should be
+ * “default y”.
+ */
+#ifdef CONFIG_FSL_USE_PCA9547_MUX
+
+int select_i2c_ch_pca9547(u8 ch, int bus)
+{
+	int ret;
+	DEVICE_HANDLE_T dev;
+
+	/* Open device handle */
+	ret = fsl_i2c_get_device(I2C_MUX_PCA_ADDR_PRI, bus, &dev);
+	if (ret) {
+		printf("PCA: No PCA9547 device found\n");
+		return ret;
+	}
+
+	ret = I2C_WRITE(dev, 0, &ch, sizeof(ch));
+	if (ret) {
+		printf("PCA: Unable to select channel %d (%d)\n", (int)ch, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+#endif
board/freescale/common/i2c_mux.h new file +15 -0
new file mode 100644
index 0000000000..0870c1918e
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2020-21 NXP
+ * Copyright 2021 Microsoft Corporation
+ */
+
+#ifndef __NXP_I2C_MUX_H__
+#define __NXP_I2C_MUX_H__
+
+#ifdef CONFIG_FSL_USE_PCA9547_MUX
+int select_i2c_ch_pca9547(u8 ch, int bus);
+#endif
+
+#endif
board/freescale/common/vid.c +12 -46

120 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 100 lines

-----Original Message-----
From: Stephen Carlson <[email protected]>
Sent: Friday, June 25, 2021 1:02 AM
To: U-Boot Mailing List <[email protected]>
Cc: Priyanka Jain <[email protected]>
Subject: [PATCH v2 01/14] board: freescale: Refactor NXP common mux code

Refactors similar mux code from multiple NXP boards into a common location, and allows it to be disabled in config.

New config: CONFIG_FSL_USE_PCA9547_MUX to enable PCA9547 mux functionality.

---
 board/freescale/common/Kconfig      |  6 +++
 board/freescale/common/Makefile     | 11 ++++++
 board/freescale/common/i2c_common.c | 34 +++++++++++++++++
 board/freescale/common/i2c_common.h | 30 +++++++++++++++
 board/freescale/common/i2c_mux.c    | 40 ++++++++++++++++++++
 board/freescale/common/i2c_mux.h    | 15 ++++++++
 board/freescale/common/vid.c        | 58 ++++++-----------------------
 7 files changed, 148 insertions(+), 46 deletions(-)
 create mode 100644 board/freescale/common/i2c_common.c
 create mode 100644 board/freescale/common/i2c_common.h
 create mode 100644 board/freescale/common/i2c_mux.c
 create mode 100644 board/freescale/common/i2c_mux.h
(quoted diff) +0 -0

b/board/freescale/common/Kconfig index 17db755951..ab9c14ae88 100644

board/freescale/common/Kconfig +6 -0
@@ -21,6 +21,12 @@ config CMD_ESBC_VALIDATE
 	    esbc_validate - validate signature using RSA verification
 	    esbc_halt - put the core in spin loop (Secure Boot Only)
 
+config FSL_USE_PCA9547_MUX
+	bool "Enable PCA9547 I2C Mux on Freescale boards"
+	default n
+	help
+	 This option enables the PCA9547 I2C mux on Freescale boards.
+
 config VID
 	depends on DM_I2C
 	bool "Enable Freescale VID"
(quoted diff) +0 -0

b/board/freescale/common/Makefile index 114b7ba8f9..45aaa16ca4 100644

board/freescale/common/Makefile +6 -0
@@ -15,6 +15,15 @@ ifdef MINIMAL
 # necessary to create built-in.o
 obj- := __dummy__.o
 else
+# include i2c_common.o once if either VID or FSL_USE_PCA9547_MUX
+I2C_COMMON= ifdef CONFIG_VID I2C_COMMON=y endif ifdef
+CONFIG_FSL_USE_PCA9547_MUX I2C_COMMON=y endif
+
 obj-$(CONFIG_FSL_CADMUS)	+= cadmus.o
 obj-$(CONFIG_FSL_VIA)		+= cds_via.o
 obj-$(CONFIG_FMAN_ENET)	+= fman.o
@@ -22,6 +31,8 @@ obj-$(CONFIG_FSL_PIXIS)	+= pixis.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_FSL_NGPIXIS)	+= ngpixis.o
 endif
+obj-$(I2C_COMMON)		+= i2c_common.o
+obj-$(CONFIG_FSL_USE_PCA9547_MUX)		+= i2c_mux.o
 obj-$(CONFIG_VID)		+= vid.o
 obj-$(CONFIG_FSL_QIXIS)	+= qixis.o
 obj-$(CONFIG_PQ_MDS_PIB)	+= pq-mds-pib.o
board/freescale/common/i2c_common.c new file +21 -0
new file mode 100644
index 0000000000..0f09ed7d34
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2020-21 NXP
+ * Copyright 2021 Microsoft Corporation  */
+
+#include <common.h>
+#include <i2c.h>
+#include "i2c_common.h"
+
+#ifdef CONFIG_DM_I2C
+
+/* If DM is in use, retrieve the chip for the specified bus number */
+int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev) {
+	int ret = i2c_get_chip_for_busnum(bus, address, 1, dev);
+
+	if (ret)
+		printf("I2C: Bus %d has no device with address 0x%02X\n",
+		       bus, address);
+	return ret;
+}

board/freescale/common/i2c_common.c line 31

Quoted 10 lines
board/freescale/common/i2c_common.c new file +10 -0
+
+#else
+
+/* Handle is passed directly */
+int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev) {
+	*dev = address;
+	return 0;
+}
+
+#endif

<snip>
Stephen,

All patches in the series has one extra space character in start on each line due to which patch does not apply with git am. Please re-send the series after removing the extra character. Do ensure git am <patch> run successfully.

Also there are some changes in vid.c on master branch, please rebase to top.

Regards
Priyanka