cam_common_util.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_COMMON_UTIL_H_
  6. #define _CAM_COMMON_UTIL_H_
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #define CAM_BITS_MASK_SHIFT(x, mask, shift) (((x) & (mask)) >> shift)
  10. #define PTR_TO_U64(ptr) ((uint64_t)(uintptr_t)ptr)
  11. #define U64_TO_PTR(ptr) ((void *)(uintptr_t)ptr)
  12. #define CAM_GET_TIMESTAMP(timestamp) ktime_get_real_ts64(&(timestamp))
  13. #define CAM_GET_TIMESTAMP_DIFF_IN_MICRO(ts_start, ts_end, diff_microsec) \
  14. ({ \
  15. diff_microsec = 0; \
  16. if (ts_end.tv_nsec >= ts_start.tv_nsec) { \
  17. diff_microsec = \
  18. (ts_end.tv_nsec - ts_start.tv_nsec) / 1000; \
  19. diff_microsec += \
  20. (ts_end.tv_sec - ts_start.tv_sec) * 1000 * 1000; \
  21. } else { \
  22. diff_microsec = \
  23. (ts_end.tv_nsec + \
  24. (1000*1000*1000 - ts_start.tv_nsec)) / 1000; \
  25. diff_microsec += \
  26. (ts_end.tv_sec - ts_start.tv_sec - 1) * 1000 * 1000; \
  27. } \
  28. })
  29. /**
  30. * cam_common_util_get_string_index()
  31. *
  32. * @brief Match the string from list of strings to return
  33. * matching index
  34. *
  35. * @strings: Pointer to list of strings
  36. * @num_strings: Number of strings in 'strings'
  37. * @matching_string: String to match
  38. * @index: Pointer to index to return matching index
  39. *
  40. * @return: 0 for success
  41. * -EINVAL for Fail
  42. */
  43. int cam_common_util_get_string_index(const char **strings,
  44. uint32_t num_strings, const char *matching_string, uint32_t *index);
  45. /**
  46. * cam_common_util_remove_duplicate_arr()
  47. *
  48. * @brief Move all the unique integers to the start of
  49. * the array and return the number of unique integers
  50. *
  51. * @array: Pointer to the first integer of array
  52. * @num: Number of elements in array
  53. *
  54. * @return: Number of unique integers in array
  55. */
  56. uint32_t cam_common_util_remove_duplicate_arr(int32_t *array,
  57. uint32_t num);
  58. #endif /* _CAM_COMMON_UTIL_H_ */