blob: 89151ccaf06012b3a6b25a733e81d5b3bcb550c0 [file] [log] [blame]
Stephen Carlsone36d49c2021-06-22 16:35:20 -07001// 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
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <config.h>
Stephen Carlsone36d49c2021-06-22 16:35:20 -07009#include <i2c.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <stdio.h>
Stephen Carlsone36d49c2021-06-22 16:35:20 -070011#include "i2c_common.h"
12#include "i2c_mux.h"
13
14/*
15 * A new Kconfig option for something that used to always be built should be
Michal Simekcc046dc2024-04-16 08:55:19 +020016 * "default y".
Stephen Carlsone36d49c2021-06-22 16:35:20 -070017 */
18#ifdef CONFIG_FSL_USE_PCA9547_MUX
19
20int select_i2c_ch_pca9547(u8 ch, int bus)
21{
22 int ret;
23 DEVICE_HANDLE_T dev;
24
25 /* Open device handle */
26 ret = fsl_i2c_get_device(I2C_MUX_PCA_ADDR_PRI, bus, &dev);
27 if (ret) {
28 printf("PCA: No PCA9547 device found\n");
29 return ret;
30 }
31
32 ret = I2C_WRITE(dev, 0, &ch, sizeof(ch));
33 if (ret) {
34 printf("PCA: Unable to select channel %d (%d)\n", (int)ch, ret);
35 return ret;
36 }
37
38 return 0;
39}
40
41#endif