[4/6] soundwire: stream: do not update parameters during DISABLED-PREPARED transition
diff mbox series

Message ID 20200108175438.13121-5-pierre-louis.bossart@linux.intel.com
State New
Headers show
Series
  • soundwire: stream: fix state machines and transitions
Related show

Commit Message

Pierre-Louis Bossart Jan. 8, 2020, 5:54 p.m. UTC
After a system suspend, the ALSA/ASoC core will invoke the .prepare()
callback and a TRIGGER_START when INFO_RESUME is not supported.

Likewise, when an underflow occurs, the .prepare callback will be invoked.

In both cases, the stream can be in DISABLED mode, and will transition
into the PREPARED mode. We however don't want the bus bandwidth to be
recomputed.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 drivers/soundwire/stream.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Vinod Koul Jan. 10, 2020, 6:55 a.m. UTC | #1
On 08-01-20, 11:54, Pierre-Louis Bossart wrote:
> After a system suspend, the ALSA/ASoC core will invoke the .prepare()
> callback and a TRIGGER_START when INFO_RESUME is not supported.
> 
> Likewise, when an underflow occurs, the .prepare callback will be invoked.
> 
> In both cases, the stream can be in DISABLED mode, and will transition
> into the PREPARED mode. We however don't want the bus bandwidth to be
> recomputed.
> 
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
>  drivers/soundwire/stream.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index bd0bddf73830..c28ce7f0d742 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -1460,7 +1460,8 @@ static void sdw_release_bus_lock(struct sdw_stream_runtime *stream)
>  	}
>  }
>  
> -static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
> +static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
> +			       bool update_params)
>  {
>  	struct sdw_master_runtime *m_rt;
>  	struct sdw_bus *bus = NULL;
> @@ -1480,6 +1481,9 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
>  			return -EINVAL;
>  		}
>  
> +		if (!update_params)
> +			goto program_params;
> +
>  		/* Increment cumulative bus bandwidth */
>  		/* TODO: Update this during Device-Device support */
>  		bus->params.bandwidth += m_rt->stream->params.rate *
> @@ -1495,6 +1499,7 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
>  			}
>  		}
>  
> +program_params:
>  		/* Program params */
>  		ret = sdw_program_params(bus);
>  		if (ret < 0) {
> @@ -1544,6 +1549,7 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
>   */
>  int sdw_prepare_stream(struct sdw_stream_runtime *stream)
>  {
> +	bool update_params = true;
>  	int ret;
>  
>  	if (!stream) {
> @@ -1567,7 +1573,16 @@ int sdw_prepare_stream(struct sdw_stream_runtime *stream)
>  		goto state_err;
>  	}
>  
> -	ret = _sdw_prepare_stream(stream);
> +	/*
> +	 * when the stream is DISABLED, this means sdw_prepare_stream()
> +	 * is called as a result of an underflow or a resume operation.
> +	 * In this case, the bus parameters shall not be recomputed, but
> +	 * still need to be re-applied
> +	 */
> +	if (stream->state == SDW_STREAM_DISABLED)
> +		update_params = false;

Should this not be handled by the caller..? I do not like to deduce this
here as the info is already available in dai driver, so go ahead and
propagate it and get it from caller when it is required..
Pierre-Louis Bossart Jan. 10, 2020, 4:11 p.m. UTC | #2
>> +	/*
>> +	 * when the stream is DISABLED, this means sdw_prepare_stream()
>> +	 * is called as a result of an underflow or a resume operation.
>> +	 * In this case, the bus parameters shall not be recomputed, but
>> +	 * still need to be re-applied
>> +	 */
>> +	if (stream->state == SDW_STREAM_DISABLED)
>> +		update_params = false;
> 
> Should this not be handled by the caller..? I do not like to deduce this
> here as the info is already available in dai driver, so go ahead and
> propagate it and get it from caller when it is required..

No, this update_params boolean is used later on to modify the bandwidth 
computation. These values are not accessible to the caller (and should 
absolutely be kept private/opaque).

Patch
diff mbox series

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index bd0bddf73830..c28ce7f0d742 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1460,7 +1460,8 @@  static void sdw_release_bus_lock(struct sdw_stream_runtime *stream)
 	}
 }
 
-static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
+static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
+			       bool update_params)
 {
 	struct sdw_master_runtime *m_rt;
 	struct sdw_bus *bus = NULL;
@@ -1480,6 +1481,9 @@  static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
 			return -EINVAL;
 		}
 
+		if (!update_params)
+			goto program_params;
+
 		/* Increment cumulative bus bandwidth */
 		/* TODO: Update this during Device-Device support */
 		bus->params.bandwidth += m_rt->stream->params.rate *
@@ -1495,6 +1499,7 @@  static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
 			}
 		}
 
+program_params:
 		/* Program params */
 		ret = sdw_program_params(bus);
 		if (ret < 0) {
@@ -1544,6 +1549,7 @@  static int _sdw_prepare_stream(struct sdw_stream_runtime *stream)
  */
 int sdw_prepare_stream(struct sdw_stream_runtime *stream)
 {
+	bool update_params = true;
 	int ret;
 
 	if (!stream) {
@@ -1567,7 +1573,16 @@  int sdw_prepare_stream(struct sdw_stream_runtime *stream)
 		goto state_err;
 	}
 
-	ret = _sdw_prepare_stream(stream);
+	/*
+	 * when the stream is DISABLED, this means sdw_prepare_stream()
+	 * is called as a result of an underflow or a resume operation.
+	 * In this case, the bus parameters shall not be recomputed, but
+	 * still need to be re-applied
+	 */
+	if (stream->state == SDW_STREAM_DISABLED)
+		update_params = false;
+
+	ret = _sdw_prepare_stream(stream, update_params);
 
 state_err:
 	sdw_release_bus_lock(stream);