btfm_codec_hw_interface.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include "btfm_codec.h"
  6. #include "btfm_codec_hw_interface.h"
  7. #include "btfm_codec_interface.h"
  8. struct mutex hwep_drv_lock;
  9. int btfmcodec_register_hw_ep (struct hwep_data *ep_info)
  10. {
  11. struct btfmcodec_data *btfmcodec;
  12. struct hwep_data *hwep_info;
  13. int ret = 0;
  14. // ToDo Check wether we need mutex_init api
  15. mutex_lock(&hwep_drv_lock);
  16. btfmcodec = btfm_get_btfmcodec();
  17. if (!btfmcodec) {
  18. BTFMCODEC_ERR("btfm codec driver it not initialized");
  19. ret = -EPERM;
  20. goto end;
  21. }
  22. if (ep_info->num_dai == 0) {
  23. BTFMCODEC_ERR("no active information provided by hw ep interface");
  24. ret = -EPERM;
  25. goto end;
  26. }
  27. hwep_info = btfmcodec->hwep_info;
  28. if (hwep_info) {
  29. BTFMCODEC_ERR("driver already holds hardware endpoint info");
  30. ret = -EPERM;
  31. goto end;
  32. }
  33. hwep_info = kzalloc(sizeof(struct hwep_data), GFP_KERNEL);
  34. if (!hwep_info) {
  35. BTFMCODEC_ERR("%s: failed to allocate memory\n", __func__);
  36. ret = -ENOMEM;
  37. goto end;
  38. }
  39. btfmcodec->hwep_info = hwep_info;
  40. memcpy(hwep_info, ep_info, sizeof(struct hwep_data));
  41. BTFMCODEC_INFO("Below driver registered with btfm codec\n");
  42. BTFMCODEC_INFO("Driver name: %s\n", hwep_info->driver_name);
  43. BTFMCODEC_INFO("Num of dai: %d supported", hwep_info->num_dai);
  44. BTFMCODEC_INFO("Master config enabled: %u\n", test_bit(BTADV_AUDIO_MASTER_CONFIG,
  45. &hwep_info->flags));
  46. ret = btfm_register_codec(hwep_info);
  47. end:
  48. mutex_unlock(&hwep_drv_lock);
  49. return ret;
  50. }
  51. int btfmcodec_unregister_hw_ep (char *driver_name)
  52. {
  53. struct btfmcodec_data *btfmcodec;
  54. struct hwep_data *hwep_info;
  55. int ret;
  56. mutex_lock(&hwep_drv_lock);
  57. btfmcodec = btfm_get_btfmcodec();
  58. if (!btfmcodec) {
  59. BTFMCODEC_ERR("btfm codec driver it not initialized");
  60. ret = -EPERM;
  61. goto end;
  62. }
  63. hwep_info = btfmcodec->hwep_info;
  64. if (!hwep_info) {
  65. BTFMCODEC_ERR("%s: no active hardware endpoint registered\n", __func__);
  66. ret = -EPERM;
  67. goto end;
  68. }
  69. if(!strncmp(hwep_info->driver_name, driver_name, DEVICE_NAME_MAX_LEN)) {
  70. btfm_unregister_codec();
  71. kfree(hwep_info);
  72. BTFMCODEC_INFO("%s: deleted %s hardware endpoint\n", __func__, driver_name);
  73. ret = -1;
  74. goto end;
  75. } else {
  76. BTFMCODEC_ERR("%s: No hardware endpoint registered with %s\n", __func__, driver_name);
  77. ret = -1;
  78. goto end;
  79. }
  80. end:
  81. mutex_unlock(&hwep_drv_lock);
  82. return ret;
  83. }
  84. EXPORT_SYMBOL(btfmcodec_register_hw_ep);
  85. EXPORT_SYMBOL(btfmcodec_unregister_hw_ep);