All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] soundwire: stream: Fix test for DP prepare complete
@ 2021-06-18 14:47 ` Richard Fitzgerald
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2021-06-18 14:47 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: alsa-devel, linux-kernel, patches, Richard Fitzgerald

In sdw_prep_deprep_slave_ports(), after the wait_for_completion()
the DP prepare status register is read. If this indicates that the
port is now prepared, the code should continue with the port setup.
It is irrelevant whether the wait_for_completion() timed out if the
port is now ready.

The previous implementation would always fail if the
wait_for_completion() timed out, even if the port was reporting
successful prepare.

This patch also fixes a minor bug where the return from sdw_read()
was not checked for error - any error code with LSBits clear could
be misinterpreted as a successful port prepare.

Fixes: 79df15b7d37c ("soundwire: Add helpers for ports operations")
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/soundwire/stream.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 1eaedaaba094..1a18308f4ef4 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -422,7 +422,6 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
 	struct completion *port_ready;
 	struct sdw_dpn_prop *dpn_prop;
 	struct sdw_prepare_ch prep_ch;
-	unsigned int time_left;
 	bool intr = false;
 	int ret = 0, val;
 	u32 addr;
@@ -479,15 +478,15 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
 
 		/* Wait for completion on port ready */
 		port_ready = &s_rt->slave->port_ready[prep_ch.num];
-		time_left = wait_for_completion_timeout(port_ready,
-				msecs_to_jiffies(dpn_prop->ch_prep_timeout));
+		wait_for_completion_timeout(port_ready,
+			msecs_to_jiffies(dpn_prop->ch_prep_timeout));
 
 		val = sdw_read(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num));
-		val &= p_rt->ch_mask;
-		if (!time_left || val) {
+		if ((val < 0) || (val & p_rt->ch_mask)) {
+			ret = (val < 0) ? val : -ETIMEDOUT;
 			dev_err(&s_rt->slave->dev,
-				"Chn prep failed for port:%d\n", prep_ch.num);
-			return -ETIMEDOUT;
+				"Chn prep failed for port %d: %d\n", prep_ch.num, ret);
+			return ret;
 		}
 	}
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] soundwire: stream: Fix test for DP prepare complete
@ 2021-06-18 14:47 ` Richard Fitzgerald
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2021-06-18 14:47 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: patches, alsa-devel, Richard Fitzgerald, linux-kernel

In sdw_prep_deprep_slave_ports(), after the wait_for_completion()
the DP prepare status register is read. If this indicates that the
port is now prepared, the code should continue with the port setup.
It is irrelevant whether the wait_for_completion() timed out if the
port is now ready.

The previous implementation would always fail if the
wait_for_completion() timed out, even if the port was reporting
successful prepare.

This patch also fixes a minor bug where the return from sdw_read()
was not checked for error - any error code with LSBits clear could
be misinterpreted as a successful port prepare.

Fixes: 79df15b7d37c ("soundwire: Add helpers for ports operations")
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/soundwire/stream.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 1eaedaaba094..1a18308f4ef4 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -422,7 +422,6 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
 	struct completion *port_ready;
 	struct sdw_dpn_prop *dpn_prop;
 	struct sdw_prepare_ch prep_ch;
-	unsigned int time_left;
 	bool intr = false;
 	int ret = 0, val;
 	u32 addr;
@@ -479,15 +478,15 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
 
 		/* Wait for completion on port ready */
 		port_ready = &s_rt->slave->port_ready[prep_ch.num];
-		time_left = wait_for_completion_timeout(port_ready,
-				msecs_to_jiffies(dpn_prop->ch_prep_timeout));
+		wait_for_completion_timeout(port_ready,
+			msecs_to_jiffies(dpn_prop->ch_prep_timeout));
 
 		val = sdw_read(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num));
