diff mbox

[RFC] spi: core: Use master->max_speed_hz as transfer speed when xfer->speed_hz > master->max_speed_hz

Message ID 1395022092.30299.1.camel@phoenix (mailing list archive)
State Accepted
Commit a6f87fad7b5132f026592729ccf65b995cdec35d
Headers show

Commit Message

Axel Lin March 17, 2014, 2:08 a.m. UTC
When xfer->speed_hz is greater than master->max_speed_hz, it's generally safe
to use master->max_speed_hz as transfer speed.
Thus use master->max_speed_hz as transfer speed rather than return error when
xfer->speed_hz > master->max_speed_hz.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi Guenter,
Does this patch fix the issue you encounter?
Regards,
Axel
 drivers/spi/spi.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Guenter Roeck March 17, 2014, 2:21 a.m. UTC | #1
On 03/16/2014 07:08 PM, Axel Lin wrote:
> When xfer->speed_hz is greater than master->max_speed_hz, it's generally safe
> to use master->max_speed_hz as transfer speed.
> Thus use master->max_speed_hz as transfer speed rather than return error when
> xfer->speed_hz > master->max_speed_hz.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> Hi Guenter,
> Does this patch fix the issue you encounter?
> Regards,
> Axel

I'll test it and let you know.

Guenter

>   drivers/spi/spi.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 454a523..26b331d 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1844,12 +1844,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
>   		message->frame_length += xfer->len;
>   		if (!xfer->bits_per_word)
>   			xfer->bits_per_word = spi->bits_per_word;
> -		if (!xfer->speed_hz) {
> +
> +		if (!xfer->speed_hz)
>   			xfer->speed_hz = spi->max_speed_hz;
> -			if (master->max_speed_hz &&
> -			    xfer->speed_hz > master->max_speed_hz)
> -				xfer->speed_hz = master->max_speed_hz;
> -		}
> +
> +		if (master->max_speed_hz &&
> +		    xfer->speed_hz > master->max_speed_hz)
> +			xfer->speed_hz = master->max_speed_hz;
>
>   		if (master->bits_per_word_mask) {
>   			/* Only 32 bits fit in the mask */
> @@ -1878,9 +1879,6 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
>   		if (xfer->speed_hz && master->min_speed_hz &&
>   		    xfer->speed_hz < master->min_speed_hz)
>   			return -EINVAL;
> -		if (xfer->speed_hz && master->max_speed_hz &&
> -		    xfer->speed_hz > master->max_speed_hz)
> -			return -EINVAL;
>
>   		if (xfer->tx_buf && !xfer->tx_nbits)
>   			xfer->tx_nbits = SPI_NBITS_SINGLE;
>

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guenter Roeck March 17, 2014, 3:54 a.m. UTC | #2
On 03/16/2014 07:08 PM, Axel Lin wrote:
> When xfer->speed_hz is greater than master->max_speed_hz, it's generally safe
> to use master->max_speed_hz as transfer speed.
> Thus use master->max_speed_hz as transfer speed rather than return error when
> xfer->speed_hz > master->max_speed_hz.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Guenter

> ---
> Hi Guenter,
> Does this patch fix the issue you encounter?
> Regards,
> Axel
>   drivers/spi/spi.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 454a523..26b331d 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1844,12 +1844,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
>   		message->frame_length += xfer->len;
>   		if (!xfer->bits_per_word)
>   			xfer->bits_per_word = spi->bits_per_word;
> -		if (!xfer->speed_hz) {
> +
> +		if (!xfer->speed_hz)
>   			xfer->speed_hz = spi->max_speed_hz;
> -			if (master->max_speed_hz &&
> -			    xfer->speed_hz > master->max_speed_hz)
> -				xfer->speed_hz = master->max_speed_hz;
> -		}
> +
> +		if (master->max_speed_hz &&
> +		    xfer->speed_hz > master->max_speed_hz)
> +			xfer->speed_hz = master->max_speed_hz;
>
>   		if (master->bits_per_word_mask) {
>   			/* Only 32 bits fit in the mask */
> @@ -1878,9 +1879,6 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
>   		if (xfer->speed_hz && master->min_speed_hz &&
>   		    xfer->speed_hz < master->min_speed_hz)
>   			return -EINVAL;
> -		if (xfer->speed_hz && master->max_speed_hz &&
> -		    xfer->speed_hz > master->max_speed_hz)
> -			return -EINVAL;
>
>   		if (xfer->tx_buf && !xfer->tx_nbits)
>   			xfer->tx_nbits = SPI_NBITS_SINGLE;
>

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mark Brown March 17, 2014, 3:46 p.m. UTC | #3
On Mon, Mar 17, 2014 at 10:08:12AM +0800, Axel Lin wrote:
> When xfer->speed_hz is greater than master->max_speed_hz, it's generally safe
> to use master->max_speed_hz as transfer speed.
> Thus use master->max_speed_hz as transfer speed rather than return error when
> xfer->speed_hz > master->max_speed_hz.

Applied, thanks.
diff mbox

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 454a523..26b331d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1844,12 +1844,13 @@  static int __spi_validate(struct spi_device *spi, struct spi_message *message)
 		message->frame_length += xfer->len;
 		if (!xfer->bits_per_word)
 			xfer->bits_per_word = spi->bits_per_word;
-		if (!xfer->speed_hz) {
+
+		if (!xfer->speed_hz)
 			xfer->speed_hz = spi->max_speed_hz;
-			if (master->max_speed_hz &&
-			    xfer->speed_hz > master->max_speed_hz)
-				xfer->speed_hz = master->max_speed_hz;
-		}
+
+		if (master->max_speed_hz &&
+		    xfer->speed_hz > master->max_speed_hz)
+			xfer->speed_hz = master->max_speed_hz;
 
 		if (master->bits_per_word_mask) {
 			/* Only 32 bits fit in the mask */
@@ -1878,9 +1879,6 @@  static int __spi_validate(struct spi_device *spi, struct spi_message *message)
 		if (xfer->speed_hz && master->min_speed_hz &&
 		    xfer->speed_hz < master->min_speed_hz)
 			return -EINVAL;
-		if (xfer->speed_hz && master->max_speed_hz &&
-		    xfer->speed_hz > master->max_speed_hz)
-			return -EINVAL;
 
 		if (xfer->tx_buf && !xfer->tx_nbits)
 			xfer->tx_nbits = SPI_NBITS_SINGLE;