2020-12-09 23:50:20

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH] spi: Limit the spi device max speed to controller's max speed

Hello Tudor,

On Wed, Dec 09, 2020 at 07:35:14PM +0200, Tudor Ambarus wrote:
> Make sure the max_speed_hz of spi_device does not override
> the max_speed_hz of controller.

I have doubts that's right thing to do. It seems better to let
the controller driver to handle the speed clamping itself, while
to leave the SPI client device max_speed_hz field describing the
device speed capability. Moreover the SPI-transfers passed to the
controller will have a SPI-bus speed fixed in accordance with the
controller and client device capabilities anyway.
See the __spi_validate() method for details:
https://elixir.bootlin.com/linux/v5.10-rc7/source/drivers/spi/spi.c#L3570

-Sergey

>
> Signed-off-by: Tudor Ambarus <[email protected]>
> ---
> drivers/spi/spi.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index cd3c395b4e90..51d7c004fbab 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -3378,7 +3378,8 @@ int spi_setup(struct spi_device *spi)
> if (status)
> return status;
>
> - if (!spi->max_speed_hz)
> + if (!spi->max_speed_hz ||
> + spi->max_speed_hz > spi->controller->max_speed_hz)
> spi->max_speed_hz = spi->controller->max_speed_hz;
>
> mutex_lock(&spi->controller->io_mutex);
> --
> 2.25.1
>