i2c_mux.c 778 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include <common.h>
  8. #include <i2c.h>
  9. #include "i2c_common.h"
  10. #include "i2c_mux.h"
  11. /*
  12. * A new Kconfig option for something that used to always be built should be
  13. * “default y”.
  14. */
  15. #ifdef CONFIG_FSL_USE_PCA9547_MUX
  16. int select_i2c_ch_pca9547(u8 ch, int bus)
  17. {
  18. int ret;
  19. DEVICE_HANDLE_T dev;
  20. /* Open device handle */
  21. ret = fsl_i2c_get_device(I2C_MUX_PCA_ADDR_PRI, bus, &dev);
  22. if (ret) {
  23. printf("PCA: No PCA9547 device found\n");
  24. return ret;
  25. }
  26. ret = I2C_WRITE(dev, 0, &ch, sizeof(ch));
  27. if (ret) {
  28. printf("PCA: Unable to select channel %d (%d)\n", (int)ch, ret);
  29. return ret;
  30. }
  31. return 0;
  32. }
  33. #endif