Merge branch 'master' of git://www.denx.de/git/u-boot-sh
authorWolfgang Denk <wd@denx.de>
Thu, 27 Dec 2007 00:12:56 +0000 (01:12 +0100)
committerWolfgang Denk <wd@denx.de>
Thu, 27 Dec 2007 00:12:56 +0000 (01:12 +0100)
Conflicts:

MAINTAINERS

Signed-off-by: Wolfgang Denk <wd@denx.de>
45 files changed:
MAINTAINERS
MAKEALL
Makefile
README
board/cm5200/cm5200.c
board/ids8247/ids8247.c
common/Makefile
common/cmd_fdt.c
common/fdt_support.c
cpu/at32ap/at32ap7000/Makefile [deleted file]
cpu/at32ap/at32ap7000/gpio.c [deleted file]
cpu/at32ap/at32ap700x/Makefile [new file with mode: 0644]
cpu/at32ap/at32ap700x/gpio.c [new file with mode: 0644]
cpu/at32ap/atmel_mci.c
cpu/mpc83xx/cpu.c
drivers/mtd/Makefile
drivers/mtd/cfi_flash.c
drivers/mtd/jedec_flash.c [new file with mode: 0644]
include/asm-arm/io.h
include/asm-avr32/arch-at32ap7000/clk.h [deleted file]
include/asm-avr32/arch-at32ap7000/gpio.h [deleted file]
include/asm-avr32/arch-at32ap7000/hmatrix2.h [deleted file]
include/asm-avr32/arch-at32ap7000/memory-map.h [deleted file]
include/asm-avr32/arch-at32ap7000/mmc.h [deleted file]
include/asm-avr32/arch-at32ap700x/chip-features.h [new file with mode: 0644]
include/asm-avr32/arch-at32ap700x/clk.h [new file with mode: 0644]
include/asm-avr32/arch-at32ap700x/gpio.h [new file with mode: 0644]
include/asm-avr32/arch-at32ap700x/hmatrix2.h [new file with mode: 0644]
include/asm-avr32/arch-at32ap700x/memory-map.h [new file with mode: 0644]
include/asm-avr32/arch-at32ap700x/mmc.h [new file with mode: 0644]
include/asm-avr32/io.h
include/asm-blackfin/io.h
include/asm-i386/io.h
include/asm-m68k/io.h
include/asm-microblaze/io.h
include/asm-mips/io.h
include/asm-nios/io.h
include/asm-nios2/io.h
include/asm-ppc/io.h
include/configs/atstk1003.h [new file with mode: 0644]
include/configs/atstk1004.h [new file with mode: 0644]
include/fdt_support.h
include/flash.h
lib_avr32/board.c
lib_avr32/interrupts.c

index ec5e400ffc49e3ab3029708c5416753a0c46ddf8..5c68e5d74dca1d0dfe95ef485fd5683080f7e9a9 100644 (file)
@@ -630,7 +630,10 @@ Hayden Fraser <Hayden.Fraser@freescale.com>
 
 Haavard Skinnemoen <hskinnemoen@atmel.com>
 
-       ATSTK1000               AT32AP7000
+       ATSTK1000               AT32AP7xxx
+       ATSTK1002               AT32AP7000
+       ATSTK1003               AT32AP7001
+       ATSTK1004               AT32AP7002
  
 #########################################################################
 # SuperH Systems:                                                      #
diff --git a/MAKEALL b/MAKEALL
index fce70eb233b12d602bf1487ab2581aca6f733ee5..228a4b772018ec7654889c3509ac16b9defb197a 100755 (executable)
--- a/MAKEALL
+++ b/MAKEALL
@@ -642,6 +642,8 @@ LIST_coldfire="                     \
 
 LIST_avr32="           \
        atstk1002       \
+       atstk1003       \
+       atstk1004       \
 "
 
 #########################################################################
index b32bd3badc7fe683e824de023b902cd06f61c424..4519ac05d9ade2fec8f8f1dea73a6c1e751ec7f1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2659,7 +2659,13 @@ bf561-ezkit_config:      unconfig
 #########################################################################
 
 atstk1002_config       :       unconfig
-       @$(MKCONFIG) $(@:_config=) avr32 at32ap atstk1000 atmel at32ap7000
+       @$(MKCONFIG) $(@:_config=) avr32 at32ap atstk1000 atmel at32ap700x
+
+atstk1003_config       :       unconfig
+       @$(MKCONFIG) $(@:_config=) avr32 at32ap atstk1000 atmel at32ap700x
+
+atstk1004_config       :       unconfig
+       @$(MKCONFIG) $(@:_config=) avr32 at32ap atstk1000 atmel at32ap700x
 
 #########################################################################
 #########################################################################
diff --git a/README b/README
index 3dad5fc726f76e72eaa797a31370cca8348e03b3..26f93c21a769d0ccfd4dff6ba0a63a5a8b8dec2a 100644 (file)
--- a/README
+++ b/README
@@ -235,9 +235,7 @@ The following options need to be configured:
 - Board Type:  Define exactly one, e.g. CONFIG_MPC8540ADS.
 
 - CPU Daughterboard Type: (if CONFIG_ATSTK1000 is defined)
-               Define exactly one of
-               CONFIG_ATSTK1002
-
+               Define exactly one, e.g. CONFIG_ATSTK1002
 
 - CPU Module Type: (if CONFIG_COGENT is defined)
                Define exactly one of
index 4a86d3c5527b652ec2c339f32a7072010d67a745..79fb71dc704ee3f997b64694a228edbc155f15c6 100644 (file)
@@ -263,7 +263,6 @@ static void ft_blob_update(void *blob, bd_t *bd)
 {
        int len, ret, nodeoffset = 0;
        char module_name[MODULE_NAME_MAXLEN] = {0};
-       ulong memory_data[2] = {0};
 
        compose_module_name(hw_id, module_name);
        len = strlen(module_name) + 1;
@@ -273,22 +272,12 @@ static void ft_blob_update(void *blob, bd_t *bd)
        printf("ft_blob_update(): cannot set /model property err:%s\n",
                fdt_strerror(ret));
 
-       memory_data[0] = cpu_to_be32(bd->bi_memstart);
-       memory_data[1] = cpu_to_be32(bd->bi_memsize);
+       ret = fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
 
-       nodeoffset = fdt_path_offset (blob, "/memory");
-       if (nodeoffset >= 0) {
-               ret = fdt_setprop(blob, nodeoffset, "reg", memory_data,
-                                       sizeof(memory_data));
-       if (ret < 0)
+       if (ret < 0) {
                printf("ft_blob_update): cannot set /memory/reg "
                        "property err:%s\n", fdt_strerror(ret));
        }
-       else {
-               /* memory node is required in dts */
-               printf("ft_blob_update(): cannot find /memory node "
-               "err:%s\n", fdt_strerror(nodeoffset));
-       }
 }
 #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */
 
index b05424d32b29a2cf3120445dc2d0da2f6bd398ad..7176770f6854731c7b9871bc5598c987f44a594d 100644 (file)
@@ -329,25 +329,14 @@ nand_init (void)
  */
 void ft_blob_update(void *blob, bd_t *bd)
 {
-       int ret, nodeoffset = 0;
-       ulong memory_data[2] = {0};
+       int ret;
 
-       memory_data[0] = cpu_to_be32(bd->bi_memstart);
-       memory_data[1] = cpu_to_be32(bd->bi_memsize);
+       ret = fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
 
-       nodeoffset = fdt_find_node_by_path (blob, "/memory");
-       if (nodeoffset >= 0) {
-               ret = fdt_setprop(blob, nodeoffset, "reg", memory_data,
-                                       sizeof(memory_data));
-       if (ret < 0)
+       if (ret < 0) {
                printf("ft_blob_update): cannot set /memory/reg "
                        "property err:%s\n", fdt_strerror(ret));
        }
-       else {
-               /* memory node is required in dts */
-               printf("ft_blob_update(): cannot find /memory node "
-               "err:%s\n", fdt_strerror(nodeoffset));
-       }
 }
 
 void ft_board_setup(void *blob, bd_t *bd)
index ace8cc7edc0663cd250c5ffebaab57aa344676e5..7be89a41c6e0addc2519efad7336a72d2dd7e63e 100644 (file)
@@ -55,7 +55,7 @@ COBJS-$(CONFIG_CMD_ELF) += cmd_elf.o
 COBJS-$(CONFIG_CMD_EXT2) += cmd_ext2.o
 COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o
 COBJS-y += cmd_fdc.o
-COBJS-$(CONFIG_OF_LIBFDT) += cmd_fdt.o
+COBJS-$(CONFIG_OF_LIBFDT) += cmd_fdt.o fdt_support.o
 COBJS-$(CONFIG_CMD_FDOS) += cmd_fdos.o
 COBJS-$(CONFIG_CMD_FLASH) += cmd_flash.o
 ifdef CONFIG_FPGA
@@ -105,7 +105,6 @@ COBJS-y += env_onenand.o
 COBJS-y += env_nvram.o
 COBJS-y += env_nowhere.o
 COBJS-y += exports.o
-COBJS-y += fdt_support.o
 COBJS-y += flash.o
 COBJS-y += fpga.o
 COBJS-y += ft_build.o
index 629c9b413ea6524cfebd565240ef098ace230ca8..4639126536bea5ad5c6eb24fb03eb18b0a26a887 100644 (file)
@@ -588,7 +588,7 @@ static int fdt_print(const char *pathp, char *prop, int depth)
                        printf("%s %s\n", pathp, prop);
                        return 0;
                } else if (len > 0) {
-                       printf("%s=", prop);
+                       printf("%s = ", prop);
                        print_data (nodep, len);
                        printf("\n");
                        return 0;
@@ -649,7 +649,7 @@ static int fdt_print(const char *pathp, char *prop, int depth)
                                                pathp);
                        } else {
                                if (level <= depth) {
-                                       printf("%s%s=",
+                                       printf("%s%s = ",
                                                &tabs[MAX_LEVEL - level],
                                                pathp);
                                        print_data (nodep, len);
index c67bb3d390f4f4524679bbec4c450b605c347a2a..b5ee6e9601bf5322aa1216371f870af1f7e0bbd4 100644 (file)
 #include <common.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
-
-#ifdef CONFIG_OF_LIBFDT
-
 #include <asm/global_data.h>
 #include <fdt.h>
 #include <libfdt.h>
 #include <fdt_support.h>
+#include <exports.h>
 
 /*
  * Global data (for the gd->bd)
@@ -70,6 +68,43 @@ int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
        return fdt_setprop(fdt, nodeoff, prop, val, len);
 }
 
+#ifdef CONFIG_OF_STDOUT_VIA_ALIAS
+static int fdt_fixup_stdout(void *fdt, int choosenoff)
+{
+       int err = 0;
+#ifdef CONFIG_CONS_INDEX
+       int node;
+       char sername[9] = { 0 };
+       const char *path;
+
+       sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1);
+
+       err = node = fdt_path_offset(fdt, "/aliases");
+       if (node >= 0) {
+               int len;
+               path = fdt_getprop(fdt, node, sername, &len);
+               if (path) {
+                       char *p = malloc(len);
+                       err = -FDT_ERR_NOSPACE;
+                       if (p) {
+                               memcpy(p, path, len);
+                               err = fdt_setprop(fdt, choosenoff,
+                                       "linux,stdout-path", p, len);
+                               free(p);
+                       }
+               } else {
+                       err = len;
+               }
+       }
+#endif
+       if (err < 0)
+               printf("WARNING: could not set linux,stdout-path %s.\n",
+                               fdt_strerror(err));
+
+       return err;
+}
+#endif
+
 int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 {
        int   nodeoffset;
@@ -160,6 +195,11 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
                        printf("WARNING: could not set linux,initrd-end %s.\n",
                                fdt_strerror(err));
        }
+
+#ifdef CONFIG_OF_STDOUT_VIA_ALIAS
+       err = fdt_fixup_stdout(fdt, nodeoffset);
+#endif
+
 #ifdef OF_STDOUT_PATH
        err = fdt_setprop(fdt, nodeoffset,
                "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1);
@@ -441,6 +481,87 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat,
        do_fixup_by_compat(fdt, compat, prop, &val, 4, create);
 }
 
+int fdt_fixup_memory(void *blob, u64 start, u64 size)
+{
+       int err, nodeoffset, len = 0;
+       u8 tmp[16];
+       const u32 *addrcell, *sizecell;
+
+       err = fdt_check_header(blob);
+       if (err < 0) {
+               printf("%s: %s\n", __FUNCTION__, fdt_strerror(err));
+               return err;
+       }
+
+       /* update, or add and update /memory node */
+       nodeoffset = fdt_path_offset(blob, "/memory");
+       if (nodeoffset < 0) {
+               nodeoffset = fdt_add_subnode(blob, 0, "memory");
+               if (nodeoffset < 0)
+                       printf("WARNING: could not create /memory: %s.\n",
+                                       fdt_strerror(nodeoffset));
+               return nodeoffset;
+       }
+       err = fdt_setprop(blob, nodeoffset, "device_type", "memory",
+                       sizeof("memory"));
+       if (err < 0) {
+               printf("WARNING: could not set %s %s.\n", "device_type",
+                               fdt_strerror(err));
+               return err;
+       }
+
+       addrcell = fdt_getprop(blob, 0, "#address-cells", NULL);
+       /* use shifts and mask to ensure endianness */
+       if ((addrcell) && (*addrcell == 2)) {
+               tmp[0] = (start >> 56) & 0xff;
+               tmp[1] = (start >> 48) & 0xff;
+               tmp[2] = (start >> 40) & 0xff;
+               tmp[3] = (start >> 32) & 0xff;
+               tmp[4] = (start >> 24) & 0xff;
+               tmp[5] = (start >> 16) & 0xff;
+               tmp[6] = (start >>  8) & 0xff;
+               tmp[7] = (start      ) & 0xff;
+               len = 8;
+       } else {
+               tmp[0] = (start >> 24) & 0xff;
+               tmp[1] = (start >> 16) & 0xff;
+               tmp[2] = (start >>  8) & 0xff;
+               tmp[3] = (start      ) & 0xff;
+               len = 4;
+       }
+
+       sizecell = fdt_getprop(blob, 0, "#size-cells", NULL);
+       /* use shifts and mask to ensure endianness */
+       if ((sizecell) && (*sizecell == 2)) {
+               tmp[0+len] = (size >> 56) & 0xff;
+               tmp[1+len] = (size >> 48) & 0xff;
+               tmp[2+len] = (size >> 40) & 0xff;
+               tmp[3+len] = (size >> 32) & 0xff;
+               tmp[4+len] = (size >> 24) & 0xff;
+               tmp[5+len] = (size >> 16) & 0xff;
+               tmp[6+len] = (size >>  8) & 0xff;
+               tmp[7+len] = (size      ) & 0xff;
+               len += 8;
+       } else {
+               tmp[0+len] = (size >> 24) & 0xff;
+               tmp[1+len] = (size >> 16) & 0xff;
+               tmp[2+len] = (size >>  8) & 0xff;
+               tmp[3+len] = (size      ) & 0xff;
+               len += 4;
+       }
+
+       err = fdt_setprop(blob, nodeoffset, "reg", tmp, len);
+       if (err < 0) {
+               printf("WARNING: could not set %s %s.\n",
+                               "reg", fdt_strerror(err));
+               return err;
+       }
+       return 0;
+}
+
+#if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
+    defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
+
 void fdt_fixup_ethernet(void *fdt, bd_t *bd)
 {
        int node;
@@ -486,5 +607,4 @@ void fdt_fixup_ethernet(void *fdt, bd_t *bd)
 #endif
        }
 }
-
-#endif /* CONFIG_OF_LIBFDT */
+#endif
diff --git a/cpu/at32ap/at32ap7000/Makefile b/cpu/at32ap/at32ap7000/Makefile
deleted file mode 100644 (file)
index d276712..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Copyright (C) 2005-2006 Atmel Corporation
-#
-# 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 $(TOPDIR)/config.mk
-
-LIB    := $(obj)lib$(SOC).a
-
-COBJS  := gpio.o
-SRCS   := $(SOBJS:.o=.S) $(COBJS:.o=.c)
-OBJS   := $(addprefix $(obj),$(SOBJS) $(COBJS))
-
-all: $(obj).depend $(LIB)
-
-$(LIB): $(OBJS)
-       $(AR) $(ARFLAGS) $@ $^
-
-#########################################################################
-
-# defines $(obj).depend target
-include $(SRCTREE)/rules.mk
-
-sinclude $(obj).depend
-
-#########################################################################
diff --git a/cpu/at32ap/at32ap7000/gpio.c b/cpu/at32ap/at32ap7000/gpio.c
deleted file mode 100644 (file)
index 52f5372..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2006 Atmel Corporation
- *
- * 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 <asm/arch/gpio.h>
-
-/*
- * Lots of small functions here. We depend on --gc-sections getting
- * rid of the ones we don't need.
- */
-void gpio_enable_ebi(void)
-{
-#ifdef CFG_HSDRAMC
-#ifndef CFG_SDRAM_16BIT
-       gpio_select_periph_A(GPIO_PIN_PE0, 0);
-       gpio_select_periph_A(GPIO_PIN_PE1, 0);
-       gpio_select_periph_A(GPIO_PIN_PE2, 0);
-       gpio_select_periph_A(GPIO_PIN_PE3, 0);
-       gpio_select_periph_A(GPIO_PIN_PE4, 0);
-       gpio_select_periph_A(GPIO_PIN_PE5, 0);
-       gpio_select_periph_A(GPIO_PIN_PE6, 0);
-       gpio_select_periph_A(GPIO_PIN_PE7, 0);
-       gpio_select_periph_A(GPIO_PIN_PE8, 0);
-       gpio_select_periph_A(GPIO_PIN_PE9, 0);
-       gpio_select_periph_A(GPIO_PIN_PE10, 0);
-       gpio_select_periph_A(GPIO_PIN_PE11, 0);
-       gpio_select_periph_A(GPIO_PIN_PE12, 0);
-       gpio_select_periph_A(GPIO_PIN_PE13, 0);
-       gpio_select_periph_A(GPIO_PIN_PE14, 0);
-       gpio_select_periph_A(GPIO_PIN_PE15, 0);
-#endif
-       gpio_select_periph_A(GPIO_PIN_PE26, 0);
-#endif
-}
-
-void gpio_enable_usart0(void)
-{
-       gpio_select_periph_B(GPIO_PIN_PA8, 0);
-       gpio_select_periph_B(GPIO_PIN_PA9, 0);
-}
-
-void gpio_enable_usart1(void)
-{
-       gpio_select_periph_A(GPIO_PIN_PA17, 0);
-       gpio_select_periph_A(GPIO_PIN_PA18, 0);
-}
-
-void gpio_enable_usart2(void)
-{
-       gpio_select_periph_B(GPIO_PIN_PB26, 0);
-       gpio_select_periph_B(GPIO_PIN_PB27, 0);
-}
-
-void gpio_enable_usart3(void)
-{
-       gpio_select_periph_B(GPIO_PIN_PB18, 0);
-       gpio_select_periph_B(GPIO_PIN_PB19, 0);
-}
-
-void gpio_enable_macb0(void)
-{
-       gpio_select_periph_A(GPIO_PIN_PC3,  0); /* TXD0 */
-       gpio_select_periph_A(GPIO_PIN_PC4,  0); /* TXD1 */
-       gpio_select_periph_A(GPIO_PIN_PC7,  0); /* TXEN */
-       gpio_select_periph_A(GPIO_PIN_PC8,  0); /* TXCK */
-       gpio_select_periph_A(GPIO_PIN_PC9,  0); /* RXD0 */
-       gpio_select_periph_A(GPIO_PIN_PC10, 0); /* RXD1 */
-       gpio_select_periph_A(GPIO_PIN_PC13, 0); /* RXER */
-       gpio_select_periph_A(GPIO_PIN_PC15, 0); /* RXDV */
-       gpio_select_periph_A(GPIO_PIN_PC16, 0); /* MDC  */
-       gpio_select_periph_A(GPIO_PIN_PC17, 0); /* MDIO */
-#if !defined(CONFIG_RMII)
-       gpio_select_periph_A(GPIO_PIN_PC0,  0); /* COL  */
-       gpio_select_periph_A(GPIO_PIN_PC1,  0); /* CRS  */
-       gpio_select_periph_A(GPIO_PIN_PC2,  0); /* TXER */
-       gpio_select_periph_A(GPIO_PIN_PC5,  0); /* TXD2 */
-       gpio_select_periph_A(GPIO_PIN_PC6,  0); /* TXD3 */
-       gpio_select_periph_A(GPIO_PIN_PC11, 0); /* RXD2 */
-       gpio_select_periph_A(GPIO_PIN_PC12, 0); /* RXD3 */
-       gpio_select_periph_A(GPIO_PIN_PC14, 0); /* RXCK */
-       gpio_select_periph_A(GPIO_PIN_PC18, 0); /* SPD  */
-#endif
-}
-
-void gpio_enable_macb1(void)
-{
-       gpio_select_periph_B(GPIO_PIN_PD13, 0); /* TXD0 */
-       gpio_select_periph_B(GPIO_PIN_PD14, 0); /* TXD1 */
-       gpio_select_periph_B(GPIO_PIN_PD11, 0); /* TXEN */
-       gpio_select_periph_B(GPIO_PIN_PD12, 0); /* TXCK */
-       gpio_select_periph_B(GPIO_PIN_PD10, 0); /* RXD0 */
-       gpio_select_periph_B(GPIO_PIN_PD6,  0); /* RXD1 */
-       gpio_select_periph_B(GPIO_PIN_PD5,  0); /* RXER */
-       gpio_select_periph_B(GPIO_PIN_PD4,  0); /* RXDV */
-       gpio_select_periph_B(GPIO_PIN_PD3,  0); /* MDC  */
-       gpio_select_periph_B(GPIO_PIN_PD2,  0); /* MDIO */
-#if !defined(CONFIG_RMII)
-       gpio_select_periph_B(GPIO_PIN_PC19, 0); /* COL  */
-       gpio_select_periph_B(GPIO_PIN_PC23, 0); /* CRS  */
-       gpio_select_periph_B(GPIO_PIN_PC26, 0); /* TXER */
-       gpio_select_periph_B(GPIO_PIN_PC27, 0); /* TXD2 */
-       gpio_select_periph_B(GPIO_PIN_PC28, 0); /* TXD3 */
-       gpio_select_periph_B(GPIO_PIN_PC29, 0); /* RXD2 */
-       gpio_select_periph_B(GPIO_PIN_PC30, 0); /* RXD3 */
-       gpio_select_periph_B(GPIO_PIN_PC24, 0); /* RXCK */
-       gpio_select_periph_B(GPIO_PIN_PD15, 0); /* SPD  */
-#endif
-}
-
-void gpio_enable_mmci(void)
-{
-       gpio_select_periph_A(GPIO_PIN_PA10, 0); /* CLK   */
-       gpio_select_periph_A(GPIO_PIN_PA11, 0); /* CMD   */
-       gpio_select_periph_A(GPIO_PIN_PA12, 0); /* DATA0 */
-       gpio_select_periph_A(GPIO_PIN_PA13, 0); /* DATA1 */
-       gpio_select_periph_A(GPIO_PIN_PA14, 0); /* DATA2 */
-       gpio_select_periph_A(GPIO_PIN_PA15, 0); /* DATA3 */
-}
diff --git a/cpu/at32ap/at32ap700x/Makefile b/cpu/at32ap/at32ap700x/Makefile
new file mode 100644 (file)
index 0000000..d276712
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2005-2006 Atmel Corporation
+#
+# 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 $(TOPDIR)/config.mk
+
+LIB    := $(obj)lib$(SOC).a
+
+COBJS  := gpio.o
+SRCS   := $(SOBJS:.o=.S) $(COBJS:.o=.c)
+OBJS   := $(addprefix $(obj),$(SOBJS) $(COBJS))
+
+all: $(obj).depend $(LIB)
+
+$(LIB): $(OBJS)
+       $(AR) $(ARFLAGS) $@ $^
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
diff --git a/cpu/at32ap/at32ap700x/gpio.c b/cpu/at32ap/at32ap700x/gpio.c
new file mode 100644 (file)
index 0000000..859124a
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2006 Atmel Corporation
+ *
+ * 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 <asm/arch/chip-features.h>
+#include <asm/arch/gpio.h>
+
+/*
+ * Lots of small functions here. We depend on --gc-sections getting
+ * rid of the ones we don't need.
+ */
+void gpio_enable_ebi(void)
+{
+#ifdef CFG_HSDRAMC
+#ifndef CFG_SDRAM_16BIT
+       gpio_select_periph_A(GPIO_PIN_PE0, 0);
+       gpio_select_periph_A(GPIO_PIN_PE1, 0);
+       gpio_select_periph_A(GPIO_PIN_PE2, 0);
+       gpio_select_periph_A(GPIO_PIN_PE3, 0);
+       gpio_select_periph_A(GPIO_PIN_PE4, 0);
+       gpio_select_periph_A(GPIO_PIN_PE5, 0);
+       gpio_select_periph_A(GPIO_PIN_PE6, 0);
+       gpio_select_periph_A(GPIO_PIN_PE7, 0);
+       gpio_select_periph_A(GPIO_PIN_PE8, 0);
+       gpio_select_periph_A(GPIO_PIN_PE9, 0);
+       gpio_select_periph_A(GPIO_PIN_PE10, 0);
+       gpio_select_periph_A(GPIO_PIN_PE11, 0);
+       gpio_select_periph_A(GPIO_PIN_PE12, 0);
+       gpio_select_periph_A(GPIO_PIN_PE13, 0);
+       gpio_select_periph_A(GPIO_PIN_PE14, 0);
+       gpio_select_periph_A(GPIO_PIN_PE15, 0);
+#endif
+       gpio_select_periph_A(GPIO_PIN_PE26, 0);
+#endif
+}
+
+#ifdef AT32AP700x_CHIP_HAS_USART
+void gpio_enable_usart0(void)
+{
+       gpio_select_periph_B(GPIO_PIN_PA8, 0);
+       gpio_select_periph_B(GPIO_PIN_PA9, 0);
+}
+
+void gpio_enable_usart1(void)
+{
+       gpio_select_periph_A(GPIO_PIN_PA17, 0);
+       gpio_select_periph_A(GPIO_PIN_PA18, 0);
+}
+
+void gpio_enable_usart2(void)
+{
+       gpio_select_periph_B(GPIO_PIN_PB26, 0);
+       gpio_select_periph_B(GPIO_PIN_PB27, 0);
+}
+
+void gpio_enable_usart3(void)
+{
+       gpio_select_periph_B(GPIO_PIN_PB17, 0);
+       gpio_select_periph_B(GPIO_PIN_PB18, 0);
+}
+#endif
+
+#ifdef AT32AP700x_CHIP_HAS_MACB
+void gpio_enable_macb0(void)
+{
+       gpio_select_periph_A(GPIO_PIN_PC3,  0); /* TXD0 */
+       gpio_select_periph_A(GPIO_PIN_PC4,  0); /* TXD1 */
+       gpio_select_periph_A(GPIO_PIN_PC7,  0); /* TXEN */
+       gpio_select_periph_A(GPIO_PIN_PC8,  0); /* TXCK */
+       gpio_select_periph_A(GPIO_PIN_PC9,  0); /* RXD0 */
+       gpio_select_periph_A(GPIO_PIN_PC10, 0); /* RXD1 */
+       gpio_select_periph_A(GPIO_PIN_PC13, 0); /* RXER */
+       gpio_select_periph_A(GPIO_PIN_PC15, 0); /* RXDV */
+       gpio_select_periph_A(GPIO_PIN_PC16, 0); /* MDC  */
+       gpio_select_periph_A(GPIO_PIN_PC17, 0); /* MDIO */
+#if !defined(CONFIG_RMII)
+       gpio_select_periph_A(GPIO_PIN_PC0,  0); /* COL  */
+       gpio_select_periph_A(GPIO_PIN_PC1,  0); /* CRS  */
+       gpio_select_periph_A(GPIO_PIN_PC2,  0); /* TXER */
+       gpio_select_periph_A(GPIO_PIN_PC5,  0); /* TXD2 */
+       gpio_select_periph_A(GPIO_PIN_PC6,  0); /* TXD3 */
+       gpio_select_periph_A(GPIO_PIN_PC11, 0); /* RXD2 */
+       gpio_select_periph_A(GPIO_PIN_PC12, 0); /* RXD3 */
+       gpio_select_periph_A(GPIO_PIN_PC14, 0); /* RXCK */
+       gpio_select_periph_A(GPIO_PIN_PC18, 0); /* SPD  */
+#endif
+}
+
+void gpio_enable_macb1(void)
+{
+       gpio_select_periph_B(GPIO_PIN_PD13, 0); /* TXD0 */
+       gpio_select_periph_B(GPIO_PIN_PD14, 0); /* TXD1 */
+       gpio_select_periph_B(GPIO_PIN_PD11, 0); /* TXEN */
+       gpio_select_periph_B(GPIO_PIN_PD12, 0); /* TXCK */
+       gpio_select_periph_B(GPIO_PIN_PD10, 0); /* RXD0 */
+       gpio_select_periph_B(GPIO_PIN_PD6,  0); /* RXD1 */
+       gpio_select_periph_B(GPIO_PIN_PD5,  0); /* RXER */
+       gpio_select_periph_B(GPIO_PIN_PD4,  0); /* RXDV */
+       gpio_select_periph_B(GPIO_PIN_PD3,  0); /* MDC  */
+       gpio_select_periph_B(GPIO_PIN_PD2,  0); /* MDIO */
+#if !defined(CONFIG_RMII)
+       gpio_select_periph_B(GPIO_PIN_PC19, 0); /* COL  */
+       gpio_select_periph_B(GPIO_PIN_PC23, 0); /* CRS  */
+       gpio_select_periph_B(GPIO_PIN_PC26, 0); /* TXER */
+       gpio_select_periph_B(GPIO_PIN_PC27, 0); /* TXD2 */
+       gpio_select_periph_B(GPIO_PIN_PC28, 0); /* TXD3 */
+       gpio_select_periph_B(GPIO_PIN_PC29, 0); /* RXD2 */
+       gpio_select_periph_B(GPIO_PIN_PC30, 0); /* RXD3 */
+       gpio_select_periph_B(GPIO_PIN_PC24, 0); /* RXCK */
+       gpio_select_periph_B(GPIO_PIN_PD15, 0); /* SPD  */
+#endif
+}
+#endif
+
+#ifdef AT32AP700x_CHIP_HAS_MMCI
+void gpio_enable_mmci(void)
+{
+       gpio_select_periph_A(GPIO_PIN_PA10, 0); /* CLK   */
+       gpio_select_periph_A(GPIO_PIN_PA11, 0); /* CMD   */
+       gpio_select_periph_A(GPIO_PIN_PA12, 0); /* DATA0 */
+       gpio_select_periph_A(GPIO_PIN_PA13, 0); /* DATA1 */
+       gpio_select_periph_A(GPIO_PIN_PA14, 0); /* DATA2 */
+       gpio_select_periph_A(GPIO_PIN_PA15, 0); /* DATA3 */
+}
+#endif
index cf48be10ba4d44795aadef6afda5cdfa0df30f22..f59dfb5995e1c7d3dfc6b987d586b93fb0aeba90 100644 (file)
@@ -198,11 +198,11 @@ mmc_bread(int dev, unsigned long start, lbaint_t blkcnt,
 
        /* Put the device into Transfer state */
        ret = mmc_cmd(MMC_CMD_SELECT_CARD, mmc_rca << 16, resp, R1 | NCR);
-       if (ret) goto fail;
+       if (ret) goto out;
 
        /* Set block length */
        ret = mmc_cmd(MMC_CMD_SET_BLOCKLEN, mmc_blkdev.blksz, resp, R1 | NCR);
-       if (ret) goto fail;
+       if (ret) goto out;
 
        pr_debug("MCI_DTOR = %08lx\n", mmci_readl(DTOR));
 
@@ -211,7 +211,7 @@ mmc_bread(int dev, unsigned long start, lbaint_t blkcnt,
                              start * mmc_blkdev.blksz, resp,
                              (R1 | NCR | TRCMD_START | TRDIR_READ
                               | TRTYP_BLOCK));
-               if (ret) goto fail;
+               if (ret) goto out;
 
                ret = -EIO;
                wordcount = 0;
@@ -219,7 +219,7 @@ mmc_bread(int dev, unsigned long start, lbaint_t blkcnt,
                        do {
                                status = mmci_readl(SR);
                                if (status & (ERROR_FLAGS | MMCI_BIT(OVRE)))
-                                       goto fail;
+                                       goto read_error;
                        } while (!(status & MMCI_BIT(RXRDY)));
 
                        if (status & MMCI_BIT(RXRDY)) {
@@ -244,9 +244,10 @@ out:
        mmc_cmd(MMC_CMD_SELECT_CARD, 0, resp, NCR);
        return i;
 
-fail:
+read_error:
        mmc_cmd(MMC_CMD_SEND_STATUS, mmc_rca << 16, &card_status, R1 | NCR);
-       printf("mmc: bread failed, card status = %08x\n", card_status);
+       printf("mmc: bread failed, status = %08x, card status = %08x\n",
+              status, card_status);
        goto out;
 }
 
index b2c35d3007c6dfe360f950c48893a69afe6a9204..f1ea17d5a52d331a8c5f7b9a2bc9f37310305158 100644 (file)
@@ -35,6 +35,7 @@
 #include <ft_build.h>
 #elif defined(CONFIG_OF_LIBFDT)
 #include <libfdt.h>
+#include <fdt_support.h>
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -526,7 +527,6 @@ ft_cpu_setup(void *blob, bd_t *bd)
        int nodeoffset;
        int err;
        int j;
-       int tmp[2];
 
        for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
                nodeoffset = fdt_path_offset(blob, fixup_props[j].node);
@@ -543,21 +543,7 @@ ft_cpu_setup(void *blob, bd_t *bd)
                }
        }
 
-       /* update, or add and update /memory node */
-       nodeoffset = fdt_path_offset(blob, "/memory");
-       if (nodeoffset < 0) {
-               nodeoffset = fdt_add_subnode(blob, 0, "memory");
-               if (nodeoffset < 0)
-                       debug("failed to add /memory node: %s\n",
-                             fdt_strerror(nodeoffset));
-       }
-       if (nodeoffset >= 0) {
-               fdt_setprop(blob, nodeoffset, "device_type",
-                           "memory", sizeof("memory"));
-               tmp[0] = cpu_to_be32(bd->bi_memstart);
-               tmp[1] = cpu_to_be32(bd->bi_memsize);
-               fdt_setprop(blob, nodeoffset, "reg", tmp, sizeof(tmp));
-       }
+       fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
 }
 #elif defined(CONFIG_OF_FLAT_TREE)
 void
