123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482 |
- // SPDX-License-Identifier: GPL-2.0-only
- /* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
- */
- #include <linux/slab.h>
- #include <linux/ratelimit.h>
- #include <sound/compress_params.h>
- #include <audio/sound/devdep_params.h>
- #include <dsp/apr_audio-v2.h>
- #include <dsp/q6asm-v2.h>
- #include <dsp/msm-audio-effects-q6-v2.h>
- #include <dsp/q6common.h>
- #define MAX_ENABLE_CMD_SIZE 32
- #define GET_NEXT(ptr, upper_limit, rc) \
- ({ \
- if (((ptr) + 1) > (upper_limit)) { \
- pr_err_ratelimited("%s: param list out of boundary\n", \
- __func__); \
- (rc) = -EINVAL; \
- } \
- ((rc) == 0) ? *(ptr)++ : -EINVAL; \
- })
- #define CHECK_PARAM_LEN(len, max_len, tag, rc) \
- do { \
- if ((len) > (max_len)) { \
- pr_err_ratelimited("%s: params length overflows\n", \
- (tag)); \
- (rc) = -EINVAL; \
- } \
- } while (0)
- /**
- * msm_audio_effects_is_effmodule_supp_in_top -
- * Checks if given topology and module in effects
- *
- */
- bool msm_audio_effects_is_effmodule_supp_in_top(int effect_module,
- int topology)
- {
- switch (effect_module) {
- case VIRTUALIZER_MODULE:
- case REVERB_MODULE:
- case BASS_BOOST_MODULE:
- case PBE_MODULE:
- case EQ_MODULE:
- switch (topology) {
- case ASM_STREAM_POSTPROC_TOPO_ID_SA_PLUS:
- return true;
- default:
- return false;
- }
- default:
- return false;
- }
- }
- EXPORT_SYMBOL(msm_audio_effects_is_effmodule_supp_in_top);
- int msm_audio_effects_enable_extn(struct audio_client *ac,
- struct msm_nt_eff_all_config *effects,
- bool flag)
- {
- u32 flag_param = flag ? 1 : 0;
- struct param_hdr_v3 param_hdr;
- int rc = 0;
- pr_debug("%s\n", __func__);
- memset(¶m_hdr, 0, sizeof(param_hdr));
- param_hdr.module_id = AUDPROC_MODULE_ID_VIRTUALIZER;
- param_hdr.instance_id = INSTANCE_ID_0;
- param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
- param_hdr.param_size = VIRTUALIZER_ENABLE_PARAM_SZ;
- if (effects->virtualizer.enable_flag)
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_hdr,
- (u8 *) &flag_param);
- param_hdr.module_id = AUDPROC_MODULE_ID_BASS_BOOST;
- param_hdr.instance_id = INSTANCE_ID_0;
- param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
- param_hdr.param_size = BASS_BOOST_ENABLE_PARAM_SZ;
- if (effects->bass_boost.enable_flag)
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_hdr,
- (u8 *) &flag_param);
- param_hdr.module_id = AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
- param_hdr.instance_id = INSTANCE_ID_0;
- param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE;
- param_hdr.param_size = EQ_ENABLE_PARAM_SZ;
- if (effects->equalizer.enable_flag)
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_hdr,
- (u8 *) &flag_param);
- return rc;
- }
- /**
- * msm_audio_effects_virtualizer_handler -
- * Audio effects handler for virtualizer
- *
- * @ac: audio client handle
- * @pbe: virtualizer params
- * @values: values to be updated
- *
- * Return 0 on success or error on failure
- */
- int msm_audio_effects_virtualizer_handler(struct audio_client *ac,
- struct virtualizer_params *virtualizer,
- long *values)
- {
- long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
- char *params = NULL;
- u8 *updt_params;
- int rc = 0;
- int devices = GET_NEXT(values, param_max_offset, rc);
- int num_commands = GET_NEXT(values, param_max_offset, rc);
- int i, prev_enable_flag;
- uint32_t max_params_length = 0;
- uint32_t params_length = 0;
- struct param_hdr_v3 param_hdr;
- u8 *param_data = NULL;
- u32 packed_data_size = 0;
- pr_debug("%s\n", __func__);
- if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
- pr_err("%s: cannot set audio effects\n", __func__);
- return -EINVAL;
- }
- params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
- if (!params) {
- pr_err("%s, params memory alloc failed\n", __func__);
- return -ENOMEM;
- }
- pr_debug("%s: device: %d\n", __func__, devices);
- updt_params = (u8 *) params;
- /* Set MID and IID once at top and only update param specific fields*/
- memset(¶m_hdr, 0, sizeof(param_hdr));
- param_hdr.module_id = AUDPROC_MODULE_ID_VIRTUALIZER;
- param_hdr.instance_id = INSTANCE_ID_0;
- for (i = 0; i < num_commands; i++) {
- uint32_t command_id =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t command_config_state =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t index_offset =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t length =
- GET_NEXT(values, param_max_offset, rc);
- switch (command_id) {
- case VIRTUALIZER_ENABLE:
- if (length != 1 || index_offset != 0) {
- pr_err("VIRT ENABLE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- prev_enable_flag = virtualizer->enable_flag;
- virtualizer->enable_flag =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s:VIRT ENABLE prev:%d, new:%d\n", __func__,
- prev_enable_flag, virtualizer->enable_flag);
- if (prev_enable_flag == virtualizer->enable_flag)
- continue;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- VIRTUALIZER_ENABLE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "VIRT ENABLE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_VIRTUALIZER_ENABLE;
- param_hdr.param_size = VIRTUALIZER_ENABLE_PARAM_SZ;
- param_data = (u8 *) &virtualizer->enable_flag;
- break;
- case VIRTUALIZER_STRENGTH:
- if (length != 1 || index_offset != 0) {
- pr_err("VIRT STRENGTH:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- virtualizer->strength =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: VIRT STRENGTH val: %d\n",
- __func__, virtualizer->strength);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- VIRTUALIZER_STRENGTH_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "VIRT STRENGTH", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_VIRTUALIZER_STRENGTH;
- param_hdr.param_size = VIRTUALIZER_STRENGTH_PARAM_SZ;
- param_data = (u8 *) &virtualizer->strength;
- break;
- case VIRTUALIZER_OUT_TYPE:
- if (length != 1 || index_offset != 0) {
- pr_err("VIRT OUT_TYPE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- virtualizer->out_type =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: VIRT OUT_TYPE val:%d\n",
- __func__, virtualizer->out_type);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- VIRTUALIZER_OUT_TYPE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "VIRT OUT_TYPE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_VIRTUALIZER_OUT_TYPE;
- param_hdr.param_size = VIRTUALIZER_OUT_TYPE_PARAM_SZ;
- param_data = (u8 *) &virtualizer->out_type;
- break;
- case VIRTUALIZER_GAIN_ADJUST:
- if (length != 1 || index_offset != 0) {
- pr_err("VIRT GAIN_ADJUST: invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- virtualizer->gain_adjust =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: VIRT GAIN_ADJUST val:%d\n",
- __func__, virtualizer->gain_adjust);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- VIRTUALIZER_GAIN_ADJUST_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "VIRT GAIN_ADJUST", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_VIRTUALIZER_GAIN_ADJUST;
- param_hdr.param_size = VIRTUALIZER_GAIN_ADJUST_PARAM_SZ;
- param_data = (u8 *) &virtualizer->gain_adjust;
- break;
- default:
- pr_err_ratelimited("%s: Invalid command to set config\n",
- __func__);
- continue;
- }
- if (rc)
- goto invalid_config;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- param_data, &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- }
- if (params_length && (rc == 0))
- q6asm_set_pp_params(ac, NULL, params, params_length);
- else
- pr_debug("%s: did not send pp params\n", __func__);
- invalid_config:
- kfree(params);
- return rc;
- }
- EXPORT_SYMBOL(msm_audio_effects_virtualizer_handler);
- /**
- * msm_audio_effects_reverb_handler -
- * Audio effects handler for reverb
- *
- * @ac: audio client handle
- * @pbe: reverb params
- * @values: values to be updated
- *
- * Return 0 on success or error on failure
- */
- int msm_audio_effects_reverb_handler(struct audio_client *ac,
- struct reverb_params *reverb,
- long *values)
- {
- long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
- char *params = NULL;
- u8 *updt_params;
- int rc = 0;
- int devices = GET_NEXT(values, param_max_offset, rc);
- int num_commands = GET_NEXT(values, param_max_offset, rc);
- int i, prev_enable_flag;
- uint32_t max_params_length = 0;
- uint32_t params_length = 0;
- struct param_hdr_v3 param_hdr;
- u8 *param_data = NULL;
- u32 packed_data_size = 0;
- pr_debug("%s\n", __func__);
- if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
- pr_err("%s: cannot set audio effects\n", __func__);
- return -EINVAL;
- }
- params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
- if (!params) {
- pr_err("%s, params memory alloc failed\n", __func__);
- return -ENOMEM;
- }
- pr_debug("%s: device: %d\n", __func__, devices);
- updt_params = (u8 *) params;
- /* Set MID and IID once at top and only update param specific fields*/
- memset(¶m_hdr, 0, sizeof(param_hdr));
- param_hdr.module_id = AUDPROC_MODULE_ID_REVERB;
- param_hdr.instance_id = INSTANCE_ID_0;
- for (i = 0; i < num_commands; i++) {
- uint32_t command_id =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t command_config_state =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t index_offset =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t length =
- GET_NEXT(values, param_max_offset, rc);
- switch (command_id) {
- case REVERB_ENABLE:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_ENABLE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- prev_enable_flag = reverb->enable_flag;
- reverb->enable_flag =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s:REVERB_ENABLE prev:%d,new:%d\n", __func__,
- prev_enable_flag, reverb->enable_flag);
- if (prev_enable_flag == reverb->enable_flag)
- continue;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_ENABLE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_ENABLE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_ENABLE;
- param_hdr.param_size = REVERB_ENABLE_PARAM_SZ;
- param_data = (u8 *) &reverb->enable_flag;
- break;
- case REVERB_MODE:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_MODE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->mode =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_MODE val:%d\n",
- __func__, reverb->mode);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_MODE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_MODE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_MODE;
- param_hdr.param_size = REVERB_MODE_PARAM_SZ;
- param_data = (u8 *) &reverb->mode;
- break;
- case REVERB_PRESET:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_PRESET:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->preset =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_PRESET val:%d\n",
- __func__, reverb->preset);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_PRESET_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_PRESET", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_PRESET;
- param_hdr.param_size = REVERB_PRESET_PARAM_SZ;
- param_data = (u8 *) &reverb->preset;
- break;
- case REVERB_WET_MIX:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_WET_MIX:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->wet_mix =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_WET_MIX val:%d\n",
- __func__, reverb->wet_mix);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_WET_MIX_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_WET_MIX", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_WET_MIX;
- param_hdr.param_size = REVERB_WET_MIX_PARAM_SZ;
- param_data = (u8 *) &reverb->wet_mix;
- break;
- case REVERB_GAIN_ADJUST:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_GAIN_ADJUST:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->gain_adjust =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_GAIN_ADJUST val:%d\n",
- __func__, reverb->gain_adjust);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_GAIN_ADJUST_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_GAIN_ADJUST", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_REVERB_GAIN_ADJUST;
- param_hdr.param_size = REVERB_GAIN_ADJUST_PARAM_SZ;
- param_data = (u8 *) &reverb->gain_adjust;
- break;
- case REVERB_ROOM_LEVEL:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_ROOM_LEVEL:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->room_level =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_ROOM_LEVEL val:%d\n",
- __func__, reverb->room_level);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_ROOM_LEVEL_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_ROOM_LEVEL", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_ROOM_LEVEL;
- param_hdr.param_size = REVERB_ROOM_LEVEL_PARAM_SZ;
- param_data = (u8 *) &reverb->room_level;
- break;
- case REVERB_ROOM_HF_LEVEL:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_ROOM_HF_LEVEL:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->room_hf_level =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_ROOM_HF_LEVEL val%d\n",
- __func__, reverb->room_hf_level);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_ROOM_HF_LEVEL_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_ROOM_HF_LEVEL", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_REVERB_ROOM_HF_LEVEL;
- param_hdr.param_size = REVERB_ROOM_HF_LEVEL_PARAM_SZ;
- param_data = (u8 *) &reverb->room_hf_level;
- break;
- case REVERB_DECAY_TIME:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_DECAY_TIME:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->decay_time =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_DECAY_TIME val:%d\n",
- __func__, reverb->decay_time);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_DECAY_TIME_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_DECAY_TIME", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DECAY_TIME;
- param_hdr.param_size = REVERB_DECAY_TIME_PARAM_SZ;
- param_data = (u8 *) &reverb->decay_time;
- break;
- case REVERB_DECAY_HF_RATIO:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_DECAY_HF_RATIOinvalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->decay_hf_ratio =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_DECAY_HF_RATIO val%d\n",
- __func__, reverb->decay_hf_ratio);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_DECAY_HF_RATIO_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_DECAY_HF_RATIO", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_REVERB_DECAY_HF_RATIO;
- param_hdr.param_size = REVERB_DECAY_HF_RATIO_PARAM_SZ;
- param_data = (u8 *) &reverb->decay_hf_ratio;
- break;
- case REVERB_REFLECTIONS_LEVEL:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_REFLECTION_LVLinvalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->reflections_level =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_REFLECTIONS_LEVEL val:%d\n",
- __func__, reverb->reflections_level);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_REFLECTIONS_LEVEL_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_REFLECTIONS_LEVEL", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_REVERB_REFLECTIONS_LEVEL;
- param_hdr.param_size =
- REVERB_REFLECTIONS_LEVEL_PARAM_SZ;
- param_data = (u8 *) &reverb->reflections_level;
- break;
- case REVERB_REFLECTIONS_DELAY:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_REFLECTION_DLYinvalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->reflections_delay =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_REFLECTIONS_DELAY val:%d\n",
- __func__, reverb->reflections_delay);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_REFLECTIONS_DELAY_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_REFLECTIONS_DELAY", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_REVERB_REFLECTIONS_DELAY;
- param_hdr.param_size =
- REVERB_REFLECTIONS_DELAY_PARAM_SZ;
- param_data = (u8 *) &reverb->reflections_delay;
- break;
- case REVERB_LEVEL:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_LEVEL:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->level =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_LEVEL val:%d\n",
- __func__, reverb->level);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_LEVEL_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_LEVEL", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_LEVEL;
- param_hdr.param_size = REVERB_LEVEL_PARAM_SZ;
- param_data = (u8 *) &reverb->level;
- break;
- case REVERB_DELAY:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_DELAY:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->delay =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s:REVERB_DELAY val:%d\n",
- __func__, reverb->delay);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_DELAY_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_DELAY", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DELAY;
- param_hdr.param_size = REVERB_DELAY_PARAM_SZ;
- param_data = (u8 *) &reverb->delay;
- break;
- case REVERB_DIFFUSION:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_DIFFUSION:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->diffusion =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_DIFFUSION val:%d\n",
- __func__, reverb->diffusion);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_DIFFUSION_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_DIFFUSION", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DIFFUSION;
- param_hdr.param_size = REVERB_DIFFUSION_PARAM_SZ;
- param_data = (u8 *) &reverb->diffusion;
- break;
- case REVERB_DENSITY:
- if (length != 1 || index_offset != 0) {
- pr_err("REVERB_DENSITY:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- reverb->density =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: REVERB_DENSITY val:%d\n",
- __func__, reverb->density);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- REVERB_DENSITY_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "REVERB_DENSITY", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_REVERB_DENSITY;
- param_hdr.param_size = REVERB_DENSITY_PARAM_SZ;
- param_data = (u8 *) &reverb->density;
- break;
- default:
- pr_err_ratelimited("%s: Invalid command to set config\n",
- __func__);
- continue;
- }
- if (rc)
- goto invalid_config;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- param_data, &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- }
- if (params_length && (rc == 0))
- q6asm_set_pp_params(ac, NULL, params, params_length);
- else
- pr_debug("%s: did not send pp params\n", __func__);
- invalid_config:
- kfree(params);
- return rc;
- }
- EXPORT_SYMBOL(msm_audio_effects_reverb_handler);
- /**
- * msm_audio_effects_bass_boost_handler -
- * Audio effects handler for bass_boost
- *
- * @ac: audio client handle
- * @bass_boost: bass_boost params
- * @values: values to be updated
- *
- * Return 0 on success or error on failure
- */
- int msm_audio_effects_bass_boost_handler(struct audio_client *ac,
- struct bass_boost_params *bass_boost,
- long *values)
- {
- long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
- char *params = NULL;
- u8 *updt_params;
- int rc = 0;
- int devices = GET_NEXT(values, param_max_offset, rc);
- int num_commands = GET_NEXT(values, param_max_offset, rc);
- int i, prev_enable_flag;
- uint32_t max_params_length = 0;
- uint32_t params_length = 0;
- struct param_hdr_v3 param_hdr;
- u8 *param_data = NULL;
- u32 packed_data_size = 0;
- pr_debug("%s\n", __func__);
- if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
- pr_err("%s: cannot set audio effects\n", __func__);
- return -EINVAL;
- }
- params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
- if (!params) {
- pr_err("%s, params memory alloc failed\n", __func__);
- return -ENOMEM;
- }
- pr_debug("%s: device: %d\n", __func__, devices);
- updt_params = (u8 *) params;
- /* Set MID and IID once at top and only update param specific fields*/
- memset(¶m_hdr, 0, sizeof(param_hdr));
- param_hdr.module_id = AUDPROC_MODULE_ID_BASS_BOOST;
- param_hdr.instance_id = INSTANCE_ID_0;
- for (i = 0; i < num_commands; i++) {
- uint32_t command_id =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t command_config_state =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t index_offset =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t length =
- GET_NEXT(values, param_max_offset, rc);
- switch (command_id) {
- case BASS_BOOST_ENABLE:
- if (length != 1 || index_offset != 0) {
- pr_err("BASS_BOOST_ENABLE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- prev_enable_flag = bass_boost->enable_flag;
- bass_boost->enable_flag =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: BASS_BOOST_ENABLE prev:%d new:%d\n",
- __func__, prev_enable_flag,
- bass_boost->enable_flag);
- if (prev_enable_flag == bass_boost->enable_flag)
- continue;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- BASS_BOOST_ENABLE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "BASS_BOOST_ENABLE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_BASS_BOOST_ENABLE;
- param_hdr.param_size = BASS_BOOST_ENABLE_PARAM_SZ;
- param_data = (u8 *) &bass_boost->enable_flag;
- break;
- case BASS_BOOST_MODE:
- if (length != 1 || index_offset != 0) {
- pr_err("BASS_BOOST_MODE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- bass_boost->mode =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: BASS_BOOST_MODE val:%d\n",
- __func__, bass_boost->mode);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- BASS_BOOST_MODE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "BASS_BOOST_MODE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_BASS_BOOST_MODE;
- param_hdr.param_size = BASS_BOOST_MODE_PARAM_SZ;
- param_data = (u8 *) &bass_boost->mode;
- break;
- case BASS_BOOST_STRENGTH:
- if (length != 1 || index_offset != 0) {
- pr_err("BASS_BOOST_STRENGTH:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- bass_boost->strength =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: BASS_BOOST_STRENGTH val:%d\n",
- __func__, bass_boost->strength);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- BASS_BOOST_STRENGTH_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "BASS_BOOST_STRENGTH", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_BASS_BOOST_STRENGTH;
- param_hdr.param_size = BASS_BOOST_STRENGTH_PARAM_SZ;
- param_data = (u8 *) &bass_boost->strength;
- break;
- default:
- pr_err_ratelimited("%s: Invalid command to set config\n",
- __func__);
- continue;
- }
- if (rc)
- goto invalid_config;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- param_data, &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- }
- if (params_length && (rc == 0))
- q6asm_set_pp_params(ac, NULL, params, params_length);
- else
- pr_debug("%s: did not send pp params\n", __func__);
- invalid_config:
- kfree(params);
- return rc;
- }
- EXPORT_SYMBOL(msm_audio_effects_bass_boost_handler);
- /**
- * msm_audio_effects_pbe_handler -
- * Audio effects handler for pbe
- *
- * @ac: audio client handle
- * @pbe: pbe params
- * @values: values to be updated
- *
- * Return 0 on success or error on failure
- */
- int msm_audio_effects_pbe_handler(struct audio_client *ac,
- struct pbe_params *pbe,
- long *values)
- {
- long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
- char *params = NULL;
- u8 *updt_params;
- int rc = 0;
- int devices = GET_NEXT(values, param_max_offset, rc);
- int num_commands = GET_NEXT(values, param_max_offset, rc);
- int i, prev_enable_flag;
- uint32_t max_params_length = 0;
- uint32_t params_length = 0;
- struct param_hdr_v3 param_hdr;
- u8 *param_data = NULL;
- u32 packed_data_size = 0;
- int32_t *p_coeffs = NULL;
- uint32_t lpf_len = 0, hpf_len = 0, bpf_len = 0;
- uint32_t bsf_len = 0, tsf_len = 0, total_coeffs_len = 0;
- pr_debug("%s\n", __func__);
- if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
- pr_err("%s: cannot set audio effects\n", __func__);
- return -EINVAL;
- }
- params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
- if (!params) {
- pr_err("%s, params memory alloc failed\n", __func__);
- return -ENOMEM;
- }
- pr_debug("%s: device: %d\n", __func__, devices);
- updt_params = (u8 *) params;
- /* Set MID and IID once at top and only update param specific fields*/
- memset(¶m_hdr, 0, sizeof(param_hdr));
- param_hdr.module_id = AUDPROC_MODULE_ID_PBE;
- param_hdr.instance_id = INSTANCE_ID_0;
- for (i = 0; i < num_commands; i++) {
- uint32_t command_id =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t command_config_state =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t index_offset =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t length =
- GET_NEXT(values, param_max_offset, rc);
- switch (command_id) {
- case PBE_ENABLE:
- pr_debug("%s: PBE_ENABLE\n", __func__);
- if (length != 1 || index_offset != 0) {
- pr_err("no valid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- prev_enable_flag = pbe->enable_flag;
- pbe->enable_flag =
- GET_NEXT(values, param_max_offset, rc);
- if (prev_enable_flag == pbe->enable_flag)
- continue;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- PBE_ENABLE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "PBE_ENABLE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_PBE_ENABLE;
- param_hdr.param_size = PBE_ENABLE_PARAM_SZ;
- param_data = (u8 *) &pbe->enable_flag;
- break;
- case PBE_CONFIG:
- pr_debug("%s: PBE_PARAM length %u\n", __func__, length);
- if (length > sizeof(struct pbe_config_t) ||
- length < PBE_CONFIG_PARAM_LEN ||
- index_offset != 0) {
- pr_err("no valid params, len %d\n", length);
- rc = -EINVAL;
- goto invalid_config;
- }
- pbe->config.real_bass_mix =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.bass_color_control =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.main_chain_delay =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.xover_filter_order =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.bandpass_filter_order =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.drc_delay =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.rms_tav =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.exp_threshold =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.exp_slope =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.comp_threshold =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.comp_slope =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.makeup_gain =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.comp_attack =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.comp_release =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.exp_attack =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.exp_release =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_bass_threshold =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_high_threshold =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_bass_makeup_gain =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_high_makeup_gain =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_bass_gc =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_high_gc =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.limiter_delay =
- GET_NEXT(values, param_max_offset, rc);
- pbe->config.reserved =
- GET_NEXT(values, param_max_offset, rc);
- p_coeffs = &pbe->config.p1LowPassCoeffs[0];
- lpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
- hpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
- bpf_len = pbe->config.bandpass_filter_order * 5;
- bsf_len = 5;
- tsf_len = 5;
- total_coeffs_len = lpf_len + hpf_len + bpf_len + bsf_len + tsf_len;
- for (i = 0; i < total_coeffs_len; i++) {
- *p_coeffs++ = GET_NEXT(values, param_max_offset, rc);
- }
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length =
- params_length + COMMAND_IID_PAYLOAD_SZ + length;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "PBE_PARAM", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_PBE_PARAM_CONFIG;
- param_hdr.param_size = length;
- param_data = (u8 *) &pbe->config;
- break;
- default:
- pr_err_ratelimited("%s: Invalid command to set config\n",
- __func__);
- continue;
- }
- if (rc)
- goto invalid_config;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- param_data, &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- }
- if (params_length && (rc == 0))
- q6asm_set_pp_params(ac, NULL, params, params_length);
- invalid_config:
- kfree(params);
- return rc;
- }
- EXPORT_SYMBOL(msm_audio_effects_pbe_handler);
- /**
- * msm_audio_effects_popless_eq_handler -
- * Audio effects handler for popless equalizer
- *
- * @ac: audio client handle
- * @eq: equalizer params
- * @values: values to be updated
- *
- * Return 0 on success or error on failure
- */
- int msm_audio_effects_popless_eq_handler(struct audio_client *ac,
- struct eq_params *eq,
- long *values)
- {
- long *param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
- char *params = NULL;
- u8 *updt_params = NULL;
- int rc = 0;
- int devices = GET_NEXT(values, param_max_offset, rc);
- int num_commands = GET_NEXT(values, param_max_offset, rc);
- int i, prev_enable_flag;
- uint32_t max_params_length = 0;
- uint32_t params_length = 0;
- struct param_hdr_v3 param_hdr;
- u8 *param_data = NULL;
- u32 packed_data_size = 0;
- u8 *eq_config_data = NULL;
- u32 *updt_config_data = NULL;
- int config_param_length;
- pr_debug("%s\n", __func__);
- if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
- pr_err("%s: cannot set audio effects\n", __func__);
- return -EINVAL;
- }
- params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
- if (!params) {
- pr_err("%s, params memory alloc failed\n", __func__);
- return -ENOMEM;
- }
- pr_debug("%s: device: %d\n", __func__, devices);
- updt_params = (u8 *) params;
- /* Set MID and IID once at top and only update param specific fields*/
- memset(¶m_hdr, 0, sizeof(param_hdr));
- param_hdr.module_id = AUDPROC_MODULE_ID_POPLESS_EQUALIZER;
- param_hdr.instance_id = INSTANCE_ID_0;
- for (i = 0; i < num_commands; i++) {
- uint32_t command_id =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t command_config_state =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t index_offset =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t length =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t idx;
- int j;
- switch (command_id) {
- case EQ_ENABLE:
- if (length != 1 || index_offset != 0) {
- pr_err("EQ_ENABLE:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- prev_enable_flag = eq->enable_flag;
- eq->enable_flag =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: EQ_ENABLE prev:%d new:%d\n", __func__,
- prev_enable_flag, eq->enable_flag);
- if (prev_enable_flag == eq->enable_flag)
- continue;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- EQ_ENABLE_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "EQ_ENABLE", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_EQ_ENABLE;
- param_hdr.param_size = EQ_ENABLE_PARAM_SZ;
- param_data = (u8 *) &eq->enable_flag;
- break;
- case EQ_CONFIG:
- if (length < EQ_CONFIG_PARAM_LEN || index_offset != 0) {
- pr_err("EQ_CONFIG:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- pr_debug("%s: EQ_CONFIG bands:%d, pgain:%d, pset:%d\n",
- __func__, eq->config.num_bands,
- eq->config.eq_pregain, eq->config.preset_id);
- for (idx = 0; idx < MAX_EQ_BANDS; idx++)
- eq->per_band_cfg[idx].band_idx = -1;
- eq->config.eq_pregain =
- GET_NEXT(values, param_max_offset, rc);
- eq->config.preset_id =
- GET_NEXT(values, param_max_offset, rc);
- eq->config.num_bands =
- GET_NEXT(values, param_max_offset, rc);
- if (eq->config.num_bands > MAX_EQ_BANDS) {
- pr_err("EQ_CONFIG:invalid num of bands\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- if (eq->config.num_bands &&
- (((length - EQ_CONFIG_PARAM_LEN)/
- EQ_CONFIG_PER_BAND_PARAM_LEN)
- != eq->config.num_bands)) {
- pr_err("EQ_CONFIG:invalid length per band\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- for (j = 0; j < eq->config.num_bands; j++) {
- idx = GET_NEXT(values, param_max_offset, rc);
- if (idx >= MAX_EQ_BANDS) {
- pr_err("EQ_CONFIG:invalid band index\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- eq->per_band_cfg[idx].band_idx = idx;
- eq->per_band_cfg[idx].filter_type =
- GET_NEXT(values, param_max_offset, rc);
- eq->per_band_cfg[idx].freq_millihertz =
- GET_NEXT(values, param_max_offset, rc);
- eq->per_band_cfg[idx].gain_millibels =
- GET_NEXT(values, param_max_offset, rc);
- eq->per_band_cfg[idx].quality_factor =
- GET_NEXT(values, param_max_offset, rc);
- }
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- config_param_length = EQ_CONFIG_PARAM_SZ +
- (EQ_CONFIG_PER_BAND_PARAM_SZ *
- eq->config.num_bands);
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- config_param_length;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "EQ_CONFIG", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_EQ_CONFIG;
- param_hdr.param_size = config_param_length;
- if (!eq_config_data)
- eq_config_data = kzalloc(config_param_length,
- GFP_KERNEL);
- else
- memset(eq_config_data, 0, config_param_length);
- if (!eq_config_data) {
- pr_err("%s, EQ_CONFIG:memory alloc failed\n",
- __func__);
- rc = -ENOMEM;
- goto invalid_config;
- }
- param_data = eq_config_data;
- updt_config_data = (u32 *) eq_config_data;
- *updt_config_data++ = eq->config.eq_pregain;
- *updt_config_data++ = eq->config.preset_id;
- *updt_config_data++ = eq->config.num_bands;
- for (idx = 0; idx < MAX_EQ_BANDS; idx++) {
- if (eq->per_band_cfg[idx].band_idx < 0)
- continue;
- *updt_config_data++ =
- eq->per_band_cfg[idx].filter_type;
- *updt_config_data++ =
- eq->per_band_cfg[idx].freq_millihertz;
- *updt_config_data++ =
- eq->per_band_cfg[idx].gain_millibels;
- *updt_config_data++ =
- eq->per_band_cfg[idx].quality_factor;
- *updt_config_data++ =
- eq->per_band_cfg[idx].band_idx;
- }
- break;
- case EQ_BAND_INDEX:
- if (length != 1 || index_offset != 0) {
- pr_err("EQ_BAND_INDEX:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- idx = GET_NEXT(values, param_max_offset, rc);
- if (idx > MAX_EQ_BANDS) {
- pr_err("EQ_BAND_INDEX:invalid band index\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- eq->band_index = idx;
- pr_debug("%s: EQ_BAND_INDEX val:%d\n",
- __func__, eq->band_index);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- EQ_BAND_INDEX_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "EQ_BAND_INDEX", rc);
- if (rc != 0)
- break;
- param_hdr.param_id = AUDPROC_PARAM_ID_EQ_BAND_INDEX;
- param_hdr.param_size = EQ_BAND_INDEX_PARAM_SZ;
- param_data = (u8 *) &eq->band_index;
- break;
- case EQ_SINGLE_BAND_FREQ:
- if (length != 1 || index_offset != 0) {
- pr_err("EQ_SINGLE_BAND_FREQ:invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- if (eq->band_index > MAX_EQ_BANDS) {
- pr_err("EQ_SINGLE_BAND_FREQ:invalid index\n");
- break;
- }
- eq->freq_millihertz =
- GET_NEXT(values, param_max_offset, rc);
- pr_debug("%s: EQ_SINGLE_BAND_FREQ idx:%d, val:%d\n",
- __func__, eq->band_index, eq->freq_millihertz);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- EQ_SINGLE_BAND_FREQ_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "EQ_SINGLE_BAND_FREQ", rc);
- if (rc != 0)
- break;
- param_hdr.param_id =
- AUDPROC_PARAM_ID_EQ_SINGLE_BAND_FREQ;
- param_hdr.param_size = EQ_SINGLE_BAND_FREQ_PARAM_SZ;
- param_data = (u8 *) &eq->freq_millihertz;
- break;
- default:
- pr_err_ratelimited("%s: Invalid command to set config\n",
- __func__);
- continue;
- }
- if (rc)
- goto invalid_config;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- param_data, &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- }
- if (params_length && (rc == 0))
- q6asm_set_pp_params(ac, NULL, params, params_length);
- else
- pr_debug("%s: did not send pp params\n", __func__);
- invalid_config:
- kfree(params);
- kfree(eq_config_data);
- return rc;
- }
- EXPORT_SYMBOL(msm_audio_effects_popless_eq_handler);
- static int __msm_audio_effects_volume_handler(struct audio_client *ac,
- struct soft_volume_params *vol,
- long *values,
- int instance)
- {
- int devices;
- int num_commands;
- char *params = NULL;
- u8 *updt_params;
- int i;
- uint32_t vol_gain_2ch = 0;
- uint32_t max_params_length = 0;
- uint32_t params_length = 0;
- struct param_hdr_v3 param_hdr;
- u32 packed_data_size = 0;
- long *param_max_offset;
- int rc = 0;
- pr_debug("%s: instance: %d\n", __func__, instance);
- if (!values) {
- pr_err("%s: set audio effects failed, no valid data\n",
- __func__);
- return -EINVAL;
- }
- param_max_offset = values + MAX_PP_PARAMS_SZ - 1;
- devices = GET_NEXT(values, param_max_offset, rc);
- num_commands = GET_NEXT(values, param_max_offset, rc);
- if (!ac || (devices == -EINVAL) || (num_commands == -EINVAL)) {
- pr_err("%s: cannot set audio effects\n", __func__);
- return -EINVAL;
- }
- params = kzalloc(MAX_INBAND_PARAM_SZ, GFP_KERNEL);
- if (!params) {
- pr_err("%s, params memory alloc failed\n", __func__);
- return -ENOMEM;
- }
- updt_params = (u8 *) params;
- /* Set MID and IID once at top and only update param specific fields*/
- memset(¶m_hdr, 0, sizeof(param_hdr));
- q6asm_set_soft_volume_module_instance_ids(instance, ¶m_hdr);
- for (i = 0; i < num_commands; i++) {
- uint32_t command_id =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t command_config_state =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t index_offset =
- GET_NEXT(values, param_max_offset, rc);
- uint32_t length =
- GET_NEXT(values, param_max_offset, rc);
- switch (command_id) {
- case SOFT_VOLUME_GAIN_2CH:
- case SOFT_VOLUME2_GAIN_2CH:
- if (length != 2 || index_offset != 0) {
- pr_err("VOLUME_GAIN_2CH: invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- vol->left_gain = GET_NEXT(values, param_max_offset, rc);
- vol->right_gain =
- GET_NEXT(values, param_max_offset, rc);
- vol->master_gain = 0x2000;
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- SOFT_VOLUME_GAIN_2CH_PARAM_SZ +
- COMMAND_IID_PAYLOAD_SZ +
- SOFT_VOLUME_GAIN_MASTER_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "VOLUME/VOLUME2_GAIN_2CH", rc);
- break;
- case SOFT_VOLUME_GAIN_MASTER:
- case SOFT_VOLUME2_GAIN_MASTER:
- if (length != 1 || index_offset != 0) {
- pr_err("VOLUME_GAIN_MASTER: invalid params\n");
- rc = -EINVAL;
- goto invalid_config;
- }
- vol->left_gain = 0x2000;
- vol->right_gain = 0x2000;
- vol->master_gain =
- GET_NEXT(values, param_max_offset, rc);
- if (command_config_state != AUDIO_EFFECTS_CONFIG_SET)
- break;
- max_params_length = params_length +
- COMMAND_IID_PAYLOAD_SZ +
- SOFT_VOLUME_GAIN_2CH_PARAM_SZ +
- COMMAND_IID_PAYLOAD_SZ +
- SOFT_VOLUME_GAIN_MASTER_PARAM_SZ;
- CHECK_PARAM_LEN(max_params_length, MAX_INBAND_PARAM_SZ,
- "VOLUME/VOLUME2_GAIN_MASTER", rc);
- break;
- default:
- pr_err_ratelimited("%s: Invalid command id: %d to set config\n",
- __func__, command_id);
- continue;
- }
- if (rc)
- continue;
- /* Set Volume Control for Left/Right */
- param_hdr.param_id = ASM_PARAM_ID_VOL_CTRL_LR_CHANNEL_GAIN;
- param_hdr.param_size = SOFT_VOLUME_GAIN_2CH_PARAM_SZ;
- vol_gain_2ch = (vol->left_gain << 16) | vol->right_gain;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- (u8 *) &vol_gain_2ch,
- &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- /* Set Master Volume Control */
- param_hdr.param_id = ASM_PARAM_ID_VOL_CTRL_MASTER_GAIN;
- param_hdr.param_size = SOFT_VOLUME_GAIN_MASTER_PARAM_SZ;
- rc = q6common_pack_pp_params(updt_params, ¶m_hdr,
- (u8 *) &vol->master_gain,
- &packed_data_size);
- if (rc) {
- pr_err("%s: Failed to pack params, error %d\n",
- __func__, rc);
- goto invalid_config;
- }
- updt_params += packed_data_size;
- params_length += packed_data_size;
- }
- if (params_length && (rc == 0))
- q6asm_set_pp_params(ac, NULL, params, params_length);
- invalid_config:
- kfree(params);
- return rc;
- }
- int msm_audio_effects_volume_handler(struct audio_client *ac,
- struct soft_volume_params *vol,
- long *values)
- {
- return __msm_audio_effects_volume_handler(ac, vol, values,
- SOFT_VOLUME_INSTANCE_1);
- }
- /**
- * msm_audio_effects_volume_handler_v2 -
- * Audio effects handler for volume
- *
- * @ac: audio client handle
- * @vol: volume params
- * @values: values to be updated
- * @instance: instance to update
- *
- * Return 0 on success or error on failure
- */
- int msm_audio_effects_volume_handler_v2(struct audio_client *ac,
- struct soft_volume_params *vol,
- long *values, int instance)
- {
- return __msm_audio_effects_volume_handler(ac, vol, values, instance);
- }
- EXPORT_SYMBOL(msm_audio_effects_volume_handler_v2);
|