public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org,
	"Rob Herring" <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Pawel Moll" <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
	"Mark Rutland" <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	"Ian Campbell"
	<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
	"Kumar Gala" <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	"David Woodhouse" <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	"Marek Vasut" <marex-ynQEQJNshbs@public.gmane.org>,
	"Huang Shijie" <b32955-KZfg59tc24xl57MIdRCFDg@public.gmane.org>,
	"Rafał Miłecki" <zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"Ben Hutchings" <ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org>,
	"Alison Chaiken"
	<alison_chaiken-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>,
	"Mika Westerberg"
	<mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	"Bean Huo 霍斌斌 (beanhuo)"
	<beanhuo-AL4WhLSQfzjQT0dZR+AlfA@public.gmane.org>,
	"grmoore-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org"
	<grmoore-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Mark Brown" <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: Re: [PATCH 2/3] MTD: spi-nor: check for short writes in spi_nor_write.
Date: Wed, 20 May 2015 16:38:35 -0700	[thread overview]
Message-ID: <20150520233835.GX11598@ld-irv-0074> (raw)
In-Reply-To: <50c40ef17ab6566f35ef5a4426bf23567f896db7.1430403750.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

+ linux-spi, Mark

On Thu, Apr 30, 2015 at 03:38:50PM +0200, Michal Suchanek wrote:
> My SPI controller driver does not support DMA so writes are truncated to
> FIFO size.

Which SPI master driver?

> Check the amount of data actually written by the driver.

I'm not sure if we should just reactively use the retlen, or if we
should be communicating such a limitation via the SPI API. Thoughts?

Brian

> Signed-off-by: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 42 +++++++++++++++++-------------------------
>  1 file changed, 17 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 14a5d23..75904b5 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -807,7 +807,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>  	size_t *retlen, const u_char *buf)
>  {
>  	struct spi_nor *nor = mtd_to_spi_nor(mtd);
> -	u32 page_offset, page_size, i;
> +	u32 page_offset, page_remainder, page_size, i;
>  	int ret;
>  
>  	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
> @@ -816,36 +816,28 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>  	if (ret)
>  		return ret;
>  
> -	write_enable(nor);
> -
> -	page_offset = to & (nor->page_size - 1);
> -
> -	/* do all the bytes fit onto one page? */
> -	if (page_offset + len <= nor->page_size) {
> -		nor->write(nor, to, len, retlen, buf);
> -	} else {
> -		/* the size of data remaining on the first page */
> -		page_size = nor->page_size - page_offset;
> -		nor->write(nor, to, page_size, retlen, buf);
> +	/* write everything in nor->page_size chunks */
> +	/* check the size of data actually written */
> +	for (i = 0; i < len; i += *retlen) {
> +		page_size = len - i;
> +		page_offset = (to + i) & (nor->page_size - 1);
> +		page_remainder = nor->page_size - page_offset;
> +		if (page_size > nor->page_size)
> +			page_size = nor->page_size;
> +		if (page_remainder && (page_size > page_remainder))
> +			page_size = page_remainder;
>  
> -		/* write everything in nor->page_size chunks */
> -		for (i = page_size; i < len; i += page_size) {
> -			page_size = len - i;
> -			if (page_size > nor->page_size)
> -				page_size = nor->page_size;
> -
> -			ret = spi_nor_wait_till_ready(nor);
> -			if (ret)
> -				goto write_err;
> +		write_enable(nor);
>  
> -			write_enable(nor);
> +		nor->write(nor, to + i, page_size, retlen, buf + i);
>  
> -			nor->write(nor, to + i, page_size, retlen, buf + i);
> -		}
> +		ret = spi_nor_wait_till_ready(nor);
> +		if (ret)
> +			goto write_err;
>  	}
>  
> -	ret = spi_nor_wait_till_ready(nor);
>  write_err:
> +	*retlen = i;
>  	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
>  	return ret;
>  }

  parent reply	other threads:[~2015-05-20 23:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 14:22 [PATCH 0/3] Using SPI NOR flah on sunxi Michal Suchanek
     [not found] ` <cover.1430403750.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-04-30 13:33   ` [PATCH 1/3] MTD: m25p80: fix write return value Michal Suchanek
     [not found]     ` <55132b4496e7fe73f949186c0f140f3e4fd4e2c7.1430403750.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-04-30 18:43       ` Marek Vasut
     [not found]         ` <201504302043.11118.marex-ynQEQJNshbs@public.gmane.org>
2015-04-30 21:37           ` Michal Suchanek
2015-04-30 13:38   ` [PATCH 2/3] MTD: spi-nor: check for short writes in spi_nor_write Michal Suchanek
     [not found]     ` <50c40ef17ab6566f35ef5a4426bf23567f896db7.1430403750.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-20 23:38       ` Brian Norris [this message]
2015-05-21  8:39         ` Michal Suchanek
     [not found]           ` <CAOMqctTYqDWL51twOuGi+oXONXQ4B2-2BkdJNSpzZAXshZUN6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-21 10:28             ` Mark Brown
     [not found]               ` <20150521102802.GS21577-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-05-22  7:17                 ` Brian Norris
2015-04-30 13:46   ` [PATCH 3/3] MTD: m25p80: Add option to limit SPI transfer size Michal Suchanek
     [not found]     ` <3b0c112672f364452e80c333048161eaffb655db.1430403750.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-04-30 14:58       ` Julian Calaby
     [not found]         ` <CAGRGNgXKrpJ8rc4h4BykgHsn3kfT5fuAssMK1bQJtxhVL=s2BA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-20 23:27           ` Brian Norris
2015-04-30 16:30   ` [PATCH 0/3] Using SPI NOR flah on sunxi Thomas.Betker-Bf/A/FSCP0w3s4ca2cGeAgC/G2K4zDHf
2015-04-30 16:30 ` Thomas.Betker
     [not found]   ` <OF23B05612.4290AF80-ONC1257E37.00589292-C1257E37.005AB106-Bf/A/FSCP0w3s4ca2cGeAgC/G2K4zDHf@public.gmane.org>
2015-04-30 16:56     ` Michal Suchanek
     [not found]       ` <CAOMqctRLnCJfVCYGjsmhORYNk+HCf07wwSXnZv4oqDxbaQqKGw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-30 18:34         ` Marek Vasut
2015-05-20 23:54           ` Brian Norris
2015-04-30 16:30 ` Thomas.Betker
2015-04-30 16:30 ` Thomas.Betker
2015-05-01 12:27 ` Stefan Monnier
     [not found]   ` <jwv4mnwfppf.fsf-monnier+gmane.comp.hardware.netbook.arm.sunxi-mXXj517/zsQ@public.gmane.org>
2015-05-04 10:32     ` [linux-sunxi] " Michal Suchanek

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=20150520233835.GX11598@ld-irv-0074 \
    --to=computersforpeace-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=alison_chaiken-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org \
    --cc=b32955-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=beanhuo-AL4WhLSQfzjQT0dZR+AlfA@public.gmane.org \
    --cc=ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=grmoore-EIB2kfCEclfQT0dZR+AlfA@public.gmane.org \
    --cc=hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    --cc=marex-ynQEQJNshbs@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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