-		val &= p_rt->ch_mask;
-		if (!time_left || val) {
+		if ((val < 0) || (val & p_rt->ch_mask)) {
+			ret = (val < 0) ? val : -ETIMEDOUT;
 			dev_err(&s_rt->slave->dev,
-				"Chn prep failed for port:%d\n", prep_ch.num);
-			return -ETIMEDOUT;
+				"Chn prep failed for port %d: %d\n", prep_ch.num, ret);
+			return ret;
 		}
 	}
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] soundwire: stream: Fix test for DP prepare complete
  2021-06-18 14:47 ` Richard Fitzgerald
@ 2021-06-18 15:28   ` Pierre-Louis Bossart
  -1 siblings, 0 replies; 6+ messages in thread
From: Pierre-Louis Bossart @ 2021-06-18 15:28 UTC (permalink / raw)
  To: Richard Fitzgerald, vkoul, yung-chuan.liao, sanyog.r.kale
  Cc: alsa-devel, linux-kernel, patches



On 6/18/21 9:47 AM, Richard Fitzgerald wrote:
> In sdw_prep_deprep_slave_ports(), after the wait_for_completion()
> the DP prepare status register is read. If this indicates that the
> port is now prepared, the code should continue with the port setup.
> It is irrelevant whether the wait_for_completion() timed out if the
> port is now ready.
> 
> The previous implementation would always fail if the
> wait_for_completion() timed out, even if the port was reporting
> successful prepare.
> 
> This patch also fixes a minor bug where the return from sdw_read()
> was not checked for error - any error code with LSBits clear could
> be misinterpreted as a successful port prepare.
> 
> Fixes: 79df15b7d37c ("soundwire: Add helpers for ports operations")
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>

Looks good to me

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

> ---
>  drivers/soundwire/stream.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 1eaedaaba094..1a18308f4ef4 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -422,7 +422,6 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
>  	struct completion *port_ready;
>  	struct sdw_dpn_prop *dpn_prop;
>  	struct sdw_prepare_ch prep_ch;
> -	unsigned int time_left;
>  	bool intr = false;
>  	int ret = 0, val;
>  	u32 addr;
> @@ -479,15 +478,15 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
>  
>  		/* Wait for completion on port ready */
>  		port_ready = &s_rt->slave->port_ready[prep_ch.num];
> -		time_left = wait_for_completion_timeout(port_ready,
> -				msecs_to_jiffies(dpn_prop->ch_prep_timeout));
> +		wait_for_completion_timeout(port_ready,
> +			msecs_to_jiffies(dpn_prop->ch_prep_timeout));
>  
>  		val = sdw_read(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num));
> -		val &= p_rt->ch_mask;
> -		if (!time_left || val) {
> +		if ((val < 0) || (val & p_rt->ch_mask)) {
> +			ret = (val < 0) ? val : -ETIMEDOUT;
>  			dev_err(&s_rt->slave->dev,
> -				"Chn prep failed for port:%d\n", prep_ch.num);
> -			return -ETIMEDOUT;
> +				"Chn prep failed for port %d: %d\n", prep_ch.num, ret);
> +			return ret;
>  		}
>  	}
>  
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soundwire: stream: Fix test for DP prepare complete
@ 2021-06-18 15:28   ` Pierre-Louis Bossart
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre-Louis Bossart @ 2021-06-18 15:28 UTC (permalink / raw)
  To: Richard Fitzgerald, vkoul, yung-chuan.liao, sanyog.r.kale
  Cc: patches, alsa-devel, linux-kernel



On 6/18/21 9:47 AM, Richard Fitzgerald wrote:
> In sdw_prep_deprep_slave_ports(), after the wait_for_completion()
> the DP prepare status register is read. If this indicates that the
> port is now prepared, the code should continue with the port setup.
> It is irrelevant whether the wait_for_completion() timed out if the
> port is now ready.
> 
> The previous implementation would always fail if the
> wait_for_completion() timed out, even if the port was reporting
> successful prepare.
> 
> This patch also fixes a minor bug where the return from sdw_read()
> was not checked for error - any error code with LSBits clear could
> be misinterpreted as a successful port prepare.
> 
> Fixes: 79df15b7d37c ("soundwire: Add helpers for ports operations")
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>

Looks good to me

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

> ---
>  drivers/soundwire/stream.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 1eaedaaba094..1a18308f4ef4 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -422,7 +422,6 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
>  	struct completion *port_ready;
>  	struct sdw_dpn_prop *dpn_prop;
>  	struct sdw_prepare_ch prep_ch;
> -	unsigned int time_left;
>  	bool intr = false;
>  	int ret = 0, val;
>  	u32 addr;
> @@ -479,15 +478,15 @@ static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus,
>  
>  		/* Wait for completion on port ready */
>  		port_ready = &s_rt->slave->port_ready[prep_ch.num];
> -		time_left = wait_for_completion_timeout(port_ready,
> -				msecs_to_jiffies(dpn_prop->ch_prep_timeout));
> +		wait_for_completion_timeout(port_ready,
> +			msecs_to_jiffies(dpn_prop->ch_prep_timeout));
>  
>  		val = sdw_read(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num));
> -		val &= p_rt->ch_mask;
> -		if (!time_left || val) {
> +		if ((val < 0) || (val & p_rt->ch_mask)) {
> +			ret = (val < 0) ? val : -ETIMEDOUT;
>  			dev_err(&s_rt->slave->dev,
> -				"Chn prep failed for port:%d\n", prep_ch.num);
> -			return -ETIMEDOUT;
> +				"Chn prep failed for port %d: %d\n", prep_ch.num, ret);
> +			return ret;
>  		}
>  	}
>  
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soundwire: stream: Fix test for DP prepare complete
  2021-06-18 14:47 ` Richard Fitzgerald