index 95c5e02af9f6a88379c040df124cec6477223cf7..952e9198437059c540cce55a369138809cbfd204 100644 (file)
@@ -29,6 +29,7 @@ COBJS-y += at45.o
 COBJS-y += cfi_flash.o
 COBJS-y += dataflash.o
 COBJS-y += mw_eeprom.o
+COBJS-$(CONFIG_FLASH_CFI_LEGACY) += jedec_flash.o
 
 COBJS  := $(COBJS-y)
 SRCS   := $(COBJS:.o=.c)
index 5579a1efc155e3cb9d488af81d5262b2d2b19c95..f370e4fbd3f7d95f27eee193efc4689f0ed64322 100644 (file)
 #ifdef CFG_FLASH_CFI_DRIVER
 
 /*
- * This file implements a Common Flash Interface (CFI) driver for U-Boot.
- * The width of the port and the width of the chips are determined at initialization.
- * These widths are used to calculate the address for access CFI data structures.
+ * This file implements a Common Flash Interface (CFI) driver for
+ * U-Boot.
+ *
+ * The width of the port and the width of the chips are determined at
+ * initialization.  These widths are used to calculate the address for
+ * access CFI data structures.
  *
  * References
  * JEDEC Standard JESD68 - Common Flash Interface (CFI)
@@ -55,7 +58,7 @@
  * AMD/Spansion Application Note: Migration from Single-byte to Three-byte
  *   Device IDs, Publication Number 25538 Revision A, November 8, 2001
  *
- * define CFG_WRITE_SWAPPED_DATA, if you have to swap the Bytes between
+ * Define CFG_WRITE_SWAPPED_DATA, if you have to swap the Bytes between
  * reading and writing ... (yes there is such a Hardware).
  */
 
 #define AMD_STATUS_TOGGLE              0x40
 #define AMD_STATUS_ERROR               0x20
 
-#define AMD_ADDR_ERASE_START   ((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
-#define AMD_ADDR_START         ((info->portwidth == FLASH_CFI_8BIT) ? 0xAAA : 0x555)
-#define AMD_ADDR_ACK           ((info->portwidth == FLASH_CFI_8BIT) ? 0x555 : 0x2AA)
-
 #define FLASH_OFFSET_MANUFACTURER_ID   0x00
 #define FLASH_OFFSET_DEVICE_ID         0x01
 #define FLASH_OFFSET_DEVICE_ID2                0x0E
 #define FLASH_OFFSET_CFI_ALT           0x555
 #define FLASH_OFFSET_CFI_RESP          0x10
 #define FLASH_OFFSET_PRIMARY_VENDOR    0x13
-#define FLASH_OFFSET_EXT_QUERY_T_P_ADDR        0x15    /* extended query table primary addr */
+/* extended query table primary address */
+#define FLASH_OFFSET_EXT_QUERY_T_P_ADDR        0x15
 #define FLASH_OFFSET_WTOUT             0x1F
 #define FLASH_OFFSET_WBTOUT            0x20
 #define FLASH_OFFSET_ETOUT             0x21
@@ -149,16 +149,9 @@ typedef union {
        unsigned long long ll;
 } cfiword_t;
 
-typedef union {
-       volatile unsigned char *cp;
-       volatile unsigned short *wp;
-       volatile unsigned long *lp;
-       volatile unsigned long long *llp;
-} cfiptr_t;
-
 #define NUM_ERASE_REGIONS      4 /* max. number of erase regions */
 
-static uint flash_offset_cfi[2]={FLASH_OFFSET_CFI,FLASH_OFFSET_CFI_ALT};
+static uint flash_offset_cfi[2] = { FLASH_OFFSET_CFI, FLASH_OFFSET_CFI_ALT };
 
 /* use CFG_MAX_FLASH_BANKS_DETECT if defined */
 #ifdef CFG_MAX_FLASH_BANKS_DETECT
@@ -176,46 +169,151 @@ flash_info_t flash_info[CFG_MAX_FLASH_BANKS];            /* FLASH chips info */
 #define CFG_FLASH_CFI_WIDTH    FLASH_CFI_8BIT
 #endif
 
+typedef unsigned long flash_sect_t;
+
+/* CFI standard query structure */
+struct cfi_qry {
+       u8      qry[3];
+       u16     p_id;
+       u16     p_adr;
+       u16     a_id;
+       u16     a_adr;
+       u8      vcc_min;
+       u8      vcc_max;
+       u8      vpp_min;
+       u8      vpp_max;
+       u8      word_write_timeout_typ;
+       u8      buf_write_timeout_typ;
+       u8      block_erase_timeout_typ;
+       u8      chip_erase_timeout_typ;
+       u8      word_write_timeout_max;
+       u8      buf_write_timeout_max;
+       u8      block_erase_timeout_max;
+       u8      chip_erase_timeout_max;
+       u8      dev_size;
+       u16     interface_desc;
+       u16     max_buf_write_size;
+       u8      num_erase_regions;
+       u32     erase_region_info[NUM_ERASE_REGIONS];
+} __attribute__((packed));
+
+struct cfi_pri_hdr {
+       u8      pri[3];
+       u8      major_version;
+       u8      minor_version;
+} __attribute__((packed));
+
+static void flash_write8(u8 value, void *addr)
+{
+       __raw_writeb(value, addr);
+}
+
+static void flash_write16(u16 value, void *addr)
+{
+       __raw_writew(value, addr);
+}
+
+static void flash_write32(u32 value, void *addr)
+{
+       __raw_writel(value, addr);
+}
+
+static void flash_write64(u64 value, void *addr)
+{
+       /* No architectures currently implement __raw_writeq() */
+       *(volatile u64 *)addr = value;
+}
+
+static u8 flash_read8(void *addr)
+{
+       return __raw_readb(addr);
+}
+
+static u16 flash_read16(void *addr)
+{
+       return __raw_readw(addr);
+}
+
+static u32 flash_read32(void *addr)
+{
+       return __raw_readl(addr);
+}
+
+static u64 flash_read64(void *addr)
+{
+       /* No architectures currently implement __raw_readq() */
+       return *(volatile u64 *)addr;
+}
 
 /*-----------------------------------------------------------------------
- * Functions
  */
+#if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
+static flash_info_t *flash_get_info(ulong base)
+{
+       int i;
+       flash_info_t * info = 0;
 
-typedef unsigned long flash_sect_t;
+       for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) {
+               info = & flash_info[i];
+               if (info->size && info->start[0] <= base &&
+                   base <= info->start[0] + info->size - 1)
+                       break;
+       }
 
-static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c);
-static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf);
-static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
-static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect);
-static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
-static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
-static int flash_toggle (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd);
-static void flash_read_jedec_ids (flash_info_t * info);
-static int flash_detect_cfi (flash_info_t * info);
-static int flash_write_cfiword (flash_info_t * info, ulong dest, cfiword_t cword);
-static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
-                                   ulong tout, char *prompt);
-ulong flash_get_size (ulong base, int banknum);
-#if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
-static flash_info_t *flash_get_info(ulong base);
-#endif
-#ifdef CFG_FLASH_USE_BUFFER_WRITE
-static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, int len);
+       return i == CFG_MAX_FLASH_BANKS ? 0 : info;
+}
 #endif
 
+unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect)
+{
+       if (sect != (info->sector_count - 1))
+               return info->start[sect + 1] - info->start[sect];
+       else
+               return info->start[0] + info->size - info->start[sect];
+}
+
 /*-----------------------------------------------------------------------
  * create an address based on the offset and the port width
  */
-inline uchar *flash_make_addr (flash_info_t * info, flash_sect_t sect, uint offset)
+static inline void *
+flash_map (flash_info_t * info, flash_sect_t sect, uint offset)
+{
+       unsigned int byte_offset = offset * info->portwidth;
+
+       return map_physmem(info->start[sect] + byte_offset,
+                       flash_sector_size(info, sect) - byte_offset,
+                       MAP_NOCACHE);
+}
+
+static inline void flash_unmap(flash_info_t *info, flash_sect_t sect,
+               unsigned int offset, void *addr)
+{
+       unsigned int byte_offset = offset * info->portwidth;
+
+       unmap_physmem(addr, flash_sector_size(info, sect) - byte_offset);
+}
+
+/*-----------------------------------------------------------------------
+ * make a proper sized command based on the port and chip widths
+ */
+static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf)
 {
-       return ((uchar *) (info->start[sect] + (offset * info->portwidth)));
+       int i;
+       uchar *cp = (uchar *) cmdbuf;
+
+#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
+       for (i = info->portwidth; i > 0; i--)
+#else
+       for (i = 1; i <= info->portwidth; i++)
+#endif
+               *cp++ = (i & (info->chipwidth - 1)) ? '\0' : cmd;
 }
 
 #ifdef DEBUG
 /*-----------------------------------------------------------------------
  * Debug support
  */
-void print_longlong (char *str, unsigned long long data)
+static void print_longlong (char *str, unsigned long long data)
 {
        int i;
        char *cp;
@@ -224,28 +322,25 @@ void print_longlong (char *str, unsigned long long data)
        for (i = 0; i < 8; i++)
                sprintf (&str[i * 2], "%2.2x", *cp++);
 }
