[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1jlefm6h8g.fsf@starbuckisacylon.baylibre.com>
Date: Tue, 11 Jul 2023 09:25:31 +0200
From: Jerome Brunet <jbrunet@...libre.com>
To: Martin Kurbanov <mmkurbanov@...rdevices.ru>,
Mark Brown <broonie@...nel.org>,
Neil Armstrong <neil.armstrong@...aro.org>,
Andy Shevchenko <andy.shevchenko@...il.com>
Cc: linux-spi@...r.kernel.org, linux-amlogic@...ts.infradead.org,
linux-kernel@...r.kernel.org, kernel@...rdevices.ru
Subject: Re: [PATCH v2 2/2] spi: amlogic-spifc-a1: add support for max_speed_hz
On Thu 06 Jul 2023 at 14:03, Martin Kurbanov <mmkurbanov@...rdevices.ru> wrote:
> This patch sets the clock rate (spi_transfer->max_speed_hz) from the
> amlogic_spifc_a1_exec_op().
>
> Signed-off-by: Martin Kurbanov <mmkurbanov@...rdevices.ru>
> ---
> drivers/spi/spi-amlogic-spifc-a1.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/spi/spi-amlogic-spifc-a1.c b/drivers/spi/spi-amlogic-spifc-a1.c
> index a92e4fc23396..605e9e40455c 100644
> --- a/drivers/spi/spi-amlogic-spifc-a1.c
> +++ b/drivers/spi/spi-amlogic-spifc-a1.c
> @@ -107,6 +107,7 @@ struct amlogic_spifc_a1 {
> struct clk *clk;
> struct device *dev;
> void __iomem *base;
> + u32 curr_speed_hz;
> };
>
> static int amlogic_spifc_a1_request(struct amlogic_spifc_a1 *spifc, bool read)
> @@ -235,6 +236,21 @@ static int amlogic_spifc_a1_write(struct amlogic_spifc_a1 *spifc,
> return amlogic_spifc_a1_request(spifc, false);
> }
>
> +static int amlogic_spifc_a1_set_freq(struct amlogic_spifc_a1 *spifc, u32 freq)
> +{
> + int ret;
> +
> + if (freq == spifc->curr_speed_hz)
> + return 0;
> +
> + ret = clk_set_rate(spifc->clk, freq);
> + if (ret)
> + return ret;
> +
> + spifc->curr_speed_hz = freq;
There is no guarantee that clk_set_rate() has set the rate you have
requested, at least not precisely. You should call clk_get_rate() here.
> + return 0;
> +}
> +
> static int amlogic_spifc_a1_exec_op(struct spi_mem *mem,
> const struct spi_mem_op *op)
> {
> @@ -243,6 +259,10 @@ static int amlogic_spifc_a1_exec_op(struct spi_mem *mem,
> size_t data_size = op->data.nbytes;
> int ret;
>
> + ret = amlogic_spifc_a1_set_freq(spifc, mem->spi->max_speed_hz);
> + if (ret)
> + return ret;
> +
> amlogic_spifc_a1_user_init(spifc);
> amlogic_spifc_a1_set_cmd(spifc, SPIFC_A1_USER_CMD(op));
Powered by blists - more mailing lists