linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: mux: repair mux usage
@ 2020-05-25 10:43 Peter Rosin
  2020-05-25 14:57 ` Mark Brown
  2020-05-25 21:13 ` Chris Packham
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Rosin @ 2020-05-25 10:43 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Rosin, Mark Brown, Chris Packham, Andy Shevchenko,
	linux-spi, Matthew Wilcox, Geert Uytterhoeven

It is not valid to cache/short out selection of the mux.

mux_control_select() only locks the mux until mux_control_deselect()
is called. mux_control_deselect() may put the mux in some low power
state or some other user of the mux might select it for other purposes.
These things are probably not happening in the original setting where
this driver was developed, but it is said to be a generic SPI mux.

Also, the mux framework will short out the actual low level muxing
operation when/if that is possible.

Fixes: e9e40543ad5b ("spi: Add generic SPI multiplexer")
Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/spi/spi-mux.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-mux.c b/drivers/spi/spi-mux.c
index 4f94c9127fc1..cc9ef371db14 100644
--- a/drivers/spi/spi-mux.c
+++ b/drivers/spi/spi-mux.c
@@ -51,6 +51,10 @@ static int spi_mux_select(struct spi_device *spi)
 	struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller);
 	int ret;
 
+	ret = mux_control_select(priv->mux, spi->chip_select);
+	if (ret)
+		return ret;
+
 	if (priv->current_cs == spi->chip_select)
 		return 0;
 
@@ -62,10 +66,6 @@ static int spi_mux_select(struct spi_device *spi)
 	priv->spi->mode = spi->mode;
 	priv->spi->bits_per_word = spi->bits_per_word;
 
-	ret = mux_control_select(priv->mux, spi->chip_select);
-	if (ret)
-		return ret;
-
 	priv->current_cs = spi->chip_select;
 
 	return 0;
-- 
2.20.1


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

* Re: [PATCH] spi: mux: repair mux usage
  2020-05-25 10:43 [PATCH] spi: mux: repair mux usage Peter Rosin
@ 2020-05-25 14:57 ` Mark Brown
  2020-05-25 21:13 ` Chris Packham
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2020-05-25 14:57 UTC (permalink / raw)
  To: linux-kernel, Peter Rosin
  Cc: Geert Uytterhoeven, Chris Packham, linux-spi, Matthew Wilcox,
	Andy Shevchenko

On Mon, 25 May 2020 12:43:52 +0200, Peter Rosin wrote:
> It is not valid to cache/short out selection of the mux.
> 
> mux_control_select() only locks the mux until mux_control_deselect()
> is called. mux_control_deselect() may put the mux in some low power
> state or some other user of the mux might select it for other purposes.
> These things are probably not happening in the original setting where
> this driver was developed, but it is said to be a generic SPI mux.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: mux: repair mux usage
      commit: a2b02e4623fb127fa65a13e4ac5aa56e4ae16291

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

* Re: [PATCH] spi: mux: repair mux usage
  2020-05-25 10:43 [PATCH] spi: mux: repair mux usage Peter Rosin
  2020-05-25 14:57 ` Mark Brown
@ 2020-05-25 21:13 ` Chris Packham
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Packham @ 2020-05-25 21:13 UTC (permalink / raw)
  To: Peter Rosin, linux-kernel
  Cc: Mark Brown, Andy Shevchenko, linux-spi, Matthew Wilcox,
	Geert Uytterhoeven


On 25/05/20 10:43 pm, Peter Rosin wrote:
> It is not valid to cache/short out selection of the mux.
>
> mux_control_select() only locks the mux until mux_control_deselect()
> is called. mux_control_deselect() may put the mux in some low power
> state or some other user of the mux might select it for other purposes.
> These things are probably not happening in the original setting where
> this driver was developed, but it is said to be a generic SPI mux.
>
> Also, the mux framework will short out the actual low level muxing
> operation when/if that is possible.
>
> Fixes: e9e40543ad5b ("spi: Add generic SPI multiplexer")
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>   drivers/spi/spi-mux.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/spi/spi-mux.c b/drivers/spi/spi-mux.c
> index 4f94c9127fc1..cc9ef371db14 100644
> --- a/drivers/spi/spi-mux.c
> +++ b/drivers/spi/spi-mux.c
> @@ -51,6 +51,10 @@ static int spi_mux_select(struct spi_device *spi)
>   	struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller);
>   	int ret;
>   
> +	ret = mux_control_select(priv->mux, spi->chip_select);
> +	if (ret)
> +		return ret;
> +
>   	if (priv->current_cs == spi->chip_select)
>   		return 0;
>   
> @@ -62,10 +66,6 @@ static int spi_mux_select(struct spi_device *spi)
>   	priv->spi->mode = spi->mode;
>   	priv->spi->bits_per_word = spi->bits_per_word;
>   
> -	ret = mux_control_select(priv->mux, spi->chip_select);
> -	if (ret)
> -		return ret;
> -
>   	priv->current_cs = spi->chip_select;
>   
>   	return 0;


I've tested this on the 2 hardware platforms I have with the multiplexed 
CS and both work fine with this change so

Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

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

end of thread, other threads:[~2020-05-25 21:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-25 10:43 [PATCH] spi: mux: repair mux usage Peter Rosin
2020-05-25 14:57 ` Mark Brown
2020-05-25 21:13 ` Chris Packham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).