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

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