i2c_common.c 705 B

12345678910111213141516171819202122232425262728293031323334
  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. #if CONFIG_IS_ENABLED(DM_I2C)
  11. /* If DM is in use, retrieve the chip for the specified bus number */
  12. int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev)
  13. {
  14. int ret = i2c_get_chip_for_busnum(bus, address, 1, dev);
  15. if (ret)
  16. printf("I2C: Bus %d has no device with address 0x%02X\n",
  17. bus, address);
  18. return ret;
  19. }
  20. #else
  21. /* Handle is passed directly */
  22. int fsl_i2c_get_device(int address, int bus, DEVICE_HANDLE_T *dev)
  23. {
  24. *dev = address;
  25. return 0;
  26. }
  27. #endif