All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Boris Brezillon <boris.brezillon@collabora.com>
Cc: linux-mtd@lists.infradead.org,
	Tudor Ambarus <tudor.ambarus@microchip.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Richard Weinberger <richard@nod.at>
Subject: Re: [PATCH 13/17] mtd: rawnand: cafe: Add exec_op() support
Date: Mon, 27 Apr 2020 21:59:33 +0200	[thread overview]
Message-ID: <20200427215933.13fb1bbc@xps13> (raw)
In-Reply-To: <20200427082028.394719-14-boris.brezillon@collabora.com>

Hi Boris,

Boris Brezillon <boris.brezillon@collabora.com> wrote on Mon, 27 Apr
2020 10:20:23 +0200:

> Implementing exec_op() will help us get rid of the legacy interface and
> should make drivers much cleaner too.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
>  drivers/mtd/nand/raw/cafe_nand.c | 137 ++++++++++++++++++++++++++++++-
>  1 file changed, 136 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/cafe_nand.c b/drivers/mtd/nand/raw/cafe_nand.c
> index edf65197604b..ada9c8b06a41 100644
> --- a/drivers/mtd/nand/raw/cafe_nand.c
> +++ b/drivers/mtd/nand/raw/cafe_nand.c
> @@ -21,7 +21,7 @@
>  #include <linux/dma-mapping.h>
>  #include <linux/slab.h>
>  #include <linux/module.h>
> -#include <linux/io.h>
> +#include <linux/iopoll.h>
>  
>  #define CAFE_NAND_CTRL1				0x00
>  #define CAFE_NAND_CTRL1_HAS_CMD			BIT(31)
> @@ -774,9 +774,144 @@ static void cafe_nand_detach_chip(struct nand_chip *chip)
>  	dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
>  }
>  
> +static int cafe_nand_exec_subop(struct nand_chip *chip,
> +				const struct nand_subop *subop)
> +{
> +	struct cafe_priv *cafe = nand_get_controller_data(chip);
> +	u32 ctrl1 = 0, ctrl2 = cafe->ctl2, addr1 = 0, addr2 = 0;
> +	const struct nand_op_instr *data_instr = NULL;
> +	u32 status, wait = CAFE_NAND_IRQ_CMD_DONE;
> +	bool waitrdy = false;
> +	unsigned int i, j;
> +	int ret;
> +
> +	if (WARN_ON(subop->cs > 1))
> +		return -EINVAL;
> +
> +	cafe->datalen = 0;
> +	ctrl1 |= CAFE_FIELD_PREP(NAND_CTRL1, CE, subop->cs);
> +
> +	for (i = 0; i < subop->ninstrs; i++) {
> +		const struct nand_op_instr *instr = &subop->instrs[i];
> +
> +		switch (instr->type) {
> +		case NAND_OP_CMD_INSTR:
> +			if (WARN_ON((ctrl1 & CAFE_NAND_CTRL1_HAS_CMD) &&
> +				    (ctrl2 & CAFE_NAND_CTRL2_HAS_CMD2)))
> +				return -EINVAL;

Same comment as in the previous drivers, just showing it to do not
foget.

> +
> +			if (!(ctrl1 & CAFE_NAND_CTRL1_HAS_CMD))
> +				ctrl1 |= CAFE_NAND_CTRL1_HAS_CMD |
> +					 CAFE_FIELD_PREP(NAND_CTRL1, CMD,
> +							 instr->ctx.cmd.opcode);
> +			else
> +				ctrl2 |= CAFE_NAND_CTRL2_HAS_CMD2 |
> +					 CAFE_FIELD_PREP(NAND_CTRL2, CMD2,
> +							 instr->ctx.cmd.opcode);
> +			break;
> +
> +		case NAND_OP_ADDR_INSTR:
> +			if (WARN_ON(instr->ctx.addr.naddrs > 5 ||
> +				    !instr->ctx.addr.naddrs))
> +				return -EINVAL;
> +
> +			for (j = 0; j < instr->ctx.addr.naddrs; j++) {
> +				u32 addr = instr->ctx.addr.addrs[j];
> +
> +				if (j < 2)
> +					addr1 |= addr << (8 * j);
> +				else
> +					addr2 |= addr << (8 * (j - 2));
> +			}
> +
> +			ctrl1 |= CAFE_NAND_CTRL1_HAS_ADDR |
> +				 CAFE_FIELD_PREP(NAND_CTRL1, NUM_ADDR_CYC,
> +						 instr->ctx.addr.naddrs - 1);
> +			cafe_writel(cafe, addr1, NAND_ADDR1);
> +			if (instr->ctx.addr.naddrs > 2)
> +				cafe_writel(cafe, addr2, NAND_ADDR2);

Maybe it is safer to always write this register, no? I don't know if
the IP clears registers between operations. If it does not, you might
end up sending extra command cycles.

> +			break;
> +
> +		case NAND_OP_DATA_IN_INSTR:
> +			data_instr = instr;
> +			ctrl1 |= CAFE_NAND_CTRL1_HAS_DATA_IN;
> +			break;
> +
> +		case NAND_OP_DATA_OUT_INSTR:
> +			data_instr = instr;
> +			ctrl1 |= CAFE_NAND_CTRL1_HAS_DATA_OUT;
> +			cafe_write_buf(chip, instr->ctx.data.buf.out,
> +				       instr->ctx.data.len);
> +			break;
> +
> +		case NAND_OP_WAITRDY_INSTR:
> +			wait |= CAFE_NAND_IRQ_FLASH_RDY;
> +			waitrdy = true;
> +			break;
> +		}
> +	}
> +
> +	if (data_instr)
> +		cafe_writel(cafe, data_instr->ctx.data.len, NAND_DATA_LEN);
> +
> +	if (cafe->usedma && data_instr) {
> +		u32 dmactrl = CAFE_NAND_DMA_CTRL_ENABLE |
> +			      CAFE_NAND_DMA_CTRL_RESERVED;
> +
> +		wait |= CAFE_NAND_IRQ_DMA_DONE;
> +		dmactrl |= CAFE_FIELD_PREP(NAND_DMA_CTRL, DATA_LEN,
> +					   data_instr->ctx.data.len);
> +		if (ctrl1 & CAFE_NAND_CTRL1_HAS_DATA_IN)
> +			dmactrl |= CAFE_NAND_DMA_CTRL_DATA_IN;
> +
> +		cafe_writel(cafe, dmactrl, NAND_DMA_CTRL);
> +	}
> +
> +	/* Clear the pending interrupts before starting the operation. */
> +	cafe_writel(cafe, wait, NAND_IRQ);
> +
> +	cafe_writel(cafe, ctrl2, NAND_CTRL2);
> +	cafe_writel(cafe, ctrl1, NAND_CTRL1);
> +
> +	ret = readl_poll_timeout(cafe->mmio + CAFE_NAND_IRQ, status,
> +				 (status & wait) == wait, 1, USEC_PER_SEC);
> +	if (ret)
> +		return ret;
> +
> +	if (ctrl1 & CAFE_NAND_DMA_CTRL_DATA_IN)
> +		cafe_read_buf(chip, data_instr->ctx.data.buf.in,
> +			      data_instr->ctx.data.len);

As you are limiting the amount of data to 2112B and the number of
address cycles to 5, you should probably use the core's helper
nand_subop_data_len, nand_subob_data_buf and nand_subop_addr_len in
this function.

> +
> +	return 0;
> +}
> +
> +static const struct nand_op_parser cafe_nand_op_parser = NAND_OP_PARSER(
> +	NAND_OP_PARSER_PATTERN(cafe_nand_exec_subop,
> +			       NAND_OP_PARSER_PAT_CMD_ELEM(true),
> +			       NAND_OP_PARSER_PAT_ADDR_ELEM(true, 5),
> +			       NAND_OP_PARSER_PAT_CMD_ELEM(true),
> +			       NAND_OP_PARSER_PAT_WAITRDY_ELEM(true),
> +			       NAND_OP_PARSER_PAT_DATA_IN_ELEM(true, 2112)),
> +	NAND_OP_PARSER_PATTERN(cafe_nand_exec_subop,
> +			       NAND_OP_PARSER_PAT_CMD_ELEM(true),
> +			       NAND_OP_PARSER_PAT_ADDR_ELEM(true, 5),
> +			       NAND_OP_PARSER_PAT_CMD_ELEM(true),
> +			       NAND_OP_PARSER_PAT_DATA_IN_ELEM(true, 2112),
> +			       NAND_OP_PARSER_PAT_WAITRDY_ELEM(true))
> +);
> +
> +static int cafe_nand_exec_op(struct nand_chip *chip,
> +			     const struct nand_operation *op,
> +			     bool check_only)
> +{

I didn't check but are you sure there is no chip-select/timings
handling to do here?

> +	return nand_op_parser_exec_op(chip, &cafe_nand_op_parser, op,
> +				      check_only);
> +}
> +
>  static const struct nand_controller_ops cafe_nand_controller_ops = {
>  	.attach_chip = cafe_nand_attach_chip,
>  	.detach_chip = cafe_nand_detach_chip,
> +	.exec_op = cafe_nand_exec_op,
>  };
>  
>  static void cafe_nand_init(struct cafe_priv *cafe)

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2020-04-27 19:59 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27  8:20 [PATCH 00/17] mtd: rawnand: cafe: Convert to exec_op() (and more) Boris Brezillon
2020-04-27  8:20 ` [PATCH 01/17] mtd: rawnand: cafe: Get rid of an inaccurate kernel doc header Boris Brezillon
2020-04-27 19:33   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 02/17] mtd: rawnand: cafe: Rename cafe_nand_write_page_lowlevel() Boris Brezillon
2020-04-27 19:33   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 03/17] mtd: rawnand: cafe: Use a correct ECC mode and pass the ECC alg Boris Brezillon
2020-04-27 19:34   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 04/17] mtd: rawnand: cafe: Include linux/io.h instead of asm/io.h Boris Brezillon
2020-04-27 19:35   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 05/17] mtd: rawnand: cafe: Demistify register fields Boris Brezillon
2020-04-27 19:42   ` Miquel Raynal
2020-04-28  6:06     ` Boris Brezillon
2020-04-27  8:20 ` [PATCH 06/17] mtd: rawnand: cafe: Factor out the controller initialization logic Boris Brezillon
2020-04-27 19:45   ` Miquel Raynal
2020-04-28  6:06     ` Boris Brezillon
2020-04-27  8:20 ` [PATCH 07/17] mtd: rawnand: cafe: Get rid of the debug module param Boris Brezillon
2020-04-27 19:46   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 08/17] mtd: rawnand: cafe: Use devm_kzalloc and devm_request_irq() Boris Brezillon
2020-04-27 19:47   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 09/17] mtd: rawnand: cafe: Get rid of a useless label Boris Brezillon
2020-04-27 19:47   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 10/17] mtd: rawnand: cafe: Explicitly inherit from nand_controller Boris Brezillon
2020-04-27 19:49   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 11/17] mtd: rawnand: cafe: Don't leave ECC enabled in the write path Boris Brezillon
2020-04-27 19:51   ` Miquel Raynal
2020-04-28  6:08     ` Boris Brezillon
2020-04-27  8:20 ` [PATCH 12/17] mtd: rawnand: cafe: Don't split things when reading/writing a page Boris Brezillon
2020-04-27 19:53   ` Miquel Raynal
2020-04-28  6:20     ` Boris Brezillon
2020-04-28  7:44       ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 13/17] mtd: rawnand: cafe: Add exec_op() support Boris Brezillon
2020-04-27 19:59   ` Miquel Raynal [this message]
2020-04-28  6:24     ` Boris Brezillon
     [not found]   ` <20200502111410.330584-1-lkundrak@v3.sk>
2020-05-02 13:18     ` Boris Brezillon
     [not found]       ` <20200502191843.GA363829@furthur.local>
2020-05-02 22:34         ` Boris Brezillon
     [not found]           ` <20200503060610.GA386731@furthur.local>
2020-05-03  7:04             ` Boris Brezillon
2020-05-03  7:26               ` Boris Brezillon
     [not found]                 ` <20200503175537.GA404453@furthur.local>
