From 33b2108fd6f9d30372631512d42a42e46fe000e0 Mon Sep 17 00:00:00 2001 From: Aditya Bavanari Date: Tue, 14 Jan 2020 14:56:23 +0530 Subject: [PATCH] asoc: Set and get lsm port indices on a per session basis When multiple LSM sessions are running, lsm port index might be overwritten with index of different sessions during concurrent LPI and Non LPI session switches. Maintain lsm port index on a per session basis to avoid this issue. Change-Id: I943ea7899b977e06f467a140a9d1c9feb31c58bd Signed-off-by: Aditya Bavanari --- asoc/msm-pcm-routing-v2.c | 48 +++++++++++++++++++++++++++++++++++---- include/dsp/q6lsm.h | 4 +++- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/asoc/msm-pcm-routing-v2.c b/asoc/msm-pcm-routing-v2.c index abc4c59a3077..200fcd6b4db5 100644 --- a/asoc/msm-pcm-routing-v2.c +++ b/asoc/msm-pcm-routing-v2.c @@ -68,7 +68,7 @@ static int quin_mi2s_switch_enable; static int sen_mi2s_switch_enable; static int fm_pcmrx_switch_enable; static int usb_switch_enable; -static int lsm_port_index; +static int lsm_port_index[MAX_LSM_SESSIONS]; static int slim0_rx_aanc_fb_port; static int msm_route_ec_ref_rx; static int msm_ec_ref_ch = 4; @@ -1383,9 +1383,11 @@ static bool route_check_fe_id_adm_support(int fe_id) if ((fe_id >= MSM_FRONTEND_DAI_LSM1) && (fe_id <= MSM_FRONTEND_DAI_LSM8)) { /* fe id is listen while port is set to afe */ - if (lsm_port_index != ADM_LSM_PORT_INDEX) { + if (lsm_port_index[fe_id - MSM_FRONTEND_DAI_LSM1] != + ADM_LSM_PORT_INDEX) { pr_debug("%s: fe_id %d, lsm mux slim port %d\n", - __func__, fe_id, lsm_port_index); + __func__, fe_id, + lsm_port_index[fe_id - MSM_FRONTEND_DAI_LSM1]); rc = false; } } @@ -2976,10 +2978,44 @@ static int msm_routing_put_fm_pcmrx_switch_mixer(struct snd_kcontrol *kcontrol, return 1; } +static void msm_routing_get_lsm_fe_idx(struct snd_kcontrol *kcontrol, + u8 *fe_idx) +{ + int fe_id = MSM_FRONTEND_DAI_LSM1; + + if (strnstr(kcontrol->id.name, "LSM1", sizeof("LSM1"))) { + fe_id = MSM_FRONTEND_DAI_LSM1; + } else if (strnstr(kcontrol->id.name, "LSM2", sizeof("LSM2"))) { + fe_id = MSM_FRONTEND_DAI_LSM2; + } else if (strnstr(kcontrol->id.name, "LSM3", sizeof("LSM3"))) { + fe_id = MSM_FRONTEND_DAI_LSM3; + } else if (strnstr(kcontrol->id.name, "LSM4", sizeof("LSM4"))) { + fe_id = MSM_FRONTEND_DAI_LSM4; + } else if (strnstr(kcontrol->id.name, "LSM5", sizeof("LSM5"))) { + fe_id = MSM_FRONTEND_DAI_LSM5; + } else if (strnstr(kcontrol->id.name, "LSM6", sizeof("LSM6"))) { + fe_id = MSM_FRONTEND_DAI_LSM6; + } else if (strnstr(kcontrol->id.name, "LSM7", sizeof("LSM7"))) { + fe_id = MSM_FRONTEND_DAI_LSM7; + } else if (strnstr(kcontrol->id.name, "LSM8", sizeof("LSM8"))) { + fe_id = MSM_FRONTEND_DAI_LSM8; + } else { + pr_err("%s: Invalid kcontrol name:%s\n", __func__, + kcontrol->id.name); + return; + } + + *fe_idx = fe_id - MSM_FRONTEND_DAI_LSM1; + pr_debug("%s: fe_id: %d, fe_idx:%d\n", __func__, fe_id, *fe_idx); +} + static int msm_routing_lsm_port_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ucontrol->value.integer.value[0] = lsm_port_index; + u8 fe_idx = 0; + + msm_routing_get_lsm_fe_idx(kcontrol, &fe_idx); + ucontrol->value.integer.value[0] = lsm_port_index[fe_idx]; return 0; } @@ -2989,6 +3025,7 @@ static int msm_routing_lsm_port_put(struct snd_kcontrol *kcontrol, struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; int mux = ucontrol->value.enumerated.item[0]; int lsm_port = AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_TX; + u8 fe_idx = 0; if (mux >= e->items) { pr_err("%s: Invalid mux value %d\n", __func__, mux); @@ -3051,7 +3088,8 @@ static int msm_routing_lsm_port_put(struct snd_kcontrol *kcontrol, break; } set_lsm_port(lsm_port); - lsm_port_index = ucontrol->value.integer.value[0]; + msm_routing_get_lsm_fe_idx(kcontrol, &fe_idx); + lsm_port_index[fe_idx] = ucontrol->value.integer.value[0]; return 0; } diff --git a/include/dsp/q6lsm.h b/include/dsp/q6lsm.h index af43cdd4cbf3..02897d98e06d 100644 --- a/include/dsp/q6lsm.h +++ b/include/dsp/q6lsm.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. */ #ifndef __Q6LSM_H__ #define __Q6LSM_H__ @@ -20,6 +20,8 @@ #define LSM_API_VERSION_V3 3 +#define MAX_LSM_SESSIONS 8 + typedef void (*lsm_app_cb)(uint32_t opcode, uint32_t token, uint32_t *payload, uint16_t client_size, void *priv);