Skip to content

Commit

Permalink
ASoC: msm: Add LSM topology & custom topology
Browse files Browse the repository at this point in the history
Add LSM topology and custom topology calibration
blocks. Custom topology is sent only on ADSP
bootup and topology is sent before opening a
session.

Change-Id: Ib55b201392a4360e86ba8937ae530227fddf1dce
Signed-off-by: Ben Romberger <bromberg@codeaurora.org>
Signed-off-by: Vidyakumar Athota <vathota@codeaurora.org>
  • Loading branch information
Ben Romberger authored and Gerrit - the friendly Code Review server committed Sep 1, 2015
1 parent 3c70a88 commit a1d0e63
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 20 deletions.
20 changes: 20 additions & 0 deletions include/uapi/linux/msm_audio_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ enum {
AFE_HW_DELAY_CAL_TYPE,
AFE_SIDETONE_CAL_TYPE,

LSM_CUST_TOPOLOGY_CAL_TYPE,
LSM_TOPOLOGY_CAL_TYPE,
LSM_CAL_TYPE,

ADM_RTAC_INFO_CAL_TYPE,
Expand Down Expand Up @@ -285,6 +287,13 @@ struct audio_cal_info_sidetone {
int32_t pid;
};

struct audio_cal_info_lsm_top {
int32_t topology;
int32_t acdb_id;
int32_t app_type;
};


struct audio_cal_info_lsm {
int32_t acdb_id;
/* RX_DEVICE or TX_DEVICE */
Expand Down Expand Up @@ -480,6 +489,17 @@ struct audio_cal_sidetone {
struct audio_cal_type_sidetone cal_type;
};

struct audio_cal_type_lsm_top {
struct audio_cal_type_header cal_hdr;
struct audio_cal_data cal_data;
struct audio_cal_info_lsm_top cal_info;
};

struct audio_cal_lsm_top {
struct audio_cal_header hdr;
struct audio_cal_type_lsm_top cal_type;
};

struct audio_cal_type_lsm {
struct audio_cal_type_header cal_hdr;
struct audio_cal_data cal_data;
Expand Down
12 changes: 12 additions & 0 deletions sound/soc/msm/qdsp6v2/audio_cal_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ size_t get_cal_info_size(int32_t cal_type)
case AFE_SIDETONE_CAL_TYPE:
size = sizeof(struct audio_cal_info_sidetone);
break;
case LSM_CUST_TOPOLOGY_CAL_TYPE:
size = 0;
break;
case LSM_TOPOLOGY_CAL_TYPE:
size = sizeof(struct audio_cal_info_lsm_top);
break;
case LSM_CAL_TYPE:
size = sizeof(struct audio_cal_info_lsm);
break;
Expand Down Expand Up @@ -205,6 +211,12 @@ size_t get_user_cal_type_size(int32_t cal_type)
case AFE_SIDETONE_CAL_TYPE:
size = sizeof(struct audio_cal_type_sidetone);
break;
case LSM_CUST_TOPOLOGY_CAL_TYPE:
size = sizeof(struct audio_cal_type_basic);
break;
case LSM_TOPOLOGY_CAL_TYPE:
size = sizeof(struct audio_cal_type_lsm_top);
break;
case LSM_CAL_TYPE:
size = sizeof(struct audio_cal_type_lsm);
break;
Expand Down
124 changes: 104 additions & 20 deletions sound/soc/msm/qdsp6v2/q6lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
#define QLSM_PARAM_ID_MINOR_VERSION 1
static int lsm_afe_port;

enum {
LSM_CUSTOM_TOP_IDX,
LSM_TOP_IDX,
LSM_CAL_IDX,
LSM_MAX_CAL_IDX
};

enum {
CMD_STATE_CLEARED = 0,
CMD_STATE_WAIT_RESP = 1,
Expand All @@ -56,7 +63,10 @@ struct lsm_common {
void *apr;
atomic_t apr_users;
struct lsm_client common_client[LSM_MAX_SESSION_ID + 1];
struct cal_type_data *cal_data;

int set_custom_topology;
struct cal_type_data *cal_data[LSM_MAX_CAL_IDX];

struct mutex apr_lock;
};

Expand Down Expand Up @@ -92,6 +102,12 @@ static int q6lsm_callback(struct apr_client_data *data, void *priv)
pr_debug("%s: SSR event received 0x%x, event 0x%x, proc 0x%x\n",
__func__, data->opcode, data->reset_event,
data->reset_proc);

cal_utils_clear_cal_block_q6maps(LSM_MAX_CAL_IDX,
lsm_common.cal_data);
mutex_lock(&lsm_common.cal_data[LSM_CUSTOM_TOP_IDX]->lock);
lsm_common.set_custom_topology = 1;
mutex_unlock(&lsm_common.cal_data[LSM_CUSTOM_TOP_IDX]->lock);
return 0;
}

Expand Down Expand Up @@ -789,11 +805,12 @@ static int q6lsm_send_cal(struct lsm_client *client)
return -EINVAL;
}

if (lsm_common.cal_data == NULL)
if (lsm_common.cal_data[LSM_CAL_IDX] == NULL)
goto done;

mutex_lock(&lsm_common.cal_data->lock);
cal_block = cal_utils_get_only_cal_block(lsm_common.cal_data);
mutex_lock(&lsm_common.cal_data[LSM_CAL_IDX]->lock);
cal_block = cal_utils_get_only_cal_block(
lsm_common.cal_data[LSM_CAL_IDX]);
if (cal_block == NULL)
goto unlock;

Expand Down Expand Up @@ -826,7 +843,7 @@ static int q6lsm_send_cal(struct lsm_client *client)
pr_err("%s: Failed set_params opcode 0x%x, rc %d\n",
__func__, msg_hdr->opcode, rc);
unlock:
mutex_unlock(&lsm_common.cal_data->lock);
mutex_unlock(&lsm_common.cal_data[LSM_CAL_IDX]->lock);
done:
return rc;
}
Expand Down Expand Up @@ -901,7 +918,8 @@ static int q6lsm_mmapcallback(struct apr_client_data *data, void *priv)
"proc 0x%x SID 0x%x\n", __func__, data->opcode,
data->reset_event, data->reset_proc, sid);
lsm_common.common_client[sid].lsm_cal_phy_addr = 0;
cal_utils_clear_cal_block_q6maps(1, &lsm_common.cal_data);
cal_utils_clear_cal_block_q6maps(LSM_MAX_CAL_IDX,
lsm_common.cal_data);
return 0;
}