-static void flash_printqry (flash_info_t * info, flash_sect_t sect)
+
+static void flash_printqry (struct cfi_qry *qry)
 {
-       cfiptr_t cptr;
+       u8 *p = (u8 *)qry;
        int x, y;
 
-       for (x = 0; x < 0x40; x += 16U / info->portwidth) {
-               cptr.cp =
-                       flash_make_addr (info, sect,
-                                        x + FLASH_OFFSET_CFI_RESP);
-               debug ("%p : ", cptr.cp);
+       for (x = 0; x < sizeof(struct cfi_qry); x += 16) {
+               debug("%02x : ", x);
+               for (y = 0; y < 16; y++)
+                       debug("%2.2x ", p[x + y]);
+               debug(" ");
                for (y = 0; y < 16; y++) {
-                       debug ("%2.2x ", cptr.cp[y]);
-               }
-               debug (" ");
-               for (y = 0; y < 16; y++) {
-                       if (cptr.cp[y] >= 0x20 && cptr.cp[y] <= 0x7e) {
-                               debug ("%c", cptr.cp[y]);
-                       } else {
-                               debug (".");
-                       }
+                       unsigned char c = p[x + y];
+                       if (c >= 0x20 && c <= 0x7e)
+                               debug("%c", c);
+                       else
+                               debug(".");
                }
-               debug ("\n");
+               debug("\n");
        }
 }
 #endif
@@ -254,46 +349,18 @@ static void flash_printqry (flash_info_t * info, flash_sect_t sect)
 /*-----------------------------------------------------------------------
  * read a character at a port width address
  */
-inline uchar flash_read_uchar (flash_info_t * info, uint offset)
+static inline uchar flash_read_uchar (flash_info_t * info, uint offset)
 {
        uchar *cp;
+       uchar retval;
 
-       cp = flash_make_addr (info, 0, offset);
-#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
-       return (cp[0]);
-#else
-       return (cp[info->portwidth - 1]);
-#endif
-}
-
-/*-----------------------------------------------------------------------
- * read a short word by swapping for ppc format.
- */
-ushort flash_read_ushort (flash_info_t * info, flash_sect_t sect, uint offset)
-{
-       uchar *addr;
-       ushort retval;
-
-#ifdef DEBUG
-       int x;
-#endif
-       addr = flash_make_addr (info, sect, offset);
-
-#ifdef DEBUG
-       debug ("ushort addr is at %p info->portwidth = %d\n", addr,
-              info->portwidth);
-       for (x = 0; x < 2 * info->portwidth; x++) {
-               debug ("addr[%x] = 0x%x\n", x, addr[x]);
-       }
-#endif
+       cp = flash_map (info, 0, offset);
 #if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
-       retval = ((addr[(info->portwidth)] << 8) | addr[0]);
+       retval = flash_read8(cp);
 #else
-       retval = ((addr[(2 * info->portwidth) - 1] << 8) |
-                 addr[info->portwidth - 1]);
+       retval = flash_read8(cp + info->portwidth - 1);
 #endif
-
-       debug ("retval = 0x%x\n", retval);
+       flash_unmap (info, 0, offset, cp);
        return retval;
 }
 
@@ -301,7 +368,8 @@ ushort flash_read_ushort (flash_info_t * info, flash_sect_t sect, uint offset)
  * read a long word by picking the least significant byte of each maximum
  * port size word. Swap for ppc format.
  */
-ulong flash_read_long (flash_info_t * info, flash_sect_t sect, uint offset)
+static ulong flash_read_long (flash_info_t * info, flash_sect_t sect,
+                             uint offset)
 {
        uchar *addr;
        ulong retval;
@@ -309,163 +377,607 @@ ulong flash_read_long (flash_info_t * info, flash_sect_t sect, uint offset)
 #ifdef DEBUG
        int x;
 #endif
-       addr = flash_make_addr (info, sect, offset);
+       addr = flash_map (info, sect, offset);
 
 #ifdef DEBUG
        debug ("long addr is at %p info->portwidth = %d\n", addr,
               info->portwidth);
        for (x = 0; x < 4 * info->portwidth; x++) {
-               debug ("addr[%x] = 0x%x\n", x, addr[x]);
+               debug ("addr[%x] = 0x%x\n", x, flash_read8(addr + x));
        }
 #endif
 #if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
-       retval = (addr[0] << 16) | (addr[(info->portwidth)] << 24) |
-               (addr[(2 * info->portwidth)]) | (addr[(3 * info->portwidth)] << 8);
+       retval = ((flash_read8(addr) << 16) |
+                 (flash_read8(addr + info->portwidth) << 24) |
+                 (flash_read8(addr + 2 * info->portwidth)) |
+                 (flash_read8(addr + 3 * info->portwidth) << 8));
 #else
-       retval = (addr[(2 * info->portwidth) - 1] << 24) |
-               (addr[(info->portwidth) - 1] << 16) |
-               (addr[(4 * info->portwidth) - 1] << 8) |
-               addr[(3 * info->portwidth) - 1];
+       retval = ((flash_read8(addr + 2 * info->portwidth - 1) << 24) |
+                 (flash_read8(addr + info->portwidth - 1) << 16) |
+                 (flash_read8(addr + 4 * info->portwidth - 1) << 8) |
+                 (flash_read8(addr + 3 * info->portwidth - 1)));
 #endif
+       flash_unmap(info, sect, offset, addr);
+
        return retval;
 }
 
-
-/*-----------------------------------------------------------------------
+/*
+ * Write a proper sized command to the correct address
  */
-unsigned long flash_init (void)
+static void flash_write_cmd (flash_info_t * info, flash_sect_t sect,
+                            uint offset, uchar cmd)
 {
-       unsigned long size = 0;
-       int i;
-
-#ifdef CFG_FLASH_PROTECTION
-       char *s = getenv("unlock");
-#endif
-
-       /* Init: no FLASHes known */
-       for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
-               flash_info[i].flash_id = FLASH_UNKNOWN;
-               size += flash_info[i].size = flash_get_size (bank_base[i], i);
-               if (flash_info[i].flash_id == FLASH_UNKNOWN) {
-#ifndef CFG_FLASH_QUIET_TEST
-                       printf ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
-                               i+1, flash_info[i].size, flash_info[i].size << 20);
-#endif /* CFG_FLASH_QUIET_TEST */
-               }
-#ifdef CFG_FLASH_PROTECTION
-               else if ((s != NULL) && (strcmp(s, "yes") == 0)) {
-                       /*
-                        * Only the U-Boot image and it's environment is protected,
-                        * all other sectors are unprotected (unlocked) if flash
-                        * hardware protection is used (CFG_FLASH_PROTECTION) and
-                        * the environment variable "unlock" is set to "yes".
-                        */
-                       if (flash_info[i].legacy_unlock) {
-                               int k;
 
-                               /*
-                                * Disable legacy_unlock temporarily, since
-                                * flash_real_protect would relock all other sectors
-                                * again otherwise.
-                                */
-                               flash_info[i].legacy_unlock = 0;
+       void *addr;
+       cfiword_t cword;
 
-                               /*
-                                * Legacy unlocking (e.g. Intel J3) -> unlock only one
-                                * sector. This will unlock all sectors.
-                                */
-                               flash_real_protect (&flash_info[i], 0, 0);
+       addr = flash_map (info, sect, offset);
+       flash_make_cmd (info, cmd, &cword);
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               debug ("fwc addr %p cmd %x %x 8bit x %d bit\n", addr, cmd,
+                      cword.c, info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
+               flash_write8(cword.c, addr);
+               break;
+       case FLASH_CFI_16BIT:
+               debug ("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr,
+                      cmd, cword.w,
+                      info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
+               flash_write16(cword.w, addr);
+               break;
+       case FLASH_CFI_32BIT:
+               debug ("fwc addr %p cmd %x %8.8lx 32bit x %d bit\n", addr,
+                      cmd, cword.l,
+                      info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
+               flash_write32(cword.l, addr);
+               break;
+       case FLASH_CFI_64BIT:
+#ifdef DEBUG
+               {
+                       char str[20];
 
-                               flash_info[i].legacy_unlock = 1;
+                       print_longlong (str, cword.ll);
 
-                               /*
-                                * Manually mark other sectors as unlocked (unprotected)
-                                */
-                               for (k = 1; k < flash_info[i].sector_count; k++)
-                                       flash_info[i].protect[k] = 0;
-                       } else {
-                               /*
-                                * No legancy unlocking -> unlock all sectors
-                                */
-                               flash_protect (FLAG_PROTECT_CLEAR,
-                                              flash_info[i].start[0],
-                                              flash_info[i].start[0] + flash_info[i].size - 1,
-                                              &flash_info[i]);
-                       }
+                       debug ("fwrite addr %p cmd %x %s 64 bit x %d bit\n",
+                              addr, cmd, str,
+                              info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
                }
-#endif /* CFG_FLASH_PROTECTION */
+#endif
+               flash_write64(cword.ll, addr);
+               break;
        }
 
-       /* Monitor protection ON by default */
-#if (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
-       flash_protect (FLAG_PROTECT_SET,
-                      CFG_MONITOR_BASE,
-                      CFG_MONITOR_BASE + monitor_flash_len  - 1,
-                      flash_get_info(CFG_MONITOR_BASE));
-#endif
+       /* Ensure all the instructions are fully finished */
+       sync();
 
-       /* Environment protection ON by default */
-#ifdef CFG_ENV_IS_IN_FLASH
-       flash_protect (FLAG_PROTECT_SET,
-                      CFG_ENV_ADDR,
-                      CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
-                      flash_get_info(CFG_ENV_ADDR));
-#endif
+       flash_unmap(info, sect, offset, addr);
+}
 
-       /* Redundant environment protection ON by default */
-#ifdef CFG_ENV_ADDR_REDUND
-       flash_protect (FLAG_PROTECT_SET,
-                      CFG_ENV_ADDR_REDUND,
-                      CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
-                      flash_get_info(CFG_ENV_ADDR_REDUND));
-#endif
-       return (size);
+static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect)
+{
+       flash_write_cmd (info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START);
+       flash_write_cmd (info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK);
 }
 
 /*-----------------------------------------------------------------------
  */
-#if defined(CFG_ENV_IS_IN_FLASH) || defined(CFG_ENV_ADDR_REDUND) || (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
-static flash_info_t *flash_get_info(ulong base)
+static int flash_isequal (flash_info_t * info, flash_sect_t sect,
+                         uint offset, uchar cmd)
 {
-       int i;
-       flash_info_t * info = 0;
+       void *addr;
+       cfiword_t cword;
+       int retval;
 
-       for (i = 0; i < CFG_MAX_FLASH_BANKS; i ++) {
-               info = & flash_info[i];
-               if (info->size && info->start[0] <= base &&
-                   base <= info->start[0] + info->size - 1)
-                       break;
+       addr = flash_map (info, sect, offset);
+       flash_make_cmd (info, cmd, &cword);
+
+       debug ("is= cmd %x(%c) addr %p ", cmd, cmd, addr);
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               debug ("is= %x %x\n", flash_read8(addr), cword.c);
+               retval = (flash_read8(addr) == cword.c);
+               break;
+       case FLASH_CFI_16BIT:
+               debug ("is= %4.4x %4.4x\n", flash_read16(addr), cword.w);
+               retval = (flash_read16(addr) == cword.w);
+               break;
+       case FLASH_CFI_32BIT:
+               debug ("is= %8.8lx %8.8lx\n", flash_read32(addr), cword.l);
+               retval = (flash_read32(addr) == cword.l);
+               break;
+       case FLASH_CFI_64BIT:
+#ifdef DEBUG
+               {
+                       char str1[20];
+                       char str2[20];
+
+                       print_longlong (str1, flash_read64(addr));
+                       print_longlong (str2, cword.ll);
+                       debug ("is= %s %s\n", str1, str2);
+               }
+#endif
+               retval = (flash_read64(addr) == cword.ll);
+               break;
+       default:
+               retval = 0;
+               break;
        }
+       flash_unmap(info, sect, offset, addr);
 
-       return i == CFG_MAX_FLASH_BANKS ? 0 : info;
+       return retval;
 }
-#endif
 
 /*-----------------------------------------------------------------------
  */
-int flash_erase (flash_info_t * info, int s_first, int s_last)
+static int flash_isset (flash_info_t * info, flash_sect_t sect,
+                       uint offset, uchar cmd)
 {
-       int rcode = 0;
-       int prot;
-       flash_sect_t sect;
+       void *addr;
+       cfiword_t cword;
+       int retval;
 
-       if (info->flash_id != FLASH_MAN_CFI) {
-               puts ("Can't erase unknown flash type - aborted\n");
-               return 1;
-       }
-       if ((s_first < 0) || (s_first > s_last)) {
-               puts ("- no sectors to erase\n");
-               return 1;
+       addr = flash_map (info, sect, offset);
+       flash_make_cmd (info, cmd, &cword);
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               retval = ((flash_read8(addr) & cword.c) == cword.c);
+               break;
+       case FLASH_CFI_16BIT:
+               retval = ((flash_read16(addr) & cword.w) == cword.w);
+               break;
+       case FLASH_CFI_32BIT:
+               retval = ((flash_read16(addr) & cword.l) == cword.l);
+               break;
+       case FLASH_CFI_64BIT:
+               retval = ((flash_read64(addr) & cword.ll) == cword.ll);
+               break;
+       default:
+               retval = 0;
+               break;
        }
+       flash_unmap(info, sect, offset, addr);
 
-       prot = 0;
-       for (sect = s_first; sect <= s_last; ++sect) {
+       return retval;
+}
+
+/*-----------------------------------------------------------------------
+ */
+static int flash_toggle (flash_info_t * info, flash_sect_t sect,
+                        uint offset, uchar cmd)
+{
+       void *addr;
+       cfiword_t cword;
+       int retval;
+
+       addr = flash_map (info, sect, offset);
+       flash_make_cmd (info, cmd, &cword);
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               retval = ((flash_read8(addr) & cword.c) !=
+                         (flash_read8(addr) & cword.c));
+               break;
+       case FLASH_CFI_16BIT:
+               retval = ((flash_read16(addr) & cword.w) !=
+                         (flash_read16(addr) & cword.w));
+               break;
+       case FLASH_CFI_32BIT:
+               retval = ((flash_read32(addr) & cword.l) !=
+                         (flash_read32(addr) & cword.l));
+               break;
+       case FLASH_CFI_64BIT:
+               retval = ((flash_read64(addr) & cword.ll) !=
+                         (flash_read64(addr) & cword.ll));
+               break;
+       default:
+               retval = 0;
+               break;
+       }
+       flash_unmap(info, sect, offset, addr);
+
+       return retval;
+}
+
+/*
+ * flash_is_busy - check to see if the flash is busy
+ *
+ * This routine checks the status of the chip and returns true if the
+ * chip is busy.
+ */
+static int flash_is_busy (flash_info_t * info, flash_sect_t sect)
+{
+       int retval;
+
+       switch (info->vendor) {
+       case CFI_CMDSET_INTEL_STANDARD:
+       case CFI_CMDSET_INTEL_EXTENDED:
+               retval = !flash_isset (info, sect, 0, FLASH_STATUS_DONE);
+               break;
+       case CFI_CMDSET_AMD_STANDARD:
+       case CFI_CMDSET_AMD_EXTENDED:
+#ifdef CONFIG_FLASH_CFI_LEGACY
+       case CFI_CMDSET_AMD_LEGACY:
+#endif
+               retval = flash_toggle (info, sect, 0, AMD_STATUS_TOGGLE);
+               break;
+       default:
+               retval = 0;
+       }
+       debug ("flash_is_busy: %d\n", retval);
+       return retval;
+}
+
+/*-----------------------------------------------------------------------
+ *  wait for XSR.7 to be set. Time out with an error if it does not.
+ *  This routine does not set the flash to read-array mode.
+ */
+static int flash_status_check (flash_info_t * info, flash_sect_t sector,
+                              ulong tout, char *prompt)
+{
+       ulong start;
+
+#if CFG_HZ != 1000
+       tout *= CFG_HZ/1000;
+#endif
+
+       /* Wait for command completion */
+       start = get_timer (0);
+       while (flash_is_busy (info, sector)) {
+               if (get_timer (start) > tout) {
+                       printf ("Flash %s timeout at address %lx data %lx\n",
+                               prompt, info->start[sector],
+                               flash_read_long (info, sector, 0));
+                       flash_write_cmd (info, sector, 0, info->cmd_reset);
+                       return ERR_TIMOUT;
+               }
+               udelay (1);             /* also triggers watchdog */
+       }
+       return ERR_OK;
+}
+
+/*-----------------------------------------------------------------------
+ * Wait for XSR.7 to be set, if it times out print an error, otherwise
+ * do a full status check.
+ *
+ * This routine sets the flash to read-array mode.
+ */
+static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
+                                   ulong tout, char *prompt)
+{
+       int retcode;
+
+       retcode = flash_status_check (info, sector, tout, prompt);
+       switch (info->vendor) {
+       case CFI_CMDSET_INTEL_EXTENDED:
+       case CFI_CMDSET_INTEL_STANDARD:
+               if ((retcode == ERR_OK)
+                   && !flash_isequal (info, sector, 0, FLASH_STATUS_DONE)) {
+                       retcode = ERR_INVAL;
+                       printf ("Flash %s error at address %lx\n", prompt,
+                               info->start[sector]);
+                       if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS |
+                                        FLASH_STATUS_PSLBS)) {
+                               puts ("Command Sequence Error.\n");
+                       } else if (flash_isset (info, sector, 0,
+                                               FLASH_STATUS_ECLBS)) {
+                               puts ("Block Erase Error.\n");
+                               retcode = ERR_NOT_ERASED;
+                       } else if (flash_isset (info, sector, 0,
+                                               FLASH_STATUS_PSLBS)) {
+                               puts ("Locking Error\n");
+                       }
+                       if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
+                               puts ("Block locked.\n");
+                               retcode = ERR_PROTECTED;
+                       }
+                       if (flash_isset (info, sector, 0, FLASH_STATUS_VPENS))
+                               puts ("Vpp Low Error.\n");
+               }
+               flash_write_cmd (info, sector, 0, info->cmd_reset);
+               break;
+       default:
+               break;
+       }
+       return retcode;
+}
+
+/*-----------------------------------------------------------------------
+ */
+static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
+{
+#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
+       unsigned short  w;
+       unsigned int    l;
+       unsigned long long ll;
+#endif
+
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               cword->c = c;
+               break;
+       case FLASH_CFI_16BIT:
+#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
+               w = c;
+               w <<= 8;
+               cword->w = (cword->w >> 8) | w;
+#else
+               cword->w = (cword->w << 8) | c;
+#endif
+               break;
+       case FLASH_CFI_32BIT:
+#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
+               l = c;
+               l <<= 24;
+               cword->l = (cword->l >> 8) | l;
+#else
+               cword->l = (cword->l << 8) | c;
+#endif
+               break;
+       case FLASH_CFI_64BIT:
+#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
+               ll = c;
+               ll <<= 56;
+               cword->ll = (cword->ll >> 8) | ll;
+#else
+               cword->ll = (cword->ll << 8) | c;
+#endif
+               break;
+       }
+}
+
+/* loop through the sectors from the highest address when the passed
+ * address is greater or equal to the sector address we have a match
+ */
+static flash_sect_t find_sector (flash_info_t * info, ulong addr)
+{
+       flash_sect_t sector;
+
+       for (sector = info->sector_count - 1; sector >= 0; sector--) {
+               if (addr >= info->start[sector])
+                       break;
+       }
+       return sector;
+}
+
+/*-----------------------------------------------------------------------
+ */
+static int flash_write_cfiword (flash_info_t * info, ulong dest,
+                               cfiword_t cword)
+{
+       void *dstaddr;
+       int flag;
+
+       dstaddr = map_physmem(dest, info->portwidth, MAP_NOCACHE);
+
+       /* Check if Flash is (sufficiently) erased */
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               flag = ((flash_read8(dstaddr) & cword.c) == cword.c);
+               break;
+       case FLASH_CFI_16BIT:
+               flag = ((flash_read16(dstaddr) & cword.w) == cword.w);
+               break;
+       case FLASH_CFI_32BIT:
+               flag = ((flash_read32(dstaddr) & cword.l) == cword.l);
+               break;
+       case FLASH_CFI_64BIT:
+               flag = ((flash_read64(dstaddr) & cword.ll) == cword.ll);
+               break;
+       default:
+               flag = 0;
+               break;
+       }
+       if (!flag) {
+               unmap_physmem(dstaddr, info->portwidth);
+               return 2;
+       }
+
+       /* Disable interrupts which might cause a timeout here */
+       flag = disable_interrupts ();
+
+       switch (info->vendor) {
+       case CFI_CMDSET_INTEL_EXTENDED:
+       case CFI_CMDSET_INTEL_STANDARD:
+               flash_write_cmd (info, 0, 0, FLASH_CMD_CLEAR_STATUS);
+               flash_write_cmd (info, 0, 0, FLASH_CMD_WRITE);
+               break;
+       case CFI_CMDSET_AMD_EXTENDED:
+       case CFI_CMDSET_AMD_STANDARD:
+#ifdef CONFIG_FLASH_CFI_LEGACY
+       case CFI_CMDSET_AMD_LEGACY:
+#endif
+               flash_unlock_seq (info, 0);
+               flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_WRITE);
+               break;
+       }
+
+       switch (info->portwidth) {
+       case FLASH_CFI_8BIT:
+               flash_write8(cword.c, dstaddr);
+               break;
+       case FLASH_CFI_16BIT:
+               flash_write16(cword.w, dstaddr);
+               break;
+       case FLASH_CFI_32BIT:
+               flash_write32(cword.l, dstaddr);
+               break;
+       case FLASH_CFI_64BIT:
+               flash_write64(cword.ll, dstaddr);
+               break;
+       }
+
+       /* re-enable interrupts if necessary */
+       if (flag)
+               enable_interrupts ();
+
+       unmap_physmem(dstaddr, info->portwidth);
+
+       return flash_full_status_check (info, find_sector (info, dest),
+                                       info->write_tout, "write");
+}
+
+#ifdef CFG_FLASH_USE_BUFFER_WRITE
+
+static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
+                                 int len)
+{
+       flash_sect_t sector;
+       int cnt;
+       int retcode;
+       void *src = cp;
+       void *dst = map_physmem(dest, len, MAP_NOCACHE);
+
+       sector = find_sector (info, dest);
+
+       switch (info->vendor) {
+       case CFI_CMDSET_INTEL_STANDARD:
+       case CFI_CMDSET_INTEL_EXTENDED:
+               flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
+               flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
+               retcode = flash_status_check (info, sector,
+                                             info->buffer_write_tout,
+                                             "write to buffer");
+               if (retcode == ERR_OK) {
+                       /* reduce the number of loops by the width of
+                        * the port */
+                       switch (info->portwidth) {
+                       case FLASH_CFI_8BIT:
+                               cnt = len;
+                               break;
+                       case FLASH_CFI_16BIT:
+                               cnt = len >> 1;
+                               break;
+                       case FLASH_CFI_32BIT:
+                               cnt = len >> 2;
+                               break;
+                       case FLASH_CFI_64BIT:
+                               cnt = len >> 3;
+                               break;
+                       default:
+                               retcode = ERR_INVAL;
+                               goto out_unmap;
+                       }
+                       flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
+                       while (cnt-- > 0) {
+                               switch (info->portwidth) {
+                               case FLASH_CFI_8BIT:
+                                       flash_write8(flash_read8(src), dst);
+                                       src += 1, dst += 1;
+                                       break;
+                               case FLASH_CFI_16BIT:
+                                       flash_write16(flash_read16(src), dst);
+                                       src += 2, dst += 2;
+                                       break;
+                               case FLASH_CFI_32BIT:
+                                       flash_write32(flash_read32(src), dst);
+                                       src += 4, dst += 4;
+                                       break;
+                               case FLASH_CFI_64BIT:
+                                       flash_write64(flash_read64(src), dst);
+                                       src += 8, dst += 8;
+                                       break;
+                               default:
+                                       retcode = ERR_INVAL;
+                                       goto out_unmap;
+                               }
+                       }
+                       flash_write_cmd (info, sector, 0,
+                                        FLASH_CMD_WRITE_BUFFER_CONFIRM);
+                       retcode = flash_full_status_check (
+                               info, sector, info->buffer_write_tout,
+                               "buffer write");
+               }
+
+               break;
+
+       case CFI_CMDSET_AMD_STANDARD:
+       case CFI_CMDSET_AMD_EXTENDED:
+               flash_unlock_seq(info,0);
+               flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_TO_BUFFER);
+
+               switch (info->portwidth) {
+               case FLASH_CFI_8BIT:
+                       cnt = len;
+                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
+                       while (cnt-- > 0) {
+                               flash_write8(flash_read8(src), dst);
+                               src += 1, dst += 1;
+                       }
+                       break;
+               case FLASH_CFI_16BIT:
+                       cnt = len >> 1;
+                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
+                       while (cnt-- > 0) {
+                               flash_write16(flash_read16(src), dst);
+                               src += 2, dst += 2;
+                       }
+                       break;
+               case FLASH_CFI_32BIT:
+                       cnt = len >> 2;
+                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
+                       while (cnt-- > 0) {
+                               flash_write32(flash_read32(src), dst);
+                               src += 4, dst += 4;
+                       }
+                       break;
+               case FLASH_CFI_64BIT:
+                       cnt = len >> 3;
+                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
+                       while (cnt-- > 0) {
+                               flash_write64(flash_read64(src), dst);
+                               src += 8, dst += 8;
+                       }
+                       break;
+               default:
+                       retcode = ERR_INVAL;
+                       goto out_unmap;
+               }
+
+               flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
+               retcode = flash_full_status_check (info, sector,
+                                                  info->buffer_write_tout,
+                                                  "buffer write");
+               break;
+
+       default:
+               debug ("Unknown Command Set\n");
+               retcode = ERR_INVAL;
+               break;
+       }
+
+out_unmap:
+       unmap_physmem(dst, len);
+       return retcode;
+}
+#endif /* CFG_FLASH_USE_BUFFER_WRITE */
+
+
+/*-----------------------------------------------------------------------
+ */
+int flash_erase (flash_info_t * info, int s_first, int s_last)
+{
+       int rcode = 0;
+       int prot;
+       flash_sect_t sect;
+
+       if (info->flash_id != FLASH_MAN_CFI) {
+               puts ("Can't erase unknown flash type - aborted\n");
+               return 1;
+       }
+       if ((s_first < 0) || (s_first > s_last)) {
+               puts ("- no sectors to erase\n");
+               return 1;
+       }
+
+       prot = 0;
+       for (sect = s_first; sect <= s_last; ++sect) {
                if (info->protect[sect]) {
                        prot++;
                }
        }
        if (prot) {
-               printf ("- Warning: %d protected sectors will not be erased!\n", prot);
+               printf ("- Warning: %d protected sectors will not be erased!\n",
+                       prot);
        } else {
                putc ('\n');
        }
@@ -476,18 +988,33 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
                        switch (info->vendor) {
                        case CFI_CMDSET_INTEL_STANDARD:
                        case CFI_CMDSET_INTEL_EXTENDED:
-                               flash_write_cmd (info, sect, 0, FLASH_CMD_CLEAR_STATUS);
-                               flash_write_cmd (info, sect, 0, FLASH_CMD_BLOCK_ERASE);
-                               flash_write_cmd (info, sect, 0, FLASH_CMD_ERASE_CONFIRM);
+                               flash_write_cmd (info, sect, 0,
+                                                FLASH_CMD_CLEAR_STATUS);
+                               flash_write_cmd (info, sect, 0,
+                                                FLASH_CMD_BLOCK_ERASE);
+                               flash_write_cmd (info, sect, 0,
+                                                FLASH_CMD_ERASE_CONFIRM);
                                break;
                        case CFI_CMDSET_AMD_STANDARD:
                        case CFI_CMDSET_AMD_EXTENDED:
                                flash_unlock_seq (info, sect);
-                               flash_write_cmd (info, sect, AMD_ADDR_ERASE_START,
-                                                       AMD_CMD_ERASE_START);
+                               flash_write_cmd (info, sect,
+                                               info->addr_unlock1,
+                                               AMD_CMD_ERASE_START);
                                flash_unlock_seq (info, sect);
-                               flash_write_cmd (info, sect, 0, AMD_CMD_ERASE_SECTOR);
+                               flash_write_cmd (info, sect, 0,
+                                                AMD_CMD_ERASE_SECTOR);
+                               break;
+#ifdef CONFIG_FLASH_CFI_LEGACY
+                       case CFI_CMDSET_AMD_LEGACY:
+                               flash_unlock_seq (info, 0);
+                               flash_write_cmd (info, 0, info->addr_unlock1,
+                                               AMD_CMD_ERASE_START);
+                               flash_unlock_seq (info, 0);
+                               flash_write_cmd (info, sect, 0,
+                                               AMD_CMD_ERASE_SECTOR);
                                break;
+#endif
                        default:
                                debug ("Unkown flash vendor %d\n",
                                       info->vendor);
@@ -516,10 +1043,15 @@ void flash_print_info (flash_info_t * info)
                return;
        }
 
-       printf ("CFI conformant FLASH (%d x %d)",
+       printf ("%s FLASH (%d x %d)",
+               info->name,
                (info->portwidth << 3), (info->chipwidth << 3));
-       printf ("  Size: %ld MB in %d Sectors\n",
-               info->size >> 20, info->sector_count);
+       if (info->size < 1024*1024)
+               printf ("  Size: %ld kB in %d Sectors\n",
+                       info->size >> 10, info->sector_count);
+       else
+               printf ("  Size: %ld MB in %d Sectors\n",
+                       info->size >> 20, info->sector_count);
        printf ("  ");
        switch (info->vendor) {
                case CFI_CMDSET_INTEL_STANDARD:
@@ -534,6 +1066,11 @@ void flash_print_info (flash_info_t * info)
                case CFI_CMDSET_AMD_EXTENDED:
                        printf ("AMD Extended");
                        break;
+#ifdef CONFIG_FLASH_CFI_LEGACY
+               case CFI_CMDSET_AMD_LEGACY:
+                       printf ("AMD Legacy");
+                       break;
+#endif
                default:
                        printf ("Unknown (%d)", info->vendor);
                        break;
@@ -547,7 +1084,8 @@ void flash_print_info (flash_info_t * info)
                info->erase_blk_tout,
                info->write_tout);
        if (info->buffer_size > 1) {
-               printf ("  Buffer write timeout: %ld ms, buffer size: %d bytes\n",
+               printf ("  Buffer write timeout: %ld ms, "
+                       "buffer size: %d bytes\n",
                info->buffer_write_tout,
                info->buffer_size);
        }
@@ -565,10 +1103,7 @@ void flash_print_info (flash_info_t * info)
                /*
                 * Check if whole sector is erased
                 */
-               if (i != (info->sector_count - 1))
-                       size = info->start[i + 1] - info->start[i];
-               else
-                       size = info->start[0] + info->size - info->start[i];
+               size = flash_sector_size(info, i);
                erased = 1;
                flash = (volatile unsigned long *) info->start[i];
                size = size >> 2;       /* divide by 4 for longword access */
@@ -603,7 +1138,7 @@ void flash_print_info (flash_info_t * info)
 int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
 {
        ulong wp;
-       ulong cp;
+       uchar *p;
        int aln;
        cfiword_t cword;
        int i, rc;
@@ -611,27 +1146,29 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
 #ifdef CFG_FLASH_USE_BUFFER_WRITE
        int buffered_size;
 #endif
-       /* get lower aligned address */
        /* get lower aligned address */
        wp = (addr & ~(info->portwidth - 1));
 
        /* handle unaligned start */
        if ((aln = addr - wp) != 0) {
                cword.l = 0;
-               cp = wp;
-               for (i = 0; i < aln; ++i, ++cp)
-                       flash_add_byte (info, &cword, (*(uchar *) cp));
+               p = map_physmem(wp, info->portwidth, MAP_NOCACHE);
+               for (i = 0; i < aln; ++i)
+                       flash_add_byte (info, &cword, flash_read8(p + i));
 
                for (; (i < info->portwidth) && (cnt > 0); i++) {
                        flash_add_byte (info, &cword, *src++);
                        cnt--;
-                       cp++;
                }
-               for (; (cnt == 0) && (i < info->portwidth); ++i, ++cp)
-                       flash_add_byte (info, &cword, (*(uchar *) cp));
-               if ((rc = flash_write_cfiword (info, wp, cword)) != 0)
+               for (; (cnt == 0) && (i < info->portwidth); ++i)
+                       flash_add_byte (info, &cword, flash_read8(p + i));
+
+               rc = flash_write_cfiword (info, wp, cword);
+               unmap_physmem(p, info->portwidth);
+               if (rc != 0)
                        return rc;
-               wp = cp;
+
+               wp += i;
        }
 
        /* handle the aligned part */
@@ -682,13 +1219,14 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
         * handle unaligned tail bytes
         */
        cword.l = 0;
-       for (i = 0, cp = wp; (i < info->portwidth) && (cnt > 0); ++i, ++cp) {
+       p = map_physmem(wp, info->portwidth, MAP_NOCACHE);
+       for (i = 0; (i < info->portwidth) && (cnt > 0); ++i) {
                flash_add_byte (info, &cword, *src++);
                --cnt;
        }
-       for (; i < info->portwidth; ++i, ++cp) {
-               flash_add_byte (info, &cword, (*(uchar *) cp));
-       }
+       for (; i < info->portwidth; ++i)
+               flash_add_byte (info, &cword, flash_read8(p + i));
+       unmap_physmem(p, info->portwidth);
 
        return flash_write_cfiword (info, wp, cword);
 }
@@ -708,463 +1246,356 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)
        else
                flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
 
-       if ((retcode =
-            flash_full_status_check (info, sector, info->erase_blk_tout,
-                                     prot ? "protect" : "unprotect")) == 0) {
-
-               info->protect[sector] = prot;
-
-               /*
-                * On some of Intel's flash chips (marked via legacy_unlock)
-                * unprotect unprotects all locking.
-                */
-               if ((prot == 0) && (info->legacy_unlock)) {
-                       flash_sect_t i;
-
-                       for (i = 0; i < info->sector_count; i++) {
-                               if (info->protect[i])
-                                       flash_real_protect (info, i, 1);
-                       }
-               }
-       }
-       return retcode;
-}
-
-/*-----------------------------------------------------------------------
- * flash_read_user_serial - read the OneTimeProgramming cells
- */
-void flash_read_user_serial (flash_info_t * info, void *buffer, int offset,
-                            int len)
-{
-       uchar *src;
-       uchar *dst;
-
-       dst = buffer;
-       src = flash_make_addr (info, 0, FLASH_OFFSET_USER_PROTECTION);
-       flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID);
-       memcpy (dst, src + offset, len);
-       flash_write_cmd (info, 0, 0, info->cmd_reset);
-}
-
-/*
- * flash_read_factory_serial - read the device Id from the protection area
- */
-void flash_read_factory_serial (flash_info_t * info, void *buffer, int offset,
-                               int len)
-{
-       uchar *src;
-
-       src = flash_make_addr (info, 0, FLASH_OFFSET_INTEL_PROTECTION);
-       flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID);
-       memcpy (buffer, src + offset, len);
-       flash_write_cmd (info, 0, 0, info->cmd_reset);
-}
-
-#endif /* CFG_FLASH_PROTECTION */
-
-/*
- * flash_is_busy - check to see if the flash is busy
- * This routine checks the status of the chip and returns true if the chip is busy
- */
-static int flash_is_busy (flash_info_t * info, flash_sect_t sect)
-{
-       int retval;
-
-       switch (info->vendor) {
-       case CFI_CMDSET_INTEL_STANDARD:
-       case CFI_CMDSET_INTEL_EXTENDED:
-               retval = !flash_isset (info, sect, 0, FLASH_STATUS_DONE);
-               break;
-       case CFI_CMDSET_AMD_STANDARD:
-       case CFI_CMDSET_AMD_EXTENDED:
-               retval = flash_toggle (info, sect, 0, AMD_STATUS_TOGGLE);
-               break;
-       default:
-               retval = 0;
-       }
-       debug ("flash_is_busy: %d\n", retval);
-       return retval;
-}
-
-/*-----------------------------------------------------------------------
- *  wait for XSR.7 to be set. Time out with an error if it does not.
- *  This routine does not set the flash to read-array mode.
- */
-static int flash_status_check (flash_info_t * info, flash_sect_t sector,
-                              ulong tout, char *prompt)
-{
-       ulong start;
-
-#if CFG_HZ != 1000
-       tout *= CFG_HZ/1000;
-#endif
-
-       /* Wait for command completion */
-       start = get_timer (0);
-       while (flash_is_busy (info, sector)) {
-               if (get_timer (start) > tout) {
-                       printf ("Flash %s timeout at address %lx data %lx\n",
-                               prompt, info->start[sector],
-                               flash_read_long (info, sector, 0));
-                       flash_write_cmd (info, sector, 0, info->cmd_reset);
-                       return ERR_TIMOUT;
-               }
-               udelay (1);             /* also triggers watchdog */
-       }
-       return ERR_OK;
-}
-
-/*-----------------------------------------------------------------------
- * Wait for XSR.7 to be set, if it times out print an error, otherwise do a full status check.
- * This routine sets the flash to read-array mode.
- */
-static int flash_full_status_check (flash_info_t * info, flash_sect_t sector,
-                                   ulong tout, char *prompt)
-{
-       int retcode;
-
-       retcode = flash_status_check (info, sector, tout, prompt);
-       switch (info->vendor) {
-       case CFI_CMDSET_INTEL_EXTENDED:
-       case CFI_CMDSET_INTEL_STANDARD:
-               if ((retcode == ERR_OK)
-                   && !flash_isequal (info, sector, 0, FLASH_STATUS_DONE)) {
-                       retcode = ERR_INVAL;
-                       printf ("Flash %s error at address %lx\n", prompt,
-                               info->start[sector]);
-                       if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) {
-                               puts ("Command Sequence Error.\n");
-                       } else if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS)) {
-                               puts ("Block Erase Error.\n");
-                               retcode = ERR_NOT_ERASED;
-                       } else if (flash_isset (info, sector, 0, FLASH_STATUS_PSLBS)) {
-                               puts ("Locking Error\n");
-                       }
-                       if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
-                               puts ("Block locked.\n");
-                               retcode = ERR_PROTECTED;
+       if ((retcode =
+            flash_full_status_check (info, sector, info->erase_blk_tout,
+                                     prot ? "protect" : "unprotect")) == 0) {
+
+               info->protect[sector] = prot;
+
+               /*
+                * On some of Intel's flash chips (marked via legacy_unlock)
+                * unprotect unprotects all locking.
+                */
+               if ((prot == 0) && (info->legacy_unlock)) {
+                       flash_sect_t i;
+
+                       for (i = 0; i < info->sector_count; i++) {
+                               if (info->protect[i])
+                                       flash_real_protect (info, i, 1);
                        }
-                       if (flash_isset (info, sector, 0, FLASH_STATUS_VPENS))
-                               puts ("Vpp Low Error.\n");
                }
-               flash_write_cmd (info, sector, 0, info->cmd_reset);
-               break;
-       default:
-               break;
        }
        return retcode;
 }
 
 /*-----------------------------------------------------------------------
+ * flash_read_user_serial - read the OneTimeProgramming cells
  */
-static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
+void flash_read_user_serial (flash_info_t * info, void *buffer, int offset,
+                            int len)
 {
-#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
-       unsigned short  w;
-       unsigned int    l;
-       unsigned long long ll;
-#endif
+       uchar *src;
+       uchar *dst;
 
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               cword->c = c;
-               break;
-       case FLASH_CFI_16BIT:
-#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
-               w = c;
-               w <<= 8;
-               cword->w = (cword->w >> 8) | w;
-#else
-               cword->w = (cword->w << 8) | c;
-#endif
-               break;
-       case FLASH_CFI_32BIT:
-#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
-               l = c;
-               l <<= 24;
-               cword->l = (cword->l >> 8) | l;
-#else
-               cword->l = (cword->l << 8) | c;
-#endif
-               break;
-       case FLASH_CFI_64BIT:
-#if defined(__LITTLE_ENDIAN) && !defined(CFG_WRITE_SWAPPED_DATA)
-               ll = c;
-               ll <<= 56;
-               cword->ll = (cword->ll >> 8) | ll;
-#else
-               cword->ll = (cword->ll << 8) | c;
-#endif
-               break;
-       }
+       dst = buffer;
+       src = flash_map (info, 0, FLASH_OFFSET_USER_PROTECTION);
+       flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID);
+       memcpy (dst, src + offset, len);
+       flash_write_cmd (info, 0, 0, info->cmd_reset);
+       flash_unmap(info, 0, FLASH_OFFSET_USER_PROTECTION, src);
+}
+
+/*
+ * flash_read_factory_serial - read the device Id from the protection area
+ */
+void flash_read_factory_serial (flash_info_t * info, void *buffer, int offset,
+                               int len)
+{
+       uchar *src;
+
+       src = flash_map (info, 0, FLASH_OFFSET_INTEL_PROTECTION);
+       flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID);
+       memcpy (buffer, src + offset, len);
+       flash_write_cmd (info, 0, 0, info->cmd_reset);
+       flash_unmap(info, 0, FLASH_OFFSET_INTEL_PROTECTION, src);
 }
 
