Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52a87923 authored by Banajit Goswami's avatar Banajit Goswami
Browse files

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: default avatarBanajit Goswami <bgoswami@codeaurora.org>
parent d3d92fb2
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
/*
 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
 * Author: Brian Swetland <swetland@google.com>
 *
 * This software is licensed under the terms of the GNU General Public
@@ -412,6 +412,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;
}

static int q6asm_map_cal_memory(struct cal_block_data *cal_block)
{
	int			result = 0;
@@ -1787,7 +1795,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;
	}
@@ -1838,7 +1847,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;
}

@@ -4842,7 +4852,8 @@ static int __q6asm_read(struct audio_client *ac, bool is_custom_len_reqd,
		read.buf_size = is_custom_len_reqd ? len : 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);
		dev_vdbg(ac->dev, "%s: buf add[%pa] token[%d] uid[%d]\n",
				__func__, &ab->phys, read.hdr.token,
@@ -4920,7 +4931,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);
		dev_vdbg(ac->dev, "%s: buf add[%pa] token[%d] uid[%d]\n",
				__func__, &ab->phys, read.hdr.token,
				read.seq_id);
@@ -5125,7 +5137,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);
@@ -5202,7 +5215,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);

		dev_vdbg(ac->dev, "%s: ab->phys[%pa]bufadd[0x%x]token[0x%x] buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
				, __func__,