msm-qti-pp-config.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/err.h>
  5. #include <linux/module.h>
  6. #include <linux/bitops.h>
  7. #include <linux/mutex.h>
  8. #include <sound/control.h>
  9. #include <sound/tlv.h>
  10. #include <dsp/q6adm-v2.h>
  11. #include <dsp/q6asm-v2.h>
  12. #include <dsp/q6afe-v2.h>
  13. #include <dsp/q6audio-v2.h>
  14. #include <dsp/q6common.h>
  15. #include "msm-qti-pp-config.h"
  16. #include "msm-pcm-routing-v2.h"
  17. /* EQUALIZER */
  18. /* Equal to Frontend after last of the MULTIMEDIA SESSIONS */
  19. #define MAX_EQ_SESSIONS (MSM_FRONTEND_DAI_MAX + 1)
  20. #define CHMIX_CFG_CONST_PARAM_SIZE 4
  21. enum {
  22. EQ_BAND1 = 0,
  23. EQ_BAND2,
  24. EQ_BAND3,
  25. EQ_BAND4,
  26. EQ_BAND5,
  27. EQ_BAND6,
  28. EQ_BAND7,
  29. EQ_BAND8,
  30. EQ_BAND9,
  31. EQ_BAND10,
  32. EQ_BAND11,
  33. EQ_BAND12,
  34. EQ_BAND_MAX,
  35. };
  36. /* Audio Sphere data structures */
  37. struct msm_audio_pp_asphere_state_s {
  38. uint32_t enabled;
  39. uint32_t strength;
  40. uint32_t mode;
  41. uint32_t version;
  42. int port_id[AFE_MAX_PORTS];
  43. int copp_idx[AFE_MAX_PORTS];
  44. bool initialized;
  45. uint32_t enabled_prev;
  46. uint32_t strength_prev;
  47. };
  48. static struct msm_audio_pp_asphere_state_s asphere_state;
  49. struct msm_audio_eq_stream_config eq_data[MAX_EQ_SESSIONS];
  50. static int msm_route_hfp_vol_control;
  51. static const DECLARE_TLV_DB_LINEAR(hfp_rx_vol_gain, 0,
  52. INT_RX_VOL_MAX_STEPS);
  53. static int msm_route_icc_vol_control;
  54. static const DECLARE_TLV_DB_LINEAR(icc_rx_vol_gain, 0,
  55. INT_RX_VOL_MAX_STEPS);
  56. static int msm_route_pri_auxpcm_lb_vol_ctrl;
  57. static const DECLARE_TLV_DB_LINEAR(pri_auxpcm_lb_vol_gain, 0,
  58. INT_RX_VOL_MAX_STEPS);
  59. static int msm_route_sec_auxpcm_lb_vol_ctrl;
  60. static const DECLARE_TLV_DB_LINEAR(sec_auxpcm_lb_vol_gain, 0,
  61. INT_RX_VOL_MAX_STEPS);
  62. static int msm_multichannel_ec_primary_mic_ch;
  63. static int msm_ffecns_effect;
  64. static void msm_qti_pp_send_eq_values_(int eq_idx)
  65. {
  66. int result;
  67. struct msm_pcm_routing_fdai_data fe_dai;
  68. struct audio_client *ac = NULL;
  69. msm_pcm_routing_get_fedai_info(eq_idx, SESSION_TYPE_RX, &fe_dai);
  70. ac = q6asm_get_audio_client(fe_dai.strm_id);
  71. if (ac == NULL) {
  72. pr_err("%s: Could not get audio client for session: %d\n",
  73. __func__, fe_dai.strm_id);
  74. goto done;
  75. }
  76. result = q6asm_equalizer(ac, &eq_data[eq_idx]);
  77. if (result < 0)
  78. pr_err("%s: Call to ASM equalizer failed, returned = %d\n",
  79. __func__, result);
  80. done:
  81. return;
  82. }
  83. static int msm_qti_pp_get_eq_enable_mixer(struct snd_kcontrol *kcontrol,
  84. struct snd_ctl_elem_value *ucontrol)
  85. {
  86. int eq_idx = ((struct soc_multi_mixer_control *)
  87. kcontrol->private_value)->reg;
  88. if ((eq_idx < 0) || (eq_idx >= MAX_EQ_SESSIONS))
  89. return -EINVAL;
  90. ucontrol->value.integer.value[0] = eq_data[eq_idx].enable;
  91. pr_debug("%s: EQ #%d enable %d\n", __func__,
  92. eq_idx, eq_data[eq_idx].enable);
  93. return 0;
  94. }
  95. static int msm_qti_pp_put_eq_enable_mixer(struct snd_kcontrol *kcontrol,
  96. struct snd_ctl_elem_value *ucontrol)
  97. {
  98. int eq_idx = ((struct soc_multi_mixer_control *)
  99. kcontrol->private_value)->reg;
  100. int value = ucontrol->value.integer.value[0];
  101. if ((eq_idx < 0) || (eq_idx >= MAX_EQ_SESSIONS))
  102. return -EINVAL;
  103. pr_debug("%s: EQ #%d enable %d\n", __func__,
  104. eq_idx, value);
  105. eq_data[eq_idx].enable = value;
  106. msm_pcm_routing_acquire_lock();
  107. msm_qti_pp_send_eq_values_(eq_idx);
  108. msm_pcm_routing_release_lock();
  109. return 0;
  110. }
  111. static int msm_qti_pp_get_eq_band_count_audio_mixer(
  112. struct snd_kcontrol *kcontrol,
  113. struct snd_ctl_elem_value *ucontrol)
  114. {
  115. int eq_idx = ((struct soc_multi_mixer_control *)
  116. kcontrol->private_value)->reg;
  117. if ((eq_idx < 0) || (eq_idx >= MAX_EQ_SESSIONS))
  118. return -EINVAL;
  119. ucontrol->value.integer.value[0] = eq_data[eq_idx].num_bands;
  120. pr_debug("%s: EQ #%d bands %d\n", __func__,
  121. eq_idx, eq_data[eq_idx].num_bands);
  122. return eq_data[eq_idx].num_bands;
  123. }
  124. static int msm_qti_pp_put_eq_band_count_audio_mixer(
  125. struct snd_kcontrol *kcontrol,
  126. struct snd_ctl_elem_value *ucontrol)
  127. {
  128. int eq_idx = ((struct soc_multi_mixer_control *)
  129. kcontrol->private_value)->reg;
  130. int value = ucontrol->value.integer.value[0];
  131. if ((eq_idx < 0) || (eq_idx >= MAX_EQ_SESSIONS))
  132. return -EINVAL;
  133. pr_debug("%s: EQ #%d bands %d\n", __func__,
  134. eq_idx, value);
  135. eq_data[eq_idx].num_bands = value;
  136. return 0;
  137. }
  138. static int msm_qti_pp_put_dtmf_module_enable
  139. (struct snd_kcontrol *kcontrol,
  140. struct snd_ctl_elem_value *ucontrol)
  141. {
  142. u16 fe_id = 0;
  143. struct msm_pcm_routing_fdai_data fe_dai;
  144. struct audio_client *ac = NULL;
  145. struct param_hdr_v3 param_hdr;
  146. int ret = 0;
  147. u32 flag = ucontrol->value.integer.value[0];
  148. fe_id = ((struct soc_multi_mixer_control *)
  149. kcontrol->private_value)->shift;
  150. if (fe_id >= MSM_FRONTEND_DAI_MM_SIZE) {
  151. pr_err("%s: invalid FE %d\n", __func__, fe_id);
  152. return -EINVAL;
  153. }
  154. msm_pcm_routing_get_fedai_info(fe_id, SESSION_TYPE_RX, &fe_dai);
  155. ac = q6asm_get_audio_client(fe_dai.strm_id);
  156. if (ac == NULL) {
  157. pr_err("%s ac is null.\n", __func__);
  158. ret = -EINVAL;
  159. goto done;
  160. }
  161. param_hdr.module_id = AUDPROC_MODULE_ID_DTMF_DETECTION;
  162. param_hdr.instance_id = INSTANCE_ID_0;
  163. param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
  164. param_hdr.param_size = 4;
  165. ret = q6asm_pack_and_set_pp_param_in_band(ac,
  166. param_hdr, (u8 *)&flag);
  167. done:
  168. return ret;
  169. }
  170. static int msm_qti_pp_get_eq_band_audio_mixer(struct snd_kcontrol *kcontrol,
  171. struct snd_ctl_elem_value *ucontrol)
  172. {
  173. int eq_idx = ((struct soc_multi_mixer_control *)
  174. kcontrol->private_value)->reg;
  175. int band_idx = ((struct soc_multi_mixer_control *)
  176. kcontrol->private_value)->shift;
  177. if ((eq_idx < 0) || (eq_idx >= MAX_EQ_SESSIONS) ||
  178. (band_idx < EQ_BAND1) || (band_idx >= EQ_BAND_MAX))
  179. return -EINVAL;
  180. ucontrol->value.integer.value[0] =
  181. eq_data[eq_idx].eq_bands[band_idx].band_idx;
  182. ucontrol->value.integer.value[1] =
  183. eq_data[eq_idx].eq_bands[band_idx].filter_type;
  184. ucontrol->value.integer.value[2] =
  185. eq_data[eq_idx].eq_bands[band_idx].center_freq_hz;
  186. ucontrol->value.integer.value[3] =
  187. eq_data[eq_idx].eq_bands[band_idx].filter_gain;
  188. ucontrol->value.integer.value[4] =
  189. eq_data[eq_idx].eq_bands[band_idx].q_factor;
  190. pr_debug("%s: band_idx = %d\n", __func__,
  191. eq_data[eq_idx].eq_bands[band_idx].band_idx);
  192. pr_debug("%s: filter_type = %d\n", __func__,
  193. eq_data[eq_idx].eq_bands[band_idx].filter_type);
  194. pr_debug("%s: center_freq_hz = %d\n", __func__,
  195. eq_data[eq_idx].eq_bands[band_idx].center_freq_hz);
  196. pr_debug("%s: filter_gain = %d\n", __func__,
  197. eq_data[eq_idx].eq_bands[band_idx].filter_gain);
  198. pr_debug("%s: q_factor = %d\n", __func__,
  199. eq_data[eq_idx].eq_bands[band_idx].q_factor);
  200. return 0;
  201. }
  202. static int msm_qti_pp_put_eq_band_audio_mixer(struct snd_kcontrol *kcontrol,
  203. struct snd_ctl_elem_value *ucontrol)
  204. {
  205. int eq_idx = ((struct soc_multi_mixer_control *)
  206. kcontrol->private_value)->reg;
  207. int band_idx = ((struct soc_multi_mixer_control *)
  208. kcontrol->private_value)->shift;
  209. if ((eq_idx < 0) || (eq_idx >= MAX_EQ_SESSIONS) ||
  210. (band_idx < EQ_BAND1) || (band_idx >= EQ_BAND_MAX))
  211. return -EINVAL;
  212. eq_data[eq_idx].eq_bands[band_idx].band_idx =
  213. ucontrol->value.integer.value[0];
  214. eq_data[eq_idx].eq_bands[band_idx].filter_type =
  215. ucontrol->value.integer.value[1];
  216. eq_data[eq_idx].eq_bands[band_idx].center_freq_hz =
  217. ucontrol->value.integer.value[2];
  218. eq_data[eq_idx].eq_bands[band_idx].filter_gain =
  219. ucontrol->value.integer.value[3];
  220. eq_data[eq_idx].eq_bands[band_idx].q_factor =
  221. ucontrol->value.integer.value[4];
  222. return 0;
  223. }
  224. #ifdef CONFIG_QTI_PP
  225. void msm_qti_pp_send_eq_values(int fedai_id)
  226. {
  227. if (eq_data[fedai_id].enable)
  228. msm_qti_pp_send_eq_values_(fedai_id);
  229. }
  230. /* CUSTOM MIXING */
  231. int msm_qti_pp_send_stereo_to_custom_stereo_cmd(int port_id, int copp_idx,
  232. unsigned int session_id,
  233. uint16_t op_FL_ip_FL_weight,
  234. uint16_t op_FL_ip_FR_weight,
  235. uint16_t op_FR_ip_FL_weight,
  236. uint16_t op_FR_ip_FR_weight)
  237. {
  238. char *params_value;
  239. int *update_params_value32, rc = 0;
  240. int16_t *update_params_value16 = 0;
  241. uint32_t params_length = CUSTOM_STEREO_PAYLOAD_SIZE * sizeof(uint32_t);
  242. uint32_t avail_length = params_length;
  243. pr_debug("%s: port_id - %d, session id - %d\n", __func__, port_id,
  244. session_id);
  245. params_value = kzalloc(params_length, GFP_KERNEL);
  246. if (!params_value) {
  247. pr_err("%s, params memory alloc failed\n", __func__);
  248. return -ENOMEM;
  249. }
  250. update_params_value32 = (int *)params_value;
  251. if (avail_length < 2 * sizeof(uint32_t))
  252. goto skip_send_cmd;
  253. /*
  254. * This module is internal to ADSP and cannot be configured with
  255. * an instance id
  256. */
  257. *update_params_value32++ = MTMX_MODULE_ID_DEFAULT_CHMIXER;
  258. *update_params_value32++ = DEFAULT_CHMIXER_PARAM_ID_COEFF;
  259. avail_length = avail_length - (2 * sizeof(uint32_t));
  260. update_params_value16 = (int16_t *)update_params_value32;
  261. if (avail_length < 10 * sizeof(uint16_t))
  262. goto skip_send_cmd;
  263. *update_params_value16++ = CUSTOM_STEREO_CMD_PARAM_SIZE;
  264. /*for alignment only*/
  265. *update_params_value16++ = 0;
  266. /*index is 32-bit param in little endian*/
  267. *update_params_value16++ = CUSTOM_STEREO_INDEX_PARAM;
  268. *update_params_value16++ = 0;
  269. /*for stereo mixing num out ch*/
  270. *update_params_value16++ = CUSTOM_STEREO_NUM_OUT_CH;
  271. /*for stereo mixing num in ch*/
  272. *update_params_value16++ = CUSTOM_STEREO_NUM_IN_CH;
  273. /* Out ch map FL/FR*/
  274. *update_params_value16++ = PCM_CHANNEL_FL;
  275. *update_params_value16++ = PCM_CHANNEL_FR;
  276. /* In ch map FL/FR*/
  277. *update_params_value16++ = PCM_CHANNEL_FL;
  278. *update_params_value16++ = PCM_CHANNEL_FR;
  279. avail_length = avail_length - (10 * sizeof(uint16_t));
  280. /* weighting coefficients as name suggests,
  281. * mixing will be done according to these coefficients
  282. */
  283. if (avail_length < 4 * sizeof(uint16_t))
  284. goto skip_send_cmd;
  285. *update_params_value16++ = op_FL_ip_FL_weight;
  286. *update_params_value16++ = op_FL_ip_FR_weight;
  287. *update_params_value16++ = op_FR_ip_FL_weight;
  288. *update_params_value16++ = op_FR_ip_FR_weight;
  289. avail_length = avail_length - (4 * sizeof(uint16_t));
  290. if (params_length) {
  291. rc = adm_set_stereo_to_custom_stereo(port_id,
  292. copp_idx,
  293. session_id,
  294. params_value,
  295. params_length);
  296. if (rc) {
  297. pr_err("%s: send params failed rc=%d\n", __func__, rc);
  298. kfree(params_value);
  299. return -EINVAL;
  300. }
  301. }
  302. kfree(params_value);
  303. return 0;
  304. skip_send_cmd:
  305. pr_err("%s: insufficient memory, send cmd failed\n",
  306. __func__);
  307. kfree(params_value);
  308. return -ENOMEM;
  309. }
  310. static int msm_qti_pp_arrange_mch_map(int16_t *update_params_value16,
  311. int channel_count)
  312. {
  313. int i;
  314. int16_t ch_map[PCM_FORMAT_MAX_CHANNELS_9] = {
  315. PCM_CHANNEL_FL, PCM_CHANNEL_FR, PCM_CHANNEL_FC,
  316. PCM_CHANNEL_LS, PCM_CHANNEL_RS, PCM_CHANNEL_LFE,
  317. PCM_CHANNEL_LB, PCM_CHANNEL_RB, PCM_CHANNEL_CS };
  318. if (channel_count < 1 ||
  319. channel_count > PCM_FORMAT_MAX_CHANNELS_9) {
  320. pr_err("%s: invalid ch_cnt %d\n",
  321. __func__, channel_count);
  322. return -EINVAL;
  323. }
  324. switch (channel_count) {
  325. /* Add special cases here */
  326. case 1:
  327. *update_params_value16++ = PCM_CHANNEL_FC;
  328. break;
  329. case 4:
  330. *update_params_value16++ = PCM_CHANNEL_FL;
  331. *update_params_value16++ = PCM_CHANNEL_FR;
  332. *update_params_value16++ = PCM_CHANNEL_LS;
  333. *update_params_value16++ = PCM_CHANNEL_RS;
  334. break;
  335. /* Add standard cases here */
  336. default:
  337. for (i = 0; i < channel_count; i++)
  338. *update_params_value16++ = ch_map[i];
  339. break;
  340. }
  341. return 0;
  342. }
  343. static uint32_t msm_qti_pp_get_chmix_param_size(int ip_ch_cnt, int op_ch_cnt)
  344. {
  345. uint32_t param_size;
  346. /* Assign constant part of param length initially -
  347. * Index, Num out channels, Num in channels.
  348. */
  349. param_size = CHMIX_CFG_CONST_PARAM_SIZE * sizeof(uint16_t);
  350. /* Calculate variable part of param length using ip and op channels */
  351. /* channel map for input and output channels */
  352. param_size += op_ch_cnt * sizeof(uint16_t);
  353. param_size += ip_ch_cnt * sizeof(uint16_t);
  354. /* weightage coeff for each op ch corresponding to each ip ch */
  355. param_size += (ip_ch_cnt * op_ch_cnt) * sizeof(uint16_t);
  356. /* Params length should be multiple of 4 bytes i.e 32bit aligned*/
  357. param_size = (param_size + 3) & 0xFFFFFFFC;
  358. return param_size;
  359. }
  360. /*
  361. * msm_qti_pp_send_chmix_cfg_cmd:
  362. * Send the custom channel mixer configuration command.
  363. *
  364. * @port_id: Backend port id
  365. * @copp_idx: ADM copp index
  366. * @session_id: id for the session requesting channel mixer
  367. * @ip_channel_cnt: Input channel count
  368. * @op_channel_cnt: Output channel count
  369. * @ch_wght_coeff: Channel weight co-efficients for mixing
  370. * @session_type: Indicates TX or RX session
  371. * @stream_type: Indicates Audio or Listen stream type
  372. */
  373. int msm_qti_pp_send_chmix_cfg_cmd(int port_id, int copp_idx,
  374. unsigned int session_id, int ip_channel_cnt,
  375. int op_channel_cnt, int *ch_wght_coeff,
  376. int session_type, int stream_type)
  377. {
  378. char *params_value;
  379. int rc = 0, i, direction;
  380. u8 *param_ptr;
  381. int16_t *update_params_value16 = 0;
  382. uint32_t param_size = msm_qti_pp_get_chmix_param_size(ip_channel_cnt,
  383. op_channel_cnt);
  384. struct param_hdr_v3 *param_hdr;
  385. /* constant payload data size represents module_id, param_id,
  386. * param size, reserved field.
  387. */
  388. uint32_t params_length = param_size + sizeof(*param_hdr);
  389. pr_debug("%s: port_id - %d, session id - %d\n", __func__, port_id,
  390. session_id);
  391. params_value = kzalloc(params_length, GFP_KERNEL);
  392. if (!params_value)
  393. return -ENOMEM;
  394. param_ptr = params_value;
  395. param_hdr = (struct param_hdr_v3 *) param_ptr;
  396. param_hdr->module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER;
  397. param_hdr->instance_id = INSTANCE_ID_0;
  398. param_hdr->param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF;
  399. param_hdr->param_size = param_size;
  400. param_ptr += sizeof(*param_hdr);
  401. update_params_value16 = (int16_t *) param_ptr;
  402. /*for alignment only*/
  403. *update_params_value16++ = 0;
  404. /*index is 32-bit param in little endian*/
  405. *update_params_value16++ = CUSTOM_STEREO_INDEX_PARAM;
  406. *update_params_value16++ = 0;
  407. /*number of out ch*/
  408. *update_params_value16++ = op_channel_cnt;
  409. /*number of in ch*/
  410. *update_params_value16++ = ip_channel_cnt;
  411. /* Out ch map FL/FR*/
  412. msm_qti_pp_arrange_mch_map(update_params_value16, op_channel_cnt);
  413. update_params_value16 += op_channel_cnt;
  414. /* In ch map FL/FR*/
  415. msm_qti_pp_arrange_mch_map(update_params_value16, ip_channel_cnt);
  416. update_params_value16 += ip_channel_cnt;
  417. /* weighting coefficients as name suggests,
  418. * mixing will be done according to these coefficients.
  419. */
  420. for (i = 0; i < ip_channel_cnt * op_channel_cnt; i++)
  421. *update_params_value16++ =
  422. ch_wght_coeff[i] ? Q14_GAIN_UNITY : 0;
  423. if (params_length) {
  424. direction = (session_type == SESSION_TYPE_RX) ?
  425. ADM_MATRIX_ID_AUDIO_RX : ADM_MATRIX_ID_AUDIO_TX;
  426. rc = adm_set_custom_chmix_cfg(port_id,
  427. copp_idx,
  428. session_id,
  429. params_value,
  430. params_length,
  431. direction,
  432. stream_type);
  433. if (rc) {
  434. pr_err("%s: send params failed rc=%d\n", __func__, rc);
  435. kfree(params_value);
  436. return -EINVAL;
  437. }
  438. }
  439. kfree(params_value);
  440. return 0;
  441. }
  442. EXPORT_SYMBOL(msm_qti_pp_send_chmix_cfg_cmd);
  443. #endif /* CONFIG_QTI_PP */
  444. /* RMS */
  445. static int msm_qti_pp_get_rms_value_control(struct snd_kcontrol *kcontrol,
  446. struct snd_ctl_elem_value *ucontrol)
  447. {
  448. int rc = 0;
  449. int be_idx = 0, copp_idx;
  450. char *param_value;
  451. int *update_param_value;
  452. uint32_t param_size = (RMS_PAYLOAD_LEN + 1) * sizeof(uint32_t);
  453. struct msm_pcm_routing_bdai_data msm_bedai;
  454. struct param_hdr_v3 param_hdr;
  455. param_value = kzalloc(param_size, GFP_KERNEL);
  456. if (!param_value)
  457. return -ENOMEM;
  458. msm_pcm_routing_acquire_lock();
  459. for (be_idx = 0; be_idx < MSM_BACKEND_DAI_MAX; be_idx++) {
  460. msm_pcm_routing_get_bedai_info(be_idx, &msm_bedai);
  461. if (msm_bedai.port_id == SLIMBUS_0_TX)
  462. break;
  463. }
  464. if ((be_idx >= MSM_BACKEND_DAI_MAX) || !msm_bedai.active) {
  465. pr_err("%s, back not active to query rms be_idx:%d\n",
  466. __func__, be_idx);
  467. rc = -EINVAL;
  468. goto get_rms_value_err;
  469. }
  470. copp_idx = adm_get_default_copp_idx(SLIMBUS_0_TX);
  471. if ((copp_idx < 0) || (copp_idx > MAX_COPPS_PER_PORT)) {
  472. pr_err("%s, no active copp to query rms copp_idx:%d\n",
  473. __func__, copp_idx);
  474. rc = -EINVAL;
  475. goto get_rms_value_err;
  476. }
  477. memset(&param_hdr, 0, sizeof(param_hdr));
  478. param_hdr.module_id = RMS_MODULEID_APPI_PASSTHRU;
  479. param_hdr.instance_id = INSTANCE_ID_0;
  480. param_hdr.param_id = RMS_PARAM_FIRST_SAMPLE;
  481. param_hdr.param_size = param_size;
  482. rc = adm_get_pp_params(SLIMBUS_0_TX, copp_idx, ADM_CLIENT_ID_DEFAULT,
  483. NULL, &param_hdr, param_value);
  484. if (rc) {
  485. pr_err("%s: get parameters failed rc=%d\n", __func__, rc);
  486. rc = -EINVAL;
  487. goto get_rms_value_err;
  488. }
  489. update_param_value = (int *)param_value;
  490. ucontrol->value.integer.value[0] = update_param_value[0];
  491. pr_debug("%s: FROM DSP value[0] 0x%x\n",
  492. __func__, update_param_value[0]);
  493. get_rms_value_err:
  494. msm_pcm_routing_release_lock();
  495. kfree(param_value);
  496. return rc;
  497. }
  498. static int msm_qti_pp_put_rms_value_control(struct snd_kcontrol *kcontrol,
  499. struct snd_ctl_elem_value *ucontrol)
  500. {
  501. /* not used */
  502. return 0;
  503. }
  504. /* VOLUME */
  505. static int msm_route_fm_vol_control;
  506. static int msm_afe_lb_vol_ctrl;
  507. static int msm_afe_sec_mi2s_lb_vol_ctrl;
  508. static int msm_afe_tert_mi2s_lb_vol_ctrl;
  509. static int msm_afe_quat_mi2s_lb_vol_ctrl;
  510. static int msm_afe_slimbus_7_lb_vol_ctrl;
  511. static int msm_afe_slimbus_8_lb_vol_ctrl;
  512. static int msm_asm_bit_width;
  513. static const DECLARE_TLV_DB_LINEAR(fm_rx_vol_gain, 0, INT_RX_VOL_MAX_STEPS);
  514. static const DECLARE_TLV_DB_LINEAR(afe_lb_vol_gain, 0, INT_RX_VOL_MAX_STEPS);
  515. static int msm_qti_pp_get_fm_vol_mixer(struct snd_kcontrol *kcontrol,
  516. struct snd_ctl_elem_value *ucontrol)
  517. {
  518. ucontrol->value.integer.value[0] = msm_route_fm_vol_control;
  519. return 0;
  520. }
  521. static int msm_qti_pp_set_fm_vol_mixer(struct snd_kcontrol *kcontrol,
  522. struct snd_ctl_elem_value *ucontrol)
  523. {
  524. afe_loopback_gain(INT_FM_TX, ucontrol->value.integer.value[0]);
  525. msm_route_fm_vol_control = ucontrol->value.integer.value[0];
  526. return 0;
  527. }
  528. static int msm_asm_bit_width_get(struct snd_kcontrol *kcontrol,
  529. struct snd_ctl_elem_value *ucontrol)
  530. {
  531. pr_debug("%s get ASM bitwidth = %d\n",
  532. __func__, msm_asm_bit_width);
  533. ucontrol->value.integer.value[0] = msm_asm_bit_width;
  534. return 0;
  535. }
  536. static int msm_asm_bit_width_put(struct snd_kcontrol *kcontrol,
  537. struct snd_ctl_elem_value *ucontrol)
  538. {
  539. switch (ucontrol->value.integer.value[0]) {
  540. case 16:
  541. msm_asm_bit_width = 16;
  542. break;
  543. case 24:
  544. msm_asm_bit_width = 24;
  545. break;
  546. case 32:
  547. msm_asm_bit_width = 32;
  548. break;
  549. default:
  550. msm_asm_bit_width = 0;
  551. break;
  552. }
  553. return 0;
  554. }
  555. static int msm_qti_pp_get_pri_mi2s_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  556. struct snd_ctl_elem_value *ucontrol)
  557. {
  558. ucontrol->value.integer.value[0] = msm_afe_lb_vol_ctrl;
  559. return 0;
  560. }
  561. static int msm_qti_pp_set_pri_mi2s_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  562. struct snd_ctl_elem_value *ucontrol)
  563. {
  564. afe_loopback_gain(AFE_PORT_ID_PRIMARY_MI2S_TX,
  565. ucontrol->value.integer.value[0]);
  566. msm_afe_lb_vol_ctrl = ucontrol->value.integer.value[0];
  567. return 0;
  568. }
  569. static int msm_qti_pp_get_sec_mi2s_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  570. struct snd_ctl_elem_value *ucontrol)
  571. {
  572. ucontrol->value.integer.value[0] = msm_afe_sec_mi2s_lb_vol_ctrl;
  573. return 0;
  574. }
  575. static int msm_qti_pp_set_sec_mi2s_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  576. struct snd_ctl_elem_value *ucontrol)
  577. {
  578. afe_loopback_gain(AFE_PORT_ID_SECONDARY_MI2S_TX,
  579. ucontrol->value.integer.value[0]);
  580. msm_afe_sec_mi2s_lb_vol_ctrl = ucontrol->value.integer.value[0];
  581. return 0;
  582. }
  583. static int msm_qti_pp_get_tert_mi2s_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  584. struct snd_ctl_elem_value *ucontrol)
  585. {
  586. ucontrol->value.integer.value[0] = msm_afe_tert_mi2s_lb_vol_ctrl;
  587. return 0;
  588. }
  589. static int msm_qti_pp_set_tert_mi2s_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  590. struct snd_ctl_elem_value *ucontrol)
  591. {
  592. afe_loopback_gain(AFE_PORT_ID_TERTIARY_MI2S_TX,
  593. ucontrol->value.integer.value[0]);
  594. msm_afe_tert_mi2s_lb_vol_ctrl = ucontrol->value.integer.value[0];
  595. return 0;
  596. }
  597. static int msm_qti_pp_get_slimbus_7_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  598. struct snd_ctl_elem_value *ucontrol)
  599. {
  600. ucontrol->value.integer.value[0] = msm_afe_slimbus_7_lb_vol_ctrl;
  601. return 0;
  602. }
  603. static int msm_qti_pp_set_slimbus_7_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  604. struct snd_ctl_elem_value *ucontrol)
  605. {
  606. int ret = afe_loopback_gain(SLIMBUS_7_TX,
  607. ucontrol->value.integer.value[0]);
  608. if (ret)
  609. pr_err("%s: failed to set LB vol for SLIMBUS_7_TX, err %d\n",
  610. __func__, ret);
  611. else
  612. msm_afe_slimbus_7_lb_vol_ctrl =
  613. ucontrol->value.integer.value[0];
  614. return ret;
  615. }
  616. static int msm_qti_pp_get_slimbus_8_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  617. struct snd_ctl_elem_value *ucontrol)
  618. {
  619. ucontrol->value.integer.value[0] = msm_afe_slimbus_8_lb_vol_ctrl;
  620. return 0;
  621. }
  622. static int msm_qti_pp_set_slimbus_8_lb_vol_mixer(struct snd_kcontrol *kcontrol,
  623. struct snd_ctl_elem_value *ucontrol)
  624. {
  625. int ret = 0;
  626. ret = afe_loopback_gain(SLIMBUS_8_TX,
  627. ucontrol->value.integer.value[0]);
  628. if (ret)
  629. pr_err("%s: failed to set LB vol for SLIMBUS_8_TX", __func__);
  630. else
  631. msm_afe_slimbus_8_lb_vol_ctrl =
  632. ucontrol->value.integer.value[0];
  633. return ret;
  634. }
  635. static int msm_qti_pp_get_icc_vol_mixer(struct snd_kcontrol *kcontrol,
  636. struct snd_ctl_elem_value *ucontrol)
  637. {
  638. ucontrol->value.integer.value[0] = msm_route_icc_vol_control;
  639. return 0;
  640. }
  641. static int msm_qti_pp_set_icc_vol_mixer(struct snd_kcontrol *kcontrol,
  642. struct snd_ctl_elem_value *ucontrol)
  643. {
  644. adm_set_mic_gain(AFE_PORT_ID_QUATERNARY_TDM_TX,
  645. adm_get_default_copp_idx(AFE_PORT_ID_QUATERNARY_TDM_TX),
  646. ucontrol->value.integer.value[0]);
  647. msm_route_icc_vol_control = ucontrol->value.integer.value[0];
  648. return 0;
  649. }
  650. static int msm_qti_pp_get_quat_mi2s_fm_vol_mixer(struct snd_kcontrol *kcontrol,
  651. struct snd_ctl_elem_value *ucontrol)
  652. {
  653. ucontrol->value.integer.value[0] = msm_afe_quat_mi2s_lb_vol_ctrl;
  654. return 0;
  655. }
  656. static int msm_qti_pp_set_quat_mi2s_fm_vol_mixer(struct snd_kcontrol *kcontrol,
  657. struct snd_ctl_elem_value *ucontrol)
  658. {
  659. afe_loopback_gain(AFE_PORT_ID_QUATERNARY_MI2S_TX,
  660. ucontrol->value.integer.value[0]);
  661. msm_afe_quat_mi2s_lb_vol_ctrl = ucontrol->value.integer.value[0];
  662. return 0;
  663. }
  664. static int msm_qti_pp_get_hfp_vol_mixer(struct snd_kcontrol *kcontrol,
  665. struct snd_ctl_elem_value *ucontrol)
  666. {
  667. ucontrol->value.integer.value[0] = msm_route_hfp_vol_control;
  668. return 0;
  669. }
  670. static int msm_qti_pp_set_hfp_vol_mixer(struct snd_kcontrol *kcontrol,
  671. struct snd_ctl_elem_value *ucontrol)
  672. {
  673. afe_loopback_gain(INT_BT_SCO_TX, ucontrol->value.integer.value[0]);
  674. msm_route_hfp_vol_control = ucontrol->value.integer.value[0];
  675. return 0;
  676. }
  677. static int msm_qti_pp_get_pri_auxpcm_lb_vol_mixer(
  678. struct snd_kcontrol *kcontrol,
  679. struct snd_ctl_elem_value *ucontrol)
  680. {
  681. ucontrol->value.integer.value[0] = msm_route_pri_auxpcm_lb_vol_ctrl;
  682. pr_debug("%s: Volume = %ld\n", __func__,
  683. ucontrol->value.integer.value[0]);
  684. return 0;
  685. }
  686. static int msm_qti_pp_set_pri_auxpcm_lb_vol_mixer(
  687. struct snd_kcontrol *kcontrol,
  688. struct snd_ctl_elem_value *ucontrol)
  689. {
  690. struct soc_mixer_control *mc =
  691. (struct soc_mixer_control *)kcontrol->private_value;
  692. afe_loopback_gain(mc->reg, ucontrol->value.integer.value[0]);
  693. msm_route_pri_auxpcm_lb_vol_ctrl = ucontrol->value.integer.value[0];
  694. return 0;
  695. }
  696. static int msm_qti_pp_get_sec_auxpcm_lb_vol_mixer(
  697. struct snd_kcontrol *kcontrol,
  698. struct snd_ctl_elem_value *ucontrol)
  699. {
  700. ucontrol->value.integer.value[0] = msm_route_sec_auxpcm_lb_vol_ctrl;
  701. pr_debug("%s: Volume = %ld\n", __func__,
  702. ucontrol->value.integer.value[0]);
  703. return 0;
  704. }
  705. static int msm_qti_pp_set_sec_auxpcm_lb_vol_mixer(
  706. struct snd_kcontrol *kcontrol,
  707. struct snd_ctl_elem_value *ucontrol)
  708. {
  709. struct soc_mixer_control *mc =
  710. (struct soc_mixer_control *)kcontrol->private_value;
  711. afe_loopback_gain(mc->reg, ucontrol->value.integer.value[0]);
  712. msm_route_sec_auxpcm_lb_vol_ctrl = ucontrol->value.integer.value[0];
  713. return 0;
  714. }
  715. static int msm_qti_pp_get_channel_map_mixer(struct snd_kcontrol *kcontrol,
  716. struct snd_ctl_elem_value *ucontrol)
  717. {
  718. char channel_map[PCM_FORMAT_MAX_NUM_CHANNEL_V8] = {0};
  719. int i;
  720. adm_get_multi_ch_map(channel_map, ADM_PATH_PLAYBACK);
  721. for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
  722. ucontrol->value.integer.value[i] =
  723. (unsigned int) channel_map[i];
  724. return 0;
  725. }
  726. static int msm_qti_pp_put_channel_map_mixer(struct snd_kcontrol *kcontrol,
  727. struct snd_ctl_elem_value *ucontrol)
  728. {
  729. char channel_map[PCM_FORMAT_MAX_NUM_CHANNEL_V8];
  730. int i;
  731. for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
  732. channel_map[i] = (char)(ucontrol->value.integer.value[i]);
  733. adm_set_multi_ch_map(channel_map, ADM_PATH_PLAYBACK);
  734. return 0;
  735. }
  736. static int msm_qti_pp_get_channel_map_capture(struct snd_kcontrol *kcontrol,
  737. struct snd_ctl_elem_value *ucontrol)
  738. {
  739. char channel_map[PCM_FORMAT_MAX_NUM_CHANNEL_V8] = {0};
  740. int i;
  741. adm_get_multi_ch_map(channel_map, ADM_PATH_LIVE_REC);
  742. for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
  743. ucontrol->value.integer.value[i] =
  744. (unsigned int) channel_map[i];
  745. return 0;
  746. }
  747. static int msm_qti_pp_put_channel_map_capture(struct snd_kcontrol *kcontrol,
  748. struct snd_ctl_elem_value *ucontrol)
  749. {
  750. char channel_map[PCM_FORMAT_MAX_NUM_CHANNEL_V8];
  751. int i;
  752. for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)
  753. channel_map[i] = (char)(ucontrol->value.integer.value[i]);
  754. adm_set_multi_ch_map(channel_map, ADM_PATH_LIVE_REC);
  755. return 0;
  756. }
  757. /* Audio Sphere functions */
  758. static void msm_qti_pp_asphere_init_state(void)
  759. {
  760. int i;
  761. if (asphere_state.initialized)
  762. return;
  763. asphere_state.initialized = true;
  764. for (i = 0; i < AFE_MAX_PORTS; i++) {
  765. asphere_state.port_id[i] = -1;
  766. asphere_state.copp_idx[i] = -1;
  767. }
  768. asphere_state.enabled = 0;
  769. asphere_state.strength = 0;
  770. asphere_state.mode = 0;
  771. asphere_state.version = 0;
  772. asphere_state.enabled_prev = 0;
  773. asphere_state.strength_prev = 0;
  774. }
  775. static int msm_qti_pp_asphere_send_params(int port_id, int copp_idx, bool force)
  776. {
  777. u8 *packed_params = NULL;
  778. u32 packed_params_size = 0;
  779. u32 param_size = 0;
  780. struct param_hdr_v3 param_hdr;
  781. bool set_enable = force ||
  782. (asphere_state.enabled != asphere_state.enabled_prev);
  783. bool set_strength = asphere_state.enabled == 1 && (set_enable ||
  784. (asphere_state.strength != asphere_state.strength_prev));
  785. int param_count = 0;
  786. int ret = 0;
  787. if (set_enable)
  788. param_count++;
  789. if (set_strength)
  790. param_count++;
  791. if (param_count == 0) {
  792. pr_debug("%s: Nothing to send, exiting\n", __func__);
  793. return 0;
  794. }
  795. pr_debug("%s: port_id %d, copp_id %d, forced %d, param_count %d\n",
  796. __func__, port_id, copp_idx, force, param_count);
  797. pr_debug("%s: enable prev:%u cur:%u, strength prev:%u cur:%u\n",
  798. __func__, asphere_state.enabled_prev, asphere_state.enabled,
  799. asphere_state.strength_prev, asphere_state.strength);
  800. packed_params_size =
  801. param_count * (sizeof(struct param_hdr_v3) + sizeof(uint32_t));
  802. packed_params = kzalloc(packed_params_size, GFP_KERNEL);
  803. if (!packed_params)
  804. return -ENOMEM;
  805. memset(&param_hdr, 0, sizeof(param_hdr));
  806. packed_params_size = 0;
  807. param_hdr.module_id = AUDPROC_MODULE_ID_AUDIOSPHERE;
  808. param_hdr.instance_id = INSTANCE_ID_0;
  809. if (set_strength) {
  810. /* add strength command */
  811. param_hdr.param_id = AUDPROC_PARAM_ID_AUDIOSPHERE_STRENGTH;
  812. param_hdr.param_size = sizeof(asphere_state.strength);
  813. ret = q6common_pack_pp_params(packed_params +
  814. packed_params_size,
  815. &param_hdr,
  816. (u8 *) &asphere_state.strength,
  817. &param_size);
  818. if (ret) {
  819. pr_err("%s: Failed to pack params for audio sphere"
  820. " strength, error %d\n", __func__, ret);
  821. goto done;
  822. }
  823. packed_params_size += param_size;
  824. }
  825. if (set_enable) {
  826. /* add enable command */
  827. param_hdr.param_id = AUDPROC_PARAM_ID_AUDIOSPHERE_ENABLE;
  828. param_hdr.param_size = sizeof(asphere_state.enabled);
  829. q6common_pack_pp_params(packed_params + packed_params_size,
  830. &param_hdr,
  831. (u8 *) &asphere_state.enabled,
  832. &param_size);
  833. if (ret) {
  834. pr_err("%s: Failed to pack params for audio sphere"
  835. " enable, error %d\n", __func__, ret);
  836. goto done;
  837. }
  838. packed_params_size += param_size;
  839. }
  840. pr_debug("%s: packed data size: %d\n", __func__, packed_params_size);
  841. ret = adm_set_pp_params(port_id, copp_idx, NULL, packed_params,
  842. packed_params_size);
  843. if (ret)
  844. pr_err("%s: set param failed with err=%d\n", __func__, ret);
  845. done:
  846. kfree(packed_params);
  847. return 0;
  848. }
  849. #if defined(CONFIG_QTI_PP) && defined(CONFIG_QTI_PP_AUDIOSPHERE)
  850. int msm_qti_pp_asphere_init(int port_id, int copp_idx)
  851. {
  852. int index = adm_validate_and_get_port_index(port_id);
  853. pr_debug("%s, port_id %d, copp_id %d\n", __func__, port_id, copp_idx);
  854. if (index < 0) {
  855. pr_err("%s: Invalid port idx %d port_id %#x\n", __func__, index,
  856. port_id);
  857. return -EINVAL;
  858. }
  859. msm_qti_pp_asphere_init_state();
  860. asphere_state.port_id[index] = port_id;
  861. asphere_state.copp_idx[index] = copp_idx;
  862. if (asphere_state.enabled)
  863. msm_qti_pp_asphere_send_params(port_id, copp_idx, true);
  864. return 0;
  865. }
  866. void msm_qti_pp_asphere_deinit(int port_id)
  867. {
  868. int index = adm_validate_and_get_port_index(port_id);
  869. pr_debug("%s, port_id %d\n", __func__, port_id);
  870. if (index < 0) {
  871. pr_err("%s: Invalid port idx %d port_id %#x\n", __func__, index,
  872. port_id);
  873. return;
  874. }
  875. if (asphere_state.port_id[index] == port_id) {
  876. asphere_state.port_id[index] = -1;
  877. asphere_state.copp_idx[index] = -1;
  878. }
  879. }
  880. #endif
  881. static int msm_qti_pp_asphere_get(struct snd_kcontrol *kcontrol,
  882. struct snd_ctl_elem_value *ucontrol)
  883. {
  884. if (!asphere_state.initialized)
  885. return -EAGAIN;
  886. ucontrol->value.integer.value[0] = asphere_state.enabled;
  887. ucontrol->value.integer.value[1] = asphere_state.strength;
  888. pr_debug("%s, enable %u, strength %u\n", __func__,
  889. asphere_state.enabled, asphere_state.strength);
  890. return 0;
  891. }
  892. static int msm_qti_pp_asphere_set(struct snd_kcontrol *kcontrol,
  893. struct snd_ctl_elem_value *ucontrol)
  894. {
  895. int32_t enable = ucontrol->value.integer.value[0];
  896. int32_t strength = ucontrol->value.integer.value[1];
  897. int i;
  898. pr_debug("%s, enable %u, strength %u\n", __func__, enable, strength);
  899. msm_qti_pp_asphere_init_state();
  900. if (enable == 0 || enable == 1) {
  901. asphere_state.enabled_prev = asphere_state.enabled;
  902. asphere_state.enabled = enable;
  903. }
  904. if (strength >= 0 && strength <= 1000) {
  905. asphere_state.strength_prev = asphere_state.strength;
  906. asphere_state.strength = strength;
  907. }
  908. if (asphere_state.strength != asphere_state.strength_prev ||
  909. asphere_state.enabled != asphere_state.enabled_prev) {
  910. for (i = 0; i < AFE_MAX_PORTS; i++) {
  911. if (asphere_state.port_id[i] >= 0)
  912. msm_qti_pp_asphere_send_params(
  913. asphere_state.port_id[i],
  914. asphere_state.copp_idx[i],
  915. false);
  916. }
  917. }
  918. return 0;
  919. }
  920. int msm_adsp_init_mixer_ctl_pp_event_queue(struct snd_soc_pcm_runtime *rtd)
  921. {
  922. struct snd_kcontrol *kctl;
  923. const char *deviceNo = "NN";
  924. char *mixer_str = NULL;
  925. int ctl_len = 0, ret = 0;
  926. const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
  927. struct dsp_stream_callback_prtd *kctl_prtd = NULL;
  928. if (!rtd) {
  929. pr_err("%s: rtd is NULL\n", __func__);
  930. ret = -EINVAL;
  931. goto done;
  932. }
  933. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  934. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  935. if (!mixer_str) {
  936. ret = -EINVAL;
  937. goto done;
  938. }
  939. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name,
  940. rtd->pcm->device);
  941. kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
  942. kfree(mixer_str);
  943. if (!kctl) {
  944. pr_err("%s: failed to get kctl.\n", __func__);
  945. ret = -EINVAL;
  946. goto done;
  947. }
  948. if (kctl->private_data != NULL) {
  949. pr_err("%s: kctl_prtd is not NULL at initialization.\n",
  950. __func__);
  951. return -EINVAL;
  952. }
  953. kctl_prtd = kzalloc(sizeof(struct dsp_stream_callback_prtd),
  954. GFP_KERNEL);
  955. if (!kctl_prtd) {
  956. ret = -ENOMEM;
  957. goto done;
  958. }
  959. spin_lock_init(&kctl_prtd->prtd_spin_lock);
  960. INIT_LIST_HEAD(&kctl_prtd->event_queue);
  961. kctl_prtd->event_count = 0;
  962. kctl->private_data = kctl_prtd;
  963. done:
  964. return ret;
  965. }
  966. int msm_adsp_clean_mixer_ctl_pp_event_queue(struct snd_soc_pcm_runtime *rtd)
  967. {
  968. struct snd_kcontrol *kctl;
  969. const char *deviceNo = "NN";
  970. char *mixer_str = NULL;
  971. int ctl_len = 0, ret = 0;
  972. struct dsp_stream_callback_list *node, *n;
  973. unsigned long spin_flags;
  974. const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
  975. struct dsp_stream_callback_prtd *kctl_prtd = NULL;
  976. if (!rtd) {
  977. pr_err("%s: rtd is NULL\n", __func__);
  978. ret = -EINVAL;
  979. goto done;
  980. }
  981. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  982. mixer_str = kzalloc(ctl_len, GFP_KERNEL);
  983. if (!mixer_str) {
  984. ret = -EINVAL;
  985. goto done;
  986. }
  987. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name,
  988. rtd->pcm->device);
  989. kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
  990. kfree(mixer_str);
  991. if (!kctl) {
  992. pr_err("%s: failed to get kctl.\n", __func__);
  993. ret = -EINVAL;
  994. goto done;
  995. }
  996. kctl_prtd = (struct dsp_stream_callback_prtd *)
  997. kctl->private_data;
  998. if (kctl_prtd != NULL) {
  999. spin_lock_irqsave(&kctl_prtd->prtd_spin_lock, spin_flags);
  1000. /* clean the queue */
  1001. list_for_each_entry_safe(node, n,
  1002. &kctl_prtd->event_queue, list) {
  1003. list_del(&node->list);
  1004. kctl_prtd->event_count--;
  1005. pr_debug("%s: %d remaining events after del.\n",
  1006. __func__, kctl_prtd->event_count);
  1007. kfree(node);
  1008. }
  1009. spin_unlock_irqrestore(&kctl_prtd->prtd_spin_lock, spin_flags);
  1010. }
  1011. kfree(kctl_prtd);
  1012. kctl->private_data = NULL;
  1013. done:
  1014. return ret;
  1015. }
  1016. int msm_adsp_inform_mixer_ctl(struct snd_soc_pcm_runtime *rtd,
  1017. uint32_t *payload)
  1018. {
  1019. /* adsp pp event notifier */
  1020. struct snd_kcontrol *kctl;
  1021. struct snd_ctl_elem_value control;
  1022. const char *deviceNo = "NN";
  1023. char *mixer_str = NULL;
  1024. int ctl_len = 0, ret = 0;
  1025. struct dsp_stream_callback_list *new_event;
  1026. struct dsp_stream_callback_list *oldest_event;
  1027. unsigned long spin_flags;
  1028. struct dsp_stream_callback_prtd *kctl_prtd = NULL;
  1029. struct msm_adsp_event_data *event_data = NULL;
  1030. const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
  1031. struct snd_ctl_elem_info kctl_info;
  1032. if (!rtd || !payload) {
  1033. pr_err("%s: %s is NULL\n", __func__,
  1034. (!rtd) ? "rtd" : "payload");
  1035. ret = -EINVAL;
  1036. goto done;
  1037. }
  1038. if (rtd->card->snd_card == NULL) {
  1039. pr_err("%s: snd_card is null.\n", __func__);
  1040. ret = -EINVAL;
  1041. goto done;
  1042. }
  1043. ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
  1044. mixer_str = kzalloc(ctl_len, GFP_ATOMIC);
  1045. if (!mixer_str) {
  1046. ret = -EINVAL;
  1047. goto done;
  1048. }
  1049. snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name,
  1050. rtd->pcm->device);
  1051. kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
  1052. kfree(mixer_str);
  1053. if (!kctl) {
  1054. pr_err("%s: failed to get kctl.\n", __func__);
  1055. ret = -EINVAL;
  1056. goto done;
  1057. }
  1058. event_data = (struct msm_adsp_event_data *)payload;
  1059. if (event_data->payload_len < sizeof(struct msm_adsp_event_data)) {
  1060. pr_err("%s: event_data size of %x is less than expected.\n",
  1061. __func__, event_data->payload_len);
  1062. ret = -EINVAL;
  1063. goto done;
  1064. }
  1065. kctl->info(kctl, &kctl_info);
  1066. if (event_data->payload_len >
  1067. kctl_info.count - sizeof(struct msm_adsp_event_data)) {
  1068. pr_err("%s: payload length exceeds limit of %u bytes.\n",
  1069. __func__, kctl_info.count);
  1070. ret = -EINVAL;
  1071. goto done;
  1072. }
  1073. kctl_prtd = (struct dsp_stream_callback_prtd *)
  1074. kctl->private_data;
  1075. if (kctl_prtd == NULL) {
  1076. /* queue is not initialized */
  1077. ret = -EINVAL;
  1078. pr_err("%s: event queue is not initialized.\n", __func__);
  1079. goto done;
  1080. }
  1081. new_event = kzalloc(sizeof(struct dsp_stream_callback_list)
  1082. + event_data->payload_len,
  1083. GFP_ATOMIC);
  1084. if (new_event == NULL) {
  1085. ret = -ENOMEM;
  1086. goto done;
  1087. }
  1088. memcpy((void *)&new_event->event, (void *)payload,
  1089. event_data->payload_len
  1090. + sizeof(struct msm_adsp_event_data));
  1091. spin_lock_irqsave(&kctl_prtd->prtd_spin_lock, spin_flags);
  1092. while (kctl_prtd->event_count >= DSP_STREAM_CALLBACK_QUEUE_SIZE) {
  1093. pr_info("%s: queue of size %d is full. delete oldest one.\n",
  1094. __func__, DSP_STREAM_CALLBACK_QUEUE_SIZE);
  1095. oldest_event = list_first_entry(&kctl_prtd->event_queue,
  1096. struct dsp_stream_callback_list, list);
  1097. pr_info("%s: event deleted: type %d length %d\n",
  1098. __func__, oldest_event->event.event_type,
  1099. oldest_event->event.payload_len);
  1100. list_del(&oldest_event->list);
  1101. kctl_prtd->event_count--;
  1102. kfree(oldest_event);
  1103. }
  1104. list_add_tail(&new_event->list, &kctl_prtd->event_queue);
  1105. kctl_prtd->event_count++;
  1106. spin_unlock_irqrestore(&kctl_prtd->prtd_spin_lock, spin_flags);
  1107. control.id = kctl->id;
  1108. snd_ctl_notify(rtd->card->snd_card,
  1109. SNDRV_CTL_EVENT_MASK_INFO,
  1110. &control.id);
  1111. done:
  1112. return ret;
  1113. }
  1114. int msm_adsp_stream_cmd_info(struct snd_kcontrol *kcontrol,
  1115. struct snd_ctl_elem_info *uinfo)
  1116. {
  1117. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1118. uinfo->count =
  1119. sizeof(((struct snd_ctl_elem_value *)0)->value.bytes.data);
  1120. return 0;
  1121. }
  1122. int msm_adsp_stream_callback_get(struct snd_kcontrol *kcontrol,
  1123. struct snd_ctl_elem_value *ucontrol)
  1124. {
  1125. uint32_t payload_size = 0;
  1126. struct dsp_stream_callback_list *oldest_event;
  1127. unsigned long spin_flags;
  1128. struct dsp_stream_callback_prtd *kctl_prtd = NULL;
  1129. int ret = 0;
  1130. kctl_prtd = (struct dsp_stream_callback_prtd *)
  1131. kcontrol->private_data;
  1132. if (kctl_prtd == NULL) {
  1133. pr_debug("%s: ASM Stream PP event queue is not initialized.\n",
  1134. __func__);
  1135. ret = -EINVAL;
  1136. goto done;
  1137. }
  1138. spin_lock_irqsave(&kctl_prtd->prtd_spin_lock, spin_flags);
  1139. pr_debug("%s: %d events in queue.\n", __func__, kctl_prtd->event_count);
  1140. if (list_empty(&kctl_prtd->event_queue)) {
  1141. pr_err("%s: ASM Stream PP event queue is empty.\n", __func__);
  1142. ret = -EINVAL;
  1143. spin_unlock_irqrestore(&kctl_prtd->prtd_spin_lock, spin_flags);
  1144. goto done;
  1145. }
  1146. oldest_event = list_first_entry(&kctl_prtd->event_queue,
  1147. struct dsp_stream_callback_list, list);
  1148. list_del(&oldest_event->list);
  1149. kctl_prtd->event_count--;
  1150. spin_unlock_irqrestore(&kctl_prtd->prtd_spin_lock, spin_flags);
  1151. payload_size = oldest_event->event.payload_len;
  1152. pr_debug("%s: event fetched: type %d length %d\n",
  1153. __func__, oldest_event->event.event_type,
  1154. oldest_event->event.payload_len);
  1155. memcpy(ucontrol->value.bytes.data, &oldest_event->event,
  1156. sizeof(struct msm_adsp_event_data) + payload_size);
  1157. kfree(oldest_event);
  1158. done:
  1159. return ret;
  1160. }
  1161. int msm_adsp_stream_callback_info(struct snd_kcontrol *kcontrol,
  1162. struct snd_ctl_elem_info *uinfo)
  1163. {
  1164. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1165. uinfo->count =
  1166. sizeof(((struct snd_ctl_elem_value *)0)->value.bytes.data);
  1167. return 0;
  1168. }
  1169. static int msm_multichannel_ec_primary_mic_ch_put(struct snd_kcontrol *kcontrol,
  1170. struct snd_ctl_elem_value *ucontrol)
  1171. {
  1172. int ret = 0;
  1173. int copp_idx = 0;
  1174. int port_id = AFE_PORT_ID_QUATERNARY_TDM_TX;
  1175. msm_multichannel_ec_primary_mic_ch = ucontrol->value.integer.value[0];
  1176. pr_debug("%s: msm_multichannel_ec_primary_mic_ch = %u\n",
  1177. __func__, msm_multichannel_ec_primary_mic_ch);
  1178. copp_idx = adm_get_default_copp_idx(port_id);
  1179. if ((copp_idx < 0) || (copp_idx > MAX_COPPS_PER_PORT)) {
  1180. pr_err("%s : no active copp to query multichannel ec copp_idx: %u\n",
  1181. __func__, copp_idx);
  1182. return -EINVAL;
  1183. }
  1184. adm_send_set_multichannel_ec_primary_mic_ch(port_id, copp_idx,
  1185. msm_multichannel_ec_primary_mic_ch);
  1186. return ret;
  1187. }
  1188. static int msm_multichannel_ec_primary_mic_ch_get(struct snd_kcontrol *kcontrol,
  1189. struct snd_ctl_elem_value *ucontrol)
  1190. {
  1191. ucontrol->value.integer.value[0] = msm_multichannel_ec_primary_mic_ch;
  1192. pr_debug("%s: msm_multichannel_ec_primary_mic_ch = %lu\n",
  1193. __func__, ucontrol->value.integer.value[0]);
  1194. return 0;
  1195. }
  1196. static const struct snd_kcontrol_new msm_multichannel_ec_controls[] = {
  1197. SOC_SINGLE_EXT("Multichannel EC Primary Mic Ch", SND_SOC_NOPM, 0,
  1198. 0xFFFFFFFF, 0, msm_multichannel_ec_primary_mic_ch_get,
  1199. msm_multichannel_ec_primary_mic_ch_put),
  1200. };
  1201. static char const *ffecns_effect_text[] = {"NO_EFFECT", "EC_ONLY", "NS_ONLY", "ECNS"};
  1202. static int msm_ffecns_put(struct snd_kcontrol *kcontrol,
  1203. struct snd_ctl_elem_value *ucontrol)
  1204. {
  1205. int ret = -EINVAL;
  1206. if (ucontrol->value.integer.value[0] < 0 ||
  1207. ucontrol->value.integer.value[0] >= ARRAY_SIZE(ffecns_effect_text)) {
  1208. pr_err("%s: invalid ffecns effect value %ld\n",
  1209. __func__, ucontrol->value.integer.value[0]);
  1210. return -EINVAL;
  1211. }
  1212. msm_ffecns_effect = ucontrol->value.integer.value[0];
  1213. pr_debug("%s: set %s for ffecns\n", __func__,
  1214. ffecns_effect_text[msm_ffecns_effect]);
  1215. ret = adm_set_ffecns_effect(msm_ffecns_effect);
  1216. if (ret)
  1217. pr_err("%s: failed to set %s for ffecns\n",
  1218. __func__, ffecns_effect_text[msm_ffecns_effect]);
  1219. return ret;
  1220. }
  1221. static int msm_ffecns_get(struct snd_kcontrol *kcontrol,
  1222. struct snd_ctl_elem_value *ucontrol)
  1223. {
  1224. ucontrol->value.integer.value[0] = msm_ffecns_effect;
  1225. pr_debug("%s: ffecns effect = %ld\n",
  1226. __func__, ucontrol->value.integer.value[0]);
  1227. return 0;
  1228. }
  1229. static SOC_ENUM_SINGLE_EXT_DECL(ffecns_effect_enum, ffecns_effect_text);
  1230. static const struct snd_kcontrol_new ec_ffecns_controls[] = {
  1231. SOC_ENUM_EXT("FFECNS Effect", ffecns_effect_enum,
  1232. msm_ffecns_get, msm_ffecns_put),
  1233. };
  1234. static const struct snd_kcontrol_new int_fm_vol_mixer_controls[] = {
  1235. SOC_SINGLE_EXT_TLV("Internal FM RX Volume", SND_SOC_NOPM, 0,
  1236. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_fm_vol_mixer,
  1237. msm_qti_pp_set_fm_vol_mixer, fm_rx_vol_gain),
  1238. SOC_SINGLE_EXT_TLV("Quat MI2S FM RX Volume", SND_SOC_NOPM, 0,
  1239. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_quat_mi2s_fm_vol_mixer,
  1240. msm_qti_pp_set_quat_mi2s_fm_vol_mixer, fm_rx_vol_gain),
  1241. };
  1242. static const struct snd_kcontrol_new dsp_bit_width_controls[] = {
  1243. SOC_SINGLE_EXT(DSP_BIT_WIDTH_MIXER_CTL, SND_SOC_NOPM, 0, 0x20,
  1244. 0, msm_asm_bit_width_get, msm_asm_bit_width_put),
  1245. };
  1246. static const struct snd_kcontrol_new pri_mi2s_lb_vol_mixer_controls[] = {
  1247. SOC_SINGLE_EXT_TLV("PRI MI2S LOOPBACK Volume", SND_SOC_NOPM, 0,
  1248. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_pri_mi2s_lb_vol_mixer,
  1249. msm_qti_pp_set_pri_mi2s_lb_vol_mixer, afe_lb_vol_gain),
  1250. };
  1251. static const struct snd_kcontrol_new sec_mi2s_lb_vol_mixer_controls[] = {
  1252. SOC_SINGLE_EXT_TLV("SEC MI2S LOOPBACK Volume", SND_SOC_NOPM, 0,
  1253. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_sec_mi2s_lb_vol_mixer,
  1254. msm_qti_pp_set_sec_mi2s_lb_vol_mixer, afe_lb_vol_gain),
  1255. };
  1256. static const struct snd_kcontrol_new tert_mi2s_lb_vol_mixer_controls[] = {
  1257. SOC_SINGLE_EXT_TLV("Tert MI2S LOOPBACK Volume", SND_SOC_NOPM, 0,
  1258. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_tert_mi2s_lb_vol_mixer,
  1259. msm_qti_pp_set_tert_mi2s_lb_vol_mixer, afe_lb_vol_gain),
  1260. };
  1261. static const struct snd_kcontrol_new slimbus_7_lb_vol_mixer_controls[] = {
  1262. SOC_SINGLE_EXT_TLV("SLIMBUS_7 LOOPBACK Volume", SND_SOC_NOPM, 0,
  1263. INT_RX_VOL_GAIN, 0,
  1264. msm_qti_pp_get_slimbus_7_lb_vol_mixer,
  1265. msm_qti_pp_set_slimbus_7_lb_vol_mixer,
  1266. afe_lb_vol_gain),
  1267. };
  1268. static const struct snd_kcontrol_new slimbus_8_lb_vol_mixer_controls[] = {
  1269. SOC_SINGLE_EXT_TLV("SLIMBUS_8 LOOPBACK Volume", SND_SOC_NOPM, 0,
  1270. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_slimbus_8_lb_vol_mixer,
  1271. msm_qti_pp_set_slimbus_8_lb_vol_mixer, afe_lb_vol_gain),
  1272. };
  1273. static const struct snd_kcontrol_new int_hfp_vol_mixer_controls[] = {
  1274. SOC_SINGLE_EXT_TLV("Internal HFP RX Volume", SND_SOC_NOPM, 0,
  1275. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_hfp_vol_mixer,
  1276. msm_qti_pp_set_hfp_vol_mixer, hfp_rx_vol_gain),
  1277. };
  1278. static const struct snd_kcontrol_new int_icc_vol_mixer_controls[] = {
  1279. SOC_SINGLE_EXT_TLV("Internal ICC Volume", SND_SOC_NOPM, 0,
  1280. INT_RX_VOL_GAIN, 0, msm_qti_pp_get_icc_vol_mixer,
  1281. msm_qti_pp_set_icc_vol_mixer, icc_rx_vol_gain),
  1282. };
  1283. static const struct snd_kcontrol_new pri_auxpcm_lb_vol_mixer_controls[] = {
  1284. SOC_SINGLE_EXT_TLV("PRI AUXPCM LOOPBACK Volume",
  1285. AFE_PORT_ID_PRIMARY_PCM_TX, 0, INT_RX_VOL_GAIN, 0,
  1286. msm_qti_pp_get_pri_auxpcm_lb_vol_mixer,
  1287. msm_qti_pp_set_pri_auxpcm_lb_vol_mixer,
  1288. pri_auxpcm_lb_vol_gain),
  1289. };
  1290. static const struct snd_kcontrol_new sec_auxpcm_lb_vol_mixer_controls[] = {
  1291. SOC_SINGLE_EXT_TLV("SEC AUXPCM LOOPBACK Volume",
  1292. AFE_PORT_ID_SECONDARY_PCM_TX, 0, INT_RX_VOL_GAIN, 0,
  1293. msm_qti_pp_get_sec_auxpcm_lb_vol_mixer,
  1294. msm_qti_pp_set_sec_auxpcm_lb_vol_mixer,
  1295. sec_auxpcm_lb_vol_gain),
  1296. };
  1297. static const struct snd_kcontrol_new multi_ch_channel_map_mixer_controls[] = {
  1298. SOC_SINGLE_MULTI_EXT("Playback Device Channel Map", SND_SOC_NOPM,
  1299. 0, PCM_MAX_CHMAP_ID, 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8,
  1300. msm_qti_pp_get_channel_map_mixer,
  1301. msm_qti_pp_put_channel_map_mixer),
  1302. };
  1303. static const struct snd_kcontrol_new multi_ch_channel_map_capture_controls[] = {
  1304. SOC_SINGLE_MULTI_EXT("Capture Device Channel Map", SND_SOC_NOPM,
  1305. 0, PCM_MAX_CHMAP_ID, 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8,
  1306. msm_qti_pp_get_channel_map_capture,
  1307. msm_qti_pp_put_channel_map_capture),
  1308. };
  1309. static const struct snd_kcontrol_new get_rms_controls[] = {
  1310. SOC_SINGLE_EXT("Get RMS", SND_SOC_NOPM, 0, 0xFFFFFFFF,
  1311. 0, msm_qti_pp_get_rms_value_control, msm_qti_pp_put_rms_value_control),
  1312. };
  1313. static const struct snd_kcontrol_new eq_enable_mixer_controls[] = {
  1314. SOC_SINGLE_EXT("MultiMedia1 EQ Enable", SND_SOC_NOPM,
  1315. MSM_FRONTEND_DAI_MULTIMEDIA1, 1, 0, msm_qti_pp_get_eq_enable_mixer,
  1316. msm_qti_pp_put_eq_enable_mixer),
  1317. SOC_SINGLE_EXT("MultiMedia2 EQ Enable", SND_SOC_NOPM,
  1318. MSM_FRONTEND_DAI_MULTIMEDIA2, 1, 0, msm_qti_pp_get_eq_enable_mixer,
  1319. msm_qti_pp_put_eq_enable_mixer),
  1320. SOC_SINGLE_EXT("MultiMedia3 EQ Enable", SND_SOC_NOPM,
  1321. MSM_FRONTEND_DAI_MULTIMEDIA3, 1, 0, msm_qti_pp_get_eq_enable_mixer,
  1322. msm_qti_pp_put_eq_enable_mixer),
  1323. };
  1324. static const struct snd_kcontrol_new eq_band_mixer_controls[] = {
  1325. SOC_SINGLE_EXT("MultiMedia1 EQ Band Count", SND_SOC_NOPM,
  1326. MSM_FRONTEND_DAI_MULTIMEDIA1, 11, 0,
  1327. msm_qti_pp_get_eq_band_count_audio_mixer,
  1328. msm_qti_pp_put_eq_band_count_audio_mixer),
  1329. SOC_SINGLE_EXT("MultiMedia2 EQ Band Count", SND_SOC_NOPM,
  1330. MSM_FRONTEND_DAI_MULTIMEDIA2, 11, 0,
  1331. msm_qti_pp_get_eq_band_count_audio_mixer,
  1332. msm_qti_pp_put_eq_band_count_audio_mixer),
  1333. SOC_SINGLE_EXT("MultiMedia3 EQ Band Count", SND_SOC_NOPM,
  1334. MSM_FRONTEND_DAI_MULTIMEDIA3, 11, 0,
  1335. msm_qti_pp_get_eq_band_count_audio_mixer,
  1336. msm_qti_pp_put_eq_band_count_audio_mixer),
  1337. };
  1338. static const struct snd_kcontrol_new eq_coeff_mixer_controls[] = {
  1339. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band1", EQ_BAND1,
  1340. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1341. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1342. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band2", EQ_BAND2,
  1343. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1344. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1345. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band3", EQ_BAND3,
  1346. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1347. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1348. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band4", EQ_BAND4,
  1349. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1350. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1351. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band5", EQ_BAND5,
  1352. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1353. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1354. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band6", EQ_BAND6,
  1355. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1356. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1357. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band7", EQ_BAND7,
  1358. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1359. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1360. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band8", EQ_BAND8,
  1361. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1362. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1363. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band9", EQ_BAND9,
  1364. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1365. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1366. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band10", EQ_BAND10,
  1367. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1368. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1369. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band11", EQ_BAND11,
  1370. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1371. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1372. SOC_SINGLE_MULTI_EXT("MultiMedia1 EQ Band12", EQ_BAND12,
  1373. MSM_FRONTEND_DAI_MULTIMEDIA1, 255, 0, 5,
  1374. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1375. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band1", EQ_BAND1,
  1376. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1377. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1378. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band2", EQ_BAND2,
  1379. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1380. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1381. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band3", EQ_BAND3,
  1382. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1383. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1384. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band4", EQ_BAND4,
  1385. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1386. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1387. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band5", EQ_BAND5,
  1388. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1389. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1390. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band6", EQ_BAND6,
  1391. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1392. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1393. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band7", EQ_BAND7,
  1394. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1395. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1396. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band8", EQ_BAND8,
  1397. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1398. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1399. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band9", EQ_BAND9,
  1400. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1401. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1402. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band10", EQ_BAND10,
  1403. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1404. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1405. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band11", EQ_BAND11,
  1406. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1407. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1408. SOC_SINGLE_MULTI_EXT("MultiMedia2 EQ Band12", EQ_BAND12,
  1409. MSM_FRONTEND_DAI_MULTIMEDIA2, 255, 0, 5,
  1410. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1411. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band1", EQ_BAND1,
  1412. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1413. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1414. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band2", EQ_BAND2,
  1415. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1416. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1417. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band3", EQ_BAND3,
  1418. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1419. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1420. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band4", EQ_BAND4,
  1421. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1422. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1423. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band5", EQ_BAND5,
  1424. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1425. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1426. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band6", EQ_BAND6,
  1427. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1428. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1429. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band7", EQ_BAND7,
  1430. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1431. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1432. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band8", EQ_BAND8,
  1433. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1434. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1435. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band9", EQ_BAND9,
  1436. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1437. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1438. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band10", EQ_BAND10,
  1439. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1440. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1441. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band11", EQ_BAND11,
  1442. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1443. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1444. SOC_SINGLE_MULTI_EXT("MultiMedia3 EQ Band12", EQ_BAND12,
  1445. MSM_FRONTEND_DAI_MULTIMEDIA3, 255, 0, 5,
  1446. msm_qti_pp_get_eq_band_audio_mixer, msm_qti_pp_put_eq_band_audio_mixer),
  1447. };
  1448. static const struct snd_kcontrol_new asphere_mixer_controls[] = {
  1449. SOC_SINGLE_MULTI_EXT("MSM ASphere Set Param", SND_SOC_NOPM, 0,
  1450. 0xFFFFFFFF, 0, 2, msm_qti_pp_asphere_get, msm_qti_pp_asphere_set),
  1451. };
  1452. static const struct snd_kcontrol_new dtmf_detect_enable_mixer_controls[] = {
  1453. SOC_SINGLE_EXT("MultiMedia1 DTMF Detect Enable", SND_SOC_NOPM,
  1454. MSM_FRONTEND_DAI_MULTIMEDIA1, 1, 0, NULL,
  1455. msm_qti_pp_put_dtmf_module_enable),
  1456. SOC_SINGLE_EXT("MultiMedia6 DTMF Detect Enable", SND_SOC_NOPM,
  1457. MSM_FRONTEND_DAI_MULTIMEDIA6, 1, 0, NULL,
  1458. msm_qti_pp_put_dtmf_module_enable),
  1459. SOC_SINGLE_EXT("MultiMedia21 DTMF Detect Enable", SND_SOC_NOPM,
  1460. MSM_FRONTEND_DAI_MULTIMEDIA21, 1, 0, NULL,
  1461. msm_qti_pp_put_dtmf_module_enable),
  1462. };
  1463. #ifdef CONFIG_QTI_PP
  1464. void msm_qti_pp_add_controls(struct snd_soc_component *component)
  1465. {
  1466. snd_soc_add_component_controls(component, int_fm_vol_mixer_controls,
  1467. ARRAY_SIZE(int_fm_vol_mixer_controls));
  1468. snd_soc_add_component_controls(component,
  1469. pri_mi2s_lb_vol_mixer_controls,
  1470. ARRAY_SIZE(pri_mi2s_lb_vol_mixer_controls));
  1471. snd_soc_add_component_controls(component,
  1472. sec_mi2s_lb_vol_mixer_controls,
  1473. ARRAY_SIZE(sec_mi2s_lb_vol_mixer_controls));
  1474. snd_soc_add_component_controls(component,
  1475. tert_mi2s_lb_vol_mixer_controls,
  1476. ARRAY_SIZE(tert_mi2s_lb_vol_mixer_controls));
  1477. snd_soc_add_component_controls(component,
  1478. slimbus_7_lb_vol_mixer_controls,
  1479. ARRAY_SIZE(slimbus_7_lb_vol_mixer_controls));
  1480. snd_soc_add_component_controls(component,
  1481. slimbus_8_lb_vol_mixer_controls,
  1482. ARRAY_SIZE(slimbus_8_lb_vol_mixer_controls));
  1483. snd_soc_add_component_controls(component, int_hfp_vol_mixer_controls,
  1484. ARRAY_SIZE(int_hfp_vol_mixer_controls));
  1485. snd_soc_add_component_controls(component, int_icc_vol_mixer_controls,
  1486. ARRAY_SIZE(int_icc_vol_mixer_controls));
  1487. snd_soc_add_component_controls(component,
  1488. pri_auxpcm_lb_vol_mixer_controls,
  1489. ARRAY_SIZE(pri_auxpcm_lb_vol_mixer_controls));
  1490. snd_soc_add_component_controls(component,
  1491. sec_auxpcm_lb_vol_mixer_controls,
  1492. ARRAY_SIZE(sec_auxpcm_lb_vol_mixer_controls));
  1493. snd_soc_add_component_controls(component,
  1494. multi_ch_channel_map_mixer_controls,
  1495. ARRAY_SIZE(multi_ch_channel_map_mixer_controls));
  1496. snd_soc_add_component_controls(component, get_rms_controls,
  1497. ARRAY_SIZE(get_rms_controls));
  1498. snd_soc_add_component_controls(component,
  1499. multi_ch_channel_map_capture_controls,
  1500. ARRAY_SIZE(multi_ch_channel_map_capture_controls));
  1501. snd_soc_add_component_controls(component, eq_enable_mixer_controls,
  1502. ARRAY_SIZE(eq_enable_mixer_controls));
  1503. snd_soc_add_component_controls(component, eq_band_mixer_controls,
  1504. ARRAY_SIZE(eq_band_mixer_controls));
  1505. snd_soc_add_component_controls(component, eq_coeff_mixer_controls,
  1506. ARRAY_SIZE(eq_coeff_mixer_controls));
  1507. snd_soc_add_component_controls(component, asphere_mixer_controls,
  1508. ARRAY_SIZE(asphere_mixer_controls));
  1509. snd_soc_add_component_controls(component, msm_multichannel_ec_controls,
  1510. ARRAY_SIZE(msm_multichannel_ec_controls));
  1511. snd_soc_add_component_controls(component, dsp_bit_width_controls,
  1512. ARRAY_SIZE(dsp_bit_width_controls));
  1513. snd_soc_add_component_controls(component, ec_ffecns_controls,
  1514. ARRAY_SIZE(ec_ffecns_controls));
  1515. snd_soc_add_component_controls(component,
  1516. dtmf_detect_enable_mixer_controls,
  1517. ARRAY_SIZE(dtmf_detect_enable_mixer_controls));
  1518. }
  1519. #endif /* CONFIG_QTI_PP */