+#endif /* CFG_FLASH_PROTECTION */
 
 /*-----------------------------------------------------------------------
- * make a proper sized command based on the port and chip widths
+ * Reverse the order of the erase regions in the CFI QRY structure.
+ * This is needed for chips that are either a) correctly detected as
+ * top-boot, or b) buggy.
  */
-static void flash_make_cmd (flash_info_t * info, uchar cmd, void *cmdbuf)
+static void cfi_reverse_geometry(struct cfi_qry *qry)
 {
-       int i;
-       uchar *cp = (uchar *) cmdbuf;
+       unsigned int i, j;
+       u32 tmp;
 
-#if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
-       for (i = info->portwidth; i > 0; i--)
-#else
-       for (i = 1; i <= info->portwidth; i++)
-#endif
-               *cp++ = (i & (info->chipwidth - 1)) ? '\0' : cmd;
+       for (i = 0, j = qry->num_erase_regions - 1; i < j; i++, j--) {
+               tmp = qry->erase_region_info[i];
+               qry->erase_region_info[i] = qry->erase_region_info[j];
+               qry->erase_region_info[j] = tmp;
+       }
 }
 
-/*
- * Write a proper sized command to the correct address
+/*-----------------------------------------------------------------------
+ * read jedec ids from device and set corresponding fields in info struct
+ *
+ * Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct
+ *
  */
-static void flash_write_cmd (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
+static void cmdset_intel_read_jedec_ids(flash_info_t *info)
 {
+       flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
+       flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID);
+       udelay(1000); /* some flash are slow to respond */
+       info->manufacturer_id = flash_read_uchar (info,
+                                       FLASH_OFFSET_MANUFACTURER_ID);
+       info->device_id = flash_read_uchar (info,
+                                       FLASH_OFFSET_DEVICE_ID);
+       flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
+}
 
-       volatile cfiptr_t addr;
-       cfiword_t cword;
-
-       addr.cp = flash_make_addr (info, sect, offset);
-       flash_make_cmd (info, cmd, &cword);
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               debug ("fwc addr %p cmd %x %x 8bit x %d bit\n", addr.cp, cmd,
-                      cword.c, info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
-               *addr.cp = cword.c;
-               break;
-       case FLASH_CFI_16BIT:
-               debug ("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr.wp,
-                      cmd, cword.w,
-                      info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
-               *addr.wp = cword.w;
-               break;
-       case FLASH_CFI_32BIT:
-               debug ("fwc addr %p cmd %x %8.8lx 32bit x %d bit\n", addr.lp,
-                      cmd, cword.l,
-                      info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
-               *addr.lp = cword.l;
-               break;
-       case FLASH_CFI_64BIT:
-#ifdef DEBUG
-               {
-                       char str[20];
+static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry)
+{
+       info->cmd_reset = FLASH_CMD_RESET;
 
-                       print_longlong (str, cword.ll);
+       cmdset_intel_read_jedec_ids(info);
+       flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI);
 
-                       debug ("fwrite addr %p cmd %x %s 64 bit x %d bit\n",
-                              addr.llp, cmd, str,
-                              info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
-               }
-#endif
-               *addr.llp = cword.ll;
-               break;
+#ifdef CFG_FLASH_PROTECTION
+       /* read legacy lock/unlock bit from intel flash */
+       if (info->ext_addr) {
+               info->legacy_unlock = flash_read_uchar (info,
+                               info->ext_addr + 5) & 0x08;
        }
+#endif
 
-       /* Ensure all the instructions are fully finished */
-       sync();
+       return 0;
 }
 
-static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect)
+static void cmdset_amd_read_jedec_ids(flash_info_t *info)
 {
-       flash_write_cmd (info, sect, AMD_ADDR_START, AMD_CMD_UNLOCK_START);
-       flash_write_cmd (info, sect, AMD_ADDR_ACK, AMD_CMD_UNLOCK_ACK);
+       flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
+       flash_unlock_seq(info, 0);
+       flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID);
+       udelay(1000); /* some flash are slow to respond */
+       info->manufacturer_id = flash_read_uchar (info,
+                                       FLASH_OFFSET_MANUFACTURER_ID);
+       info->device_id = flash_read_uchar (info,
+                                       FLASH_OFFSET_DEVICE_ID);
+       if (info->device_id == 0x7E) {
+               /* AMD 3-byte (expanded) device ids */
+               info->device_id2 = flash_read_uchar (info,
+                                       FLASH_OFFSET_DEVICE_ID2);
+               info->device_id2 <<= 8;
+               info->device_id2 |= flash_read_uchar (info,
+                                       FLASH_OFFSET_DEVICE_ID3);
+       }
+       flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
 }
 
-/*-----------------------------------------------------------------------
- */
-static int flash_isequal (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
+static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry)
 {
-       cfiptr_t cptr;
-       cfiword_t cword;
-       int retval;
+       info->cmd_reset = AMD_CMD_RESET;
 
-       cptr.cp = flash_make_addr (info, sect, offset);
-       flash_make_cmd (info, cmd, &cword);
+       cmdset_amd_read_jedec_ids(info);
+       flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI);
 
-       debug ("is= cmd %x(%c) addr %p ", cmd, cmd, cptr.cp);
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               debug ("is= %x %x\n", cptr.cp[0], cword.c);
-               retval = (cptr.cp[0] == cword.c);
-               break;
-       case FLASH_CFI_16BIT:
-               debug ("is= %4.4x %4.4x\n", cptr.wp[0], cword.w);
-               retval = (cptr.wp[0] == cword.w);
-               break;
-       case FLASH_CFI_32BIT:
-               debug ("is= %8.8lx %8.8lx\n", cptr.lp[0], cword.l);
-               retval = (cptr.lp[0] == cword.l);
-               break;
-       case FLASH_CFI_64BIT:
-#ifdef DEBUG
-               {
-                       char str1[20];
-                       char str2[20];
+       return 0;
+}
 
-                       print_longlong (str1, cptr.llp[0]);
-                       print_longlong (str2, cword.ll);
-                       debug ("is= %s %s\n", str1, str2);
-               }
-#endif
-               retval = (cptr.llp[0] == cword.ll);
+#ifdef CONFIG_FLASH_CFI_LEGACY
+static void flash_read_jedec_ids (flash_info_t * info)
+{
+       info->manufacturer_id = 0;
+       info->device_id       = 0;
+       info->device_id2      = 0;
+
+       switch (info->vendor) {
+       case CFI_CMDSET_INTEL_STANDARD:
+       case CFI_CMDSET_INTEL_EXTENDED:
+               flash_read_jedec_ids_intel(info);
+               break;
+       case CFI_CMDSET_AMD_STANDARD:
+       case CFI_CMDSET_AMD_EXTENDED:
+               flash_read_jedec_ids_amd(info);
                break;
        default:
-               retval = 0;
                break;
        }
-       return retval;
 }
 
 /*-----------------------------------------------------------------------
+ * Call board code to request info about non-CFI flash.
+ * board_flash_get_legacy needs to fill in at least:
+ * info->portwidth, info->chipwidth and info->interface for Jedec probing.
  */
-static int flash_isset (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
+static int flash_detect_legacy(ulong base, int banknum)
 {
-       cfiptr_t cptr;
-       cfiword_t cword;
-       int retval;
+       flash_info_t *info = &flash_info[banknum];
 
-       cptr.cp = flash_make_addr (info, sect, offset);
-       flash_make_cmd (info, cmd, &cword);
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               retval = ((cptr.cp[0] & cword.c) == cword.c);
-               break;
-       case FLASH_CFI_16BIT:
-               retval = ((cptr.wp[0] & cword.w) == cword.w);
-               break;
-       case FLASH_CFI_32BIT:
-               retval = ((cptr.lp[0] & cword.l) == cword.l);
-               break;
-       case FLASH_CFI_64BIT:
-               retval = ((cptr.llp[0] & cword.ll) == cword.ll);
-               break;
-       default:
-               retval = 0;
-               break;
+       if (board_flash_get_legacy(base, banknum, info)) {
+               /* board code may have filled info completely. If not, we
+                  use JEDEC ID probing. */
+               if (!info->vendor) {
+                       int modes[] = {
+                               CFI_CMDSET_AMD_STANDARD,
+                               CFI_CMDSET_INTEL_STANDARD
+                       };
+                       int i;
+
+                       for (i = 0; i < sizeof(modes) / sizeof(modes[0]); i++) {
+                               info->vendor = modes[i];
+                               info->start[0] = base;
+                               if (info->portwidth == FLASH_CFI_8BIT
+                                       && info->interface == FLASH_CFI_X8X16) {
+                                       info->addr_unlock1 = 0x2AAA;
+                                       info->addr_unlock2 = 0x5555;
+                               } else {
+                                       info->addr_unlock1 = 0x5555;
+                                       info->addr_unlock2 = 0x2AAA;
+                               }
+                               flash_read_jedec_ids(info);
+                               debug("JEDEC PROBE: ID %x %x %x\n",
+                                               info->manufacturer_id,
+                                               info->device_id,
+                                               info->device_id2);
+                               if (jedec_flash_match(info, base))
+                                       break;
+                       }
+               }
+
+               switch(info->vendor) {
+               case CFI_CMDSET_INTEL_STANDARD:
+               case CFI_CMDSET_INTEL_EXTENDED:
+                       info->cmd_reset = FLASH_CMD_RESET;
+                       break;
+               case CFI_CMDSET_AMD_STANDARD:
+               case CFI_CMDSET_AMD_EXTENDED:
+               case CFI_CMDSET_AMD_LEGACY:
+                       info->cmd_reset = AMD_CMD_RESET;
+                       break;
+               }
+               info->flash_id = FLASH_MAN_CFI;
+               return 1;
        }
-       return retval;
+       return 0; /* use CFI */
+}
+#else
+static inline int flash_detect_legacy(ulong base, int banknum)
+{
+       return 0; /* use CFI */
 }
+#endif
 
 /*-----------------------------------------------------------------------
+ * detect if flash is compatible with the Common Flash Interface (CFI)
+ * http://www.jedec.org/download/search/jesd68.pdf
  */
-static int flash_toggle (flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd)
+static void flash_read_cfi (flash_info_t *info, void *buf,
+               unsigned int start, size_t len)
 {
-       cfiptr_t cptr;
-       cfiword_t cword;
-       int retval;
+       u8 *p = buf;
+       unsigned int i;
 
-       cptr.cp = flash_make_addr (info, sect, offset);
-       flash_make_cmd (info, cmd, &cword);
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               retval = ((cptr.cp[0] & cword.c) != (cptr.cp[0] & cword.c));
-               break;
-       case FLASH_CFI_16BIT:
-               retval = ((cptr.wp[0] & cword.w) != (cptr.wp[0] & cword.w));
-               break;
-       case FLASH_CFI_32BIT:
-               retval = ((cptr.lp[0] & cword.l) != (cptr.lp[0] & cword.l));
-               break;
-       case FLASH_CFI_64BIT:
-               retval = ((cptr.llp[0] & cword.ll) !=
-                         (cptr.llp[0] & cword.ll));
-               break;
-       default:
-               retval = 0;
-               break;
-       }
-       return retval;
+       for (i = 0; i < len; i++)
+               p[i] = flash_read_uchar(info, start + i);
 }
 
-/*-----------------------------------------------------------------------
- * read jedec ids from device and set corresponding fields in info struct
- *
- * Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct
- *
-*/
-static void flash_read_jedec_ids (flash_info_t * info)
+static int __flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry)
 {
-       info->manufacturer_id = 0;
-       info->device_id       = 0;
-       info->device_id2      = 0;
+       int cfi_offset;
 
-       switch (info->vendor) {
-       case CFI_CMDSET_INTEL_STANDARD:
-       case CFI_CMDSET_INTEL_EXTENDED:
-               flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
-               flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID);
-               udelay(1000); /* some flash are slow to respond */
-               info->manufacturer_id = flash_read_uchar (info,
-                                               FLASH_OFFSET_MANUFACTURER_ID);
-               info->device_id = flash_read_uchar (info,
-                                               FLASH_OFFSET_DEVICE_ID);
-               flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
-               break;
-       case CFI_CMDSET_AMD_STANDARD:
-       case CFI_CMDSET_AMD_EXTENDED:
-               flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
-               flash_unlock_seq(info, 0);
-               flash_write_cmd(info, 0, AMD_ADDR_START, FLASH_CMD_READ_ID);
-               udelay(1000); /* some flash are slow to respond */
-               info->manufacturer_id = flash_read_uchar (info,
-                                               FLASH_OFFSET_MANUFACTURER_ID);
-               info->device_id = flash_read_uchar (info,
-                                               FLASH_OFFSET_DEVICE_ID);
-               if (info->device_id == 0x7E) {
-                       /* AMD 3-byte (expanded) device ids */
-                       info->device_id2 = flash_read_uchar (info,
-                                               FLASH_OFFSET_DEVICE_ID2);
-                       info->device_id2 <<= 8;
-                       info->device_id2 |= flash_read_uchar (info,
-                                               FLASH_OFFSET_DEVICE_ID3);
+       flash_write_cmd (info, 0, 0, info->cmd_reset);
+       for (cfi_offset=0;
+            cfi_offset < sizeof(flash_offset_cfi) / sizeof(uint);
+            cfi_offset++) {
+               flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset],
+                                FLASH_CMD_CFI);
+               if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q')
+                   && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R')
+                   && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) {
+                       flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP,
+                                       sizeof(struct cfi_qry));
+                       info->interface = le16_to_cpu(qry->interface_desc);
+
+                       info->cfi_offset = flash_offset_cfi[cfi_offset];
+                       debug ("device interface is %d\n",
+                              info->interface);
+                       debug ("found port %d chip %d ",
+                              info->portwidth, info->chipwidth);
+                       debug ("port %d bits chip %d bits\n",
+                              info->portwidth << CFI_FLASH_SHIFT_WIDTH,
+                              info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
+
+                       /* calculate command offsets as in the Linux driver */
+                       info->addr_unlock1 = 0x555;
+                       info->addr_unlock2 = 0x2aa;
+
+                       /*
+                        * modify the unlock address if we are
+                        * in compatibility mode
+                        */
+                       if (    /* x8/x16 in x8 mode */
+                               ((info->chipwidth == FLASH_CFI_BY8) &&
+                                       (info->interface == FLASH_CFI_X8X16)) ||
+                               /* x16/x32 in x16 mode */
+                               ((info->chipwidth == FLASH_CFI_BY16) &&
+                                       (info->interface == FLASH_CFI_X16X32)))
+                       {
+                               info->addr_unlock1 = 0xaaa;
+                               info->addr_unlock2 = 0x555;
+                       }
+
+                       info->name = "CFI conformant";
+                       return 1;
                }
-               flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
-               break;
-       default:
-               break;
        }
+
+       return 0;
 }
 
-/*-----------------------------------------------------------------------
- * detect if flash is compatible with the Common Flash Interface (CFI)
- * http://www.jedec.org/download/search/jesd68.pdf
- *
-*/
-static int flash_detect_cfi (flash_info_t * info)
+static int flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry)
 {
-       int cfi_offset;
        debug ("flash detect cfi\n");
 
        for (info->portwidth = CFG_FLASH_CFI_WIDTH;
             info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) {
                for (info->chipwidth = FLASH_CFI_BY8;
                     info->chipwidth <= info->portwidth;
-                    info->chipwidth <<= 1) {
-                       flash_write_cmd (info, 0, 0, info->cmd_reset);
-                       for (cfi_offset=0; cfi_offset < sizeof(flash_offset_cfi)/sizeof(uint); cfi_offset++) {
-                               flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI);
-                               if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q')
-                                && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R')
-                                && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) {
-                                       info->interface = flash_read_ushort (info, 0, FLASH_OFFSET_INTERFACE);
-                                       info->cfi_offset=flash_offset_cfi[cfi_offset];
-                                       debug ("device interface is %d\n",
-                                               info->interface);
-                                       debug ("found port %d chip %d ",
-                                               info->portwidth, info->chipwidth);
-                                       debug ("port %d bits chip %d bits\n",
-                                               info->portwidth << CFI_FLASH_SHIFT_WIDTH,
-                                               info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
-                                       return 1;
-                               }
-                       }
-               }
+                    info->chipwidth <<= 1)
+                       if (__flash_detect_cfi(info, qry))
+                               return 1;
        }
        debug ("not found\n");
        return 0;
 }
 
+/*
+ * Manufacturer-specific quirks. Add workarounds for geometry
+ * reversal, etc. here.
+ */
+static void flash_fixup_amd(flash_info_t *info, struct cfi_qry *qry)
+{
+       /* check if flash geometry needs reversal */
+       if (qry->num_erase_regions > 1) {
+               /* reverse geometry if top boot part */
+               if (info->cfi_version < 0x3131) {
+                       /* CFI < 1.1, try to guess from device id */
+                       if ((info->device_id & 0x80) != 0)
+                               cfi_reverse_geometry(qry);
+               } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) {
+                       /* CFI >= 1.1, deduct from top/bottom flag */
+                       /* note: ext_addr is valid since cfi_version > 0 */
+                       cfi_reverse_geometry(qry);
+               }
+       }
+}
+
+static void flash_fixup_atmel(flash_info_t *info, struct cfi_qry *qry)
+{
+       int reverse_geometry = 0;
+
+       /* Check the "top boot" bit in the PRI */
+       if (info->ext_addr && !(flash_read_uchar(info, info->ext_addr + 6) & 1))
+               reverse_geometry = 1;
+
+       /* AT49BV6416(T) list the erase regions in the wrong order.
+        * However, the device ID is identical with the non-broken
+        * AT49BV642D since u-boot only reads the low byte (they
+        * differ in the high byte.) So leave out this fixup for now.
+        */
+#if 0
+       if (info->device_id == 0xd6 || info->device_id == 0xd2)
+               reverse_geometry = !reverse_geometry;
+#endif
+
+       if (reverse_geometry)
+               cfi_reverse_geometry(qry);
+}
+
 /*
  * The following code cannot be run from FLASH!
  *
@@ -1180,7 +1611,7 @@ ulong flash_get_size (ulong base, int banknum)
        uchar num_erase_regions;
        int erase_region_size;
        int erase_region_count;
-       int geometry_reversed = 0;
+       struct cfi_qry qry;
 
        info->ext_addr = 0;
        info->cfi_version = 0;
@@ -1190,56 +1621,50 @@ ulong flash_get_size (ulong base, int banknum)
 
        info->start[0] = base;
 
-       if (flash_detect_cfi (info)) {
-               info->vendor = flash_read_ushort (info, 0,
-                                       FLASH_OFFSET_PRIMARY_VENDOR);
-               flash_read_jedec_ids (info);
-               flash_write_cmd (info, 0, info->cfi_offset, FLASH_CMD_CFI);
-               num_erase_regions = flash_read_uchar (info,
-                                       FLASH_OFFSET_NUM_ERASE_REGIONS);
-               info->ext_addr = flash_read_ushort (info, 0,
-                                       FLASH_OFFSET_EXT_QUERY_T_P_ADDR);
+       if (flash_detect_cfi (info, &qry)) {
+               info->vendor = le16_to_cpu(qry.p_id);
+               info->ext_addr = le16_to_cpu(qry.p_adr);
+               num_erase_regions = qry.num_erase_regions;
+
                if (info->ext_addr) {
                        info->cfi_version = (ushort) flash_read_uchar (info,
                                                info->ext_addr + 3) << 8;
                        info->cfi_version |= (ushort) flash_read_uchar (info,
                                                info->ext_addr + 4);
                }
+
 #ifdef DEBUG
-               flash_printqry (info, 0);
+               flash_printqry (&qry);
 #endif
+
                switch (info->vendor) {
                case CFI_CMDSET_INTEL_STANDARD:
                case CFI_CMDSET_INTEL_EXTENDED:
-               default:
-                       info->cmd_reset = FLASH_CMD_RESET;
-#ifdef CFG_FLASH_PROTECTION
-                       /* read legacy lock/unlock bit from intel flash */
-                       if (info->ext_addr) {
-                               info->legacy_unlock = flash_read_uchar (info,
-                                               info->ext_addr + 5) & 0x08;
-                       }
-#endif
+                       cmdset_intel_init(info, &qry);
                        break;
                case CFI_CMDSET_AMD_STANDARD:
                case CFI_CMDSET_AMD_EXTENDED:
-                       info->cmd_reset = AMD_CMD_RESET;
-                       /* check if flash geometry needs reversal */
-                       if (num_erase_regions <= 1)
-                               break;
-                       /* reverse geometry if top boot part */
-                       if (info->cfi_version < 0x3131) {
-                               /* CFI < 1.1, try to guess from device id */
-                               if ((info->device_id & 0x80) != 0) {
-                                       geometry_reversed = 1;
-                               }
-                               break;
-                       }
-                       /* CFI >= 1.1, deduct from top/bottom flag */
-                       /* note: ext_addr is valid since cfi_version > 0 */
-                       if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) {
-                               geometry_reversed = 1;
-                       }
+                       cmdset_amd_init(info, &qry);
+                       break;
+               default:
+                       printf("CFI: Unknown command set 0x%x\n",
+                                       info->vendor);
+                       /*
+                        * Unfortunately, this means we don't know how
+                        * to get the chip back to Read mode. Might
+                        * as well try an Intel-style reset...
+                        */
+                       flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
+                       return 0;
+               }
+
+               /* Do manufacturer-specific fixups */
+               switch (info->manufacturer_id) {
+               case 0x0001:
+                       flash_fixup_amd(info, &qry);
+                       break;
+               case 0x001f:
+                       flash_fixup_atmel(info, &qry);
                        break;
                }
 
@@ -1267,26 +1692,27 @@ ulong flash_get_size (ulong base, int banknum)
                                        num_erase_regions, NUM_ERASE_REGIONS);
                                break;
                        }
-                       if (geometry_reversed)
-                               tmp = flash_read_long (info, 0,
-                                              FLASH_OFFSET_ERASE_REGIONS +
-                                              (num_erase_regions - 1 - i) * 4);
-                       else
-                               tmp = flash_read_long (info, 0,
-                                              FLASH_OFFSET_ERASE_REGIONS +
-                                              i * 4);
+
+                       tmp = le32_to_cpu(qry.erase_region_info[i]);
+                       debug("erase region %u: 0x%08lx\n", i, tmp);
+
+                       erase_region_count = (tmp & 0xffff) + 1;
+                       tmp >>= 16;
                        erase_region_size =
                                (tmp & 0xffff) ? ((tmp & 0xffff) * 256) : 128;
-                       tmp >>= 16;
-                       erase_region_count = (tmp & 0xffff) + 1;
                        debug ("erase_region_count = %d erase_region_size = %d\n",
                                erase_region_count, erase_region_size);
                        for (j = 0; j < erase_region_count; j++) {
+                               if (sect_cnt >= CFG_MAX_FLASH_SECT) {
+                                       printf("ERROR: too many flash sectors\n");
+                                       break;
+                               }
                                info->start[sect_cnt] = sector;
                                sector += (erase_region_size * size_ratio);
 
                                /*
-                                * Only read protection status from supported devices (intel...)
+                                * Only read protection status from
+                                * supported devices (intel...)
                                 */
                                switch (info->vendor) {
                                case CFI_CMDSET_INTEL_EXTENDED:
@@ -1297,7 +1723,8 @@ ulong flash_get_size (ulong base, int banknum)
                                                             FLASH_STATUS_PROTECT);
                                        break;
                                default:
-                                       info->protect[sect_cnt] = 0; /* default: not protected */
+                                       /* default: not protected */
+                                       info->protect[sect_cnt] = 0;
                                }
 
                                sect_cnt++;
@@ -1305,20 +1732,27 @@ ulong flash_get_size (ulong base, int banknum)
                }
 
                info->sector_count = sect_cnt;
+               info->size = 1 << qry.dev_size;
                /* multiply the size by the number of chips */
-               info->size = (1 << flash_read_uchar (info, FLASH_OFFSET_SIZE)) * size_ratio;
-               info->buffer_size = (1 << flash_read_ushort (info, 0, FLASH_OFFSET_BUFFER_SIZE));
-               tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT);
-               info->erase_blk_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_EMAX_TOUT)));
-               tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) *
-                       (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT));
-               info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
-               tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) *
-                     (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT));
-               info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
+               info->size *= size_ratio;
+               info->buffer_size = 1 << le16_to_cpu(qry.max_buf_write_size);
+               tmp = 1 << qry.block_erase_timeout_typ;
+               info->erase_blk_tout = tmp *
+                       (1 << qry.block_erase_timeout_max);
+               tmp = (1 << qry.buf_write_timeout_typ) *
+                       (1 << qry.buf_write_timeout_max);
+
+               /* round up when converting to ms */
+               info->buffer_write_tout = (tmp + 999) / 1000;
+               tmp = (1 << qry.word_write_timeout_typ) *
+                       (1 << qry.word_write_timeout_max);
+               /* round up when converting to ms */
+               info->write_tout = (tmp + 999) / 1000;
                info->flash_id = FLASH_MAN_CFI;
-               if ((info->interface == FLASH_CFI_X8X16) && (info->chipwidth == FLASH_CFI_BY8)) {
-                       info->portwidth >>= 1;  /* XXX - Need to test on x8/x16 in parallel. */
+               if ((info->interface == FLASH_CFI_X8X16) &&
+                   (info->chipwidth == FLASH_CFI_BY8)) {
+                       /* XXX - Need to test on x8/x16 in parallel. */
+                       info->portwidth >>= 1;
                }
        }
 
@@ -1326,203 +1760,106 @@ ulong flash_get_size (ulong base, int banknum)
        return (info->size);
 }
 
-/* loop through the sectors from the highest address
- * when the passed address is greater or equal to the sector address
- * we have a match
- */
-static flash_sect_t find_sector (flash_info_t * info, ulong addr)
-{
-       flash_sect_t sector;
-
-       for (sector = info->sector_count - 1; sector >= 0; sector--) {
-               if (addr >= info->start[sector])
-                       break;
-       }
-       return sector;
-}
-
 /*-----------------------------------------------------------------------
  */
-static int flash_write_cfiword (flash_info_t * info, ulong dest,
-                               cfiword_t cword)
+unsigned long flash_init (void)
 {
-       cfiptr_t ctladdr;
-       cfiptr_t cptr;
-       int flag;
-
-       ctladdr.cp = flash_make_addr (info, 0, 0);
-       cptr.cp = (uchar *) dest;
-
-       /* Check if Flash is (sufficiently) erased */
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               flag = ((cptr.cp[0] & cword.c) == cword.c);
-               break;
-       case FLASH_CFI_16BIT:
-               flag = ((cptr.wp[0] & cword.w) == cword.w);
-               break;
-       case FLASH_CFI_32BIT:
-               flag = ((cptr.lp[0] & cword.l) == cword.l);
-               break;
-       case FLASH_CFI_64BIT:
-               flag = ((cptr.llp[0] & cword.ll) == cword.ll);
-               break;
-       default:
-               return 2;
-       }
-       if (!flag)
-               return 2;
-
-       /* Disable interrupts which might cause a timeout here */
-       flag = disable_interrupts ();
+       unsigned long size = 0;
+       int i;
 
