summaryrefslogtreecommitdiff
path: root/board/freescale/common/i2c_mux.c
diff options
context:
space:
mode:
authorStephen Carlson <stcarlso@linux.microsoft.com>2021-06-22 16:35:20 -0700
committerPriyanka Jain <priyanka.jain@nxp.com>2021-07-20 14:18:04 +0530
commit15347d2dea32d88e9d1553e26b7eb3553550f424 (patch)
treeb48dd2886cd363b78e13d67553990a9db584e56d /board/freescale/common/i2c_mux.c
parentdd3dfa50d88cffeb244485594a7bf18c58ae6d63 (diff)
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. Signed-off-by: Stephen Carlson <stcarlso@linux.microsoft.com> Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
Diffstat (limited to 'board/freescale/common/i2c_mux.c')
-rw-r--r--board/freescale/common/i2c_mux.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/board/freescale/common/i2c_mux.c b/board/freescale/common/i2c_mux.c
new file mode 100644
index 00000000000..54f89e25760
--- /dev/null
+++ b/board/freescale/common/i2c_mux.c
@@ -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