[PATCH] soundwire: stream: only change state if needed

Srinivas Kandagatla srinivas.kandagatla at linaro.org
Tue Mar 17 12:53:29 CET 2020


Thanks Pierre for this patch,

On 17/03/2020 10:51, Pierre-Louis Bossart wrote:
> In a multi-cpu DAI context, the stream routines may be called from
> multiple DAI callbacks. Make sure the stream state only changes for
> the first call, and don't return error messages if the target state is
> already reached.
> 
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>
> ---
>   drivers/soundwire/stream.c | 19 +++++++++++++++++++
>   1 file changed, 19 insertions(+)
> 

This patch did not work for me as it is as wsa881x codec does prepare 
and enable in one function, which breaks some of the assumptions in this 
patch.

However with below change I could get it working without moving stream 
handling to machine driver.

---------------------------->cut<-------------------------------
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index be71af4671a4..4a94ea64c1c5 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1574,7 +1574,8 @@ int sdw_prepare_stream(struct sdw_stream_runtime 
*stream)

         sdw_acquire_bus_lock(stream);

-       if (stream->state == SDW_STREAM_PREPARED) {
+       if (stream->state == SDW_STREAM_PREPARED ||
+           stream->state == SDW_STREAM_ENABLED) {
                 /* nothing to do */
                 ret = 0;
                 goto state_err;
@@ -1754,7 +1755,8 @@ int sdw_disable_stream(struct sdw_stream_runtime 
*stream)

         sdw_acquire_bus_lock(stream);

-       if (stream->state == SDW_STREAM_DISABLED) {
+       if (stream->state == SDW_STREAM_DISABLED ||
+           stream->state == SDW_STREAM_DEPREPARED) {
                 /* nothing to do */
                 ret = 0;
                 goto state_err;
---------------------------->cut<-------------------------------

--srini

> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 1b43d03c79ea..3319121cd706 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -1572,6 +1572,7 @@ int sdw_prepare_stream(struct sdw_stream_runtime *stream)
>   	sdw_acquire_bus_lock(stream);
>   
>   	if (stream->state == SDW_STREAM_PREPARED) {
> +		/* nothing to do */
>   		ret = 0;
>   		goto state_err;
>   	}
> @@ -1661,6 +1662,12 @@ int sdw_enable_stream(struct sdw_stream_runtime *stream)
>   
>   	sdw_acquire_bus_lock(stream);
>   
> +	if (stream->state == SDW_STREAM_ENABLED) {
> +		/* nothing to do */
> +		ret = 0;
> +		goto state_err;
> +	}
> +
>   	if (stream->state != SDW_STREAM_PREPARED &&
>   	    stream->state != SDW_STREAM_DISABLED) {
>   		pr_err("%s: %s: inconsistent state state %d\n",
> @@ -1744,6 +1751,12 @@ int sdw_disable_stream(struct sdw_stream_runtime *stream)
>   
>   	sdw_acquire_bus_lock(stream);
>   
> +	if (stream->state == SDW_STREAM_DISABLED) {
> +		/* nothing to do */
> +		ret = 0;
> +		goto state_err;
> +	}
> +
>   	if (stream->state != SDW_STREAM_ENABLED) {
>   		pr_err("%s: %s: inconsistent state state %d\n",
>   		       __func__, stream->name, stream->state);
> @@ -1809,6 +1822,12 @@ int sdw_deprepare_stream(struct sdw_stream_runtime *stream)
>   
>   	sdw_acquire_bus_lock(stream);
>   
> +	if (stream->state == SDW_STREAM_DEPREPARED) {
> +		/* nothing to do */
> +		ret = 0;
> +		goto state_err;
> +	}
> +
>   	if (stream->state != SDW_STREAM_PREPARED &&
>   	    stream->state != SDW_STREAM_DISABLED) {
>   		pr_err("%s: %s: inconsistent state state %d\n",
> 


More information about the Alsa-devel mailing list