linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: fsl-espi: master->mem_ops is implemented in the controller
@ 2018-08-17 10:07 Chuanhua Han
  2018-08-17 10:32 ` Boris Brezillon
  0 siblings, 1 reply; 2+ messages in thread
From: Chuanhua Han @ 2018-08-17 10:07 UTC (permalink / raw)
  To: broonie, boris.brezillon
  Cc: linux-spi, linux-kernel, cheetah0585, Chuanhua Han

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);
+	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);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] spi: fsl-espi: master->mem_ops is implemented in the controller
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Boris Brezillon @ 2018-08-17 10:32 UTC (permalink / raw)
  To: Chuanhua Han; +Cc: broonie, linux-spi, linux-kernel, cheetah0585

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);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-17 10:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).