[PATCH 01/24] spi: spi-mem: Extend spi-mem operations with a per-operation maximum frequency
Tudor Ambarus
tudor.ambarus at linaro.org
Mon Nov 11 05:07:09 PST 2024
On 10/25/24 5:14 PM, Miquel Raynal wrote:
cut
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 17b8baf749e6..ab650ae953bb 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -356,6 +356,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
> {
> unsigned int tmpbufsize, xferpos = 0, totalxferlen = 0;
> struct spi_controller *ctlr = mem->spi->controller;
> + unsigned int xfer_speed = op->max_freq;
be aware that for controllers that don't support SPIMEM ops, you pass
the frequency from the upper layers, without adjusting it with
spi->max_speed_hz. Was this intentional?
> struct spi_transfer xfers[4] = { };
> struct spi_message msg;
> u8 *tmpbuf;
> @@ -368,6 +369,9 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
> if (!spi_mem_internal_supports_op(mem, op))
> return -EOPNOTSUPP;
>
> + if (!op->max_freq || op->max_freq > mem->spi->max_speed_hz)
> + ((struct spi_mem_op *)op)->max_freq = mem->spi->max_speed_hz;
not a big fan of casting the const out. How about introducing a
spi_mem_adjust_op_freq()? The upper layers will use that were needed,
and you'll still be able to pass a const op to spi_mem_exec_op()
cut
> diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h
> index f866d5c8ed32..8963f236911b 100644
> --- a/include/linux/spi/spi-mem.h
> +++ b/include/linux/spi/spi-mem.h
> @@ -68,6 +68,9 @@ enum spi_mem_data_dir {
> SPI_MEM_DATA_OUT,
> };
>
> +#define SPI_MEM_OP_MAX_FREQ(__freq) \
> + .max_freq = __freq
> +
> /**
> * struct spi_mem_op - describes a SPI memory operation
> * @cmd.nbytes: number of opcode bytes (only 1 or 2 are valid). The opcode is
> @@ -95,6 +98,9 @@ enum spi_mem_data_dir {
> * operation does not involve transferring data
> * @data.buf.in: input buffer (must be DMA-able)
> * @data.buf.out: output buffer (must be DMA-able)
> + * @max_freq: frequency limitation wrt this operation. 0 means there is no
> + * specific constraint and the highest achievable frequency can be
> + * attempted).
nit: you close a parenthesis without opening one
Looking good,
ta
More information about the linux-mtd
mailing list