Commit 25ab80db authored by Srinivas Kandagatla's avatar Srinivas Kandagatla Committed by Mark Brown

ASoC: qdsp6: audioreach: add module configuration command helpers

Audioreach module configuration helpers, which will be used by
the q6apm-dai driver.
Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20211026111655.1702-12-srinivas.kandagatla@linaro.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5477518b
This diff is collapsed.
......@@ -568,6 +568,15 @@ struct param_id_hw_ep_dma_data_align {
uint32_t dma_data_align;
} __packed;
#define PARAM_ID_VOL_CTRL_MASTER_GAIN 0x08001035
#define VOL_CTRL_DEFAULT_GAIN 0x2000
struct param_id_vol_ctrl_master_gain {
uint16_t master_gain;
uint16_t reserved;
} __packed;
/* Graph */
struct audioreach_connection {
/* Connections */
......@@ -684,6 +693,23 @@ void *audioreach_alloc_pkt(int payload_size, uint32_t opcode,
void *audioreach_alloc_graph_pkt(struct q6apm *apm,
struct list_head *sg_list,
int graph_id);
/* Module specific */
void audioreach_graph_free_buf(struct q6apm_graph *graph);
int audioreach_map_memory_regions(struct q6apm_graph *graph,
unsigned int dir, size_t period_sz,
unsigned int periods,
bool is_contiguous);
int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, struct gpr_ibasic_rsp_result_t *result,
struct mutex *cmd_lock, gpr_port_t *port, wait_queue_head_t *cmd_wait,
struct gpr_pkt *pkt, uint32_t rsp_opcode);
int audioreach_graph_send_cmd_sync(struct q6apm_graph *graph, struct gpr_pkt *pkt,
uint32_t rsp_opcode);
int audioreach_set_media_format(struct q6apm_graph *graph,
struct audioreach_module *module,
struct audioreach_module_config *cfg);
int audioreach_shared_memory_send_eos(struct q6apm_graph *graph);
int audioreach_gain_set_vol_ctrl(struct q6apm *apm,
struct audioreach_module *module, int vol);
struct audioreach_module *audioreach_get_container_last_module(
struct audioreach_container *container);
struct audioreach_module *audioreach_get_container_first_module(
......
......@@ -258,6 +258,150 @@ int q6apm_connect_sub_graphs(struct q6apm *apm, u32 src_sgid, u32 dst_sgid, bool
return 0;
}
int q6apm_graph_media_format_shmem(struct q6apm_graph *graph,
struct audioreach_module_config *cfg)
{
struct audioreach_module *module;
if (cfg->direction == SNDRV_PCM_STREAM_CAPTURE)
module = q6apm_find_module_by_mid(graph, MODULE_ID_RD_SHARED_MEM_EP);
else
module = q6apm_find_module_by_mid(graph, MODULE_ID_WR_SHARED_MEM_EP);
if (!module)
return -ENODEV;
audioreach_set_media_format(graph, module, cfg);
return 0;
}
EXPORT_SYMBOL_GPL(q6apm_graph_media_format_shmem);
int q6apm_map_memory_regions(struct q6apm_graph *graph, unsigned int dir, phys_addr_t phys,
size_t period_sz, unsigned int periods)
{
struct audioreach_graph_data *data;
struct audio_buffer *buf;
int cnt;
int rc;
if (dir == SNDRV_PCM_STREAM_PLAYBACK)
data = &graph->rx_data;
else
data = &graph->tx_data;
mutex_lock(&graph->lock);
if (data->buf) {
mutex_unlock(&graph->lock);
return 0;
}
buf = kzalloc(((sizeof(struct audio_buffer)) * periods), GFP_KERNEL);
if (!buf) {
mutex_unlock(&graph->lock);
return -ENOMEM;
}
if (dir == SNDRV_PCM_STREAM_PLAYBACK)
data = &graph->rx_data;
else
data = &graph->tx_data;
data->buf = buf;
buf[0].phys = phys;
buf[0].size = period_sz;
for (cnt = 1; cnt < periods; cnt++) {
if (period_sz > 0) {
buf[cnt].phys = buf[0].phys + (cnt * period_sz);
buf[cnt].size = period_sz;
}
}
data->num_periods = periods;
mutex_unlock(&graph->lock);
rc = audioreach_map_memory_regions(graph, dir, period_sz, periods, 1);
if (rc < 0) {
dev_err(graph->dev, "Memory_map_regions failed\n");
audioreach_graph_free_buf(graph);
}
return rc;
}
EXPORT_SYMBOL_GPL(q6apm_map_memory_regions);
int q6apm_unmap_memory_regions(struct q6apm_graph *graph, unsigned int dir)
{
struct apm_cmd_shared_mem_unmap_regions *cmd;
struct audioreach_graph_data *data;
struct gpr_pkt *pkt;
int rc;
if (dir == SNDRV_PCM_STREAM_PLAYBACK)
data = &graph->rx_data;
else
data = &graph->tx_data;
if (!data->mem_map_handle)
return 0;
pkt = audioreach_alloc_apm_pkt(sizeof(*cmd), APM_CMD_SHARED_MEM_UNMAP_REGIONS, dir,
graph->port->id);
if (IS_ERR(pkt))
return PTR_ERR(pkt);
cmd = (void *)pkt + GPR_HDR_SIZE;
cmd->mem_map_handle = data->mem_map_handle;
rc = audioreach_graph_send_cmd_sync(graph, pkt, APM_CMD_SHARED_MEM_UNMAP_REGIONS);
kfree(pkt);
audioreach_graph_free_buf(graph);
return rc;
}
EXPORT_SYMBOL_GPL(q6apm_unmap_memory_regions);
int q6apm_graph_media_format_pcm(struct q6apm_graph *graph, struct audioreach_module_config *cfg)
{
struct audioreach_graph_info *info = graph->info;
struct audioreach_sub_graph *sgs;
struct audioreach_container *container;
struct audioreach_module *module;
list_for_each_entry(sgs, &info->sg_list, node) {
list_for_each_entry(container, &sgs->container_list, node) {
list_for_each_entry(module, &container->modules_list, node) {
if ((module->module_id == MODULE_ID_WR_SHARED_MEM_EP) ||
(module->module_id == MODULE_ID_RD_SHARED_MEM_EP))
continue;
audioreach_set_media_format(graph, module, cfg);
}
}
}
return 0;
}
EXPORT_SYMBOL_GPL(q6apm_graph_media_format_pcm);
static int q6apm_graph_get_tx_shmem_module_iid(struct q6apm_graph *graph)
{
struct audioreach_module *module;
module = q6apm_find_module_by_mid(graph, MODULE_ID_RD_SHARED_MEM_EP);
if (!module)
return -ENODEV;
return module->instance_id;
}
int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph)
{
struct audioreach_module *module;
......@@ -271,6 +415,88 @@ int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph)
}
EXPORT_SYMBOL_GPL(q6apm_graph_get_rx_shmem_module_iid);
int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,
uint32_t lsw_ts, uint32_t wflags)
{
struct apm_data_cmd_wr_sh_mem_ep_data_buffer_v2 *write_buffer;
struct audio_buffer *ab;
struct gpr_pkt *pkt;
int rc, iid;
iid = q6apm_graph_get_rx_shmem_module_iid(graph);
pkt = audioreach_alloc_pkt(sizeof(*write_buffer), DATA_CMD_WR_SH_MEM_EP_DATA_BUFFER_V2,
graph->rx_data.dsp_buf | (len << APM_WRITE_TOKEN_LEN_SHIFT),
graph->port->id, iid);
if (IS_ERR(pkt))
return PTR_ERR(pkt);
write_buffer = (void *)pkt + GPR_HDR_SIZE;
mutex_lock(&graph->lock);
ab = &graph->rx_data.buf[graph->rx_data.dsp_buf];
write_buffer->buf_addr_lsw = lower_32_bits(ab->phys);
write_buffer->buf_addr_msw = upper_32_bits(ab->phys);
write_buffer->buf_size = len;
write_buffer->timestamp_lsw = lsw_ts;
write_buffer->timestamp_msw = msw_ts;
write_buffer->mem_map_handle = graph->rx_data.mem_map_handle;
write_buffer->flags = wflags;
graph->rx_data.dsp_buf++;
if (graph->rx_data.dsp_buf >= graph->rx_data.num_periods)
graph->rx_data.dsp_buf = 0;
mutex_unlock(&graph->lock);
rc = gpr_send_port_pkt(graph->port, pkt);
kfree(pkt);
return rc;
}
EXPORT_SYMBOL_GPL(q6apm_write_async);
int q6apm_read(struct q6apm_graph *graph)
{
struct data_cmd_rd_sh_mem_ep_data_buffer_v2 *read_buffer;
struct audioreach_graph_data *port;
struct audio_buffer *ab;
struct gpr_pkt *pkt;
int rc, iid;
iid = q6apm_graph_get_tx_shmem_module_iid(graph);
pkt = audioreach_alloc_pkt(sizeof(*read_buffer), DATA_CMD_RD_SH_MEM_EP_DATA_BUFFER_V2,
graph->tx_data.dsp_buf, graph->port->id, iid);
if (IS_ERR(pkt))
return PTR_ERR(pkt);
read_buffer = (void *)pkt + GPR_HDR_SIZE;
mutex_lock(&graph->lock);
port = &graph->tx_data;
ab = &port->buf[port->dsp_buf];
read_buffer->buf_addr_lsw = lower_32_bits(ab->phys);
read_buffer->buf_addr_msw = upper_32_bits(ab->phys);
read_buffer->mem_map_handle = port->mem_map_handle;
read_buffer->buf_size = ab->size;
port->dsp_buf++;
if (port->dsp_buf >= port->num_periods)
port->dsp_buf = 0;
mutex_unlock(&graph->lock);
rc = gpr_send_port_pkt(graph->port, pkt);
kfree(pkt);
return rc;
}
EXPORT_SYMBOL_GPL(q6apm_read);
static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
{
struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done_v2 *rd_done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment