linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pratyush Yadav <p.yadav@ti.com>
To: Michael Walle <michael@walle.cc>
Cc: Nishanth Menon <nm@ti.com>, Tero Kristo <kristo@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Tudor Ambarus <tudor.ambarus@microchip.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Mark Brown <broonie@kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-mtd@lists.infradead.org>, <linux-spi@vger.kernel.org>,
	Lokesh Vutla <lokeshvutla@ti.com>
Subject: Re: [RFC PATCH 2/6] mtd: spi-nor: core: consolidate read op creation
Date: Wed, 24 Mar 2021 13:34:27 +0530	[thread overview]
Message-ID: <20210324080425.c4ospw4p6w7lrjok@ti.com> (raw)
In-Reply-To: <77a4d73b65bd371e93538886038f1acb@walle.cc>

On 24/03/21 12:17AM, Michael Walle wrote:
> Am 2021-03-11 20:12, schrieb Pratyush Yadav:
> > Currently the spi_mem_op to read from the flash is used in two places:
> > spi_nor_create_read_dirmap() and spi_nor_spimem_read_data(). In a later
> > commit this number will increase to three. Instead of repeating the same
> > code thrice, add a function that returns a template of the read op. The
> > callers can then fill in the details like address, data length, data
> > buffer location.
> > 
> > Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> > ---
> >  drivers/mtd/spi-nor/core.c | 62 ++++++++++++++++++++------------------
> >  1 file changed, 32 insertions(+), 30 deletions(-)
> > 
> > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> > index 4a315cb1c4db..88888df009f0 100644
> > --- a/drivers/mtd/spi-nor/core.c
> > +++ b/drivers/mtd/spi-nor/core.c
> > @@ -183,6 +183,33 @@ static int spi_nor_controller_ops_erase(struct
> > spi_nor *nor, loff_t offs)
> >  	return nor->controller_ops->erase(nor, offs);
> >  }
> > 
> > +/**
> > + * spi_nor_spimem_get_read_op() - return a template for the spi_mem_op
> > used for
> > + *                                reading data from the flash via
> > spi-mem.
> > + * @nor:        pointer to 'struct spi_nor'
> > + *
> > + * Return: A template of the 'struct spi_mem_op' for used for reading
> > data from
> > + * the flash. The caller is expected to fill in the address, data
> > length, and
> > + * the data buffer.
> > + */
> > +static struct spi_mem_op spi_nor_spimem_get_read_op(struct spi_nor
> > *nor)
> > +{
> > +	struct spi_mem_op op =
> > +		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0),
> > +			   SPI_MEM_OP_ADDR(nor->addr_width, 0, 0),
> > +			   SPI_MEM_OP_DUMMY(nor->read_dummy, 0),
> > +			   SPI_MEM_OP_DATA_IN(1, NULL, 0));
> > +
> > +	spi_nor_spimem_setup_op(nor, &op, nor->read_proto);
> > +
> > +	/* convert the dummy cycles to the number of bytes */
> > +	op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
> > +	if (spi_nor_protocol_is_dtr(nor->read_proto))
> > +		op.dummy.nbytes *= 2;
> > +
> > +	return op;
> > +}
> > +
> >  /**
> >   * spi_nor_spimem_read_data() - read data from flash's memory region
> > via
> >   *                              spi-mem
> > @@ -196,21 +223,14 @@ static int spi_nor_controller_ops_erase(struct
> > spi_nor *nor, loff_t offs)
> >  static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t
> > from,
> >  					size_t len, u8 *buf)
> >  {
> > -	struct spi_mem_op op =
> > -		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0),
> > -			   SPI_MEM_OP_ADDR(nor->addr_width, from, 0),
> > -			   SPI_MEM_OP_DUMMY(nor->read_dummy, 0),
> > -			   SPI_MEM_OP_DATA_IN(len, buf, 0));
> > +	struct spi_mem_op op = spi_nor_spimem_get_read_op(nor);
> >  	bool usebouncebuf;
> >  	ssize_t nbytes;
> >  	int error;
> > 
> > -	spi_nor_spimem_setup_op(nor, &op, nor->read_proto);
> > -
> > -	/* convert the dummy cycles to the number of bytes */
> > -	op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
> > -	if (spi_nor_protocol_is_dtr(nor->read_proto))
> > -		op.dummy.nbytes *= 2;
> > +	op.addr.val = from;
> > +	op.data.nbytes = len;
> > +	op.data.buf.in = buf;
> > 
> >  	usebouncebuf = spi_nor_spimem_bounce(nor, &op);
> > 
> > @@ -3581,28 +3601,10 @@ EXPORT_SYMBOL_GPL(spi_nor_scan);
> >  static int spi_nor_create_read_dirmap(struct spi_nor *nor)
> >  {
> >  	struct spi_mem_dirmap_info info = {
> > -		.op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0),
> > -				      SPI_MEM_OP_ADDR(nor->addr_width, 0, 0),
> > -				      SPI_MEM_OP_DUMMY(nor->read_dummy, 0),
> > -				      SPI_MEM_OP_DATA_IN(0, NULL, 0)),
> > +		.op_tmpl = spi_nor_spimem_get_read_op(nor),
> >  		.offset = 0,
> >  		.length = nor->mtd.size,
> >  	};
> > -	struct spi_mem_op *op = &info.op_tmpl;
> > -
> > -	spi_nor_spimem_setup_op(nor, op, nor->read_proto);
> > -
> > -	/* convert the dummy cycles to the number of bytes */
> > -	op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8;
> > -	if (spi_nor_protocol_is_dtr(nor->read_proto))
> > -		op->dummy.nbytes *= 2;
> > -
> > -	/*
> > -	 * Since spi_nor_spimem_setup_op() only sets buswidth when the number
> > -	 * of data bytes is non-zero, the data buswidth won't be set here. So,
> > -	 * do it explicitly.
> > -	 */
> > -	op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto);
> 
> I guess this isn't needed anymore because spi_nor_spimem_get_read_op() uses
> a
> data length of 1, right?

