123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725 |
- // SPDX-License-Identifier: GPL-2.0-only
- /* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
- */
- #include <linux/init.h>
- #include <linux/err.h>
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/time.h>
- #include <linux/math64.h>
- #include <linux/wait.h>
- #include <linux/platform_device.h>
- #include <linux/slab.h>
- #include <sound/core.h>
- #include <sound/soc.h>
- #include <sound/soc-dapm.h>
- #include <sound/pcm.h>
- #include <sound/initval.h>
- #include <sound/control.h>
- #include <audio/sound/audio_effects.h>
- #include <sound/pcm_params.h>
- #include <sound/timer.h>
- #include <sound/tlv.h>
- #include <sound/compress_params.h>
- #include <sound/compress_offload.h>
- #include <sound/compress_driver.h>
- #include <dsp/msm_audio_ion.h>
- #include <dsp/apr_audio-v2.h>
- #include <dsp/q6asm-v2.h>
- #include <dsp/q6audio-v2.h>
- #include <dsp/msm-audio-effects-q6-v2.h>
- #include "msm-pcm-routing-v2.h"
- #include "msm-qti-pp-config.h"
- #define DRV_NAME "msm-transcode-loopback-v2"
- #define LOOPBACK_SESSION_MAX_NUM_STREAMS 2
- /* Max volume corresponding to 24dB */
- #define TRANSCODE_LR_VOL_MAX_DB 0xFFFF
- #define APP_TYPE_CONFIG_IDX_APP_TYPE 0
- #define APP_TYPE_CONFIG_IDX_ACDB_ID 1
- #define APP_TYPE_CONFIG_IDX_SAMPLE_RATE 2
- #define APP_TYPE_CONFIG_IDX_BE_ID 3
- static DEFINE_MUTEX(transcode_loopback_session_lock);
- struct msm_transcode_audio_effects {
- struct bass_boost_params bass_boost;
- struct pbe_params pbe;
- struct virtualizer_params virtualizer;
- struct reverb_params reverb;
- struct eq_params equalizer;
- struct soft_volume_params volume;
- };
- struct trans_loopback_pdata {
- struct snd_compr_stream *cstream[MSM_FRONTEND_DAI_MAX];
- uint32_t master_gain;
- int perf_mode[MSM_FRONTEND_DAI_MAX];
- struct msm_transcode_audio_effects *audio_effects[MSM_FRONTEND_DAI_MAX];
- };
- struct loopback_stream {
- struct snd_compr_stream *cstream;
- uint32_t codec_format;
- bool start;
- int perf_mode;
- };
- enum loopback_session_state {
- /* One or both streams not opened */
- LOOPBACK_SESSION_CLOSE = 0,
- /* Loopback streams opened */
- LOOPBACK_SESSION_READY,
- /* Loopback streams opened and formats configured */
- LOOPBACK_SESSION_START,
- /* Trigger issued on either of streams when in START state */
- LOOPBACK_SESSION_RUN
- };
- struct msm_transcode_loopback {
- struct loopback_stream source;
- struct loopback_stream sink;
- struct snd_compr_caps source_compr_cap;
- struct snd_compr_caps sink_compr_cap;
- uint32_t instance;
- uint32_t num_streams;
- int session_state;
- struct mutex lock;
- int session_id;
- struct audio_client *audio_client;
- };
- /* Transcode loopback global info struct */
- static struct msm_transcode_loopback transcode_info;
- static void loopback_event_handler(uint32_t opcode,
- uint32_t token, uint32_t *payload, void *priv)
- {
- struct msm_transcode_loopback *trans =
- (struct msm_transcode_loopback *)priv;
- struct snd_soc_pcm_runtime *rtd;
- struct snd_compr_stream *cstream;
- struct audio_client *ac;
- int stream_id;
- int ret;
- if (!trans || !payload) {
- pr_err("%s: rtd or payload is NULL\n", __func__);
- return;
- }
- cstream = trans->sink.cstream;
- ac = trans->audio_client;
- /*
- * Token for rest of the compressed commands use to set
- * session id, stream id, dir etc.
- */
- stream_id = q6asm_get_stream_id_from_token(token);
- switch (opcode) {
- case ASM_STREAM_CMD_ENCDEC_EVENTS:
- case ASM_IEC_61937_MEDIA_FMT_EVENT:
- pr_debug("%s: Handling stream event : 0X%x\n",
- __func__, opcode);
- rtd = cstream->private_data;
- if (!rtd) {
- pr_err("%s: rtd is NULL\n", __func__);
- return;
- }
- ret = msm_adsp_inform_mixer_ctl(rtd, payload);
- if (ret) {
- pr_err("%s: failed to inform mixer ctrl. err = %d\n",
- __func__, ret);
- return;
- }
- break;
- case APR_BASIC_RSP_RESULT: {
- switch (payload[0]) {
- case ASM_SESSION_CMD_RUN_V2:
- pr_debug("%s: ASM_SESSION_CMD_RUN_V2:", __func__);
- pr_debug("token 0x%x, stream id %d\n", token,
- stream_id);
- break;
- case ASM_STREAM_CMD_CLOSE:
- pr_debug("%s: ASM_DATA_CMD_CLOSE:", __func__);
- pr_debug("token 0x%x, stream id %d\n", token,
- stream_id);
- break;
- default:
- break;
- }
- break;
- }
- default:
- pr_debug("%s: Not Supported Event opcode[0x%x]\n",
- __func__, opcode);
- break;
- }
- }
- static void populate_codec_list(struct msm_transcode_loopback *trans,
- struct snd_compr_stream *cstream)
- {
- struct snd_compr_caps compr_cap;
- pr_debug("%s\n", __func__);
- memset(&compr_cap, 0, sizeof(struct snd_compr_caps));
- if (cstream->direction == SND_COMPRESS_CAPTURE) {
- compr_cap.direction = SND_COMPRESS_CAPTURE;
- compr_cap.num_codecs = 4;
- compr_cap.codecs[0] = SND_AUDIOCODEC_PCM;
- compr_cap.codecs[1] = SND_AUDIOCODEC_AC3;
- compr_cap.codecs[2] = SND_AUDIOCODEC_EAC3;
- compr_cap.codecs[3] = SND_AUDIOCODEC_TRUEHD;
- memcpy(&trans->source_compr_cap, &compr_cap,
- sizeof(struct snd_compr_caps));
- }
- if (cstream->direction == SND_COMPRESS_PLAYBACK) {
- compr_cap.direction = SND_COMPRESS_PLAYBACK;
- compr_cap.num_codecs = 1;
- compr_cap.codecs[0] = SND_AUDIOCODEC_PCM;
- memcpy(&trans->sink_compr_cap, &compr_cap,
- sizeof(struct snd_compr_caps));
- }
- }
- static int msm_transcode_loopback_open(struct snd_compr_stream *cstream)
- {
- int ret = 0;
- struct snd_compr_runtime *runtime;
- struct snd_soc_pcm_runtime *rtd;
- struct msm_transcode_loopback *trans = &transcode_info;
- struct trans_loopback_pdata *pdata;
- struct snd_soc_component *component;
- if (cstream == NULL) {
- pr_err("%s: Invalid substream\n", __func__);
- return -EINVAL;
- }
- runtime = cstream->runtime;
- rtd = snd_pcm_substream_chip(cstream);
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- pdata->cstream[rtd->dai_link->id] = cstream;
- pdata->audio_effects[rtd->dai_link->id] =
- kzalloc(sizeof(struct msm_transcode_audio_effects), GFP_KERNEL);
- if (pdata->audio_effects[rtd->dai_link->id] == NULL) {
- ret = -ENOMEM;
- goto effect_error;
- }
- mutex_lock(&trans->lock);
- if (trans->num_streams > LOOPBACK_SESSION_MAX_NUM_STREAMS) {
- pr_err("msm_transcode_open failed..invalid stream\n");
- ret = -EINVAL;
- goto exit;
- }
- if (cstream->direction == SND_COMPRESS_CAPTURE) {
- if (trans->source.cstream == NULL) {
- trans->source.cstream = cstream;
- trans->num_streams++;
- } else {
- pr_err("%s: capture stream already opened\n",
- __func__);
- ret = -EINVAL;
- goto exit;
- }
- } else if (cstream->direction == SND_COMPRESS_PLAYBACK) {
- if (trans->sink.cstream == NULL) {
- trans->sink.cstream = cstream;
- trans->num_streams++;
- } else {
- pr_debug("%s: playback stream already opened\n",
- __func__);
- ret = -EINVAL;
- goto exit;
- }
- msm_adsp_init_mixer_ctl_pp_event_queue(rtd);
- }
- pr_debug("%s: num stream%d, stream name %s\n", __func__,
- trans->num_streams, cstream->name);
- populate_codec_list(trans, cstream);
- if (trans->num_streams == LOOPBACK_SESSION_MAX_NUM_STREAMS) {
- pr_debug("%s: Moving loopback session to READY state %d\n",
- __func__, trans->session_state);
- trans->session_state = LOOPBACK_SESSION_READY;
- }
- runtime->private_data = trans;
- exit:
- mutex_unlock(&trans->lock);
- if ((pdata->audio_effects[rtd->dai_link->id] != NULL) && (ret < 0)) {
- kfree(pdata->audio_effects[rtd->dai_link->id]);
- pdata->audio_effects[rtd->dai_link->id] = NULL;
- }
- effect_error:
- return ret;
- }
- static void stop_transcoding(struct msm_transcode_loopback *trans)
- {
- struct snd_soc_pcm_runtime *soc_pcm_rx;
- struct snd_soc_pcm_runtime *soc_pcm_tx;
- if (trans->audio_client != NULL) {
- q6asm_cmd(trans->audio_client, CMD_CLOSE);
- if (trans->sink.cstream != NULL) {
- soc_pcm_rx = trans->sink.cstream->private_data;
- msm_pcm_routing_dereg_phy_stream(
- soc_pcm_rx->dai_link->id,
- SND_COMPRESS_PLAYBACK);
- }
- if (trans->source.cstream != NULL) {
- soc_pcm_tx = trans->source.cstream->private_data;
- msm_pcm_routing_dereg_phy_stream(
- soc_pcm_tx->dai_link->id,
- SND_COMPRESS_CAPTURE);
- }
- q6asm_audio_client_free(trans->audio_client);
- trans->audio_client = NULL;
- }
- }
- static int msm_transcode_loopback_free(struct snd_compr_stream *cstream)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_transcode_loopback *trans = runtime->private_data;
- struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(cstream);
- struct snd_soc_component *component;
- struct trans_loopback_pdata *pdata;
- int ret = 0;
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- mutex_lock(&trans->lock);
- if (pdata->audio_effects[rtd->dai_link->id] != NULL) {
- kfree(pdata->audio_effects[rtd->dai_link->id]);
- pdata->audio_effects[rtd->dai_link->id] = NULL;
- }
- pr_debug("%s: Transcode loopback end:%d, streams %d\n", __func__,
- cstream->direction, trans->num_streams);
- trans->num_streams--;
- stop_transcoding(trans);
- if (cstream->direction == SND_COMPRESS_PLAYBACK) {
- memset(&trans->sink, 0, sizeof(struct loopback_stream));
- msm_adsp_clean_mixer_ctl_pp_event_queue(rtd);
- } else if (cstream->direction == SND_COMPRESS_CAPTURE) {
- memset(&trans->source, 0, sizeof(struct loopback_stream));
- }
- trans->session_state = LOOPBACK_SESSION_CLOSE;
- mutex_unlock(&trans->lock);
- return ret;
- }
- static int msm_transcode_loopback_trigger(struct snd_compr_stream *cstream,
- int cmd)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_transcode_loopback *trans = runtime->private_data;
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- case SNDRV_PCM_TRIGGER_RESUME:
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- if (trans->session_state == LOOPBACK_SESSION_START) {
- pr_debug("%s: Issue Loopback session %d RUN\n",
- __func__, trans->instance);
- q6asm_run_nowait(trans->audio_client, 0, 0, 0);
- trans->session_state = LOOPBACK_SESSION_RUN;
- }
- break;
- case SNDRV_PCM_TRIGGER_SUSPEND:
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- case SNDRV_PCM_TRIGGER_STOP:
- pr_debug("%s: Issue Loopback session %d STOP\n", __func__,
- trans->instance);
- if (trans->session_state == LOOPBACK_SESSION_RUN)
- q6asm_cmd_nowait(trans->audio_client, CMD_PAUSE);
- trans->session_state = LOOPBACK_SESSION_START;
- break;
- default:
- break;
- }
- return 0;
- }
- static int msm_transcode_set_render_window(struct audio_client *ac,
- uint32_t ws_lsw, uint32_t ws_msw,
- uint32_t we_lsw, uint32_t we_msw)
- {
- int ret = -EINVAL;
- struct asm_session_mtmx_strtr_param_window_v2_t asm_mtmx_strtr_window;
- uint32_t param_id;
- pr_debug("%s, ws_lsw 0x%x ws_msw 0x%x we_lsw 0x%x we_msw 0x%x\n",
- __func__, ws_lsw, ws_msw, we_lsw, we_msw);
- memset(&asm_mtmx_strtr_window, 0,
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t));
- asm_mtmx_strtr_window.window_lsw = ws_lsw;
- asm_mtmx_strtr_window.window_msw = ws_msw;
- param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_START_V2;
- ret = q6asm_send_mtmx_strtr_window(ac, &asm_mtmx_strtr_window, param_id);
- if (ret) {
- pr_err("%s, start window can't be set error %d\n", __func__, ret);
- goto exit;
- }
- asm_mtmx_strtr_window.window_lsw = we_lsw;
- asm_mtmx_strtr_window.window_msw = we_msw;
- param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_END_V2;
- ret = q6asm_send_mtmx_strtr_window(ac, &asm_mtmx_strtr_window, param_id);
- if (ret)
- pr_err("%s, end window can't be set error %d\n", __func__, ret);
- exit:
- return ret;
- }
- static int msm_transcode_loopback_set_params(struct snd_compr_stream *cstream,
- struct snd_compr_params *codec_param)
- {
- struct snd_compr_runtime *runtime = cstream->runtime;
- struct msm_transcode_loopback *trans = runtime->private_data;
- struct snd_soc_pcm_runtime *soc_pcm_rx;
- struct snd_soc_pcm_runtime *soc_pcm_tx;
- struct snd_soc_pcm_runtime *rtd;
- struct snd_soc_component *component;
- struct trans_loopback_pdata *pdata;
- uint32_t bit_width = 16;
- int ret = 0;
- enum apr_subsys_state subsys_state;
- if (trans == NULL) {
- pr_err("%s: Invalid param\n", __func__);
- return -EINVAL;
- }
- subsys_state = apr_get_subsys_state();
- if (subsys_state == APR_SUBSYS_DOWN) {
- pr_debug("%s: adsp is down\n", __func__);
- return -ENETRESET;
- }
- mutex_lock(&trans->lock);
- rtd = snd_pcm_substream_chip(cstream);
- if (!rtd) {
- pr_err("%s: rtd is NULL\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- if (cstream->direction == SND_COMPRESS_PLAYBACK) {
- if (codec_param->codec.id == SND_AUDIOCODEC_PCM) {
- trans->sink.codec_format =
- FORMAT_LINEAR_PCM;
- switch (codec_param->codec.format) {
- case SNDRV_PCM_FORMAT_S32_LE:
- bit_width = 32;
- break;
- case SNDRV_PCM_FORMAT_S24_LE:
- bit_width = 24;
- break;
- case SNDRV_PCM_FORMAT_S24_3LE:
- bit_width = 24;
- break;
- case SNDRV_PCM_FORMAT_S16_LE:
- default:
- bit_width = 16;
- break;
- }
- } else {
- pr_debug("%s: unknown sink codec\n", __func__);
- ret = -EINVAL;
- goto exit;
- }
- trans->sink.start = true;
- trans->sink.perf_mode = pdata->perf_mode[rtd->dai_link->id];
- }
- if (cstream->direction == SND_COMPRESS_CAPTURE) {
- switch (codec_param->codec.id) {
- case SND_AUDIOCODEC_PCM:
- pr_debug("Source SND_AUDIOCODEC_PCM\n");
- trans->source.codec_format =
- FORMAT_LINEAR_PCM;
- break;
- case SND_AUDIOCODEC_AC3:
- pr_debug("Source SND_AUDIOCODEC_AC3\n");
- trans->source.codec_format =
- FORMAT_AC3;
- break;
- case SND_AUDIOCODEC_EAC3:
- pr_debug("Source SND_AUDIOCODEC_EAC3\n");
- trans->source.codec_format =
- FORMAT_EAC3;
- break;
- case SND_AUDIOCODEC_TRUEHD:
- pr_debug("Source SND_AUDIOCODEC_TRUEHD\n");
- trans->source.codec_format =
- FORMAT_TRUEHD;
- break;
- default:
- pr_debug("%s: unknown source codec\n", __func__);
- ret = -EINVAL;
- goto exit;
- }
- trans->source.start = true;
- trans->source.perf_mode = pdata->perf_mode[rtd->dai_link->id];
- }
- pr_debug("%s: trans->source.start %d trans->sink.start %d trans->source.cstream %pK trans->sink.cstream %pK trans->session_state %d\n",
- __func__, trans->source.start, trans->sink.start,
- trans->source.cstream, trans->sink.cstream,
- trans->session_state);
- if ((trans->session_state == LOOPBACK_SESSION_READY) &&
- trans->source.start && trans->sink.start) {
- pr_debug("%s: Moving loopback session to start state\n",
- __func__);
- trans->session_state = LOOPBACK_SESSION_START;
- }
- if (trans->session_state == LOOPBACK_SESSION_START) {
- if (trans->audio_client != NULL) {
- pr_debug("%s: ASM client already opened, closing\n",
- __func__);
- stop_transcoding(trans);
- }
- trans->audio_client = q6asm_audio_client_alloc(
- (app_cb)loopback_event_handler, trans);
- if (!trans->audio_client) {
- pr_err("%s: Could not allocate memory\n", __func__);
- ret = -EINVAL;
- goto exit;
- }
- pr_debug("%s: ASM client allocated, callback %pK\n", __func__,
- loopback_event_handler);
- trans->session_id = trans->audio_client->session;
- trans->audio_client->perf_mode = trans->sink.perf_mode;
- ret = q6asm_open_transcode_loopback(trans->audio_client,
- bit_width,
- trans->source.codec_format,
- trans->sink.codec_format);
- if (ret < 0) {
- pr_err("%s: Session transcode loopback open failed\n",
- __func__);
- q6asm_audio_client_free(trans->audio_client);
- trans->audio_client = NULL;
- goto exit;
- }
- pr_debug("%s: Starting ADM open for loopback\n", __func__);
- soc_pcm_rx = trans->sink.cstream->private_data;
- soc_pcm_tx = trans->source.cstream->private_data;
- if (trans->source.codec_format != FORMAT_LINEAR_PCM)
- msm_pcm_routing_reg_phy_compr_stream(
- soc_pcm_tx->dai_link->id,
- LEGACY_PCM_MODE,
- trans->session_id,
- SNDRV_PCM_STREAM_CAPTURE,
- COMPRESSED_PASSTHROUGH_GEN);
- else
- msm_pcm_routing_reg_phy_stream(
- soc_pcm_tx->dai_link->id,
- trans->source.perf_mode,
- trans->session_id,
- SNDRV_PCM_STREAM_CAPTURE);
- /* Opening Rx ADM in LOW_LATENCY mode by default */
- msm_pcm_routing_reg_phy_stream(
- soc_pcm_rx->dai_link->id,
- trans->sink.perf_mode,
- trans->session_id,
- SNDRV_PCM_STREAM_PLAYBACK);
- pr_debug("%s: Successfully opened ADM sessions\n", __func__);
- }
- exit:
- mutex_unlock(&trans->lock);
- return ret;
- }
- static int msm_transcode_loopback_get_caps(struct snd_compr_stream *cstream,
- struct snd_compr_caps *arg)
- {
- struct snd_compr_runtime *runtime;
- struct msm_transcode_loopback *trans;
- if (!arg || !cstream) {
- pr_err("%s: Invalid arguments\n", __func__);
- return -EINVAL;
- }
- runtime = cstream->runtime;
- trans = runtime->private_data;
- pr_debug("%s\n", __func__);
- if (cstream->direction == SND_COMPRESS_CAPTURE)
- memcpy(arg, &trans->source_compr_cap,
- sizeof(struct snd_compr_caps));
- else
- memcpy(arg, &trans->sink_compr_cap,
- sizeof(struct snd_compr_caps));
- return 0;
- }
- static int msm_transcode_loopback_set_metadata(struct snd_compr_stream *cstream,
- struct snd_compr_metadata *metadata)
- {
- struct snd_soc_pcm_runtime *rtd;
- struct trans_loopback_pdata *pdata;
- struct msm_transcode_loopback *prtd = NULL;
- struct snd_soc_component *component;
- struct audio_client *ac = NULL;
- if (!metadata || !cstream) {
- pr_err("%s: Invalid arguments\n", __func__);
- return -EINVAL;
- }
- rtd = snd_pcm_substream_chip(cstream);
- if (!rtd) {
- pr_err("%s: rtd is NULL\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pdata = snd_soc_component_get_drvdata(component);
- prtd = cstream->runtime->private_data;
- if (!prtd || !prtd->audio_client) {
- pr_err("%s: prtd or audio client is NULL\n", __func__);
- return -EINVAL;
- }
- ac = prtd->audio_client;
- switch (metadata->key) {
- case SNDRV_COMPRESS_LATENCY_MODE:
- {
- switch (metadata->value[0]) {
- case SNDRV_COMPRESS_LEGACY_LATENCY_MODE:
- pdata->perf_mode[rtd->dai_link->id] = LEGACY_PCM_MODE;
- break;
- case SNDRV_COMPRESS_LOW_LATENCY_MODE:
- pdata->perf_mode[rtd->dai_link->id] =
- LOW_LATENCY_PCM_MODE;
- break;
- default:
- pr_debug("%s: Unsupported latency mode %d, default to Legacy\n",
- __func__, metadata->value[0]);
- pdata->perf_mode[rtd->dai_link->id] = LEGACY_PCM_MODE;
- break;
- }
- break;
- }
- case SNDRV_COMPRESS_RENDER_WINDOW:
- {
- return msm_transcode_set_render_window(
- ac,
- metadata->value[0],
- metadata->value[1],
- metadata->value[2],
- metadata->value[3]);
- }
- default:
- pr_debug("%s: Unsupported metadata %d\n",
- __func__, metadata->key);
- break;
- }
- return 0;
- }
- static int msm_transcode_stream_cmd_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_transcode_loopback *prtd;
- int ret = 0;
- struct msm_adsp_event_data *event_data = NULL;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received invalid fe_id %lu\n",
- __func__, fe_id);
- ret = -EINVAL;
- goto done;
- }
- cstream = pdata->cstream[fe_id];
- if (cstream == NULL) {
- pr_err("%s cstream is null.\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: prtd is null.\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- if (prtd->audio_client == NULL) {
- pr_err("%s: audio_client is null.\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- event_data = (struct msm_adsp_event_data *)ucontrol->value.bytes.data;
- if ((event_data->event_type < ADSP_STREAM_PP_EVENT) ||
- (event_data->event_type >= ADSP_STREAM_EVENT_MAX)) {
- pr_err("%s: invalid event_type=%d",
- __func__, event_data->event_type);
- ret = -EINVAL;
- goto done;
- }
- if (event_data->payload_len > sizeof(ucontrol->value.bytes.data)
- - sizeof(struct msm_adsp_event_data)) {
- pr_err("%s param length=%d exceeds limit",
- __func__, event_data->payload_len);
- ret = -EINVAL;
- goto done;
- }
- ret = q6asm_send_stream_cmd(prtd->audio_client, event_data);
- if (ret < 0)
- pr_err("%s: failed to send stream event cmd, err = %d\n",
- __func__, ret);
- done:
- return ret;
- }
- static int msm_transcode_ion_fd_map_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_transcode_loopback *prtd;
- int fd;
- int ret = 0;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds invalid fe_id %lu\n",
- __func__, fe_id);
- ret = -EINVAL;
- goto done;
- }
- cstream = pdata->cstream[fe_id];
- if (cstream == NULL) {
- pr_err("%s cstream is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: prtd is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- if (prtd->audio_client == NULL) {
- pr_err("%s: audio_client is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- memcpy(&fd, ucontrol->value.bytes.data, sizeof(fd));
- ret = q6asm_send_ion_fd(prtd->audio_client, fd);
- if (ret < 0)
- pr_err("%s: failed to register ion fd\n", __func__);
- done:
- return ret;
- }
- static int msm_transcode_rtic_event_ack_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- struct msm_transcode_loopback *prtd;
- int ret = 0;
- int param_length = 0;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received invalid fe_id %lu\n",
- __func__, fe_id);
- ret = -EINVAL;
- goto done;
- }
- cstream = pdata->cstream[fe_id];
- if (cstream == NULL) {
- pr_err("%s cstream is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: prtd is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- if (prtd->audio_client == NULL) {
- pr_err("%s: audio_client is null\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- memcpy(¶m_length, ucontrol->value.bytes.data,
- sizeof(param_length));
- if ((param_length + sizeof(param_length))
- >= sizeof(ucontrol->value.bytes.data)) {
- pr_err("%s param length=%d exceeds limit",
- __func__, param_length);
- ret = -EINVAL;
- goto done;
- }
- ret = q6asm_send_rtic_event_ack(prtd->audio_client,
- ucontrol->value.bytes.data + sizeof(param_length),
- param_length);
- if (ret < 0)
- pr_err("%s: failed to send rtic event ack, err = %d\n",
- __func__, ret);
- done:
- return ret;
- }
- static int msm_transcode_playback_app_type_cfg_put(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_RX;
- int be_id = ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID];
- struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
- int ret = 0;
- cfg_data.app_type = ucontrol->value.integer.value[
- APP_TYPE_CONFIG_IDX_APP_TYPE];
- cfg_data.acdb_dev_id = ucontrol->value.integer.value[
- APP_TYPE_CONFIG_IDX_ACDB_ID];
- if (ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] != 0)
- cfg_data.sample_rate = ucontrol->value.integer.value[
- APP_TYPE_CONFIG_IDX_SAMPLE_RATE];
- pr_debug("%s: fe_id %llu session_type %d be_id %d app_type %d acdb_dev_id %d sample_rate- %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
- be_id, &cfg_data);
- if (ret < 0)
- pr_err("%s: msm_transcode_playback_stream_app_type_cfg set failed returned %d\n",
- __func__, ret);
- return ret;
- }
- static int msm_transcode_playback_app_type_cfg_get(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_RX;
- int be_id = 0;
- struct msm_pcm_stream_app_type_cfg cfg_data = {0};
- int ret = 0;
- ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
- &be_id, &cfg_data);
- if (ret < 0) {
- pr_err("%s: msm_transcode_playback_stream_app_type_cfg get failed returned %d\n",
- __func__, ret);
- goto done;
- }
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_APP_TYPE] =
- cfg_data.app_type;
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_ACDB_ID] =
- cfg_data.acdb_dev_id;
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] =
- cfg_data.sample_rate;
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID] = be_id;
- pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- done:
- return ret;
- }
- static int msm_transcode_capture_app_type_cfg_put(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_TX;
- int be_id = ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID];
- struct msm_pcm_stream_app_type_cfg cfg_data = {0, 0, 48000};
- int ret = 0;
- cfg_data.app_type = ucontrol->value.integer.value[
- APP_TYPE_CONFIG_IDX_APP_TYPE];
- cfg_data.acdb_dev_id = ucontrol->value.integer.value[
- APP_TYPE_CONFIG_IDX_ACDB_ID];
- if (ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] != 0)
- cfg_data.sample_rate = ucontrol->value.integer.value[
- APP_TYPE_CONFIG_IDX_SAMPLE_RATE];
- pr_debug("%s: fe_id %llu session_type %d be_id %d app_type %d acdb_dev_id %d sample_rate- %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- ret = msm_pcm_routing_reg_stream_app_type_cfg(fe_id, session_type,
- be_id, &cfg_data);
- if (ret < 0)
- pr_err("%s: register stream app type cfg failed, returned %d\n",
- __func__, ret);
- return ret;
- }
- static int msm_transcode_capture_app_type_cfg_get(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u64 fe_id = kcontrol->private_value;
- int session_type = SESSION_TYPE_TX;
- int be_id = 0;
- struct msm_pcm_stream_app_type_cfg cfg_data = {0};
- int ret = 0;
- ret = msm_pcm_routing_get_stream_app_type_cfg(fe_id, session_type,
- &be_id, &cfg_data);
- if (ret < 0) {
- pr_err("%s: get stream app type cfg failed, returned %d\n",
- __func__, ret);
- goto done;
- }
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_APP_TYPE] =
- cfg_data.app_type;
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_ACDB_ID] =
- cfg_data.acdb_dev_id;
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_SAMPLE_RATE] =
- cfg_data.sample_rate;
- ucontrol->value.integer.value[APP_TYPE_CONFIG_IDX_BE_ID] = be_id;
- pr_debug("%s: fedai_id %llu, session_type %d, be_id %d, app_type %d, acdb_dev_id %d, sample_rate %d\n",
- __func__, fe_id, session_type, be_id,
- cfg_data.app_type, cfg_data.acdb_dev_id, cfg_data.sample_rate);
- done:
- return ret;
- }
- static int msm_transcode_set_volume(struct snd_compr_stream *cstream,
- uint32_t master_gain)
- {
- int rc = 0;
- struct msm_transcode_loopback *prtd;
- struct snd_soc_pcm_runtime *rtd;
- pr_debug("%s: master_gain %d\n", __func__, master_gain);
- if (!cstream || !cstream->runtime) {
- pr_err("%s: session not active\n", __func__);
- return -EINVAL;
- }
- rtd = cstream->private_data;
- prtd = cstream->runtime->private_data;
- if (!rtd || !prtd || !prtd->audio_client) {
- pr_err("%s: invalid rtd, prtd or audio client", __func__);
- return -EINVAL;
- }
- rc = q6asm_set_volume(prtd->audio_client, master_gain);
- if (rc < 0)
- pr_err("%s: Send vol gain command failed rc=%d\n",
- __func__, rc);
- return rc;
- }
- static int msm_transcode_volume_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct snd_compr_stream *cstream = NULL;
- uint32_t ret = 0;
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- cstream = pdata->cstream[fe_id];
- pdata->master_gain = ucontrol->value.integer.value[0];
- pr_debug("%s: fe_id %lu master_gain %d\n",
- __func__, fe_id, pdata->master_gain);
- if (cstream)
- ret = msm_transcode_set_volume(cstream, pdata->master_gain);
- return ret;
- }
- static int msm_transcode_volume_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bound fe_id %lu\n", __func__, fe_id);
- return -EINVAL;
- }
- pr_debug("%s: fe_id %lu\n", __func__, fe_id);
- ucontrol->value.integer.value[0] = pdata->master_gain;
- return 0;
- }
- static int msm_transcode_audio_effects_config_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = MAX_PP_PARAMS_SZ;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0xFFFFFFFF;
- return 0;
- }
- static int msm_transcode_audio_effects_config_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_transcode_audio_effects *audio_effects = NULL;
- struct snd_compr_stream *cstream = NULL;
- pr_debug("%s: fe_id: %lu\n", __func__, fe_id);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- return -EINVAL;
- }
- cstream = pdata->cstream[fe_id];
- audio_effects = pdata->audio_effects[fe_id];
- if (!cstream || !audio_effects) {
- pr_err("%s: stream or effects inactive\n", __func__);
- return -EINVAL;
- }
- return 0;
- }
- static int msm_transcode_audio_effects_config_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
- unsigned long fe_id = kcontrol->private_value;
- struct trans_loopback_pdata *pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(comp);
- struct msm_transcode_audio_effects *audio_effects = NULL;
- struct snd_compr_stream *cstream = NULL;
- struct msm_transcode_loopback *prtd = NULL;
- long *values = &(ucontrol->value.integer.value[0]);
- int effects_module;
- int ret = 0;
- pr_debug("%s: fe_id: %lu\n", __func__, fe_id);
- if (fe_id >= MSM_FRONTEND_DAI_MAX) {
- pr_err("%s Received out of bounds fe_id %lu\n",
- __func__, fe_id);
- ret = -EINVAL;
- goto exit;
- }
- cstream = pdata->cstream[fe_id];
- audio_effects = pdata->audio_effects[fe_id];
- if (!cstream || !audio_effects) {
- pr_err("%s: stream or effects inactive\n", __func__);
- ret = -EINVAL;
- goto exit;
- }
- prtd = cstream->runtime->private_data;
- if (!prtd) {
- pr_err("%s: cannot set audio effects\n", __func__);
- ret = -EINVAL;
- goto exit;
- }
- effects_module = *values++;
- switch (effects_module) {
- case VIRTUALIZER_MODULE:
- pr_debug("%s: VIRTUALIZER_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- ret = msm_audio_effects_virtualizer_handler(
- prtd->audio_client,
- &(audio_effects->virtualizer),
- values);
- break;
- case REVERB_MODULE:
- pr_debug("%s: REVERB_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- ret = msm_audio_effects_reverb_handler(prtd->audio_client,
- &(audio_effects->reverb),
- values);
- break;
- case BASS_BOOST_MODULE:
- pr_debug("%s: BASS_BOOST_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- ret = msm_audio_effects_bass_boost_handler(prtd->audio_client,
- &(audio_effects->bass_boost),
- values);
- break;
- case PBE_MODULE:
- pr_debug("%s: PBE_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- ret = msm_audio_effects_pbe_handler(prtd->audio_client,
- &(audio_effects->pbe),
- values);
- break;
- case EQ_MODULE:
- pr_debug("%s: EQ_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- ret = msm_audio_effects_popless_eq_handler(prtd->audio_client,
- &(audio_effects->equalizer),
- values);
- break;
- case SOFT_VOLUME_MODULE:
- pr_debug("%s: SOFT_VOLUME_MODULE\n", __func__);
- break;
- case SOFT_VOLUME2_MODULE:
- pr_debug("%s: SOFT_VOLUME2_MODULE\n", __func__);
- if (msm_audio_effects_is_effmodule_supp_in_top(effects_module,
- prtd->audio_client->topology))
- ret = msm_audio_effects_volume_handler_v2(prtd->audio_client,
- &(audio_effects->volume),
- values, SOFT_VOLUME_INSTANCE_2);
- break;
- default:
- pr_err("%s Invalid effects config module\n", __func__);
- ret = -EINVAL;
- }
- exit:
- return ret;
- }
- static int msm_transcode_add_audio_effects_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Audio Effects Config";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0;
- int ret = 0;
- struct snd_kcontrol_new fe_audio_effects_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_transcode_audio_effects_config_info,
- .get = msm_transcode_audio_effects_config_get,
- .put = msm_transcode_audio_effects_config_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n", __func__,
- rtd->dai_link->name, rtd->dai_link->id,
- rtd->dai_link->cpus->dai_name, rtd->pcm->device);
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- ret = -ENOMEM;
- goto done;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_audio_effects_config_control[0].name = mixer_str;
- fe_audio_effects_config_control[0].private_value = rtd->dai_link->id;
- ret = snd_soc_add_component_controls(component,
- fe_audio_effects_config_control,
- ARRAY_SIZE(fe_audio_effects_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s. err = %d\n", __func__, mixer_str, ret);
- kfree(mixer_str);
- done:
- return ret;
- }
- static int msm_transcode_stream_cmd_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = DSP_STREAM_CMD;
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol_new fe_loopback_stream_cmd_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_cmd_info,
- .put = msm_transcode_stream_cmd_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- ret = -ENOMEM;
- goto done;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_loopback_stream_cmd_config_control[0].name = mixer_str;
- fe_loopback_stream_cmd_config_control[0].private_value =
- rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_loopback_stream_cmd_config_control,
- ARRAY_SIZE(fe_loopback_stream_cmd_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s. err = %d\n",
- __func__, mixer_str, ret);
- kfree(mixer_str);
- done:
- return ret;
- }
- static int msm_transcode_stream_callback_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = DSP_STREAM_CALLBACK;
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol *kctl;
- struct snd_kcontrol_new fe_loopback_callback_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_callback_info,
- .get = msm_adsp_stream_callback_get,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s: rtd is NULL\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- ret = -ENOMEM;
- goto done;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_loopback_callback_config_control[0].name = mixer_str;
- fe_loopback_callback_config_control[0].private_value =
- rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_loopback_callback_config_control,
- ARRAY_SIZE(fe_loopback_callback_config_control));
- if (ret < 0) {
- pr_err("%s: failed to add ctl %s. err = %d\n",
- __func__, mixer_str, ret);
- ret = -EINVAL;
- goto free_mixer_str;
- }
- kctl = snd_soc_card_get_kcontrol(rtd->card, mixer_str);
- if (!kctl) {
- pr_err("%s: failed to get kctl %s.\n", __func__, mixer_str);
- ret = -EINVAL;
- goto free_mixer_str;
- }
- kctl->private_data = NULL;
- free_mixer_str:
- kfree(mixer_str);
- done:
- return ret;
- }
- static int msm_transcode_add_ion_fd_cmd_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Playback ION FD";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol_new fe_ion_fd_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_cmd_info,
- .put = msm_transcode_ion_fd_map_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- ret = -ENOMEM;
- goto done;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_ion_fd_config_control[0].name = mixer_str;
- fe_ion_fd_config_control[0].private_value = rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_ion_fd_config_control,
- ARRAY_SIZE(fe_ion_fd_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
- kfree(mixer_str);
- done:
- return ret;
- }
- static int msm_transcode_add_event_ack_cmd_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- const char *mixer_ctl_name = "Playback Event Ack";
- const char *deviceNo = "NN";
- char *mixer_str = NULL;
- int ctl_len = 0, ret = 0;
- struct snd_kcontrol_new fe_event_ack_config_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "?",
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_adsp_stream_cmd_info,
- .put = msm_transcode_rtic_event_ack_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1;
- mixer_str = kzalloc(ctl_len, GFP_KERNEL);
- if (!mixer_str) {
- ret = -ENOMEM;
- goto done;
- }
- snprintf(mixer_str, ctl_len, "%s %d", mixer_ctl_name, rtd->pcm->device);
- fe_event_ack_config_control[0].name = mixer_str;
- fe_event_ack_config_control[0].private_value = rtd->dai_link->id;
- pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
- ret = snd_soc_add_component_controls(component,
- fe_event_ack_config_control,
- ARRAY_SIZE(fe_event_ack_config_control));
- if (ret < 0)
- pr_err("%s: failed to add ctl %s\n", __func__, mixer_str);
- kfree(mixer_str);
- done:
- return ret;
- }
- static int msm_transcode_app_type_cfg_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 5;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 0xFFFFFFFF;
- return 0;
- }
- static int msm_transcode_add_app_type_cfg_control(
- struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- char mixer_str[128];
- struct snd_kcontrol_new fe_app_type_cfg_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_transcode_app_type_cfg_info,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
- snprintf(mixer_str, sizeof(mixer_str),
- "Audio Stream %d App Type Cfg",
- rtd->pcm->device);
- fe_app_type_cfg_control[0].name = mixer_str;
- fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
- fe_app_type_cfg_control[0].put =
- msm_transcode_playback_app_type_cfg_put;
- fe_app_type_cfg_control[0].get =
- msm_transcode_playback_app_type_cfg_get;
- pr_debug("Registering new mixer ctl %s", mixer_str);
- snd_soc_add_component_controls(component,
- fe_app_type_cfg_control,
- ARRAY_SIZE(fe_app_type_cfg_control));
- } else if (rtd->compr->direction == SND_COMPRESS_CAPTURE) {
- snprintf(mixer_str, sizeof(mixer_str),
- "Audio Stream Capture %d App Type Cfg",
- rtd->pcm->device);
- fe_app_type_cfg_control[0].name = mixer_str;
- fe_app_type_cfg_control[0].private_value = rtd->dai_link->id;
- fe_app_type_cfg_control[0].put =
- msm_transcode_capture_app_type_cfg_put;
- fe_app_type_cfg_control[0].get =
- msm_transcode_capture_app_type_cfg_get;
- pr_debug("Registering new mixer ctl %s", mixer_str);
- snd_soc_add_component_controls(component,
- fe_app_type_cfg_control,
- ARRAY_SIZE(fe_app_type_cfg_control));
- }
- return 0;
- }
- static int msm_transcode_volume_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = TRANSCODE_LR_VOL_MAX_DB;
- return 0;
- }
- static int msm_transcode_add_volume_control(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- struct snd_kcontrol_new fe_volume_control[1] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Transcode Loopback Rx Volume",
- .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
- SNDRV_CTL_ELEM_ACCESS_READWRITE,
- .info = msm_transcode_volume_info,
- .get = msm_transcode_volume_get,
- .put = msm_transcode_volume_put,
- .private_value = 0,
- }
- };
- if (!rtd) {
- pr_err("%s NULL rtd\n", __func__);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- if (!component) {
- pr_err("%s: component is NULL\n", __func__);
- return -EINVAL;
- }
- if (rtd->compr->direction == SND_COMPRESS_PLAYBACK) {
- fe_volume_control[0].private_value = rtd->dai_link->id;
- pr_debug("Registering new mixer ctl %s",
- fe_volume_control[0].name);
- snd_soc_add_component_controls(component, fe_volume_control,
- ARRAY_SIZE(fe_volume_control));
- }
- return 0;
- }
- static int msm_transcode_loopback_new(struct snd_soc_pcm_runtime *rtd)
- {
- int rc;
- rc = msm_transcode_add_audio_effects_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr Audio Effects Control\n",
- __func__);
- rc = msm_transcode_stream_cmd_control(rtd);
- if (rc)
- pr_err("%s: ADSP Stream Cmd Control open failed\n", __func__);
- rc = msm_transcode_stream_callback_control(rtd);
- if (rc)
- pr_err("%s: ADSP Stream callback Control open failed\n",
- __func__);
- rc = msm_transcode_add_ion_fd_cmd_control(rtd);
- if (rc)
- pr_err("%s: Could not add transcode ion fd Control\n",
- __func__);
- rc = msm_transcode_add_event_ack_cmd_control(rtd);
- if (rc)
- pr_err("%s: Could not add transcode event ack Control\n",
- __func__);
- rc = msm_transcode_add_app_type_cfg_control(rtd);
- if (rc)
- pr_err("%s: Could not add Compr App Type Cfg Control\n",
- __func__);
- rc = msm_transcode_add_volume_control(rtd);
- if (rc)
- pr_err("%s: Could not add transcode volume Control\n",
- __func__);
- return 0;
- }
- static struct snd_compr_ops msm_transcode_loopback_ops = {
- .open = msm_transcode_loopback_open,
- .free = msm_transcode_loopback_free,
- .trigger = msm_transcode_loopback_trigger,
- .set_params = msm_transcode_loopback_set_params,
- .get_caps = msm_transcode_loopback_get_caps,
- .set_metadata = msm_transcode_loopback_set_metadata,
- };
- static int msm_transcode_loopback_probe(struct snd_soc_component *component)
- {
- struct trans_loopback_pdata *pdata = NULL;
- int i;
- pr_debug("%s\n", __func__);
- pdata = (struct trans_loopback_pdata *)
- kzalloc(sizeof(struct trans_loopback_pdata),
- GFP_KERNEL);
- if (!pdata)
- return -ENOMEM;
- for (i = 0; i < MSM_FRONTEND_DAI_MAX; i++) {
- pdata->audio_effects[i] = NULL;
- pdata->perf_mode[i] = LOW_LATENCY_PCM_MODE;
- }
- snd_soc_component_set_drvdata(component, pdata);
- return 0;
- }
- static void msm_transcode_loopback_remove(struct snd_soc_component *component)
- {
- struct trans_loopback_pdata *pdata = NULL;
- pdata = (struct trans_loopback_pdata *)
- snd_soc_component_get_drvdata(component);
- kfree(pdata);
- return;
- }
- static struct snd_soc_component_driver msm_soc_component = {
- .name = DRV_NAME,
- .probe = msm_transcode_loopback_probe,
- .compr_ops = &msm_transcode_loopback_ops,
- .pcm_new = msm_transcode_loopback_new,
- .remove = msm_transcode_loopback_remove,
- };
- static int msm_transcode_dev_probe(struct platform_device *pdev)
- {
- pr_debug("%s: dev name %s\n", __func__, dev_name(&pdev->dev));
- return snd_soc_register_component(&pdev->dev,
- &msm_soc_component,
- NULL, 0);
- }
- static int msm_transcode_remove(struct platform_device *pdev)
- {
- snd_soc_unregister_component(&pdev->dev);
- return 0;
- }
- static const struct of_device_id msm_transcode_loopback_dt_match[] = {
- {.compatible = "qcom,msm-transcode-loopback"},
- {}
- };
- MODULE_DEVICE_TABLE(of, msm_transcode_loopback_dt_match);
- static struct platform_driver msm_transcode_loopback_driver = {
- .driver = {
- .name = "msm-transcode-loopback",
- .owner = THIS_MODULE,
- .of_match_table = msm_transcode_loopback_dt_match,
- .suppress_bind_attrs = true,
- },
- .probe = msm_transcode_dev_probe,
- .remove = msm_transcode_remove,
- };
- int __init msm_transcode_loopback_init(void)
- {
- memset(&transcode_info, 0, sizeof(struct msm_transcode_loopback));
- mutex_init(&transcode_info.lock);
- return platform_driver_register(&msm_transcode_loopback_driver);
- }
- void msm_transcode_loopback_exit(void)
- {
- mutex_destroy(&transcode_info.lock);
- platform_driver_unregister(&msm_transcode_loopback_driver);
- }
- MODULE_DESCRIPTION("Transcode loopback platform driver");
- MODULE_LICENSE("GPL v2");
|