[Sound-open-firmware] [PATCH] core: comp: Add component trigger API call.

Liam Girdwood liam.r.girdwood at linux.intel.com
Thu Mar 29 10:38:50 CEST 2018


Add a new component API for performing atomic stream state change
operations. This leave the cmd API for non atomic usage.

This patch also does some renaming to use _trigger() instead of _cmd().

Signed-off-by: Liam Girdwood <liam.r.girdwood at linux.intel.com>
Tested-By: Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
---
 src/audio/component.c              | 14 ++++++------
 src/audio/dai.c                    | 28 +++++++++++-------------
 src/audio/eq_fir.c                 | 20 ++++++++++-------
 src/audio/eq_iir.c                 | 20 ++++++++++-------
 src/audio/host.c                   | 22 +++++++++----------
 src/audio/mixer.c                  | 18 ++++++++--------
 src/audio/pipeline.c               | 44 ++++++++++++++++++--------------------
 src/audio/src.c                    | 16 ++++++++------
 src/audio/tone.c                   | 18 ++++++++++------
 src/audio/volume.c                 | 21 ++++++++++--------
 src/drivers/apl-ssp.c              | 12 +++++------
 src/drivers/ssp.c                  | 12 +++++------
 src/include/reef/audio/component.h | 32 +++++++++++++++++----------
 src/include/reef/audio/pipeline.h  |  5 ++---
 src/ipc/intel-ipc.c                | 13 ++++++-----
 15 files changed, 159 insertions(+), 136 deletions(-)

diff --git a/src/audio/component.c b/src/audio/component.c
index 1802278e..605652a2 100644
--- a/src/audio/component.c
+++ b/src/audio/component.c
@@ -121,7 +121,7 @@ int comp_set_state(struct comp_dev *dev, int cmd)
 	int ret = 0;
 
 	switch (cmd) {
-	case COMP_CMD_START:
+	case COMP_TRIGGER_START:
 		if (dev->state == COMP_STATE_PREPARE ||
 			dev->state == COMP_STATE_PAUSED) {
 			dev->state = COMP_STATE_ACTIVE;
@@ -131,7 +131,7 @@ int comp_set_state(struct comp_dev *dev, int cmd)
 			ret = -EINVAL;
 		}
 		break;
-	case COMP_CMD_RELEASE:
+	case COMP_TRIGGER_RELEASE:
 		if (dev->state == COMP_STATE_PAUSED) {
 			dev->state = COMP_STATE_ACTIVE;
 		} else {
@@ -140,8 +140,8 @@ int comp_set_state(struct comp_dev *dev, int cmd)
 			ret = -EINVAL;
 		}
 		break;
-	case COMP_CMD_STOP:
-	case COMP_CMD_XRUN:
+	case COMP_TRIGGER_STOP:
+	case COMP_TRIGGER_XRUN:
 		if (dev->state == COMP_STATE_ACTIVE) {
 			dev->state = COMP_STATE_PREPARE;
 		} else {
@@ -150,7 +150,7 @@ int comp_set_state(struct comp_dev *dev, int cmd)
 			ret = -EINVAL;
 		}
 		break;
-	case COMP_CMD_PAUSE:
+	case COMP_TRIGGER_PAUSE:
 		/* only support pausing for running */
 		if (dev->state == COMP_STATE_ACTIVE)
 			dev->state = COMP_STATE_PAUSED;
@@ -160,7 +160,7 @@ int comp_set_state(struct comp_dev *dev, int cmd)
 			ret = -EINVAL;
 		}
 		break;
-	case COMP_CMD_RESET:
+	case COMP_TRIGGER_RESET:
 		/* reset always succeeds */
 		dev->state = COMP_STATE_READY;
 		if (dev->state == COMP_STATE_ACTIVE ||
@@ -170,7 +170,7 @@ int comp_set_state(struct comp_dev *dev, int cmd)
 			ret = 0;
 		}
 		break;
