Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Chuanhua Han <chuanhua.han@nxp.com>
Cc: broonie@kernel.org, linux-spi@vger.kernel.org,
	linux-kernel@vger.kernel.org, cheetah0585@163.com
Subject: Re: [PATCH] spi: fsl-espi: master->mem_ops is implemented in the controller
Date: Fri, 17 Aug 2018 12:32:35 +0200	[thread overview]
Message-ID: <20180817123235.08b33825@bbrezillon> (raw)
In-Reply-To: <1534500425-9977-1-git-send-email-chuanhua.han@nxp.com>

On Fri, 17 Aug 2018 18:07:05 +0800
Chuanhua Han <chuanhua.han@nxp.com> wrote:

> The length of the transmitted data needs to be adjusted due to the maximum 
> length limit for espi transmission messages
> 
> Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
> ---
>  drivers/spi/spi-fsl-espi.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
> index 1d332e2..4724127 100644
> --- a/drivers/spi/spi-fsl-espi.c
> +++ b/drivers/spi/spi-fsl-espi.c
> @@ -22,6 +22,7 @@
>  #include <linux/spi/spi.h>
>  #include <linux/pm_runtime.h>
>  #include <sysdev/fsl_soc.h>
> +#include <linux/spi/spi-mem.h>
>  
>  /* eSPI Controller registers */
>  #define ESPI_SPMODE	0x00	/* eSPI mode register */
> @@ -659,6 +660,29 @@ static void fsl_espi_init_regs(struct device *dev, bool initial)
>  	fsl_espi_write_reg(espi, ESPI_SPMODE, SPMODE_INIT_VAL | SPMODE_ENABLE);
>  }
>  
> +static int fsl_espi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
> +{
> +	if (!mem || !op)
> +		return -EINVAL;
> +	op->data.nbytes = min3((unsigned long)op->data.nbytes,
> +			spi_max_transfer_size(mem->spi),
> +			spi_max_message_size(mem->spi) -
> +			sizeof(op->cmd.opcode) -
> +			op->addr.nbytes -
> +			op->dummy.nbytes);

Oops! Looks like I was wrong in my initial review, this code is generic
and should be placed in spi_mem_adjust_op_size() if !ctlr->mem_ops
or !ctlr->mem_ops->exec_op:

int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
{
	struct spi_controller *ctlr = mem->spi->controller;

	if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
		return ctlr->mem_ops->adjust_op_size(mem, op);

	if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op)
		op->data.nbytes = min3((unsigned long)op->data.nbytes,
				       spi_max_transfer_size(mem->spi),
				       spi_max_message_size(mem->spi) -
				       sizeof(op->cmd.opcode) -
				       op->addr.nbytes -
				       op->dummy.nbytes);

	return 0;
}

Also, you don't seem to check spi_max_message_size(mem->spi) value
before subtracting opcode, addr and dummy bytes.


> +	return 0;
> +}
> +
> +static int fsl_espi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
> +{
> +	return -ENOTSUPP;
> +}
> +
> +static const struct spi_controller_mem_ops fsl_espi_mem_ops = {
> +	.adjust_op_size = fsl_espi_adjust_op_size,
> +	.exec_op = fsl_espi_exec_op,
> +};
> +
>  static int fsl_espi_probe(struct device *dev, struct resource *mem,
>  			  unsigned int irq, unsigned int num_cs)
>  {
> @@ -682,6 +706,7 @@ static int fsl_espi_probe(struct device *dev, struct resource *mem,
>  	master->auto_runtime_pm = true;
>  	master->max_message_size = fsl_espi_max_message_size;
>  	master->num_chipselect = num_cs;
> +	master->mem_ops = &fsl_espi_mem_ops;
>  
>  	espi = spi_master_get_devdata(master);
>  	spin_lock_init(&espi->lock);

      reply	other threads:[~2018-08-17 10:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-17 10:07 [PATCH] spi: fsl-espi: master->mem_ops is implemented in the controller Chuanhua Han
2018-08-17 10:32 ` Boris Brezillon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180817123235.08b33825@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=broonie@kernel.org \
    --cc=cheetah0585@163.com \
    --cc=chuanhua.han@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox