msm-transcode-loopback-q6-v2.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/init.h>
  5. #include <linux/err.h>
  6. #include <linux/module.h>
  7. #include <linux/moduleparam.h>
  8. #include <linux/time.h>
  9. #include <linux/math64.h>
  10. #include <linux/wait.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/slab.h>
  13. #include <sound/core.h>
  14. #include <sound/soc.h>
  15. #include <sound/soc-dapm.h>
  16. #include <sound/pcm.h>
  17. #include <sound/initval.h>
  18. #include <sound/control.h>
  19. #include <sound/audio_effects.h>
  20. #include <sound/pcm_params.h>
  21. #include <sound/timer.h>
  22. #include <sound/tlv.h>
  23. #include <sound/compress_params.h>
  24. #include <sound/compress_offload.h>
  25. #include <sound/compress_driver.h>
  26. #include <dsp/msm_audio_ion.h>
  27. #include <dsp/apr_audio-v2.h>
  28. #include <dsp/q6asm-v2.h>
  29. #include <dsp/q6audio-v2.h>
  30. #include <dsp/msm-audio-effects-q6-v2.h>
  31. #include "msm-pcm-routing-v2.h"
  32. #include "msm-qti-pp-config.h"
  33. #define DRV_NAME "msm-transcode-loopback-v2"
  34. #define LOOPBACK_SESSION_MAX_NUM_STREAMS 2
  35. /* Max volume corresponding to 24dB */
  36. #define TRANSCODE_LR_VOL_MAX_DB 0xFFFF
  37. #define APP_TYPE_CONFIG_IDX_APP_TYPE 0
  38. #define APP_TYPE_CONFIG_IDX_ACDB_ID 1
  39. #define APP_TYPE_CONFIG_IDX_SAMPLE_RATE 2
  40. #define APP_TYPE_CONFIG_IDX_BE_ID 3
  41. static DEFINE_MUTEX(transcode_loopback_session_lock);
  42. struct msm_transcode_audio_effects {
  43. struct bass_boost_params bass_boost;
  44. struct pbe_params pbe;
  45. struct virtualizer_params virtualizer;
  46. struct reverb_params reverb;
  47. struct eq_params equalizer;
  48. struct soft_volume_params volume;
  49. };
  50. struct trans_loopback_pdata {
  51. struct snd_compr_stream *cstream[MSM_FRONTEND_DAI_MAX];
  52. uint32_t master_gain;
  53. int perf_mode[MSM_FRONTEND_DAI_MAX];
  54. struct msm_transcode_audio_effects *audio_effects[MSM_FRONTEND_DAI_MAX];
  55. };
  56. struct loopback_stream {
  57. struct snd_compr_stream *cstream;
  58. uint32_t codec_format;
  59. bool start;
  60. int perf_mode;
  61. };
  62. enum loopback_session_state {
  63. /* One or both streams not opened */
  64. LOOPBACK_SESSION_CLOSE = 0,
  65. /* Loopback streams opened */
  66. LOOPBACK_SESSION_READY,
  67. /* Loopback streams opened and formats configured */
  68. LOOPBACK_SESSION_START,
  69. /* Trigger issued on either of streams when in START state */
  70. LOOPBACK_SESSION_RUN
  71. };
  72. struct msm_transcode_loopback {
  73. struct loopback_stream source;
  74. struct loopback_stream sink;
  75. struct snd_compr_caps source_compr_cap;
  76. struct snd_compr_caps sink_compr_cap;
  77. uint32_t instance;
  78. uint32_t num_streams;
  79. int session_state;
  80. struct mutex lock;
  81. int session_id;
  82. struct audio_client *audio_client;
  83. };
  84. /* Transcode loopback global info struct */
  85. static struct msm_transcode_loopback transcode_info;
  86. static void loopback_event_handler(uint32_t opcode,
  87. uint32_t token, uint32_t *payload, void *priv)
  88. {
  89. struct msm_transcode_loopback *trans =
  90. (struct msm_transcode_loopback *)priv;
  91. struct snd_soc_pcm_runtime *rtd;
  92. struct snd_compr_stream *cstream;
  93. struct audio_client *ac;
  94. int stream_id;
  95. int ret;
  96. if (!trans || !payload) {
  97. pr_err("%s: rtd or payload is NULL\n", __func__);
  98. return;
  99. }
  100. cstream = trans->sink.cstream;
  101. ac = trans->audio_client;
  102. /*
  103. * Token for rest of the compressed commands use to set
  104. * session id, stream id, dir etc.
  105. */
  106. stream_id = q6asm_get_stream_id_from_token(token);
  107. switch (opcode) {
  108. case ASM_STREAM_CMD_ENCDEC_EVENTS:
  109. case ASM_IEC_61937_MEDIA_FMT_EVENT:
  110. pr_debug("%s: Handling stream event : 0X%x\n",
  111. __func__, opcode);
  112. rtd = cstream->private_data;
  113. if (!rtd) {
  114. pr_err("%s: rtd is NULL\n", __func__);
  115. return;
  116. }
  117. ret = msm_adsp_inform_mixer_ctl(rtd, payload);
  118. if (ret) {
  119. pr_err("%s: failed to inform mixer ctrl. err = %d\n",
  120. __func__, ret);
  121. return;
  122. }
  123. break;
  124. case APR_BASIC_RSP_RESULT: {
  125. switch (payload[0]) {
  126. case ASM_SESSION_CMD_RUN_V2:
  127. pr_debug("%s: ASM_SESSION_CMD_RUN_V2:", __func__);
  128. pr_debug("token 0x%x, stream id %d\n", token,
  129. stream_id);
  130. break;
  131. case ASM_STREAM_CMD_CLOSE:
  132. pr_debug("%s: ASM_DATA_CMD_CLOSE:", __func__);
  133. pr_debug("token 0x%x, stream id %d\n", token,
  134. stream_id);
  135. break;
  136. default:
  137. break;
  138. }
  139. break;
  140. }
  141. default:
  142. pr_debug("%s: Not Supported Event opcode[0x%x]\n",
  143. __func__, opcode);
  144. break;
  145. }
  146. }
  147. static void populate_codec_list(struct msm_transcode_loopback *trans,
  148. struct snd_compr_stream *cstream)
  149. {
  150. struct snd_compr_caps compr_cap;
  151. pr_debug("%s\n", __func__);
  152. memset(&compr_cap, 0, sizeof(struct snd_compr_caps));
  153. if (cstream->direction == SND_COMPRESS_CAPTURE) {
  154. compr_cap.direction = SND_COMPRESS_CAPTURE;
  155. compr_cap.num_codecs = 4;
  156. compr_cap.codecs[0] = SND_AUDIOCODEC_PCM;
  157. compr_cap.codecs[1] = SND_AUDIOCODEC_AC3;
  158. compr_cap.codecs[2] = SND_AUDIOCODEC_EAC3;
  159. compr_cap.codecs[3] = SND_AUDIOCODEC_TRUEHD;
  160. memcpy(&trans->source_compr_cap, &compr_cap,
  161. sizeof(struct snd_compr_caps));
  162. }
  163. if (cstream->direction == SND_COMPRESS_PLAYBACK) {
  164. compr_cap.direction = SND_COMPRESS_PLAYBACK;
  165. compr_cap.num_codecs = 1;
  166. compr_cap.codecs[0] = SND_AUDIOCODEC_PCM;
  167. memcpy(&trans->sink_compr_cap, &compr_cap,
  168. sizeof(struct snd_compr_caps));
  169. }
  170. }
  171. static int msm_transcode_loopback_open(struct snd_compr_stream *cstream)
  172. {
  173. int ret = 0;
  174. struct snd_compr_runtime *runtime;
  175. struct snd_soc_pcm_runtime *rtd;
  176. struct msm_transcode_loopback *trans = &transcode_info;
  177. struct trans_loopback_pdata *pdata;
  178. struct snd_soc_component *component;
  179. if (cstream == NULL) {
  180. pr_err("%s: Invalid substream\n", __func__);
  181. return -EINVAL;
  182. }
  183. runtime = cstream->runtime;
  184. rtd = snd_pcm_substream_chip(cstream);
  185. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  186. if (!component) {
  187. pr_err("%s: component is NULL\n", __func__);
  188. return -EINVAL;
  189. }
  190. pdata = snd_soc_component_get_drvdata(component);
  191. pdata->cstream[rtd->dai_link->id] = cstream;
  192. pdata->audio_effects[rtd->dai_link->id] =
  193. kzalloc(sizeof(struct msm_transcode_audio_effects), GFP_KERNEL);
  194. if (pdata->audio_effects[rtd->dai_link->id] == NULL) {
  195. ret = -ENOMEM;
  196. goto effect_error;
  197. }
  198. mutex_lock(&trans->lock);
  199. if (trans->num_streams > LOOPBACK_SESSION_MAX_NUM_STREAMS) {
  200. pr_err("msm_transcode_open failed..invalid stream\n");
  201. ret = -EINVAL;
  202. goto exit;
  203. }
  204. if (cstream->direction == SND_COMPRESS_CAPTURE) {
  205. if (trans->source.cstream == NULL) {
  206. trans->source.cstream = cstream;
  207. trans->num_streams++;
  208. } else {
  209. pr_err("%s: capture stream already opened\n",
  210. __func__);
  211. ret = -EINVAL;
  212. goto exit;
  213. }
  214. } else if (cstream->direction == SND_COMPRESS_PLAYBACK) {
  215. if (trans->sink.cstream == NULL) {
  216. trans->sink.cstream = cstream;
  217. trans->num_streams++;
  218. } else {
  219. pr_debug("%s: playback stream already opened\n",
  220. __func__);
  221. ret = -EINVAL;
  222. goto exit;
  223. }
  224. msm_adsp_init_mixer_ctl_pp_event_queue(rtd);
  225. }
  226. pr_debug("%s: num stream%d, stream name %s\n", __func__,
  227. trans->num_streams, cstream->name);
  228. populate_codec_list(trans, cstream);
  229. if (trans->num_streams == LOOPBACK_SESSION_MAX_NUM_STREAMS) {
  230. pr_debug("%s: Moving loopback session to READY state %d\n",
  231. __func__, trans->session_state);
  232. trans->session_state = LOOPBACK_SESSION_READY;
  233. }
  234. runtime->private_data = trans;
  235. exit:
  236. mutex_unlock(&trans->lock);
  237. if ((pdata->audio_effects[rtd->dai_link->id] != NULL) && (ret < 0)) {
  238. kfree(pdata->audio_effects[rtd->dai_link->id]);
  239. pdata->audio_effects[rtd->dai_link->id] = NULL;
  240. }
  241. effect_error:
  242. return ret;
  243. }
  244. static void stop_transcoding(struct msm_transcode_loopback *trans)
  245. {
  246. struct snd_soc_pcm_runtime *soc_pcm_rx;
  247. struct snd_soc_pcm_runtime *soc_pcm_tx;
  248. if (trans->audio_client != NULL) {
  249. q6asm_cmd(trans->audio_client, CMD_CLOSE);
  250. if (trans->sink.cstream != NULL) {
  251. soc_pcm_rx = trans->sink.cstream->private_data;
  252. msm_pcm_routing_dereg_phy_stream(
  253. soc_pcm_rx->dai_link->id,
  254. SND_COMPRESS_PLAYBACK);
  255. }
  256. if (trans->source.cstream != NULL) {
  257. soc_pcm_tx = trans->source.cstream->private_data;
  258. msm_pcm_routing_dereg_phy_stream(
  259. soc_pcm_tx->dai_link->id,
  260. SND_COMPRESS_CAPTURE);
  261. }
  262. q6asm_audio_client_free(trans->audio_client);
  263. trans->audio_client = NULL;
  264. }
  265. }
  266. static int msm_transcode_loopback_free(struct snd_compr_stream *cstream)
  267. {
  268. struct snd_compr_runtime *runtime = cstream->runtime;
  269. struct msm_transcode_loopback *trans = runtime->private_data;
  270. struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(cstream);
  271. struct snd_soc_component *component;
  272. struct trans_loopback_pdata *pdata;
  273. int ret = 0;
  274. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  275. if (!component) {
  276. pr_err("%s: component is NULL\n", __func__);
  277. return -EINVAL;
  278. }
  279. pdata = snd_soc_component_get_drvdata(component);
  280. mutex_lock(&trans->lock);
  281. if (pdata->audio_effects[rtd->dai_link->id] != NULL) {
  282. kfree(pdata->audio_effects[rtd->dai_link->id]);
  283. pdata->audio_effects[rtd->dai_link->id] = NULL;
  284. }
  285. pr_debug("%s: Transcode loopback end:%d, streams %d\n", __func__,
  286. cstream->direction, trans->num_streams);
  287. trans->num_streams--;
  288. stop_transcoding(trans);
  289. if (cstream->direction == SND_COMPRESS_PLAYBACK) {
  290. memset(&trans->sink, 0, sizeof(struct loopback_stream));
  291. msm_adsp_clean_mixer_ctl_pp_event_queue(rtd);
  292. } else if (cstream->direction == SND_COMPRESS_CAPTURE) {
  293. memset(&trans->source, 0, sizeof(struct loopback_stream));
  294. }
  295. trans->session_state = LOOPBACK_SESSION_CLOSE;
  296. mutex_unlock(&trans->lock);
  297. return ret;
  298. }
  299. static int msm_transcode_loopback_trigger(struct snd_compr_stream *cstream,
  300. int cmd)
  301. {
  302. struct snd_compr_runtime *runtime = cstream->runtime;
  303. struct msm_transcode_loopback *trans = runtime->private_data;
  304. switch (cmd) {
  305. case SNDRV_PCM_TRIGGER_START:
  306. case SNDRV_PCM_TRIGGER_RESUME:
  307. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  308. if (trans->session_state == LOOPBACK_SESSION_START) {
  309. pr_debug("%s: Issue Loopback session %d RUN\n",
  310. __func__, trans->instance);
  311. q6asm_run_nowait(trans->audio_client, 0, 0, 0);
  312. trans->session_state = LOOPBACK_SESSION_RUN;
  313. }
  314. break;
  315. case SNDRV_PCM_TRIGGER_SUSPEND:
  316. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  317. case SNDRV_PCM_TRIGGER_STOP:
  318. pr_debug("%s: Issue Loopback session %d STOP\n", __func__,
  319. trans->instance);
  320. if (trans->session_state == LOOPBACK_SESSION_RUN)
  321. q6asm_cmd_nowait(trans->audio_client, CMD_PAUSE);
  322. trans->session_state = LOOPBACK_SESSION_START;
  323. break;
  324. default:
  325. break;
  326. }
  327. return 0;
  328. }
  329. static int msm_transcode_set_render_window(struct audio_client *ac,
  330. uint32_t ws_lsw, uint32_t ws_msw,
  331. uint32_t we_lsw, uint32_t we_msw)
  332. {
  333. int ret = -EINVAL;
  334. struct asm_session_mtmx_strtr_param_window_v2_t asm_mtmx_strtr_window;
  335. uint32_t param_id;
  336. pr_debug("%s, ws_lsw 0x%x ws_msw 0x%x we_lsw 0x%x we_msw 0x%x\n",
  337. __func__, ws_lsw, ws_msw, we_lsw, we_msw);
  338. memset(&asm_mtmx_strtr_window, 0,
  339. sizeof(struct asm_session_mtmx_strtr_param_window_v2_t));
  340. asm_mtmx_strtr_window.window_lsw = ws_lsw;
  341. asm_mtmx_strtr_window.window_msw = ws_msw;
  342. param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_START_V2;
  343. ret = q6asm_send_mtmx_strtr_window(ac, &asm_mtmx_strtr_window, param_id);
  344. if (ret) {
  345. pr_err("%s, start window can't be set error %d\n", __func__, ret);
  346. goto exit;
  347. }
  348. asm_mtmx_strtr_window.window_lsw = we_lsw;
  349. asm_mtmx_strtr_window.window_msw = we_msw;
  350. param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_END_V2;
  351. ret = q6asm_send_mtmx_strtr_window(ac, &asm_mtmx_strtr_window, param_id);
  352. if (ret)
  353. pr_err("%s, end window can't be set error %d\n", __func__, ret);
  354. exit:
  355. return ret;
  356. }
  357. static int msm_transcode_loopback_set_params(struct snd_compr_stream *cstream,
  358. struct snd_compr_params *codec_param)
  359. {
  360. struct snd_compr_runtime *runtime = cstream->runtime;
  361. struct msm_transcode_loopback *trans = runtime->private_data;
  362. struct snd_soc_pcm_runtime *soc_pcm_rx;
  363. struct snd_soc_pcm_runtime *soc_pcm_tx;
  364. struct snd_soc_pcm_runtime *rtd;
  365. struct snd_soc_component *component;
  366. struct trans_loopback_pdata *pdata;
  367. uint32_t bit_width = 16;
  368. int ret = 0;
  369. if (trans == NULL) {
  370. pr_err("%s: Invalid param\n", __func__);
  371. return -EINVAL;
  372. }
  373. mutex_lock(&trans->lock);
  374. rtd = snd_pcm_substream_chip(cstream);
  375. if (!rtd) {
  376. pr_err("%s: rtd is NULL\n", __func__);
  377. return -EINVAL;
  378. }
  379. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  380. if (!component) {
  381. pr_err("%s: component is NULL\n", __func__);
  382. return -EINVAL;
  383. }
  384. pdata = snd_soc_component_get_drvdata(component);
  385. if (cstream->direction == SND_COMPRESS_PLAYBACK) {
  386. if (codec_param->codec.id == SND_AUDIOCODEC_PCM) {
  387. trans->sink.codec_format =
  388. FORMAT_LINEAR_PCM;
  389. switch (codec_param->codec.format) {
  390. case SNDRV_PCM_FORMAT_S32_LE:
  391. bit_width = 32;
  392. break;
  393. case SNDRV_PCM_FORMAT_S24_LE:
  394. bit_width = 24;
  395. break;
  396. case SNDRV_PCM_FORMAT_S24_3LE:
  397. bit_width = 24;
  398. break;
  399. case SNDRV_PCM_FORMAT_S16_LE:
  400. default:
  401. bit_width = 16;
  402. break;
  403. }
  404. } else {
  405. pr_debug("%s: unknown sink codec\n", __func__);
  406. ret = -EINVAL;
  407. goto exit;
  408. }
  409. trans->sink.start = true;
  410. trans->sink.perf_mode = pdata->perf_mode[rtd->dai_link->id];
  411. }
  412. if (cstream->direction == SND_COMPRESS_CAPTURE) {
  413. switch (codec_param->codec.id) {
  414. case SND_AUDIOCODEC_PCM:
  415. pr_debug("Source SND_AUDIOCODEC_PCM\n");
  416. trans->source.codec_format =
  417. FORMAT_LINEAR_PCM;
  418. break;
  419. case SND_AUDIOCODEC_AC3:
  420. pr_debug("Source SND_AUDIOCODEC_AC3\n");
  421. trans->source.codec_format =
  422. FORMAT_AC3;
  423. break;
  424. case SND_AUDIOCODEC_EAC3:
  425. pr_debug("Source SND_AUDIOCODEC_EAC3\n");
  426. trans->source.codec_format =
  427. FORMAT_EAC3;
  428. break;
  429. case SND_AUDIOCODEC_TRUEHD:
  430. pr_debug("Source SND_AUDIOCODEC_TRUEHD\n");
  431. trans->source.codec_format =
  432. FORMAT_TRUEHD;
  433. break;
  434. default:
  435. pr_debug("%s: unknown source codec\n", __func__);
  436. ret = -EINVAL;
  437. goto exit;
  438. }
  439. trans->source.start = true;
  440. trans->source.perf_mode = pdata->perf_mode[rtd->dai_link->id];
  441. }
  442. pr_debug("%s: trans->source.start %d trans->sink.start %d trans->source.cstream %pK trans->sink.cstream %pK trans->session_state %d\n",
  443. __func__, trans->source.start, trans->sink.start,
  444. trans->source.cstream, trans->sink.cstream,
  445. trans->session_state);
  446. if ((trans->session_state == LOOPBACK_SESSION_READY) &&
  447. trans->source.start && trans->sink.start) {
  448. pr_debug("%s: Moving loopback session to start state\n",
  449. __func__);
  450. trans->session_state = LOOPBACK_SESSION_START;
  451. }
  452. if (trans->session_state == LOOPBACK_SESSION_START) {
  453. if (trans->audio_client != NULL) {
  454. pr_debug("%s: ASM client already opened, closing\n",
  455. __func__);
  456. stop_transcoding(trans);
  457. }
  458. trans->audio_client = q6asm_audio_client_alloc(
  459. (app_cb)loopback_event_handler, trans);
  460. if (!trans->audio_client) {
  461. pr_err("%s: Could not allocate memory\n", __func__);
  462. ret = -EINVAL;
  463. goto exit;
  464. }
  465. pr_debug("%s: ASM client allocated, callback %pK\n", __func__,
  466. loopback_event_handler);
  467. trans->session_id = trans->audio_client->session;
  468. trans->audio_client->perf_mode = trans->sink.perf_mode;
  469. ret = q6asm_open_transcode_loopback(trans->audio_client,
  470. bit_width,
  471. trans->source.codec_format,
  472. trans->sink.codec_format);
  473. if (ret < 0) {
  474. pr_err("%s: Session transcode loopback open failed\n",
  475. __func__);
  476. q6asm_audio_client_free(trans->audio_client);
  477. trans->audio_client = NULL;
  478. goto exit;
  479. }
  480. pr_debug("%s: Starting ADM open for loopback\n", __func__);
  481. soc_pcm_rx = trans->sink.cstream->private_data;
  482. soc_pcm_tx = trans->source.cstream->private_data;
  483. if (trans->source.codec_format != FORMAT_LINEAR_PCM)
  484. msm_pcm_routing_reg_phy_compr_stream(
  485. soc_pcm_tx->dai_link->id,
  486. LEGACY_PCM_MODE,
  487. trans->session_id,
  488. SNDRV_PCM_STREAM_CAPTURE,
  489. COMPRESSED_PASSTHROUGH_GEN);
  490. else
  491. msm_pcm_routing_reg_phy_stream(
  492. soc_pcm_tx->dai_link->id,
  493. trans->source.perf_mode,
  494. trans->session_id,
  495. SNDRV_PCM_STREAM_CAPTURE);
  496. /* Opening Rx ADM in LOW_LATENCY mode by default */
  497. msm_pcm_routing_reg_phy_stream(
  498. soc_pcm_rx->dai_link->id,
  499. trans->sink.perf_mode,
  500. trans->session_id,
  501. SNDRV_PCM_STREAM_PLAYBACK);
  502. pr_debug("%s: Successfully opened ADM sessions\n", __func__);
  503. }
  504. exit:
  505. mutex_unlock(&trans->lock);
  506. return ret;
  507. }
  508. static int msm_transcode_loopback_get_caps(struct snd_compr_stream *cstream,
  509. struct snd_compr_caps *arg)
  510. {
  511. struct snd_compr_runtime *runtime;
  512. struct msm_transcode_loopback *trans;
  513. if (!arg || !cstream) {
  514. pr_err("%s: Invalid arguments\n", __func__);
  515. return -EINVAL;
  516. }
  517. runtime = cstream->runtime;
  518. trans = runtime->private_data;
  519. pr_debug("%s\n", __func__);
  520. if (cstream->direction == SND_COMPRESS_CAPTURE)
  521. memcpy(arg, &trans->source_compr_cap,
  522. sizeof(struct snd_compr_caps));
  523. else
  524. memcpy(arg, &trans->sink_compr_cap,
  525. sizeof(struct snd_compr_caps));
  526. return 0;
  527. }
  528. static int msm_transcode_loopback_set_metadata(struct snd_compr_stream *cstream,
  529. struct snd_compr_metadata *metadata)
  530. {
  531. struct snd_soc_pcm_runtime *rtd;
  532. struct trans_loopback_pdata *pdata;
  533. struct msm_transcode_loopback *prtd = NULL;
  534. struct snd_soc_component *component;
  535. struct audio_client *ac = NULL;
  536. if (!metadata || !cstream) {
  537. pr_err("%s: Invalid arguments\n", __func__);
  538. return -EINVAL;
  539. }
  540. rtd = snd_pcm_substream_chip(cstream);
  541. if (!rtd) {
  542. pr_err("%s: rtd is NULL\n", __func__);
  543. return -EINVAL;
  544. }
  545. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  546. if (!component) {
  547. pr_err("%s: component is NULL\n", __func__);
  548. return -EINVAL;
  549. }
  550. pdata = snd_soc_component_get_drvdata(component);
  551. prtd = cstream->runtime->private_data;
  552. if (!prtd || !prtd->audio_client) {
  553. pr_err("%s: prtd or audio client is NULL\n", __func__);
  554. return -EINVAL;
  555. }
  556. ac = prtd->audio_client;
  557. switch (metadata->key) {
  558. case SNDRV_COMPRESS_LATENCY_MODE:
  559. {
  560. switch (metadata->value[0]) {
  561. case SNDRV_COMPRESS_LEGACY_LATENCY_MODE:
  562. pdata->perf_mode[rtd->dai_link->id] = LEGACY_PCM_MODE;
  563. break;
  564. case SNDRV_COMPRESS_LOW_LATENCY_MODE:
  565. pdata->perf_mode[rtd->dai_link->id] =
  566. LOW_LATENCY_PCM_MODE;
  567. break;
  568. default:
  569. pr_debug("%s: Unsupported latency mode %d, default to Legacy\n",
  570. __func__, metadata->value[0]);
  571. pdata->perf_mode[rtd->dai_link->id] = LEGACY_PCM_MODE;
  572. break;
  573. }
  574. break;
  575. }
  576. case SNDRV_COMPRESS_RENDER_WINDOW:
  577. {
  578. return msm_transcode_set_render_window(
  579. ac,
  580. metadata->value[0],
  581. metadata->value[1],
  582. metadata->value[2],
  583. metadata->value[3]);
  584. }
  585. default:
  586. pr_debug("%s: Unsupported metadata %d\n",
  587. __func__, metadata->key);
  588. break;
  589. }
  590. return 0;
  591. }
  592. static int msm_transcode_stream_cmd_put(struct snd_kcontrol *kcontrol,
  593. struct snd_ctl_elem_value *ucontrol)
  594. {
  595. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  596. unsigned long fe_id = kcontrol->private_value;
  597. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  598. snd_soc_component_get_drvdata(comp);
  599. struct snd_compr_stream *cstream = NULL;
  600. struct msm_transcode_loopback *prtd;
  601. int ret = 0;
  602. struct msm_adsp_event_data *event_data = NULL;
  603. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  604. pr_err("%s Received invalid fe_id %lu\n",
  605. __func__, fe_id);
  606. ret = -EINVAL;
  607. goto done;
  608. }
  609. cstream = pdata->cstream[fe_id];
  610. if (cstream == NULL) {
  611. pr_err("%s cstream is null.\n", __func__);
  612. ret = -EINVAL;
  613. goto done;
  614. }
  615. prtd = cstream->runtime->private_data;
  616. if (!prtd) {
  617. pr_err("%s: prtd is null.\n", __func__);
  618. ret = -EINVAL;
  619. goto done;
  620. }
  621. if (prtd->audio_client == NULL) {
  622. pr_err("%s: audio_client is null.\n", __func__);
  623. ret = -EINVAL;
  624. goto done;
  625. }
  626. event_data = (struct msm_adsp_event_data *)ucontrol->value.bytes.data;
  627. if ((event_data->event_type < ADSP_STREAM_PP_EVENT) ||
  628. (event_data->event_type >= ADSP_STREAM_EVENT_MAX)) {
  629. pr_err("%s: invalid event_type=%d",
  630. __func__, event_data->event_type);
  631. ret = -EINVAL;
  632. goto done;
  633. }
  634. if (event_data->payload_len > sizeof(ucontrol->value.bytes.data)
  635. - sizeof(struct msm_adsp_event_data)) {
  636. pr_err("%s param length=%d exceeds limit",
  637. __func__, event_data->payload_len);
  638. ret = -EINVAL;
  639. goto done;
  640. }
  641. ret = q6asm_send_stream_cmd(prtd->audio_client, event_data);
  642. if (ret < 0)
  643. pr_err("%s: failed to send stream event cmd, err = %d\n",
  644. __func__, ret);
  645. done:
  646. return ret;
  647. }
  648. static int msm_transcode_ion_fd_map_put(struct snd_kcontrol *kcontrol,
  649. struct snd_ctl_elem_value *ucontrol)
  650. {
  651. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  652. unsigned long fe_id = kcontrol->private_value;
  653. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  654. snd_soc_component_get_drvdata(comp);
  655. struct snd_compr_stream *cstream = NULL;
  656. struct msm_transcode_loopback *prtd;
  657. int fd;
  658. int ret = 0;
  659. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  660. pr_err("%s Received out of bounds invalid fe_id %lu\n",
  661. __func__, fe_id);
  662. ret = -EINVAL;
  663. goto done;
  664. }
  665. cstream = pdata->cstream[fe_id];
  666. if (cstream == NULL) {
  667. pr_err("%s cstream is null\n", __func__);
  668. ret = -EINVAL;
  669. goto done;
  670. }
  671. prtd = cstream->runtime->private_data;
  672. if (!prtd) {
  673. pr_err("%s: prtd is null\n", __func__);
  674. ret = -EINVAL;
  675. goto done;
  676. }
  677. if (prtd->audio_client == NULL) {
  678. pr_err("%s: audio_client is null\n", __func__);
  679. ret = -EINVAL;
  680. goto done;
  681. }
  682. memcpy(&fd, ucontrol->value.bytes.data, sizeof(fd));
  683. ret = q6asm_send_ion_fd(prtd->audio_client, fd);
  684. if (ret < 0)
  685. pr_err("%s: failed to register ion fd\n", __func__);
  686. done:
  687. return ret;
  688. }
  689. static int msm_transcode_rtic_event_ack_put(struct snd_kcontrol *kcontrol,
  690. struct snd_ctl_elem_value *ucontrol)
  691. {
  692. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  693. unsigned long fe_id = kcontrol->private_value;
  694. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  695. snd_soc_component_get_drvdata(comp);
  696. struct snd_compr_stream *cstream = NULL;
  697. struct msm_transcode_loopback *prtd;
  698. int ret = 0;
  699. int param_length = 0;
  700. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  701. pr_err("%s Received invalid fe_id %lu\n",
  702. __func__, fe_id);
  703. ret = -EINVAL;
  704. goto done;
  705. }
  706. cstream = pdata->cstream[fe_id];
  707. if (cstream == NULL) {
  708. pr_err("%s cstream is null\n", __func__);
  709. ret = -EINVAL;
  710. goto done;
  711. }
  712. prtd = cstream->runtime->private_data;
  713. if (!prtd) {
  714. pr_err("%s: prtd is null\n", __func__);
  715. ret = -EINVAL;
  716. goto done;
  717. }
  718. if (prtd->audio_client == NULL) {
  719. pr_err("%s: audio_client is null\n", __func__);
  720. ret = -EINVAL;
  721. goto done;
  722. }
  723. memcpy(&param_length, ucontrol->value.bytes.data,
  724. sizeof(param_length));
  725. if ((param_length + sizeof(param_length))
  726. >= sizeof(ucontrol->value.bytes.data)) {
  727. pr_err("%s param length=%d exceeds limit",
  728. __func__, param_length);
  729. ret = -EINVAL;
  730. goto done;
  731. }
  732. ret = q6asm_send_rtic_event_ack(prtd->audio_client,
  733. ucontrol->value.bytes.data + sizeof(param_length),
  734. param_length);
  735. if (ret < 0)
  736. pr_err("%s: failed to send rtic event ack, err = %d\n",
  737. __func__, ret);
  738. done:
  739. return ret;
  740. }
  741. static int msm_transcode_playback_app_type_cfg_put(
  742. struct snd_kcontrol *kcontrol,
  743. struct snd_ctl_elem_value *ucontrol)
  744. {
  745. u64 fe_id = kcontrol->private_value;
  746. int session_type = SESSION_TYPE_RX;
  747. int be_id = ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID];
  748. struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
  749. int ret = 0;
  750. cfg_data.app_type = ucontrol->value.integer.value[
  751. APP_TYPE_CONFIG_IDX_APP_TYPE];
  752. cfg_data.acdb_dev_id = ucontrol->value.integer.value[
  753. APP_TYPE_CONFIG_IDX_ACDB_ID];
  754. if (ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] != 0)
  755. cfg_data.sample_rate = ucontrol->value.integer.value[
  756. APP_TYPE_CONFIG_IDX_SAMPLE_RATE];
  757. pr_debug("%s: fe_id %llu session_type %d be_id %d app_type %d acdb_dev_id %d sample_rate- %d\n",
  758. __func__, fe_id, session_type, be_id,
  759. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  760. ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
  761. be_id, &cfg_data);
  762. if (ret < 0)
  763. pr_err("%s: msm_transcode_playback_stream_app_type_cfg set failed returned %d\n",
  764. __func__, ret);
  765. return ret;
  766. }
  767. static int msm_transcode_playback_app_type_cfg_get(
  768. struct snd_kcontrol *kcontrol,
  769. struct snd_ctl_elem_value *ucontrol)
  770. {
  771. u64 fe_id = kcontrol->private_value;
  772. int session_type = SESSION_TYPE_RX;
  773. int be_id = 0;
  774. struct msm_pcm_stream_app_type_cfg cfg_data = {0};
  775. int ret = 0;
  776. ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
  777. &be_id, &cfg_data);
  778. if (ret < 0) {
  779. pr_err("%s: msm_transcode_playback_stream_app_type_cfg get failed returned %d\n",
  780. __func__, ret);
  781. goto done;
  782. }
  783. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_APP_TYPE] =
  784. cfg_data.app_type;
  785. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_ACDB_ID] =
  786. cfg_data.acdb_dev_id;
  787. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] =
  788. cfg_data.sample_rate;
  789. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID] = be_id;
  790. pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
  791. __func__, fe_id, session_type, be_id,
  792. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  793. done:
  794. return ret;
  795. }
  796. static int msm_transcode_capture_app_type_cfg_put(
  797. struct snd_kcontrol *kcontrol,
  798. struct snd_ctl_elem_value *ucontrol)
  799. {
  800. u64 fe_id = kcontrol->private_value;
  801. int session_type = SESSION_TYPE_TX;
  802. int be_id = ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID];
  803. struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
  804. int ret = 0;
  805. cfg_data.app_type = ucontrol->value.integer.value[
  806. APP_TYPE_CONFIG_IDX_APP_TYPE];
  807. cfg_data.acdb_dev_id = ucontrol->value.integer.value[
  808. APP_TYPE_CONFIG_IDX_ACDB_ID];
  809. if (ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] != 0)
  810. cfg_data.sample_rate = ucontrol->value.integer.value[
  811. APP_TYPE_CONFIG_IDX_SAMPLE_RATE];
  812. pr_debug("%s: fe_id %llu session_type %d be_id %d app_type %d acdb_dev_id %d sample_rate- %d\n",
  813. __func__, fe_id, session_type, be_id,
  814. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  815. ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
  816. be_id, &cfg_data);
  817. if (ret < 0)
  818. pr_err("%s: register stream app type cfg failed, returned %d\n",
  819. __func__, ret);
  820. return ret;
  821. }
  822. static int msm_transcode_capture_app_type_cfg_get(
  823. struct snd_kcontrol *kcontrol,
  824. struct snd_ctl_elem_value *ucontrol)
  825. {
  826. u64 fe_id = kcontrol->private_value;
  827. int session_type = SESSION_TYPE_TX;
  828. int be_id = 0;
  829. struct msm_pcm_stream_app_type_cfg cfg_data = {0};
  830. int ret = 0;
  831. ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
  832. &be_id, &cfg_data);
  833. if (ret < 0) {
  834. pr_err("%s: get stream app type cfg failed, returned %d\n",
  835. __func__, ret);
  836. goto done;
  837. }
  838. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_APP_TYPE] =
  839. cfg_data.app_type;
  840. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_ACDB_ID] =
  841. cfg_data.acdb_dev_id;
  842. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] =
  843. cfg_data.sample_rate;
  844. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID] = be_id;
  845. pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
  846. __func__, fe_id, session_type, be_id,
  847. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  848. done:
  849. return ret;
  850. }
  851. static int msm_transcode_set_volume(struct snd_compr_stream *cstream,
  852. uint32_t master_gain)
  853. {
  854. int rc = 0;
  855. struct msm_transcode_loopback *prtd;
  856. struct snd_soc_pcm_runtime *rtd;
  857. pr_debug("%s: master_gain %d\n", __func__, master_gain);
  858. if (!cstream || !cstream->runtime) {
  859. pr_err("%s: session not active\n", __func__);
  860. return -EINVAL;
  861. }
  862. rtd = cstream->private_data;
  863. prtd = cstream->runtime->private_data;
  864. if (!rtd || !prtd || !prtd->audio_client) {
  865. pr_err("%s: invalid rtd, prtd or audio client", __func__);
  866. return -EINVAL;
  867. }
  868. rc = q6asm_set_volume(prtd->audio_client, master_gain);
  869. if (rc < 0)
  870. pr_err("%s: Send vol gain command failed rc=%d\n",
  871. __func__, rc);
  872. return rc;
  873. }
  874. static int msm_transcode_volume_put(struct snd_kcontrol *kcontrol,
  875. struct snd_ctl_elem_value *ucontrol)
  876. {
  877. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  878. unsigned long fe_id = kcontrol->private_value;
  879. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  880. snd_soc_component_get_drvdata(comp);
  881. struct snd_compr_stream *cstream = NULL;
  882. uint32_t ret = 0;
  883. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  884. pr_err("%s Received out of bounds fe_id %lu\n",
  885. __func__, fe_id);
  886. return -EINVAL;
  887. }
  888. cstream = pdata->cstream[fe_id];
  889. pdata->master_gain = ucontrol->value.integer.value[0];
  890. pr_debug("%s: fe_id %lu master_gain %d\n",
  891. __func__, fe_id, pdata->master_gain);
  892. if (cstream)
  893. ret = msm_transcode_set_volume(cstream, pdata->master_gain);
  894. return ret;
  895. }
  896. static int msm_transcode_volume_get(struct snd_kcontrol *kcontrol,
  897. struct snd_ctl_elem_value *ucontrol)
  898. {
  899. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  900. unsigned long fe_id = kcontrol->private_value;
  901. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  902. snd_soc_component_get_drvdata(comp);
  903. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  904. pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
  905. return -EINVAL;
  906. }
  907. pr_debug("%s: fe_id %lu\n", __func__, fe_id);
  908. ucontrol->value.integer.value[0] = pdata->master_gain;
  909. return 0;
  910. }
  911. static int msm_transcode_audio_effects_config_info(struct snd_kcontrol *kcontrol,
  912. struct snd_ctl_elem_info *uinfo)
  913. {
  914. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  915. uinfo->count = MAX_PP_PARAMS_SZ;
  916. uinfo->value.integer.min = 0;
  917. uinfo->value.integer.max = 0xFFFFFFFF;
  918. return 0;
  919. }
  920. static int msm_transcode_audio_effects_config_get(struct snd_kcontrol *kcontrol,
  921. struct snd_ctl_elem_value *ucontrol)
  922. {
  923. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  924. unsigned long fe_id = kcontrol->private_value;
  925. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  926. snd_soc_component_get_drvdata(comp);
  927. struct msm_transcode_audio_effects *audio_effects = NULL;
  928. struct snd_compr_stream *cstream = NULL;
  929. pr_debug("%s: fe_id: %lu\n", __func__, fe_id);
  930. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  931. pr_err("%s Received out of bounds fe_id %lu\n",
  932. __func__, fe_id);
  933. return -EINVAL;
  934. }
  935. cstream = pdata->cstream[fe_id];
  936. audio_effects = pdata->audio_effects[fe_id];
  937. if (!cstream || !audio_effects) {
  938. pr_err("%s: stream or effects inactive\n", __func__);
  939. return -EINVAL;
  940. }
  941. return 0;
  942. }
  943. static int msm_transcode_audio_effects_config_put(struct snd_kcontrol *kcontrol,
  944. struct snd_ctl_elem_value *ucontrol)
  945. {
  946. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  947. unsigned long fe_id = kcontrol->private_value;
  948. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  949. snd_soc_component_get_drvdata(comp);
  950. struct msm_transcode_audio_effects *audio_effects = NULL;
  951. struct snd_compr_stream *cstream = NULL;
  952. struct msm_transcode_loopback *prtd = NULL;
  953. long *values = &(ucontrol->value.integer.value[0]);
  954. int effects_module;
  955. int ret = 0;
  956. pr_debug("%s: fe_id: %lu\n", __func__, fe_id);
  957. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  958. pr_err("%s Received out of bounds fe_id %lu\n",
  959. __func__, fe_id);
  960. ret = -EINVAL;
  961. goto exit;
  962. }
  963. cstream = pdata->cstream[fe_id];
  964. audio_effects = pdata->audio_effects[fe_id];
  965. if (!cstream || !audio_effects) {
  966. pr_err("%s: stream or effects inactive\n", __func__);
  967. ret = -EINVAL;
  968. goto exit;
  969. }
  970. prtd = cstream->runtime->private_data;
  971. if (!prtd) {
  972. pr_err("%s: cannot set audio effects\n", __func__);
  973. ret = -EINVAL;
  974. goto exit;
  975. }
  976. effects_module = *values++;
  977. switch (effects_module) {
  978. case VIRTUALIZER_MODULE:
  979. pr_debug("%s: VIRTUALIZER_MODULE\n", __func__);
  980. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  981. prtd->audio_client->topology))
  982. ret = msm_audio_effects_virtualizer_handler(
  983. prtd->audio_client,
  984. &(audio_effects->virtualizer),
  985. values);
  986. break;
  987. case REVERB_MODULE:
  988. pr_debug("%s: REVERB_MODULE\n", __func__);
  989. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  990. prtd->audio_client->topology))
  991. ret = msm_audio_effects_reverb_handler(prtd->audio_client,
  992. &(audio_effects->reverb),
  993. values);
  994. break;
  995. case BASS_BOOST_MODULE:
  996. pr_debug("%s: BASS_BOOST_MODULE\n", __func__);
  997. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  998. prtd->audio_client->topology))
  999. ret = msm_audio_effects_bass_boost_handler(prtd->audio_client,
  1000. &(audio_effects->bass_boost),
  1001. values);
  1002. break;
  1003. case PBE_MODULE:
  1004. pr_debug("%s: PBE_MODULE\n", __func__);
  1005. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1006. prtd->audio_client->topology))
  1007. ret = msm_audio_effects_pbe_handler(prtd->audio_client,
  1008. &(audio_effects->pbe),
  1009. values);
  1010. break;
  1011. case EQ_MODULE:
  1012. pr_debug("%s: EQ_MODULE\n", __func__);
  1013. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1014. prtd->audio_client->topology))
  1015. ret = msm_audio_effects_popless_eq_handler(prtd->audio_client,
  1016. &(audio_effects->equalizer),
  1017. values);
  1018. break;
  1019. case SOFT_VOLUME_MODULE:
  1020. pr_debug("%s: SOFT_VOLUME_MODULE\n", __func__);
  1021. break;
  1022. case SOFT_VOLUME2_MODULE:
  1023. pr_debug("%s: SOFT_VOLUME2_MODULE\n", __func__);
  1024. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1025. prtd->audio_client->topology))
  1026. ret = msm_audio_effects_volume_handler_v2(prtd->audio_client,
  1027. &(audio_effects->volume),
  1028. values, SOFT_VOLUME_INSTANCE_2);
  1029. break;
  1030. default:
  1031. pr_err("%s Invalid effects config module\n", __func__);
  1032. ret = -EINVAL;
  1033. }
  1034. exit:
  1035. return ret;
  1036. }
  1037. static int msm_transcode_add_audio_effects_control(struct snd_soc_pcm_runtime *rtd)
  1038. {
  1039. struct snd_soc_component *component = NULL;
  1040. const char *mixer_ctl_name = "Audio Effects Config";
  1041. const char *deviceNo = "NN";
  1042. char *mixer_str = NULL;
  1043. int ctl_len = 0;
  1044. int ret = 0;
  1045. struct snd_kcontrol_new fe_audio_effects_config_control[1] = {
  1046. {
  1047. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1048. .name = "?",
  1049. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1050. .info = msm_transcode_audio_effects_config_info,
  1051. .get = msm_transcode_audio_effects_config_get,
  1052. .put = msm_transcode_audio_effects_config_put,
  1053. .private_value = 0,
  1054. }
  1055. };
  1056. if (!rtd) {
  1057. pr_err("%s NULL rtd\n", __func__);
  1058. ret = -EINVAL;
  1059. goto done;
  1060. }
  1061. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1062. if (!component) {
  1063. pr_err("%s: component is NULL\n", __func__);
  1064. return -EINVAL;
  1065. }
  1066. pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n", __func__,
  1067. rtd->dai_link->name, rtd->dai_link->id,
  1068. rtd->dai_link->cpu_dai_name, rtd->pcm->device);
  1069. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1070. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1071. if (!mixer_str) {
  1072. ret = -ENOMEM;
  1073. goto done;
  1074. }
  1075. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1076. fe_audio_effects_config_control[0].name = mixer_str;
  1077. fe_audio_effects_config_control[0].private_value = rtd->dai_link->id;
  1078. ret = snd_soc_add_component_controls(component,
  1079. fe_audio_effects_config_control,
  1080. ARRAY_SIZE(fe_audio_effects_config_control));
  1081. if (ret < 0)
  1082. pr_err("%s: failed to add ctl %s. err = %d\n", __func__, mixer_str, ret);
  1083. kfree(mixer_str);
  1084. done:
  1085. return ret;
  1086. }
  1087. static int msm_transcode_stream_cmd_control(
  1088. struct snd_soc_pcm_runtime *rtd)
  1089. {
  1090. struct snd_soc_component *component = NULL;
  1091. const char *mixer_ctl_name = DSP_STREAM_CMD;
  1092. const char *deviceNo = "NN";
  1093. char *mixer_str = NULL;
  1094. int ctl_len = 0, ret = 0;
  1095. struct snd_kcontrol_new fe_loopback_stream_cmd_config_control[1] = {
  1096. {
  1097. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1098. .name = "?",
  1099. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1100. .info = msm_adsp_stream_cmd_info,
  1101. .put = msm_transcode_stream_cmd_put,
  1102. .private_value = 0,
  1103. }
  1104. };
  1105. if (!rtd) {
  1106. pr_err("%s NULL rtd\n", __func__);
  1107. ret = -EINVAL;
  1108. goto done;
  1109. }
  1110. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1111. if (!component) {
  1112. pr_err("%s: component is NULL\n", __func__);
  1113. return -EINVAL;
  1114. }
  1115. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1116. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1117. if (!mixer_str) {
  1118. ret = -ENOMEM;
  1119. goto done;
  1120. }
  1121. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1122. fe_loopback_stream_cmd_config_control[0].name = mixer_str;
  1123. fe_loopback_stream_cmd_config_control[0].private_value =
  1124. rtd->dai_link->id;
  1125. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1126. ret = snd_soc_add_component_controls(component,
  1127. fe_loopback_stream_cmd_config_control,
  1128. ARRAY_SIZE(fe_loopback_stream_cmd_config_control));
  1129. if (ret < 0)
  1130. pr_err("%s: failed to add ctl %s. err = %d\n",
  1131. __func__, mixer_str, ret);
  1132. kfree(mixer_str);
  1133. done:
  1134. return ret;
  1135. }
  1136. static int msm_transcode_stream_callback_control(
  1137. struct snd_soc_pcm_runtime *rtd)
  1138. {
  1139. struct snd_soc_component *component = NULL;
  1140. const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
  1141. const char *deviceNo = "NN";
  1142. char *mixer_str = NULL;
  1143. int ctl_len = 0, ret = 0;
  1144. struct snd_kcontrol *kctl;
  1145. struct snd_kcontrol_new fe_loopback_callback_config_control[1] = {
  1146. {
  1147. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1148. .name = "?",
  1149. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1150. .info = msm_adsp_stream_callback_info,
  1151. .get = msm_adsp_stream_callback_get,
  1152. .private_value = 0,
  1153. }
  1154. };
  1155. if (!rtd) {
  1156. pr_err("%s: rtd is NULL\n", __func__);
  1157. ret = -EINVAL;
  1158. goto done;
  1159. }
  1160. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1161. if (!component) {
  1162. pr_err("%s: component is NULL\n", __func__);
  1163. return -EINVAL;
  1164. }
  1165. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1166. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1167. if (!mixer_str) {
  1168. ret = -ENOMEM;
  1169. goto done;
  1170. }
  1171. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1172. fe_loopback_callback_config_control[0].name = mixer_str;
  1173. fe_loopback_callback_config_control[0].private_value =
  1174. rtd->dai_link->id;
  1175. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1176. ret = snd_soc_add_component_controls(component,
  1177. fe_loopback_callback_config_control,
  1178. ARRAY_SIZE(fe_loopback_callback_config_control));
  1179. if (ret < 0) {
  1180. pr_err("%s: failed to add ctl %s. err = %d\n",
  1181. __func__, mixer_str, ret);
  1182. ret = -EINVAL;
  1183. goto free_mixer_str;
  1184. }
  1185. kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
  1186. if (!kctl) {
  1187. pr_err("%s: failed to get kctl %s.\n", __func__, mixer_str);
  1188. ret = -EINVAL;
  1189. goto free_mixer_str;
  1190. }
  1191. kctl->private_data = NULL;
  1192. free_mixer_str:
  1193. kfree(mixer_str);
  1194. done:
  1195. return ret;
  1196. }
  1197. static int msm_transcode_add_ion_fd_cmd_control(struct snd_soc_pcm_runtime *rtd)
  1198. {
  1199. struct snd_soc_component *component = NULL;
  1200. const char *mixer_ctl_name = "Playback ION FD";
  1201. const char *deviceNo = "NN";
  1202. char *mixer_str = NULL;
  1203. int ctl_len = 0, ret = 0;
  1204. struct snd_kcontrol_new fe_ion_fd_config_control[1] = {
  1205. {
  1206. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1207. .name = "?",
  1208. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1209. .info = msm_adsp_stream_cmd_info,
  1210. .put = msm_transcode_ion_fd_map_put,
  1211. .private_value = 0,
  1212. }
  1213. };
  1214. if (!rtd) {
  1215. pr_err("%s NULL rtd\n", __func__);
  1216. ret = -EINVAL;
  1217. goto done;
  1218. }
  1219. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1220. if (!component) {
  1221. pr_err("%s: component is NULL\n", __func__);
  1222. return -EINVAL;
  1223. }
  1224. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1225. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1226. if (!mixer_str) {
  1227. ret = -ENOMEM;
  1228. goto done;
  1229. }
  1230. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1231. fe_ion_fd_config_control[0].name = mixer_str;
  1232. fe_ion_fd_config_control[0].private_value = rtd->dai_link->id;
  1233. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1234. ret = snd_soc_add_component_controls(component,
  1235. fe_ion_fd_config_control,
  1236. ARRAY_SIZE(fe_ion_fd_config_control));
  1237. if (ret < 0)
  1238. pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
  1239. kfree(mixer_str);
  1240. done:
  1241. return ret;
  1242. }
  1243. static int msm_transcode_add_event_ack_cmd_control(
  1244. struct snd_soc_pcm_runtime *rtd)
  1245. {
  1246. struct snd_soc_component *component = NULL;
  1247. const char *mixer_ctl_name = "Playback Event Ack";
  1248. const char *deviceNo = "NN";
  1249. char *mixer_str = NULL;
  1250. int ctl_len = 0, ret = 0;
  1251. struct snd_kcontrol_new fe_event_ack_config_control[1] = {
  1252. {
  1253. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1254. .name = "?",
  1255. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1256. .info = msm_adsp_stream_cmd_info,
  1257. .put = msm_transcode_rtic_event_ack_put,
  1258. .private_value = 0,
  1259. }
  1260. };
  1261. if (!rtd) {
  1262. pr_err("%s NULL rtd\n", __func__);
  1263. ret = -EINVAL;
  1264. goto done;
  1265. }
  1266. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1267. if (!component) {
  1268. pr_err("%s: component is NULL\n", __func__);
  1269. return -EINVAL;
  1270. }
  1271. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1272. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1273. if (!mixer_str) {
  1274. ret = -ENOMEM;
  1275. goto done;
  1276. }
  1277. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1278. fe_event_ack_config_control[0].name = mixer_str;
  1279. fe_event_ack_config_control[0].private_value = rtd->dai_link->id;
  1280. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1281. ret = snd_soc_add_component_controls(component,
  1282. fe_event_ack_config_control,
  1283. ARRAY_SIZE(fe_event_ack_config_control));
  1284. if (ret < 0)
  1285. pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
  1286. kfree(mixer_str);
  1287. done:
  1288. return ret;
  1289. }
  1290. static int msm_transcode_app_type_cfg_info(struct snd_kcontrol *kcontrol,
  1291. struct snd_ctl_elem_info *uinfo)
  1292. {
  1293. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1294. uinfo->count = 5;
  1295. uinfo->value.integer.min = 0;
  1296. uinfo->value.integer.max = 0xFFFFFFFF;
  1297. return 0;
  1298. }
  1299. static int msm_transcode_add_app_type_cfg_control(
  1300. struct snd_soc_pcm_runtime *rtd)
  1301. {
  1302. struct snd_soc_component *component = NULL;
  1303. char mixer_str[128];
  1304. struct snd_kcontrol_new fe_app_type_cfg_control[1] = {
  1305. {
  1306. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1307. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1308. .info = msm_transcode_app_type_cfg_info,
  1309. .private_value = 0,
  1310. }
  1311. };
  1312. if (!rtd) {
  1313. pr_err("%s NULL rtd\n", __func__);
  1314. return -EINVAL;
  1315. }
  1316. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1317. if (!component) {
  1318. pr_err("%s: component is NULL\n", __func__);
  1319. return -EINVAL;
  1320. }
  1321. if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
  1322. snprintf(mixer_str, sizeof(mixer_str),
  1323. "Audio Stream %d App Type Cfg",
  1324. rtd->pcm->device);
  1325. fe_app_type_cfg_control[0].name = mixer_str;
  1326. fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
  1327. fe_app_type_cfg_control[0].put =
  1328. msm_transcode_playback_app_type_cfg_put;
  1329. fe_app_type_cfg_control[0].get =
  1330. msm_transcode_playback_app_type_cfg_get;
  1331. pr_debug("Registering new mixer ctl %s", mixer_str);
  1332. snd_soc_add_component_controls(component,
  1333. fe_app_type_cfg_control,
  1334. ARRAY_SIZE(fe_app_type_cfg_control));
  1335. } else if (rtd->compr->direction == SND_COMPRESS_CAPTURE) {
  1336. snprintf(mixer_str, sizeof(mixer_str),
  1337. "Audio Stream Capture %d App Type Cfg",
  1338. rtd->pcm->device);
  1339. fe_app_type_cfg_control[0].name = mixer_str;
  1340. fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
  1341. fe_app_type_cfg_control[0].put =
  1342. msm_transcode_capture_app_type_cfg_put;
  1343. fe_app_type_cfg_control[0].get =
  1344. msm_transcode_capture_app_type_cfg_get;
  1345. pr_debug("Registering new mixer ctl %s", mixer_str);
  1346. snd_soc_add_component_controls(component,
  1347. fe_app_type_cfg_control,
  1348. ARRAY_SIZE(fe_app_type_cfg_control));
  1349. }
  1350. return 0;
  1351. }
  1352. static int msm_transcode_volume_info(struct snd_kcontrol *kcontrol,
  1353. struct snd_ctl_elem_info *uinfo)
  1354. {
  1355. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1356. uinfo->count = 1;
  1357. uinfo->value.integer.min = 0;
  1358. uinfo->value.integer.max = TRANSCODE_LR_VOL_MAX_DB;
  1359. return 0;
  1360. }
  1361. static int msm_transcode_add_volume_control(struct snd_soc_pcm_runtime *rtd)
  1362. {
  1363. struct snd_soc_component *component = NULL;
  1364. struct snd_kcontrol_new fe_volume_control[1] = {
  1365. {
  1366. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1367. .name = "Transcode Loopback Rx Volume",
  1368. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  1369. SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1370. .info = msm_transcode_volume_info,
  1371. .get = msm_transcode_volume_get,
  1372. .put = msm_transcode_volume_put,
  1373. .private_value = 0,
  1374. }
  1375. };
  1376. if (!rtd) {
  1377. pr_err("%s NULL rtd\n", __func__);
  1378. return -EINVAL;
  1379. }
  1380. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1381. if (!component) {
  1382. pr_err("%s: component is NULL\n", __func__);
  1383. return -EINVAL;
  1384. }
  1385. if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
  1386. fe_volume_control[0].private_value = rtd->dai_link->id;
  1387. pr_debug("Registering new mixer ctl %s",
  1388. fe_volume_control[0].name);
  1389. snd_soc_add_component_controls(component, fe_volume_control,
  1390. ARRAY_SIZE(fe_volume_control));
  1391. }
  1392. return 0;
  1393. }
  1394. static int msm_transcode_loopback_new(struct snd_soc_pcm_runtime *rtd)
  1395. {
  1396. int rc;
  1397. rc = msm_transcode_add_audio_effects_control(rtd);
  1398. if (rc)
  1399. pr_err("%s: Could not add Compr Audio Effects Control\n",
  1400. __func__);
  1401. rc = msm_transcode_stream_cmd_control(rtd);
  1402. if (rc)
  1403. pr_err("%s: ADSP Stream Cmd Control open failed\n", __func__);
  1404. rc = msm_transcode_stream_callback_control(rtd);
  1405. if (rc)
  1406. pr_err("%s: ADSP Stream callback Control open failed\n",
  1407. __func__);
  1408. rc = msm_transcode_add_ion_fd_cmd_control(rtd);
  1409. if (rc)
  1410. pr_err("%s: Could not add transcode ion fd Control\n",
  1411. __func__);
  1412. rc = msm_transcode_add_event_ack_cmd_control(rtd);
  1413. if (rc)
  1414. pr_err("%s: Could not add transcode event ack Control\n",
  1415. __func__);
  1416. rc = msm_transcode_add_app_type_cfg_control(rtd);
  1417. if (rc)
  1418. pr_err("%s: Could not add Compr App Type Cfg Control\n",
  1419. __func__);
  1420. rc = msm_transcode_add_volume_control(rtd);
  1421. if (rc)
  1422. pr_err("%s: Could not add transcode volume Control\n",
  1423. __func__);
  1424. return 0;
  1425. }
  1426. static struct snd_compr_ops msm_transcode_loopback_ops = {
  1427. .open = msm_transcode_loopback_open,
  1428. .free = msm_transcode_loopback_free,
  1429. .trigger = msm_transcode_loopback_trigger,
  1430. .set_params = msm_transcode_loopback_set_params,
  1431. .get_caps = msm_transcode_loopback_get_caps,
  1432. .set_metadata = msm_transcode_loopback_set_metadata,
  1433. };
  1434. static int msm_transcode_loopback_probe(struct snd_soc_component *component)
  1435. {
  1436. struct trans_loopback_pdata *pdata = NULL;
  1437. int i;
  1438. pr_debug("%s\n", __func__);
  1439. pdata = (struct trans_loopback_pdata *)
  1440. kzalloc(sizeof(struct trans_loopback_pdata),
  1441. GFP_KERNEL);
  1442. if (!pdata)
  1443. return -ENOMEM;
  1444. for (i = 0; i < MSM_FRONTEND_DAI_MAX; i++) {
  1445. pdata->audio_effects[i] = NULL;
  1446. pdata->perf_mode[i] = LOW_LATENCY_PCM_MODE;
  1447. }
  1448. snd_soc_component_set_drvdata(component, pdata);
  1449. return 0;
  1450. }
  1451. static void msm_transcode_loopback_remove(struct snd_soc_component *component)
  1452. {
  1453. struct trans_loopback_pdata *pdata = NULL;
  1454. pdata = (struct trans_loopback_pdata *)
  1455. snd_soc_component_get_drvdata(component);
  1456. kfree(pdata);
  1457. return;
  1458. }
  1459. static struct snd_soc_component_driver msm_soc_component = {
  1460. .name = DRV_NAME,
  1461. .probe = msm_transcode_loopback_probe,
  1462. .compr_ops = &msm_transcode_loopback_ops,
  1463. .pcm_new = msm_transcode_loopback_new,
  1464. .remove = msm_transcode_loopback_remove,
  1465. };
  1466. static int msm_transcode_dev_probe(struct platform_device *pdev)
  1467. {
  1468. pr_debug("%s: dev name %s\n", __func__, dev_name(&pdev->dev));
  1469. return snd_soc_register_component(&pdev->dev,
  1470. &msm_soc_component,
  1471. NULL, 0);
  1472. }
  1473. static int msm_transcode_remove(struct platform_device *pdev)
  1474. {
  1475. snd_soc_unregister_component(&pdev->dev);
  1476. return 0;
  1477. }
  1478. static const struct of_device_id msm_transcode_loopback_dt_match[] = {
  1479. {.compatible = "qcom,msm-transcode-loopback"},
  1480. {}
  1481. };
  1482. MODULE_DEVICE_TABLE(of, msm_transcode_loopback_dt_match);
  1483. static struct platform_driver msm_transcode_loopback_driver = {
  1484. .driver = {
  1485. .name = "msm-transcode-loopback",
  1486. .owner = THIS_MODULE,
  1487. .of_match_table = msm_transcode_loopback_dt_match,
  1488. .suppress_bind_attrs = true,
  1489. },
  1490. .probe = msm_transcode_dev_probe,
  1491. .remove = msm_transcode_remove,
  1492. };
  1493. int __init msm_transcode_loopback_init(void)
  1494. {
  1495. memset(&transcode_info, 0, sizeof(struct msm_transcode_loopback));
  1496. mutex_init(&transcode_info.lock);
  1497. return platform_driver_register(&msm_transcode_loopback_driver);
  1498. }
  1499. void msm_transcode_loopback_exit(void)
  1500. {
  1501. mutex_destroy(&transcode_info.lock);
  1502. platform_driver_unregister(&msm_transcode_loopback_driver);
  1503. }
  1504. MODULE_DESCRIPTION("Transcode loopback platform driver");
  1505. MODULE_LICENSE("GPL v2");