From 4a466532e4c3152f8a99159cc79df3678575c7f9 Mon Sep 17 00:00:00 2001 From: Chaithanya Krishna Bacharaju Date: Mon, 21 Jan 2019 10:59:51 +0530 Subject: [PATCH] dsp: Add support for Aptx Adaptive decoder Add support for Aptx Adaptive decoder. Introduce flag to indicate ABR feedback decoder configuration to differentiate from regular decoder configuration. Change-Id: I272e0a9572a56e878f7ad1385514b3be7010145a Signed-off-by: Chaithanya Krishna Bacharaju --- dsp/q6afe.c | 57 ++++++++++++++++++++++++++++++++++---- include/dsp/apr_audio-v2.h | 16 +++++++++++ 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/dsp/q6afe.c b/dsp/q6afe.c index 1b5c94d59a5f..8743b56c5279 100644 --- a/dsp/q6afe.c +++ b/dsp/q6afe.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. */ #include #include @@ -76,6 +75,11 @@ enum { Q6AFE_MSM_SPKR_FTM_MODE }; +enum { + APTX_AD_48 = 0, + APTX_AD_44_1 = 1 +}; + struct wlock { struct wakeup_source ws; }; @@ -3541,6 +3545,29 @@ static int q6afe_send_dec_config(u16 port_id, goto exit; } break; + case ASM_MEDIA_FMT_APTX_ADAPTIVE: + if (!cfg->abr_dec_cfg.is_abr_enabled) { + pr_debug("%s: sending aptx adaptive congestion buffer size to dsp\n", + __func__); + param_hdr.param_id = + AFE_DECODER_PARAM_ID_CONGESTION_BUFFER_SIZE; + param_hdr.param_size = + sizeof(struct avs_dec_congestion_buffer_param_t); + dec_buffer_id_param.version = 0; + dec_buffer_id_param.max_nr_buffers = 226; + dec_buffer_id_param.pre_buffer_size = 226; + ret = q6afe_pack_and_set_param_in_band(port_id, + q6audio_get_port_index(port_id), + param_hdr, + (u8 *) &dec_buffer_id_param); + if (ret) { + pr_err("%s: aptx adaptive congestion buffer size for port 0x%x failed %d\n", + __func__, port_id, ret); + goto exit; + } + break; + } + /* fall through for abr enabled case */ default: pr_debug("%s:sending AFE_ENCDEC_PARAM_ID_DEC_TO_ENC_COMMUNICATION to DSP payload\n", __func__); @@ -3561,7 +3588,7 @@ static int q6afe_send_dec_config(u16 port_id, break; } - pr_debug("%s:Sending AFE_API_VERSION_PORT_MEDIA_TYPE to DSP", __func__); + pr_debug("%s: Send AFE_API_VERSION_PORT_MEDIA_TYPE to DSP\n", __func__); param_hdr.module_id = AFE_MODULE_PORT; param_hdr.param_id = AFE_PARAM_ID_PORT_MEDIA_TYPE; param_hdr.param_size = sizeof(struct afe_port_media_type_t); @@ -3575,6 +3602,15 @@ static int q6afe_send_dec_config(u16 port_id, media_type.sample_rate = cfg->data.sbc_config.sample_rate; break; + case ASM_MEDIA_FMT_APTX_ADAPTIVE: + if (!cfg->abr_dec_cfg.is_abr_enabled) { + media_type.sample_rate = + (cfg->data.aptx_ad_config.sample_rate == APTX_AD_44_1) ? + AFE_PORT_SAMPLE_RATE_44_1K : + AFE_PORT_SAMPLE_RATE_48K; + break; + } + /* fall through for abr enabled case */ default: media_type.sample_rate = afe_config.slim_sch.sample_rate; @@ -3600,11 +3636,19 @@ static int q6afe_send_dec_config(u16 port_id, goto exit; } - if (format != ASM_MEDIA_FMT_SBC && format != ASM_MEDIA_FMT_AAC_V2) { + if (format != ASM_MEDIA_FMT_SBC && format != ASM_MEDIA_FMT_AAC_V2 && + format != ASM_MEDIA_FMT_APTX_ADAPTIVE) { pr_debug("%s:Unsuppported dec format. Ignore AFE config %u\n", __func__, format); goto exit; } + + if (format == ASM_MEDIA_FMT_APTX_ADAPTIVE && + cfg->abr_dec_cfg.is_abr_enabled) { + pr_debug("%s: Ignore AFE config for abr case\n", __func__); + goto exit; + } + pr_debug("%s: sending AFE_DECODER_PARAM_ID_DEC_MEDIA_FMT to DSP payload\n", __func__); param_hdr.module_id = AFE_MODULE_ID_DECODER; @@ -3623,9 +3667,10 @@ static int q6afe_send_dec_config(u16 port_id, switch (cfg->format) { case ASM_MEDIA_FMT_AAC_V2: + case ASM_MEDIA_FMT_APTX_ADAPTIVE: param_hdr.param_size = sizeof(struct afe_dec_media_fmt_t); - pr_debug("%s:send AFE_DECODER_PARAM_ID DEC_MEDIA_FMT to DSP payload\n", + pr_debug("%s:send AVS_DECODER_PARAM_ID DEC_MEDIA_FMT to DSP payload\n", __func__); param_hdr.param_id = AVS_DECODER_PARAM_ID_DEC_MEDIA_FMT; dec_media_fmt.dec_media_config = cfg->data; @@ -3634,7 +3679,7 @@ static int q6afe_send_dec_config(u16 port_id, param_hdr, (u8 *) &dec_media_fmt); if (ret) { - pr_err("%s: AFE_DECODER_PARAM_ID DEC_MEDIA_FMT for port 0x%x failed %d\n", + pr_err("%s: AVS_DECODER_PARAM_ID DEC_MEDIA_FMT for port 0x%x failed %d\n", __func__, port_id, ret); goto exit; } diff --git a/include/dsp/apr_audio-v2.h b/include/dsp/apr_audio-v2.h index 9daebe5a4113..532742794127 100644 --- a/include/dsp/apr_audio-v2.h +++ b/include/dsp/apr_audio-v2.h @@ -2477,6 +2477,7 @@ struct afe_port_data_cmd_rt_proxy_port_read_v2 { #define AFE_MODULE_AUDIO_DEV_INTERFACE 0x0001020C #define AFE_PORT_SAMPLE_RATE_8K 8000 #define AFE_PORT_SAMPLE_RATE_16K 16000 +#define AFE_PORT_SAMPLE_RATE_44_1K 44100 #define AFE_PORT_SAMPLE_RATE_48K 48000 #define AFE_PORT_SAMPLE_RATE_96K 96000 #define AFE_PORT_SAMPLE_RATE_176P4K 176400 @@ -3795,6 +3796,7 @@ struct afe_imc_dec_enc_info { struct afe_abr_dec_cfg_t { struct afe_imc_dec_enc_info imc_info; + bool is_abr_enabled; } __packed; struct afe_abr_enc_cfg_t { @@ -4437,6 +4439,19 @@ struct asm_aac_dec_cfg_v2_t { */ } __packed; +/* + * Payload of the APTX AD decoder configuration parameters in the + * #ASM_MEDIA_FMT_APTX_ADAPTIVE media format. + */ +struct asm_aptx_ad_dec_cfg_t { + uint32_t sample_rate; + /* + * Number of samples per second. + * + * @values 0x0(48000Hz), 0x1(44100Hz) + */ +} __packed; + union afe_enc_config_data { struct asm_sbc_enc_cfg_t sbc_config; struct asm_aac_enc_cfg_t aac_config; @@ -4458,6 +4473,7 @@ union afe_dec_config_data { struct asm_sbc_dec_cfg_t sbc_config; struct asm_aac_dec_cfg_v2_t aac_config; struct asm_mp3_dec_cfg_t mp3_config; + struct asm_aptx_ad_dec_cfg_t aptx_ad_config; }; struct afe_dec_config {