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

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