]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/st_smi.c
arm: mx6: remove CONFIG_ macros that are now included in Kconfig from header file
[karo-tx-uboot.git] / drivers / mtd / st_smi.c
index 976b0979e290ca523ed1a4887261ffd4e1c2b428..208119c5f06e74342e85e3991deacb10f248967f 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2009
  * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -91,7 +75,7 @@ static struct flash_device flash_devices[] = {
        FLASH_ID("mac 25l3205"   , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
        FLASH_ID("mac 25l3205a"  , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
        FLASH_ID("mac 25l6405"   , 0xd8, 0x001720C2, 0x100, 0x10000, 0x800000),
-       FLASH_ID("wbd w25q128" , 0xd8, 0x001840EF, 0x1000, 0x10000, 0x1000000),
+       FLASH_ID("wbd w25q128" , 0xd8, 0x001840EF, 0x100, 0x10000, 0x1000000),
 };
 
 /*
@@ -102,11 +86,15 @@ static struct flash_device flash_devices[] = {
  */
 static int smi_wait_xfer_finish(int timeout)
 {
-       do {
+       ulong start = get_timer(0);
+
+       while (get_timer(start) < timeout) {
                if (readl(&smicntl->smi_sr) & TFF)
                        return 0;
-               udelay(1000);
-       } while (timeout--);
+
+               /* Try after 10 ms */
+               udelay(10);
+       };
 
        return -1;
 }
@@ -219,16 +207,17 @@ static int smi_read_sr(int bank)
 static int smi_wait_till_ready(int bank, int timeout)
 {
        int sr;
+       ulong start = get_timer(0);
 
        /* One chip guarantees max 5 msec wait here after page writes,
           but potentially three seconds (!) after page erase. */
-       do {
+       while (get_timer(start) < timeout) {
                sr = smi_read_sr(bank);
                if ((sr >= 0) && (!(sr & WIP_BIT)))
                        return 0;
 
-               /* Try again after 1m-sec */
-               udelay(1000);
+               /* Try again after 10 usec */
+               udelay(10);
        } while (timeout--);
 
        printf("SMI controller is still in wait, timeout=%d\n", timeout);
@@ -245,6 +234,7 @@ static int smi_wait_till_ready(int bank, int timeout)
 static int smi_write_enable(int bank)
 {
        u32 ctrlreg1;
+       u32 start;
        int timeout = WMODE_TOUT;
        int sr;
 
@@ -263,14 +253,15 @@ static int smi_write_enable(int bank)
        /* Restore the CTRL REG1 state */
        writel(ctrlreg1, &smicntl->smi_cr1);
 
-       do {
+       start = get_timer(0);
+       while (get_timer(start) < timeout) {
                sr = smi_read_sr(bank);
                if ((sr >= 0) && (sr & (1 << (bank + WM_SHIFT))))
                        return 0;
 
-               /* Try again after 1m-sec */
-               udelay(1000);
-       } while (timeout--);
+               /* Try again after 10 usec */
+               udelay(10);
+       };
 
        return -1;
 }
@@ -355,7 +346,7 @@ static int smi_sector_erase(flash_info_t *info, unsigned int sector)
  * smi_write - Write to SMI flash
  * @src_addr:   source buffer
  * @dst_addr:   destination buffer
- * @length:     length to write in words
+ * @length:     length to write in bytes
  * @bank:       bank base address
  *
  * Write to SMI flash
@@ -363,7 +354,10 @@ static int smi_sector_erase(flash_info_t *info, unsigned int sector)
 static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
                     unsigned int length, ulong bank_addr)
 {
+       u8 *src_addr8 = (u8 *)src_addr;
+       u8 *dst_addr8 = (u8 *)dst_addr;
        int banknum;
+       int i;
 
        switch (bank_addr) {
        case SMIBANK0_BASE:
@@ -392,7 +386,7 @@ static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
                return -EIO;
 
        /* Perform the write command */
-       while (length--) {
+       for (i = 0; i < length; i += 4) {
                if (((ulong) (dst_addr) % SFLASH_PAGE_SIZE) == 0) {
                        if (smi_wait_till_ready(banknum,
                                                CONFIG_SYS_FLASH_WRITE_TOUT))
@@ -402,7 +396,18 @@ static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
                                return -EIO;
                }
 
-               *dst_addr++ = *src_addr++;
+               if (length < 4) {
+                       int k;
+
+                       /*
+                        * Handle special case, where length < 4 (redundant env)
+                        */
+                       for (k = 0; k < length; k++)
+                               *dst_addr8++ = *src_addr8++;
+               } else {
+                       /* Normal 32bit write */
+                       *dst_addr++ = *src_addr++;
+               }
 
                if ((readl(&smicntl->smi_sr) & (ERF1 | ERF2)))
                        return -EIO;
@@ -428,7 +433,7 @@ static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
 int write_buff(flash_info_t *info, uchar *src, ulong dest_addr, ulong length)
 {
        return smi_write((unsigned int *)src, (unsigned int *)dest_addr,
-                 (length + 3) / 4, info->start[0]);
+                        length, info->start[0]);
 }
 
 /*
@@ -471,8 +476,13 @@ void flash_print_info(flash_info_t *info)
                puts("missing or unknown FLASH type\n");
                return;
        }
-       printf("  Size: %ld MB in %d Sectors\n",
-              info->size >> 20, info->sector_count);
+
+       if (info->size >= 0x100000)
+               printf("  Size: %ld MB in %d Sectors\n",
+                      info->size >> 20, info->sector_count);
+       else
+               printf("  Size: %ld KB in %d Sectors\n",
+                      info->size >> 10, info->sector_count);
 
        puts("  Sector Start Addresses:");
        for (i = 0; i < info->sector_count; ++i) {