Merge branch '2022-08-04-Kconfig-migrations'
[platform/kernel/u-boot.git] / board / freescale / m5253demo / flash.c
index 1bf1e97..bff1ac5 100644 (file)
@@ -1,34 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000-2003
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
  * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  * TsiChung Liew (Tsi-Chung.Liew@freescale.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
  */
 
 #include <common.h>
+#include <flash.h>
+#include <init.h>
+#include <irq_func.h>
 
 #include <asm/immap.h>
 
-#ifndef CFG_FLASH_CFI
+#ifndef CONFIG_SYS_FLASH_CFI
 typedef unsigned short FLASH_PORT_WIDTH;
 typedef volatile unsigned short FLASH_PORT_WIDTHV;
 
@@ -47,16 +33,16 @@ typedef volatile unsigned short FLASH_PORT_WIDTHV;
 ulong flash_get_size(FPWV * addr, flash_info_t * info);
 int flash_get_offsets(ulong base, flash_info_t * info);
 int write_word(flash_info_t * info, FPWV * dest, u16 data);
-void inline spin_wheel(void);
+static inline void spin_wheel(void);
 
-flash_info_t flash_info[CFG_MAX_FLASH_BANKS];
+flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
 
 ulong flash_init(void)
 {
        ulong size = 0;
        ulong fbase = 0;
 
-       fbase = (ulong) CFG_FLASH_BASE;
+       fbase = (ulong) CONFIG_SYS_FLASH_BASE;
        flash_get_size((FPWV *) fbase, &flash_info[0]);
        flash_get_offsets((ulong) fbase, &flash_info[0]);
        fbase += flash_info[0].size;
@@ -64,22 +50,24 @@ ulong flash_init(void)
 
        /* Protect monitor and environment sectors */
        flash_protect(FLAG_PROTECT_SET,
-                     CFG_MONITOR_BASE,
-                     CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);
+                     CONFIG_SYS_MONITOR_BASE,
+                     CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);
 
        return size;
 }
 
 int flash_get_offsets(ulong base, flash_info_t * info)
 {
-       int j, k;
+       int i;
 
        if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) {
 
                info->start[0] = base;
-               for (k = 0, j = 0; j < CFG_SST_SECT; j++, k++) {
-                       info->start[k + 1] = info->start[k] + CFG_SST_SECTSZ;
-                       info->protect[k] = 0;
+               info->protect[0] = 0;
+               for (i = 1; i < CONFIG_SYS_SST_SECT; i++) {
+                       info->start[i] = info->start[i - 1]
+                                               + CONFIG_SYS_SST_SECTSZ;
+                       info->protect[i] = 0;
                }
        }
 
@@ -174,16 +162,16 @@ ulong flash_get_size(FPWV * addr, flash_info_t * info)
 
        info->sector_count = 0;
        info->size = 0;
-       info->sector_count = CFG_SST_SECT;
-       info->size = CFG_SST_SECT * CFG_SST_SECTSZ;
+       info->sector_count = CONFIG_SYS_SST_SECT;
+       info->size = CONFIG_SYS_SST_SECT * CONFIG_SYS_SST_SECTSZ;
 
        /* reset ID mode */
        *addr = (FPWV) 0x00F000F0;
 
-       if (info->sector_count > CFG_MAX_FLASH_SECT) {
+       if (info->sector_count > CONFIG_SYS_MAX_FLASH_SECT) {
                printf("** ERROR: sector count %d > max (%d) **\n",
-                      info->sector_count, CFG_MAX_FLASH_SECT);
-               info->sector_count = CFG_MAX_FLASH_SECT;
+                      info->sector_count, CONFIG_SYS_MAX_FLASH_SECT);
+               info->sector_count = CONFIG_SYS_MAX_FLASH_SECT;
        }
 
        return (info->size);
@@ -193,7 +181,7 @@ int flash_erase(flash_info_t * info, int s_first, int s_last)
 {
        FPWV *addr;
        int flag, prot, sect, count;
-       ulong type, start, last;
+       ulong type, start;
        int rcode = 0, flashtype = 0;
 
        if ((s_first < 0) || (s_first > s_last)) {
@@ -233,9 +221,8 @@ int flash_erase(flash_info_t * info, int s_first, int s_last)
        flag = disable_interrupts();
 
        start = get_timer(0);
-       last = start;
 
-       if ((s_last - s_first) == (CFG_SST_SECT - 1)) {
+       if ((s_last - s_first) == (CONFIG_SYS_SST_SECT - 1)) {
                if (prot == 0) {
                        addr = (FPWV *) info->start[0];
 
@@ -255,7 +242,8 @@ int flash_erase(flash_info_t * info, int s_first, int s_last)
                                        count = 0;
                                }
 
-                               if (get_timer(start) > CFG_FLASH_ERASE_TOUT) {
+                               /* check timeout, 1000ms */
+                               if (get_timer(start) > 1000) {
                                        printf("Timeout\n");
                                        *addr = 0x00F0; /* reset to read mode */
 
@@ -271,7 +259,7 @@ int flash_erase(flash_info_t * info, int s_first, int s_last)
                                enable_interrupts();
 
                        return 0;
-               } else if (prot == CFG_SST_SECT) {
+               } else if (prot == CONFIG_SYS_SST_SECT) {
                        return 1;
                }
        }
@@ -294,7 +282,7 @@ int flash_erase(flash_info_t * info, int s_first, int s_last)
 
                                        flag = disable_interrupts();
 
-                                       base = (FPWV *) (CFG_FLASH_BASE);       /* First sector */
+                                       base = (FPWV *) (CONFIG_SYS_FLASH_BASE);        /* First sector */
 
                                        base[FLASH_CYCLE1] = 0x00AA;    /* unlock */
                                        base[FLASH_CYCLE2] = 0x0055;    /* unlock */
@@ -307,8 +295,8 @@ int flash_erase(flash_info_t * info, int s_first, int s_last)
                                                enable_interrupts();
 
                                        while ((*addr & 0x0080) != 0x0080) {
-                                               if (get_timer(start) >
-                                                   CFG_FLASH_ERASE_TOUT) {
+                                               /* check timeout, 1000ms */
+                                               if (get_timer(start) > 1000) {
                                                        printf("Timeout\n");
                                                        *addr = 0x00F0; /* reset to read mode */
 
@@ -335,14 +323,13 @@ int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
 {
        ulong wp, count;
        u16 data;
-       int rc, port_width;
+       int rc;
 
        if (info->flash_id == FLASH_UNKNOWN)
                return 4;
 
        /* get lower word aligned address */
        wp = addr;
-       port_width = sizeof(FPW);
 
        /* handle unaligned start bytes */
        if (wp & 1) {
@@ -424,7 +411,7 @@ int write_word(flash_info_t * info, FPWV * dest, u16 data)
                return (2);
        }
 
-       base = (FPWV *) (CFG_FLASH_BASE);
+       base = (FPWV *) (CONFIG_SYS_FLASH_BASE);
 
        /* Disable interrupts which might cause a timeout here */
        flag = disable_interrupts();
@@ -444,7 +431,8 @@ int write_word(flash_info_t * info, FPWV * dest, u16 data)
        /* data polling for D7 */
        while (res == 0
               && (*dest & (u8) 0x00800080) != (data & (u8) 0x00800080)) {
-               if (get_timer(start) > CFG_FLASH_WRITE_TOUT) {
+               /* check timeout, 500ms */
+               if (get_timer(start) > 500) {
                        *dest = (u8) 0x00F000F0;        /* reset bank */
                        res = 1;
                }
@@ -455,7 +443,7 @@ int write_word(flash_info_t * info, FPWV * dest, u16 data)
        return (res);
 }
 
-void inline spin_wheel(void)
+static inline void spin_wheel(void)
 {
        static int p = 0;
        static char w[] = "\\/-";