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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2017-2020, 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 <audio/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. enum apr_subsys_state subsys_state;
  370. if (trans == NULL) {
  371. pr_err("%s: Invalid param\n", __func__);
  372. return -EINVAL;
  373. }
  374. subsys_state = apr_get_subsys_state();
  375. if (subsys_state == APR_SUBSYS_DOWN) {
  376. pr_debug("%s: adsp is down\n", __func__);
  377. return -ENETRESET;
  378. }
  379. mutex_lock(&trans->lock);
  380. rtd = snd_pcm_substream_chip(cstream);
  381. if (!rtd) {
  382. pr_err("%s: rtd is NULL\n", __func__);
  383. return -EINVAL;
  384. }
  385. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  386. if (!component) {
  387. pr_err("%s: component is NULL\n", __func__);
  388. return -EINVAL;
  389. }
  390. pdata = snd_soc_component_get_drvdata(component);
  391. if (cstream->direction == SND_COMPRESS_PLAYBACK) {
  392. if (codec_param->codec.id == SND_AUDIOCODEC_PCM) {
  393. trans->sink.codec_format =
  394. FORMAT_LINEAR_PCM;
  395. switch (codec_param->codec.format) {
  396. case SNDRV_PCM_FORMAT_S32_LE:
  397. bit_width = 32;
  398. break;
  399. case SNDRV_PCM_FORMAT_S24_LE:
  400. bit_width = 24;
  401. break;
  402. case SNDRV_PCM_FORMAT_S24_3LE:
  403. bit_width = 24;
  404. break;
  405. case SNDRV_PCM_FORMAT_S16_LE:
  406. default:
  407. bit_width = 16;
  408. break;
  409. }
  410. } else {
  411. pr_debug("%s: unknown sink codec\n", __func__);
  412. ret = -EINVAL;
  413. goto exit;
  414. }
  415. trans->sink.start = true;
  416. trans->sink.perf_mode = pdata->perf_mode[rtd->dai_link->id];
  417. }
  418. if (cstream->direction == SND_COMPRESS_CAPTURE) {
  419. switch (codec_param->codec.id) {
  420. case SND_AUDIOCODEC_PCM:
  421. pr_debug("Source SND_AUDIOCODEC_PCM\n");
  422. trans->source.codec_format =
  423. FORMAT_LINEAR_PCM;
  424. break;
  425. case SND_AUDIOCODEC_AC3:
  426. pr_debug("Source SND_AUDIOCODEC_AC3\n");
  427. trans->source.codec_format =
  428. FORMAT_AC3;
  429. break;
  430. case SND_AUDIOCODEC_EAC3:
  431. pr_debug("Source SND_AUDIOCODEC_EAC3\n");
  432. trans->source.codec_format =
  433. FORMAT_EAC3;
  434. break;
  435. case SND_AUDIOCODEC_TRUEHD:
  436. pr_debug("Source SND_AUDIOCODEC_TRUEHD\n");
  437. trans->source.codec_format =
  438. FORMAT_TRUEHD;
  439. break;
  440. default:
  441. pr_debug("%s: unknown source codec\n", __func__);
  442. ret = -EINVAL;
  443. goto exit;
  444. }
  445. trans->source.start = true;
  446. trans->source.perf_mode = pdata->perf_mode[rtd->dai_link->id];
  447. }
  448. pr_debug("%s: trans->source.start %d trans->sink.start %d trans->source.cstream %pK trans->sink.cstream %pK trans->session_state %d\n",
  449. __func__, trans->source.start, trans->sink.start,
  450. trans->source.cstream, trans->sink.cstream,
  451. trans->session_state);
  452. if ((trans->session_state == LOOPBACK_SESSION_READY) &&
  453. trans->source.start && trans->sink.start) {
  454. pr_debug("%s: Moving loopback session to start state\n",
  455. __func__);
  456. trans->session_state = LOOPBACK_SESSION_START;
  457. }
  458. if (trans->session_state == LOOPBACK_SESSION_START) {
  459. if (trans->audio_client != NULL) {
  460. pr_debug("%s: ASM client already opened, closing\n",
  461. __func__);
  462. stop_transcoding(trans);
  463. }
  464. trans->audio_client = q6asm_audio_client_alloc(
  465. (app_cb)loopback_event_handler, trans);
  466. if (!trans->audio_client) {
  467. pr_err("%s: Could not allocate memory\n", __func__);
  468. ret = -EINVAL;
  469. goto exit;
  470. }
  471. pr_debug("%s: ASM client allocated, callback %pK\n", __func__,
  472. loopback_event_handler);
  473. trans->session_id = trans->audio_client->session;
  474. trans->audio_client->perf_mode = trans->sink.perf_mode;
  475. ret = q6asm_open_transcode_loopback(trans->audio_client,
  476. bit_width,
  477. trans->source.codec_format,
  478. trans->sink.codec_format);
  479. if (ret < 0) {
  480. pr_err("%s: Session transcode loopback open failed\n",
  481. __func__);
  482. q6asm_audio_client_free(trans->audio_client);
  483. trans->audio_client = NULL;
  484. goto exit;
  485. }
  486. pr_debug("%s: Starting ADM open for loopback\n", __func__);
  487. soc_pcm_rx = trans->sink.cstream->private_data;
  488. soc_pcm_tx = trans->source.cstream->private_data;
  489. if (trans->source.codec_format != FORMAT_LINEAR_PCM)
  490. msm_pcm_routing_reg_phy_compr_stream(
  491. soc_pcm_tx->dai_link->id,
  492. LEGACY_PCM_MODE,
  493. trans->session_id,
  494. SNDRV_PCM_STREAM_CAPTURE,
  495. COMPRESSED_PASSTHROUGH_GEN);
  496. else
  497. msm_pcm_routing_reg_phy_stream(
  498. soc_pcm_tx->dai_link->id,
  499. trans->source.perf_mode,
  500. trans->session_id,
  501. SNDRV_PCM_STREAM_CAPTURE);
  502. /* Opening Rx ADM in LOW_LATENCY mode by default */
  503. msm_pcm_routing_reg_phy_stream(
  504. soc_pcm_rx->dai_link->id,
  505. trans->sink.perf_mode,
  506. trans->session_id,
  507. SNDRV_PCM_STREAM_PLAYBACK);
  508. pr_debug("%s: Successfully opened ADM sessions\n", __func__);
  509. }
  510. exit:
  511. mutex_unlock(&trans->lock);
  512. return ret;
  513. }
  514. static int msm_transcode_loopback_get_caps(struct snd_compr_stream *cstream,
  515. struct snd_compr_caps *arg)
  516. {
  517. struct snd_compr_runtime *runtime;
  518. struct msm_transcode_loopback *trans;
  519. if (!arg || !cstream) {
  520. pr_err("%s: Invalid arguments\n", __func__);
  521. return -EINVAL;
  522. }
  523. runtime = cstream->runtime;
  524. trans = runtime->private_data;
  525. pr_debug("%s\n", __func__);
  526. if (cstream->direction == SND_COMPRESS_CAPTURE)
  527. memcpy(arg, &trans->source_compr_cap,
  528. sizeof(struct snd_compr_caps));
  529. else
  530. memcpy(arg, &trans->sink_compr_cap,
  531. sizeof(struct snd_compr_caps));
  532. return 0;
  533. }
  534. static int msm_transcode_loopback_set_metadata(struct snd_compr_stream *cstream,
  535. struct snd_compr_metadata *metadata)
  536. {
  537. struct snd_soc_pcm_runtime *rtd;
  538. struct trans_loopback_pdata *pdata;
  539. struct msm_transcode_loopback *prtd = NULL;
  540. struct snd_soc_component *component;
  541. struct audio_client *ac = NULL;
  542. if (!metadata || !cstream) {
  543. pr_err("%s: Invalid arguments\n", __func__);
  544. return -EINVAL;
  545. }
  546. rtd = snd_pcm_substream_chip(cstream);
  547. if (!rtd) {
  548. pr_err("%s: rtd is NULL\n", __func__);
  549. return -EINVAL;
  550. }
  551. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  552. if (!component) {
  553. pr_err("%s: component is NULL\n", __func__);
  554. return -EINVAL;
  555. }
  556. pdata = snd_soc_component_get_drvdata(component);
  557. prtd = cstream->runtime->private_data;
  558. if (!prtd || !prtd->audio_client) {
  559. pr_err("%s: prtd or audio client is NULL\n", __func__);
  560. return -EINVAL;
  561. }
  562. ac = prtd->audio_client;
  563. switch (metadata->key) {
  564. case SNDRV_COMPRESS_LATENCY_MODE:
  565. {
  566. switch (metadata->value[0]) {
  567. case SNDRV_COMPRESS_LEGACY_LATENCY_MODE:
  568. pdata->perf_mode[rtd->dai_link->id] = LEGACY_PCM_MODE;
  569. break;
  570. case SNDRV_COMPRESS_LOW_LATENCY_MODE:
  571. pdata->perf_mode[rtd->dai_link->id] =
  572. LOW_LATENCY_PCM_MODE;
  573. break;
  574. default:
  575. pr_debug("%s: Unsupported latency mode %d, default to Legacy\n",
  576. __func__, metadata->value[0]);
  577. pdata->perf_mode[rtd->dai_link->id] = LEGACY_PCM_MODE;
  578. break;
  579. }
  580. break;
  581. }
  582. case SNDRV_COMPRESS_RENDER_WINDOW:
  583. {
  584. return msm_transcode_set_render_window(
  585. ac,
  586. metadata->value[0],
  587. metadata->value[1],
  588. metadata->value[2],
  589. metadata->value[3]);
  590. }
  591. default:
  592. pr_debug("%s: Unsupported metadata %d\n",
  593. __func__, metadata->key);
  594. break;
  595. }
  596. return 0;
  597. }
  598. static int msm_transcode_stream_cmd_put(struct snd_kcontrol *kcontrol,
  599. struct snd_ctl_elem_value *ucontrol)
  600. {
  601. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  602. unsigned long fe_id = kcontrol->private_value;
  603. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  604. snd_soc_component_get_drvdata(comp);
  605. struct snd_compr_stream *cstream = NULL;
  606. struct msm_transcode_loopback *prtd;
  607. int ret = 0;
  608. struct msm_adsp_event_data *event_data = NULL;
  609. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  610. pr_err("%s Received invalid fe_id %lu\n",
  611. __func__, fe_id);
  612. ret = -EINVAL;
  613. goto done;
  614. }
  615. cstream = pdata->cstream[fe_id];
  616. if (cstream == NULL) {
  617. pr_err("%s cstream is null.\n", __func__);
  618. ret = -EINVAL;
  619. goto done;
  620. }
  621. prtd = cstream->runtime->private_data;
  622. if (!prtd) {
  623. pr_err("%s: prtd is null.\n", __func__);
  624. ret = -EINVAL;
  625. goto done;
  626. }
  627. if (prtd->audio_client == NULL) {
  628. pr_err("%s: audio_client is null.\n", __func__);
  629. ret = -EINVAL;
  630. goto done;
  631. }
  632. event_data = (struct msm_adsp_event_data *)ucontrol->value.bytes.data;
  633. if ((event_data->event_type < ADSP_STREAM_PP_EVENT) ||
  634. (event_data->event_type >= ADSP_STREAM_EVENT_MAX)) {
  635. pr_err("%s: invalid event_type=%d",
  636. __func__, event_data->event_type);
  637. ret = -EINVAL;
  638. goto done;
  639. }
  640. if (event_data->payload_len > sizeof(ucontrol->value.bytes.data)
  641. - sizeof(struct msm_adsp_event_data)) {
  642. pr_err("%s param length=%d exceeds limit",
  643. __func__, event_data->payload_len);
  644. ret = -EINVAL;
  645. goto done;
  646. }
  647. ret = q6asm_send_stream_cmd(prtd->audio_client, event_data);
  648. if (ret < 0)
  649. pr_err("%s: failed to send stream event cmd, err = %d\n",
  650. __func__, ret);
  651. done:
  652. return ret;
  653. }
  654. static int msm_transcode_ion_fd_map_put(struct snd_kcontrol *kcontrol,
  655. struct snd_ctl_elem_value *ucontrol)
  656. {
  657. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  658. unsigned long fe_id = kcontrol->private_value;
  659. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  660. snd_soc_component_get_drvdata(comp);
  661. struct snd_compr_stream *cstream = NULL;
  662. struct msm_transcode_loopback *prtd;
  663. int fd;
  664. int ret = 0;
  665. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  666. pr_err("%s Received out of bounds invalid fe_id %lu\n",
  667. __func__, fe_id);
  668. ret = -EINVAL;
  669. goto done;
  670. }
  671. cstream = pdata->cstream[fe_id];
  672. if (cstream == NULL) {
  673. pr_err("%s cstream is null\n", __func__);
  674. ret = -EINVAL;
  675. goto done;
  676. }
  677. prtd = cstream->runtime->private_data;
  678. if (!prtd) {
  679. pr_err("%s: prtd is null\n", __func__);
  680. ret = -EINVAL;
  681. goto done;
  682. }
  683. if (prtd->audio_client == NULL) {
  684. pr_err("%s: audio_client is null\n", __func__);
  685. ret = -EINVAL;
  686. goto done;
  687. }
  688. memcpy(&fd, ucontrol->value.bytes.data, sizeof(fd));
  689. ret = q6asm_send_ion_fd(prtd->audio_client, fd);
  690. if (ret < 0)
  691. pr_err("%s: failed to register ion fd\n", __func__);
  692. done:
  693. return ret;
  694. }
  695. static int msm_transcode_rtic_event_ack_put(struct snd_kcontrol *kcontrol,
  696. struct snd_ctl_elem_value *ucontrol)
  697. {
  698. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  699. unsigned long fe_id = kcontrol->private_value;
  700. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  701. snd_soc_component_get_drvdata(comp);
  702. struct snd_compr_stream *cstream = NULL;
  703. struct msm_transcode_loopback *prtd;
  704. int ret = 0;
  705. int param_length = 0;
  706. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  707. pr_err("%s Received invalid fe_id %lu\n",
  708. __func__, fe_id);
  709. ret = -EINVAL;
  710. goto done;
  711. }
  712. cstream = pdata->cstream[fe_id];
  713. if (cstream == NULL) {
  714. pr_err("%s cstream is null\n", __func__);
  715. ret = -EINVAL;
  716. goto done;
  717. }
  718. prtd = cstream->runtime->private_data;
  719. if (!prtd) {
  720. pr_err("%s: prtd is null\n", __func__);
  721. ret = -EINVAL;
  722. goto done;
  723. }
  724. if (prtd->audio_client == NULL) {
  725. pr_err("%s: audio_client is null\n", __func__);
  726. ret = -EINVAL;
  727. goto done;
  728. }
  729. memcpy(&param_length, ucontrol->value.bytes.data,
  730. sizeof(param_length));
  731. if ((param_length + sizeof(param_length))
  732. >= sizeof(ucontrol->value.bytes.data)) {
  733. pr_err("%s param length=%d exceeds limit",
  734. __func__, param_length);
  735. ret = -EINVAL;
  736. goto done;
  737. }
  738. ret = q6asm_send_rtic_event_ack(prtd->audio_client,
  739. ucontrol->value.bytes.data + sizeof(param_length),
  740. param_length);
  741. if (ret < 0)
  742. pr_err("%s: failed to send rtic event ack, err = %d\n",
  743. __func__, ret);
  744. done:
  745. return ret;
  746. }
  747. static int msm_transcode_playback_app_type_cfg_put(
  748. struct snd_kcontrol *kcontrol,
  749. struct snd_ctl_elem_value *ucontrol)
  750. {
  751. u64 fe_id = kcontrol->private_value;
  752. int session_type = SESSION_TYPE_RX;
  753. int be_id = ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID];
  754. struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
  755. int ret = 0;
  756. cfg_data.app_type = ucontrol->value.integer.value[
  757. APP_TYPE_CONFIG_IDX_APP_TYPE];
  758. cfg_data.acdb_dev_id = ucontrol->value.integer.value[
  759. APP_TYPE_CONFIG_IDX_ACDB_ID];
  760. if (ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] != 0)
  761. cfg_data.sample_rate = ucontrol->value.integer.value[
  762. APP_TYPE_CONFIG_IDX_SAMPLE_RATE];
  763. pr_debug("%s: fe_id %llu session_type %d be_id %d app_type %d acdb_dev_id %d sample_rate- %d\n",
  764. __func__, fe_id, session_type, be_id,
  765. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  766. ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
  767. be_id, &cfg_data);
  768. if (ret < 0)
  769. pr_err("%s: msm_transcode_playback_stream_app_type_cfg set failed returned %d\n",
  770. __func__, ret);
  771. return ret;
  772. }
  773. static int msm_transcode_playback_app_type_cfg_get(
  774. struct snd_kcontrol *kcontrol,
  775. struct snd_ctl_elem_value *ucontrol)
  776. {
  777. u64 fe_id = kcontrol->private_value;
  778. int session_type = SESSION_TYPE_RX;
  779. int be_id = 0;
  780. struct msm_pcm_stream_app_type_cfg cfg_data = {0};
  781. int ret = 0;
  782. ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
  783. &be_id, &cfg_data);
  784. if (ret < 0) {
  785. pr_err("%s: msm_transcode_playback_stream_app_type_cfg get failed returned %d\n",
  786. __func__, ret);
  787. goto done;
  788. }
  789. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_APP_TYPE] =
  790. cfg_data.app_type;
  791. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_ACDB_ID] =
  792. cfg_data.acdb_dev_id;
  793. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] =
  794. cfg_data.sample_rate;
  795. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID] = be_id;
  796. pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
  797. __func__, fe_id, session_type, be_id,
  798. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  799. done:
  800. return ret;
  801. }
  802. static int msm_transcode_capture_app_type_cfg_put(
  803. struct snd_kcontrol *kcontrol,
  804. struct snd_ctl_elem_value *ucontrol)
  805. {
  806. u64 fe_id = kcontrol->private_value;
  807. int session_type = SESSION_TYPE_TX;
  808. int be_id = ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID];
  809. struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
  810. int ret = 0;
  811. cfg_data.app_type = ucontrol->value.integer.value[
  812. APP_TYPE_CONFIG_IDX_APP_TYPE];
  813. cfg_data.acdb_dev_id = ucontrol->value.integer.value[
  814. APP_TYPE_CONFIG_IDX_ACDB_ID];
  815. if (ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] != 0)
  816. cfg_data.sample_rate = ucontrol->value.integer.value[
  817. APP_TYPE_CONFIG_IDX_SAMPLE_RATE];
  818. pr_debug("%s: fe_id %llu session_type %d be_id %d app_type %d acdb_dev_id %d sample_rate- %d\n",
  819. __func__, fe_id, session_type, be_id,
  820. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  821. ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
  822. be_id, &cfg_data);
  823. if (ret < 0)
  824. pr_err("%s: register stream app type cfg failed, returned %d\n",
  825. __func__, ret);
  826. return ret;
  827. }
  828. static int msm_transcode_capture_app_type_cfg_get(
  829. struct snd_kcontrol *kcontrol,
  830. struct snd_ctl_elem_value *ucontrol)
  831. {
  832. u64 fe_id = kcontrol->private_value;
  833. int session_type = SESSION_TYPE_TX;
  834. int be_id = 0;
  835. struct msm_pcm_stream_app_type_cfg cfg_data = {0};
  836. int ret = 0;
  837. ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
  838. &be_id, &cfg_data);
  839. if (ret < 0) {
  840. pr_err("%s: get stream app type cfg failed, returned %d\n",
  841. __func__, ret);
  842. goto done;
  843. }
  844. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_APP_TYPE] =
  845. cfg_data.app_type;
  846. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_ACDB_ID] =
  847. cfg_data.acdb_dev_id;
  848. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] =
  849. cfg_data.sample_rate;
  850. ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID] = be_id;
  851. pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
  852. __func__, fe_id, session_type, be_id,
  853. cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
  854. done:
  855. return ret;
  856. }
  857. static int msm_transcode_set_volume(struct snd_compr_stream *cstream,
  858. uint32_t master_gain)
  859. {
  860. int rc = 0;
  861. struct msm_transcode_loopback *prtd;
  862. struct snd_soc_pcm_runtime *rtd;
  863. pr_debug("%s: master_gain %d\n", __func__, master_gain);
  864. if (!cstream || !cstream->runtime) {
  865. pr_err("%s: session not active\n", __func__);
  866. return -EINVAL;
  867. }
  868. rtd = cstream->private_data;
  869. prtd = cstream->runtime->private_data;
  870. if (!rtd || !prtd || !prtd->audio_client) {
  871. pr_err("%s: invalid rtd, prtd or audio client", __func__);
  872. return -EINVAL;
  873. }
  874. rc = q6asm_set_volume(prtd->audio_client, master_gain);
  875. if (rc < 0)
  876. pr_err("%s: Send vol gain command failed rc=%d\n",
  877. __func__, rc);
  878. return rc;
  879. }
  880. static int msm_transcode_volume_put(struct snd_kcontrol *kcontrol,
  881. struct snd_ctl_elem_value *ucontrol)
  882. {
  883. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  884. unsigned long fe_id = kcontrol->private_value;
  885. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  886. snd_soc_component_get_drvdata(comp);
  887. struct snd_compr_stream *cstream = NULL;
  888. uint32_t ret = 0;
  889. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  890. pr_err("%s Received out of bounds fe_id %lu\n",
  891. __func__, fe_id);
  892. return -EINVAL;
  893. }
  894. cstream = pdata->cstream[fe_id];
  895. pdata->master_gain = ucontrol->value.integer.value[0];
  896. pr_debug("%s: fe_id %lu master_gain %d\n",
  897. __func__, fe_id, pdata->master_gain);
  898. if (cstream)
  899. ret = msm_transcode_set_volume(cstream, pdata->master_gain);
  900. return ret;
  901. }
  902. static int msm_transcode_volume_get(struct snd_kcontrol *kcontrol,
  903. struct snd_ctl_elem_value *ucontrol)
  904. {
  905. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  906. unsigned long fe_id = kcontrol->private_value;
  907. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  908. snd_soc_component_get_drvdata(comp);
  909. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  910. pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
  911. return -EINVAL;
  912. }
  913. pr_debug("%s: fe_id %lu\n", __func__, fe_id);
  914. ucontrol->value.integer.value[0] = pdata->master_gain;
  915. return 0;
  916. }
  917. static int msm_transcode_audio_effects_config_info(struct snd_kcontrol *kcontrol,
  918. struct snd_ctl_elem_info *uinfo)
  919. {
  920. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  921. uinfo->count = MAX_PP_PARAMS_SZ;
  922. uinfo->value.integer.min = 0;
  923. uinfo->value.integer.max = 0xFFFFFFFF;
  924. return 0;
  925. }
  926. static int msm_transcode_audio_effects_config_get(struct snd_kcontrol *kcontrol,
  927. struct snd_ctl_elem_value *ucontrol)
  928. {
  929. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  930. unsigned long fe_id = kcontrol->private_value;
  931. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  932. snd_soc_component_get_drvdata(comp);
  933. struct msm_transcode_audio_effects *audio_effects = NULL;
  934. struct snd_compr_stream *cstream = NULL;
  935. pr_debug("%s: fe_id: %lu\n", __func__, fe_id);
  936. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  937. pr_err("%s Received out of bounds fe_id %lu\n",
  938. __func__, fe_id);
  939. return -EINVAL;
  940. }
  941. cstream = pdata->cstream[fe_id];
  942. audio_effects = pdata->audio_effects[fe_id];
  943. if (!cstream || !audio_effects) {
  944. pr_err("%s: stream or effects inactive\n", __func__);
  945. return -EINVAL;
  946. }
  947. return 0;
  948. }
  949. static int msm_transcode_audio_effects_config_put(struct snd_kcontrol *kcontrol,
  950. struct snd_ctl_elem_value *ucontrol)
  951. {
  952. struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
  953. unsigned long fe_id = kcontrol->private_value;
  954. struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
  955. snd_soc_component_get_drvdata(comp);
  956. struct msm_transcode_audio_effects *audio_effects = NULL;
  957. struct snd_compr_stream *cstream = NULL;
  958. struct msm_transcode_loopback *prtd = NULL;
  959. long *values = &(ucontrol->value.integer.value[0]);
  960. int effects_module;
  961. int ret = 0;
  962. pr_debug("%s: fe_id: %lu\n", __func__, fe_id);
  963. if (fe_id >= MSM_FRONTEND_DAI_MAX) {
  964. pr_err("%s Received out of bounds fe_id %lu\n",
  965. __func__, fe_id);
  966. ret = -EINVAL;
  967. goto exit;
  968. }
  969. cstream = pdata->cstream[fe_id];
  970. audio_effects = pdata->audio_effects[fe_id];
  971. if (!cstream || !audio_effects) {
  972. pr_err("%s: stream or effects inactive\n", __func__);
  973. ret = -EINVAL;
  974. goto exit;
  975. }
  976. prtd = cstream->runtime->private_data;
  977. if (!prtd) {
  978. pr_err("%s: cannot set audio effects\n", __func__);
  979. ret = -EINVAL;
  980. goto exit;
  981. }
  982. effects_module = *values++;
  983. switch (effects_module) {
  984. case VIRTUALIZER_MODULE:
  985. pr_debug("%s: VIRTUALIZER_MODULE\n", __func__);
  986. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  987. prtd->audio_client->topology))
  988. ret = msm_audio_effects_virtualizer_handler(
  989. prtd->audio_client,
  990. &(audio_effects->virtualizer),
  991. values);
  992. break;
  993. case REVERB_MODULE:
  994. pr_debug("%s: REVERB_MODULE\n", __func__);
  995. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  996. prtd->audio_client->topology))
  997. ret = msm_audio_effects_reverb_handler(prtd->audio_client,
  998. &(audio_effects->reverb),
  999. values);
  1000. break;
  1001. case BASS_BOOST_MODULE:
  1002. pr_debug("%s: BASS_BOOST_MODULE\n", __func__);
  1003. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1004. prtd->audio_client->topology))
  1005. ret = msm_audio_effects_bass_boost_handler(prtd->audio_client,
  1006. &(audio_effects->bass_boost),
  1007. values);
  1008. break;
  1009. case PBE_MODULE:
  1010. pr_debug("%s: PBE_MODULE\n", __func__);
  1011. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1012. prtd->audio_client->topology))
  1013. ret = msm_audio_effects_pbe_handler(prtd->audio_client,
  1014. &(audio_effects->pbe),
  1015. values);
  1016. break;
  1017. case EQ_MODULE:
  1018. pr_debug("%s: EQ_MODULE\n", __func__);
  1019. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1020. prtd->audio_client->topology))
  1021. ret = msm_audio_effects_popless_eq_handler(prtd->audio_client,
  1022. &(audio_effects->equalizer),
  1023. values);
  1024. break;
  1025. case SOFT_VOLUME_MODULE:
  1026. pr_debug("%s: SOFT_VOLUME_MODULE\n", __func__);
  1027. break;
  1028. case SOFT_VOLUME2_MODULE:
  1029. pr_debug("%s: SOFT_VOLUME2_MODULE\n", __func__);
  1030. if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
  1031. prtd->audio_client->topology))
  1032. ret = msm_audio_effects_volume_handler_v2(prtd->audio_client,
  1033. &(audio_effects->volume),
  1034. values, SOFT_VOLUME_INSTANCE_2);
  1035. break;
  1036. default:
  1037. pr_err("%s Invalid effects config module\n", __func__);
  1038. ret = -EINVAL;
  1039. }
  1040. exit:
  1041. return ret;
  1042. }
  1043. static int msm_transcode_add_audio_effects_control(struct snd_soc_pcm_runtime *rtd)
  1044. {
  1045. struct snd_soc_component *component = NULL;
  1046. const char *mixer_ctl_name = "Audio Effects Config";
  1047. const char *deviceNo = "NN";
  1048. char *mixer_str = NULL;
  1049. int ctl_len = 0;
  1050. int ret = 0;
  1051. struct snd_kcontrol_new fe_audio_effects_config_control[1] = {
  1052. {
  1053. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1054. .name = "?",
  1055. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1056. .info = msm_transcode_audio_effects_config_info,
  1057. .get = msm_transcode_audio_effects_config_get,
  1058. .put = msm_transcode_audio_effects_config_put,
  1059. .private_value = 0,
  1060. }
  1061. };
  1062. if (!rtd) {
  1063. pr_err("%s NULL rtd\n", __func__);
  1064. ret = -EINVAL;
  1065. goto done;
  1066. }
  1067. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1068. if (!component) {
  1069. pr_err("%s: component is NULL\n", __func__);
  1070. return -EINVAL;
  1071. }
  1072. pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n", __func__,
  1073. rtd->dai_link->name, rtd->dai_link->id,
  1074. rtd->dai_link->cpus->dai_name, rtd->pcm->device);
  1075. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1076. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1077. if (!mixer_str) {
  1078. ret = -ENOMEM;
  1079. goto done;
  1080. }
  1081. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1082. fe_audio_effects_config_control[0].name = mixer_str;
  1083. fe_audio_effects_config_control[0].private_value = rtd->dai_link->id;
  1084. ret = snd_soc_add_component_controls(component,
  1085. fe_audio_effects_config_control,
  1086. ARRAY_SIZE(fe_audio_effects_config_control));
  1087. if (ret < 0)
  1088. pr_err("%s: failed to add ctl %s. err = %d\n", __func__, mixer_str, ret);
  1089. kfree(mixer_str);
  1090. done:
  1091. return ret;
  1092. }
  1093. static int msm_transcode_stream_cmd_control(
  1094. struct snd_soc_pcm_runtime *rtd)
  1095. {
  1096. struct snd_soc_component *component = NULL;
  1097. const char *mixer_ctl_name = DSP_STREAM_CMD;
  1098. const char *deviceNo = "NN";
  1099. char *mixer_str = NULL;
  1100. int ctl_len = 0, ret = 0;
  1101. struct snd_kcontrol_new fe_loopback_stream_cmd_config_control[1] = {
  1102. {
  1103. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1104. .name = "?",
  1105. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1106. .info = msm_adsp_stream_cmd_info,
  1107. .put = msm_transcode_stream_cmd_put,
  1108. .private_value = 0,
  1109. }
  1110. };
  1111. if (!rtd) {
  1112. pr_err("%s NULL rtd\n", __func__);
  1113. ret = -EINVAL;
  1114. goto done;
  1115. }
  1116. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1117. if (!component) {
  1118. pr_err("%s: component is NULL\n", __func__);
  1119. return -EINVAL;
  1120. }
  1121. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1122. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1123. if (!mixer_str) {
  1124. ret = -ENOMEM;
  1125. goto done;
  1126. }
  1127. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1128. fe_loopback_stream_cmd_config_control[0].name = mixer_str;
  1129. fe_loopback_stream_cmd_config_control[0].private_value =
  1130. rtd->dai_link->id;
  1131. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1132. ret = snd_soc_add_component_controls(component,
  1133. fe_loopback_stream_cmd_config_control,
  1134. ARRAY_SIZE(fe_loopback_stream_cmd_config_control));
  1135. if (ret < 0)
  1136. pr_err("%s: failed to add ctl %s. err = %d\n",
  1137. __func__, mixer_str, ret);
  1138. kfree(mixer_str);
  1139. done:
  1140. return ret;
  1141. }
  1142. static int msm_transcode_stream_callback_control(
  1143. struct snd_soc_pcm_runtime *rtd)
  1144. {
  1145. struct snd_soc_component *component = NULL;
  1146. const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
  1147. const char *deviceNo = "NN";
  1148. char *mixer_str = NULL;
  1149. int ctl_len = 0, ret = 0;
  1150. struct snd_kcontrol *kctl;
  1151. struct snd_kcontrol_new fe_loopback_callback_config_control[1] = {
  1152. {
  1153. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1154. .name = "?",
  1155. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1156. .info = msm_adsp_stream_callback_info,
  1157. .get = msm_adsp_stream_callback_get,
  1158. .private_value = 0,
  1159. }
  1160. };
  1161. if (!rtd) {
  1162. pr_err("%s: rtd is NULL\n", __func__);
  1163. ret = -EINVAL;
  1164. goto done;
  1165. }
  1166. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1167. if (!component) {
  1168. pr_err("%s: component is NULL\n", __func__);
  1169. return -EINVAL;
  1170. }
  1171. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1172. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1173. if (!mixer_str) {
  1174. ret = -ENOMEM;
  1175. goto done;
  1176. }
  1177. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1178. fe_loopback_callback_config_control[0].name = mixer_str;
  1179. fe_loopback_callback_config_control[0].private_value =
  1180. rtd->dai_link->id;
  1181. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1182. ret = snd_soc_add_component_controls(component,
  1183. fe_loopback_callback_config_control,
  1184. ARRAY_SIZE(fe_loopback_callback_config_control));
  1185. if (ret < 0) {
  1186. pr_err("%s: failed to add ctl %s. err = %d\n",
  1187. __func__, mixer_str, ret);
  1188. ret = -EINVAL;
  1189. goto free_mixer_str;
  1190. }
  1191. kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
  1192. if (!kctl) {
  1193. pr_err("%s: failed to get kctl %s.\n", __func__, mixer_str);
  1194. ret = -EINVAL;
  1195. goto free_mixer_str;
  1196. }
  1197. kctl->private_data = NULL;
  1198. free_mixer_str:
  1199. kfree(mixer_str);
  1200. done:
  1201. return ret;
  1202. }
  1203. static int msm_transcode_add_ion_fd_cmd_control(struct snd_soc_pcm_runtime *rtd)
  1204. {
  1205. struct snd_soc_component *component = NULL;
  1206. const char *mixer_ctl_name = "Playback ION FD";
  1207. const char *deviceNo = "NN";
  1208. char *mixer_str = NULL;
  1209. int ctl_len = 0, ret = 0;
  1210. struct snd_kcontrol_new fe_ion_fd_config_control[1] = {
  1211. {
  1212. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1213. .name = "?",
  1214. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1215. .info = msm_adsp_stream_cmd_info,
  1216. .put = msm_transcode_ion_fd_map_put,
  1217. .private_value = 0,
  1218. }
  1219. };
  1220. if (!rtd) {
  1221. pr_err("%s NULL rtd\n", __func__);
  1222. ret = -EINVAL;
  1223. goto done;
  1224. }
  1225. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1226. if (!component) {
  1227. pr_err("%s: component is NULL\n", __func__);
  1228. return -EINVAL;
  1229. }
  1230. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1231. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1232. if (!mixer_str) {
  1233. ret = -ENOMEM;
  1234. goto done;
  1235. }
  1236. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1237. fe_ion_fd_config_control[0].name = mixer_str;
  1238. fe_ion_fd_config_control[0].private_value = rtd->dai_link->id;
  1239. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1240. ret = snd_soc_add_component_controls(component,
  1241. fe_ion_fd_config_control,
  1242. ARRAY_SIZE(fe_ion_fd_config_control));
  1243. if (ret < 0)
  1244. pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
  1245. kfree(mixer_str);
  1246. done:
  1247. return ret;
  1248. }
  1249. static int msm_transcode_add_event_ack_cmd_control(
  1250. struct snd_soc_pcm_runtime *rtd)
  1251. {
  1252. struct snd_soc_component *component = NULL;
  1253. const char *mixer_ctl_name = "Playback Event Ack";
  1254. const char *deviceNo = "NN";
  1255. char *mixer_str = NULL;
  1256. int ctl_len = 0, ret = 0;
  1257. struct snd_kcontrol_new fe_event_ack_config_control[1] = {
  1258. {
  1259. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1260. .name = "?",
  1261. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1262. .info = msm_adsp_stream_cmd_info,
  1263. .put = msm_transcode_rtic_event_ack_put,
  1264. .private_value = 0,
  1265. }
  1266. };
  1267. if (!rtd) {
  1268. pr_err("%s NULL rtd\n", __func__);
  1269. ret = -EINVAL;
  1270. goto done;
  1271. }
  1272. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1273. if (!component) {
  1274. pr_err("%s: component is NULL\n", __func__);
  1275. return -EINVAL;
  1276. }
  1277. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1278. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  1279. if (!mixer_str) {
  1280. ret = -ENOMEM;
  1281. goto done;
  1282. }
  1283. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
  1284. fe_event_ack_config_control[0].name = mixer_str;
  1285. fe_event_ack_config_control[0].private_value = rtd->dai_link->id;
  1286. pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
  1287. ret = snd_soc_add_component_controls(component,
  1288. fe_event_ack_config_control,
  1289. ARRAY_SIZE(fe_event_ack_config_control));
  1290. if (ret < 0)
  1291. pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
  1292. kfree(mixer_str);
  1293. done:
  1294. return ret;
  1295. }
  1296. static int msm_transcode_app_type_cfg_info(struct snd_kcontrol *kcontrol,
  1297. struct snd_ctl_elem_info *uinfo)
  1298. {
  1299. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1300. uinfo->count = 5;
  1301. uinfo->value.integer.min = 0;
  1302. uinfo->value.integer.max = 0xFFFFFFFF;
  1303. return 0;
  1304. }
  1305. static int msm_transcode_add_app_type_cfg_control(
  1306. struct snd_soc_pcm_runtime *rtd)
  1307. {
  1308. struct snd_soc_component *component = NULL;
  1309. char mixer_str[128];
  1310. struct snd_kcontrol_new fe_app_type_cfg_control[1] = {
  1311. {
  1312. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1313. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1314. .info = msm_transcode_app_type_cfg_info,
  1315. .private_value = 0,
  1316. }
  1317. };
  1318. if (!rtd) {
  1319. pr_err("%s NULL rtd\n", __func__);
  1320. return -EINVAL;
  1321. }
  1322. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1323. if (!component) {
  1324. pr_err("%s: component is NULL\n", __func__);
  1325. return -EINVAL;
  1326. }
  1327. if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
  1328. snprintf(mixer_str, sizeof(mixer_str),
  1329. "Audio Stream %d App Type Cfg",
  1330. rtd->pcm->device);
  1331. fe_app_type_cfg_control[0].name = mixer_str;
  1332. fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
  1333. fe_app_type_cfg_control[0].put =
  1334. msm_transcode_playback_app_type_cfg_put;
  1335. fe_app_type_cfg_control[0].get =
  1336. msm_transcode_playback_app_type_cfg_get;
  1337. pr_debug("Registering new mixer ctl %s", mixer_str);
  1338. snd_soc_add_component_controls(component,
  1339. fe_app_type_cfg_control,
  1340. ARRAY_SIZE(fe_app_type_cfg_control));
  1341. } else if (rtd->compr->direction == SND_COMPRESS_CAPTURE) {
  1342. snprintf(mixer_str, sizeof(mixer_str),
  1343. "Audio Stream Capture %d App Type Cfg",
  1344. rtd->pcm->device);
  1345. fe_app_type_cfg_control[0].name = mixer_str;
  1346. fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
  1347. fe_app_type_cfg_control[0].put =
  1348. msm_transcode_capture_app_type_cfg_put;
  1349. fe_app_type_cfg_control[0].get =
  1350. msm_transcode_capture_app_type_cfg_get;
  1351. pr_debug("Registering new mixer ctl %s", mixer_str);
  1352. snd_soc_add_component_controls(component,
  1353. fe_app_type_cfg_control,
  1354. ARRAY_SIZE(fe_app_type_cfg_control));
  1355. }
  1356. return 0;
  1357. }
  1358. static int msm_transcode_volume_info(struct snd_kcontrol *kcontrol,
  1359. struct snd_ctl_elem_info *uinfo)
  1360. {
  1361. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1362. uinfo->count = 1;
  1363. uinfo->value.integer.min = 0;
  1364. uinfo->value.integer.max = TRANSCODE_LR_VOL_MAX_DB;
  1365. return 0;
  1366. }
  1367. static int msm_transcode_add_volume_control(struct snd_soc_pcm_runtime *rtd)
  1368. {
  1369. struct snd_soc_component *component = NULL;
  1370. struct snd_kcontrol_new fe_volume_control[1] = {
  1371. {
  1372. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1373. .name = "Transcode Loopback Rx Volume",
  1374. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  1375. SNDRV_CTL_ELEM_ACCESS_READWRITE,
  1376. .info = msm_transcode_volume_info,
  1377. .get = msm_transcode_volume_get,
  1378. .put = msm_transcode_volume_put,
  1379. .private_value = 0,
  1380. }
  1381. };
  1382. if (!rtd) {
  1383. pr_err("%s NULL rtd\n", __func__);
  1384. return -EINVAL;
  1385. }
  1386. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1387. if (!component) {
  1388. pr_err("%s: component is NULL\n", __func__);
  1389. return -EINVAL;
  1390. }
  1391. if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
  1392. fe_volume_control[0].private_value = rtd->dai_link->id;
  1393. pr_debug("Registering new mixer ctl %s",
  1394. fe_volume_control[0].name);
  1395. snd_soc_add_component_controls(component, fe_volume_control,
  1396. ARRAY_SIZE(fe_volume_control));
  1397. }
  1398. return 0;
  1399. }
  1400. static int msm_transcode_loopback_new(struct snd_soc_pcm_runtime *rtd)
  1401. {
  1402. int rc;
  1403. rc = msm_transcode_add_audio_effects_control(rtd);
  1404. if (rc)
  1405. pr_err("%s: Could not add Compr Audio Effects Control\n",
  1406. __func__);
  1407. rc = msm_transcode_stream_cmd_control(rtd);
  1408. if (rc)
  1409. pr_err("%s: ADSP Stream Cmd Control open failed\n", __func__);
  1410. rc = msm_transcode_stream_callback_control(rtd);
  1411. if (rc)
  1412. pr_err("%s: ADSP Stream callback Control open failed\n",
  1413. __func__);
  1414. rc = msm_transcode_add_ion_fd_cmd_control(rtd);
  1415. if (rc)
  1416. pr_err("%s: Could not add transcode ion fd Control\n",
  1417. __func__);
  1418. rc = msm_transcode_add_event_ack_cmd_control(rtd);
  1419. if (rc)
  1420. pr_err("%s: Could not add transcode event ack Control\n",
  1421. __func__);
  1422. rc = msm_transcode_add_app_type_cfg_control(rtd);
  1423. if (rc)
  1424. pr_err("%s: Could not add Compr App Type Cfg Control\n",
  1425. __func__);
  1426. rc = msm_transcode_add_volume_control(rtd);
  1427. if (rc)
  1428. pr_err("%s: Could not add transcode volume Control\n",
  1429. __func__);
  1430. return 0;
  1431. }
  1432. static struct snd_compr_ops msm_transcode_loopback_ops = {
  1433. .open = msm_transcode_loopback_open,
  1434. .free = msm_transcode_loopback_free,
  1435. .trigger = msm_transcode_loopback_trigger,
  1436. .set_params = msm_transcode_loopback_set_params,
  1437. .get_caps = msm_transcode_loopback_get_caps,
  1438. .set_metadata = msm_transcode_loopback_set_metadata,
  1439. };
  1440. static int msm_transcode_loopback_probe(struct snd_soc_component *component)
  1441. {
  1442. struct trans_loopback_pdata *pdata = NULL;
  1443. int i;
  1444. pr_debug("%s\n", __func__);
  1445. pdata = (struct trans_loopback_pdata *)
  1446. kzalloc(sizeof(struct trans_loopback_pdata),
  1447. GFP_KERNEL);
  1448. if (!pdata)
  1449. return -ENOMEM;
  1450. for (i = 0; i < MSM_FRONTEND_DAI_MAX; i++) {
  1451. pdata->audio_effects[i] = NULL;
  1452. pdata->perf_mode[i] = LOW_LATENCY_PCM_MODE;
  1453. }
  1454. snd_soc_component_set_drvdata(component, pdata);
  1455. return 0;
  1456. }
  1457. static void msm_transcode_loopback_remove(struct snd_soc_component *component)
  1458. {
  1459. struct trans_loopback_pdata *pdata = NULL;
  1460. pdata = (struct trans_loopback_pdata *)
  1461. snd_soc_component_get_drvdata(component);
  1462. kfree(pdata);
  1463. return;
  1464. }
  1465. static struct snd_soc_component_driver msm_soc_component = {
  1466. .name = DRV_NAME,
  1467. .probe = msm_transcode_loopback_probe,
  1468. .compr_ops = &msm_transcode_loopback_ops,
  1469. .pcm_new = msm_transcode_loopback_new,
  1470. .remove = msm_transcode_loopback_remove,
  1471. };
  1472. static int msm_transcode_dev_probe(struct platform_device *pdev)
  1473. {
  1474. pr_debug("%s: dev name %s\n", __func__, dev_name(&pdev->dev));
  1475. return snd_soc_register_component(&pdev->dev,
  1476. &msm_soc_component,
  1477. NULL, 0);
  1478. }
  1479. static int msm_transcode_remove(struct platform_device *pdev)
  1480. {
  1481. snd_soc_unregister_component(&pdev->dev);
  1482. return 0;
  1483. }
  1484. static const struct of_device_id msm_transcode_loopback_dt_match[] = {
  1485. {.compatible = "qcom,msm-transcode-loopback"},
  1486. {}
  1487. };
  1488. MODULE_DEVICE_TABLE(of, msm_transcode_loopback_dt_match);
  1489. static struct platform_driver msm_transcode_loopback_driver = {
  1490. .driver = {
  1491. .name = "msm-transcode-loopback",
  1492. .owner = THIS_MODULE,
  1493. .of_match_table = msm_transcode_loopback_dt_match,
  1494. .suppress_bind_attrs = true,
  1495. },
  1496. .probe = msm_transcode_dev_probe,
  1497. .remove = msm_transcode_remove,
  1498. };
  1499. int __init msm_transcode_loopback_init(void)
  1500. {
  1501. memset(&transcode_info, 0, sizeof(struct msm_transcode_loopback));
  1502. mutex_init(&transcode_info.lock);
  1503. return platform_driver_register(&msm_transcode_loopback_driver);
  1504. }
  1505. void msm_transcode_loopback_exit(void)
  1506. {
  1507. mutex_destroy(&transcode_info.lock);
  1508. platform_driver_unregister(&msm_transcode_loopback_driver);
  1509. }
  1510. MODULE_DESCRIPTION("Transcode loopback platform driver");
  1511. MODULE_LICENSE("GPL v2");