-	case COMP_CMD_PREPARE:
+	case COMP_TRIGGER_PREPARE:
 		if (dev->state == COMP_STATE_PREPARE ||
 			dev->state == COMP_STATE_READY) {
 			dev->state = COMP_STATE_PREPARE;
diff --git a/src/audio/dai.c b/src/audio/dai.c
index 53536ed3..5691aca7 100644
--- a/src/audio/dai.c
+++ b/src/audio/dai.c
@@ -72,8 +72,6 @@ struct dai_data {
 	uint64_t wallclock;	/* wall clock at stream start */
 };
 
-static int dai_cmd(struct comp_dev *dev, int cmd, void *data);
-
 /* this is called by DMA driver every time descriptor has completed */
 static void dai_dma_cb(void *data, uint32_t type, struct dma_sg_elem *next)
 {
@@ -88,7 +86,7 @@ static void dai_dma_cb(void *data, uint32_t type, struct dma_sg_elem *next)
 	if (dev->state != COMP_STATE_ACTIVE && dd->xrun == 0) {
 
 		/* stop the DAI */
-		dai_trigger(dd->dai, COMP_CMD_STOP, dev->params.direction);
+		dai_trigger(dd->dai, COMP_TRIGGER_STOP, dev->params.direction);
 
 		/* tell DMA not to reload */
 		next->size = DMA_RELOAD_END;
@@ -435,7 +433,7 @@ static int dai_prepare(struct comp_dev *dev)
 
 	trace_dai("pre");
 
-	ret = comp_set_state(dev, COMP_CMD_PREPARE);
+	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
 		return ret;
 
@@ -443,7 +441,7 @@ static int dai_prepare(struct comp_dev *dev)
 
 	if (list_is_empty(&dd->config.elem_list)) {
 		trace_dai_error("wdm");
-		comp_set_state(dev, COMP_CMD_RESET);
+		comp_set_state(dev, COMP_TRIGGER_RESET);
 		return -EINVAL;
 	}
 
@@ -463,7 +461,7 @@ static int dai_prepare(struct comp_dev *dev)
 
 	ret = dma_set_config(dd->dma, dd->chan, &dd->config);
 	if (ret < 0)
-		comp_set_state(dev, COMP_CMD_RESET);
+		comp_set_state(dev, COMP_TRIGGER_RESET);
 
 	return ret;
 }
@@ -492,7 +490,7 @@ static int dai_reset(struct comp_dev *dev)
 	dd->wallclock = 0;
 	dev->position = 0;
 	dd->xrun = 0;
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 
 	return 0;
 }
@@ -529,12 +527,12 @@ static void dai_pointer_init(struct comp_dev *dev)
 }
 
 /* used to pass standard and bespoke command (with data) to component */