Expand Down Expand Up @@ -975,13 +993,15 @@ int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len)

mutex_lock(&client->cmd_lock);

mutex_lock(&lsm_common.cal_data->lock);
cal_block = cal_utils_get_only_cal_block(lsm_common.cal_data);
mutex_lock(&lsm_common.cal_data[LSM_CAL_IDX]->lock);
cal_block = cal_utils_get_only_cal_block(
lsm_common.cal_data[LSM_CAL_IDX]);
if (cal_block == NULL)
goto fail;

pr_debug("%s:Snd Model len = %zd cal size %zd phys addr %pa", __func__,
len, cal_block->cal_data.size, &cal_block->cal_data.paddr);
len, cal_block->cal_data.size,
&cal_block->cal_data.paddr);
if (!cal_block->cal_data.paddr) {
pr_err("%s: No LSM calibration set for session", __func__);
rc = -EINVAL;
Expand Down Expand Up @@ -1035,7 +1055,7 @@ int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len)
rc = -EBUSY;
goto fail;
}
mutex_unlock(&lsm_common.cal_data->lock);
mutex_unlock(&lsm_common.cal_data[LSM_CAL_IDX]->lock);
mutex_unlock(&client->cmd_lock);

rc = q6lsm_memory_map_regions(client, client->sound_model.phys,
Expand All @@ -1048,7 +1068,7 @@ int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len)

return 0;
fail:
mutex_unlock(&lsm_common.cal_data->lock);
mutex_unlock(&lsm_common.cal_data[LSM_CAL_IDX]->lock);
mutex_unlock(&client->cmd_lock);
exit:
q6lsm_snd_model_buf_free(client);
Expand Down Expand Up @@ -1277,14 +1297,43 @@ int q6lsm_lab_buffer_alloc(struct lsm_client *client, bool alloc)
return ret;
}

static int get_cal_type_index(int32_t cal_type)
{
int ret = -EINVAL;

switch (cal_type) {
case LSM_CUST_TOPOLOGY_CAL_TYPE:
ret = LSM_CUSTOM_TOP_IDX;
break;
case LSM_TOPOLOGY_CAL_TYPE:
ret = LSM_TOP_IDX;
break;
case LSM_CAL_TYPE:
ret = LSM_CAL_IDX;
break;
default:
pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
}
return ret;
}