@ 2021-06-20 11:17   ` Vinod Koul
  -1 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2021-06-20 11:17 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale, alsa-devel,
	linux-kernel, patches

On 18-06-21, 15:47, Richard Fitzgerald wrote:
> In sdw_prep_deprep_slave_ports(), after the wait_for_completion()
> the DP prepare status register is read. If this indicates that the
> port is now prepared, the code should continue with the port setup.
> It is irrelevant whether the wait_for_completion() timed out if the
> port is now ready.
> 
> The previous implementation would always fail if the
> wait_for_completion() timed out, even if the port was reporting
> successful prepare.
> 
> This patch also fixes a minor bug where the return from sdw_read()
> was not checked for error - any error code with LSBits clear could
> be misinterpreted as a successful port prepare.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soundwire: stream: Fix test for DP prepare complete
@ 2021-06-20 11:17   ` Vinod Koul
  0 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2021-06-20 11:17 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: alsa-devel, patches, pierre-louis.bossart, linux-kernel,
	sanyog.r.kale, yung-chuan.liao

On 18-06-21, 15:47, Richard Fitzgerald wrote:
> In sdw_prep_deprep_slave_ports(), after the wait_for_completion()
> the DP prepare status register is read. If this indicates that the
> port is now prepared, the code should continue with the port setup.
> It is irrelevant whether the wait_for_completion() timed out if the
> port is now ready.
> 
> The previous implementation would always fail if the
> wait_for_completion() timed out, even if the port was reporting
> successful prepare.
> 
> This patch also fixes a minor bug where the return from sdw_read()
> was not checked for error - any error code with LSBits clear could
> be misinterpreted as a successful port prepare.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-20 11:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 14:47 [PATCH] soundwire: stream: Fix test for DP prepare complete Richard Fitzgerald
2021-06-18 14:47 ` Richard Fitzgerald
2021-06-18 15:28 ` Pierre-Louis Bossart
2021-06-18 15:28   ` Pierre-Louis Bossart
2021-06-20 11:17 ` Vinod Koul
2021-06-20 11:17   ` Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.