-       switch (info->vendor) {
-       case CFI_CMDSET_INTEL_EXTENDED:
-       case CFI_CMDSET_INTEL_STANDARD:
-               flash_write_cmd (info, 0, 0, FLASH_CMD_CLEAR_STATUS);
-               flash_write_cmd (info, 0, 0, FLASH_CMD_WRITE);
-               break;
-       case CFI_CMDSET_AMD_EXTENDED:
-       case CFI_CMDSET_AMD_STANDARD:
-               flash_unlock_seq (info, 0);
-               flash_write_cmd (info, 0, AMD_ADDR_START, AMD_CMD_WRITE);
-               break;
-       }
+#ifdef CFG_FLASH_PROTECTION
+       char *s = getenv("unlock");
+#endif
 
-       switch (info->portwidth) {
-       case FLASH_CFI_8BIT:
-               cptr.cp[0] = cword.c;
-               break;
-       case FLASH_CFI_16BIT:
-               cptr.wp[0] = cword.w;
-               break;
-       case FLASH_CFI_32BIT:
-               cptr.lp[0] = cword.l;
-               break;
-       case FLASH_CFI_64BIT:
-               cptr.llp[0] = cword.ll;
-               break;
-       }
+       /* Init: no FLASHes known */
+       for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
+               flash_info[i].flash_id = FLASH_UNKNOWN;
 
-       /* re-enable interrupts if necessary */
-       if (flag)
-               enable_interrupts ();
+               if (!flash_detect_legacy (bank_base[i], i))
+                       flash_get_size (bank_base[i], i);
+               size += flash_info[i].size;
+               if (flash_info[i].flash_id == FLASH_UNKNOWN) {
+#ifndef CFG_FLASH_QUIET_TEST
+                       printf ("## Unknown FLASH on Bank %d "
+                               "- Size = 0x%08lx = %ld MB\n",
+                               i+1, flash_info[i].size,
+                               flash_info[i].size << 20);
+#endif /* CFG_FLASH_QUIET_TEST */
+               }
+#ifdef CFG_FLASH_PROTECTION
+               else if ((s != NULL) && (strcmp(s, "yes") == 0)) {
+                       /*
+                        * Only the U-Boot image and it's environment
+                        * is protected, all other sectors are
+                        * unprotected (unlocked) if flash hardware
+                        * protection is used (CFG_FLASH_PROTECTION)
+                        * and the environment variable "unlock" is
+                        * set to "yes".
+                        */
+                       if (flash_info[i].legacy_unlock) {
+                               int k;
 
-       return flash_full_status_check (info, find_sector (info, dest),
-                                       info->write_tout, "write");
-}
+                               /*
+                                * Disable legacy_unlock temporarily,
+                                * since flash_real_protect would
+                                * relock all other sectors again
+                                * otherwise.
+                                */
+                               flash_info[i].legacy_unlock = 0;
 
-#ifdef CFG_FLASH_USE_BUFFER_WRITE
+                               /*
+                                * Legacy unlocking (e.g. Intel J3) ->
+                                * unlock only one sector. This will
+                                * unlock all sectors.
+                                */
+                               flash_real_protect (&flash_info[i], 0, 0);
 
-static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
-                                 int len)
-{
-       flash_sect_t sector;
-       int cnt;
-       int retcode;
-       volatile cfiptr_t src;
-       volatile cfiptr_t dst;
+                               flash_info[i].legacy_unlock = 1;
 
-       switch (info->vendor) {
-       case CFI_CMDSET_INTEL_STANDARD:
-       case CFI_CMDSET_INTEL_EXTENDED:
-               src.cp = cp;
-               dst.cp = (uchar *) dest;
-               sector = find_sector (info, dest);
-               flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
-               flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
-               if ((retcode = flash_status_check (info, sector, info->buffer_write_tout,
-                                                  "write to buffer")) == ERR_OK) {
-                       /* reduce the number of loops by the width of the port  */
-                       switch (info->portwidth) {
-                       case FLASH_CFI_8BIT:
-                               cnt = len;
-                               break;
-                       case FLASH_CFI_16BIT:
-                               cnt = len >> 1;
-                               break;
-                       case FLASH_CFI_32BIT:
-                               cnt = len >> 2;
-                               break;
-                       case FLASH_CFI_64BIT:
-                               cnt = len >> 3;
-                               break;
-                       default:
-                               return ERR_INVAL;
-                               break;
-                       }
-                       flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
-                       while (cnt-- > 0) {
-                               switch (info->portwidth) {
-                               case FLASH_CFI_8BIT:
-                                       *dst.cp++ = *src.cp++;
-                                       break;
-                               case FLASH_CFI_16BIT:
-                                       *dst.wp++ = *src.wp++;
-                                       break;
-                               case FLASH_CFI_32BIT:
-                                       *dst.lp++ = *src.lp++;
-                                       break;
-                               case FLASH_CFI_64BIT:
-                                       *dst.llp++ = *src.llp++;
-                                       break;
-                               default:
-                                       return ERR_INVAL;
-                                       break;
-                               }
+                               /*
+                                * Manually mark other sectors as
+                                * unlocked (unprotected)
+                                */
+                               for (k = 1; k < flash_info[i].sector_count; k++)
+                                       flash_info[i].protect[k] = 0;
+                       } else {
+                               /*
+                                * No legancy unlocking -> unlock all sectors
+                                */
+                               flash_protect (FLAG_PROTECT_CLEAR,
+                                              flash_info[i].start[0],
+                                              flash_info[i].start[0]
+                                              + flash_info[i].size - 1,
+                                              &flash_info[i]);
                        }
-                       flash_write_cmd (info, sector, 0,
-                                        FLASH_CMD_WRITE_BUFFER_CONFIRM);
-                       retcode = flash_full_status_check (info, sector,
-                                                          info->buffer_write_tout,
-                                                          "buffer write");
                }
-               return retcode;
-
-       case CFI_CMDSET_AMD_STANDARD:
-       case CFI_CMDSET_AMD_EXTENDED:
-               src.cp = cp;
-               dst.cp = (uchar *) dest;
-               sector = find_sector (info, dest);
-
-               flash_unlock_seq(info,0);
-               flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_TO_BUFFER);
+#endif /* CFG_FLASH_PROTECTION */
+       }
 
-               switch (info->portwidth) {
-               case FLASH_CFI_8BIT:
-                       cnt = len;
-                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
-                       while (cnt-- > 0) *dst.cp++ = *src.cp++;
-                       break;
-               case FLASH_CFI_16BIT:
-                       cnt = len >> 1;
-                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
-                       while (cnt-- > 0) *dst.wp++ = *src.wp++;
-                       break;
-               case FLASH_CFI_32BIT:
-                       cnt = len >> 2;
-                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
-                       while (cnt-- > 0) *dst.lp++ = *src.lp++;
-                       break;
-               case FLASH_CFI_64BIT:
-                       cnt = len >> 3;
-                       flash_write_cmd (info, sector, 0,  (uchar) cnt - 1);
-                       while (cnt-- > 0) *dst.llp++ = *src.llp++;
-                       break;
-               default:
-                       return ERR_INVAL;
-               }
+       /* Monitor protection ON by default */
+#if (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
+       flash_protect (FLAG_PROTECT_SET,
+                      CFG_MONITOR_BASE,
+                      CFG_MONITOR_BASE + monitor_flash_len  - 1,
+                      flash_get_info(CFG_MONITOR_BASE));
+#endif
 
-               flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
-               retcode = flash_full_status_check (info, sector, info->buffer_write_tout,
-                                                  "buffer write");
-               return retcode;
+       /* Environment protection ON by default */
+#ifdef CFG_ENV_IS_IN_FLASH
+       flash_protect (FLAG_PROTECT_SET,
+                      CFG_ENV_ADDR,
+                      CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
+                      flash_get_info(CFG_ENV_ADDR));
+#endif
 
-       default:
-               debug ("Unknown Command Set\n");
-               return ERR_INVAL;
-       }
+       /* Redundant environment protection ON by default */
+#ifdef CFG_ENV_ADDR_REDUND
+       flash_protect (FLAG_PROTECT_SET,
+                      CFG_ENV_ADDR_REDUND,
+                      CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
+                      flash_get_info(CFG_ENV_ADDR_REDUND));
+#endif
+       return (size);
 }
-#endif /* CFG_FLASH_USE_BUFFER_WRITE */
 
 #endif /* CFG_FLASH_CFI */