static int q6lsm_alloc_cal(int32_t cal_type,
size_t data_size, void *data)
{
int ret = 0;
int cal_index;
pr_debug("%s:\n", __func__);

cal_index = get_cal_type_index(cal_type);
if (cal_index < 0) {
pr_err("%s: could not get cal index %d!\n",
__func__, cal_index);
ret = -EINVAL;
goto done;
}

ret = cal_utils_alloc_cal(data_size, data,
lsm_common.cal_data, 0, NULL);
lsm_common.cal_data[cal_index], 0, NULL);
if (ret < 0) {
pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
__func__, ret, cal_type);
Expand All @@ -1299,10 +1348,19 @@ static int q6lsm_dealloc_cal(int32_t cal_type,
size_t data_size, void *data)
{
int ret = 0;
int cal_index;
pr_debug("%s:\n", __func__);

cal_index = get_cal_type_index(cal_type);
if (cal_index < 0) {
pr_err("%s: could not get cal index %d!\n",
__func__, cal_index);
ret = -EINVAL;
goto done;
}

ret = cal_utils_dealloc_cal(data_size, data,
lsm_common.cal_data);
lsm_common.cal_data[cal_index]);
if (ret < 0) {
pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
__func__, ret, cal_type);
Expand All @@ -1317,16 +1375,32 @@ static int q6lsm_set_cal(int32_t cal_type,
size_t data_size, void *data)
{
int ret = 0;
int cal_index;
pr_debug("%s:\n", __func__);

cal_index = get_cal_type_index(cal_type);
if (cal_index < 0) {
pr_err("%s: could not get cal index %d!\n",
__func__, cal_index);
ret = -EINVAL;
goto done;
}

ret = cal_utils_set_cal(data_size, data,
lsm_common.cal_data, 0, NULL);
lsm_common.cal_data[cal_index], 0, NULL);
if (ret < 0) {
pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
__func__, ret, cal_type);
ret = -EINVAL;
goto done;
}

if (cal_index == LSM_CUSTOM_TOP_IDX) {
mutex_lock(&lsm_common.cal_data[LSM_CUSTOM_TOP_IDX]->lock);
lsm_common.set_custom_topology = 1;
mutex_unlock(&lsm_common.cal_data[LSM_CUSTOM_TOP_IDX]->lock);
}

done:
return ret;
}
Expand All @@ -1335,23 +1409,33 @@ static void lsm_delete_cal_data(void)
{
pr_debug("%s:\n", __func__);

cal_utils_destroy_cal_types(1, &lsm_common.cal_data);
cal_utils_destroy_cal_types(LSM_MAX_CAL_IDX, lsm_common.cal_data);
return;
}

static int q6lsm_init_cal_data(void)
{
int ret = 0;
struct cal_type_info cal_type_info = {
{LSM_CAL_TYPE,
struct cal_type_info cal_type_info[] = {
{{LSM_CUST_TOPOLOGY_CAL_TYPE,
{q6lsm_alloc_cal, q6lsm_dealloc_cal, NULL,
q6lsm_set_cal, NULL, NULL} },
{NULL, NULL, cal_utils_match_buf_num} },

{{LSM_TOPOLOGY_CAL_TYPE,
{NULL, NULL, NULL,
q6lsm_set_cal, NULL, NULL} },
{NULL, NULL, cal_utils_match_buf_num} },

{{LSM_CAL_TYPE,
{q6lsm_alloc_cal, q6lsm_dealloc_cal, NULL,
q6lsm_set_cal, NULL, NULL} },
{NULL, NULL, cal_utils_match_buf_num}
{NULL, NULL, cal_utils_match_buf_num} }
};
pr_debug("%s:\n", __func__);

ret = cal_utils_create_cal_types(1, &lsm_common.cal_data,
&cal_type_info);
ret = cal_utils_create_cal_types(LSM_MAX_CAL_IDX,
lsm_common.cal_data, cal_type_info);
if (ret < 0) {
pr_err("%s: could not create cal type!\n",
__func__);
Expand Down

0 comments on commit a1d0e63

Please sign in to comment.