]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/dataflash.c
sunxi_nand_spl: Remove NAND_SUNXI_SPL_SYNDROME_PARTITIONS_END
[karo-tx-uboot.git] / drivers / mtd / dataflash.c
index a092dc634fa7363e25cd1da93f404f522b4f7419..3fb6ed6df7cdcc6e65f34105756c765828be98ea 100644 (file)
@@ -1,21 +1,8 @@
-/* LowLevel function for ATMEL DataFlash support
+/*
+ * LowLevel function for ATMEL DataFlash support
  * Author : Hamid Ikdoumi (Atmel)
  *
- * 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>
 #include <config.h>
@@ -39,13 +26,12 @@ int AT91F_DataflashInit (void)
        int i, j;
        int dfcode;
        int part;
-       int last_part;
-       int found[CFG_MAX_DATAFLASH_BANKS];
+       int found[CONFIG_SYS_MAX_DATAFLASH_BANKS];
        unsigned char protected;
 
        AT91F_SpiInit ();
 
-       for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++) {
+       for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++) {
                found[i] = 0;
                dataflash_info[i].Desc.state = IDLE;
                dataflash_info[i].id = 0;
@@ -56,7 +42,7 @@ int AT91F_DataflashInit (void)
                switch (dfcode) {
                case AT45DB021:
                        dataflash_info[i].Device.pages_number = 1024;
-                       dataflash_info[i].Device.pages_size = 263;
+                       dataflash_info[i].Device.pages_size = 264;
                        dataflash_info[i].Device.page_offset = 9;
                        dataflash_info[i].Device.byte_mask = 0x300;
                        dataflash_info[i].Device.cs = cs[i].cs;
@@ -65,6 +51,19 @@ int AT91F_DataflashInit (void)
                        dataflash_info[i].id = dfcode;
                        found[i] += dfcode;;
                        break;
+
+               case AT45DB081:
+                       dataflash_info[i].Device.pages_number = 4096;
+                       dataflash_info[i].Device.pages_size = 264;
+                       dataflash_info[i].Device.page_offset = 9;
+                       dataflash_info[i].Device.byte_mask = 0x300;
+                       dataflash_info[i].Device.cs = cs[i].cs;
+                       dataflash_info[i].Desc.DataFlash_state = IDLE;
+                       dataflash_info[i].logical_address = cs[i].addr;
+                       dataflash_info[i].id = dfcode;
+                       found[i] += dfcode;;
+                       break;
+
                case AT45DB161:
                        dataflash_info[i].Device.pages_number = 4096;
                        dataflash_info[i].Device.pages_size = 528;
@@ -118,14 +117,13 @@ int AT91F_DataflashInit (void)
                        break;
                }
                /* set the last area end to the dataflash size*/
-               area_list[NB_DATAFLASH_AREA -1].end =
+               dataflash_info[i].end_address =
                                (dataflash_info[i].Device.pages_number *
-                               dataflash_info[i].Device.pages_size)-1;
+                               dataflash_info[i].Device.pages_size) - 1;
 
                part = 0;
-               last_part = 0;
                /* set the area addresses */
