audio_cal_utils.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2014, 2018, 2020 The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _AUDIO_CAL_UTILS_H
  6. #define _AUDIO_CAL_UTILS_H
  7. #include <linux/msm_ion.h>
  8. #include <audio/linux/msm_audio_calibration.h>
  9. #include <dsp/msm_audio_ion.h>
  10. #include <dsp/audio_calibration.h>
  11. struct cal_data {
  12. size_t size;
  13. void *kvaddr;
  14. phys_addr_t paddr;
  15. };
  16. struct mem_map_data {
  17. size_t map_size;
  18. int32_t q6map_handle;
  19. int32_t ion_map_handle;
  20. struct dma_buf *dma_buf;
  21. };
  22. struct cal_block_data {
  23. size_t client_info_size;
  24. void *client_info;
  25. void *cal_info;
  26. struct list_head list;
  27. struct cal_data cal_data;
  28. bool cal_stale;
  29. bool cma_mem;
  30. struct mem_map_data map_data;
  31. int32_t buffer_number;
  32. };
  33. struct cal_util_callbacks {
  34. int (*map_cal)
  35. (int32_t cal_type, struct cal_block_data *cal_block);
  36. int (*unmap_cal)
  37. (int32_t cal_type, struct cal_block_data *cal_block);
  38. bool (*match_block)
  39. (struct cal_block_data *cal_block, void *user_data);
  40. };
  41. struct cal_type_info {
  42. struct audio_cal_reg reg;
  43. struct cal_util_callbacks cal_util_callbacks;
  44. };
  45. struct cal_type_data {
  46. struct cal_type_info info;
  47. struct mutex lock;
  48. struct list_head cal_blocks;
  49. };
  50. /* to register & degregister with cal util driver */
  51. int cal_utils_create_cal_types(int num_cal_types,
  52. struct cal_type_data **cal_type,
  53. struct cal_type_info *info);
  54. void cal_utils_destroy_cal_types(int num_cal_types,
  55. struct cal_type_data **cal_type);
  56. /* common functions for callbacks */
  57. int cal_utils_alloc_cal(size_t data_size, void *data,
  58. struct cal_type_data *cal_type,
  59. size_t client_info_size, void *client_info);
  60. int cal_utils_dealloc_cal(size_t data_size, void *data,
  61. struct cal_type_data *cal_type);
  62. int cal_utils_set_cal(size_t data_size, void *data,
  63. struct cal_type_data *cal_type,
  64. size_t client_info_size, void *client_info);
  65. /* use for SSR */
  66. void cal_utils_clear_cal_block_q6maps(int num_cal_types,
  67. struct cal_type_data **cal_type);
  68. /* common matching functions used to add blocks */
  69. bool cal_utils_match_buf_num(struct cal_block_data *cal_block,
  70. void *user_data);
  71. /* common matching functions to find cal blocks */
  72. struct cal_block_data *cal_utils_get_only_cal_block(
  73. struct cal_type_data *cal_type);
  74. /* Size of calibration specific data */
  75. size_t get_cal_info_size(int32_t cal_type);
  76. size_t get_user_cal_type_size(int32_t cal_type);
  77. /* Version of the cal type*/
  78. int32_t cal_utils_get_cal_type_version(void *cal_type_data);
  79. void cal_utils_mark_cal_used(struct cal_block_data *cal_block);
  80. bool cal_utils_is_cal_stale(struct cal_block_data *cal_block, struct cal_type_data *cal_type);
  81. int cal_utils_init(void);
  82. #endif