btfm_codec_hw_interface.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. int btfmcodec_register_hw_ep (struct hwep_data *ep_info)
  9. {
  10. struct btfmcodec_data *btfmcodec;
  11. struct hwep_data *hwep_info;
  12. int ret = 0;
  13. btfmcodec = btfm_get_btfmcodec();
  14. mutex_lock(&btfmcodec->hwep_drv_lock);
  15. if (!btfmcodec) {
  16. BTFMCODEC_ERR("btfm codec driver it not initialized");
  17. ret = -EPERM;
  18. goto end;
  19. }
  20. if (ep_info->num_dai == 0) {
  21. BTFMCODEC_ERR("no active information provided by hw ep interface");
  22. ret = -EPERM;
  23. goto end;
  24. }
  25. hwep_info = btfmcodec->hwep_info;
  26. if (hwep_info) {
  27. BTFMCODEC_ERR("driver already holds hardware endpoint info");
  28. ret = -EPERM;
  29. goto end;
  30. }
  31. hwep_info = kzalloc(sizeof(struct hwep_data), GFP_KERNEL);
  32. if (!hwep_info) {
  33. BTFMCODEC_ERR("%s: failed to allocate memory\n", __func__);
  34. ret = -ENOMEM;
  35. goto end;
  36. }
  37. btfmcodec->hwep_info = hwep_info;
  38. memcpy(hwep_info, ep_info, sizeof(struct hwep_data));
  39. BTFMCODEC_INFO("Below driver registered with btfm codec\n");
  40. BTFMCODEC_INFO("Driver name: %s\n", hwep_info->driver_name);
  41. BTFMCODEC_INFO("Num of dai: %d supported", hwep_info->num_dai);
  42. BTFMCODEC_INFO("Master config enabled: %u\n", test_bit(BTADV_AUDIO_MASTER_CONFIG,
  43. &hwep_info->flags));
  44. ret = btfm_register_codec(hwep_info);
  45. end:
  46. mutex_unlock(&btfmcodec->hwep_drv_lock);
  47. return ret;
  48. }
  49. int btfmcodec_unregister_hw_ep (char *driver_name)
  50. {
  51. struct btfmcodec_data *btfmcodec;
  52. struct hwep_data *hwep_info;
  53. int ret;
  54. btfmcodec = btfm_get_btfmcodec();
  55. mutex_lock(&btfmcodec->hwep_drv_lock);
  56. if (!btfmcodec) {
  57. BTFMCODEC_ERR("btfm codec driver it not initialized");
  58. ret = -EPERM;
  59. goto end;
  60. }
  61. hwep_info = btfmcodec->hwep_info;
  62. if (!hwep_info) {
  63. BTFMCODEC_ERR("%s: no active hardware endpoint registered\n", __func__);
  64. ret = -EPERM;
  65. goto end;
  66. }
  67. if(!strncmp(hwep_info->driver_name, driver_name, DEVICE_NAME_MAX_LEN)) {
  68. btfm_unregister_codec();
  69. kfree(hwep_info);
  70. BTFMCODEC_INFO("%s: deleted %s hardware endpoint\n", __func__, driver_name);
  71. ret = -1;
  72. goto end;
  73. } else {
  74. BTFMCODEC_ERR("%s: No hardware endpoint registered with %s\n", __func__, driver_name);
  75. ret = -1;
  76. goto end;
  77. }
  78. end:
  79. mutex_unlock(&btfmcodec->hwep_drv_lock);
  80. return ret;
  81. }
  82. EXPORT_SYMBOL(btfmcodec_register_hw_ep);
  83. EXPORT_SYMBOL(btfmcodec_unregister_hw_ep);