msm-adie-codec.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* Copyright (c) 2010, 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. */
  13. #include <linux/module.h>
  14. #include <linux/err.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mfd/msm-adie-codec.h>
  17. #include <linux/mfd/marimba.h>
  18. static const struct adie_codec_operations *cur_adie_ops;
  19. int adie_codec_register_codec_operations(
  20. const struct adie_codec_operations *adie_ops)
  21. {
  22. if (adie_ops == NULL)
  23. return -EINVAL;
  24. if (adie_ops->codec_id != adie_get_detected_codec_type())
  25. return -EINVAL;
  26. cur_adie_ops = adie_ops;
  27. pr_info("%s: codec type %d\n", __func__, adie_ops->codec_id);
  28. return 0;
  29. }
  30. int adie_codec_open(struct adie_codec_dev_profile *profile,
  31. struct adie_codec_path **path_pptr)
  32. {
  33. int rc = -EPERM;
  34. if (cur_adie_ops != NULL) {
  35. if (cur_adie_ops->codec_open != NULL)
  36. rc = cur_adie_ops->codec_open(profile, path_pptr);
  37. } else
  38. rc = -ENODEV;
  39. return rc;
  40. }
  41. EXPORT_SYMBOL(adie_codec_open);
  42. int adie_codec_close(struct adie_codec_path *path_ptr)
  43. {
  44. int rc = -EPERM;
  45. if (cur_adie_ops != NULL) {
  46. if (cur_adie_ops->codec_close != NULL)
  47. rc = cur_adie_ops->codec_close(path_ptr);
  48. } else
  49. rc = -ENODEV;
  50. return rc;
  51. }
  52. EXPORT_SYMBOL(adie_codec_close);
  53. int adie_codec_set_device_digital_volume(struct adie_codec_path *path_ptr,
  54. u32 num_channels, u32 vol_percentage /* in percentage */)
  55. {
  56. int rc = -EPERM;
  57. if (cur_adie_ops != NULL) {
  58. if (cur_adie_ops->codec_set_device_digital_volume != NULL) {
  59. rc = cur_adie_ops->codec_set_device_digital_volume(
  60. path_ptr,
  61. num_channels,
  62. vol_percentage);
  63. }
  64. } else
  65. rc = -ENODEV;
  66. return rc;
  67. }
  68. EXPORT_SYMBOL(adie_codec_set_device_digital_volume);
  69. int adie_codec_set_device_analog_volume(struct adie_codec_path *path_ptr,
  70. u32 num_channels, u32 volume /* in percentage */)
  71. {
  72. int rc = -EPERM;
  73. if (cur_adie_ops != NULL) {
  74. if (cur_adie_ops->codec_set_device_analog_volume != NULL) {
  75. rc = cur_adie_ops->codec_set_device_analog_volume(
  76. path_ptr,
  77. num_channels,
  78. volume);
  79. }
  80. } else
  81. rc = -ENODEV;
  82. return rc;
  83. }
  84. EXPORT_SYMBOL(adie_codec_set_device_analog_volume);
  85. int adie_codec_setpath(struct adie_codec_path *path_ptr, u32 freq_plan, u32 osr)
  86. {
  87. int rc = -EPERM;
  88. if (cur_adie_ops != NULL) {
  89. if (cur_adie_ops->codec_setpath != NULL) {
  90. rc = cur_adie_ops->codec_setpath(path_ptr,
  91. freq_plan,
  92. osr);
  93. }
  94. } else
  95. rc = -ENODEV;
  96. return rc;
  97. }
  98. EXPORT_SYMBOL(adie_codec_setpath);
  99. u32 adie_codec_freq_supported(struct adie_codec_dev_profile *profile,
  100. u32 requested_freq)
  101. {
  102. int rc = -EPERM;
  103. if (cur_adie_ops != NULL) {
  104. if (cur_adie_ops->codec_freq_supported != NULL)
  105. rc = cur_adie_ops->codec_freq_supported(profile,
  106. requested_freq);
  107. } else
  108. rc = -ENODEV;
  109. return rc;
  110. }
  111. EXPORT_SYMBOL(adie_codec_freq_supported);
  112. int adie_codec_enable_sidetone(struct adie_codec_path *rx_path_ptr,
  113. u32 enable)
  114. {
  115. int rc = -EPERM;
  116. if (cur_adie_ops != NULL) {
  117. if (cur_adie_ops->codec_enable_sidetone != NULL)
  118. rc = cur_adie_ops->codec_enable_sidetone(rx_path_ptr,
  119. enable);
  120. } else
  121. rc = -ENODEV;
  122. return rc;
  123. }
  124. EXPORT_SYMBOL(adie_codec_enable_sidetone);
  125. int adie_codec_enable_anc(struct adie_codec_path *rx_path_ptr,
  126. u32 enable, struct adie_codec_anc_data *calibration_writes)
  127. {
  128. int rc = -EPERM;
  129. if (cur_adie_ops != NULL) {
  130. if (cur_adie_ops->codec_enable_anc != NULL)
  131. rc = cur_adie_ops->codec_enable_anc(rx_path_ptr,
  132. enable, calibration_writes);
  133. }
  134. return rc;
  135. }
  136. EXPORT_SYMBOL(adie_codec_enable_anc);
  137. int adie_codec_proceed_stage(struct adie_codec_path *path_ptr, u32 state)
  138. {
  139. int rc = -EPERM;
  140. if (cur_adie_ops != NULL) {
  141. if (cur_adie_ops->codec_proceed_stage != NULL)
  142. rc = cur_adie_ops->codec_proceed_stage(path_ptr,
  143. state);
  144. } else
  145. rc = -ENODEV;
  146. return rc;
  147. }
  148. EXPORT_SYMBOL(adie_codec_proceed_stage);
  149. int adie_codec_set_master_mode(struct adie_codec_path *path_ptr, u8 master)
  150. {
  151. int rc = -EPERM;
  152. if (cur_adie_ops != NULL) {
  153. if (cur_adie_ops->codec_set_master_mode != NULL)
  154. rc = cur_adie_ops->codec_set_master_mode(path_ptr,
  155. master);
  156. } else
  157. rc = -ENODEV;
  158. return rc;
  159. }
  160. EXPORT_SYMBOL(adie_codec_set_master_mode);