smbx-get-chan.c 932 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/iio/consumer.h>
  8. #include "smb5-iio.h"
  9. #if defined(CONFIG_QPNP_SMBLITE) && defined(CONFIG_QPNP_SMB5)
  10. struct iio_channel **get_ext_channels(struct device *dev,
  11. const char *const *channel_map, int size)
  12. {
  13. int i, rc = 0;
  14. struct iio_channel **iio_ch_ext;
  15. iio_ch_ext = devm_kcalloc(dev, size, sizeof(*iio_ch_ext), GFP_KERNEL);
  16. if (!iio_ch_ext)
  17. return ERR_PTR(-ENOMEM);
  18. for (i = 0; i < size; i++) {
  19. iio_ch_ext[i] = devm_iio_channel_get(dev, channel_map[i]);
  20. if (IS_ERR(iio_ch_ext[i])) {
  21. rc = PTR_ERR(iio_ch_ext[i]);
  22. if (rc != -EPROBE_DEFER)
  23. dev_err(dev, "%s channel unavailable, %d\n",
  24. channel_map[i], rc);
  25. return ERR_PTR(rc);
  26. }
  27. }
  28. return iio_ch_ext;
  29. }
  30. #endif