All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH resend 5/7] mtd/st_smi: Write to flash in a tight loop
Date: Thu, 06 Dec 2012 08:51:18 +0100	[thread overview]
Message-ID: <50C04E76.6090503@denx.de> (raw)
In-Reply-To: <8cfab9e68a46250daf5bb0e7de3f0b4d3398753e.1354774371.git.vipin.kumar@st.com>

On 12/06/2012 07:21 AM, Vipin Kumar wrote:
> The write loop is checking for dest_addr alignment with page size. This
> sometimes leads to smi controller coming out of write mode and eventually the
> next write failing with ERF1 being set.
> 
> To avoid this, write to flash in a tight loop and write bytewise to also support
> not word aligned data bytes to be written. Additionally, enable burst mode
> before this loop so that the controller does not deselect the chip if the
> transfer is finished.
> 
> Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
> ---
>  drivers/mtd/st_smi.c | 30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
> index a84802a..998bacb 100644
> --- a/drivers/mtd/st_smi.c
> +++ b/drivers/mtd/st_smi.c
> @@ -368,13 +368,11 @@ static int smi_sector_erase(flash_info_t *info, unsigned int sector)
>   *
>   * Write to SMI flash
>   */
> -static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
> +static int smi_write(unsigned char *src_addr, unsigned char *dst_addr,
>  		     unsigned int length, ulong bank_addr)
>  {
> -	u8 *src_addr8 = (u8 *)src_addr;
> -	u8 *dst_addr8 = (u8 *)dst_addr;
>  	int banknum;
> -	int i, issue_we;
> +	int issue_we;
>  
>  	switch (bank_addr) {
>  	case SMIBANK0_BASE:
> @@ -400,7 +398,10 @@ static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
>  	writel(readl(&smicntl->smi_cr1) & ~SW_MODE, &smicntl->smi_cr1);
>  
>  	/* Perform the write command */
> -	for (i = 0; i < length; i += 4) {
> +	while (length) {
> +		int k;
> +		unsigned int wlen = min(SFLASH_PAGE_SIZE, length);
> +
>  		if (issue_we || (((ulong)(dst_addr) % SFLASH_PAGE_SIZE) == 0)) {
>  			issue_we = 0;
>  
> @@ -412,19 +413,14 @@ static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
>  				return -EIO;
>  		}
>  
> -		if (length < 4) {
> -			int k;
> +		writel(readl(&smicntl->smi_cr1) | WB_MODE, &smicntl->smi_cr1);

Use setbits_le32() please.

> -			/*
> -			 * Handle special case, where length < 4 (redundant env)
> -			 */
> -			for (k = 0; k < length; k++)
> -				*dst_addr8++ = *src_addr8++;
> -		} else {
> -			/* Normal 32bit write */
> +		for (k = 0; k < wlen; k++)
>  			*dst_addr++ = *src_addr++;
> -		}
>  
> +		writel(readl(&smicntl->smi_cr1) & ~WB_MODE, &smicntl->smi_cr1);

clrbits_le32()

Thanks,
Stefan

  reply	other threads:[~2012-12-06  7:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-06  6:21 [U-Boot] [PATCH resend 0/7] mtd/st_smi: Add fixes for smi driver Vipin Kumar
2012-12-06  6:21 ` [U-Boot] [PATCH resend 1/7] mtd/st_smi: Clear error flags while initiating a fresh write Vipin Kumar
2012-12-06  7:37   ` Stefan Roese
2012-12-06  8:16     ` Vipin Kumar
2012-12-06  6:21 ` [U-Boot] [PATCH resend 2/7] mtd/st_smi: Rearrange the supported devices in alphabetical order Vipin Kumar
2012-12-06  7:37   ` Stefan Roese
2012-12-06  6:21 ` [U-Boot] [PATCH resend 3/7] mtd/st_smi: Add support for Micron N25Q128 Flash Vipin Kumar
2012-12-06  7:38   ` Stefan Roese
2012-12-06  6:21 ` [U-Boot] [PATCH resend 4/7] mtd/st_smi: Avoid issuing multiple WE commands Vipin Kumar
2012-12-06  7:44   ` Stefan Roese
2012-12-06  6:21 ` [U-Boot] [PATCH resend 5/7] mtd/st_smi: Write to flash in a tight loop Vipin Kumar
2012-12-06  7:51   ` Stefan Roese [this message]
2012-12-06  6:21 ` [U-Boot] [PATCH resend 6/7] mtd/st_smi: Use page sizes respective to flash Vipin Kumar
2012-12-06  7:53   ` Stefan Roese
2012-12-06  6:21 ` [U-Boot] [PATCH resend 7/7] mtd/st_smi: Add mtd support for smi Vipin Kumar
2012-12-06  8:02   ` Stefan Roese
2012-12-06  8:36     ` Vipin Kumar
2012-12-06  7:35 ` [U-Boot] [PATCH resend 0/7] mtd/st_smi: Add fixes for smi driver Stefan Roese
2012-12-06  8:19   ` Vipin Kumar
2012-12-06  8:32     ` Stefan Roese
2012-12-06  8:48       ` Vipin Kumar

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=50C04E76.6090503@denx.de \
    --to=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /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.