-               for(j = 0; j<NB_DATAFLASH_AREA; j++) {
+               for(j = 0; j < NB_DATAFLASH_AREA; j++) {
                        if(found[i]!=0) {
                                dataflash_info[i].Device.area_list[j].start =
                                        area_list[part].start +
@@ -133,8 +131,7 @@ int AT91F_DataflashInit (void)
                                if(area_list[part].end == 0xffffffff) {
                                        dataflash_info[i].Device.area_list[j].end =
                                                dataflash_info[i].end_address +
-                                               dataflash_info  [i].logical_address;
-                                       last_part = 1;
+                                               dataflash_info[i].logical_address;
                                } else {
                                        dataflash_info[i].Device.area_list[j].end =
                                                area_list[part].end +
@@ -166,14 +163,13 @@ void AT91F_DataflashSetEnv (void)
        unsigned char s[32];    /* Will fit a long int in hex */
        unsigned long start;
 
-       for (i = 0, part= 0; i < CFG_MAX_DATAFLASH_BANKS; i++) {
-               for(j = 0; j<NB_DATAFLASH_AREA; j++) {
+       for (i = 0, part= 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++) {
+               for(j = 0; j < NB_DATAFLASH_AREA; j++) {
                        env = area_list[part].setenv;
                        /* Set the environment according to the label...*/
                        if((env & FLAG_SETENV) == FLAG_SETENV) {
-                               start =
-                               dataflash_info[i].Device.area_list[j].start;
-                               sprintf((char*) s,"%X",start);
+                               start = dataflash_info[i].Device.area_list[j].start;
+                               sprintf((char*) s,"%lX",start);
                                setenv((char*) area_list[part].label,(char*) s);
                        }
                        part++;
@@ -185,7 +181,7 @@ void dataflash_print_info (void)
 {
        int i, j;
 
-       for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++) {
+       for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++) {
                if (dataflash_info[i].id != 0) {
                        printf("DataFlash:");
                        switch (dataflash_info[i].id) {
@@ -217,7 +213,7 @@ void dataflash_print_info (void)
                                (unsigned int) dataflash_info[i].Device.pages_number *
                                dataflash_info[i].Device.pages_size,
                                (unsigned int) dataflash_info[i].logical_address);
-                       for (j=0; j< NB_DATAFLASH_AREA; j++) {
+                       for (j = 0; j < NB_DATAFLASH_AREA; j++) {
                                switch(dataflash_info[i].Device.area_list[j].protected) {
                                case    FLAG_PROTECT_SET:
                                case    FLAG_PROTECT_CLEAR:
@@ -245,7 +241,7 @@ AT91PS_DataFlash AT91F_DataflashSelect (AT91PS_DataFlash pFlash,
        char addr_valid = 0;
        int i;
 
-       for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++)
+       for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
                if ( dataflash_info[i].id
                        && ((((int) *addr) & 0xFF000000) ==
                        dataflash_info[i].logical_address)) {
@@ -271,7 +267,7 @@ int addr_dataflash (unsigned long addr)
        int addr_valid = 0;
        int i;
 
-       for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++) {
+       for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++) {
                if ((((int) addr) & 0xFF000000) ==
                        dataflash_info[i].logical_address) {
                        addr_valid = 1;
@@ -309,7 +305,7 @@ int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr)
        int area;
 
        /* find area */
-       for (area=0; area < NB_DATAFLASH_AREA; area++) {
+       for (area = 0; area < NB_DATAFLASH_AREA; area++) {
                if ((addr >= pdataFlash->pDevice->area_list[area].start) &&
                        (addr < pdataFlash->pDevice->area_list[area].end))
                        break;
@@ -336,7 +332,7 @@ int dataflash_real_protect (int flag, unsigned long start_addr,
        int i,j, area1, area2, addr_valid = 0;
 
        /* find dataflash */
-       for (i = 0; i < CFG_MAX_DATAFLASH_BANKS; i++) {
+       for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++) {
                if ((((int) start_addr) & 0xF0000000) ==
                        dataflash_info[i].logical_address) {
                                addr_valid = 1;
@@ -347,13 +343,13 @@ int dataflash_real_protect (int flag, unsigned long start_addr,
                return -1;
        }
        /* find start area */
-       for (area1=0; area1 < NB_DATAFLASH_AREA; area1++) {
+       for (area1 = 0; area1 < NB_DATAFLASH_AREA; area1++) {
                if (start_addr == dataflash_info[i].Device.area_list[area1].start)
                        break;
        }
        if (area1 == NB_DATAFLASH_AREA) return -1;
        /* find end area */
-       for (area2=0; area2 < NB_DATAFLASH_AREA; area2++) {
+       for (area2 = 0; area2 < NB_DATAFLASH_AREA; area2++) {
                if (end_addr == dataflash_info[i].Device.area_list[area2].end)
                        break;
        }
@@ -361,7 +357,7 @@ int dataflash_real_protect (int flag, unsigned long start_addr,
                return -1;
 
        /*set protection value*/
-       for(j = area1; j < area2+1 ; j++)
+       for(j = area1; j < area2 + 1 ; j++)
                if(dataflash_info[i].Device.area_list[j].protected
                                != FLAG_PROTECT_INVALID) {
                        if (flag == 0) {
@@ -373,7 +369,7 @@ int dataflash_real_protect (int flag, unsigned long start_addr,
                        }
                }
 
-       return (area2-area1+1);
+       return (area2 - area1 + 1);
 }
 
 /*---------------------------------------------------------------------------*/