diff --git a/drivers/mtd/jedec_flash.c b/drivers/mtd/jedec_flash.c
new file mode 100644 (file)
index 0000000..94e87cb
--- /dev/null
@@ -0,0 +1,311 @@
+/*
+ * (C) Copyright 2007
+ * Michael Schwingen, <michael@schwingen.org>
+ *
+ * based in great part on jedec_probe.c from linux kernel:
+ * (C) 2000 Red Hat. GPL'd.
+ * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot 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
+ *
+ */
+
+/* The DEBUG define must be before common to enable debugging */
+/*#define DEBUG*/
+
+#include <common.h>
+#include <asm/processor.h>
+#include <asm/io.h>
+#include <asm/byteorder.h>
+#include <environment.h>
+
+#define P_ID_AMD_STD CFI_CMDSET_AMD_LEGACY
+
+/* Manufacturers */
+#define MANUFACTURER_AMD       0x0001
+#define MANUFACTURER_SST       0x00BF
+
+/* AMD */
+#define AM29DL800BB    0x22C8
+#define AM29DL800BT    0x224A
+
+#define AM29F800BB     0x2258
+#define AM29F800BT     0x22D6
+#define AM29LV400BB    0x22BA
+#define AM29LV400BT    0x22B9
+#define AM29LV800BB    0x225B
+#define AM29LV800BT    0x22DA
+#define AM29LV160DT    0x22C4
+#define AM29LV160DB    0x2249
+#define AM29F017D      0x003D
+#define AM29F016D      0x00AD
+#define AM29F080       0x00D5
+#define AM29F040       0x00A4
+#define AM29LV040B     0x004F
+#define AM29F032B      0x0041
+#define AM29F002T      0x00B0
+
+/* SST */
+#define SST39LF800     0x2781
+#define SST39LF160     0x2782
+#define SST39VF1601    0x234b
+#define SST39LF512     0x00D4
+#define SST39LF010     0x00D5
+#define SST39LF020     0x00D6
+#define SST39LF040     0x00D7
+#define SST39SF010A    0x00B5
+#define SST39SF020A    0x00B6
+
+
+/*
+ * Unlock address sets for AMD command sets.
+ * Intel command sets use the MTD_UADDR_UNNECESSARY.
+ * Each identifier, except MTD_UADDR_UNNECESSARY, and
+ * MTD_UADDR_NO_SUPPORT must be defined below in unlock_addrs[].
+ * MTD_UADDR_NOT_SUPPORTED must be 0 so that structure
+ * initialization need not require initializing all of the
+ * unlock addresses for all bit widths.
+ */
+enum uaddr {
+       MTD_UADDR_NOT_SUPPORTED = 0,    /* data width not supported */
+       MTD_UADDR_0x0555_0x02AA,
+       MTD_UADDR_0x0555_0x0AAA,
+       MTD_UADDR_0x5555_0x2AAA,
+       MTD_UADDR_0x0AAA_0x0555,
+       MTD_UADDR_DONT_CARE,            /* Requires an arbitrary address */
+       MTD_UADDR_UNNECESSARY,          /* Does not require any address */
+};
+
+
+struct unlock_addr {
+       u32 addr1;
+       u32 addr2;
+};
+
+
+/*
+ * I don't like the fact that the first entry in unlock_addrs[]
+ * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore,
+ * should not be used.  The  problem is that structures with
+ * initializers have extra fields initialized to 0.  It is _very_
+ * desireable to have the unlock address entries for unsupported
+ * data widths automatically initialized - that means that
+ * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here
+ * must go unused.
+ */
+static const struct unlock_addr  unlock_addrs[] = {
+       [MTD_UADDR_NOT_SUPPORTED] = {
+               .addr1 = 0xffff,
+               .addr2 = 0xffff
+       },
+
+       [MTD_UADDR_0x0555_0x02AA] = {
+               .addr1 = 0x0555,
+               .addr2 = 0x02aa
+       },
+
+       [MTD_UADDR_0x0555_0x0AAA] = {
+               .addr1 = 0x0555,
+               .addr2 = 0x0aaa
+       },
+
+       [MTD_UADDR_0x5555_0x2AAA] = {
+               .addr1 = 0x5555,
+               .addr2 = 0x2aaa
+       },
+
+       [MTD_UADDR_0x0AAA_0x0555] = {
+               .addr1 = 0x0AAA,
+               .addr2 = 0x0555
+       },
+
+       [MTD_UADDR_DONT_CARE] = {
+               .addr1 = 0x0000,      /* Doesn't matter which address */
+               .addr2 = 0x0000       /* is used - must be last entry */
+       },
+
+       [MTD_UADDR_UNNECESSARY] = {
+               .addr1 = 0x0000,
+               .addr2 = 0x0000
+       }
+};
+
+
+struct amd_flash_info {
+       const __u16 mfr_id;
+       const __u16 dev_id;
+       const char *name;
+       const int DevSize;
+       const int NumEraseRegions;
+       const int CmdSet;
+       const __u8 uaddr[4];            /* unlock addrs for 8, 16, 32, 64 */
+       const ulong regions[6];
+};
+
+#define ERASEINFO(size,blocks) (size<<8)|(blocks-1)
+
+#define SIZE_64KiB  16
+#define SIZE_128KiB 17
+#define SIZE_256KiB 18
+#define SIZE_512KiB 19
+#define SIZE_1MiB   20
+#define SIZE_2MiB   21
+#define SIZE_4MiB   22
+#define SIZE_8MiB   23
+
+static const struct amd_flash_info jedec_table[] = {
+#ifdef CFG_FLASH_LEGACY_256Kx8
+       {
+               .mfr_id         = MANUFACTURER_SST,
+               .dev_id         = SST39LF020,
+               .name           = "SST 39LF020",
+               .uaddr          = {
+                       [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */
+               },
+               .DevSize        = SIZE_256KiB,
+               .CmdSet         = P_ID_AMD_STD,
+               .NumEraseRegions= 1,
+               .regions        = {
+                       ERASEINFO(0x01000,64),
+               }
+       },
+#endif
+#ifdef CFG_FLASH_LEGACY_512Kx8
+       {
+               .mfr_id         = MANUFACTURER_AMD,
+               .dev_id         = AM29LV040B,
+               .name           = "AMD AM29LV040B",
+               .uaddr          = {
+                       [0] = MTD_UADDR_0x0555_0x02AA /* x8 */
+               },
+               .DevSize        = SIZE_512KiB,
+               .CmdSet         = P_ID_AMD_STD,
+               .NumEraseRegions= 1,
+               .regions        = {
+                       ERASEINFO(0x10000,8),
+               }
+       },
+       {
+               .mfr_id         = MANUFACTURER_SST,
+               .dev_id         = SST39LF040,
+               .name           = "SST 39LF040",
+               .uaddr          = {
+                       [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */
+               },
+               .DevSize        = SIZE_512KiB,
+               .CmdSet         = P_ID_AMD_STD,
+               .NumEraseRegions= 1,
+               .regions        = {
+                       ERASEINFO(0x01000,128),
+               }
+       },
+#endif
+};
+
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+
+static inline void fill_info(flash_info_t *info, const struct amd_flash_info *jedec_entry, ulong base)
+{
+       int i,j;
+       int sect_cnt;
+       int size_ratio;
+       int total_size;
+       enum uaddr uaddr_idx;
+
+       size_ratio = info->portwidth / info->chipwidth;
+
+       debug("Found JEDEC Flash: %s\n", jedec_entry->name);
+       info->vendor = jedec_entry->CmdSet;
+       /* Todo: do we need device-specific timeouts? */
+       info->erase_blk_tout = 30000;
+       info->buffer_write_tout = 1000;
+       info->write_tout = 100;
+       info->name = jedec_entry->name;
+
+       /* copy unlock addresses from device table to CFI info struct. This
+          is just here because the addresses are in the table anyway - if
+          the flash is not detected due to wrong unlock addresses,
+          flash_detect_legacy would have to try all of them before we even
+          get here. */
+       switch(info->chipwidth) {
+       case FLASH_CFI_8BIT:
+               uaddr_idx = jedec_entry->uaddr[0];
+               break;
+       case FLASH_CFI_16BIT:
+               uaddr_idx = jedec_entry->uaddr[1];
+               break;
+       case FLASH_CFI_32BIT:
+               uaddr_idx = jedec_entry->uaddr[2];
+               break;
+       default:
+               uaddr_idx = MTD_UADDR_NOT_SUPPORTED;
+               break;
+       }
+
+       debug("unlock address index %d\n", uaddr_idx);
+       info->addr_unlock1 = unlock_addrs[uaddr_idx].addr1;
+       info->addr_unlock2 = unlock_addrs[uaddr_idx].addr2;
+       debug("unlock addresses are 0x%x/0x%x\n", info->addr_unlock1, info->addr_unlock2);
+
+       sect_cnt = 0;
+       total_size = 0;
+       for (i = 0; i < jedec_entry->NumEraseRegions; i++) {
+               ulong erase_region_size = jedec_entry->regions[i] >> 8;
+               ulong erase_region_count = (jedec_entry->regions[i] & 0xff) + 1;
+
+               total_size += erase_region_size * erase_region_count;
+               debug ("erase_region_count = %d erase_region_size = %d\n",
+                      erase_region_count, erase_region_size);
+               for (j = 0; j < erase_region_count; j++) {
+                       if (sect_cnt >= CFG_MAX_FLASH_SECT) {
+                               printf("ERROR: too many flash sectors\n");
+                               break;
+                       }
+                       info->start[sect_cnt] = base;
+                       base += (erase_region_size * size_ratio);
+                       sect_cnt++;
+               }
+       }
+       info->sector_count = sect_cnt;
+       info->size = total_size * size_ratio;
+}
+
+/*-----------------------------------------------------------------------
+ * match jedec ids against table. If a match is found, fill flash_info entry
+ */
+int jedec_flash_match(flash_info_t *info, ulong base)
+{
+       int ret = 0;
+       int i;
+       ulong mask = 0xFFFF;
+       if (info->chipwidth == 1)
+               mask = 0xFF;
+
+       for (i = 0; i < ARRAY_SIZE(jedec_table); i++) {
+               if ((jedec_table[i].mfr_id & mask) == (info->manufacturer_id & mask) &&
+                   (jedec_table[i].dev_id & mask) == (info->device_id & mask)) {
+                       fill_info(info, &jedec_table[i], base);
+                       ret = 1;
+                       break;
+               }
+       }
+       return ret;
+}
index 47c18e7e86965defdf8500c739bffe4dc1424a19..029b7f9eeb41de1431927e00a26e2aea980e7eef 100644 (file)
@@ -33,6 +33,32 @@ static inline void sync(void)
 {
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 /*
  * Generic virtual read/write.  Note that we don't support half-word
  * read/writes.  We define __arch_*[bl] here, and leave __arch_*w
diff --git a/include/asm-avr32/arch-at32ap7000/clk.h b/include/asm-avr32/arch-at32ap7000/clk.h
deleted file mode 100644 (file)
index 7e20d97..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2006 Atmel Corporation
- *
- * 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
- */
-#ifndef __ASM_AVR32_ARCH_CLK_H__
-#define __ASM_AVR32_ARCH_CLK_H__
-
-#ifdef CONFIG_PLL
-#define MAIN_CLK_RATE ((CFG_OSC0_HZ / CFG_PLL0_DIV) * CFG_PLL0_MUL)
-#else
-#define MAIN_CLK_RATE (CFG_OSC0_HZ)
-#endif
-
-static inline unsigned long get_cpu_clk_rate(void)
-{
-       return MAIN_CLK_RATE >> CFG_CLKDIV_CPU;
-}
-static inline unsigned long get_hsb_clk_rate(void)
-{
-       return MAIN_CLK_RATE >> CFG_CLKDIV_HSB;
-}
-static inline unsigned long get_pba_clk_rate(void)
-{
-       return MAIN_CLK_RATE >> CFG_CLKDIV_PBA;
-}
-static inline unsigned long get_pbb_clk_rate(void)
-{
-       return MAIN_CLK_RATE >> CFG_CLKDIV_PBB;
-}
-
-/* Accessors for specific devices. More will be added as needed. */
-static inline unsigned long get_sdram_clk_rate(void)
-{
-       return get_hsb_clk_rate();
-}
-static inline unsigned long get_usart_clk_rate(unsigned int dev_id)
-{
-       return get_pba_clk_rate();
-}
-static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
-{
-       return get_pbb_clk_rate();
-}
-static inline unsigned long get_macb_hclk_rate(unsigned int dev_id)
-{
-       return get_hsb_clk_rate();
-}
-static inline unsigned long get_mci_clk_rate(void)
-{
-       return get_pbb_clk_rate();
-}
-
-#endif /* __ASM_AVR32_ARCH_CLK_H__ */
diff --git a/include/asm-avr32/arch-at32ap7000/gpio.h b/include/asm-avr32/arch-at32ap7000/gpio.h
deleted file mode 100644 (file)
index e4812d4..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (C) 2006 Atmel Corporation
- *
- * 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
- */
-#ifndef __ASM_AVR32_ARCH_GPIO_H__
-#define __ASM_AVR32_ARCH_GPIO_H__
-
-#include <asm/arch/memory-map.h>
-
-#define NR_GPIO_CONTROLLERS    5
-
-/*
- * Pin numbers identifying specific GPIO pins on the chip.
- */
-#define GPIO_PIOA_BASE (0)
-#define GPIO_PIN_PA0   (GPIO_PIOA_BASE +  0)
-#define GPIO_PIN_PA1   (GPIO_PIOA_BASE +  1)
-#define GPIO_PIN_PA2   (GPIO_PIOA_BASE +  2)
-#define GPIO_PIN_PA3   (GPIO_PIOA_BASE +  3)
-#define GPIO_PIN_PA4   (GPIO_PIOA_BASE +  4)
-#define GPIO_PIN_PA5   (GPIO_PIOA_BASE +  5)
-#define GPIO_PIN_PA6   (GPIO_PIOA_BASE +  6)
-#define GPIO_PIN_PA7   (GPIO_PIOA_BASE +  7)
-#define GPIO_PIN_PA8   (GPIO_PIOA_BASE +  8)
-#define GPIO_PIN_PA9   (GPIO_PIOA_BASE +  9)
-#define GPIO_PIN_PA10  (GPIO_PIOA_BASE + 10)
-#define GPIO_PIN_PA11  (GPIO_PIOA_BASE + 11)
-#define GPIO_PIN_PA12  (GPIO_PIOA_BASE + 12)
-#define GPIO_PIN_PA13  (GPIO_PIOA_BASE + 13)
-#define GPIO_PIN_PA14  (GPIO_PIOA_BASE + 14)
-#define GPIO_PIN_PA15  (GPIO_PIOA_BASE + 15)
-#define GPIO_PIN_PA16  (GPIO_PIOA_BASE + 16)
-#define GPIO_PIN_PA17  (GPIO_PIOA_BASE + 17)
-#define GPIO_PIN_PA18  (GPIO_PIOA_BASE + 18)
-#define GPIO_PIN_PA19  (GPIO_PIOA_BASE + 19)
-#define GPIO_PIN_PA20  (GPIO_PIOA_BASE + 20)
-#define GPIO_PIN_PA21  (GPIO_PIOA_BASE + 21)
-#define GPIO_PIN_PA22  (GPIO_PIOA_BASE + 22)
-#define GPIO_PIN_PA23  (GPIO_PIOA_BASE + 23)
-#define GPIO_PIN_PA24  (GPIO_PIOA_BASE + 24)
-#define GPIO_PIN_PA25  (GPIO_PIOA_BASE + 25)
-#define GPIO_PIN_PA26  (GPIO_PIOA_BASE + 26)
-#define GPIO_PIN_PA27  (GPIO_PIOA_BASE + 27)
-#define GPIO_PIN_PA28  (GPIO_PIOA_BASE + 28)
-#define GPIO_PIN_PA29  (GPIO_PIOA_BASE + 29)
-#define GPIO_PIN_PA30  (GPIO_PIOA_BASE + 30)
-#define GPIO_PIN_PA31  (GPIO_PIOA_BASE + 31)
-
-#define GPIO_PIOB_BASE (GPIO_PIOA_BASE + 32)
-#define GPIO_PIN_PB0   (GPIO_PIOB_BASE +  0)
-#define GPIO_PIN_PB1   (GPIO_PIOB_BASE +  1)
-#define GPIO_PIN_PB2   (GPIO_PIOB_BASE +  2)
-#define GPIO_PIN_PB3   (GPIO_PIOB_BASE +  3)
-#define GPIO_PIN_PB4   (GPIO_PIOB_BASE +  4)
-#define GPIO_PIN_PB5   (GPIO_PIOB_BASE +  5)
-#define GPIO_PIN_PB6   (GPIO_PIOB_BASE +  6)
-#define GPIO_PIN_PB7   (GPIO_PIOB_BASE +  7)
-#define GPIO_PIN_PB8   (GPIO_PIOB_BASE +  8)
-#define GPIO_PIN_PB9   (GPIO_PIOB_BASE +  9)
-#define GPIO_PIN_PB10  (GPIO_PIOB_BASE + 10)
-#define GPIO_PIN_PB11  (GPIO_PIOB_BASE + 11)
-#define GPIO_PIN_PB12  (GPIO_PIOB_BASE + 12)
-#define GPIO_PIN_PB13  (GPIO_PIOB_BASE + 13)
-#define GPIO_PIN_PB14  (GPIO_PIOB_BASE + 14)
-#define GPIO_PIN_PB15  (GPIO_PIOB_BASE + 15)
-#define GPIO_PIN_PB16  (GPIO_PIOB_BASE + 16)
-#define GPIO_PIN_PB17  (GPIO_PIOB_BASE + 17)
-#define GPIO_PIN_PB18  (GPIO_PIOB_BASE + 18)
-#define GPIO_PIN_PB19  (GPIO_PIOB_BASE + 19)
-#define GPIO_PIN_PB20  (GPIO_PIOB_BASE + 20)
-#define GPIO_PIN_PB21  (GPIO_PIOB_BASE + 21)
-#define GPIO_PIN_PB22  (GPIO_PIOB_BASE + 22)
-#define GPIO_PIN_PB23  (GPIO_PIOB_BASE + 23)
-#define GPIO_PIN_PB24  (GPIO_PIOB_BASE + 24)
-#define GPIO_PIN_PB25  (GPIO_PIOB_BASE + 25)
-#define GPIO_PIN_PB26  (GPIO_PIOB_BASE + 26)
-#define GPIO_PIN_PB27  (GPIO_PIOB_BASE + 27)
-#define GPIO_PIN_PB28  (GPIO_PIOB_BASE + 28)
-#define GPIO_PIN_PB29  (GPIO_PIOB_BASE + 29)
-#define GPIO_PIN_PB30  (GPIO_PIOB_BASE + 30)
-
-#define GPIO_PIOC_BASE (GPIO_PIOB_BASE + 32)
-#define GPIO_PIN_PC0   (GPIO_PIOC_BASE +  0)
-#define GPIO_PIN_PC1   (GPIO_PIOC_BASE +  1)
-#define GPIO_PIN_PC2   (GPIO_PIOC_BASE +  2)
-#define GPIO_PIN_PC3   (GPIO_PIOC_BASE +  3)
-#define GPIO_PIN_PC4   (GPIO_PIOC_BASE +  4)
-#define GPIO_PIN_PC5   (GPIO_PIOC_BASE +  5)
-#define GPIO_PIN_PC6   (GPIO_PIOC_BASE +  6)
-#define GPIO_PIN_PC7   (GPIO_PIOC_BASE +  7)
-#define GPIO_PIN_PC8   (GPIO_PIOC_BASE +  8)
-#define GPIO_PIN_PC9   (GPIO_PIOC_BASE +  9)
-#define GPIO_PIN_PC10  (GPIO_PIOC_BASE + 10)
-#define GPIO_PIN_PC11  (GPIO_PIOC_BASE + 11)
-#define GPIO_PIN_PC12  (GPIO_PIOC_BASE + 12)
-#define GPIO_PIN_PC13  (GPIO_PIOC_BASE + 13)
-#define GPIO_PIN_PC14  (GPIO_PIOC_BASE + 14)
-#define GPIO_PIN_PC15  (GPIO_PIOC_BASE + 15)
-#define GPIO_PIN_PC16  (GPIO_PIOC_BASE + 16)
-#define GPIO_PIN_PC17  (GPIO_PIOC_BASE + 17)
-#define GPIO_PIN_PC18  (GPIO_PIOC_BASE + 18)
-#define GPIO_PIN_PC19  (GPIO_PIOC_BASE + 19)
-#define GPIO_PIN_PC20  (GPIO_PIOC_BASE + 20)
-#define GPIO_PIN_PC21  (GPIO_PIOC_BASE + 21)
-#define GPIO_PIN_PC22  (GPIO_PIOC_BASE + 22)
-#define GPIO_PIN_PC23  (GPIO_PIOC_BASE + 23)
-#define GPIO_PIN_PC24  (GPIO_PIOC_BASE + 24)
-#define GPIO_PIN_PC25  (GPIO_PIOC_BASE + 25)
-#define GPIO_PIN_PC26  (GPIO_PIOC_BASE + 26)
-#define GPIO_PIN_PC27  (GPIO_PIOC_BASE + 27)
-#define GPIO_PIN_PC28  (GPIO_PIOC_BASE + 28)
-#define GPIO_PIN_PC29  (GPIO_PIOC_BASE + 29)
-#define GPIO_PIN_PC30  (GPIO_PIOC_BASE + 30)
-#define GPIO_PIN_PC31  (GPIO_PIOC_BASE + 31)
-
-#define GPIO_PIOD_BASE (GPIO_PIOC_BASE + 32)
-#define GPIO_PIN_PD0   (GPIO_PIOD_BASE +  0)
-#define GPIO_PIN_PD1   (GPIO_PIOD_BASE +  1)
-#define GPIO_PIN_PD2   (GPIO_PIOD_BASE +  2)
-#define GPIO_PIN_PD3   (GPIO_PIOD_BASE +  3)
-#define GPIO_PIN_PD4   (GPIO_PIOD_BASE +  4)
-#define GPIO_PIN_PD5   (GPIO_PIOD_BASE +  5)
-#define GPIO_PIN_PD6   (GPIO_PIOD_BASE +  6)
-#define GPIO_PIN_PD7   (GPIO_PIOD_BASE +  7)
-#define GPIO_PIN_PD8   (GPIO_PIOD_BASE +  8)
-#define GPIO_PIN_PD9   (GPIO_PIOD_BASE +  9)
-#define GPIO_PIN_PD10  (GPIO_PIOD_BASE + 10)
-#define GPIO_PIN_PD11  (GPIO_PIOD_BASE + 11)
-#define GPIO_PIN_PD12  (GPIO_PIOD_BASE + 12)
-#define GPIO_PIN_PD13  (GPIO_PIOD_BASE + 13)
-#define GPIO_PIN_PD14  (GPIO_PIOD_BASE + 14)
-#define GPIO_PIN_PD15  (GPIO_PIOD_BASE + 15)
-#define GPIO_PIN_PD16  (GPIO_PIOD_BASE + 16)
-#define GPIO_PIN_PD17  (GPIO_PIOD_BASE + 17)
-
-#define GPIO_PIOE_BASE (GPIO_PIOD_BASE + 32)
-#define GPIO_PIN_PE0   (GPIO_PIOE_BASE +  0)
-#define GPIO_PIN_PE1   (GPIO_PIOE_BASE +  1)
-#define GPIO_PIN_PE2   (GPIO_PIOE_BASE +  2)
-#define GPIO_PIN_PE3   (GPIO_PIOE_BASE +  3)
-#define GPIO_PIN_PE4   (GPIO_PIOE_BASE +  4)
-#define GPIO_PIN_PE5   (GPIO_PIOE_BASE +  5)
-#define GPIO_PIN_PE6   (GPIO_PIOE_BASE +  6)
-#define GPIO_PIN_PE7   (GPIO_PIOE_BASE +  7)
-#define GPIO_PIN_PE8   (GPIO_PIOE_BASE +  8)
-#define GPIO_PIN_PE9   (GPIO_PIOE_BASE +  9)
-#define GPIO_PIN_PE10  (GPIO_PIOE_BASE + 10)
-#define GPIO_PIN_PE11  (GPIO_PIOE_BASE + 11)
-#define GPIO_PIN_PE12  (GPIO_PIOE_BASE + 12)
-#define GPIO_PIN_PE13  (GPIO_PIOE_BASE + 13)
-#define GPIO_PIN_PE14  (GPIO_PIOE_BASE + 14)
-#define GPIO_PIN_PE15  (GPIO_PIOE_BASE + 15)
-#define GPIO_PIN_PE16  (GPIO_PIOE_BASE + 16)
-#define GPIO_PIN_PE17  (GPIO_PIOE_BASE + 17)
-#define GPIO_PIN_PE18  (GPIO_PIOE_BASE + 18)
-#define GPIO_PIN_PE19  (GPIO_PIOE_BASE + 19)
-#define GPIO_PIN_PE20  (GPIO_PIOE_BASE + 20)
-#define GPIO_PIN_PE21  (GPIO_PIOE_BASE + 21)
-#define GPIO_PIN_PE22  (GPIO_PIOE_BASE + 22)
-#define GPIO_PIN_PE23  (GPIO_PIOE_BASE + 23)
-#define GPIO_PIN_PE24  (GPIO_PIOE_BASE + 24)
-#define GPIO_PIN_PE25  (GPIO_PIOE_BASE + 25)
-#define GPIO_PIN_PE26  (GPIO_PIOE_BASE + 26)
-
-static inline void *gpio_pin_to_addr(unsigned int pin)
-{
-       switch (pin >> 5) {
-       case 0:
-               return (void *)PIOA_BASE;
-       case 1:
-               return (void *)PIOB_BASE;
-       case 2:
-               return (void *)PIOC_BASE;
-       case 3:
-               return (void *)PIOD_BASE;
-       case 4:
-               return (void *)PIOE_BASE;
-       default:
-               return NULL;
-       }
-}
-
-void gpio_select_periph_A(unsigned int pin, int use_pullup);
-void gpio_select_periph_B(unsigned int pin, int use_pullup);
-
-void gpio_enable_ebi(void);
-void gpio_enable_usart0(void);
-void gpio_enable_usart1(void);
-void gpio_enable_usart2(void);
-void gpio_enable_usart3(void);
-void gpio_enable_macb0(void);
-void gpio_enable_macb1(void);
-void gpio_enable_mmci(void);
-
-#endif /* __ASM_AVR32_ARCH_GPIO_H__ */
diff --git a/include/asm-avr32/arch-at32ap7000/hmatrix2.h b/include/asm-avr32/arch-at32ap7000/hmatrix2.h
deleted file mode 100644 (file)
index b0e787a..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Register definition for the High-speed Bus Matrix
- */
-#ifndef __ASM_AVR32_HMATRIX2_H__
-#define __ASM_AVR32_HMATRIX2_H__
-
-/* HMATRIX2 register offsets */
-#define HMATRIX2_MCFG0                         0x0000
-#define HMATRIX2_MCFG1                         0x0004
-#define HMATRIX2_MCFG2                         0x0008
-#define HMATRIX2_MCFG3                         0x000c
-#define HMATRIX2_MCFG4                         0x0010
-#define HMATRIX2_MCFG5                         0x0014
-#define HMATRIX2_MCFG6                         0x0018
-#define HMATRIX2_MCFG7                         0x001c
-#define HMATRIX2_MCFG8                         0x0020
-#define HMATRIX2_MCFG9                         0x0024
-#define HMATRIX2_MCFG10                                0x0028
-#define HMATRIX2_MCFG11                                0x002c
-#define HMATRIX2_MCFG12                                0x0030
-#define HMATRIX2_MCFG13                                0x0034
-#define HMATRIX2_MCFG14                                0x0038
-#define HMATRIX2_MCFG15                                0x003c
-#define HMATRIX2_SCFG0                         0x0040
-#define HMATRIX2_SCFG1                         0x0044
-#define HMATRIX2_SCFG2                         0x0048
-#define HMATRIX2_SCFG3                         0x004c
-#define HMATRIX2_SCFG4                         0x0050
-#define HMATRIX2_SCFG5                         0x0054
-#define HMATRIX2_SCFG6                         0x0058
-#define HMATRIX2_SCFG7                         0x005c
-#define HMATRIX2_SCFG8                         0x0060
-#define HMATRIX2_SCFG9                         0x0064
-#define HMATRIX2_SCFG10                                0x0068
-#define HMATRIX2_SCFG11                                0x006c
-#define HMATRIX2_SCFG12                                0x0070
-#define HMATRIX2_SCFG13                                0x0074
-#define HMATRIX2_SCFG14                                0x0078
-#define HMATRIX2_SCFG15                                0x007c
-#define HMATRIX2_PRAS0                         0x0080
-#define HMATRIX2_PRBS0                         0x0084
-#define HMATRIX2_PRAS1                         0x0088
-#define HMATRIX2_PRBS1                         0x008c
-#define HMATRIX2_PRAS2                         0x0090
-#define HMATRIX2_PRBS2                         0x0094
-#define HMATRIX2_PRAS3                         0x0098
-#define HMATRIX2_PRBS3                         0x009c
-#define HMATRIX2_PRAS4                         0x00a0
-#define HMATRIX2_PRBS4                         0x00a4
-#define HMATRIX2_PRAS5                         0x00a8
-#define HMATRIX2_PRBS5                         0x00ac
-#define HMATRIX2_PRAS6                         0x00b0
-#define HMATRIX2_PRBS6                         0x00b4
-#define HMATRIX2_PRAS7                         0x00b8
-#define HMATRIX2_PRBS7                         0x00bc
-#define HMATRIX2_PRAS8                         0x00c0
-#define HMATRIX2_PRBS8                         0x00c4
-#define HMATRIX2_PRAS9                         0x00c8
-#define HMATRIX2_PRBS9                         0x00cc
-#define HMATRIX2_PRAS10                                0x00d0
-#define HMATRIX2_PRBS10                                0x00d4
-#define HMATRIX2_PRAS11                                0x00d8
-#define HMATRIX2_PRBS11                                0x00dc
-#define HMATRIX2_PRAS12                                0x00e0
-#define HMATRIX2_PRBS12                                0x00e4
-#define HMATRIX2_PRAS13                                0x00e8
-#define HMATRIX2_PRBS13                                0x00ec
-#define HMATRIX2_PRAS14                                0x00f0
-#define HMATRIX2_PRBS14                                0x00f4
-#define HMATRIX2_PRAS15                                0x00f8
-#define HMATRIX2_PRBS15                                0x00fc
-#define HMATRIX2_MRCR                          0x0100
-#define HMATRIX2_SFR0                          0x0110
-#define HMATRIX2_SFR1                          0x0114
-#define HMATRIX2_SFR2                          0x0118
-#define HMATRIX2_SFR3                          0x011c
-#define HMATRIX2_SFR4                          0x0120
-#define HMATRIX2_SFR5                          0x0124
-#define HMATRIX2_SFR6                          0x0128
-#define HMATRIX2_SFR7                          0x012c
-#define HMATRIX2_SFR8                          0x0130
-#define HMATRIX2_SFR9                          0x0134
-#define HMATRIX2_SFR10                         0x0138
-#define HMATRIX2_SFR11                         0x013c
-#define HMATRIX2_SFR12                         0x0140
-#define HMATRIX2_SFR13                         0x0144
-#define HMATRIX2_SFR14                         0x0148
-#define HMATRIX2_SFR15                         0x014c
-#define HMATRIX2_VERSION                       0x01fc
-
-/* Bitfields in MCFG0 */
-#define HMATRIX2_ULBT_OFFSET                   0
-#define HMATRIX2_ULBT_SIZE                     3
-
-/* Bitfields in SCFG0 */
-#define HMATRIX2_SLOT_CYCLE_OFFSET             0
-#define HMATRIX2_SLOT_CYCLE_SIZE               8
-#define HMATRIX2_DEFMSTR_TYPE_OFFSET           16
-#define HMATRIX2_DEFMSTR_TYPE_SIZE             2
-#define HMATRIX2_FIXED_DEFMSTR_OFFSET          18
-#define HMATRIX2_FIXED_DEFMSTR_SIZE            4
-#define HMATRIX2_ARBT_OFFSET                   24
-#define HMATRIX2_ARBT_SIZE                     2
-
-/* Bitfields in PRAS0 */
-#define HMATRIX2_M0PR_OFFSET                   0
-#define HMATRIX2_M0PR_SIZE                     4
-#define HMATRIX2_M1PR_OFFSET                   4
-#define HMATRIX2_M1PR_SIZE                     4
-#define HMATRIX2_M2PR_OFFSET                   8
-#define HMATRIX2_M2PR_SIZE                     4
-#define HMATRIX2_M3PR_OFFSET                   12
-#define HMATRIX2_M3PR_SIZE                     4
-#define HMATRIX2_M4PR_OFFSET                   16
-#define HMATRIX2_M4PR_SIZE                     4
-#define HMATRIX2_M5PR_OFFSET                   20
-#define HMATRIX2_M5PR_SIZE                     4
-#define HMATRIX2_M6PR_OFFSET                   24
-#define HMATRIX2_M6PR_SIZE                     4
-#define HMATRIX2_M7PR_OFFSET                   28
-#define HMATRIX2_M7PR_SIZE                     4
-
-/* Bitfields in PRBS0 */
-#define HMATRIX2_M8PR_OFFSET                   0
-#define HMATRIX2_M8PR_SIZE                     4
-#define HMATRIX2_M9PR_OFFSET                   4
-#define HMATRIX2_M9PR_SIZE                     4
-#define HMATRIX2_M10PR_OFFSET                  8
-#define HMATRIX2_M10PR_SIZE                    4
-#define HMATRIX2_M11PR_OFFSET                  12
-#define HMATRIX2_M11PR_SIZE                    4
-#define HMATRIX2_M12PR_OFFSET                  16
-#define HMATRIX2_M12PR_SIZE                    4
-#define HMATRIX2_M13PR_OFFSET                  20
-#define HMATRIX2_M13PR_SIZE                    4
-#define HMATRIX2_M14PR_OFFSET                  24
-#define HMATRIX2_M14PR_SIZE                    4
-#define HMATRIX2_M15PR_OFFSET                  28
-#define HMATRIX2_M15PR_SIZE                    4
-
-/* Bitfields in MRCR */
-#define HMATRIX2_RBC0_OFFSET                   0
-#define HMATRIX2_RBC0_SIZE                     1
-#define HMATRIX2_RBC1_OFFSET                   1
-#define HMATRIX2_RBC1_SIZE                     1
-#define HMATRIX2_RBC2_OFFSET                   2
-#define HMATRIX2_RBC2_SIZE                     1
-#define HMATRIX2_RBC3_OFFSET                   3
-#define HMATRIX2_RBC3_SIZE                     1
-#define HMATRIX2_RBC4_OFFSET                   4
-#define HMATRIX2_RBC4_SIZE                     1
-#define HMATRIX2_RBC5_OFFSET                   5
-#define HMATRIX2_RBC5_SIZE                     1
-#define HMATRIX2_RBC6_OFFSET                   6
-#define HMATRIX2_RBC6_SIZE                     1
-#define HMATRIX2_RBC7_OFFSET                   7
-#define HMATRIX2_RBC7_SIZE                     1
-#define HMATRIX2_RBC8_OFFSET                   8
-#define HMATRIX2_RBC8_SIZE                     1
-#define HMATRIX2_RBC9_OFFSET                   9
-#define HMATRIX2_RBC9_SIZE                     1
-#define HMATRIX2_RBC10_OFFSET                  10
-#define HMATRIX2_RBC10_SIZE                    1
-#define HMATRIX2_RBC11_OFFSET                  11
-#define HMATRIX2_RBC11_SIZE                    1
-#define HMATRIX2_RBC12_OFFSET                  12
-#define HMATRIX2_RBC12_SIZE                    1
-#define HMATRIX2_RBC13_OFFSET                  13
-#define HMATRIX2_RBC13_SIZE                    1
-#define HMATRIX2_RBC14_OFFSET                  14
-#define HMATRIX2_RBC14_SIZE                    1
-#define HMATRIX2_RBC15_OFFSET                  15
-#define HMATRIX2_RBC15_SIZE                    1
-
-/* Bitfields in SFR0 */
-#define HMATRIX2_SFR_OFFSET                    0
-#define HMATRIX2_SFR_SIZE                      32
-
-/* Bitfields in SFR4 */
-#define HMATRIX2_CS1A_OFFSET                   1
-#define HMATRIX2_CS1A_SIZE                     1
-#define HMATRIX2_CS3A_OFFSET                   3
-#define HMATRIX2_CS3A_SIZE                     1
-#define HMATRIX2_CS4A_OFFSET                   4
-#define HMATRIX2_CS4A_SIZE                     1
-#define HMATRIX2_CS5A_OFFSET                   5
-#define HMATRIX2_CS5A_SIZE                     1
-#define HMATRIX2_DBPUC_OFFSET                  8
-#define HMATRIX2_DBPUC_SIZE                    1
-
-/* Bitfields in VERSION */
-#define HMATRIX2_VERSION_OFFSET                        0
-#define HMATRIX2_VERSION_SIZE                  12
-#define HMATRIX2_MFN_OFFSET                    16
-#define HMATRIX2_MFN_SIZE                      3
-
-/* Constants for ULBT */
-#define HMATRIX2_ULBT_INFINITE                 0
-#define HMATRIX2_ULBT_SINGLE                   1
-#define HMATRIX2_ULBT_FOUR_BEAT                        2
-#define HMATRIX2_ULBT_SIXTEEN_BEAT             4
-
-/* Constants for DEFMSTR_TYPE */
-#define HMATRIX2_DEFMSTR_TYPE_NO_DEFAULT       0
-#define HMATRIX2_DEFMSTR_TYPE_LAST_DEFAULT     1
-#define HMATRIX2_DEFMSTR_TYPE_FIXED_DEFAULT    2
-
-/* Constants for ARBT */
-#define HMATRIX2_ARBT_ROUND_ROBIN              0
-#define HMATRIX2_ARBT_FIXED_PRIORITY           1
-
-/* Bit manipulation macros */
-#define HMATRIX2_BIT(name)                                     \
-       (1 << HMATRIX2_##name##_OFFSET)
-#define HMATRIX2_BF(name,value)                                        \
-       (((value) & ((1 << HMATRIX2_##name##_SIZE) - 1))        \
-        << HMATRIX2_##name##_OFFSET)
-#define HMATRIX2_BFEXT(name,value)                             \
-       (((value) >> HMATRIX2_##name##_OFFSET)                  \
-        & ((1 << HMATRIX2_##name##_SIZE) - 1))
-#define HMATRIX2_BFINS(name,value,old)                         \
-       (((old) & ~(((1 << HMATRIX2_##name##_SIZE) - 1)         \
-                   << HMATRIX2_##name##_OFFSET))               \
-        | HMATRIX2_BF(name,value))
-
-/* Register access macros */
-#define hmatrix2_readl(reg)                                    \
-       readl((void *)HMATRIX_BASE + HMATRIX2_##reg)
-#define hmatrix2_writel(reg,value)                             \
-       writel((value), (void *)HMATRIX_BASE + HMATRIX2_##reg)
-
-#endif /* __ASM_AVR32_HMATRIX2_H__ */
diff --git a/include/asm-avr32/arch-at32ap7000/memory-map.h b/include/asm-avr32/arch-at32ap7000/memory-map.h
deleted file mode 100644 (file)
index 5513e88..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2005-2006 Atmel Corporation
- *
- * 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
- */
-#ifndef __AT32AP7000_MEMORY_MAP_H__
-#define __AT32AP7000_MEMORY_MAP_H__
-
-/* Devices on the High Speed Bus (HSB) */
-#define LCDC_BASE                              0xFF000000
-#define DMAC_BASE                              0xFF200000
-#define USB_FIFO                               0xFF300000
-
-/* Devices on Peripheral Bus A (PBA) */
-#define SPI0_BASE                              0xFFE00000
-#define SPI1_BASE                              0xFFE00400
-#define TWI_BASE                               0xFFE00800
-#define USART0_BASE                            0xFFE00C00
-#define USART1_BASE                            0xFFE01000
-#define USART2_BASE                            0xFFE01400
-#define USART3_BASE                            0xFFE01800
-#define SSC0_BASE                              0xFFE01C00
-#define SSC1_BASE                              0xFFE02000
-#define SSC2_BASE                              0xFFE02400
-#define PIOA_BASE                              0xFFE02800
-#define PIOB_BASE                              0xFFE02C00
-#define PIOC_BASE                              0xFFE03000
-#define PIOD_BASE                              0xFFE03400
-#define PIOE_BASE                              0xFFE03800
-#define PSIF_BASE                              0xFFE03C00
-
-/* Devices on Peripheral Bus B (PBB) */
-#define SM_BASE                                        0xFFF00000
-#define INTC_BASE                              0xFFF00400
-#define HMATRIX_BASE                           0xFFF00800
-#define TIMER0_BASE                            0xFFF00C00
-#define TIMER1_BASE                            0xFFF01000
-#define PWM_BASE                               0xFFF01400
-#define MACB0_BASE                             0xFFF01800
-#define MACB1_BASE                             0xFFF01C00
-#define DAC_BASE                               0xFFF02000
-#define MMCI_BASE                              0xFFF02400
-#define AUDIOC_BASE                            0xFFF02800
-#define HISI_BASE                              0xFFF02C00
-#define USB_BASE                               0xFFF03000
-#define HSMC_BASE                              0xFFF03400
-#define HSDRAMC_BASE                           0xFFF03800
-#define ECC_BASE                               0xFFF03C00
-
-#endif /* __AT32AP7000_MEMORY_MAP_H__ */
diff --git a/include/asm-avr32/arch-at32ap7000/mmc.h b/include/asm-avr32/arch-at32ap7000/mmc.h
deleted file mode 100644 (file)
index fcfbbb3..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2004-2006 Atmel Corporation
- *
- * 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
- */
-#ifndef __ASM_AVR32_MMC_H
-#define __ASM_AVR32_MMC_H
-
-struct mmc_cid {
-       unsigned long psn;
-       unsigned short oid;
-       unsigned char mid;
-       unsigned char prv;
-       unsigned char mdt;
-       char pnm[7];
-};
-
-struct mmc_csd
-{
-       u8      csd_structure:2,
-               spec_vers:4,
-               rsvd1:2;
-       u8      taac;
-       u8      nsac;
-       u8      tran_speed;
-       u16     ccc:12,
-               read_bl_len:4;
-       u64     read_bl_partial:1,
-               write_blk_misalign:1,
-               read_blk_misalign:1,
-               dsr_imp:1,
-               rsvd2:2,
-               c_size:12,
-               vdd_r_curr_min:3,
-               vdd_r_curr_max:3,
-               vdd_w_curr_min:3,
-               vdd_w_curr_max:3,
-               c_size_mult:3,
-               sector_size:5,
-               erase_grp_size:5,
-               wp_grp_size:5,
-               wp_grp_enable:1,
-               default_ecc:2,
-               r2w_factor:3,
-               write_bl_len:4,
-               write_bl_partial:1,
-               rsvd3:5;
-       u8      file_format_grp:1,
-               copy:1,
-               perm_write_protect:1,
-               tmp_write_protect:1,
-               file_format:2,
-               ecc:2;
-       u8      crc:7;
-       u8      one:1;
-};
-
-/* MMC Command numbers */
-#define MMC_CMD_GO_IDLE_STATE          0
-#define MMC_CMD_SEND_OP_COND           1
-#define MMC_CMD_ALL_SEND_CID           2
-#define MMC_CMD_SET_RELATIVE_ADDR      3
-#define MMC_CMD_SD_SEND_RELATIVE_ADDR  3
-#define MMC_CMD_SET_DSR                        4
-#define MMC_CMD_SELECT_CARD            7
-#define MMC_CMD_SEND_CSD               9
-#define MMC_CMD_SEND_CID               10
-#define MMC_CMD_SEND_STATUS            13
-#define MMC_CMD_SET_BLOCKLEN           16
-#define MMC_CMD_READ_SINGLE_BLOCK      17
-#define MMC_CMD_READ_MULTIPLE_BLOCK    18
-#define MMC_CMD_WRITE_BLOCK            24
-#define MMC_CMD_APP_CMD                        55
-
-#define MMC_ACMD_SD_SEND_OP_COND       41
-
-#define R1_ILLEGAL_COMMAND             (1 << 22)
-#define R1_APP_CMD                     (1 << 5)
-
-#endif /* __ASM_AVR32_MMC_H */
diff --git a/include/asm-avr32/arch-at32ap700x/chip-features.h b/include/asm-avr32/arch-at32ap700x/chip-features.h
new file mode 100644 (file)
index 0000000..29b1fd6
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2007 Atmel Corporation
+ *
+ * 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
+ */
+#ifndef __ASM_AVR32_ARCH_CHIP_FEATURES_H__
+#define __ASM_AVR32_ARCH_CHIP_FEATURES_H__
+
+/* Currently, all the AP700x chips have these */
+#define AT32AP700x_CHIP_HAS_USART
+#define AT32AP700x_CHIP_HAS_MMCI
+
+/* Only AP7000 has ethernet interface */
+#ifdef CONFIG_AT32AP7000
+#define AT32AP700x_CHIP_HAS_MACB
+#endif
+
+#endif /* __ASM_AVR32_ARCH_CHIP_FEATURES_H__ */
diff --git a/include/asm-avr32/arch-at32ap700x/clk.h b/include/asm-avr32/arch-at32ap700x/clk.h
new file mode 100644 (file)
index 0000000..ea84c08
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2006 Atmel Corporation
+ *
+ * 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
+ */
+#ifndef __ASM_AVR32_ARCH_CLK_H__
+#define __ASM_AVR32_ARCH_CLK_H__
+
+#include <asm/arch/chip-features.h>
+
+#ifdef CONFIG_PLL
+#define MAIN_CLK_RATE ((CFG_OSC0_HZ / CFG_PLL0_DIV) * CFG_PLL0_MUL)
+#else
+#define MAIN_CLK_RATE (CFG_OSC0_HZ)
+#endif
+
+static inline unsigned long get_cpu_clk_rate(void)
+{
+       return MAIN_CLK_RATE >> CFG_CLKDIV_CPU;
+}
+static inline unsigned long get_hsb_clk_rate(void)
+{
+       return MAIN_CLK_RATE >> CFG_CLKDIV_HSB;
+}
+static inline unsigned long get_pba_clk_rate(void)
+{
+       return MAIN_CLK_RATE >> CFG_CLKDIV_PBA;
+}
+static inline unsigned long get_pbb_clk_rate(void)
+{
+       return MAIN_CLK_RATE >> CFG_CLKDIV_PBB;
+}
+
+/* Accessors for specific devices. More will be added as needed. */
+static inline unsigned long get_sdram_clk_rate(void)
+{
+       return get_hsb_clk_rate();
+}
+#ifdef AT32AP700x_CHIP_HAS_USART
+static inline unsigned long get_usart_clk_rate(unsigned int dev_id)
+{
+       return get_pba_clk_rate();
+}
+#endif
+#ifdef AT32AP700x_CHIP_HAS_USART
+static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
+{
+       return get_pbb_clk_rate();
+}
+static inline unsigned long get_macb_hclk_rate(unsigned int dev_id)
+{
+       return get_hsb_clk_rate();
+}
+#endif
+#ifdef AT32AP700x_CHIP_HAS_MMCI
+static inline unsigned long get_mci_clk_rate(void)
+{
+       return get_pbb_clk_rate();
+}
+#endif
+
+#endif /* __ASM_AVR32_ARCH_CLK_H__ */
diff --git a/include/asm-avr32/arch-at32ap700x/gpio.h b/include/asm-avr32/arch-at32ap700x/gpio.h
new file mode 100644 (file)
index 0000000..b10a3e4
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2006 Atmel Corporation
+ *
+ * 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
+ */
+#ifndef __ASM_AVR32_ARCH_GPIO_H__
+#define __ASM_AVR32_ARCH_GPIO_H__
+
+#include <asm/arch/chip-features.h>
+#include <asm/arch/memory-map.h>
+
+#define NR_GPIO_CONTROLLERS    5
+
+/*
+ * Pin numbers identifying specific GPIO pins on the chip.
+ */
+#define GPIO_PIOA_BASE (0)
+#define GPIO_PIN_PA0   (GPIO_PIOA_BASE +  0)
+#define GPIO_PIN_PA1   (GPIO_PIOA_BASE +  1)
+#define GPIO_PIN_PA2   (GPIO_PIOA_BASE +  2)
+#define GPIO_PIN_PA3   (GPIO_PIOA_BASE +  3)
+#define GPIO_PIN_PA4   (GPIO_PIOA_BASE +  4)
+#define GPIO_PIN_PA5   (GPIO_PIOA_BASE +  5)
+#define GPIO_PIN_PA6   (GPIO_PIOA_BASE +  6)
+#define GPIO_PIN_PA7   (GPIO_PIOA_BASE +  7)
+#define GPIO_PIN_PA8   (GPIO_PIOA_BASE +  8)
+#define GPIO_PIN_PA9   (GPIO_PIOA_BASE +  9)
+#define GPIO_PIN_PA10  (GPIO_PIOA_BASE + 10)
+#define GPIO_PIN_PA11  (GPIO_PIOA_BASE + 11)
+#define GPIO_PIN_PA12  (GPIO_PIOA_BASE + 12)
+#define GPIO_PIN_PA13  (GPIO_PIOA_BASE + 13)
+#define GPIO_PIN_PA14  (GPIO_PIOA_BASE + 14)
+#define GPIO_PIN_PA15  (GPIO_PIOA_BASE + 15)
+#define GPIO_PIN_PA16  (GPIO_PIOA_BASE + 16)
+#define GPIO_PIN_PA17  (GPIO_PIOA_BASE + 17)
+#define GPIO_PIN_PA18  (GPIO_PIOA_BASE + 18)
+#define GPIO_PIN_PA19  (GPIO_PIOA_BASE + 19)
+#define GPIO_PIN_PA20  (GPIO_PIOA_BASE + 20)
+#define GPIO_PIN_PA21  (GPIO_PIOA_BASE + 21)
+#define GPIO_PIN_PA22  (GPIO_PIOA_BASE + 22)
+#define GPIO_PIN_PA23  (GPIO_PIOA_BASE + 23)
+#define GPIO_PIN_PA24  (GPIO_PIOA_BASE + 24)
+#define GPIO_PIN_PA25  (GPIO_PIOA_BASE + 25)
+#define GPIO_PIN_PA26  (GPIO_PIOA_BASE + 26)
+#define GPIO_PIN_PA27  (GPIO_PIOA_BASE + 27)
+#define GPIO_PIN_PA28  (GPIO_PIOA_BASE + 28)
+#define GPIO_PIN_PA29  (GPIO_PIOA_BASE + 29)
+#define GPIO_PIN_PA30  (GPIO_PIOA_BASE + 30)
+#define GPIO_PIN_PA31  (GPIO_PIOA_BASE + 31)
+
+#define GPIO_PIOB_BASE (GPIO_PIOA_BASE + 32)
+#define GPIO_PIN_PB0   (GPIO_PIOB_BASE +  0)
+#define GPIO_PIN_PB1   (GPIO_PIOB_BASE +  1)
+#define GPIO_PIN_PB2   (GPIO_PIOB_BASE +  2)
+#define GPIO_PIN_PB3   (GPIO_PIOB_BASE +  3)
+#define GPIO_PIN_PB4   (GPIO_PIOB_BASE +  4)
+#define GPIO_PIN_PB5   (GPIO_PIOB_BASE +  5)
+#define GPIO_PIN_PB6   (GPIO_PIOB_BASE +  6)
+#define GPIO_PIN_PB7   (GPIO_PIOB_BASE +  7)
+#define GPIO_PIN_PB8   (GPIO_PIOB_BASE +  8)
+#define GPIO_PIN_PB9   (GPIO_PIOB_BASE +  9)
+#define GPIO_PIN_PB10  (GPIO_PIOB_BASE + 10)
+#define GPIO_PIN_PB11  (GPIO_PIOB_BASE + 11)
+#define GPIO_PIN_PB12  (GPIO_PIOB_BASE + 12)
+#define GPIO_PIN_PB13  (GPIO_PIOB_BASE + 13)
+#define GPIO_PIN_PB14  (GPIO_PIOB_BASE + 14)
+#define GPIO_PIN_PB15  (GPIO_PIOB_BASE + 15)
+#define GPIO_PIN_PB16  (GPIO_PIOB_BASE + 16)
+#define GPIO_PIN_PB17  (GPIO_PIOB_BASE + 17)
+#define GPIO_PIN_PB18  (GPIO_PIOB_BASE + 18)
+#define GPIO_PIN_PB19  (GPIO_PIOB_BASE + 19)
+#define GPIO_PIN_PB20  (GPIO_PIOB_BASE + 20)
+#define GPIO_PIN_PB21  (GPIO_PIOB_BASE + 21)
+#define GPIO_PIN_PB22  (GPIO_PIOB_BASE + 22)
+#define GPIO_PIN_PB23  (GPIO_PIOB_BASE + 23)
+#define GPIO_PIN_PB24  (GPIO_PIOB_BASE + 24)
+#define GPIO_PIN_PB25  (GPIO_PIOB_BASE + 25)
+#define GPIO_PIN_PB26  (GPIO_PIOB_BASE + 26)
+#define GPIO_PIN_PB27  (GPIO_PIOB_BASE + 27)
+#define GPIO_PIN_PB28  (GPIO_PIOB_BASE + 28)
+#define GPIO_PIN_PB29  (GPIO_PIOB_BASE + 29)
+#define GPIO_PIN_PB30  (GPIO_PIOB_BASE + 30)
+
+#define GPIO_PIOC_BASE (GPIO_PIOB_BASE + 32)
+#define GPIO_PIN_PC0   (GPIO_PIOC_BASE +  0)
+#define GPIO_PIN_PC1   (GPIO_PIOC_BASE +  1)
+#define GPIO_PIN_PC2   (GPIO_PIOC_BASE +  2)
+#define GPIO_PIN_PC3   (GPIO_PIOC_BASE +  3)
+#define GPIO_PIN_PC4   (GPIO_PIOC_BASE +  4)
+#define GPIO_PIN_PC5   (GPIO_PIOC_BASE +  5)
+#define GPIO_PIN_PC6   (GPIO_PIOC_BASE +  6)
+#define GPIO_PIN_PC7   (GPIO_PIOC_BASE +  7)
+#define GPIO_PIN_PC8   (GPIO_PIOC_BASE +  8)
+#define GPIO_PIN_PC9   (GPIO_PIOC_BASE +  9)
+#define GPIO_PIN_PC10  (GPIO_PIOC_BASE + 10)
+#define GPIO_PIN_PC11  (GPIO_PIOC_BASE + 11)
+#define GPIO_PIN_PC12  (GPIO_PIOC_BASE + 12)
+#define GPIO_PIN_PC13  (GPIO_PIOC_BASE + 13)
+#define GPIO_PIN_PC14  (GPIO_PIOC_BASE + 14)
+#define GPIO_PIN_PC15  (GPIO_PIOC_BASE + 15)
+#define GPIO_PIN_PC16  (GPIO_PIOC_BASE + 16)
+#define GPIO_PIN_PC17  (GPIO_PIOC_BASE + 17)
+#define GPIO_PIN_PC18  (GPIO_PIOC_BASE + 18)
+#define GPIO_PIN_PC19  (GPIO_PIOC_BASE + 19)
+#define GPIO_PIN_PC20  (GPIO_PIOC_BASE + 20)
+#define GPIO_PIN_PC21  (GPIO_PIOC_BASE + 21)
+#define GPIO_PIN_PC22  (GPIO_PIOC_BASE + 22)
+#define GPIO_PIN_PC23  (GPIO_PIOC_BASE + 23)
+#define GPIO_PIN_PC24  (GPIO_PIOC_BASE + 24)
+#define GPIO_PIN_PC25  (GPIO_PIOC_BASE + 25)
+#define GPIO_PIN_PC26  (GPIO_PIOC_BASE + 26)
+#define GPIO_PIN_PC27  (GPIO_PIOC_BASE + 27)
+#define GPIO_PIN_PC28  (GPIO_PIOC_BASE + 28)
+#define GPIO_PIN_PC29  (GPIO_PIOC_BASE + 29)
+#define GPIO_PIN_PC30  (GPIO_PIOC_BASE + 30)
+#define GPIO_PIN_PC31  (GPIO_PIOC_BASE + 31)
+
+#define GPIO_PIOD_BASE (GPIO_PIOC_BASE + 32)
+#define GPIO_PIN_PD0   (GPIO_PIOD_BASE +  0)
+#define GPIO_PIN_PD1   (GPIO_PIOD_BASE +  1)
+#define GPIO_PIN_PD2   (GPIO_PIOD_BASE +  2)
+#define GPIO_PIN_PD3   (GPIO_PIOD_BASE +  3)
+#define GPIO_PIN_PD4   (GPIO_PIOD_BASE +  4)
+#define GPIO_PIN_PD5   (GPIO_PIOD_BASE +  5)
+#define GPIO_PIN_PD6   (GPIO_PIOD_BASE +  6)
+#define GPIO_PIN_PD7   (GPIO_PIOD_BASE +  7)
+#define GPIO_PIN_PD8   (GPIO_PIOD_BASE +  8)
+#define GPIO_PIN_PD9   (GPIO_PIOD_BASE +  9)
+#define GPIO_PIN_PD10  (GPIO_PIOD_BASE + 10)
+#define GPIO_PIN_PD11  (GPIO_PIOD_BASE + 11)
+#define GPIO_PIN_PD12  (GPIO_PIOD_BASE + 12)
+#define GPIO_PIN_PD13  (GPIO_PIOD_BASE + 13)
+#define GPIO_PIN_PD14  (GPIO_PIOD_BASE + 14)
+#define GPIO_PIN_PD15  (GPIO_PIOD_BASE + 15)
+#define GPIO_PIN_PD16  (GPIO_PIOD_BASE + 16)
+#define GPIO_PIN_PD17  (GPIO_PIOD_BASE + 17)
+
+#define GPIO_PIOE_BASE (GPIO_PIOD_BASE + 32)
+#define GPIO_PIN_PE0   (GPIO_PIOE_BASE +  0)
+#define GPIO_PIN_PE1   (GPIO_PIOE_BASE +  1)
+#define GPIO_PIN_PE2   (GPIO_PIOE_BASE +  2)
+#define GPIO_PIN_PE3   (GPIO_PIOE_BASE +  3)
+#define GPIO_PIN_PE4   (GPIO_PIOE_BASE +  4)
+#define GPIO_PIN_PE5   (GPIO_PIOE_BASE +  5)
+#define GPIO_PIN_PE6   (GPIO_PIOE_BASE +  6)
+#define GPIO_PIN_PE7   (GPIO_PIOE_BASE +  7)
+#define GPIO_PIN_PE8   (GPIO_PIOE_BASE +  8)
+#define GPIO_PIN_PE9   (GPIO_PIOE_BASE +  9)
+#define GPIO_PIN_PE10  (GPIO_PIOE_BASE + 10)
+#define GPIO_PIN_PE11  (GPIO_PIOE_BASE + 11)
+#define GPIO_PIN_PE12  (GPIO_PIOE_BASE + 12)
+#define GPIO_PIN_PE13  (GPIO_PIOE_BASE + 13)
+#define GPIO_PIN_PE14  (GPIO_PIOE_BASE + 14)
+#define GPIO_PIN_PE15  (GPIO_PIOE_BASE + 15)
+#define GPIO_PIN_PE16  (GPIO_PIOE_BASE + 16)
+#define GPIO_PIN_PE17  (GPIO_PIOE_BASE + 17)
+#define GPIO_PIN_PE18  (GPIO_PIOE_BASE + 18)
+#define GPIO_PIN_PE19  (GPIO_PIOE_BASE + 19)
+#define GPIO_PIN_PE20  (GPIO_PIOE_BASE + 20)
+#define GPIO_PIN_PE21  (GPIO_PIOE_BASE + 21)
+#define GPIO_PIN_PE22  (GPIO_PIOE_BASE + 22)
+#define GPIO_PIN_PE23  (GPIO_PIOE_BASE + 23)
+#define GPIO_PIN_PE24  (GPIO_PIOE_BASE + 24)
+#define GPIO_PIN_PE25  (GPIO_PIOE_BASE + 25)
+#define GPIO_PIN_PE26  (GPIO_PIOE_BASE + 26)
+
+static inline void *gpio_pin_to_addr(unsigned int pin)
+{
+       switch (pin >> 5) {
+       case 0:
+               return (void *)PIOA_BASE;
+       case 1:
+               return (void *)PIOB_BASE;
+       case 2:
+               return (void *)PIOC_BASE;
+       case 3:
+               return (void *)PIOD_BASE;
+       case 4:
+               return (void *)PIOE_BASE;
+       default:
+               return NULL;
+       }
+}
+
+void gpio_select_periph_A(unsigned int pin, int use_pullup);
+void gpio_select_periph_B(unsigned int pin, int use_pullup);
+
+void gpio_enable_ebi(void);
+
+#ifdef AT32AP700x_CHIP_HAS_USART
+void gpio_enable_usart0(void);
+void gpio_enable_usart1(void);
+void gpio_enable_usart2(void);
+void gpio_enable_usart3(void);
+#endif
+#ifdef AT32AP700x_CHIP_HAS_MACB
+void gpio_enable_macb0(void);
+void gpio_enable_macb1(void);
+#endif
+#ifdef AT32AP700x_CHIP_HAS_MMCI
+void gpio_enable_mmci(void);
+#endif
+
+#endif /* __ASM_AVR32_ARCH_GPIO_H__ */
diff --git a/include/asm-avr32/arch-at32ap700x/hmatrix2.h b/include/asm-avr32/arch-at32ap700x/hmatrix2.h
new file mode 100644 (file)
index 0000000..b0e787a
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ * Register definition for the High-speed Bus Matrix
+ */
+#ifndef __ASM_AVR32_HMATRIX2_H__
+#define __ASM_AVR32_HMATRIX2_H__
+
+/* HMATRIX2 register offsets */
+#define HMATRIX2_MCFG0                         0x0000
+#define HMATRIX2_MCFG1                         0x0004
+#define HMATRIX2_MCFG2                         0x0008
+#define HMATRIX2_MCFG3                         0x000c
+#define HMATRIX2_MCFG4                         0x0010
+#define HMATRIX2_MCFG5                         0x0014
+#define HMATRIX2_MCFG6                         0x0018
+#define HMATRIX2_MCFG7                         0x001c
+#define HMATRIX2_MCFG8                         0x0020
+#define HMATRIX2_MCFG9                         0x0024
+#define HMATRIX2_MCFG10                                0x0028
+#define HMATRIX2_MCFG11                                0x002c
+#define HMATRIX2_MCFG12                                0x0030
+#define HMATRIX2_MCFG13                                0x0034
+#define HMATRIX2_MCFG14                                0x0038
+#define HMATRIX2_MCFG15                                0x003c
+#define HMATRIX2_SCFG0                         0x0040
+#define HMATRIX2_SCFG1                         0x0044
+#define HMATRIX2_SCFG2                         0x0048
+#define HMATRIX2_SCFG3                         0x004c
+#define HMATRIX2_SCFG4                         0x0050
+#define HMATRIX2_SCFG5                         0x0054
+#define HMATRIX2_SCFG6                         0x0058
+#define HMATRIX2_SCFG7                         0x005c
+#define HMATRIX2_SCFG8                         0x0060
+#define HMATRIX2_SCFG9                         0x0064
+#define HMATRIX2_SCFG10                                0x0068
+#define HMATRIX2_SCFG11                                0x006c
+#define HMATRIX2_SCFG12                                0x0070
+#define HMATRIX2_SCFG13                                0x0074
+#define HMATRIX2_SCFG14                                0x0078
+#define HMATRIX2_SCFG15                                0x007c
+#define HMATRIX2_PRAS0                         0x0080
+#define HMATRIX2_PRBS0                         0x0084
+#define HMATRIX2_PRAS1                         0x0088
+#define HMATRIX2_PRBS1                         0x008c
+#define HMATRIX2_PRAS2                         0x0090
+#define HMATRIX2_PRBS2                         0x0094
+#define HMATRIX2_PRAS3                         0x0098
+#define HMATRIX2_PRBS3                         0x009c
+#define HMATRIX2_PRAS4                         0x00a0
+#define HMATRIX2_PRBS4                         0x00a4
+#define HMATRIX2_PRAS5                         0x00a8
+#define HMATRIX2_PRBS5                         0x00ac
+#define HMATRIX2_PRAS6                         0x00b0
+#define HMATRIX2_PRBS6                         0x00b4
+#define HMATRIX2_PRAS7                         0x00b8
+#define HMATRIX2_PRBS7                         0x00bc
+#define HMATRIX2_PRAS8                         0x00c0
+#define HMATRIX2_PRBS8                         0x00c4
+#define HMATRIX2_PRAS9                         0x00c8
+#define HMATRIX2_PRBS9                         0x00cc
+#define HMATRIX2_PRAS10                                0x00d0
+#define HMATRIX2_PRBS10                                0x00d4
+#define HMATRIX2_PRAS11                                0x00d8
+#define HMATRIX2_PRBS11                                0x00dc
+#define HMATRIX2_PRAS12                                0x00e0
+#define HMATRIX2_PRBS12                                0x00e4
+#define HMATRIX2_PRAS13                                0x00e8
+#define HMATRIX2_PRBS13                                0x00ec
+#define HMATRIX2_PRAS14                                0x00f0
+#define HMATRIX2_PRBS14                                0x00f4
+#define HMATRIX2_PRAS15                                0x00f8
+#define HMATRIX2_PRBS15                                0x00fc
+#define HMATRIX2_MRCR                          0x0100
+#define HMATRIX2_SFR0                          0x0110
+#define HMATRIX2_SFR1                          0x0114
+#define HMATRIX2_SFR2                          0x0118
+#define HMATRIX2_SFR3                          0x011c
+#define HMATRIX2_SFR4                          0x0120
+#define HMATRIX2_SFR5                          0x0124
+#define HMATRIX2_SFR6                          0x0128
+#define HMATRIX2_SFR7                          0x012c
+#define HMATRIX2_SFR8                          0x0130
+#define HMATRIX2_SFR9                          0x0134
+#define HMATRIX2_SFR10                         0x0138
+#define HMATRIX2_SFR11                         0x013c
+#define HMATRIX2_SFR12                         0x0140
+#define HMATRIX2_SFR13                         0x0144
+#define HMATRIX2_SFR14                         0x0148
+#define HMATRIX2_SFR15                         0x014c
+#define HMATRIX2_VERSION                       0x01fc
+
+/* Bitfields in MCFG0 */
+#define HMATRIX2_ULBT_OFFSET                   0
+#define HMATRIX2_ULBT_SIZE                     3
+
+/* Bitfields in SCFG0 */
+#define HMATRIX2_SLOT_CYCLE_OFFSET             0
+#define HMATRIX2_SLOT_CYCLE_SIZE               8
+#define HMATRIX2_DEFMSTR_TYPE_OFFSET           16
+#define HMATRIX2_DEFMSTR_TYPE_SIZE             2
+#define HMATRIX2_FIXED_DEFMSTR_OFFSET          18
+#define HMATRIX2_FIXED_DEFMSTR_SIZE            4
+#define HMATRIX2_ARBT_OFFSET                   24
+#define HMATRIX2_ARBT_SIZE                     2
+
+/* Bitfields in PRAS0 */
+#define HMATRIX2_M0PR_OFFSET                   0
+#define HMATRIX2_M0PR_SIZE                     4
+#define HMATRIX2_M1PR_OFFSET                   4
+#define HMATRIX2_M1PR_SIZE                     4
+#define HMATRIX2_M2PR_OFFSET                   8
+#define HMATRIX2_M2PR_SIZE                     4
+#define HMATRIX2_M3PR_OFFSET                   12
+#define HMATRIX2_M3PR_SIZE                     4
+#define HMATRIX2_M4PR_OFFSET                   16
+#define HMATRIX2_M4PR_SIZE                     4
+#define HMATRIX2_M5PR_OFFSET                   20
+#define HMATRIX2_M5PR_SIZE                     4
+#define HMATRIX2_M6PR_OFFSET                   24
+#define HMATRIX2_M6PR_SIZE                     4
+#define HMATRIX2_M7PR_OFFSET                   28
+#define HMATRIX2_M7PR_SIZE                     4
+
+/* Bitfields in PRBS0 */
+#define HMATRIX2_M8PR_OFFSET                   0
+#define HMATRIX2_M8PR_SIZE                     4
+#define HMATRIX2_M9PR_OFFSET                   4
+#define HMATRIX2_M9PR_SIZE                     4
+#define HMATRIX2_M10PR_OFFSET                  8
+#define HMATRIX2_M10PR_SIZE                    4
+#define HMATRIX2_M11PR_OFFSET                  12
+#define HMATRIX2_M11PR_SIZE                    4
+#define HMATRIX2_M12PR_OFFSET                  16
+#define HMATRIX2_M12PR_SIZE                    4
+#define HMATRIX2_M13PR_OFFSET                  20
+#define HMATRIX2_M13PR_SIZE                    4
+#define HMATRIX2_M14PR_OFFSET                  24
+#define HMATRIX2_M14PR_SIZE                    4
+#define HMATRIX2_M15PR_OFFSET                  28
+#define HMATRIX2_M15PR_SIZE                    4
+
+/* Bitfields in MRCR */
+#define HMATRIX2_RBC0_OFFSET                   0
+#define HMATRIX2_RBC0_SIZE                     1
+#define HMATRIX2_RBC1_OFFSET                   1
+#define HMATRIX2_RBC1_SIZE                     1
+#define HMATRIX2_RBC2_OFFSET                   2
+#define HMATRIX2_RBC2_SIZE                     1
+#define HMATRIX2_RBC3_OFFSET                   3
+#define HMATRIX2_RBC3_SIZE                     1
+#define HMATRIX2_RBC4_OFFSET                   4
+#define HMATRIX2_RBC4_SIZE                     1
+#define HMATRIX2_RBC5_OFFSET                   5
+#define HMATRIX2_RBC5_SIZE                     1
+#define HMATRIX2_RBC6_OFFSET                   6
+#define HMATRIX2_RBC6_SIZE                     1
+#define HMATRIX2_RBC7_OFFSET                   7
+#define HMATRIX2_RBC7_SIZE                     1
+#define HMATRIX2_RBC8_OFFSET                   8
+#define HMATRIX2_RBC8_SIZE                     1
+#define HMATRIX2_RBC9_OFFSET                   9
+#define HMATRIX2_RBC9_SIZE                     1
+#define HMATRIX2_RBC10_OFFSET                  10
+#define HMATRIX2_RBC10_SIZE                    1
+#define HMATRIX2_RBC11_OFFSET                  11
+#define HMATRIX2_RBC11_SIZE                    1
+#define HMATRIX2_RBC12_OFFSET                  12
+#define HMATRIX2_RBC12_SIZE                    1
+#define HMATRIX2_RBC13_OFFSET                  13
+#define HMATRIX2_RBC13_SIZE                    1
+#define HMATRIX2_RBC14_OFFSET                  14
+#define HMATRIX2_RBC14_SIZE                    1
+#define HMATRIX2_RBC15_OFFSET                  15
+#define HMATRIX2_RBC15_SIZE                    1
+
+/* Bitfields in SFR0 */
+#define HMATRIX2_SFR_OFFSET                    0
+#define HMATRIX2_SFR_SIZE                      32
+
+/* Bitfields in SFR4 */
+#define HMATRIX2_CS1A_OFFSET                   1
+#define HMATRIX2_CS1A_SIZE                     1
+#define HMATRIX2_CS3A_OFFSET                   3
+#define HMATRIX2_CS3A_SIZE                     1
+#define HMATRIX2_CS4A_OFFSET                   4
+#define HMATRIX2_CS4A_SIZE                     1
+#define HMATRIX2_CS5A_OFFSET                   5
+#define HMATRIX2_CS5A_SIZE                     1
+#define HMATRIX2_DBPUC_OFFSET                  8
+#define HMATRIX2_DBPUC_SIZE                    1
+
+/* Bitfields in VERSION */
+#define HMATRIX2_VERSION_OFFSET                        0
+#define HMATRIX2_VERSION_SIZE                  12
+#define HMATRIX2_MFN_OFFSET                    16
+#define HMATRIX2_MFN_SIZE                      3
+
+/* Constants for ULBT */
+#define HMATRIX2_ULBT_INFINITE                 0
+#define HMATRIX2_ULBT_SINGLE                   1
+#define HMATRIX2_ULBT_FOUR_BEAT                        2
+#define HMATRIX2_ULBT_SIXTEEN_BEAT             4
+
+/* Constants for DEFMSTR_TYPE */
+#define HMATRIX2_DEFMSTR_TYPE_NO_DEFAULT       0
+#define HMATRIX2_DEFMSTR_TYPE_LAST_DEFAULT     1
+#define HMATRIX2_DEFMSTR_TYPE_FIXED_DEFAULT    2
+
+/* Constants for ARBT */
+#define HMATRIX2_ARBT_ROUND_ROBIN              0
+#define HMATRIX2_ARBT_FIXED_PRIORITY           1
+
+/* Bit manipulation macros */
+#define HMATRIX2_BIT(name)                                     \
+       (1 << HMATRIX2_##name##_OFFSET)
+#define HMATRIX2_BF(name,value)                                        \
+       (((value) & ((1 << HMATRIX2_##name##_SIZE) - 1))        \
+        << HMATRIX2_##name##_OFFSET)
+#define HMATRIX2_BFEXT(name,value)                             \
+       (((value) >> HMATRIX2_##name##_OFFSET)                  \
+        & ((1 << HMATRIX2_##name##_SIZE) - 1))
+#define HMATRIX2_BFINS(name,value,old)                         \
+       (((old) & ~(((1 << HMATRIX2_##name##_SIZE) - 1)         \
+                   << HMATRIX2_##name##_OFFSET))               \
+        | HMATRIX2_BF(name,value))
+
+/* Register access macros */
+#define hmatrix2_readl(reg)                                    \
+       readl((void *)HMATRIX_BASE + HMATRIX2_##reg)
+#define hmatrix2_writel(reg,value)                             \
+       writel((value), (void *)HMATRIX_BASE + HMATRIX2_##reg)
+
+#endif /* __ASM_AVR32_HMATRIX2_H__ */
diff --git a/include/asm-avr32/arch-at32ap700x/memory-map.h b/include/asm-avr32/arch-at32ap700x/memory-map.h
new file mode 100644 (file)
index 0000000..5513e88
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2005-2006 Atmel Corporation
+ *
+ * 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
+ */
+#ifndef __AT32AP7000_MEMORY_MAP_H__
+#define __AT32AP7000_MEMORY_MAP_H__
+
+/* Devices on the High Speed Bus (HSB) */
+#define LCDC_BASE                              0xFF000000
+#define DMAC_BASE                              0xFF200000
+#define USB_FIFO                               0xFF300000
+
+/* Devices on Peripheral Bus A (PBA) */
+#define SPI0_BASE                              0xFFE00000
+#define SPI1_BASE                              0xFFE00400
+#define TWI_BASE                               0xFFE00800
+#define USART0_BASE                            0xFFE00C00
+#define USART1_BASE                            0xFFE01000
+#define USART2_BASE                            0xFFE01400
+#define USART3_BASE                            0xFFE01800
+#define SSC0_BASE                              0xFFE01C00
+#define SSC1_BASE                              0xFFE02000
+#define SSC2_BASE                              0xFFE02400
+#define PIOA_BASE                              0xFFE02800
+#define PIOB_BASE                              0xFFE02C00
+#define PIOC_BASE                              0xFFE03000
+#define PIOD_BASE                              0xFFE03400
+#define PIOE_BASE                              0xFFE03800
+#define PSIF_BASE                              0xFFE03C00
+
+/* Devices on Peripheral Bus B (PBB) */
+#define SM_BASE                                        0xFFF00000
+#define INTC_BASE                              0xFFF00400
+#define HMATRIX_BASE                           0xFFF00800
+#define TIMER0_BASE                            0xFFF00C00
+#define TIMER1_BASE                            0xFFF01000
+#define PWM_BASE                               0xFFF01400
+#define MACB0_BASE                             0xFFF01800
+#define MACB1_BASE                             0xFFF01C00
+#define DAC_BASE                               0xFFF02000
+#define MMCI_BASE                              0xFFF02400
+#define AUDIOC_BASE                            0xFFF02800
+#define HISI_BASE                              0xFFF02C00
+#define USB_BASE                               0xFFF03000
+#define HSMC_BASE                              0xFFF03400
+#define HSDRAMC_BASE                           0xFFF03800
+#define ECC_BASE                               0xFFF03C00
+
+#endif /* __AT32AP7000_MEMORY_MAP_H__ */
diff --git a/include/asm-avr32/arch-at32ap700x/mmc.h b/include/asm-avr32/arch-at32ap700x/mmc.h
new file mode 100644 (file)
index 0000000..fcfbbb3
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2004-2006 Atmel Corporation
+ *
+ * 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
+ */
+#ifndef __ASM_AVR32_MMC_H
+#define __ASM_AVR32_MMC_H
+
+struct mmc_cid {
+       unsigned long psn;
+       unsigned short oid;
+       unsigned char mid;
+       unsigned char prv;
+       unsigned char mdt;
+       char pnm[7];
+};
+
+struct mmc_csd
+{
+       u8      csd_structure:2,
+               spec_vers:4,
+               rsvd1:2;
+       u8      taac;
+       u8      nsac;
+       u8      tran_speed;
+       u16     ccc:12,
+               read_bl_len:4;
+       u64     read_bl_partial:1,
+               write_blk_misalign:1,
+               read_blk_misalign:1,
+               dsr_imp:1,
+               rsvd2:2,
+               c_size:12,
+               vdd_r_curr_min:3,
+               vdd_r_curr_max:3,
+               vdd_w_curr_min:3,
+               vdd_w_curr_max:3,
+               c_size_mult:3,
+               sector_size:5,
+               erase_grp_size:5,
+               wp_grp_size:5,
+               wp_grp_enable:1,
+               default_ecc:2,
+               r2w_factor:3,
+               write_bl_len:4,
+               write_bl_partial:1,
+               rsvd3:5;
+       u8      file_format_grp:1,
+               copy:1,
+               perm_write_protect:1,
+               tmp_write_protect:1,
+               file_format:2,
+               ecc:2;
+       u8      crc:7;
+       u8      one:1;
+};
+
+/* MMC Command numbers */
+#define MMC_CMD_GO_IDLE_STATE          0
+#define MMC_CMD_SEND_OP_COND           1
+#define MMC_CMD_ALL_SEND_CID           2
+#define MMC_CMD_SET_RELATIVE_ADDR      3
+#define MMC_CMD_SD_SEND_RELATIVE_ADDR  3
+#define MMC_CMD_SET_DSR                        4
+#define MMC_CMD_SELECT_CARD            7
+#define MMC_CMD_SEND_CSD               9
+#define MMC_CMD_SEND_CID               10
+#define MMC_CMD_SEND_STATUS            13
+#define MMC_CMD_SET_BLOCKLEN           16
+#define MMC_CMD_READ_SINGLE_BLOCK      17
+#define MMC_CMD_READ_MULTIPLE_BLOCK    18
+#define MMC_CMD_WRITE_BLOCK            24
+#define MMC_CMD_APP_CMD                        55
+
+#define MMC_ACMD_SD_SEND_OP_COND       41
+
+#define R1_ILLEGAL_COMMAND             (1 << 22)
+#define R1_APP_CMD                     (1 << 5)
+
+#endif /* __ASM_AVR32_MMC_H */
index 3c0d569233e2693933ea667075a362fe7535e3ec..ba14674cf73780bbb72d3b3de5cb41513d3a3697 100644 (file)
@@ -93,4 +93,36 @@ static inline void sync(void)
 {
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ *
+ * This implementation works for memory below 512MiB (flash, etc.) as
+ * well as above 3.5GiB (internal peripherals.)
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (1 << 7)
+#define MAP_WRBACK     (MAP_WRCOMBINE | (1 << 9))
+#define MAP_WRTHROUGH  (MAP_WRBACK | (1 << 0))
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       if (flags == MAP_WRBACK)
+               return (void *)P1SEGADDR(paddr);
+       else
+               return (void *)P2SEGADDR(paddr);
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long len)
+{
+
+}
+
 #endif /* __ASM_AVR32_IO_H */
index 332d2c643745f6aa12b4a865c9710b5e2a55fa8f..512e13d1ca6678e5165eddaae69cfa412343fc7d 100644 (file)
@@ -40,6 +40,32 @@ static inline void sync(void)
        __builtin_bfin_ssync();
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 /*
  * These are for ISA/PCI shared memory _only_ and should never be used
  * on any other type of memory, including Zorro memory. They are meant to
index e64d788fa758cbba566688e22a967765a7252a18..db4f4428178564e4dc77dc604afdb1f23c13563b 100644 (file)
@@ -205,4 +205,30 @@ static inline void sync(void)
 {
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 #endif
index e14a581dc1645e2cbfbc6b9efdda2c27ab8929ce..91d759219de94d72afe3b417b4ef8399cf24c2ec 100644 (file)
 
 #include <asm/byteorder.h>
 
+/* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
+ * two accesses to memory, which may be undesirable for some devices.
+ */
+#define __raw_readb(addr) \
+    ({ u8 __v = (*(volatile u8 *) (addr)); __v; })
+#define __raw_readw(addr) \
+    ({ u16 __v = (*(volatile u16 *) (addr)); __v; })
+#define __raw_readl(addr) \
+    ({ u32 __v = (*(volatile u32 *) (addr)); __v; })
+
+#define __raw_writeb(addr,b) (void)((*(volatile u8 *) (addr)) = (b))
+#define __raw_writew(addr,w) (void)((*(volatile u16 *) (addr)) = (w))
+#define __raw_writel(addr,l) (void)((*(volatile u32 *) (addr)) = (l))
+
 #define readb(addr)            in_8((volatile u8 *)(addr))
 #define writeb(b,addr)         out_8((volatile u8 *)(addr), (b))
 #if !defined(__BIG_ENDIAN)
@@ -218,4 +232,31 @@ static inline void sync(void)
         * compatibility (CFI driver)
         */
 }
+
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 #endif                         /* __ASM_M68K_IO_H__ */
index 1c77ade4f1a173bb1d0cd1325d9084f838aabf21..90d18428ad1e960ab67b3e48849e7c0207b8a4ce 100644 (file)
@@ -129,4 +129,30 @@ static inline void sync(void)
 {
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 #endif /* __MICROBLAZE_IO_H__ */
index 1e060f7c31d7bfb01b14d34bfd02324ef7c828c4..e27d1f159d72527c7e1434eb8f7746f8f656cf98 100644 (file)
@@ -465,4 +465,30 @@ static inline void sync(void)
 {
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 #endif /* _ASM_IO_H */
index d77695abb9e1ccd1c9ff30cb327c7f8bd0f31f95..6fc339fb01994fed03b435b0e5c5dd40ad9f0ea6 100644 (file)
 #ifndef __ASM_NIOS_IO_H_
 #define __ASM_NIOS_IO_H_
 
+#define __raw_writeb(v,a)       (*(volatile unsigned char  *)(a) = (v))
+#define __raw_writew(v,a)       (*(volatile unsigned short *)(a) = (v))
+#define __raw_writel(v,a)       (*(volatile unsigned int   *)(a) = (v))
+
+#define __raw_readb(a)          (*(volatile unsigned char  *)(a))
+#define __raw_readw(a)          (*(volatile unsigned short *)(a))
+#define __raw_readl(a)          (*(volatile unsigned int   *)(a))
+
 #define readb(addr)\
        ({unsigned char val;\
         asm volatile(  "       pfxio   0               \n"\
@@ -101,4 +109,30 @@ static inline void sync(void)
 {
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 #endif /* __ASM_NIOS_IO_H_ */
index 5bb5322952f86884b0b8efe86afe659f9edce66e..a52b95cf235c37f3fcd1cc16ca7e027648b2db9e 100644 (file)
@@ -29,10 +29,44 @@ static inline void sync(void)
        __asm__ __volatile__ ("sync" : : : "memory");
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 extern unsigned char inb (unsigned char *port);
 extern unsigned short inw (unsigned short *port);
 extern unsigned inl (unsigned port);
 
+#define __raw_writeb(v,a)       (*(volatile unsigned char  *)(a) = (v))
+#define __raw_writew(v,a)       (*(volatile unsigned short *)(a) = (v))
+#define __raw_writel(v,a)       (*(volatile unsigned int   *)(a) = (v))
+
+#define __raw_readb(a)          (*(volatile unsigned char  *)(a))
+#define __raw_readw(a)          (*(volatile unsigned short *)(a))
+#define __raw_readl(a)          (*(volatile unsigned int   *)(a))
+
 #define readb(addr)\
        ({unsigned char val;\
         asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
index 11dfa1c57b48b6248ed96c457e9faa57a2e18c23..91c9c1e4c693335d6db2a1391d2e5e0a21ef804b 100644 (file)
@@ -120,6 +120,37 @@ static inline void isync(void)
 #define iobarrier_r()  eieio()
 #define iobarrier_w()  eieio()
 
+/*
+ * Non ordered and non-swapping "raw" accessors
+ */
+#define __iomem
+#define PCI_FIX_ADDR(addr)     (addr)
+
+static inline unsigned char __raw_readb(const volatile void __iomem *addr)
+{
+       return *(volatile unsigned char *)PCI_FIX_ADDR(addr);
+}
+static inline unsigned short __raw_readw(const volatile void __iomem *addr)
+{
+       return *(volatile unsigned short *)PCI_FIX_ADDR(addr);
+}
+static inline unsigned int __raw_readl(const volatile void __iomem *addr)
+{
+       return *(volatile unsigned int *)PCI_FIX_ADDR(addr);
+}
+static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
+{
+       *(volatile unsigned char *)PCI_FIX_ADDR(addr) = v;
+}
+static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
+{
+       *(volatile unsigned short *)PCI_FIX_ADDR(addr) = v;
+}
+static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
+{
+       *(volatile unsigned int *)PCI_FIX_ADDR(addr) = v;
+}
+
 /*
  * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  *
@@ -127,7 +158,6 @@ static inline void isync(void)
  * is actually performed (i.e. the data has come back) before we start
  * executing any following instructions.
  */
-#define __iomem
 extern inline int in_8(const volatile unsigned char __iomem *addr)
 {
        int ret;
@@ -208,4 +238,30 @@ extern inline void out_be32(volatile unsigned __iomem *addr, int val)
        __asm__ __volatile__("sync; stw%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
 }
 
+/*
+ * Given a physical address and a length, return a virtual address
+ * that can be used to access the memory range with the caching
+ * properties specified by "flags".
+ */
+typedef unsigned long phys_addr_t;
+
+#define MAP_NOCACHE    (0)
+#define MAP_WRCOMBINE  (0)
+#define MAP_WRBACK     (0)
+#define MAP_WRTHROUGH  (0)
+
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+{
+       return (void *)paddr;
+}
+
+/*
+ * Take down a mapping set up by map_physmem().
+ */
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+
+}
+
 #endif
diff --git a/include/configs/atstk1003.h b/include/configs/atstk1003.h
new file mode 100644 (file)
index 0000000..194788b
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2007 Atmel Corporation
+ *
+ * Configuration settings for the ATSTK1003 CPU daughterboard
+ *
+ * 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
+ */
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#define CONFIG_AVR32                   1
+#define CONFIG_AT32AP                  1
+#define CONFIG_AT32AP7001              1
+#define CONFIG_ATSTK1003               1
+#define CONFIG_ATSTK1000               1
+
+#define CONFIG_ATSTK1000_EXT_FLASH     1
+
+/*
+ * Timer clock frequency. We're using the CPU-internal COUNT register
+ * for this, so this is equivalent to the CPU core clock frequency
+ */
+#define CFG_HZ                         1000
+
+/*
+ * Set up the PLL to run at 140 MHz, the CPU to run at the PLL
+ * frequency, the HSB and PBB at 1/2, and the PBA to run at 1/4 the
+ * PLL frequency.
+ * (CFG_OSC0_HZ * CFG_PLL0_MUL) / CFG_PLL0_DIV = PLL MHz
+ */
+#define CONFIG_PLL                     1
+#define CFG_POWER_MANAGER              1
+#define CFG_OSC0_HZ                    20000000
+#define CFG_PLL0_DIV                   1
+#define CFG_PLL0_MUL                   7
+#define CFG_PLL0_SUPPRESS_CYCLES       16
+/*
+ * Set the CPU running at:
+ * PLL / (2^CFG_CLKDIV_CPU) = CPU MHz
+ */
+#define CFG_CLKDIV_CPU                 0
+/*
+ * Set the HSB running at:
+ * PLL / (2^CFG_CLKDIV_HSB) = HSB MHz
+ */
+#define CFG_CLKDIV_HSB                 1
+/*
+ * Set the PBA running at:
+ * PLL / (2^CFG_CLKDIV_PBA) = PBA MHz
+ */
+#define CFG_CLKDIV_PBA                 2
+/*
+ * Set the PBB running at:
+ * PLL / (2^CFG_CLKDIV_PBB) = PBB MHz
+ */
+#define CFG_CLKDIV_PBB                 1
+
+/*
+ * The PLLOPT register controls the PLL like this:
+ *   icp = PLLOPT<2>
+ *   ivco = PLLOPT<1:0>
+ *
+ * We want icp=1 (default) and ivco=0 (80-160 MHz) or ivco=2 (150-240MHz).
+ */
+#define CFG_PLL0_OPT                   0x04
+
+#undef CONFIG_USART0
+#define CONFIG_USART1                  1
+#undef CONFIG_USART2
+#undef CONFIG_USART3
+
+/* User serviceable stuff */
+#define CONFIG_DOS_PARTITION           1
+
+#define CONFIG_CMDLINE_TAG             1
+#define CONFIG_SETUP_MEMORY_TAGS       1
+#define CONFIG_INITRD_TAG              1
+
+#define CONFIG_STACKSIZE               (2048)
+
+#define CONFIG_BAUDRATE                        115200
+#define CONFIG_BOOTARGS                                                        \
+       "console=ttyS0 root=/dev/mmcblk0p1 rootwait"
+
+#define CONFIG_BOOTCOMMAND                                             \
+       "mmcinit; ext2load mmc 0:1 0x10400000 /boot/uImage; bootm"
+
+/*
+ * Only interrupt autoboot if <space> is pressed. Otherwise, garbage
+ * data on the serial line may interrupt the boot sequence.
+ */
+#define CONFIG_BOOTDELAY               1
+#define CONFIG_AUTOBOOT                        1
+#define CONFIG_AUTOBOOT_KEYED          1
+#define CONFIG_AUTOBOOT_PROMPT                         \
+       "Press SPACE to abort autoboot in %d seconds\n"
+#define CONFIG_AUTOBOOT_DELAY_STR      "d"
+#define CONFIG_AUTOBOOT_STOP_STR       " "
+
+/*
+ * Command line configuration.
+ */
+#include <config_cmd_default.h>
+
+#define CONFIG_CMD_ASKENV
+#define CONFIG_CMD_EXT2
+#define CONFIG_CMD_FAT
+#define CONFIG_CMD_JFFS2
+#define CONFIG_CMD_MMC
+
+#undef CONFIG_CMD_FPGA
+#undef CONFIG_CMD_NET
+#undef CONFIG_CMD_NFS
+#undef CONFIG_CMD_SETGETDCR
+#undef CONFIG_CMD_XIMG
+
+#define CONFIG_ATMEL_USART             1
+#define CONFIG_PIO2                    1
+#define CFG_HSDRAMC                    1
+#define CONFIG_MMC                     1
+
+#define CFG_DCACHE_LINESZ              32
+#define CFG_ICACHE_LINESZ              32
+
+#define CONFIG_NR_DRAM_BANKS           1
+
+/* External flash on STK1000 */
+#if 0
+#define CFG_FLASH_CFI                  1
+#define CFG_FLASH_CFI_DRIVER           1
+#endif
+
+#define CFG_FLASH_BASE                 0x00000000
+#define CFG_FLASH_SIZE                 0x800000
+#define CFG_MAX_FLASH_BANKS            1
+#define CFG_MAX_FLASH_SECT             135
+
+#define CFG_MONITOR_BASE               CFG_FLASH_BASE
+
+#define CFG_INTRAM_BASE                        0x24000000
+#define CFG_INTRAM_SIZE                        0x8000
+
+#define CFG_SDRAM_BASE                 0x10000000
+
+#define CFG_ENV_IS_IN_FLASH            1
+#define CFG_ENV_SIZE                   65536
+#define CFG_ENV_ADDR                   (CFG_FLASH_BASE + CFG_FLASH_SIZE - CFG_ENV_SIZE)
+
+#define CFG_INIT_SP_ADDR               (CFG_INTRAM_BASE + CFG_INTRAM_SIZE)
+
+#define CFG_MALLOC_LEN                 (256*1024)
+
+/* Allow 4MB for the kernel run-time image */
+#define CFG_LOAD_ADDR                  (CFG_SDRAM_BASE + 0x00400000)
+#define CFG_BOOTPARAMS_LEN             (16 * 1024)
+
+/* Other configuration settings that shouldn't have to change all that often */
+#define CFG_PROMPT                     "Uboot> "
+#define CFG_CBSIZE                     256
+#define CFG_MAXARGS                    16
+#define CFG_PBSIZE                     (CFG_CBSIZE + sizeof(CFG_PROMPT) + 16)
+#define CFG_LONGHELP                   1
+
+#define CFG_MEMTEST_START              CFG_SDRAM_BASE
+#define CFG_MEMTEST_END                        (CFG_MEMTEST_START + 0x700000)
+#define CFG_BAUDRATE_TABLE { 115200, 38400, 19200, 9600, 2400 }
+
+#endif /* __CONFIG_H */
diff --git a/include/configs/atstk1004.h b/include/configs/atstk1004.h
new file mode 100644 (file)
index 0000000..1bad171
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2007 Atmel Corporation
+ *
+ * Configuration settings for the ATSTK1003 CPU daughterboard
+ *
+ * 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
+ */
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#define CONFIG_AVR32                   1
+#define CONFIG_AT32AP                  1
+#define CONFIG_AT32AP7002              1
+#define CONFIG_ATSTK1004               1
+#define CONFIG_ATSTK1000               1
+
+#define CONFIG_ATSTK1000_EXT_FLASH     1
+
+/*
+ * Timer clock frequency. We're using the CPU-internal COUNT register
+ * for this, so this is equivalent to the CPU core clock frequency
+ */
+#define CFG_HZ                         1000
+
+/*
+ * Set up the PLL to run at 140 MHz, the CPU to run at the PLL
+ * frequency, the HSB and PBB at 1/2, and the PBA to run at 1/4 the
+ * PLL frequency.
+ * (CFG_OSC0_HZ * CFG_PLL0_MUL) / CFG_PLL0_DIV = PLL MHz
+ */
+#define CONFIG_PLL                     1
+#define CFG_POWER_MANAGER              1
+#define CFG_OSC0_HZ                    20000000
+#define CFG_PLL0_DIV                   1
+#define CFG_PLL0_MUL                   7
+#define CFG_PLL0_SUPPRESS_CYCLES       16
+/*
+ * Set the CPU running at:
+ * PLL / (2^CFG_CLKDIV_CPU) = CPU MHz
+ */
+#define CFG_CLKDIV_CPU                 0
+/*
+ * Set the HSB running at:
+ * PLL / (2^CFG_CLKDIV_HSB) = HSB MHz
+ */
+#define CFG_CLKDIV_HSB                 1
+/*
+ * Set the PBA running at:
+ * PLL / (2^CFG_CLKDIV_PBA) = PBA MHz
+ */
+#define CFG_CLKDIV_PBA                 2
+/*
+ * Set the PBB running at:
+ * PLL / (2^CFG_CLKDIV_PBB) = PBB MHz
+ */
+#define CFG_CLKDIV_PBB                 1
+
+/*
+ * The PLLOPT register controls the PLL like this:
+ *   icp = PLLOPT<2>
+ *   ivco = PLLOPT<1:0>
+ *
+ * We want icp=1 (default) and ivco=0 (80-160 MHz) or ivco=2 (150-240MHz).
+ */
+#define CFG_PLL0_OPT                   0x04
+
+#undef CONFIG_USART0
+#define CONFIG_USART1                  1
+#undef CONFIG_USART2
+#undef CONFIG_USART3
+
+/* User serviceable stuff */
+#define CONFIG_DOS_PARTITION           1
+
+#define CONFIG_CMDLINE_TAG             1
+#define CONFIG_SETUP_MEMORY_TAGS       1
+#define CONFIG_INITRD_TAG              1
+
+#define CONFIG_STACKSIZE               (2048)
+
+#define CONFIG_BAUDRATE                        115200
+#define CONFIG_BOOTARGS                                                        \
+       "console=ttyS0 root=/dev/mmcblk0p1 rootwait"
+
+#define CONFIG_BOOTCOMMAND                                             \
+       "mmcinit; ext2load mmc 0:1 0x10200000 /boot/uImage; bootm"
+
+/*
+ * Only interrupt autoboot if <space> is pressed. Otherwise, garbage
+ * data on the serial line may interrupt the boot sequence.
+ */
+#define CONFIG_BOOTDELAY               1
+#define CONFIG_AUTOBOOT                        1
+#define CONFIG_AUTOBOOT_KEYED          1
+#define CONFIG_AUTOBOOT_PROMPT                         \
+       "Press SPACE to abort autoboot in %d seconds\n"
+#define CONFIG_AUTOBOOT_DELAY_STR      "d"
+#define CONFIG_AUTOBOOT_STOP_STR       " "
+
+/*
+ * Command line configuration.
+ */
+#include <config_cmd_default.h>
+
+#define CONFIG_CMD_ASKENV
+#define CONFIG_CMD_EXT2
+#define CONFIG_CMD_FAT
+#define CONFIG_CMD_JFFS2
+#define CONFIG_CMD_MMC
+
+#undef CONFIG_CMD_FPGA
+#undef CONFIG_CMD_NET
+#undef CONFIG_CMD_NFS
+#undef CONFIG_CMD_SETGETDCR
+#undef CONFIG_CMD_XIMG
+
+#define CONFIG_ATMEL_USART             1
+#define CONFIG_PIO2                    1
+#define CFG_HSDRAMC                    1
+#define CONFIG_MMC                     1
+
+#define CFG_DCACHE_LINESZ              32
+#define CFG_ICACHE_LINESZ              32
+
+#define CONFIG_NR_DRAM_BANKS           1
+
+/* External flash on STK1000 */
+#if 0
+#define CFG_FLASH_CFI                  1
+#define CFG_FLASH_CFI_DRIVER           1
+#endif
+
+#define CFG_FLASH_BASE                 0x00000000
+#define CFG_FLASH_SIZE                 0x800000
+#define CFG_MAX_FLASH_BANKS            1
+#define CFG_MAX_FLASH_SECT             135
+
+#define CFG_MONITOR_BASE               CFG_FLASH_BASE
+
+#define CFG_INTRAM_BASE                        0x24000000
+#define CFG_INTRAM_SIZE                        0x8000
+
+#define CFG_SDRAM_BASE                 0x10000000
+#define CFG_SDRAM_16BIT                        1
+
+#define CFG_ENV_IS_IN_FLASH            1
+#define CFG_ENV_SIZE                   65536
+#define CFG_ENV_ADDR                   (CFG_FLASH_BASE + CFG_FLASH_SIZE - CFG_ENV_SIZE)
+
+#define CFG_INIT_SP_ADDR               (CFG_INTRAM_BASE + CFG_INTRAM_SIZE)
+
+#define CFG_MALLOC_LEN                 (256*1024)
+
+/* Allow 4MB for the kernel run-time image */
+#define CFG_LOAD_ADDR                  (CFG_SDRAM_BASE + 0x00200000)
+#define CFG_BOOTPARAMS_LEN             (16 * 1024)
+
+/* Other configuration settings that shouldn't have to change all that often */
+#define CFG_PROMPT                     "Uboot> "
+#define CFG_CBSIZE                     256
+#define CFG_MAXARGS                    16
+#define CFG_PBSIZE                     (CFG_CBSIZE + sizeof(CFG_PROMPT) + 16)
+#define CFG_LONGHELP                   1
+
+#define CFG_MEMTEST_START              CFG_SDRAM_BASE
+#define CFG_MEMTEST_END                        (CFG_MEMTEST_START + 0x700000)
+#define CFG_BAUDRATE_TABLE { 115200, 38400, 19200, 9600, 2400 }
+
+#endif /* __CONFIG_H */
index 8f781d4405bf59f15f923949ead5d7ab1533887a..3d6c1a841b70913d549e17def4ecfd217d0eaa10 100644 (file)
@@ -44,6 +44,7 @@ void do_fixup_by_compat(void *fdt, const char *compat,
                        const char *prop, const void *val, int len, int create);
 void do_fixup_by_compat_u32(void *fdt, const char *compat,
                            const char *prop, u32 val, int create);
+int fdt_fixup_memory(void *blob, u64 start, u64 size);
 void fdt_fixup_ethernet(void *fdt, bd_t *bd);
 
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
index b0bf733f18dc7c16fdeedd62b5a85d99f51fa813..2ed1e20fd22be96a45932eb3d34cb2eba6d26a0c 100644 (file)
@@ -52,6 +52,9 @@ typedef struct {
        ushort  ext_addr;               /* extended query table address         */
        ushort  cfi_version;            /* cfi version                          */
        ushort  cfi_offset;             /* offset for cfi query                 */
+       ulong   addr_unlock1;           /* unlock address 1 for AMD flash roms  */
+       ulong   addr_unlock2;           /* unlock address 2 for AMD flash roms  */
+       const char *name;               /* human-readable name                  */
 #endif
 } flash_info_t;
 
@@ -77,6 +80,7 @@ typedef struct {
 #define FLASH_CFI_X8           0x00
 #define FLASH_CFI_X16          0x01
 #define FLASH_CFI_X8X16                0x02
+#define FLASH_CFI_X16X32       0x05
 
 /* convert between bit value and numeric value */
 #define CFI_FLASH_SHIFT_WIDTH  3
@@ -101,6 +105,13 @@ extern void flash_read_user_serial(flash_info_t * info, void * buffer, int offse
 extern void flash_read_factory_serial(flash_info_t * info, void * buffer, int offset, int len);
 #endif /* CFG_FLASH_PROTECTION */
 
+#ifdef CONFIG_FLASH_CFI_LEGACY
+extern ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info);
+extern int jedec_flash_match(flash_info_t *info, ulong base);
+#define CFI_CMDSET_AMD_LEGACY          0xFFF0
+#endif
+
+
 /*-----------------------------------------------------------------------
  * return codes from flash_write():
  */
index 11d864feacabb66b783916b3a6cd0ddca41c314b..809ee3be92c29665861cef4fd296b0c15931d3d6 100644 (file)
@@ -311,6 +311,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
        dma_alloc_init();
        board_init_info();
 
+       enable_interrupts();
+
        bd->bi_flashstart = 0;
        bd->bi_flashsize = 0;
        bd->bi_flashoffset = 0;
index ce538f3d9241a5a590824d87383a8e2aeac83d18..28df20db01079fe4b84619016f483397b2d6dc04 100644 (file)
@@ -35,5 +35,5 @@ int disable_interrupts(void)
        sr = sysreg_read(SR);
        asm volatile("ssrf      %0" : : "n"(SYSREG_GM_OFFSET));
 
-       return SYSREG_BFEXT(GM, sr);
+       return !SYSREG_BFEXT(GM, sr);
 }