Yes.

> 
> > 
> >  	nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem,
> >  						       &info);
> 
> -michael

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

  reply	other threads:[~2021-03-24  8:05 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 19:12 [RFC PATCH 0/6] spi: Add OSPI PHY calibration support for spi-cadence-quadspi Pratyush Yadav
2021-03-11 19:12 ` [RFC PATCH 1/6] spi: spi-mem: Tell controller when device is ready for calibration Pratyush Yadav
2021-03-23 23:07   ` Michael Walle
2021-03-24  8:08     ` Pratyush Yadav
2021-04-29 16:23       ` Michael Walle
2021-04-29 18:41         ` Pratyush Yadav
2021-04-29 22:46           ` Michael Walle
2021-03-11 19:12 ` [RFC PATCH 2/6] mtd: spi-nor: core: consolidate read op creation Pratyush Yadav
2021-03-23 23:17   ` Michael Walle
2021-03-24  8:04     ` Pratyush Yadav [this message]
2021-04-08 12:48   ` Michael Walle
2021-03-11 19:12 ` [RFC PATCH 3/6] mtd: spi-nor: core: run calibration when initialization is done Pratyush Yadav
2022-05-17 14:02   ` Miquel Raynal
2022-05-18  6:07     ` Pratyush Yadav
2022-05-18  7:19       ` Miquel Raynal
2022-05-18  7:56         ` Pratyush Yadav
2022-05-18  8:51           ` Cédric Le Goater
2022-06-27  9:14             ` Pratyush Yadav
2022-06-27  9:43               ` Cédric Le Goater
2022-06-27 10:35                 ` Pratyush Yadav
2021-03-11 19:12 ` [RFC PATCH 4/6] spi: cadence-qspi: Use PHY for DAC reads if possible Pratyush Yadav
2021-03-12  9:13   ` Tudor.Ambarus
2021-03-12 10:17     ` Pratyush Yadav
2021-04-29 16:28       ` Michael Walle
2021-04-29 18:19         ` Pratyush Yadav
2021-04-29 22:20           ` Michael Walle
2021-05-10 11:39             ` Pratyush Yadav
2021-03-11 19:12 ` [RFC PATCH 5/6] spi: cadence-qspi: Tune PHY to allow running at higher frequencies Pratyush Yadav
2021-04-29 22:48   ` Michael Walle
2021-04-30  5:42     ` Pratyush Yadav
2021-03-11 19:12 ` [RFC PATCH 6/6] arm64: dts: ti: k3-j721e-som-p0: Enable PHY calibration Pratyush Yadav
2021-03-12  9:09 ` [RFC PATCH 0/6] spi: Add OSPI PHY calibration support for spi-cadence-quadspi Tudor.Ambarus
2021-03-12 10:10   ` Pratyush Yadav
2021-03-12 10:20     ` Michael Walle
2021-03-12 11:07       ` Pratyush Yadav
2021-03-12 13:26         ` Michael Walle
2021-03-12 11:23     ` Tudor.Ambarus
2021-03-12 18:14       ` Pratyush Yadav
2021-03-12 13:32 ` Michael Walle
2021-03-12 14:59   ` Tudor.Ambarus
2021-03-12 17:00   ` Pratyush Yadav

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=20210324080425.c4ospw4p6w7lrjok@ti.com \
    --to=p.yadav@ti.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kristo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lokeshvutla@ti.com \
    --cc=michael@walle.cc \
    --cc=miquel.raynal@bootlin.com \
    --cc=nm@ti.com \
    --cc=richard@nod.at \
    --cc=robh+dt@kernel.org \
    --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 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).