q6audio-v2.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* Copyright (c) 2012-2014, 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/slab.h>
  13. #include <linux/wait.h>
  14. #include <linux/sched.h>
  15. #include <linux/jiffies.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/atomic.h>
  18. #include <sound/q6afe-v2.h>
  19. #include <sound/q6audio-v2.h>
  20. int q6audio_get_port_index(u16 port_id)
  21. {
  22. switch (port_id) {
  23. case PRIMARY_I2S_RX: return IDX_PRIMARY_I2S_RX;
  24. case PRIMARY_I2S_TX: return IDX_PRIMARY_I2S_TX;
  25. case AFE_PORT_ID_PRIMARY_PCM_RX:
  26. return IDX_AFE_PORT_ID_PRIMARY_PCM_RX;
  27. case AFE_PORT_ID_PRIMARY_PCM_TX:
  28. return IDX_AFE_PORT_ID_PRIMARY_PCM_TX;
  29. case AFE_PORT_ID_SECONDARY_PCM_RX:
  30. return IDX_AFE_PORT_ID_SECONDARY_PCM_RX;
  31. case AFE_PORT_ID_SECONDARY_PCM_TX:
  32. return IDX_AFE_PORT_ID_SECONDARY_PCM_TX;
  33. case SECONDARY_I2S_RX: return IDX_SECONDARY_I2S_RX;
  34. case SECONDARY_I2S_TX: return IDX_SECONDARY_I2S_TX;
  35. case MI2S_RX: return IDX_MI2S_RX;
  36. case MI2S_TX: return IDX_MI2S_TX;
  37. case HDMI_RX: return IDX_HDMI_RX;
  38. case RSVD_2: return IDX_RSVD_2;
  39. case RSVD_3: return IDX_RSVD_3;
  40. case DIGI_MIC_TX: return IDX_DIGI_MIC_TX;
  41. case VOICE_RECORD_RX: return IDX_VOICE_RECORD_RX;
  42. case VOICE_RECORD_TX: return IDX_VOICE_RECORD_TX;
  43. case VOICE_PLAYBACK_TX: return IDX_VOICE_PLAYBACK_TX;
  44. case VOICE2_PLAYBACK_TX: return IDX_VOICE2_PLAYBACK_TX;
  45. case SLIMBUS_0_RX: return IDX_SLIMBUS_0_RX;
  46. case SLIMBUS_0_TX: return IDX_SLIMBUS_0_TX;
  47. case SLIMBUS_1_RX: return IDX_SLIMBUS_1_RX;
  48. case SLIMBUS_1_TX: return IDX_SLIMBUS_1_TX;
  49. case SLIMBUS_2_RX: return IDX_SLIMBUS_2_RX;
  50. case SLIMBUS_2_TX: return IDX_SLIMBUS_2_TX;
  51. case SLIMBUS_4_TX: return IDX_SLIMBUS_4_TX;
  52. case SLIMBUS_5_TX: return IDX_SLIMBUS_5_TX;
  53. case INT_BT_SCO_RX: return IDX_INT_BT_SCO_RX;
  54. case INT_BT_SCO_TX: return IDX_INT_BT_SCO_TX;
  55. case INT_BT_A2DP_RX: return IDX_INT_BT_A2DP_RX;
  56. case INT_FM_RX: return IDX_INT_FM_RX;
  57. case INT_FM_TX: return IDX_INT_FM_TX;
  58. case RT_PROXY_PORT_001_RX: return IDX_RT_PROXY_PORT_001_RX;
  59. case RT_PROXY_PORT_001_TX: return IDX_RT_PROXY_PORT_001_TX;
  60. case AFE_PORT_ID_PRIMARY_MI2S_RX:
  61. return IDX_AFE_PORT_ID_PRIMARY_MI2S_RX;
  62. case AFE_PORT_ID_PRIMARY_MI2S_TX:
  63. return IDX_AFE_PORT_ID_PRIMARY_MI2S_TX;
  64. case AFE_PORT_ID_QUATERNARY_MI2S_RX:
  65. return IDX_AFE_PORT_ID_QUATERNARY_MI2S_RX;
  66. case AFE_PORT_ID_QUATERNARY_MI2S_TX:
  67. return IDX_AFE_PORT_ID_QUATERNARY_MI2S_TX;
  68. case AFE_PORT_ID_SECONDARY_MI2S_RX:
  69. return IDX_AFE_PORT_ID_SECONDARY_MI2S_RX;
  70. case AFE_PORT_ID_SECONDARY_MI2S_TX:
  71. return IDX_AFE_PORT_ID_SECONDARY_MI2S_TX;
  72. case AFE_PORT_ID_TERTIARY_MI2S_RX:
  73. return IDX_AFE_PORT_ID_TERTIARY_MI2S_RX;
  74. case AFE_PORT_ID_TERTIARY_MI2S_TX:
  75. return IDX_AFE_PORT_ID_TERTIARY_MI2S_TX;
  76. default: return -EINVAL;
  77. }
  78. }
  79. int q6audio_get_port_id_from_index(u16 port_idx)
  80. {
  81. switch (port_idx) {
  82. case IDX_PRIMARY_I2S_RX: return PRIMARY_I2S_RX;
  83. case IDX_PRIMARY_I2S_TX: return PRIMARY_I2S_TX;
  84. case IDX_AFE_PORT_ID_PRIMARY_PCM_RX:
  85. return AFE_PORT_ID_PRIMARY_PCM_RX;
  86. case IDX_AFE_PORT_ID_PRIMARY_PCM_TX:
  87. return AFE_PORT_ID_PRIMARY_PCM_TX;
  88. case IDX_AFE_PORT_ID_SECONDARY_PCM_RX:
  89. return AFE_PORT_ID_SECONDARY_PCM_RX;
  90. case IDX_AFE_PORT_ID_SECONDARY_PCM_TX:
  91. return AFE_PORT_ID_SECONDARY_PCM_TX;
  92. case IDX_SECONDARY_I2S_RX: return SECONDARY_I2S_RX;
  93. case IDX_SECONDARY_I2S_TX: return SECONDARY_I2S_TX;
  94. case IDX_MI2S_RX: return MI2S_RX;
  95. case IDX_MI2S_TX: return MI2S_TX;
  96. case IDX_HDMI_RX: return HDMI_RX;
  97. case IDX_RSVD_2: return RSVD_2;
  98. case IDX_RSVD_3: return RSVD_3;
  99. case IDX_DIGI_MIC_TX: return DIGI_MIC_TX;
  100. case IDX_VOICE_RECORD_RX: return VOICE_RECORD_RX;
  101. case IDX_VOICE_RECORD_TX: return VOICE_RECORD_TX;
  102. case IDX_VOICE_PLAYBACK_TX: return VOICE_PLAYBACK_TX;
  103. case IDX_VOICE2_PLAYBACK_TX: return VOICE2_PLAYBACK_TX;
  104. case IDX_SLIMBUS_0_RX: return SLIMBUS_0_RX;
  105. case IDX_SLIMBUS_0_TX: return SLIMBUS_0_TX;
  106. case IDX_SLIMBUS_1_RX: return SLIMBUS_1_RX;
  107. case IDX_SLIMBUS_1_TX: return SLIMBUS_1_TX;
  108. case IDX_SLIMBUS_2_RX: return SLIMBUS_2_RX;
  109. case IDX_SLIMBUS_2_TX: return SLIMBUS_2_TX;
  110. case IDX_SLIMBUS_4_TX: return SLIMBUS_4_TX;
  111. case IDX_SLIMBUS_5_TX: return SLIMBUS_5_TX;
  112. case IDX_INT_BT_SCO_RX: return INT_BT_SCO_RX;
  113. case IDX_INT_BT_SCO_TX: return INT_BT_SCO_TX;
  114. case IDX_INT_BT_A2DP_RX: return INT_BT_A2DP_RX;
  115. case IDX_INT_FM_RX: return INT_FM_RX;
  116. case IDX_INT_FM_TX: return INT_FM_TX;
  117. case IDX_RT_PROXY_PORT_001_RX: return RT_PROXY_PORT_001_RX;
  118. case IDX_RT_PROXY_PORT_001_TX: return RT_PROXY_PORT_001_TX;
  119. case IDX_AFE_PORT_ID_PRIMARY_MI2S_RX:
  120. return AFE_PORT_ID_PRIMARY_MI2S_RX;
  121. case IDX_AFE_PORT_ID_PRIMARY_MI2S_TX:
  122. return AFE_PORT_ID_PRIMARY_MI2S_TX;
  123. case IDX_AFE_PORT_ID_QUATERNARY_MI2S_RX:
  124. return AFE_PORT_ID_QUATERNARY_MI2S_RX;
  125. case IDX_AFE_PORT_ID_QUATERNARY_MI2S_TX:
  126. return AFE_PORT_ID_QUATERNARY_MI2S_TX;
  127. case IDX_AFE_PORT_ID_SECONDARY_MI2S_RX:
  128. return AFE_PORT_ID_SECONDARY_MI2S_RX;
  129. case IDX_AFE_PORT_ID_SECONDARY_MI2S_TX:
  130. return AFE_PORT_ID_SECONDARY_MI2S_TX;
  131. case IDX_AFE_PORT_ID_TERTIARY_MI2S_RX:
  132. return AFE_PORT_ID_TERTIARY_MI2S_RX;
  133. case IDX_AFE_PORT_ID_TERTIARY_MI2S_TX:
  134. return AFE_PORT_ID_TERTIARY_MI2S_TX;
  135. default: return -EINVAL;
  136. }
  137. }
  138. int q6audio_get_port_id(u16 port_id)
  139. {
  140. switch (port_id) {
  141. case PRIMARY_I2S_RX: return PRIMARY_I2S_RX;
  142. case PRIMARY_I2S_TX: return PRIMARY_I2S_TX;
  143. case AFE_PORT_ID_PRIMARY_PCM_RX:
  144. return AFE_PORT_ID_PRIMARY_PCM_RX;
  145. case AFE_PORT_ID_PRIMARY_PCM_TX:
  146. return AFE_PORT_ID_PRIMARY_PCM_TX;
  147. case AFE_PORT_ID_SECONDARY_PCM_RX:
  148. return AFE_PORT_ID_SECONDARY_PCM_RX;
  149. case AFE_PORT_ID_SECONDARY_PCM_TX:
  150. return AFE_PORT_ID_SECONDARY_PCM_TX;
  151. case SECONDARY_I2S_RX: return AFE_PORT_ID_SECONDARY_MI2S_RX;
  152. case SECONDARY_I2S_TX: return AFE_PORT_ID_SECONDARY_MI2S_TX;
  153. case MI2S_RX: return AFE_PORT_ID_PRIMARY_MI2S_RX;
  154. case MI2S_TX: return AFE_PORT_ID_PRIMARY_MI2S_TX;
  155. case HDMI_RX: return AFE_PORT_ID_MULTICHAN_HDMI_RX;
  156. case RSVD_2: return IDX_RSVD_2;
  157. case RSVD_3: return IDX_RSVD_3;
  158. case DIGI_MIC_TX: return AFE_PORT_ID_DIGITAL_MIC_TX;
  159. case VOICE_RECORD_RX: return AFE_PORT_ID_VOICE_RECORD_RX;
  160. case VOICE_RECORD_TX: return AFE_PORT_ID_VOICE_RECORD_TX;
  161. case VOICE_PLAYBACK_TX: return AFE_PORT_ID_VOICE_PLAYBACK_TX;
  162. case VOICE2_PLAYBACK_TX: return AFE_PORT_ID_VOICE2_PLAYBACK_TX;
  163. case SLIMBUS_0_RX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_RX;
  164. case SLIMBUS_0_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_TX;
  165. case SLIMBUS_1_RX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX;
  166. case SLIMBUS_1_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_TX;
  167. case SLIMBUS_2_RX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_RX;
  168. case SLIMBUS_2_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_TX;
  169. case SLIMBUS_4_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_TX;
  170. case SLIMBUS_5_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_TX;
  171. case INT_BT_SCO_RX: return AFE_PORT_ID_INTERNAL_BT_SCO_RX;
  172. case INT_BT_SCO_TX: return AFE_PORT_ID_INTERNAL_BT_SCO_TX;
  173. case INT_BT_A2DP_RX: return AFE_PORT_ID_INTERNAL_BT_A2DP_RX;
  174. case INT_FM_RX: return AFE_PORT_ID_INTERNAL_FM_RX;
  175. case INT_FM_TX: return AFE_PORT_ID_INTERNAL_FM_TX;
  176. case RT_PROXY_PORT_001_RX: return AFE_PORT_ID_RT_PROXY_PORT_001_RX;
  177. case RT_PROXY_PORT_001_TX: return AFE_PORT_ID_RT_PROXY_PORT_001_TX;
  178. case AFE_PORT_ID_PRIMARY_MI2S_RX:
  179. return AFE_PORT_ID_PRIMARY_MI2S_RX;
  180. case AFE_PORT_ID_PRIMARY_MI2S_TX:
  181. return AFE_PORT_ID_PRIMARY_MI2S_TX;
  182. case AFE_PORT_ID_QUATERNARY_MI2S_RX:
  183. return AFE_PORT_ID_QUATERNARY_MI2S_RX;
  184. case AFE_PORT_ID_QUATERNARY_MI2S_TX:
  185. return AFE_PORT_ID_QUATERNARY_MI2S_TX;
  186. case AFE_PORT_ID_SECONDARY_MI2S_RX:
  187. return AFE_PORT_ID_SECONDARY_MI2S_RX;
  188. case AFE_PORT_ID_SECONDARY_MI2S_TX:
  189. return AFE_PORT_ID_SECONDARY_MI2S_TX;
  190. case AFE_PORT_ID_TERTIARY_MI2S_RX:
  191. return AFE_PORT_ID_TERTIARY_MI2S_RX;
  192. case AFE_PORT_ID_TERTIARY_MI2S_TX:
  193. return AFE_PORT_ID_TERTIARY_MI2S_TX;
  194. default:
  195. pr_warn("%s: Invalid port_id %d\n", __func__, port_id);
  196. return -EINVAL;
  197. }
  198. }
  199. int q6audio_convert_virtual_to_portid(u16 port_id)
  200. {
  201. int ret;
  202. /* if port_id is virtual, convert to physical..
  203. * if port_id is already physical, return physical
  204. */
  205. if (q6audio_validate_port(port_id) < 0) {
  206. if (port_id == RT_PROXY_DAI_001_RX ||
  207. port_id == RT_PROXY_DAI_001_TX ||
  208. port_id == RT_PROXY_DAI_002_RX ||
  209. port_id == RT_PROXY_DAI_002_TX)
  210. ret = VIRTUAL_ID_TO_PORTID(port_id);
  211. else
  212. ret = -EINVAL;
  213. } else
  214. ret = port_id;
  215. return ret;
  216. }
  217. int q6audio_is_digital_pcm_interface(u16 port_id)
  218. {
  219. int ret = 0;
  220. switch (port_id) {
  221. case PRIMARY_I2S_RX:
  222. case PRIMARY_I2S_TX:
  223. case AFE_PORT_ID_PRIMARY_PCM_RX:
  224. case AFE_PORT_ID_PRIMARY_PCM_TX:
  225. case AFE_PORT_ID_SECONDARY_PCM_RX:
  226. case AFE_PORT_ID_SECONDARY_PCM_TX:
  227. case SECONDARY_I2S_RX:
  228. case SECONDARY_I2S_TX:
  229. case MI2S_RX:
  230. case MI2S_TX:
  231. case AFE_PORT_ID_TERTIARY_MI2S_TX:
  232. case AFE_PORT_ID_TERTIARY_MI2S_RX:
  233. case AFE_PORT_ID_QUATERNARY_MI2S_RX:
  234. case AFE_PORT_ID_QUATERNARY_MI2S_TX:
  235. case AFE_PORT_ID_PRIMARY_MI2S_RX:
  236. case AFE_PORT_ID_PRIMARY_MI2S_TX:
  237. case AFE_PORT_ID_SECONDARY_MI2S_RX:
  238. case AFE_PORT_ID_SECONDARY_MI2S_TX:
  239. break;
  240. default:
  241. ret = -EINVAL;
  242. }
  243. return ret;
  244. }
  245. int q6audio_validate_port(u16 port_id)
  246. {
  247. int ret;
  248. switch (port_id) {
  249. case PRIMARY_I2S_RX:
  250. case PRIMARY_I2S_TX:
  251. case AFE_PORT_ID_PRIMARY_PCM_RX:
  252. case AFE_PORT_ID_PRIMARY_PCM_TX:
  253. case AFE_PORT_ID_SECONDARY_PCM_RX:
  254. case AFE_PORT_ID_SECONDARY_PCM_TX:
  255. case SECONDARY_I2S_RX:
  256. case SECONDARY_I2S_TX:
  257. case MI2S_RX:
  258. case MI2S_TX:
  259. case HDMI_RX:
  260. case RSVD_2:
  261. case RSVD_3:
  262. case DIGI_MIC_TX:
  263. case VOICE_RECORD_RX:
  264. case VOICE_RECORD_TX:
  265. case VOICE_PLAYBACK_TX:
  266. case VOICE2_PLAYBACK_TX:
  267. case SLIMBUS_0_RX:
  268. case SLIMBUS_0_TX:
  269. case SLIMBUS_1_RX:
  270. case SLIMBUS_1_TX:
  271. case SLIMBUS_2_RX:
  272. case SLIMBUS_2_TX:
  273. case SLIMBUS_4_TX:
  274. case SLIMBUS_5_TX:
  275. case INT_BT_SCO_RX:
  276. case INT_BT_SCO_TX:
  277. case INT_BT_A2DP_RX:
  278. case INT_FM_RX:
  279. case INT_FM_TX:
  280. case RT_PROXY_PORT_001_RX:
  281. case RT_PROXY_PORT_001_TX:
  282. case AFE_PORT_ID_PRIMARY_MI2S_RX:
  283. case AFE_PORT_ID_PRIMARY_MI2S_TX:
  284. case AFE_PORT_ID_QUATERNARY_MI2S_RX:
  285. case AFE_PORT_ID_QUATERNARY_MI2S_TX:
  286. case AFE_PORT_ID_SECONDARY_MI2S_RX:
  287. case AFE_PORT_ID_SECONDARY_MI2S_TX:
  288. #if defined (CONFIG_SND_SOC_MAX98504) || defined (CONFIG_SND_SOC_MAX98505) \
  289. || defined (CONFIG_SND_SOC_MAX98506)
  290. case AFE_PORT_ID_TERTIARY_MI2S_RX:
  291. case AFE_PORT_ID_TERTIARY_MI2S_TX:
  292. #endif
  293. {
  294. ret = 0;
  295. break;
  296. }
  297. default:
  298. ret = -EINVAL;
  299. }
  300. return ret;
  301. }