Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754618AbbETXiq (ORCPT ); Wed, 20 May 2015 19:38:46 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34973 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751882AbbETXim (ORCPT ); Wed, 20 May 2015 19:38:42 -0400 Date: Wed, 20 May 2015 16:38:35 -0700 From: Brian Norris To: Michal Suchanek Cc: linux-sunxi@googlegroups.com, Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , David Woodhouse , Marek Vasut , Huang Shijie , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , Ben Hutchings , Alison Chaiken , Mika Westerberg , Bean Huo =?utf-8?B?6ZyN5paM5paMIChiZWFuaHVvKQ==?= , "grmoore@altera.com" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org, Mark Brown Subject: Re: [PATCH 2/3] MTD: spi-nor: check for short writes in spi_nor_write. Message-ID: <20150520233835.GX11598@ld-irv-0074> References: <50c40ef17ab6566f35ef5a4426bf23567f896db7.1430403750.git.hramrach@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50c40ef17ab6566f35ef5a4426bf23567f896db7.1430403750.git.hramrach@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3027 Lines: 91 + 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 > --- > 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; > } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/