msm-audio-effects-q6-v2.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/slab.h>
  5. #include <linux/ratelimit.h>
  6. #include <sound/compress_params.h>
  7. #include <audio/sound/devdep_params.h>
  8. #include <dsp/apr_audio-v2.h>
  9. #include <dsp/q6asm-v2.h>
  10. #include <dsp/msm-audio-effects-q6-v2.h>
  11. #include <dsp/q6common.h>
  12. #define MAX_ENABLE_CMD_SIZE 32
  13. #define GET_NEXT(ptr, upper_limit, rc) \
  14. ({ \
  15. if (((ptr) + 1) > (upper_limit)) { \
  16. pr_err_ratelimited("%s: param list out of boundary\n", \
  17. __func__); \
  18. (rc) = -EINVAL; \
  19. } \
  20. ((rc) == 0) ? *(ptr)++ : -EINVAL; \
  21. })
  22. #define CHECK_PARAM_LEN(len, max_len, tag, rc) \
  23. do { \
  24. if ((len) > (max_len)) { \
  25. pr_err_ratelimited("%s: params length overflows\n", \
  26. (tag)); \
  27. (rc) = -EINVAL; \
  28. } \
  29. } while (0)
  30. /**
  31. * msm_audio_effects_is_effmodule_supp_in_top -
  32. * Checks if given topology and module in effects
  33. *
  34. */
  35. bool msm_audio_effects_is_effmodule_supp_in_top(int effect_module,
  36. int topology)
  37. {
  38. switch (effect_module) {
  39. case VIRTUALIZER_MODULE:
  40. case REVERB_MODULE:
  41. case BASS_BOOST_MODULE:
  42. case PBE_MODULE:
  43. case EQ_MODULE:
  44. switch (topology) {
  45. case ASM_STREAM_POSTPROC_TOPO_ID_SA_PLUS:
  46. return true;
  47. default:
  48. return false;
  49. }
  50. default:
  51. return false;
  52. }
  53. }
  54. EXPORT_SYMBOL(msm_audio_effects_is_effmodule_supp_in_top);
  55. int msm_audio_effects_enable_extn(struct audio_client *ac,
  56. struct msm_nt_eff_all_config *effects,
  57. bool flag)
  58. {
  59. u32 flag_param = flag ? 1 : 0;
  60. struct param_hdr_v3 param_hdr;
  61. int rc = 0;
  62. pr_debug("%s\n", __func__);
  63. memset(&param_hdr, 0, sizeof(param_hdr));
  64. param_hdr.module_id = AUDPROC_MODULE_ID_VIRTUALIZER;
  65. param_hdr.instance_id = INSTANCE_ID_0;
  66. param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
  67. param_hdr.param_size = VIRTUALIZER_ENABLE_PARAM_SZ;
  68. if (effects->virtualizer.enable_flag)
  69. rc = q6asm_pack_and_set_pp_param_in_band(ac, param_hdr,
  70. (u8 *) &flag_param);
  71. param_hdr.module_id = AUDPROC_MODULE_ID_BASS_BOOST;
  72. param_hdr.instance_id = INSTANCE_ID_0;
  73. param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
  74. param_hdr.param_size = BASS_BOOST_ENABLE_PARAM_SZ;
  75. if (effects->bass_boost.enable_flag)
  76. rc = q6asm_pack_and_set_pp_param_in_band(ac, param_hdr,
  77. (u8 *) &flag_param);
  78. param_hdr.module_id = AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
  79. param_hdr.instance_id = INSTANCE_ID_0;
  80. param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
  81. param_hdr.param_size = EQ_ENABLE_PARAM_SZ;
  82. if (effects->equalizer.enable_flag)
  83. rc = q6asm_pack_and_set_pp_param_in_band(ac, param_hdr,
  84. (u8 *) &flag_param);
  85. return rc;
  86. }
  87. /**
  88. * msm_audio_effects_virtualizer_handler -
  89. * Audio effects handler for virtualizer
  90. *
  91. * @ac: audio client handle
  92. * @pbe: virtualizer params
  93. * @values: values to be updated
  94. *
  95. * Return 0 on success or error on failure
  96. */
  97. int msm_audio_effects_virtualizer_handler(struct audio_client *ac,
  98. struct virtualizer_params *virtualizer,
  99. long *values)
  100. {
  101. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  102. char *params = NULL;
  103. u8 *updt_params;
  104. int rc = 0;
  105. int devices = GET_NEXT(values, param_max_offset, rc);
  106. int num_commands = GET_NEXT(values, param_max_offset, rc);
  107. int i, prev_enable_flag;
  108. uint32_t max_params_length = 0;
  109. uint32_t params_length = 0;
  110. struct param_hdr_v3 param_hdr;
  111. u8 *param_data = NULL;
  112. u32 packed_data_size = 0;
  113. pr_debug("%s\n", __func__);
  114. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  115. pr_err("%s: cannot set audio effects\n", __func__);
  116. return -EINVAL;
  117. }
  118. params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
  119. if (!params) {
  120. pr_err("%s, params memory alloc failed\n", __func__);
  121. return -ENOMEM;
  122. }
  123. pr_debug("%s: device: %d\n", __func__, devices);
  124. updt_params = (u8 *) params;
  125. /* Set MID and IID once at top and only update param specific fields*/
  126. memset(&param_hdr, 0, sizeof(param_hdr));
  127. param_hdr.module_id = AUDPROC_MODULE_ID_VIRTUALIZER;
  128. param_hdr.instance_id = INSTANCE_ID_0;
  129. for (i = 0; i < num_commands; i++) {
  130. uint32_t command_id =
  131. GET_NEXT(values, param_max_offset, rc);
  132. uint32_t command_config_state =
  133. GET_NEXT(values, param_max_offset, rc);
  134. uint32_t index_offset =
  135. GET_NEXT(values, param_max_offset, rc);
  136. uint32_t length =
  137. GET_NEXT(values, param_max_offset, rc);
  138. switch (command_id) {
  139. case VIRTUALIZER_ENABLE:
  140. if (length != 1 || index_offset != 0) {
  141. pr_err("VIRT ENABLE:invalid params\n");
  142. rc = -EINVAL;
  143. goto invalid_config;
  144. }
  145. prev_enable_flag = virtualizer->enable_flag;
  146. virtualizer->enable_flag =
  147. GET_NEXT(values, param_max_offset, rc);
  148. pr_debug("%s:VIRT ENABLE prev:%d, new:%d\n", __func__,
  149. prev_enable_flag, virtualizer->enable_flag);
  150. if (prev_enable_flag == virtualizer->enable_flag)
  151. continue;
  152. max_params_length = params_length +
  153. COMMAND_IID_PAYLOAD_SZ +
  154. VIRTUALIZER_ENABLE_PARAM_SZ;
  155. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  156. "VIRT ENABLE", rc);
  157. if (rc != 0)
  158. break;
  159. param_hdr.param_id =
  160. AUDPROC_PARAM_ID_VIRTUALIZER_ENABLE;
  161. param_hdr.param_size = VIRTUALIZER_ENABLE_PARAM_SZ;
  162. param_data = (u8 *) &virtualizer->enable_flag;
  163. break;
  164. case VIRTUALIZER_STRENGTH:
  165. if (length != 1 || index_offset != 0) {
  166. pr_err("VIRT STRENGTH:invalid params\n");
  167. rc = -EINVAL;
  168. goto invalid_config;
  169. }
  170. virtualizer->strength =
  171. GET_NEXT(values, param_max_offset, rc);
  172. pr_debug("%s: VIRT STRENGTH val: %d\n",
  173. __func__, virtualizer->strength);
  174. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  175. break;
  176. max_params_length = params_length +
  177. COMMAND_IID_PAYLOAD_SZ +
  178. VIRTUALIZER_STRENGTH_PARAM_SZ;
  179. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  180. "VIRT STRENGTH", rc);
  181. if (rc != 0)
  182. break;
  183. param_hdr.param_id =
  184. AUDPROC_PARAM_ID_VIRTUALIZER_STRENGTH;
  185. param_hdr.param_size = VIRTUALIZER_STRENGTH_PARAM_SZ;
  186. param_data = (u8 *) &virtualizer->strength;
  187. break;
  188. case VIRTUALIZER_OUT_TYPE:
  189. if (length != 1 || index_offset != 0) {
  190. pr_err("VIRT OUT_TYPE:invalid params\n");
  191. rc = -EINVAL;
  192. goto invalid_config;
  193. }
  194. virtualizer->out_type =
  195. GET_NEXT(values, param_max_offset, rc);
  196. pr_debug("%s: VIRT OUT_TYPE val:%d\n",
  197. __func__, virtualizer->out_type);
  198. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  199. break;
  200. max_params_length = params_length +
  201. COMMAND_IID_PAYLOAD_SZ +
  202. VIRTUALIZER_OUT_TYPE_PARAM_SZ;
  203. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  204. "VIRT OUT_TYPE", rc);
  205. if (rc != 0)
  206. break;
  207. param_hdr.param_id =
  208. AUDPROC_PARAM_ID_VIRTUALIZER_OUT_TYPE;
  209. param_hdr.param_size = VIRTUALIZER_OUT_TYPE_PARAM_SZ;
  210. param_data = (u8 *) &virtualizer->out_type;
  211. break;
  212. case VIRTUALIZER_GAIN_ADJUST:
  213. if (length != 1 || index_offset != 0) {
  214. pr_err("VIRT GAIN_ADJUST: invalid params\n");
  215. rc = -EINVAL;
  216. goto invalid_config;
  217. }
  218. virtualizer->gain_adjust =
  219. GET_NEXT(values, param_max_offset, rc);
  220. pr_debug("%s: VIRT GAIN_ADJUST val:%d\n",
  221. __func__, virtualizer->gain_adjust);
  222. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  223. break;
  224. max_params_length = params_length +
  225. COMMAND_IID_PAYLOAD_SZ +
  226. VIRTUALIZER_GAIN_ADJUST_PARAM_SZ;
  227. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  228. "VIRT GAIN_ADJUST", rc);
  229. if (rc != 0)
  230. break;
  231. param_hdr.param_id =
  232. AUDPROC_PARAM_ID_VIRTUALIZER_GAIN_ADJUST;
  233. param_hdr.param_size = VIRTUALIZER_GAIN_ADJUST_PARAM_SZ;
  234. param_data = (u8 *) &virtualizer->gain_adjust;
  235. break;
  236. default:
  237. pr_err_ratelimited("%s: Invalid command to set config\n",
  238. __func__);
  239. continue;
  240. }
  241. if (rc)
  242. goto invalid_config;
  243. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  244. param_data, &packed_data_size);
  245. if (rc) {
  246. pr_err("%s: Failed to pack params, error %d\n",
  247. __func__, rc);
  248. goto invalid_config;
  249. }
  250. updt_params += packed_data_size;
  251. params_length += packed_data_size;
  252. }
  253. if (params_length && (rc == 0))
  254. q6asm_set_pp_params(ac, NULL, params, params_length);
  255. else
  256. pr_debug("%s: did not send pp params\n", __func__);
  257. invalid_config:
  258. kfree(params);
  259. return rc;
  260. }
  261. EXPORT_SYMBOL(msm_audio_effects_virtualizer_handler);
  262. /**
  263. * msm_audio_effects_reverb_handler -
  264. * Audio effects handler for reverb
  265. *
  266. * @ac: audio client handle
  267. * @pbe: reverb params
  268. * @values: values to be updated
  269. *
  270. * Return 0 on success or error on failure
  271. */
  272. int msm_audio_effects_reverb_handler(struct audio_client *ac,
  273. struct reverb_params *reverb,
  274. long *values)
  275. {
  276. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  277. char *params = NULL;
  278. u8 *updt_params;
  279. int rc = 0;
  280. int devices = GET_NEXT(values, param_max_offset, rc);
  281. int num_commands = GET_NEXT(values, param_max_offset, rc);
  282. int i, prev_enable_flag;
  283. uint32_t max_params_length = 0;
  284. uint32_t params_length = 0;
  285. struct param_hdr_v3 param_hdr;
  286. u8 *param_data = NULL;
  287. u32 packed_data_size = 0;
  288. pr_debug("%s\n", __func__);
  289. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  290. pr_err("%s: cannot set audio effects\n", __func__);
  291. return -EINVAL;
  292. }
  293. params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
  294. if (!params) {
  295. pr_err("%s, params memory alloc failed\n", __func__);
  296. return -ENOMEM;
  297. }
  298. pr_debug("%s: device: %d\n", __func__, devices);
  299. updt_params = (u8 *) params;
  300. /* Set MID and IID once at top and only update param specific fields*/
  301. memset(&param_hdr, 0, sizeof(param_hdr));
  302. param_hdr.module_id = AUDPROC_MODULE_ID_REVERB;
  303. param_hdr.instance_id = INSTANCE_ID_0;
  304. for (i = 0; i < num_commands; i++) {
  305. uint32_t command_id =
  306. GET_NEXT(values, param_max_offset, rc);
  307. uint32_t command_config_state =
  308. GET_NEXT(values, param_max_offset, rc);
  309. uint32_t index_offset =
  310. GET_NEXT(values, param_max_offset, rc);
  311. uint32_t length =
  312. GET_NEXT(values, param_max_offset, rc);
  313. switch (command_id) {
  314. case REVERB_ENABLE:
  315. if (length != 1 || index_offset != 0) {
  316. pr_err("REVERB_ENABLE:invalid params\n");
  317. rc = -EINVAL;
  318. goto invalid_config;
  319. }
  320. prev_enable_flag = reverb->enable_flag;
  321. reverb->enable_flag =
  322. GET_NEXT(values, param_max_offset, rc);
  323. pr_debug("%s:REVERB_ENABLE prev:%d,new:%d\n", __func__,
  324. prev_enable_flag, reverb->enable_flag);
  325. if (prev_enable_flag == reverb->enable_flag)
  326. continue;
  327. max_params_length = params_length +
  328. COMMAND_IID_PAYLOAD_SZ +
  329. REVERB_ENABLE_PARAM_SZ;
  330. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  331. "REVERB_ENABLE", rc);
  332. if (rc != 0)
  333. break;
  334. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_ENABLE;
  335. param_hdr.param_size = REVERB_ENABLE_PARAM_SZ;
  336. param_data = (u8 *) &reverb->enable_flag;
  337. break;
  338. case REVERB_MODE:
  339. if (length != 1 || index_offset != 0) {
  340. pr_err("REVERB_MODE:invalid params\n");
  341. rc = -EINVAL;
  342. goto invalid_config;
  343. }
  344. reverb->mode =
  345. GET_NEXT(values, param_max_offset, rc);
  346. pr_debug("%s: REVERB_MODE val:%d\n",
  347. __func__, reverb->mode);
  348. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  349. break;
  350. max_params_length = params_length +
  351. COMMAND_IID_PAYLOAD_SZ +
  352. REVERB_MODE_PARAM_SZ;
  353. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  354. "REVERB_MODE", rc);
  355. if (rc != 0)
  356. break;
  357. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_MODE;
  358. param_hdr.param_size = REVERB_MODE_PARAM_SZ;
  359. param_data = (u8 *) &reverb->mode;
  360. break;
  361. case REVERB_PRESET:
  362. if (length != 1 || index_offset != 0) {
  363. pr_err("REVERB_PRESET:invalid params\n");
  364. rc = -EINVAL;
  365. goto invalid_config;
  366. }
  367. reverb->preset =
  368. GET_NEXT(values, param_max_offset, rc);
  369. pr_debug("%s: REVERB_PRESET val:%d\n",
  370. __func__, reverb->preset);
  371. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  372. break;
  373. max_params_length = params_length +
  374. COMMAND_IID_PAYLOAD_SZ +
  375. REVERB_PRESET_PARAM_SZ;
  376. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  377. "REVERB_PRESET", rc);
  378. if (rc != 0)
  379. break;
  380. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_PRESET;
  381. param_hdr.param_size = REVERB_PRESET_PARAM_SZ;
  382. param_data = (u8 *) &reverb->preset;
  383. break;
  384. case REVERB_WET_MIX:
  385. if (length != 1 || index_offset != 0) {
  386. pr_err("REVERB_WET_MIX:invalid params\n");
  387. rc = -EINVAL;
  388. goto invalid_config;
  389. }
  390. reverb->wet_mix =
  391. GET_NEXT(values, param_max_offset, rc);
  392. pr_debug("%s: REVERB_WET_MIX val:%d\n",
  393. __func__, reverb->wet_mix);
  394. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  395. break;
  396. max_params_length = params_length +
  397. COMMAND_IID_PAYLOAD_SZ +
  398. REVERB_WET_MIX_PARAM_SZ;
  399. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  400. "REVERB_WET_MIX", rc);
  401. if (rc != 0)
  402. break;
  403. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_WET_MIX;
  404. param_hdr.param_size = REVERB_WET_MIX_PARAM_SZ;
  405. param_data = (u8 *) &reverb->wet_mix;
  406. break;
  407. case REVERB_GAIN_ADJUST:
  408. if (length != 1 || index_offset != 0) {
  409. pr_err("REVERB_GAIN_ADJUST:invalid params\n");
  410. rc = -EINVAL;
  411. goto invalid_config;
  412. }
  413. reverb->gain_adjust =
  414. GET_NEXT(values, param_max_offset, rc);
  415. pr_debug("%s: REVERB_GAIN_ADJUST val:%d\n",
  416. __func__, reverb->gain_adjust);
  417. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  418. break;
  419. max_params_length = params_length +
  420. COMMAND_IID_PAYLOAD_SZ +
  421. REVERB_GAIN_ADJUST_PARAM_SZ;
  422. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  423. "REVERB_GAIN_ADJUST", rc);
  424. if (rc != 0)
  425. break;
  426. param_hdr.param_id =
  427. AUDPROC_PARAM_ID_REVERB_GAIN_ADJUST;
  428. param_hdr.param_size = REVERB_GAIN_ADJUST_PARAM_SZ;
  429. param_data = (u8 *) &reverb->gain_adjust;
  430. break;
  431. case REVERB_ROOM_LEVEL:
  432. if (length != 1 || index_offset != 0) {
  433. pr_err("REVERB_ROOM_LEVEL:invalid params\n");
  434. rc = -EINVAL;
  435. goto invalid_config;
  436. }
  437. reverb->room_level =
  438. GET_NEXT(values, param_max_offset, rc);
  439. pr_debug("%s: REVERB_ROOM_LEVEL val:%d\n",
  440. __func__, reverb->room_level);
  441. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  442. break;
  443. max_params_length = params_length +
  444. COMMAND_IID_PAYLOAD_SZ +
  445. REVERB_ROOM_LEVEL_PARAM_SZ;
  446. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  447. "REVERB_ROOM_LEVEL", rc);
  448. if (rc != 0)
  449. break;
  450. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_ROOM_LEVEL;
  451. param_hdr.param_size = REVERB_ROOM_LEVEL_PARAM_SZ;
  452. param_data = (u8 *) &reverb->room_level;
  453. break;
  454. case REVERB_ROOM_HF_LEVEL:
  455. if (length != 1 || index_offset != 0) {
  456. pr_err("REVERB_ROOM_HF_LEVEL:invalid params\n");
  457. rc = -EINVAL;
  458. goto invalid_config;
  459. }
  460. reverb->room_hf_level =
  461. GET_NEXT(values, param_max_offset, rc);
  462. pr_debug("%s: REVERB_ROOM_HF_LEVEL val%d\n",
  463. __func__, reverb->room_hf_level);
  464. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  465. break;
  466. max_params_length = params_length +
  467. COMMAND_IID_PAYLOAD_SZ +
  468. REVERB_ROOM_HF_LEVEL_PARAM_SZ;
  469. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  470. "REVERB_ROOM_HF_LEVEL", rc);
  471. if (rc != 0)
  472. break;
  473. param_hdr.param_id =
  474. AUDPROC_PARAM_ID_REVERB_ROOM_HF_LEVEL;
  475. param_hdr.param_size = REVERB_ROOM_HF_LEVEL_PARAM_SZ;
  476. param_data = (u8 *) &reverb->room_hf_level;
  477. break;
  478. case REVERB_DECAY_TIME:
  479. if (length != 1 || index_offset != 0) {
  480. pr_err("REVERB_DECAY_TIME:invalid params\n");
  481. rc = -EINVAL;
  482. goto invalid_config;
  483. }
  484. reverb->decay_time =
  485. GET_NEXT(values, param_max_offset, rc);
  486. pr_debug("%s: REVERB_DECAY_TIME val:%d\n",
  487. __func__, reverb->decay_time);
  488. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  489. break;
  490. max_params_length = params_length +
  491. COMMAND_IID_PAYLOAD_SZ +
  492. REVERB_DECAY_TIME_PARAM_SZ;
  493. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  494. "REVERB_DECAY_TIME", rc);
  495. if (rc != 0)
  496. break;
  497. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DECAY_TIME;
  498. param_hdr.param_size = REVERB_DECAY_TIME_PARAM_SZ;
  499. param_data = (u8 *) &reverb->decay_time;
  500. break;
  501. case REVERB_DECAY_HF_RATIO:
  502. if (length != 1 || index_offset != 0) {
  503. pr_err("REVERB_DECAY_HF_RATIOinvalid params\n");
  504. rc = -EINVAL;
  505. goto invalid_config;
  506. }
  507. reverb->decay_hf_ratio =
  508. GET_NEXT(values, param_max_offset, rc);
  509. pr_debug("%s: REVERB_DECAY_HF_RATIO val%d\n",
  510. __func__, reverb->decay_hf_ratio);
  511. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  512. break;
  513. max_params_length = params_length +
  514. COMMAND_IID_PAYLOAD_SZ +
  515. REVERB_DECAY_HF_RATIO_PARAM_SZ;
  516. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  517. "REVERB_DECAY_HF_RATIO", rc);
  518. if (rc != 0)
  519. break;
  520. param_hdr.param_id =
  521. AUDPROC_PARAM_ID_REVERB_DECAY_HF_RATIO;
  522. param_hdr.param_size = REVERB_DECAY_HF_RATIO_PARAM_SZ;
  523. param_data = (u8 *) &reverb->decay_hf_ratio;
  524. break;
  525. case REVERB_REFLECTIONS_LEVEL:
  526. if (length != 1 || index_offset != 0) {
  527. pr_err("REVERB_REFLECTION_LVLinvalid params\n");
  528. rc = -EINVAL;
  529. goto invalid_config;
  530. }
  531. reverb->reflections_level =
  532. GET_NEXT(values, param_max_offset, rc);
  533. pr_debug("%s: REVERB_REFLECTIONS_LEVEL val:%d\n",
  534. __func__, reverb->reflections_level);
  535. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  536. break;
  537. max_params_length = params_length +
  538. COMMAND_IID_PAYLOAD_SZ +
  539. REVERB_REFLECTIONS_LEVEL_PARAM_SZ;
  540. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  541. "REVERB_REFLECTIONS_LEVEL", rc);
  542. if (rc != 0)
  543. break;
  544. param_hdr.param_id =
  545. AUDPROC_PARAM_ID_REVERB_REFLECTIONS_LEVEL;
  546. param_hdr.param_size =
  547. REVERB_REFLECTIONS_LEVEL_PARAM_SZ;
  548. param_data = (u8 *) &reverb->reflections_level;
  549. break;
  550. case REVERB_REFLECTIONS_DELAY:
  551. if (length != 1 || index_offset != 0) {
  552. pr_err("REVERB_REFLECTION_DLYinvalid params\n");
  553. rc = -EINVAL;
  554. goto invalid_config;
  555. }
  556. reverb->reflections_delay =
  557. GET_NEXT(values, param_max_offset, rc);
  558. pr_debug("%s: REVERB_REFLECTIONS_DELAY val:%d\n",
  559. __func__, reverb->reflections_delay);
  560. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  561. break;
  562. max_params_length = params_length +
  563. COMMAND_IID_PAYLOAD_SZ +
  564. REVERB_REFLECTIONS_DELAY_PARAM_SZ;
  565. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  566. "REVERB_REFLECTIONS_DELAY", rc);
  567. if (rc != 0)
  568. break;
  569. param_hdr.param_id =
  570. AUDPROC_PARAM_ID_REVERB_REFLECTIONS_DELAY;
  571. param_hdr.param_size =
  572. REVERB_REFLECTIONS_DELAY_PARAM_SZ;
  573. param_data = (u8 *) &reverb->reflections_delay;
  574. break;
  575. case REVERB_LEVEL:
  576. if (length != 1 || index_offset != 0) {
  577. pr_err("REVERB_LEVEL:invalid params\n");
  578. rc = -EINVAL;
  579. goto invalid_config;
  580. }
  581. reverb->level =
  582. GET_NEXT(values, param_max_offset, rc);
  583. pr_debug("%s: REVERB_LEVEL val:%d\n",
  584. __func__, reverb->level);
  585. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  586. break;
  587. max_params_length = params_length +
  588. COMMAND_IID_PAYLOAD_SZ +
  589. REVERB_LEVEL_PARAM_SZ;
  590. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  591. "REVERB_LEVEL", rc);
  592. if (rc != 0)
  593. break;
  594. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_LEVEL;
  595. param_hdr.param_size = REVERB_LEVEL_PARAM_SZ;
  596. param_data = (u8 *) &reverb->level;
  597. break;
  598. case REVERB_DELAY:
  599. if (length != 1 || index_offset != 0) {
  600. pr_err("REVERB_DELAY:invalid params\n");
  601. rc = -EINVAL;
  602. goto invalid_config;
  603. }
  604. reverb->delay =
  605. GET_NEXT(values, param_max_offset, rc);
  606. pr_debug("%s:REVERB_DELAY val:%d\n",
  607. __func__, reverb->delay);
  608. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  609. break;
  610. max_params_length = params_length +
  611. COMMAND_IID_PAYLOAD_SZ +
  612. REVERB_DELAY_PARAM_SZ;
  613. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  614. "REVERB_DELAY", rc);
  615. if (rc != 0)
  616. break;
  617. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DELAY;
  618. param_hdr.param_size = REVERB_DELAY_PARAM_SZ;
  619. param_data = (u8 *) &reverb->delay;
  620. break;
  621. case REVERB_DIFFUSION:
  622. if (length != 1 || index_offset != 0) {
  623. pr_err("REVERB_DIFFUSION:invalid params\n");
  624. rc = -EINVAL;
  625. goto invalid_config;
  626. }
  627. reverb->diffusion =
  628. GET_NEXT(values, param_max_offset, rc);
  629. pr_debug("%s: REVERB_DIFFUSION val:%d\n",
  630. __func__, reverb->diffusion);
  631. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  632. break;
  633. max_params_length = params_length +
  634. COMMAND_IID_PAYLOAD_SZ +
  635. REVERB_DIFFUSION_PARAM_SZ;
  636. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  637. "REVERB_DIFFUSION", rc);
  638. if (rc != 0)
  639. break;
  640. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DIFFUSION;
  641. param_hdr.param_size = REVERB_DIFFUSION_PARAM_SZ;
  642. param_data = (u8 *) &reverb->diffusion;
  643. break;
  644. case REVERB_DENSITY:
  645. if (length != 1 || index_offset != 0) {
  646. pr_err("REVERB_DENSITY:invalid params\n");
  647. rc = -EINVAL;
  648. goto invalid_config;
  649. }
  650. reverb->density =
  651. GET_NEXT(values, param_max_offset, rc);
  652. pr_debug("%s: REVERB_DENSITY val:%d\n",
  653. __func__, reverb->density);
  654. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  655. break;
  656. max_params_length = params_length +
  657. COMMAND_IID_PAYLOAD_SZ +
  658. REVERB_DENSITY_PARAM_SZ;
  659. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  660. "REVERB_DENSITY", rc);
  661. if (rc != 0)
  662. break;
  663. param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DENSITY;
  664. param_hdr.param_size = REVERB_DENSITY_PARAM_SZ;
  665. param_data = (u8 *) &reverb->density;
  666. break;
  667. default:
  668. pr_err_ratelimited("%s: Invalid command to set config\n",
  669. __func__);
  670. continue;
  671. }
  672. if (rc)
  673. goto invalid_config;
  674. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  675. param_data, &packed_data_size);
  676. if (rc) {
  677. pr_err("%s: Failed to pack params, error %d\n",
  678. __func__, rc);
  679. goto invalid_config;
  680. }
  681. updt_params += packed_data_size;
  682. params_length += packed_data_size;
  683. }
  684. if (params_length && (rc == 0))
  685. q6asm_set_pp_params(ac, NULL, params, params_length);
  686. else
  687. pr_debug("%s: did not send pp params\n", __func__);
  688. invalid_config:
  689. kfree(params);
  690. return rc;
  691. }
  692. EXPORT_SYMBOL(msm_audio_effects_reverb_handler);
  693. /**
  694. * msm_audio_effects_bass_boost_handler -
  695. * Audio effects handler for bass_boost
  696. *
  697. * @ac: audio client handle
  698. * @bass_boost: bass_boost params
  699. * @values: values to be updated
  700. *
  701. * Return 0 on success or error on failure
  702. */
  703. int msm_audio_effects_bass_boost_handler(struct audio_client *ac,
  704. struct bass_boost_params *bass_boost,
  705. long *values)
  706. {
  707. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  708. char *params = NULL;
  709. u8 *updt_params;
  710. int rc = 0;
  711. int devices = GET_NEXT(values, param_max_offset, rc);
  712. int num_commands = GET_NEXT(values, param_max_offset, rc);
  713. int i, prev_enable_flag;
  714. uint32_t max_params_length = 0;
  715. uint32_t params_length = 0;
  716. struct param_hdr_v3 param_hdr;
  717. u8 *param_data = NULL;
  718. u32 packed_data_size = 0;
  719. pr_debug("%s\n", __func__);
  720. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  721. pr_err("%s: cannot set audio effects\n", __func__);
  722. return -EINVAL;
  723. }
  724. params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
  725. if (!params) {
  726. pr_err("%s, params memory alloc failed\n", __func__);
  727. return -ENOMEM;
  728. }
  729. pr_debug("%s: device: %d\n", __func__, devices);
  730. updt_params = (u8 *) params;
  731. /* Set MID and IID once at top and only update param specific fields*/
  732. memset(&param_hdr, 0, sizeof(param_hdr));
  733. param_hdr.module_id = AUDPROC_MODULE_ID_BASS_BOOST;
  734. param_hdr.instance_id = INSTANCE_ID_0;
  735. for (i = 0; i < num_commands; i++) {
  736. uint32_t command_id =
  737. GET_NEXT(values, param_max_offset, rc);
  738. uint32_t command_config_state =
  739. GET_NEXT(values, param_max_offset, rc);
  740. uint32_t index_offset =
  741. GET_NEXT(values, param_max_offset, rc);
  742. uint32_t length =
  743. GET_NEXT(values, param_max_offset, rc);
  744. switch (command_id) {
  745. case BASS_BOOST_ENABLE:
  746. if (length != 1 || index_offset != 0) {
  747. pr_err("BASS_BOOST_ENABLE:invalid params\n");
  748. rc = -EINVAL;
  749. goto invalid_config;
  750. }
  751. prev_enable_flag = bass_boost->enable_flag;
  752. bass_boost->enable_flag =
  753. GET_NEXT(values, param_max_offset, rc);
  754. pr_debug("%s: BASS_BOOST_ENABLE prev:%d new:%d\n",
  755. __func__, prev_enable_flag,
  756. bass_boost->enable_flag);
  757. if (prev_enable_flag == bass_boost->enable_flag)
  758. continue;
  759. max_params_length = params_length +
  760. COMMAND_IID_PAYLOAD_SZ +
  761. BASS_BOOST_ENABLE_PARAM_SZ;
  762. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  763. "BASS_BOOST_ENABLE", rc);
  764. if (rc != 0)
  765. break;
  766. param_hdr.param_id = AUDPROC_PARAM_ID_BASS_BOOST_ENABLE;
  767. param_hdr.param_size = BASS_BOOST_ENABLE_PARAM_SZ;
  768. param_data = (u8 *) &bass_boost->enable_flag;
  769. break;
  770. case BASS_BOOST_MODE:
  771. if (length != 1 || index_offset != 0) {
  772. pr_err("BASS_BOOST_MODE:invalid params\n");
  773. rc = -EINVAL;
  774. goto invalid_config;
  775. }
  776. bass_boost->mode =
  777. GET_NEXT(values, param_max_offset, rc);
  778. pr_debug("%s: BASS_BOOST_MODE val:%d\n",
  779. __func__, bass_boost->mode);
  780. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  781. break;
  782. max_params_length = params_length +
  783. COMMAND_IID_PAYLOAD_SZ +
  784. BASS_BOOST_MODE_PARAM_SZ;
  785. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  786. "BASS_BOOST_MODE", rc);
  787. if (rc != 0)
  788. break;
  789. param_hdr.param_id = AUDPROC_PARAM_ID_BASS_BOOST_MODE;
  790. param_hdr.param_size = BASS_BOOST_MODE_PARAM_SZ;
  791. param_data = (u8 *) &bass_boost->mode;
  792. break;
  793. case BASS_BOOST_STRENGTH:
  794. if (length != 1 || index_offset != 0) {
  795. pr_err("BASS_BOOST_STRENGTH:invalid params\n");
  796. rc = -EINVAL;
  797. goto invalid_config;
  798. }
  799. bass_boost->strength =
  800. GET_NEXT(values, param_max_offset, rc);
  801. pr_debug("%s: BASS_BOOST_STRENGTH val:%d\n",
  802. __func__, bass_boost->strength);
  803. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  804. break;
  805. max_params_length = params_length +
  806. COMMAND_IID_PAYLOAD_SZ +
  807. BASS_BOOST_STRENGTH_PARAM_SZ;
  808. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  809. "BASS_BOOST_STRENGTH", rc);
  810. if (rc != 0)
  811. break;
  812. param_hdr.param_id =
  813. AUDPROC_PARAM_ID_BASS_BOOST_STRENGTH;
  814. param_hdr.param_size = BASS_BOOST_STRENGTH_PARAM_SZ;
  815. param_data = (u8 *) &bass_boost->strength;
  816. break;
  817. default:
  818. pr_err_ratelimited("%s: Invalid command to set config\n",
  819. __func__);
  820. continue;
  821. }
  822. if (rc)
  823. goto invalid_config;
  824. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  825. param_data, &packed_data_size);
  826. if (rc) {
  827. pr_err("%s: Failed to pack params, error %d\n",
  828. __func__, rc);
  829. goto invalid_config;
  830. }
  831. updt_params += packed_data_size;
  832. params_length += packed_data_size;
  833. }
  834. if (params_length && (rc == 0))
  835. q6asm_set_pp_params(ac, NULL, params, params_length);
  836. else
  837. pr_debug("%s: did not send pp params\n", __func__);
  838. invalid_config:
  839. kfree(params);
  840. return rc;
  841. }
  842. EXPORT_SYMBOL(msm_audio_effects_bass_boost_handler);
  843. /**
  844. * msm_audio_effects_pbe_handler -
  845. * Audio effects handler for pbe
  846. *
  847. * @ac: audio client handle
  848. * @pbe: pbe params
  849. * @values: values to be updated
  850. *
  851. * Return 0 on success or error on failure
  852. */
  853. int msm_audio_effects_pbe_handler(struct audio_client *ac,
  854. struct pbe_params *pbe,
  855. long *values)
  856. {
  857. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  858. char *params = NULL;
  859. u8 *updt_params;
  860. int rc = 0;
  861. int devices = GET_NEXT(values, param_max_offset, rc);
  862. int num_commands = GET_NEXT(values, param_max_offset, rc);
  863. int i, prev_enable_flag;
  864. uint32_t max_params_length = 0;
  865. uint32_t params_length = 0;
  866. struct param_hdr_v3 param_hdr;
  867. u8 *param_data = NULL;
  868. u32 packed_data_size = 0;
  869. int32_t *p_coeffs = NULL;
  870. uint32_t lpf_len = 0, hpf_len = 0, bpf_len = 0;
  871. uint32_t bsf_len = 0, tsf_len = 0, total_coeffs_len = 0;
  872. pr_debug("%s\n", __func__);
  873. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  874. pr_err("%s: cannot set audio effects\n", __func__);
  875. return -EINVAL;
  876. }
  877. params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
  878. if (!params) {
  879. pr_err("%s, params memory alloc failed\n", __func__);
  880. return -ENOMEM;
  881. }
  882. pr_debug("%s: device: %d\n", __func__, devices);
  883. updt_params = (u8 *) params;
  884. /* Set MID and IID once at top and only update param specific fields*/
  885. memset(&param_hdr, 0, sizeof(param_hdr));
  886. param_hdr.module_id = AUDPROC_MODULE_ID_PBE;
  887. param_hdr.instance_id = INSTANCE_ID_0;
  888. for (i = 0; i < num_commands; i++) {
  889. uint32_t command_id =
  890. GET_NEXT(values, param_max_offset, rc);
  891. uint32_t command_config_state =
  892. GET_NEXT(values, param_max_offset, rc);
  893. uint32_t index_offset =
  894. GET_NEXT(values, param_max_offset, rc);
  895. uint32_t length =
  896. GET_NEXT(values, param_max_offset, rc);
  897. switch (command_id) {
  898. case PBE_ENABLE:
  899. pr_debug("%s: PBE_ENABLE\n", __func__);
  900. if (length != 1 || index_offset != 0) {
  901. pr_err("no valid params\n");
  902. rc = -EINVAL;
  903. goto invalid_config;
  904. }
  905. prev_enable_flag = pbe->enable_flag;
  906. pbe->enable_flag =
  907. GET_NEXT(values, param_max_offset, rc);
  908. if (prev_enable_flag == pbe->enable_flag)
  909. continue;
  910. max_params_length = params_length +
  911. COMMAND_IID_PAYLOAD_SZ +
  912. PBE_ENABLE_PARAM_SZ;
  913. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  914. "PBE_ENABLE", rc);
  915. if (rc != 0)
  916. break;
  917. param_hdr.param_id = AUDPROC_PARAM_ID_PBE_ENABLE;
  918. param_hdr.param_size = PBE_ENABLE_PARAM_SZ;
  919. param_data = (u8 *) &pbe->enable_flag;
  920. break;
  921. case PBE_CONFIG:
  922. pr_debug("%s: PBE_PARAM length %u\n", __func__, length);
  923. if (length > sizeof(struct pbe_config_t) ||
  924. length < PBE_CONFIG_PARAM_LEN ||
  925. index_offset != 0) {
  926. pr_err("no valid params, len %d\n", length);
  927. rc = -EINVAL;
  928. goto invalid_config;
  929. }
  930. pbe->config.real_bass_mix =
  931. GET_NEXT(values, param_max_offset, rc);
  932. pbe->config.bass_color_control =
  933. GET_NEXT(values, param_max_offset, rc);
  934. pbe->config.main_chain_delay =
  935. GET_NEXT(values, param_max_offset, rc);
  936. pbe->config.xover_filter_order =
  937. GET_NEXT(values, param_max_offset, rc);
  938. pbe->config.bandpass_filter_order =
  939. GET_NEXT(values, param_max_offset, rc);
  940. pbe->config.drc_delay =
  941. GET_NEXT(values, param_max_offset, rc);
  942. pbe->config.rms_tav =
  943. GET_NEXT(values, param_max_offset, rc);
  944. pbe->config.exp_threshold =
  945. GET_NEXT(values, param_max_offset, rc);
  946. pbe->config.exp_slope =
  947. GET_NEXT(values, param_max_offset, rc);
  948. pbe->config.comp_threshold =
  949. GET_NEXT(values, param_max_offset, rc);
  950. pbe->config.comp_slope =
  951. GET_NEXT(values, param_max_offset, rc);
  952. pbe->config.makeup_gain =
  953. GET_NEXT(values, param_max_offset, rc);
  954. pbe->config.comp_attack =
  955. GET_NEXT(values, param_max_offset, rc);
  956. pbe->config.comp_release =
  957. GET_NEXT(values, param_max_offset, rc);
  958. pbe->config.exp_attack =
  959. GET_NEXT(values, param_max_offset, rc);
  960. pbe->config.exp_release =
  961. GET_NEXT(values, param_max_offset, rc);
  962. pbe->config.limiter_bass_threshold =
  963. GET_NEXT(values, param_max_offset, rc);
  964. pbe->config.limiter_high_threshold =
  965. GET_NEXT(values, param_max_offset, rc);
  966. pbe->config.limiter_bass_makeup_gain =
  967. GET_NEXT(values, param_max_offset, rc);
  968. pbe->config.limiter_high_makeup_gain =
  969. GET_NEXT(values, param_max_offset, rc);
  970. pbe->config.limiter_bass_gc =
  971. GET_NEXT(values, param_max_offset, rc);
  972. pbe->config.limiter_high_gc =
  973. GET_NEXT(values, param_max_offset, rc);
  974. pbe->config.limiter_delay =
  975. GET_NEXT(values, param_max_offset, rc);
  976. pbe->config.reserved =
  977. GET_NEXT(values, param_max_offset, rc);
  978. p_coeffs = &pbe->config.p1LowPassCoeffs[0];
  979. lpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
  980. hpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
  981. bpf_len = pbe->config.bandpass_filter_order * 5;
  982. bsf_len = 5;
  983. tsf_len = 5;
  984. total_coeffs_len = lpf_len + hpf_len + bpf_len + bsf_len + tsf_len;
  985. for (i = 0; i < total_coeffs_len; i++) {
  986. *p_coeffs++ = GET_NEXT(values, param_max_offset, rc);
  987. }
  988. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  989. break;
  990. max_params_length =
  991. params_length + COMMAND_IID_PAYLOAD_SZ + length;
  992. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  993. "PBE_PARAM", rc);
  994. if (rc != 0)
  995. break;
  996. param_hdr.param_id = AUDPROC_PARAM_ID_PBE_PARAM_CONFIG;
  997. param_hdr.param_size = length;
  998. param_data = (u8 *) &pbe->config;
  999. break;
  1000. default:
  1001. pr_err_ratelimited("%s: Invalid command to set config\n",
  1002. __func__);
  1003. continue;
  1004. }
  1005. if (rc)
  1006. goto invalid_config;
  1007. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  1008. param_data, &packed_data_size);
  1009. if (rc) {
  1010. pr_err("%s: Failed to pack params, error %d\n",
  1011. __func__, rc);
  1012. goto invalid_config;
  1013. }
  1014. updt_params += packed_data_size;
  1015. params_length += packed_data_size;
  1016. }
  1017. if (params_length && (rc == 0))
  1018. q6asm_set_pp_params(ac, NULL, params, params_length);
  1019. invalid_config:
  1020. kfree(params);
  1021. return rc;
  1022. }
  1023. EXPORT_SYMBOL(msm_audio_effects_pbe_handler);
  1024. /**
  1025. * msm_audio_effects_popless_eq_handler -
  1026. * Audio effects handler for popless equalizer
  1027. *
  1028. * @ac: audio client handle
  1029. * @eq: equalizer params
  1030. * @values: values to be updated
  1031. *
  1032. * Return 0 on success or error on failure
  1033. */
  1034. int msm_audio_effects_popless_eq_handler(struct audio_client *ac,
  1035. struct eq_params *eq,
  1036. long *values)
  1037. {
  1038. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  1039. char *params = NULL;
  1040. u8 *updt_params = NULL;
  1041. int rc = 0;
  1042. int devices = GET_NEXT(values, param_max_offset, rc);
  1043. int num_commands = GET_NEXT(values, param_max_offset, rc);
  1044. int i, prev_enable_flag;
  1045. uint32_t max_params_length = 0;
  1046. uint32_t params_length = 0;
  1047. struct param_hdr_v3 param_hdr;
  1048. u8 *param_data = NULL;
  1049. u32 packed_data_size = 0;
  1050. u8 *eq_config_data = NULL;
  1051. u32 *updt_config_data = NULL;
  1052. int config_param_length;
  1053. pr_debug("%s\n", __func__);
  1054. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  1055. pr_err("%s: cannot set audio effects\n", __func__);
  1056. return -EINVAL;
  1057. }
  1058. params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
  1059. if (!params) {
  1060. pr_err("%s, params memory alloc failed\n", __func__);
  1061. return -ENOMEM;
  1062. }
  1063. pr_debug("%s: device: %d\n", __func__, devices);
  1064. updt_params = (u8 *) params;
  1065. /* Set MID and IID once at top and only update param specific fields*/
  1066. memset(&param_hdr, 0, sizeof(param_hdr));
  1067. param_hdr.module_id = AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
  1068. param_hdr.instance_id = INSTANCE_ID_0;
  1069. for (i = 0; i < num_commands; i++) {
  1070. uint32_t command_id =
  1071. GET_NEXT(values, param_max_offset, rc);
  1072. uint32_t command_config_state =
  1073. GET_NEXT(values, param_max_offset, rc);
  1074. uint32_t index_offset =
  1075. GET_NEXT(values, param_max_offset, rc);
  1076. uint32_t length =
  1077. GET_NEXT(values, param_max_offset, rc);
  1078. uint32_t idx;
  1079. int j;
  1080. switch (command_id) {
  1081. case EQ_ENABLE:
  1082. if (length != 1 || index_offset != 0) {
  1083. pr_err("EQ_ENABLE:invalid params\n");
  1084. rc = -EINVAL;
  1085. goto invalid_config;
  1086. }
  1087. prev_enable_flag = eq->enable_flag;
  1088. eq->enable_flag =
  1089. GET_NEXT(values, param_max_offset, rc);
  1090. pr_debug("%s: EQ_ENABLE prev:%d new:%d\n", __func__,
  1091. prev_enable_flag, eq->enable_flag);
  1092. if (prev_enable_flag == eq->enable_flag)
  1093. continue;
  1094. max_params_length = params_length +
  1095. COMMAND_IID_PAYLOAD_SZ +
  1096. EQ_ENABLE_PARAM_SZ;
  1097. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  1098. "EQ_ENABLE", rc);
  1099. if (rc != 0)
  1100. break;
  1101. param_hdr.param_id = AUDPROC_PARAM_ID_EQ_ENABLE;
  1102. param_hdr.param_size = EQ_ENABLE_PARAM_SZ;
  1103. param_data = (u8 *) &eq->enable_flag;
  1104. break;
  1105. case EQ_CONFIG:
  1106. if (length < EQ_CONFIG_PARAM_LEN || index_offset != 0) {
  1107. pr_err("EQ_CONFIG:invalid params\n");
  1108. rc = -EINVAL;
  1109. goto invalid_config;
  1110. }
  1111. pr_debug("%s: EQ_CONFIG bands:%d, pgain:%d, pset:%d\n",
  1112. __func__, eq->config.num_bands,
  1113. eq->config.eq_pregain, eq->config.preset_id);
  1114. for (idx = 0; idx < MAX_EQ_BANDS; idx++)
  1115. eq->per_band_cfg[idx].band_idx = -1;
  1116. eq->config.eq_pregain =
  1117. GET_NEXT(values, param_max_offset, rc);
  1118. eq->config.preset_id =
  1119. GET_NEXT(values, param_max_offset, rc);
  1120. eq->config.num_bands =
  1121. GET_NEXT(values, param_max_offset, rc);
  1122. if (eq->config.num_bands > MAX_EQ_BANDS) {
  1123. pr_err("EQ_CONFIG:invalid num of bands\n");
  1124. rc = -EINVAL;
  1125. goto invalid_config;
  1126. }
  1127. if (eq->config.num_bands &&
  1128. (((length - EQ_CONFIG_PARAM_LEN)/
  1129. EQ_CONFIG_PER_BAND_PARAM_LEN)
  1130. != eq->config.num_bands)) {
  1131. pr_err("EQ_CONFIG:invalid length per band\n");
  1132. rc = -EINVAL;
  1133. goto invalid_config;
  1134. }
  1135. for (j = 0; j < eq->config.num_bands; j++) {
  1136. idx = GET_NEXT(values, param_max_offset, rc);
  1137. if (idx >= MAX_EQ_BANDS) {
  1138. pr_err("EQ_CONFIG:invalid band index\n");
  1139. rc = -EINVAL;
  1140. goto invalid_config;
  1141. }
  1142. eq->per_band_cfg[idx].band_idx = idx;
  1143. eq->per_band_cfg[idx].filter_type =
  1144. GET_NEXT(values, param_max_offset, rc);
  1145. eq->per_band_cfg[idx].freq_millihertz =
  1146. GET_NEXT(values, param_max_offset, rc);
  1147. eq->per_band_cfg[idx].gain_millibels =
  1148. GET_NEXT(values, param_max_offset, rc);
  1149. eq->per_band_cfg[idx].quality_factor =
  1150. GET_NEXT(values, param_max_offset, rc);
  1151. }
  1152. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  1153. break;
  1154. config_param_length = EQ_CONFIG_PARAM_SZ +
  1155. (EQ_CONFIG_PER_BAND_PARAM_SZ *
  1156. eq->config.num_bands);
  1157. max_params_length = params_length +
  1158. COMMAND_IID_PAYLOAD_SZ +
  1159. config_param_length;
  1160. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  1161. "EQ_CONFIG", rc);
  1162. if (rc != 0)
  1163. break;
  1164. param_hdr.param_id = AUDPROC_PARAM_ID_EQ_CONFIG;
  1165. param_hdr.param_size = config_param_length;
  1166. if (!eq_config_data)
  1167. eq_config_data = kzalloc(config_param_length,
  1168. GFP_KERNEL);
  1169. else
  1170. memset(eq_config_data, 0, config_param_length);
  1171. if (!eq_config_data) {
  1172. pr_err("%s, EQ_CONFIG:memory alloc failed\n",
  1173. __func__);
  1174. rc = -ENOMEM;
  1175. goto invalid_config;
  1176. }
  1177. param_data = eq_config_data;
  1178. updt_config_data = (u32 *) eq_config_data;
  1179. *updt_config_data++ = eq->config.eq_pregain;
  1180. *updt_config_data++ = eq->config.preset_id;
  1181. *updt_config_data++ = eq->config.num_bands;
  1182. for (idx = 0; idx < MAX_EQ_BANDS; idx++) {
  1183. if (eq->per_band_cfg[idx].band_idx < 0)
  1184. continue;
  1185. *updt_config_data++ =
  1186. eq->per_band_cfg[idx].filter_type;
  1187. *updt_config_data++ =
  1188. eq->per_band_cfg[idx].freq_millihertz;
  1189. *updt_config_data++ =
  1190. eq->per_band_cfg[idx].gain_millibels;
  1191. *updt_config_data++ =
  1192. eq->per_band_cfg[idx].quality_factor;
  1193. *updt_config_data++ =
  1194. eq->per_band_cfg[idx].band_idx;
  1195. }
  1196. break;
  1197. case EQ_BAND_INDEX:
  1198. if (length != 1 || index_offset != 0) {
  1199. pr_err("EQ_BAND_INDEX:invalid params\n");
  1200. rc = -EINVAL;
  1201. goto invalid_config;
  1202. }
  1203. idx = GET_NEXT(values, param_max_offset, rc);
  1204. if (idx > MAX_EQ_BANDS) {
  1205. pr_err("EQ_BAND_INDEX:invalid band index\n");
  1206. rc = -EINVAL;
  1207. goto invalid_config;
  1208. }
  1209. eq->band_index = idx;
  1210. pr_debug("%s: EQ_BAND_INDEX val:%d\n",
  1211. __func__, eq->band_index);
  1212. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  1213. break;
  1214. max_params_length = params_length +
  1215. COMMAND_IID_PAYLOAD_SZ +
  1216. EQ_BAND_INDEX_PARAM_SZ;
  1217. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  1218. "EQ_BAND_INDEX", rc);
  1219. if (rc != 0)
  1220. break;
  1221. param_hdr.param_id = AUDPROC_PARAM_ID_EQ_BAND_INDEX;
  1222. param_hdr.param_size = EQ_BAND_INDEX_PARAM_SZ;
  1223. param_data = (u8 *) &eq->band_index;
  1224. break;
  1225. case EQ_SINGLE_BAND_FREQ:
  1226. if (length != 1 || index_offset != 0) {
  1227. pr_err("EQ_SINGLE_BAND_FREQ:invalid params\n");
  1228. rc = -EINVAL;
  1229. goto invalid_config;
  1230. }
  1231. if (eq->band_index > MAX_EQ_BANDS) {
  1232. pr_err("EQ_SINGLE_BAND_FREQ:invalid index\n");
  1233. break;
  1234. }
  1235. eq->freq_millihertz =
  1236. GET_NEXT(values, param_max_offset, rc);
  1237. pr_debug("%s: EQ_SINGLE_BAND_FREQ idx:%d, val:%d\n",
  1238. __func__, eq->band_index, eq->freq_millihertz);
  1239. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  1240. break;
  1241. max_params_length = params_length +
  1242. COMMAND_IID_PAYLOAD_SZ +
  1243. EQ_SINGLE_BAND_FREQ_PARAM_SZ;
  1244. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  1245. "EQ_SINGLE_BAND_FREQ", rc);
  1246. if (rc != 0)
  1247. break;
  1248. param_hdr.param_id =
  1249. AUDPROC_PARAM_ID_EQ_SINGLE_BAND_FREQ;
  1250. param_hdr.param_size = EQ_SINGLE_BAND_FREQ_PARAM_SZ;
  1251. param_data = (u8 *) &eq->freq_millihertz;
  1252. break;
  1253. default:
  1254. pr_err_ratelimited("%s: Invalid command to set config\n",
  1255. __func__);
  1256. continue;
  1257. }
  1258. if (rc)
  1259. goto invalid_config;
  1260. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  1261. param_data, &packed_data_size);
  1262. if (rc) {
  1263. pr_err("%s: Failed to pack params, error %d\n",
  1264. __func__, rc);
  1265. goto invalid_config;
  1266. }
  1267. updt_params += packed_data_size;
  1268. params_length += packed_data_size;
  1269. }
  1270. if (params_length && (rc == 0))
  1271. q6asm_set_pp_params(ac, NULL, params, params_length);
  1272. else
  1273. pr_debug("%s: did not send pp params\n", __func__);
  1274. invalid_config:
  1275. kfree(params);
  1276. kfree(eq_config_data);
  1277. return rc;
  1278. }
  1279. EXPORT_SYMBOL(msm_audio_effects_popless_eq_handler);
  1280. static int __msm_audio_effects_volume_handler(struct audio_client *ac,
  1281. struct soft_volume_params *vol,
  1282. long *values,
  1283. int instance)
  1284. {
  1285. int devices;
  1286. int num_commands;
  1287. char *params = NULL;
  1288. u8 *updt_params;
  1289. int i;
  1290. uint32_t vol_gain_2ch = 0;
  1291. uint32_t max_params_length = 0;
  1292. uint32_t params_length = 0;
  1293. struct param_hdr_v3 param_hdr;
  1294. u32 packed_data_size = 0;
  1295. long *param_max_offset;
  1296. int rc = 0;
  1297. pr_debug("%s: instance: %d\n", __func__, instance);
  1298. if (!values) {
  1299. pr_err("%s: set audio effects failed, no valid data\n",
  1300. __func__);
  1301. return -EINVAL;
  1302. }
  1303. param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  1304. devices = GET_NEXT(values, param_max_offset, rc);
  1305. num_commands = GET_NEXT(values, param_max_offset, rc);
  1306. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  1307. pr_err("%s: cannot set audio effects\n", __func__);
  1308. return -EINVAL;
  1309. }
  1310. params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
  1311. if (!params) {
  1312. pr_err("%s, params memory alloc failed\n", __func__);
  1313. return -ENOMEM;
  1314. }
  1315. updt_params = (u8 *) params;
  1316. /* Set MID and IID once at top and only update param specific fields*/
  1317. memset(&param_hdr, 0, sizeof(param_hdr));
  1318. q6asm_set_soft_volume_module_instance_ids(instance, &param_hdr);
  1319. for (i = 0; i < num_commands; i++) {
  1320. uint32_t command_id =
  1321. GET_NEXT(values, param_max_offset, rc);
  1322. uint32_t command_config_state =
  1323. GET_NEXT(values, param_max_offset, rc);
  1324. uint32_t index_offset =
  1325. GET_NEXT(values, param_max_offset, rc);
  1326. uint32_t length =
  1327. GET_NEXT(values, param_max_offset, rc);
  1328. switch (command_id) {
  1329. case SOFT_VOLUME_GAIN_2CH:
  1330. case SOFT_VOLUME2_GAIN_2CH:
  1331. if (length != 2 || index_offset != 0) {
  1332. pr_err("VOLUME_GAIN_2CH: invalid params\n");
  1333. rc = -EINVAL;
  1334. goto invalid_config;
  1335. }
  1336. vol->left_gain = GET_NEXT(values, param_max_offset, rc);
  1337. vol->right_gain =
  1338. GET_NEXT(values, param_max_offset, rc);
  1339. vol->master_gain = 0x2000;
  1340. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  1341. break;
  1342. max_params_length = params_length +
  1343. COMMAND_IID_PAYLOAD_SZ +
  1344. SOFT_VOLUME_GAIN_2CH_PARAM_SZ +
  1345. COMMAND_IID_PAYLOAD_SZ +
  1346. SOFT_VOLUME_GAIN_MASTER_PARAM_SZ;
  1347. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  1348. "VOLUME/VOLUME2_GAIN_2CH", rc);
  1349. break;
  1350. case SOFT_VOLUME_GAIN_MASTER:
  1351. case SOFT_VOLUME2_GAIN_MASTER:
  1352. if (length != 1 || index_offset != 0) {
  1353. pr_err("VOLUME_GAIN_MASTER: invalid params\n");
  1354. rc = -EINVAL;
  1355. goto invalid_config;
  1356. }
  1357. vol->left_gain = 0x2000;
  1358. vol->right_gain = 0x2000;
  1359. vol->master_gain =
  1360. GET_NEXT(values, param_max_offset, rc);
  1361. if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
  1362. break;
  1363. max_params_length = params_length +
  1364. COMMAND_IID_PAYLOAD_SZ +
  1365. SOFT_VOLUME_GAIN_2CH_PARAM_SZ +
  1366. COMMAND_IID_PAYLOAD_SZ +
  1367. SOFT_VOLUME_GAIN_MASTER_PARAM_SZ;
  1368. CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
  1369. "VOLUME/VOLUME2_GAIN_MASTER", rc);
  1370. break;
  1371. default:
  1372. pr_err_ratelimited("%s: Invalid command id: %d to set config\n",
  1373. __func__, command_id);
  1374. continue;
  1375. }
  1376. if (rc)
  1377. continue;
  1378. /* Set Volume Control for Left/Right */
  1379. param_hdr.param_id = ASM_PARAM_ID_VOL_CTRL_LR_CHANNEL_GAIN;
  1380. param_hdr.param_size = SOFT_VOLUME_GAIN_2CH_PARAM_SZ;
  1381. vol_gain_2ch = (vol->left_gain << 16) | vol->right_gain;
  1382. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  1383. (u8 *) &vol_gain_2ch,
  1384. &packed_data_size);
  1385. if (rc) {
  1386. pr_err("%s: Failed to pack params, error %d\n",
  1387. __func__, rc);
  1388. goto invalid_config;
  1389. }
  1390. updt_params += packed_data_size;
  1391. params_length += packed_data_size;
  1392. /* Set Master Volume Control */
  1393. param_hdr.param_id = ASM_PARAM_ID_VOL_CTRL_MASTER_GAIN;
  1394. param_hdr.param_size = SOFT_VOLUME_GAIN_MASTER_PARAM_SZ;
  1395. rc = q6common_pack_pp_params(updt_params, &param_hdr,
  1396. (u8 *) &vol->master_gain,
  1397. &packed_data_size);
  1398. if (rc) {
  1399. pr_err("%s: Failed to pack params, error %d\n",
  1400. __func__, rc);
  1401. goto invalid_config;
  1402. }
  1403. updt_params += packed_data_size;
  1404. params_length += packed_data_size;
  1405. }
  1406. if (params_length && (rc == 0))
  1407. q6asm_set_pp_params(ac, NULL, params, params_length);
  1408. invalid_config:
  1409. kfree(params);
  1410. return rc;
  1411. }
  1412. int msm_audio_effects_volume_handler(struct audio_client *ac,
  1413. struct soft_volume_params *vol,
  1414. long *values)
  1415. {
  1416. return __msm_audio_effects_volume_handler(ac, vol, values,
  1417. SOFT_VOLUME_INSTANCE_1);
  1418. }
  1419. /**
  1420. * msm_audio_effects_volume_handler_v2 -
  1421. * Audio effects handler for volume
  1422. *
  1423. * @ac: audio client handle
  1424. * @vol: volume params
  1425. * @values: values to be updated
  1426. * @instance: instance to update
  1427. *
  1428. * Return 0 on success or error on failure
  1429. */
  1430. int msm_audio_effects_volume_handler_v2(struct audio_client *ac,
  1431. struct soft_volume_params *vol,
  1432. long *values, int instance)
  1433. {
  1434. return __msm_audio_effects_volume_handler(ac, vol, values, instance);
  1435. }
  1436. EXPORT_SYMBOL(msm_audio_effects_volume_handler_v2);