Stephen Carlson | e36d49c | 2021-06-22 16:35:20 -0700 | [diff] [blame] | 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 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 8 | #include <config.h> |
Stephen Carlson | e36d49c | 2021-06-22 16:35:20 -0700 | [diff] [blame] | 9 | #include <i2c.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <stdio.h> |
Stephen Carlson | e36d49c | 2021-06-22 16:35:20 -0700 | [diff] [blame] | 11 | #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 Simek | cc046dc | 2024-04-16 08:55:19 +0200 | [diff] [blame] | 16 | * "default y". |
Stephen Carlson | e36d49c | 2021-06-22 16:35:20 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifdef CONFIG_FSL_USE_PCA9547_MUX |
| 19 | |
| 20 | int 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 |