Skip to content

Instantly share code, notes, and snippets.

@luca020400
Created November 26, 2015 17:58
Show Gist options
  • Save luca020400/2f99faee4788335c1096 to your computer and use it in GitHub Desktop.
Save luca020400/2f99faee4788335c1096 to your computer and use it in GitHub Desktop.
From f67ddf18eec92729c88cadfdef65fdd9775126f1 Mon Sep 17 00:00:00 2001
From: Banajit Goswami <[email protected]>
Date: Sat, 10 Jan 2015 16:39:20 -0800
Subject: [PATCH] ASoC: msm: qdsp6v2: add support for any number of ASM buffers
Current logic in ASM driver supports CPU and DSP buffers only
when the number of buffers is power of 2. At times, the number
of buffers might need to be different than power of 2. Modify
the logic to find next available CPU or DSP buffer, even when
the number of buffers is anything other than power of 2.
CRs-Fixed: 771446
Change-Id: Ibda6e0843387f6286a75c1bf4dc2068b4c4e7e9b
Signed-off-by: Banajit Goswami <[email protected]>
---
sound/soc/msm/qdsp6v2/q6asm.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/sound/soc/msm/qdsp6v2/q6asm.c b/sound/soc/msm/qdsp6v2/q6asm.c
index 1f8b519..42511e1 100644
--- a/sound/soc/msm/qdsp6v2/q6asm.c
+++ b/sound/soc/msm/qdsp6v2/q6asm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
* Author: Brian Swetland <[email protected]>
*
* This software is licensed under the terms of the GNU General Public
@@ -356,6 +356,14 @@ static void q6asm_session_free(struct audio_client *ac)
return;
}
+static uint32_t q6asm_get_next_buf(uint32_t curr_buf, uint32_t max_buf_cnt)
+{
+ pr_debug("%s: curr_buf = %d, max_buf_cnt = %d\n",
+ __func__, curr_buf, max_buf_cnt);
+ curr_buf += 1;
+ return (curr_buf >= max_buf_cnt) ? 0 : curr_buf;
+}
+
void send_asm_custom_topology(struct audio_client *ac)
{
struct acdb_cal_block cal_block;
@@ -1503,7 +1511,8 @@ void *q6asm_is_cpu_buf_avail(int dir, struct audio_client *ac, uint32_t *size,
user accesses this function,increase cpu
buf(to avoid another api)*/
port->buf[idx].used = dir;
- port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
+ port->cpu_buf = q6asm_get_next_buf(port->cpu_buf,
+ port->max_buf_cnt);
mutex_unlock(&port->lock);
return data;
}
@@ -1552,7 +1561,8 @@ void *q6asm_is_cpu_buf_avail_nolock(int dir, struct audio_client *ac,
* buf(to avoid another api)
*/
port->buf[idx].used = dir;
- port->cpu_buf = ((port->cpu_buf + 1) & (port->max_buf_cnt - 1));
+ port->cpu_buf = q6asm_get_next_buf(port->cpu_buf,
+ port->max_buf_cnt);
return data;
}
@@ -3760,7 +3770,8 @@ int q6asm_read(struct audio_client *ac)
read.buf_size = ab->size;
read.seq_id = port->dsp_buf;
read.hdr.token = port->dsp_buf;
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
+ port->dsp_buf = q6asm_get_next_buf(port->dsp_buf,
+ port->max_buf_cnt);
mutex_unlock(&port->lock);
pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
read.buf_addr_lsw,
@@ -3823,7 +3834,8 @@ int q6asm_read_nolock(struct audio_client *ac)
}
}
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
+ port->dsp_buf = q6asm_get_next_buf(port->dsp_buf,
+ port->max_buf_cnt);
pr_debug("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
read.buf_addr_lsw,
read.hdr.token,
@@ -4014,7 +4026,8 @@ int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
write.flags = (0x00000000 | (flags & 0x800000FF));
else
write.flags = (0x80000000 | flags);
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
+ port->dsp_buf = q6asm_get_next_buf(port->dsp_buf,
+ port->max_buf_cnt);
buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
struct asm_buffer_node,
list);
@@ -4085,7 +4098,8 @@ int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
write.flags = (0x00000000 | (flags & 0x800000FF));
else
write.flags = (0x80000000 | flags);
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
+ port->dsp_buf = q6asm_get_next_buf(port->dsp_buf,
+ port->max_buf_cnt);
pr_debug("%s:ab->phys[0x%x]bufadd[0x%x]token[0x%x] buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
, __func__,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment