1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
4 * Copyright 2020-21 NXP
5 * Copyright 2021 Microsoft Corporation
6 */
7
8#include <common.h>
9#include <i2c.h>
10#include "i2c_common.h"
11#include "i2c_mux.h"
12
13/*
14 * A new Kconfig option for something that used to always be built should be
15 * "default y".
16 */
17#ifdef CONFIG_FSL_USE_PCA9547_MUX
18
19int select_i2c_ch_pca9547(u8 ch, int bus)
20{
21	int ret;
22	DEVICE_HANDLE_T dev;
23
24	/* Open device handle */
25	ret = fsl_i2c_get_device(I2C_MUX_PCA_ADDR_PRI, bus, &dev);
26	if (ret) {
27		printf("PCA: No PCA9547 device found\n");
28		return ret;
29	}
30
31	ret = I2C_WRITE(dev, 0, &ch, sizeof(ch));
32	if (ret) {
33		printf("PCA: Unable to select channel %d (%d)\n", (int)ch, ret);
34		return ret;
35	}
36
37	return 0;
38}
39
40#endif
41