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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/slab.h>
  13. #include <sound/apr_audio-v2.h>
  14. #include <sound/q6asm-v2.h>
  15. #include <sound/compress_params.h>
  16. #include "msm-audio-effects-q6-v2.h"
  17. #define GET_NEXT(ptr, upper_limit, rc) \
  18. ({ \
  19. if (((ptr) + 1) > (upper_limit)) { \
  20. pr_err("%s: param list out of boundary\n", __func__); \
  21. (rc) = -EINVAL; \
  22. } \
  23. ((rc) == 0) ? *(ptr)++ : -EINVAL; \
  24. })
  25. #define CHECK_PARAM_LEN(len, max_len, tag, rc) \
  26. do { \
  27. if ((len) > (max_len)) { \
  28. pr_err("%s: params length overflows\n", (tag)); \
  29. (rc) = -EINVAL; \
  30. } \
  31. } while (0)
  32. int msm_audio_effects_virtualizer_handler(struct audio_client *ac,
  33. struct virtualizer_params *virtualizer,
  34. long *values)
  35. {
  36. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  37. char *params = NULL;
  38. int rc = 0;
  39. int devices = GET_NEXT(values, param_max_offset, rc);
  40. int num_commands = GET_NEXT(values, param_max_offset, rc);
  41. int *updt_params, i, prev_enable_flag;
  42. uint32_t params_length = (MAX_INBAND_PARAM_SZ);
  43. pr_debug("%s\n", __func__);
  44. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  45. pr_err("%s: cannot set audio effects\n", __func__);
  46. return -EINVAL;
  47. }
  48. params = kzalloc(params_length, GFP_KERNEL);
  49. if (!params) {
  50. pr_err("%s, params memory alloc failed\n", __func__);
  51. return -ENOMEM;
  52. }
  53. pr_debug("%s: device: %d\n", __func__, devices);
  54. updt_params = (int *)params;
  55. params_length = 0;
  56. for (i = 0; i < num_commands; i++) {
  57. uint32_t command_id =
  58. GET_NEXT(values, param_max_offset, rc);
  59. uint32_t command_config_state =
  60. GET_NEXT(values, param_max_offset, rc);
  61. uint32_t index_offset =
  62. GET_NEXT(values, param_max_offset, rc);
  63. uint32_t length =
  64. GET_NEXT(values, param_max_offset, rc);
  65. switch (command_id) {
  66. case VIRTUALIZER_ENABLE:
  67. if (length != 1 || index_offset != 0) {
  68. pr_err("VIRT ENABLE:invalid params\n");
  69. rc = -EINVAL;
  70. goto invalid_config;
  71. }
  72. prev_enable_flag = virtualizer->enable_flag;
  73. virtualizer->enable_flag =
  74. GET_NEXT(values, param_max_offset, rc);
  75. pr_debug("%s:VIRT ENABLE prev:%d, new:%d\n", __func__,
  76. prev_enable_flag, virtualizer->enable_flag);
  77. if (prev_enable_flag != virtualizer->enable_flag) {
  78. params_length += COMMAND_PAYLOAD_SZ +
  79. VIRTUALIZER_ENABLE_PARAM_SZ;
  80. CHECK_PARAM_LEN(params_length,
  81. MAX_INBAND_PARAM_SZ,
  82. "VIRT ENABLE", rc);
  83. if (rc != 0)
  84. goto invalid_config;
  85. *updt_params++ =
  86. AUDPROC_MODULE_ID_VIRTUALIZER;
  87. *updt_params++ =
  88. AUDPROC_PARAM_ID_VIRTUALIZER_ENABLE;
  89. *updt_params++ =
  90. VIRTUALIZER_ENABLE_PARAM_SZ;
  91. *updt_params++ =
  92. virtualizer->enable_flag;
  93. }
  94. break;
  95. case VIRTUALIZER_STRENGTH:
  96. if (length != 1 || index_offset != 0) {
  97. pr_err("VIRT STRENGTH:invalid params\n");
  98. rc = -EINVAL;
  99. goto invalid_config;
  100. }
  101. virtualizer->strength =
  102. GET_NEXT(values, param_max_offset, rc);
  103. pr_debug("%s: VIRT STRENGTH val: %d\n",
  104. __func__, virtualizer->strength);
  105. if (command_config_state == CONFIG_SET) {
  106. params_length += COMMAND_PAYLOAD_SZ +
  107. VIRTUALIZER_STRENGTH_PARAM_SZ;
  108. CHECK_PARAM_LEN(params_length,
  109. MAX_INBAND_PARAM_SZ,
  110. "VIRT STRENGTH", rc);
  111. if (rc != 0)
  112. goto invalid_config;
  113. *updt_params++ =
  114. AUDPROC_MODULE_ID_VIRTUALIZER;
  115. *updt_params++ =
  116. AUDPROC_PARAM_ID_VIRTUALIZER_STRENGTH;
  117. *updt_params++ =
  118. VIRTUALIZER_STRENGTH_PARAM_SZ;
  119. *updt_params++ =
  120. virtualizer->strength;
  121. }
  122. break;
  123. case VIRTUALIZER_OUT_TYPE:
  124. if (length != 1 || index_offset != 0) {
  125. pr_err("VIRT OUT_TYPE:invalid params\n");
  126. rc = -EINVAL;
  127. goto invalid_config;
  128. }
  129. virtualizer->out_type =
  130. GET_NEXT(values, param_max_offset, rc);
  131. pr_debug("%s: VIRT OUT_TYPE val:%d\n",
  132. __func__, virtualizer->out_type);
  133. if (command_config_state == CONFIG_SET) {
  134. params_length += COMMAND_PAYLOAD_SZ +
  135. VIRTUALIZER_OUT_TYPE_PARAM_SZ;
  136. CHECK_PARAM_LEN(params_length,
  137. MAX_INBAND_PARAM_SZ,
  138. "VIRT OUT_TYPE", rc);
  139. if (rc != 0)
  140. goto invalid_config;
  141. *updt_params++ =
  142. AUDPROC_MODULE_ID_VIRTUALIZER;
  143. *updt_params++ =
  144. AUDPROC_PARAM_ID_VIRTUALIZER_OUT_TYPE;
  145. *updt_params++ =
  146. VIRTUALIZER_OUT_TYPE_PARAM_SZ;
  147. *updt_params++ =
  148. virtualizer->out_type;
  149. }
  150. break;
  151. case VIRTUALIZER_GAIN_ADJUST:
  152. if (length != 1 || index_offset != 0) {
  153. pr_err("VIRT GAIN_ADJUST: invalid params\n");
  154. rc = -EINVAL;
  155. goto invalid_config;
  156. }
  157. virtualizer->gain_adjust =
  158. GET_NEXT(values, param_max_offset, rc);
  159. pr_debug("%s: VIRT GAIN_ADJUST val:%d\n",
  160. __func__, virtualizer->gain_adjust);
  161. if (command_config_state == CONFIG_SET) {
  162. params_length += COMMAND_PAYLOAD_SZ +
  163. VIRTUALIZER_GAIN_ADJUST_PARAM_SZ;
  164. CHECK_PARAM_LEN(params_length,
  165. MAX_INBAND_PARAM_SZ,
  166. "VIRT GAIN_ADJUST", rc);
  167. if (rc != 0)
  168. goto invalid_config;
  169. *updt_params++ =
  170. AUDPROC_MODULE_ID_VIRTUALIZER;
  171. *updt_params++ =
  172. AUDPROC_PARAM_ID_VIRTUALIZER_GAIN_ADJUST;
  173. *updt_params++ =
  174. VIRTUALIZER_GAIN_ADJUST_PARAM_SZ;
  175. *updt_params++ =
  176. virtualizer->gain_adjust;
  177. }
  178. break;
  179. default:
  180. pr_err("%s: Invalid command to set config\n", __func__);
  181. break;
  182. }
  183. }
  184. if (params_length && (rc == 0))
  185. q6asm_send_audio_effects_params(ac, params,
  186. params_length);
  187. else
  188. pr_debug("%s: did not send pp params\n", __func__);
  189. invalid_config:
  190. kfree(params);
  191. return rc;
  192. }
  193. int msm_audio_effects_reverb_handler(struct audio_client *ac,
  194. struct reverb_params *reverb,
  195. long *values)
  196. {
  197. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  198. char *params = NULL;
  199. int rc = 0;
  200. int devices = GET_NEXT(values, param_max_offset, rc);
  201. int num_commands = GET_NEXT(values, param_max_offset, rc);
  202. int *updt_params, i, prev_enable_flag;
  203. uint32_t params_length = (MAX_INBAND_PARAM_SZ);
  204. pr_debug("%s\n", __func__);
  205. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  206. pr_err("%s: cannot set audio effects\n", __func__);
  207. return -EINVAL;
  208. }
  209. params = kzalloc(params_length, GFP_KERNEL);
  210. if (!params) {
  211. pr_err("%s, params memory alloc failed\n", __func__);
  212. return -ENOMEM;
  213. }
  214. pr_debug("%s: device: %d\n", __func__, devices);
  215. updt_params = (int *)params;
  216. params_length = 0;
  217. for (i = 0; i < num_commands; i++) {
  218. uint32_t command_id =
  219. GET_NEXT(values, param_max_offset, rc);
  220. uint32_t command_config_state =
  221. GET_NEXT(values, param_max_offset, rc);
  222. uint32_t index_offset =
  223. GET_NEXT(values, param_max_offset, rc);
  224. uint32_t length =
  225. GET_NEXT(values, param_max_offset, rc);
  226. switch (command_id) {
  227. case REVERB_ENABLE:
  228. if (length != 1 || index_offset != 0) {
  229. pr_err("REVERB_ENABLE:invalid params\n");
  230. rc = -EINVAL;
  231. goto invalid_config;
  232. }
  233. prev_enable_flag = reverb->enable_flag;
  234. reverb->enable_flag =
  235. GET_NEXT(values, param_max_offset, rc);
  236. pr_debug("%s:REVERB_ENABLE prev:%d,new:%d\n", __func__,
  237. prev_enable_flag, reverb->enable_flag);
  238. if (prev_enable_flag != reverb->enable_flag) {
  239. params_length += COMMAND_PAYLOAD_SZ +
  240. REVERB_ENABLE_PARAM_SZ;
  241. CHECK_PARAM_LEN(params_length,
  242. MAX_INBAND_PARAM_SZ,
  243. "REVERB_ENABLE", rc);
  244. if (rc != 0)
  245. goto invalid_config;
  246. *updt_params++ =
  247. AUDPROC_MODULE_ID_REVERB;
  248. *updt_params++ =
  249. AUDPROC_PARAM_ID_REVERB_ENABLE;
  250. *updt_params++ =
  251. REVERB_ENABLE_PARAM_SZ;
  252. *updt_params++ =
  253. reverb->enable_flag;
  254. }
  255. break;
  256. case REVERB_MODE:
  257. if (length != 1 || index_offset != 0) {
  258. pr_err("REVERB_MODE:invalid params\n");
  259. rc = -EINVAL;
  260. goto invalid_config;
  261. }
  262. reverb->mode =
  263. GET_NEXT(values, param_max_offset, rc);
  264. pr_debug("%s: REVERB_MODE val:%d\n",
  265. __func__, reverb->mode);
  266. if (command_config_state == CONFIG_SET) {
  267. params_length += COMMAND_PAYLOAD_SZ +
  268. REVERB_MODE_PARAM_SZ;
  269. CHECK_PARAM_LEN(params_length,
  270. MAX_INBAND_PARAM_SZ,
  271. "REVERB_MODE", rc);
  272. if (rc != 0)
  273. goto invalid_config;
  274. *updt_params++ =
  275. AUDPROC_MODULE_ID_REVERB;
  276. *updt_params++ =
  277. AUDPROC_PARAM_ID_REVERB_MODE;
  278. *updt_params++ =
  279. REVERB_MODE_PARAM_SZ;
  280. *updt_params++ =
  281. reverb->mode;
  282. }
  283. break;
  284. case REVERB_PRESET:
  285. if (length != 1 || index_offset != 0) {
  286. pr_err("REVERB_PRESET:invalid params\n");
  287. rc = -EINVAL;
  288. goto invalid_config;
  289. }
  290. reverb->preset =
  291. GET_NEXT(values, param_max_offset, rc);
  292. pr_debug("%s: REVERB_PRESET val:%d\n",
  293. __func__, reverb->preset);
  294. if (command_config_state == CONFIG_SET) {
  295. params_length += COMMAND_PAYLOAD_SZ +
  296. REVERB_PRESET_PARAM_SZ;
  297. CHECK_PARAM_LEN(params_length,
  298. MAX_INBAND_PARAM_SZ,
  299. "REVERB_PRESET", rc);
  300. if (rc != 0)
  301. goto invalid_config;
  302. *updt_params++ =
  303. AUDPROC_MODULE_ID_REVERB;
  304. *updt_params++ =
  305. AUDPROC_PARAM_ID_REVERB_PRESET;
  306. *updt_params++ =
  307. REVERB_PRESET_PARAM_SZ;
  308. *updt_params++ =
  309. reverb->preset;
  310. }
  311. break;
  312. case REVERB_WET_MIX:
  313. if (length != 1 || index_offset != 0) {
  314. pr_err("REVERB_WET_MIX:invalid params\n");
  315. rc = -EINVAL;
  316. goto invalid_config;
  317. }
  318. reverb->wet_mix =
  319. GET_NEXT(values, param_max_offset, rc);
  320. pr_debug("%s: REVERB_WET_MIX val:%d\n",
  321. __func__, reverb->wet_mix);
  322. if (command_config_state == CONFIG_SET) {
  323. params_length += COMMAND_PAYLOAD_SZ +
  324. REVERB_WET_MIX_PARAM_SZ;
  325. CHECK_PARAM_LEN(params_length,
  326. MAX_INBAND_PARAM_SZ,
  327. "REVERB_WET_MIX", rc);
  328. if (rc != 0)
  329. goto invalid_config;
  330. *updt_params++ =
  331. AUDPROC_MODULE_ID_REVERB;
  332. *updt_params++ =
  333. AUDPROC_PARAM_ID_REVERB_WET_MIX;
  334. *updt_params++ =
  335. REVERB_WET_MIX_PARAM_SZ;
  336. *updt_params++ =
  337. reverb->wet_mix;
  338. }
  339. break;
  340. case REVERB_GAIN_ADJUST:
  341. if (length != 1 || index_offset != 0) {
  342. pr_err("REVERB_GAIN_ADJUST:invalid params\n");
  343. rc = -EINVAL;
  344. goto invalid_config;
  345. }
  346. reverb->gain_adjust =
  347. GET_NEXT(values, param_max_offset, rc);
  348. pr_debug("%s: REVERB_GAIN_ADJUST val:%d\n",
  349. __func__, reverb->gain_adjust);
  350. if (command_config_state == CONFIG_SET) {
  351. params_length += COMMAND_PAYLOAD_SZ +
  352. REVERB_GAIN_ADJUST_PARAM_SZ;
  353. CHECK_PARAM_LEN(params_length,
  354. MAX_INBAND_PARAM_SZ,
  355. "REVERB_GAIN_ADJUST", rc);
  356. if (rc != 0)
  357. goto invalid_config;
  358. *updt_params++ =
  359. AUDPROC_MODULE_ID_REVERB;
  360. *updt_params++ =
  361. AUDPROC_PARAM_ID_REVERB_GAIN_ADJUST;
  362. *updt_params++ =
  363. REVERB_GAIN_ADJUST_PARAM_SZ;
  364. *updt_params++ =
  365. reverb->gain_adjust;
  366. }
  367. break;
  368. case REVERB_ROOM_LEVEL:
  369. if (length != 1 || index_offset != 0) {
  370. pr_err("REVERB_ROOM_LEVEL:invalid params\n");
  371. rc = -EINVAL;
  372. goto invalid_config;
  373. }
  374. reverb->room_level =
  375. GET_NEXT(values, param_max_offset, rc);
  376. pr_debug("%s: REVERB_ROOM_LEVEL val:%d\n",
  377. __func__, reverb->room_level);
  378. if (command_config_state == CONFIG_SET) {
  379. params_length += COMMAND_PAYLOAD_SZ +
  380. REVERB_ROOM_LEVEL_PARAM_SZ;
  381. CHECK_PARAM_LEN(params_length,
  382. MAX_INBAND_PARAM_SZ,
  383. "REVERB_ROOM_LEVEL", rc);
  384. if (rc != 0)
  385. goto invalid_config;
  386. *updt_params++ =
  387. AUDPROC_MODULE_ID_REVERB;
  388. *updt_params++ =
  389. AUDPROC_PARAM_ID_REVERB_ROOM_LEVEL;
  390. *updt_params++ =
  391. REVERB_ROOM_LEVEL_PARAM_SZ;
  392. *updt_params++ =
  393. reverb->room_level;
  394. }
  395. break;
  396. case REVERB_ROOM_HF_LEVEL:
  397. if (length != 1 || index_offset != 0) {
  398. pr_err("REVERB_ROOM_HF_LEVEL:invalid params\n");
  399. rc = -EINVAL;
  400. goto invalid_config;
  401. }
  402. reverb->room_hf_level =
  403. GET_NEXT(values, param_max_offset, rc);
  404. pr_debug("%s: REVERB_ROOM_HF_LEVEL val%d\n",
  405. __func__, reverb->room_hf_level);
  406. if (command_config_state == CONFIG_SET) {
  407. params_length += COMMAND_PAYLOAD_SZ +
  408. REVERB_ROOM_HF_LEVEL_PARAM_SZ;
  409. CHECK_PARAM_LEN(params_length,
  410. MAX_INBAND_PARAM_SZ,
  411. "REVERB_ROOM_HF_LEVEL", rc);
  412. if (rc != 0)
  413. goto invalid_config;
  414. *updt_params++ =
  415. AUDPROC_MODULE_ID_REVERB;
  416. *updt_params++ =
  417. AUDPROC_PARAM_ID_REVERB_ROOM_HF_LEVEL;
  418. *updt_params++ =
  419. REVERB_ROOM_HF_LEVEL_PARAM_SZ;
  420. *updt_params++ =
  421. reverb->room_hf_level;
  422. }
  423. break;
  424. case REVERB_DECAY_TIME:
  425. if (length != 1 || index_offset != 0) {
  426. pr_err("REVERB_DECAY_TIME:invalid params\n");
  427. rc = -EINVAL;
  428. goto invalid_config;
  429. }
  430. reverb->decay_time =
  431. GET_NEXT(values, param_max_offset, rc);
  432. pr_debug("%s: REVERB_DECAY_TIME val:%d\n",
  433. __func__, reverb->decay_time);
  434. if (command_config_state == CONFIG_SET) {
  435. params_length += COMMAND_PAYLOAD_SZ +
  436. REVERB_DECAY_TIME_PARAM_SZ;
  437. CHECK_PARAM_LEN(params_length,
  438. MAX_INBAND_PARAM_SZ,
  439. "REVERB_DECAY_TIME", rc);
  440. if (rc != 0)
  441. goto invalid_config;
  442. *updt_params++ =
  443. AUDPROC_MODULE_ID_REVERB;
  444. *updt_params++ =
  445. AUDPROC_PARAM_ID_REVERB_DECAY_TIME;
  446. *updt_params++ =
  447. REVERB_DECAY_TIME_PARAM_SZ;
  448. *updt_params++ =
  449. reverb->decay_time;
  450. }
  451. break;
  452. case REVERB_DECAY_HF_RATIO:
  453. if (length != 1 || index_offset != 0) {
  454. pr_err("REVERB_DECAY_HF_RATIOinvalid params\n");
  455. rc = -EINVAL;
  456. goto invalid_config;
  457. }
  458. reverb->decay_hf_ratio =
  459. GET_NEXT(values, param_max_offset, rc);
  460. pr_debug("%s: REVERB_DECAY_HF_RATIO val%d\n",
  461. __func__, reverb->decay_hf_ratio);
  462. if (command_config_state == CONFIG_SET) {
  463. params_length += COMMAND_PAYLOAD_SZ +
  464. REVERB_DECAY_HF_RATIO_PARAM_SZ;
  465. CHECK_PARAM_LEN(params_length,
  466. MAX_INBAND_PARAM_SZ,
  467. "REVERB_DECAY_HF_RATIO", rc);
  468. if (rc != 0)
  469. goto invalid_config;
  470. *updt_params++ =
  471. AUDPROC_MODULE_ID_REVERB;
  472. *updt_params++ =
  473. AUDPROC_PARAM_ID_REVERB_DECAY_HF_RATIO;
  474. *updt_params++ =
  475. REVERB_DECAY_HF_RATIO_PARAM_SZ;
  476. *updt_params++ =
  477. reverb->decay_hf_ratio;
  478. }
  479. break;
  480. case REVERB_REFLECTIONS_LEVEL:
  481. if (length != 1 || index_offset != 0) {
  482. pr_err("REVERB_REFLECTION_LVLinvalid params\n");
  483. rc = -EINVAL;
  484. goto invalid_config;
  485. }
  486. reverb->reflections_level =
  487. GET_NEXT(values, param_max_offset, rc);
  488. pr_debug("%s: REVERB_REFLECTIONS_LEVEL val:%d\n",
  489. __func__, reverb->reflections_level);
  490. if (command_config_state == CONFIG_SET) {
  491. params_length += COMMAND_PAYLOAD_SZ +
  492. REVERB_REFLECTIONS_LEVEL_PARAM_SZ;
  493. CHECK_PARAM_LEN(params_length,
  494. MAX_INBAND_PARAM_SZ,
  495. "REVERB_REFLECTIONS_LEVEL", rc);
  496. if (rc != 0)
  497. goto invalid_config;
  498. *updt_params++ =
  499. AUDPROC_MODULE_ID_REVERB;
  500. *updt_params++ =
  501. AUDPROC_PARAM_ID_REVERB_REFLECTIONS_LEVEL;
  502. *updt_params++ =
  503. REVERB_REFLECTIONS_LEVEL_PARAM_SZ;
  504. *updt_params++ =
  505. reverb->reflections_level;
  506. }
  507. break;
  508. case REVERB_REFLECTIONS_DELAY:
  509. if (length != 1 || index_offset != 0) {
  510. pr_err("REVERB_REFLECTION_DLYinvalid params\n");
  511. rc = -EINVAL;
  512. goto invalid_config;
  513. }
  514. reverb->reflections_delay =
  515. GET_NEXT(values, param_max_offset, rc);
  516. pr_debug("%s: REVERB_REFLECTIONS_DELAY val:%d\n",
  517. __func__, reverb->reflections_delay);
  518. if (command_config_state == CONFIG_SET) {
  519. params_length += COMMAND_PAYLOAD_SZ +
  520. REVERB_REFLECTIONS_DELAY_PARAM_SZ;
  521. CHECK_PARAM_LEN(params_length,
  522. MAX_INBAND_PARAM_SZ,
  523. "REVERB_REFLECTIONS_DELAY", rc);
  524. if (rc != 0)
  525. goto invalid_config;
  526. *updt_params++ =
  527. AUDPROC_MODULE_ID_REVERB;
  528. *updt_params++ =
  529. AUDPROC_PARAM_ID_REVERB_REFLECTIONS_DELAY;
  530. *updt_params++ =
  531. REVERB_REFLECTIONS_DELAY_PARAM_SZ;
  532. *updt_params++ =
  533. reverb->reflections_delay;
  534. }
  535. break;
  536. case REVERB_LEVEL:
  537. if (length != 1 || index_offset != 0) {
  538. pr_err("REVERB_LEVEL:invalid params\n");
  539. rc = -EINVAL;
  540. goto invalid_config;
  541. }
  542. reverb->level =
  543. GET_NEXT(values, param_max_offset, rc);
  544. pr_debug("%s: REVERB_LEVEL val:%d\n",
  545. __func__, reverb->level);
  546. if (command_config_state == CONFIG_SET) {
  547. params_length += COMMAND_PAYLOAD_SZ +
  548. REVERB_LEVEL_PARAM_SZ;
  549. CHECK_PARAM_LEN(params_length,
  550. MAX_INBAND_PARAM_SZ,
  551. "REVERB_LEVEL", rc);
  552. if (rc != 0)
  553. goto invalid_config;
  554. *updt_params++ =
  555. AUDPROC_MODULE_ID_REVERB;
  556. *updt_params++ =
  557. AUDPROC_PARAM_ID_REVERB_LEVEL;
  558. *updt_params++ =
  559. REVERB_LEVEL_PARAM_SZ;
  560. *updt_params++ =
  561. reverb->level;
  562. }
  563. break;
  564. case REVERB_DELAY:
  565. if (length != 1 || index_offset != 0) {
  566. pr_err("REVERB_DELAY:invalid params\n");
  567. rc = -EINVAL;
  568. goto invalid_config;
  569. }
  570. reverb->delay =
  571. GET_NEXT(values, param_max_offset, rc);
  572. pr_debug("%s:REVERB_DELAY val:%d\n",
  573. __func__, reverb->delay);
  574. if (command_config_state == CONFIG_SET) {
  575. params_length += COMMAND_PAYLOAD_SZ +
  576. REVERB_DELAY_PARAM_SZ;
  577. CHECK_PARAM_LEN(params_length,
  578. MAX_INBAND_PARAM_SZ,
  579. "REVERB_DELAY", rc);
  580. if (rc != 0)
  581. goto invalid_config;
  582. *updt_params++ =
  583. AUDPROC_MODULE_ID_REVERB;
  584. *updt_params++ =
  585. AUDPROC_PARAM_ID_REVERB_DELAY;
  586. *updt_params++ =
  587. REVERB_DELAY_PARAM_SZ;
  588. *updt_params++ =
  589. reverb->delay;
  590. }
  591. break;
  592. case REVERB_DIFFUSION:
  593. if (length != 1 || index_offset != 0) {
  594. pr_err("REVERB_DIFFUSION:invalid params\n");
  595. rc = -EINVAL;
  596. goto invalid_config;
  597. }
  598. reverb->diffusion =
  599. GET_NEXT(values, param_max_offset, rc);
  600. pr_debug("%s: REVERB_DIFFUSION val:%d\n",
  601. __func__, reverb->diffusion);
  602. if (command_config_state == CONFIG_SET) {
  603. params_length += COMMAND_PAYLOAD_SZ +
  604. REVERB_DIFFUSION_PARAM_SZ;
  605. CHECK_PARAM_LEN(params_length,
  606. MAX_INBAND_PARAM_SZ,
  607. "REVERB_DIFFUSION", rc);
  608. if (rc != 0)
  609. goto invalid_config;
  610. *updt_params++ =
  611. AUDPROC_MODULE_ID_REVERB;
  612. *updt_params++ =
  613. AUDPROC_PARAM_ID_REVERB_DIFFUSION;
  614. *updt_params++ =
  615. REVERB_DIFFUSION_PARAM_SZ;
  616. *updt_params++ =
  617. reverb->diffusion;
  618. }
  619. break;
  620. case REVERB_DENSITY:
  621. if (length != 1 || index_offset != 0) {
  622. pr_err("REVERB_DENSITY:invalid params\n");
  623. rc = -EINVAL;
  624. goto invalid_config;
  625. }
  626. reverb->density =
  627. GET_NEXT(values, param_max_offset, rc);
  628. pr_debug("%s: REVERB_DENSITY val:%d\n",
  629. __func__, reverb->density);
  630. if (command_config_state == CONFIG_SET) {
  631. params_length += COMMAND_PAYLOAD_SZ +
  632. REVERB_DENSITY_PARAM_SZ;
  633. CHECK_PARAM_LEN(params_length,
  634. MAX_INBAND_PARAM_SZ,
  635. "REVERB_DENSITY", rc);
  636. if (rc != 0)
  637. goto invalid_config;
  638. *updt_params++ =
  639. AUDPROC_MODULE_ID_REVERB;
  640. *updt_params++ =
  641. AUDPROC_PARAM_ID_REVERB_DENSITY;
  642. *updt_params++ =
  643. REVERB_DENSITY_PARAM_SZ;
  644. *updt_params++ =
  645. reverb->density;
  646. }
  647. break;
  648. default:
  649. pr_err("%s: Invalid command to set config\n", __func__);
  650. break;
  651. }
  652. }
  653. if (params_length && (rc == 0))
  654. q6asm_send_audio_effects_params(ac, params,
  655. params_length);
  656. else
  657. pr_debug("%s: did not send pp params\n", __func__);
  658. invalid_config:
  659. kfree(params);
  660. return rc;
  661. }
  662. int msm_audio_effects_bass_boost_handler(struct audio_client *ac,
  663. struct bass_boost_params *bass_boost,
  664. long *values)
  665. {
  666. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  667. char *params = NULL;
  668. int rc = 0;
  669. int devices = GET_NEXT(values, param_max_offset, rc);
  670. int num_commands = GET_NEXT(values, param_max_offset, rc);
  671. int *updt_params, i, prev_enable_flag;
  672. uint32_t params_length = (MAX_INBAND_PARAM_SZ);
  673. pr_debug("%s\n", __func__);
  674. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  675. pr_err("%s: cannot set audio effects\n", __func__);
  676. return -EINVAL;
  677. }
  678. params = kzalloc(params_length, GFP_KERNEL);
  679. if (!params) {
  680. pr_err("%s, params memory alloc failed\n", __func__);
  681. return -ENOMEM;
  682. }
  683. pr_debug("%s: device: %d\n", __func__, devices);
  684. updt_params = (int *)params;
  685. params_length = 0;
  686. for (i = 0; i < num_commands; i++) {
  687. uint32_t command_id =
  688. GET_NEXT(values, param_max_offset, rc);
  689. uint32_t command_config_state =
  690. GET_NEXT(values, param_max_offset, rc);
  691. uint32_t index_offset =
  692. GET_NEXT(values, param_max_offset, rc);
  693. uint32_t length =
  694. GET_NEXT(values, param_max_offset, rc);
  695. switch (command_id) {
  696. case BASS_BOOST_ENABLE:
  697. if (length != 1 || index_offset != 0) {
  698. pr_err("BASS_BOOST_ENABLE:invalid params\n");
  699. rc = -EINVAL;
  700. goto invalid_config;
  701. }
  702. prev_enable_flag = bass_boost->enable_flag;
  703. bass_boost->enable_flag =
  704. GET_NEXT(values, param_max_offset, rc);
  705. pr_debug("%s: BASS_BOOST_ENABLE prev:%d new:%d\n",
  706. __func__, prev_enable_flag,
  707. bass_boost->enable_flag);
  708. if (prev_enable_flag != bass_boost->enable_flag) {
  709. params_length += COMMAND_PAYLOAD_SZ +
  710. BASS_BOOST_ENABLE_PARAM_SZ;
  711. CHECK_PARAM_LEN(params_length,
  712. MAX_INBAND_PARAM_SZ,
  713. "BASS_BOOST_ENABLE", rc);
  714. if (rc != 0)
  715. goto invalid_config;
  716. *updt_params++ =
  717. AUDPROC_MODULE_ID_BASS_BOOST;
  718. *updt_params++ =
  719. AUDPROC_PARAM_ID_BASS_BOOST_ENABLE;
  720. *updt_params++ =
  721. BASS_BOOST_ENABLE_PARAM_SZ;
  722. *updt_params++ =
  723. bass_boost->enable_flag;
  724. }
  725. break;
  726. case BASS_BOOST_MODE:
  727. if (length != 1 || index_offset != 0) {
  728. pr_err("BASS_BOOST_MODE:invalid params\n");
  729. rc = -EINVAL;
  730. goto invalid_config;
  731. }
  732. bass_boost->mode =
  733. GET_NEXT(values, param_max_offset, rc);
  734. pr_debug("%s: BASS_BOOST_MODE val:%d\n",
  735. __func__, bass_boost->mode);
  736. if (command_config_state == CONFIG_SET) {
  737. params_length += COMMAND_PAYLOAD_SZ +
  738. BASS_BOOST_MODE_PARAM_SZ;
  739. CHECK_PARAM_LEN(params_length,
  740. MAX_INBAND_PARAM_SZ,
  741. "BASS_BOOST_MODE", rc);
  742. if (rc != 0)
  743. goto invalid_config;
  744. *updt_params++ =
  745. AUDPROC_MODULE_ID_BASS_BOOST;
  746. *updt_params++ =
  747. AUDPROC_PARAM_ID_BASS_BOOST_MODE;
  748. *updt_params++ =
  749. BASS_BOOST_MODE_PARAM_SZ;
  750. *updt_params++ =
  751. bass_boost->mode;
  752. }
  753. break;
  754. case BASS_BOOST_STRENGTH:
  755. if (length != 1 || index_offset != 0) {
  756. pr_err("BASS_BOOST_STRENGTH:invalid params\n");
  757. rc = -EINVAL;
  758. goto invalid_config;
  759. }
  760. bass_boost->strength =
  761. GET_NEXT(values, param_max_offset, rc);
  762. pr_debug("%s: BASS_BOOST_STRENGTH val:%d\n",
  763. __func__, bass_boost->strength);
  764. if (command_config_state == CONFIG_SET) {
  765. params_length += COMMAND_PAYLOAD_SZ +
  766. BASS_BOOST_STRENGTH_PARAM_SZ;
  767. CHECK_PARAM_LEN(params_length,
  768. MAX_INBAND_PARAM_SZ,
  769. "BASS_BOOST_STRENGTH", rc);
  770. if (rc != 0)
  771. goto invalid_config;
  772. *updt_params++ =
  773. AUDPROC_MODULE_ID_BASS_BOOST;
  774. *updt_params++ =
  775. AUDPROC_PARAM_ID_BASS_BOOST_STRENGTH;
  776. *updt_params++ =
  777. BASS_BOOST_STRENGTH_PARAM_SZ;
  778. *updt_params++ =
  779. bass_boost->strength;
  780. }
  781. break;
  782. default:
  783. pr_err("%s: Invalid command to set config\n", __func__);
  784. break;
  785. }
  786. }
  787. if (params_length && (rc == 0))
  788. q6asm_send_audio_effects_params(ac, params,
  789. params_length);
  790. else
  791. pr_debug("%s: did not send pp params\n", __func__);
  792. invalid_config:
  793. kfree(params);
  794. return rc;
  795. }
  796. int msm_audio_effects_popless_eq_handler(struct audio_client *ac,
  797. struct eq_params *eq,
  798. long *values)
  799. {
  800. long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
  801. char *params = NULL;
  802. int rc = 0;
  803. int devices = GET_NEXT(values, param_max_offset, rc);
  804. int num_commands = GET_NEXT(values, param_max_offset, rc);
  805. int *updt_params, i, prev_enable_flag;
  806. uint32_t params_length = (MAX_INBAND_PARAM_SZ);
  807. pr_debug("%s\n", __func__);
  808. if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
  809. pr_err("%s: cannot set audio effects\n", __func__);
  810. return -EINVAL;
  811. }
  812. params = kzalloc(params_length, GFP_KERNEL);
  813. if (!params) {
  814. pr_err("%s, params memory alloc failed\n", __func__);
  815. return -ENOMEM;
  816. }
  817. pr_debug("%s: device: %d\n", __func__, devices);
  818. updt_params = (int *)params;
  819. params_length = 0;
  820. for (i = 0; i < num_commands; i++) {
  821. uint32_t command_id =
  822. GET_NEXT(values, param_max_offset, rc);
  823. uint32_t command_config_state =
  824. GET_NEXT(values, param_max_offset, rc);
  825. uint32_t index_offset =
  826. GET_NEXT(values, param_max_offset, rc);
  827. uint32_t length =
  828. GET_NEXT(values, param_max_offset, rc);
  829. uint32_t idx;
  830. int j;
  831. switch (command_id) {
  832. case EQ_ENABLE:
  833. if (length != 1 || index_offset != 0) {
  834. pr_err("EQ_ENABLE:invalid params\n");
  835. rc = -EINVAL;
  836. goto invalid_config;
  837. }
  838. prev_enable_flag = eq->enable_flag;
  839. eq->enable_flag =
  840. GET_NEXT(values, param_max_offset, rc);
  841. pr_debug("%s: EQ_ENABLE prev:%d new:%d\n", __func__,
  842. prev_enable_flag, eq->enable_flag);
  843. if (prev_enable_flag != eq->enable_flag) {
  844. params_length += COMMAND_PAYLOAD_SZ +
  845. EQ_ENABLE_PARAM_SZ;
  846. CHECK_PARAM_LEN(params_length,
  847. MAX_INBAND_PARAM_SZ,
  848. "EQ_ENABLE", rc);
  849. if (rc != 0)
  850. goto invalid_config;
  851. *updt_params++ =
  852. AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
  853. *updt_params++ =
  854. AUDPROC_PARAM_ID_EQ_ENABLE;
  855. *updt_params++ =
  856. EQ_ENABLE_PARAM_SZ;
  857. *updt_params++ =
  858. eq->enable_flag;
  859. }
  860. break;
  861. case EQ_CONFIG:
  862. if (length < EQ_CONFIG_PARAM_LEN || index_offset != 0) {
  863. pr_err("EQ_CONFIG:invalid params\n");
  864. rc = -EINVAL;
  865. goto invalid_config;
  866. }
  867. pr_debug("%s: EQ_CONFIG bands:%d, pgain:%d, pset:%d\n",
  868. __func__, eq->config.num_bands,
  869. eq->config.eq_pregain, eq->config.preset_id);
  870. for (idx = 0; idx < MAX_EQ_BANDS; idx++)
  871. eq->per_band_cfg[idx].band_idx = -1;
  872. eq->config.eq_pregain =
  873. GET_NEXT(values, param_max_offset, rc);
  874. eq->config.preset_id =
  875. GET_NEXT(values, param_max_offset, rc);
  876. eq->config.num_bands =
  877. GET_NEXT(values, param_max_offset, rc);
  878. if (eq->config.num_bands > MAX_EQ_BANDS) {
  879. pr_err("EQ_CONFIG:invalid num of bands\n");
  880. rc = -EINVAL;
  881. goto invalid_config;
  882. }
  883. if (eq->config.num_bands &&
  884. (((length - EQ_CONFIG_PARAM_LEN)/
  885. EQ_CONFIG_PER_BAND_PARAM_LEN)
  886. != eq->config.num_bands)) {
  887. pr_err("EQ_CONFIG:invalid length per band\n");
  888. rc = -EINVAL;
  889. goto invalid_config;
  890. }
  891. for (j = 0; j < eq->config.num_bands; j++) {
  892. idx = GET_NEXT(values, param_max_offset, rc);
  893. if (idx >= MAX_EQ_BANDS) {
  894. pr_err("EQ_CONFIG:invalid band index\n");
  895. rc = -EINVAL;
  896. goto invalid_config;
  897. }
  898. eq->per_band_cfg[idx].band_idx = idx;
  899. eq->per_band_cfg[idx].filter_type =
  900. GET_NEXT(values, param_max_offset, rc);
  901. eq->per_band_cfg[idx].freq_millihertz =
  902. GET_NEXT(values, param_max_offset, rc);
  903. eq->per_band_cfg[idx].gain_millibels =
  904. GET_NEXT(values, param_max_offset, rc);
  905. eq->per_band_cfg[idx].quality_factor =
  906. GET_NEXT(values, param_max_offset, rc);
  907. }
  908. if (command_config_state == CONFIG_SET) {
  909. int config_param_length = EQ_CONFIG_PARAM_SZ +
  910. (EQ_CONFIG_PER_BAND_PARAM_SZ*
  911. eq->config.num_bands);
  912. params_length += COMMAND_PAYLOAD_SZ +
  913. config_param_length;
  914. CHECK_PARAM_LEN(params_length,
  915. MAX_INBAND_PARAM_SZ,
  916. "EQ_CONFIG", rc);
  917. if (rc != 0)
  918. goto invalid_config;
  919. *updt_params++ =
  920. AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
  921. *updt_params++ =
  922. AUDPROC_PARAM_ID_EQ_CONFIG;
  923. *updt_params++ =
  924. config_param_length;
  925. *updt_params++ =
  926. eq->config.eq_pregain;
  927. *updt_params++ =
  928. eq->config.preset_id;
  929. *updt_params++ =
  930. eq->config.num_bands;
  931. for (idx = 0; idx < MAX_EQ_BANDS; idx++) {
  932. if (eq->per_band_cfg[idx].band_idx < 0)
  933. continue;
  934. *updt_params++ =
  935. eq->per_band_cfg[idx].filter_type;
  936. *updt_params++ =
  937. eq->per_band_cfg[idx].freq_millihertz;
  938. *updt_params++ =
  939. eq->per_band_cfg[idx].gain_millibels;
  940. *updt_params++ =
  941. eq->per_band_cfg[idx].quality_factor;
  942. *updt_params++ =
  943. eq->per_band_cfg[idx].band_idx;
  944. }
  945. }
  946. break;
  947. case EQ_BAND_INDEX:
  948. if (length != 1 || index_offset != 0) {
  949. pr_err("EQ_BAND_INDEX:invalid params\n");
  950. rc = -EINVAL;
  951. goto invalid_config;
  952. }
  953. idx = GET_NEXT(values, param_max_offset, rc);
  954. if (idx > MAX_EQ_BANDS) {
  955. pr_err("EQ_BAND_INDEX:invalid band index\n");
  956. rc = -EINVAL;
  957. goto invalid_config;
  958. }
  959. eq->band_index = idx;
  960. pr_debug("%s: EQ_BAND_INDEX val:%d\n",
  961. __func__, eq->band_index);
  962. if (command_config_state == CONFIG_SET) {
  963. params_length += COMMAND_PAYLOAD_SZ +
  964. EQ_BAND_INDEX_PARAM_SZ;
  965. CHECK_PARAM_LEN(params_length,
  966. MAX_INBAND_PARAM_SZ,
  967. "EQ_BAND_INDEX", rc);
  968. if (rc != 0)
  969. goto invalid_config;
  970. *updt_params++ =
  971. AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
  972. *updt_params++ =
  973. AUDPROC_PARAM_ID_EQ_BAND_INDEX;
  974. *updt_params++ =
  975. EQ_BAND_INDEX_PARAM_SZ;
  976. *updt_params++ =
  977. eq->band_index;
  978. }
  979. break;
  980. case EQ_SINGLE_BAND_FREQ:
  981. if (length != 1 || index_offset != 0) {
  982. pr_err("EQ_SINGLE_BAND_FREQ:invalid params\n");
  983. rc = -EINVAL;
  984. goto invalid_config;
  985. }
  986. if (eq->band_index > MAX_EQ_BANDS) {
  987. pr_err("EQ_SINGLE_BAND_FREQ:invalid index\n");
  988. break;
  989. }
  990. eq->freq_millihertz =
  991. GET_NEXT(values, param_max_offset, rc);
  992. pr_debug("%s: EQ_SINGLE_BAND_FREQ idx:%d, val:%d\n",
  993. __func__, eq->band_index, eq->freq_millihertz);
  994. if (command_config_state == CONFIG_SET) {
  995. params_length += COMMAND_PAYLOAD_SZ +
  996. EQ_SINGLE_BAND_FREQ_PARAM_SZ;
  997. CHECK_PARAM_LEN(params_length,
  998. MAX_INBAND_PARAM_SZ,
  999. "EQ_SINGLE_BAND_FREQ", rc);
  1000. if (rc != 0)
  1001. goto invalid_config;
  1002. *updt_params++ =
  1003. AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
  1004. *updt_params++ =
  1005. AUDPROC_PARAM_ID_EQ_SINGLE_BAND_FREQ;
  1006. *updt_params++ =
  1007. EQ_SINGLE_BAND_FREQ_PARAM_SZ;
  1008. *updt_params++ =
  1009. eq->freq_millihertz;
  1010. }
  1011. break;
  1012. default:
  1013. pr_err("%s: Invalid command to set config\n", __func__);
  1014. break;
  1015. }
  1016. }
  1017. if (params_length && (rc == 0))
  1018. q6asm_send_audio_effects_params(ac, params,
  1019. params_length);
  1020. else
  1021. pr_debug("%s: did not send pp params\n", __func__);
  1022. invalid_config:
  1023. kfree(params);
  1024. return rc;
  1025. }