All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Cyrille Pitchen <cyrille.pitchen@atmel.com>
Cc: linux-mtd@lists.infradead.org, mkraemer@de.adit-jv.com,
	David Woodhouse <dwmw2@infradead.org>,
	key.seong.lim@intel.com, linux-kernel@vger.kernel.org,
	Peter Tyser <ptyser@xes-inc.com>,
	Brian Norris <computersforpeace@gmail.com>,
	Lee Jones <lee.jones@linaro.org>, Marek Vasut <marex@denx.de>
Subject: Re: [PATCH v4 1/3] spi-nor: Add support for Intel SPI serial flash controller
Date: Wed, 9 Nov 2016 16:15:08 +0200	[thread overview]
Message-ID: <20161109141508.GH1447@lahna.fi.intel.com> (raw)
In-Reply-To: <36b27635-8163-f3cb-5953-88f102e22ee4@atmel.com>

On Wed, Nov 09, 2016 at 02:51:20PM +0100, Cyrille Pitchen wrote:
> > +/* Reads max 64 bytes from the device fifo */
> > +static int intel_spi_read_block(struct intel_spi *ispi, void *buf, size_t size)
> > +{
> > +	size_t bytes;
> > +	int i = 0;
> > +
> > +	if (size > 64)
> 
> This is not a blocking point but just a recommendation: you should define
> and use a macro for this 64 byte FIFO size instead of using this hardcoded
> 64 value here and in intel_spi_write_block(), intel_spi_write(),
> intel_spi_read().

Good point. I'll change that to use a macro.

> > +		return -EINVAL;
> > +
> > +	while (size > 0) {
> > +		bytes = min_t(size_t, size, 4);
> > +		memcpy_fromio(buf, ispi->base + FDATA(i++), bytes);
> Here again another general recommendation: be careful about using
> operators like ++ on macro parameters. In the case of this FDATA() macro
> it will work as expected but unwanted side effect might occur depending on
> the actual macro definition:
> 
> int i = 1;
> 
> #define DOUBLE(n)	((n) + (n))
> DOUBLE(i++); /* here i is incremented twice, not just once. */

Indeed, even though with the current macro it does not happen I'm going
change it to update i separately like:

	memcpy_fromio(buf, ispi->base + FDATA(i), bytes);
	i++

> > +		size -= bytes;
> > +		buf += bytes;
> > +	}
> > +
> > +	return 0;
> > +}

[snip]

> > +static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
> > +			      u_char *read_buf)
> > +{
> > +	struct intel_spi *ispi = nor->priv;
> > +	size_t block_size, retlen = 0;
> > +	u32 val, status;
> > +	ssize_t ret;
> > +
> 
> As I understand some Intel SPI controllers can only use op codes in a fixed
> instruction set, so here you should check the nor->read_opcode.
> Indeed when the support of SFDP tables will be integrated, the
> nor->read_opcode might change between calls of the nor->read() handler.

OK, I did not know that it can change.

> spi_nor_read_sfdp() make use of this nor->read() handler but set
> nor->read_opcode to SPINOR_OP_RDSFDP (5Ah) before calling the handler.
> 
> Then, if intel_spi_read() is called with an unsupported nor->read_opcode,
> it should fail returning -EINVAL. The spi-nor framework will handle this
> failure correctly.
> 
> You can find the SFDP patch here:
> http://patchwork.ozlabs.org/patch/685984/

Thanks for the pointer. I'll update the driver to take read_opcode into
account in intel_spi_read().

Thanks for the comments.

  reply	other threads:[~2016-11-09 14:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 14:58 [PATCH v4 0/3] spi-nor: Add support for Intel SPI serial flash controller Mika Westerberg
2016-10-17 14:58 ` [PATCH v4 1/3] " Mika Westerberg
2016-11-09 13:51   ` Cyrille Pitchen
2016-11-09 14:15     ` Mika Westerberg [this message]
2016-10-17 14:58 ` [PATCH v4 2/3] mfd: lpc_ich: Add support for SPI serial flash host controller Mika Westerberg
2016-10-17 14:58 ` [PATCH v4 3/3] mfd: lpc_ich: Add support for Intel Apollo Lake SoC Mika Westerberg
2016-11-09 11:00 ` [PATCH v4 0/3] spi-nor: Add support for Intel SPI serial flash controller Mika Westerberg

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=20161109141508.GH1447@lahna.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=dwmw2@infradead.org \
    --cc=key.seong.lim@intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marex@denx.de \
    --cc=mkraemer@de.adit-jv.com \
    --cc=ptyser@xes-inc.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.