-static int dai_cmd(struct comp_dev *dev, int cmd, void *data)
+static int dai_comp_trigger(struct comp_dev *dev, int cmd)
 {
 	struct dai_data *dd = comp_get_drvdata(dev);
 	int ret;
 
-	trace_dai("cmd");
+	trace_dai("trg");
 	tracev_value(cmd);
 
 	wait_init(&dd->complete);
@@ -544,10 +542,10 @@ static int dai_cmd(struct comp_dev *dev, int cmd, void *data)
 		return ret;
 
 	switch (cmd) {
-	case COMP_CMD_START:
+	case COMP_TRIGGER_START:
 		dai_pointer_init(dev);
 		/* fall through */
-	case COMP_CMD_RELEASE:
+	case COMP_TRIGGER_RELEASE:
 
 		/* only start the DAI if we are not XRUN handling */
 		if (dd->xrun == 0) {
@@ -564,11 +562,11 @@ static int dai_cmd(struct comp_dev *dev, int cmd, void *data)
 		/* update starting wallclock */
 		platform_dai_wallclock(dev, &dd->wallclock);
 		break;
-	case COMP_CMD_XRUN:
+	case COMP_TRIGGER_XRUN:
 		dd->xrun = 1;
 		/* fall through */
-	case COMP_CMD_PAUSE:
-	case COMP_CMD_STOP:
+	case COMP_TRIGGER_PAUSE:
+	case COMP_TRIGGER_STOP:
 		wait_init(&dd->complete);
 
 		/* wait for DMA to complete */
@@ -638,7 +636,7 @@ static struct comp_driver comp_dai = {
 		.new		= dai_new,
 		.free		= dai_free,
 		.params		= dai_params,
-		.cmd		= dai_cmd,
+		.trigger	= dai_comp_trigger,
 		.copy		= dai_copy,
 		.prepare	= dai_prepare,
 		.reset		= dai_reset,
diff --git a/src/audio/eq_fir.c b/src/audio/eq_fir.c
index 52988cdf..72cfe938 100644
--- a/src/audio/eq_fir.c
+++ b/src/audio/eq_fir.c
@@ -425,10 +425,6 @@ static int eq_fir_cmd(struct comp_dev *dev, int cmd, void *data)
 
 	trace_eq("cmd");
 
-	ret = comp_set_state(dev, cmd);
-	if (ret < 0)
-		return ret;
-
 	switch (cmd) {
 	case COMP_CMD_SET_VALUE:
 		ret = fir_cmd_set_value(dev, cdata);
@@ -441,6 +437,13 @@ static int eq_fir_cmd(struct comp_dev *dev, int cmd, void *data)
 	return ret;
 }
 
+static int eq_fir_trigger(struct comp_dev *dev, int cmd)
+{
+	trace_eq("trg");
+
+	return comp_set_state(dev, cmd);
+}
+
 /* copy and process stream data from source to sink buffers */
 static int eq_fir_copy(struct comp_dev *dev)
 {
@@ -482,7 +485,7 @@ static int eq_fir_prepare(struct comp_dev *dev)
 
 	trace_eq("EPp");
 
-	ret = comp_set_state(dev, COMP_CMD_PREPARE);
+	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
 		return ret;
 
@@ -490,13 +493,13 @@ static int eq_fir_prepare(struct comp_dev *dev)
 
 	/* Initialize EQ */
 	if (cd->config == NULL) {
-		comp_set_state(dev, COMP_CMD_RESET);
+		comp_set_state(dev, COMP_TRIGGER_RESET);
 		return -EINVAL;
 	}
 
 	ret = eq_fir_setup(cd->fir, cd->config, dev->params.channels);
 	if (ret < 0) {
-		comp_set_state(dev, COMP_CMD_RESET);
+		comp_set_state(dev, COMP_TRIGGER_RESET);
 		return ret;
 	}
 
@@ -517,7 +520,7 @@ static int eq_fir_reset(struct comp_dev *dev)
 	for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
 		fir_reset(&cd->fir[i]);
 
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return 0;
 }
 
@@ -528,6 +531,7 @@ struct comp_driver comp_eq_fir = {
 		.free = eq_fir_free,
 		.params = eq_fir_params,
 		.cmd = eq_fir_cmd,
+		.trigger = eq_fir_trigger,
 		.copy = eq_fir_copy,
 		.prepare = eq_fir_prepare,
 		.reset = eq_fir_reset,
diff --git a/src/audio/eq_iir.c b/src/audio/eq_iir.c
index bbcd66b8..239eead3 100644
--- a/src/audio/eq_iir.c
+++ b/src/audio/eq_iir.c
@@ -424,10 +424,6 @@ static int eq_iir_cmd(struct comp_dev *dev, int cmd, void *data)
 
 	trace_eq_iir("cmd");
 
-	ret = comp_set_state(dev, cmd);
-	if (ret < 0)
-		return ret;
-
 	switch (cmd) {
 	case COMP_CMD_SET_VALUE:
 		ret = iir_cmd_set_value(dev, cdata);
@@ -440,6 +436,13 @@ static int eq_iir_cmd(struct comp_dev *dev, int cmd, void *data)
 	return ret;
 }
 
+static int eq_iir_trigger(struct comp_dev *dev, int cmd)
+{
+	trace_eq_iir("trg");
+
+	return comp_set_state(dev, cmd);
+}
+
 /* copy and process stream data from source to sink buffers */
 static int eq_iir_copy(struct comp_dev *dev)
 {
@@ -481,7 +484,7 @@ static int eq_iir_prepare(struct comp_dev *dev)
 
 	trace_eq_iir("EPp");
 
-	ret = comp_set_state(dev, COMP_CMD_PREPARE);
+	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
 		return ret;
 
@@ -492,13 +495,13 @@ static int eq_iir_prepare(struct comp_dev *dev)
 	 * interrupts pipeline prepare for downstream.
 	 */
 	if (cd->config == NULL) {
-		comp_set_state(dev, COMP_CMD_RESET);
+		comp_set_state(dev, COMP_TRIGGER_RESET);
 		return -EINVAL;
 	}
 
 	ret = eq_iir_setup(cd->iir, cd->config, dev->params.channels);
 	if (ret < 0) {
-		comp_set_state(dev, COMP_CMD_RESET);
+		comp_set_state(dev, COMP_TRIGGER_RESET);
 		return ret;
 	}
 
@@ -519,7 +522,7 @@ static int eq_iir_reset(struct comp_dev *dev)
 	for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
 		iir_reset_df2t(&cd->iir[i]);
 
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return 0;
 }
 
@@ -530,6 +533,7 @@ struct comp_driver comp_eq_iir = {
 		.free = eq_iir_free,
 		.params = eq_iir_params,
 		.cmd = eq_iir_cmd,
+		.trigger = eq_iir_trigger,
 		.copy = eq_iir_copy,
 		.prepare = eq_iir_prepare,
 		.reset = eq_iir_reset,
diff --git a/src/audio/host.c b/src/audio/host.c
index 9177d994..3ca67b5e 100644
--- a/src/audio/host.c
+++ b/src/audio/host.c
@@ -274,7 +274,7 @@ unwind:
 }
 
 /* used to pass standard and bespoke commands (with data) to component */
-static int host_cmd(struct comp_dev *dev, int cmd, void *data)
+static int host_trigger(struct comp_dev *dev, int cmd)
 {
 	int ret = 0;
 
@@ -285,10 +285,10 @@ static int host_cmd(struct comp_dev *dev, int cmd, void *data)
 		return ret;
 
 	switch (cmd) {
-	case COMP_CMD_STOP:
+	case COMP_TRIGGER_STOP:
 		ret = host_stop(dev);
 		break;
-	case COMP_CMD_START:
+	case COMP_TRIGGER_START:
 		/* preload first playback period for preloader task */
 		if (dev->params.direction == SOF_IPC_STREAM_PLAYBACK) {
 			ret = host_copy(dev);
@@ -453,25 +453,25 @@ unwind:
 }
 
 /* used to pass standard and bespoke commands (with data) to component */
-static int host_cmd(struct comp_dev *dev, int cmd, void *data)
+static int host_trigger(struct comp_dev *dev, int cmd)
 {
 	struct host_data *hd = comp_get_drvdata(dev);
 	int ret = 0;
 
-	trace_host("cmd");
+	trace_host("trg");
 
 	ret = comp_set_state(dev, cmd);
 	if (ret < 0)
 		return ret;
 
 	switch (cmd) {
-	case COMP_CMD_PAUSE:
+	case COMP_TRIGGER_PAUSE:
 		dma_stop(hd->dma, hd->chan);
 		break;
-	case COMP_CMD_STOP:
+	case COMP_TRIGGER_STOP:
 		ret = host_stop(dev);
 		break;
-	case COMP_CMD_START:
+	case COMP_TRIGGER_START:
 		dma_start(hd->dma, hd->chan);
 
 		/* preload first playback period for preloader task */
@@ -716,7 +716,7 @@ static int host_prepare(struct comp_dev *dev)
 
 	trace_host("pre");
 
-	ret = comp_set_state(dev, COMP_CMD_PREPARE);
+	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
 		return ret;
 
@@ -744,7 +744,7 @@ static int host_pointer_reset(struct comp_dev *dev)
 	hd->local_pos = 0;
 	hd->report_pos = 0;
 	dev->position = 0;
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 
 	return 0;
 }
@@ -907,7 +907,7 @@ struct comp_driver comp_host = {
 		.free		= host_free,
 		.params		= host_params,
 		.reset		= host_reset,
-		.cmd		= host_cmd,
+		.trigger	= host_trigger,
 		.copy		= host_copy,
 		.prepare	= host_prepare,
 		.host_buffer	= host_buffer,
diff --git a/src/audio/mixer.c b/src/audio/mixer.c
index abc8881b..d05a40c3 100644
--- a/src/audio/mixer.c
+++ b/src/audio/mixer.c
@@ -178,24 +178,24 @@ static inline int mixer_sink_status(struct comp_dev *mixer)
 }
 
 /* used to pass standard and bespoke commands (with data) to component */
-static int mixer_cmd(struct comp_dev *dev, int cmd, void *data)
+static int mixer_trigger(struct comp_dev *dev, int cmd)
 {
 	int ret;
 
-	trace_mixer("cmd");
+	trace_mixer("trg");
 
 	ret = comp_set_state(dev, cmd);
 	if (ret < 0)
 		return ret;
 
 	switch(cmd) {
-	case COMP_CMD_START:
-	case COMP_CMD_RELEASE:
+	case COMP_TRIGGER_START:
+	case COMP_TRIGGER_RELEASE:
 		if (mixer_sink_status(dev) == COMP_STATE_ACTIVE)
 			return 1; /* no need to go downstream */
 		break;
-	case COMP_CMD_PAUSE:
-	case COMP_CMD_STOP:
+	case COMP_TRIGGER_PAUSE:
+	case COMP_TRIGGER_STOP:
 		if (mixer_source_status_count(dev, COMP_STATE_ACTIVE) > 0) {
 			dev->state = COMP_STATE_ACTIVE;
 			return 1; /* no need to go downstream */
@@ -289,7 +289,7 @@ static int mixer_reset(struct comp_dev *dev)
 			return 1; /* should not reset the downstream components */
 	}
 
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return 0;
 }
 
@@ -318,7 +318,7 @@ static int mixer_prepare(struct comp_dev *dev)
 		md->mix_func = mix_n;
 		dev->state = COMP_STATE_PREPARE;
 
-		ret = comp_set_state(dev, COMP_CMD_PREPARE);
+		ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 		if (ret < 0)
 			return ret;
 	}
@@ -345,7 +345,7 @@ struct comp_driver comp_mixer = {
 		.free		= mixer_free,
 		.params		= mixer_params,
 		.prepare	= mixer_prepare,
-		.cmd		= mixer_cmd,
+		.trigger	= mixer_trigger,
 		.copy		= mixer_copy,
 		.reset		= mixer_reset,
 	},
diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c
index 23be5031..31ade4eb 100644
--- a/src/audio/pipeline.c
+++ b/src/audio/pipeline.c
@@ -193,20 +193,20 @@ static void disconnect_downstream(struct pipeline *p, struct comp_dev *start,
 }
 
 /* update pipeline state based on cmd */
-static void pipeline_cmd_update(struct pipeline *p, struct comp_dev *comp,
-	int cmd)
+static void pipeline_trigger_sched_comp(struct pipeline *p,
+					struct comp_dev *comp, int cmd)
 {
 	/* only required by the scheduling component */
 	if (p->sched_comp != comp)
 		return;
 
 	switch (cmd) {
-	case COMP_CMD_PAUSE:
-	case COMP_CMD_STOP:
+	case COMP_TRIGGER_PAUSE:
+	case COMP_TRIGGER_STOP:
 		pipeline_schedule_cancel(p);
 		break;
-	case COMP_CMD_START:
-	case COMP_CMD_RELEASE:
+	case COMP_TRIGGER_START:
+	case COMP_TRIGGER_RELEASE:
 		p->xrun_bytes = 0;
 
 		/* playback pipelines need scheduled now, capture pipelines are
@@ -223,9 +223,9 @@ static void pipeline_cmd_update(struct pipeline *p, struct comp_dev *comp,
 			}
 		}
 		break;
-	case COMP_CMD_SUSPEND:
-	case COMP_CMD_RESUME:
-	case COMP_CMD_XRUN:
+	case COMP_TRIGGER_SUSPEND:
+	case COMP_TRIGGER_RESUME:
+	case COMP_TRIGGER_XRUN:
 	default:
 		break;
 	}
@@ -374,12 +374,12 @@ static int component_op_downstream(struct op_data *op_data,
 			comp_install_params(current, previous);
 		err = comp_params(current);
 		break;
-	case COMP_OPS_CMD:
+	case COMP_OPS_TRIGGER:
 		/* send command to the component and update pipeline state  */
-		err = comp_cmd(current, op_data->cmd, op_data->cmd_data);
+		err = comp_trigger(current, op_data->cmd);
 		if (err == 0)
-			pipeline_cmd_update(current->pipeline, current,
-				op_data->cmd);
+			pipeline_trigger_sched_comp(current->pipeline, current,
+						    op_data->cmd);
 		break;
 	case COMP_OPS_PREPARE:
 		/* prepare the component */
@@ -455,12 +455,12 @@ static int component_op_upstream(struct op_data *op_data,
 			comp_install_params(current, previous);
 		err = comp_params(current);
 		break;
-	case COMP_OPS_CMD:
+	case COMP_OPS_TRIGGER:
 		/* send command to the component and update pipeline state  */
-		err = comp_cmd(current, op_data->cmd, op_data->cmd_data);
+		err = comp_trigger(current, op_data->cmd);
 		if (err == 0)
-			pipeline_cmd_update(current->pipeline, current,
-				op_data->cmd);
+			pipeline_trigger_sched_comp(current->pipeline, current,
+						    op_data->cmd);
 		break;
 	case COMP_OPS_PREPARE:
 		/* prepare the component */
@@ -622,8 +622,7 @@ out:
 }
 
 /* send pipeline component/endpoint a command */
-int pipeline_cmd(struct pipeline *p, struct comp_dev *host, int cmd,
-	void *data)
+int pipeline_trigger(struct pipeline *p, struct comp_dev *host, int cmd)
 {
 	struct op_data op_data;
 	int ret;
@@ -632,9 +631,8 @@ int pipeline_cmd(struct pipeline *p, struct comp_dev *host, int cmd,
 	trace_pipe("cmd");
 
 	op_data.p = p;
-	op_data.op = COMP_OPS_CMD;
+	op_data.op = COMP_OPS_TRIGGER;
 	op_data.cmd = cmd;
-	op_data.cmd_data = data;
 
 	spin_lock_irq(&p->lock, flags);
 
@@ -1056,7 +1054,7 @@ static int pipeline_xrun_recover(struct pipeline *p)
 	trace_pipe_error("pxr");
 
 	/* notify all pipeline comps we are in XRUN */
-	ret = pipeline_cmd(p, p->source_comp, COMP_CMD_XRUN, NULL);
+	ret = pipeline_trigger(p, p->source_comp, COMP_TRIGGER_XRUN);
 	if (ret < 0) {
 		trace_pipe_error("px0");
 		return ret;
@@ -1071,7 +1069,7 @@ static int pipeline_xrun_recover(struct pipeline *p)
 	}
 
 	/* restart pipeline comps */
-	ret = pipeline_cmd(p, p->source_comp, COMP_CMD_START, NULL);
+	ret = pipeline_trigger(p, p->source_comp, COMP_TRIGGER_START);
 	if (ret < 0) {
 		trace_pipe_error("px2");
 		return ret;
diff --git a/src/audio/src.c b/src/audio/src.c
index a579fa91..1045bdf4 100644
--- a/src/audio/src.c
+++ b/src/audio/src.c
@@ -751,16 +751,19 @@ static int src_cmd(struct comp_dev *dev, int cmd, void *data)
 
 	trace_src("cmd");
 
-	ret = comp_set_state(dev, cmd);
-	if (ret < 0)
-		return ret;
-
 	if (cmd == COMP_CMD_SET_VALUE)
 		ret = src_ctrl_cmd(dev, cdata);
 
 	return ret;
 }
 
+static int src_trigger(struct comp_dev *dev, int cmd)
+{
+	trace_src("trg");
+
+	return comp_set_state(dev, cmd);
+}
+
 /* copy and process stream data from source to sink buffers */
 static int src_copy(struct comp_dev *dev)
 {
@@ -827,7 +830,7 @@ static int src_prepare(struct comp_dev *dev)
 {
 	trace_src("pre");
 
-	return comp_set_state(dev, COMP_CMD_PREPARE);
+	return comp_set_state(dev, COMP_TRIGGER_PREPARE);
 }
 
 static int src_reset(struct comp_dev *dev)
@@ -839,7 +842,7 @@ static int src_reset(struct comp_dev *dev)
 	cd->src_func = src_2s_s32_default;
 	src_polyphase_reset(&cd->src);
 
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return 0;
 }
 
@@ -850,6 +853,7 @@ struct comp_driver comp_src = {
 		.free = src_free,
 		.params = src_params,
 		.cmd = src_cmd,
+		.trigger = src_trigger,
 		.copy = src_copy,
 		.prepare = src_prepare,
 		.reset = src_reset,
diff --git a/src/audio/tone.c b/src/audio/tone.c
index e4e98927..af23cc4b 100644
--- a/src/audio/tone.c
+++ b/src/audio/tone.c
@@ -576,10 +576,6 @@ static int tone_cmd(struct comp_dev *dev, int cmd, void *data)
 
 	trace_tone("cmd");
 
-	ret = comp_set_state(dev, cmd);
-	if (ret < 0)
-		return ret;
-
 	switch (cmd) {
 	case COMP_CMD_SET_DATA:
 		ret = tone_cmd_set_data(dev, cdata);
@@ -592,6 +588,13 @@ static int tone_cmd(struct comp_dev *dev, int cmd, void *data)
 	return ret;
 }
 
+static int tone_trigger(struct comp_dev *dev, int cmd)
+{
+	trace_tone("trg");
+
+	return comp_set_state(dev, cmd);
+}
+
 /* copy and process stream data from source to sink buffers */
 static int tone_copy(struct comp_dev * dev)
 {
@@ -633,7 +636,7 @@ static int tone_prepare(struct comp_dev * dev)
 
 	trace_tone("TPp");
 
-	ret = comp_set_state(dev, COMP_CMD_PREPARE);
+	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
 		return ret;
 
@@ -646,7 +649,7 @@ static int tone_prepare(struct comp_dev * dev)
 		f = tonegen_get_f(&cd->sg[i]);
 		a = tonegen_get_a(&cd->sg[i]);
 		if (tonegen_init(&cd->sg[i], cd->rate, f, a) < 0) {
-			comp_set_state(dev, COMP_CMD_RESET);
+			comp_set_state(dev, COMP_TRIGGER_RESET);
 			return -EINVAL;
 		}
 	}
@@ -666,7 +669,7 @@ static int tone_reset(struct comp_dev * dev)
 	for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
 		tonegen_reset(&cd->sg[i]);
 
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 
 	return 0;
 }
@@ -678,6 +681,7 @@ struct comp_driver comp_tone = {
 		.free = tone_free,
 		.params = tone_params,
 		.cmd = tone_cmd,
+		.trigger = tone_trigger,
 		.copy = tone_copy,
 		.prepare = tone_prepare,
 		.reset = tone_reset,
diff --git a/src/audio/volume.c b/src/audio/volume.c
index 1a3f4369..cff09a34 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -809,24 +809,26 @@ static int volume_ctrl_get_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *c
 static int volume_cmd(struct comp_dev *dev, int cmd, void *data)
 {
 	struct sof_ipc_ctrl_data *cdata = data;
-	int ret;
 
 	trace_volume("cmd");
 
-	ret = comp_set_state(dev, cmd);
-	if (ret < 0)
-		return ret;
-
 	switch (cmd) {
 	case COMP_CMD_SET_VALUE:
 		return volume_ctrl_set_cmd(dev, cdata);
 	case COMP_CMD_GET_VALUE:
 		return volume_ctrl_get_cmd(dev, cdata);
 	default:
-		return ret;
+		return -EINVAL;
 	}
 }
 
+static int volume_trigger(struct comp_dev *dev, int cmd)
+{
+	trace_volume("trg");
+
+	return comp_set_state(dev, cmd);
+}
+
 /* copy and process stream data from source to sink buffers */
 static int volume_copy(struct comp_dev *dev)
 {
@@ -880,7 +882,7 @@ static int volume_prepare(struct comp_dev *dev)
 
 	trace_volume("pre");
 
-	ret = comp_set_state(dev, COMP_CMD_PREPARE);
+	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
 		return ret;
 
@@ -975,7 +977,7 @@ static int volume_prepare(struct comp_dev *dev)
 	trace_error_value(dev->params.channels);
 
 err:
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return ret;
 
 found:
@@ -989,7 +991,7 @@ static int volume_reset(struct comp_dev *dev)
 {
 	trace_volume("res");
 
-	comp_set_state(dev, COMP_CMD_RESET);
+	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return 0;
 }
 
@@ -1000,6 +1002,7 @@ struct comp_driver comp_volume = {
 		.free		= volume_free,
 		.params		= volume_params,
 		.cmd		= volume_cmd,
+		.trigger	= volume_trigger,
 		.copy		= volume_copy,
 		.prepare	= volume_prepare,
 		.reset		= volume_reset,
diff --git a/src/drivers/apl-ssp.c b/src/drivers/apl-ssp.c
index 6424b7d8..9af28a89 100644
--- a/src/drivers/apl-ssp.c
+++ b/src/drivers/apl-ssp.c
@@ -575,25 +575,25 @@ static int ssp_trigger(struct dai *dai, int cmd, int direction)
 	trace_ssp("tri");
 
 	switch (cmd) {
-	case COMP_CMD_START:
+	case COMP_TRIGGER_START:
 		if (ssp->state[direction] == COMP_STATE_PREPARE ||
 			ssp->state[direction] == COMP_STATE_PAUSED)
 			ssp_start(dai, direction);
 		break;
-	case COMP_CMD_RELEASE:
+	case COMP_TRIGGER_RELEASE:
 		if (ssp->state[direction] == COMP_STATE_PAUSED ||
 			ssp->state[direction] == COMP_STATE_PREPARE)
 			ssp_start(dai, direction);
 		break;
-	case COMP_CMD_STOP:
-	case COMP_CMD_PAUSE:
+	case COMP_TRIGGER_STOP:
+	case COMP_TRIGGER_PAUSE:
 		ssp->state[direction] = COMP_STATE_PAUSED;
 		ssp_stop(dai);
 		break;
-	case COMP_CMD_RESUME:
+	case COMP_TRIGGER_RESUME:
 		ssp_context_restore(dai);
 		break;
-	case COMP_CMD_SUSPEND:
+	case COMP_TRIGGER_SUSPEND:
 		ssp_context_store(dai);
 		break;
 	default:
diff --git a/src/drivers/ssp.c b/src/drivers/ssp.c
index 827a4d81..ae9c58ce 100644
--- a/src/drivers/ssp.c
+++ b/src/drivers/ssp.c
@@ -540,25 +540,25 @@ static int ssp_trigger(struct dai *dai, int cmd, int direction)
 	trace_ssp("tri");
 
 	switch (cmd) {
-	case COMP_CMD_START:
+	case COMP_TRIGGER_START:
 		if (ssp->state[direction] == COMP_STATE_PREPARE ||
 			ssp->state[direction] == COMP_STATE_PAUSED)
 			ssp_start(dai, direction);
 		break;
-	case COMP_CMD_RELEASE:
+	case COMP_TRIGGER_RELEASE:
 		if (ssp->state[direction] == COMP_STATE_PAUSED ||
 			ssp->state[direction] == COMP_STATE_PREPARE)
 			ssp_start(dai, direction);
 		break;
-	case COMP_CMD_STOP:
-	case COMP_CMD_PAUSE:
+	case COMP_TRIGGER_STOP:
+	case COMP_TRIGGER_PAUSE:
 		ssp->state[direction] = COMP_STATE_PAUSED;
 		ssp_stop(dai);
 		break;
-	case COMP_CMD_RESUME:
+	case COMP_TRIGGER_RESUME:
 		ssp_context_restore(dai);
 		break;
-	case COMP_CMD_SUSPEND:
+	case COMP_TRIGGER_SUSPEND:
 		ssp_context_store(dai);
 		break;
 	default:
diff --git a/src/include/reef/audio/component.h b/src/include/reef/audio/component.h
index 538d4761..2e58170a 100644
--- a/src/include/reef/audio/component.h
+++ b/src/include/reef/audio/component.h
@@ -70,17 +70,18 @@
 
 /*
  * standard component stream commands
+ * TODO: use IPC versions after 1.1
  */
 
-#define COMP_CMD_STOP		0	/* stop component stream */
-#define COMP_CMD_START		1	/* start component stream */
-#define COMP_CMD_PAUSE		2	/* immediately pause the component stream */
-#define COMP_CMD_RELEASE	3	/* release paused component stream */
-#define COMP_CMD_SUSPEND	5	/* suspend component */
-#define COMP_CMD_RESUME		6	/* resume component */
-#define COMP_CMD_RESET		6	/* reset component */
-#define COMP_CMD_PREPARE	7	/* prepare component */
-#define COMP_CMD_XRUN		8	/* XRUN component */
+#define COMP_TRIGGER_STOP	0	/* stop component stream */
+#define COMP_TRIGGER_START	1	/* start component stream */
+#define COMP_TRIGGER_PAUSE	2	/* pause the component stream */
+#define COMP_TRIGGER_RELEASE	3	/* release paused component stream */
+#define COMP_TRIGGER_SUSPEND	5	/* suspend component */
+#define COMP_TRIGGER_RESUME	6	/* resume component */
+#define COMP_TRIGGER_RESET	6	/* reset component */
+#define COMP_TRIGGER_PREPARE	7	/* prepare component */
+#define COMP_TRIGGER_XRUN	8	/* XRUN component */
 
 /*
  * standard component control commands
@@ -100,7 +101,7 @@
 
 /* component operations */
 #define COMP_OPS_PARAMS		0
-#define COMP_OPS_CMD		1
+#define COMP_OPS_TRIGGER	1
 #define COMP_OPS_PREPARE	2
 #define COMP_OPS_COPY		3
 #define COMP_OPS_BUFFER		4
@@ -133,9 +134,12 @@ struct comp_ops {
 	int (*dai_config)(struct comp_dev *dev,
 		struct sof_ipc_dai_config *dai_config);
 
-	/* used to pass standard and bespoke commands (with data) to component */
+	/* used to pass standard and bespoke commands (with optional data) */
 	int (*cmd)(struct comp_dev *dev, int cmd, void *data);
 
+	/* atomic - used to start/stop/pause stream operations */
+	int (*trigger)(struct comp_dev *dev, int cmd);
+
 	/* prepare component after params are set */
 	int (*prepare)(struct comp_dev *dev);
 
@@ -258,6 +262,12 @@ static inline int comp_cmd(struct comp_dev *dev, int cmd, void *data)
 	return dev->drv->ops.cmd(dev, cmd, data);
 }
 
+/* trigger component - mandatory and atomic */
+static inline int comp_trigger(struct comp_dev *dev, int cmd)
+{
+	return dev->drv->ops.trigger(dev, cmd);
+}
+
 /* prepare component - mandatory */
 static inline int comp_prepare(struct comp_dev *dev)
 {
diff --git a/src/include/reef/audio/pipeline.h b/src/include/reef/audio/pipeline.h
index dca9413b..8e5dae34 100644
--- a/src/include/reef/audio/pipeline.h
+++ b/src/include/reef/audio/pipeline.h
@@ -103,9 +103,8 @@ int pipeline_prepare(struct pipeline *p, struct comp_dev *cd);
 /* reset the pipeline and free resources */
 int pipeline_reset(struct pipeline *p, struct comp_dev *host_cd);
 
-/* send pipeline a command */
-int pipeline_cmd(struct pipeline *p, struct comp_dev *host_cd, int cmd,
-	void *data);
+/* trigger pipeline - atomic */
+int pipeline_trigger(struct pipeline *p, struct comp_dev *host_cd, int cmd);
 
 /* initialise pipeline subsys */
 int pipeline_init(void);
diff --git a/src/ipc/intel-ipc.c b/src/ipc/intel-ipc.c
index 5c062bed..8dbe7253 100644
--- a/src/ipc/intel-ipc.c
+++ b/src/ipc/intel-ipc.c
@@ -433,7 +433,7 @@ int ipc_stream_send_xrun(struct comp_dev *cdev,
 static int ipc_stream_trigger(uint32_t header)
 {
 	struct ipc_comp_dev *pcm_dev;
-	uint32_t cmd = COMP_CMD_RELEASE;
+	uint32_t cmd = COMP_TRIGGER_RELEASE;
 	struct sof_ipc_stream *stream  = _ipc->comp_data;
 	uint32_t ipc_cmd = (header & SOF_CMD_TYPE_MASK) >> SOF_CMD_TYPE_SHIFT;
 	int ret;
@@ -449,16 +449,16 @@ static int ipc_stream_trigger(uint32_t header)
 
 	switch (ipc_cmd) {
 	case iCS(SOF_IPC_STREAM_TRIG_START):
-		cmd = COMP_CMD_START;
+		cmd = COMP_TRIGGER_START;
 		break;
 	case iCS(SOF_IPC_STREAM_TRIG_STOP):
-		cmd = COMP_CMD_STOP;
+		cmd = COMP_TRIGGER_STOP;
 		break;
 	case iCS(SOF_IPC_STREAM_TRIG_PAUSE):
-		cmd = COMP_CMD_PAUSE;
+		cmd = COMP_TRIGGER_PAUSE;
 		break;
 	case iCS(SOF_IPC_STREAM_TRIG_RELEASE):
-		cmd = COMP_CMD_RELEASE;
+		cmd = COMP_TRIGGER_RELEASE;
 		break;
 	/* XRUN is special case- TODO */
 	case iCS(SOF_IPC_STREAM_TRIG_XRUN):
@@ -466,8 +466,7 @@ static int ipc_stream_trigger(uint32_t header)
 	}
 
 	/* trigger the component */
-	ret = pipeline_cmd(pcm_dev->cd->pipeline, pcm_dev->cd,
-			cmd, NULL);
+	ret = pipeline_trigger(pcm_dev->cd->pipeline, pcm_dev->cd, cmd);
 	if (ret < 0) {
 		trace_ipc_error("eRc");
 		trace_error_value(ipc_cmd);
-- 
2.14.1



More information about the Sound-open-firmware mailing list