audio_pdr.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <linux/qdsp6v2/audio_pdr.h>
  15. #include <soc/qcom/service-locator.h>
  16. #include <soc/qcom/service-notifier.h>
  17. static struct pd_qmi_client_data audio_pdr_services[AUDIO_PDR_DOMAIN_MAX] = {
  18. { /* AUDIO_PDR_DOMAIN_ADSP */
  19. .client_name = "audio_pdr_adsp",
  20. .service_name = "avs/audio"
  21. }
  22. };
  23. struct srcu_notifier_head audio_pdr_cb_list;
  24. static int audio_pdr_locator_callback(struct notifier_block *this,
  25. unsigned long opcode, void *data)
  26. {
  27. unsigned long pdr_state = AUDIO_PDR_FRAMEWORK_DOWN;
  28. if (opcode == LOCATOR_DOWN) {
  29. pr_debug("%s: Service %s is down!", __func__,
  30. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].
  31. service_name);
  32. goto done;
  33. }
  34. memcpy(&audio_pdr_services, data,
  35. sizeof(audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP]));
  36. if (audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].total_domains == 1) {
  37. pr_debug("%s: Service %s, returned total domains %d, ",
  38. __func__,
  39. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].service_name,
  40. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].
  41. total_domains);
  42. pdr_state = AUDIO_PDR_FRAMEWORK_UP;
  43. goto done;
  44. } else
  45. pr_err("%s: Service %s returned invalid total domains %d",
  46. __func__,
  47. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].service_name,
  48. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].
  49. total_domains);
  50. done:
  51. srcu_notifier_call_chain(&audio_pdr_cb_list, pdr_state, NULL);
  52. return NOTIFY_OK;
  53. }
  54. static struct notifier_block audio_pdr_locator_nb = {
  55. .notifier_call = audio_pdr_locator_callback,
  56. .priority = 0,
  57. };
  58. int audio_pdr_register(struct notifier_block *nb)
  59. {
  60. if (nb == NULL) {
  61. pr_err("%s: Notifier block is NULL\n", __func__);
  62. return -EINVAL;
  63. }
  64. return srcu_notifier_chain_register(&audio_pdr_cb_list, nb);
  65. }
  66. EXPORT_SYMBOL(audio_pdr_register);
  67. void *audio_pdr_service_register(int domain_id,
  68. struct notifier_block *nb, int *curr_state)
  69. {
  70. void *handle;
  71. if ((domain_id < 0) ||
  72. (domain_id >= AUDIO_PDR_DOMAIN_MAX)) {
  73. pr_err("%s: Invalid service ID %d\n", __func__, domain_id);
  74. return ERR_PTR(-EINVAL);
  75. }
  76. handle = service_notif_register_notifier(
  77. audio_pdr_services[domain_id].domain_list[0].name,
  78. audio_pdr_services[domain_id].domain_list[0].instance_id,
  79. nb, curr_state);
  80. if (IS_ERR_OR_NULL(handle)) {
  81. pr_err("%s: Failed to register for service %s, instance %d\n",
  82. __func__,
  83. audio_pdr_services[domain_id].domain_list[0].name,
  84. audio_pdr_services[domain_id].domain_list[0].
  85. instance_id);
  86. }
  87. return handle;
  88. }
  89. EXPORT_SYMBOL(audio_pdr_service_register);
  90. int audio_pdr_service_deregister(void *service_handle,
  91. struct notifier_block *nb)
  92. {
  93. int ret;
  94. if (service_handle == NULL) {
  95. pr_err("%s: service handle is NULL\n", __func__);
  96. ret = -EINVAL;
  97. goto done;
  98. }
  99. ret = service_notif_unregister_notifier(
  100. service_handle, nb);
  101. if (ret < 0)
  102. pr_err("%s: Failed to deregister service ret %d\n",
  103. __func__, ret);
  104. done:
  105. return ret;
  106. }
  107. EXPORT_SYMBOL(audio_pdr_service_deregister);
  108. static int __init audio_pdr_subsys_init(void)
  109. {
  110. srcu_init_notifier_head(&audio_pdr_cb_list);
  111. return 0;
  112. }
  113. subsys_initcall(audio_pdr_subsys_init);
  114. static int __init audio_pdr_late_init(void)
  115. {
  116. int ret;
  117. ret = get_service_location(
  118. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].client_name,
  119. audio_pdr_services[AUDIO_PDR_DOMAIN_ADSP].service_name,
  120. &audio_pdr_locator_nb);
  121. if (ret < 0) {
  122. pr_err("%s get_service_location failed ret %d\n",
  123. __func__, ret);
  124. srcu_notifier_call_chain(&audio_pdr_cb_list,
  125. AUDIO_PDR_FRAMEWORK_DOWN, NULL);
  126. }
  127. return ret;
  128. }
  129. late_initcall(audio_pdr_late_init);