2020-05-03 19:49                   ` Boris Brezillon
     [not found]               ` <20200503075208.GA387473@furthur.local>
2020-05-03  8:13                 ` Boris Brezillon
2020-05-03  8:35                   ` Boris Brezillon
2020-05-09 20:10         ` Boris Brezillon
2020-04-27  8:20 ` [PATCH 14/17] mtd: rawnand: cafe: Get rid of the legacy interface implementation Boris Brezillon
2020-04-27 20:00   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 15/17] mtd: rawnand: cafe: Adjust the cafe_{read, write}_buf() prototypes Boris Brezillon
2020-04-27 20:00   ` [PATCH 15/17] mtd: rawnand: cafe: Adjust the cafe_{read,write}_buf() prototypes Miquel Raynal
2020-04-28  6:24     ` Boris Brezillon
2020-04-27  8:20 ` [PATCH 16/17] mtd: rawnand: cafe: Handle non-32bit aligned reads/writes Boris Brezillon
2020-04-27 20:04   ` Miquel Raynal
2020-04-28  6:26     ` Boris Brezillon
2020-04-27  8:20 ` [PATCH 17/17] mtd: rawnand: cafe: s/uint{8,16,32}_t/u{8,16,32}/ Boris Brezillon
2020-04-27 20:05   ` Miquel Raynal
2020-04-27  8:20 ` [PATCH 17/17] mtd: rawnand: s/uint{8,16,32}_t/u{8,16,32}/ Boris Brezillon
2020-04-27  8:25   ` Boris Brezillon
2020-04-29  6:37 ` [PATCH 00/17] mtd: rawnand: cafe: Convert to exec_op() (and more) Thomas Petazzoni
2020-04-29  8:28   ` Boris Brezillon
     [not found]     ` <20200501055209.GA44510@furthur.local>
2020-05-01  6:21       ` Boris Brezillon
     [not found] ` <20200502112732.330971-1-lkundrak@v3.sk>
2020-05-02 13:15   ` Boris Brezillon
2020-05-08 10:32     ` Miquel Raynal

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=20200427215933.13fb1bbc@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=boris.brezillon@collabora.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=tudor.ambarus@microchip.com \
    --cc=vigneshr@ti.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.