Patchwork [U-Boot,v3,01/11] arm: add MMU/D-Cache support for Faraday cores

login
register
mail settings
Submitter Kuo-Jung Su
Date April 26, 2013, 8:02 a.m.
Message ID <1366963360-2987-2-git-send-email-dantesu@gmail.com>
Download mbox | patch
Permalink /patch/239714/
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Comments

Kuo-Jung Su - April 26, 2013, 8:02 a.m.
From: Kuo-Jung Su <dantesu@faraday-tech.com>

This patch updates the map_physmem()/unmap_physmem(), and use
them to implement dma_alloc_coherent(), dma_free_coherent().

It uses 1MB section for each mapping, and thus waste lots of
address space, however this should still be good enough for
tiny systems (i.e. u-boot).

Signed-off-by: Kuo-Jung Su <dantesu@faraday-tech.com>
CC: Albert Aribaud <albert.u.boot@aribaud.net>
---
 arch/arm/include/asm/dma-mapping.h |   60 +++++++++++++-
 arch/arm/include/asm/global_data.h |    4 +
 arch/arm/include/asm/io.h          |  154 ++++++++++++++++++++++++++++++++++--
 arch/arm/include/asm/system.h      |    7 +-
 arch/arm/lib/cache-cp15.c          |   30 +++++++
 drivers/mtd/cfi_flash.c            |    2 +-
 6 files changed, 243 insertions(+), 14 deletions(-)
Kuo-Jung Su - May 7, 2013, 6:25 a.m.
From: Kuo-Jung Su <dantesu@faraday-tech.com>

These patches introduce Faraday A36x SoC platform support.

Here are some public documents for your reference.

    http://www.faraday-tech.com/html/documentation/index.html

There is also a A369 QEMU emulator available at my github account:

    https://github.com/dantesu1218/qemu.git

Here is quick start for QEMU:

1. Download the QEMU source tree

    $ git clone -b qemu-1.3.0 https://github.com/dantesu1218/qemu.git

2. Build & Install the QEMU:

    $ ./configure --target-list=arm-softmmu
    $ make
    $ make install

3. Launch u-boot with QEMU:

    $ qemu-system-arm -M a369 -m 512M -nographic -kernel ~/u-boot-devel/u-boot

Changes for v4:
   - Coding Style cleanup.
   - Break down the patch series:
       - Patches without hard dependency to this series are now
         seperate patches.
       - Split up the patch into more logical changesets
         (i.e. interrupt & timers are now split up)
   - Drop the faraday/nand.h to remove dependency to ftnandc021
   - Drop the faraday/mmc.h to remove dependency to ftsdc010
   - Add change logs to each part of the patch series to make
     patchwork be able to grab comments.

Changes for v3:
   - Coding Style cleanup.
     There is still one warnning reported by checkpatch.pl,
     however it's too deep for me to fix it.
     Here is the shapshot for it:
     -----------------------------------------------------
     WARNING: do not add new typedefs
     #9735: FILE: include/lcd.h:258:
     +typedef struct vidinfo {
     -----------------------------------------------------
   - Drop bit fields from c struct.
   - Drop macros for wirtel()/readl(), call them directly.
   - Always insert a blank line between declarations and code.
   - Replace all the infinite wait loop with a timeout.
   - Add '__iomem' to all the declaration of HW register pointers.
   - cmd_boot.c: Make it a separate stand-alone patch.
   - ftspi020: Make it a separate stand-alone patch.
   - dma-mapping.h: Have the global data ptr declared outside functions.
   - dma-mapping.h: Add #if...#else...#endif to dma_free_coherent().
   - MMU/D-Cache: Drop static non-cached region, now we use
     map_physmem()/unmap_physmem() for dynamic mappings.
   - ftmac110: Make a correction to multi-line comment style
   - ftmac110: Use random MAC address while having trouble
     to get one from environment variables.
   - ftmac110: Add comments to timing control registers.
   - ftnandc021: Re-write this driver with ECC enabled and
     correct column address handling for OOB read/write,
     and fixing issused addressed by Scott.
   - a36x_config: No more static global network configurations.
   - a36x_config: Add a common file for the redundant configurations.

Changes for v2:
   - Coding Style cleanup.
   - Use readl(), writel(), clrsetbits_le32() to replace REG() macros.
   - Use structure based hardware registers to replace the macro constants.
   - Replace BIT() with BIT_MASK().
   - echi-faraday: Remove debug codes.
   - ftmac110: Remove debug codes.
   - cache-cp15: Enable write buffer in write-through mode.

Kuo-Jung Su (7):
  arm: add MMU/D-Cache support for Faraday cores
  arm: add Faraday common utilities
  arm: add Faraday FTINTC020 interrupt controller support
  arm: add Faraday FTTMR010 timer support
  arm: add Faraday FTPWMTMR010 timer support
  arm: add Faraday firmware image utility
  arm: add Faraday A36x SoC platform support

 arch/arm/cpu/faraday/Makefile             |   57 ++++
 arch/arm/cpu/faraday/a360/Makefile        |   49 +++
 arch/arm/cpu/faraday/a369/Makefile        |   50 +++
 arch/arm/cpu/faraday/a369/cmd_fa606.c     |   77 +++++
 arch/arm/cpu/faraday/cmd_bootfa.c         |  132 ++++++++
 arch/arm/cpu/faraday/config.mk            |   33 ++
 arch/arm/cpu/faraday/cpu.c                |  280 +++++++++++++++
 arch/arm/cpu/faraday/ftpwmtmr010.c        |  160 +++++++++
 arch/arm/cpu/faraday/fttmr010.c           |  160 +++++++++
 arch/arm/cpu/faraday/fwimage.h            |   38 +++
 arch/arm/cpu/faraday/fwimage2.h           |   70 ++++
 arch/arm/cpu/faraday/interrupts.c         |  151 +++++++++
 arch/arm/cpu/faraday/start.S              |  523 +++++++++++++++++++++++++++++
 arch/arm/cpu/u-boot.lds                   |   11 +
 arch/arm/include/asm/arch-a360/hardware.h |   73 ++++
 arch/arm/include/asm/arch-a360/pmu.h      |   39 +++
 arch/arm/include/asm/arch-a360/scu.h      |   27 ++
 arch/arm/include/asm/arch-a369/ahbc.h     |   23 ++
 arch/arm/include/asm/arch-a369/hardware.h |   88 +++++
 arch/arm/include/asm/arch-a369/scu.h      |  213 ++++++++++++
 arch/arm/include/asm/dma-mapping.h        |   61 +++-
 arch/arm/include/asm/global_data.h        |    4 +
 arch/arm/include/asm/io.h                 |  160 ++++++++-
 arch/arm/include/asm/mach-types.h         |    1 +
 arch/arm/include/asm/system.h             |    7 +-
 arch/arm/lib/cache-cp15.c                 |   30 ++
 board/faraday/a360evb/Makefile            |   49 +++
 board/faraday/a360evb/board.c             |   73 ++++
 board/faraday/a360evb/clk.c               |   57 ++++
 board/faraday/a360evb/config.mk           |   33 ++
 board/faraday/a360evb/lowlevel_init.S     |   33 ++
 board/faraday/a369evb/Makefile            |   49 +++
 board/faraday/a369evb/board.c             |  184 ++++++++++
 board/faraday/a369evb/clk.c               |   80 +++++
 board/faraday/a369evb/config.mk           |   33 ++
 board/faraday/a369evb/lowlevel_init.S     |  136 ++++++++
 boards.cfg                                |    3 +
 drivers/mtd/cfi_flash.c                   |    2 +-
 include/common.h                          |   13 +
 include/configs/a360.h                    |   63 ++++
 include/configs/a369-common.h             |   74 ++++
 include/configs/a369.h                    |   33 ++
 include/configs/a369_fa606te.h            |   29 ++
 include/configs/faraday-common.h          |  304 +++++++++++++++++
 include/faraday/ftintc020.h               |   37 ++
 include/faraday/ftpwmtmr010.h             |   41 +++
 include/faraday/ftsmc020.h                |    1 +
 include/faraday/fttmr010.h                |   17 +
 48 files changed, 3847 insertions(+), 14 deletions(-)
 create mode 100644 arch/arm/cpu/faraday/Makefile
 create mode 100644 arch/arm/cpu/faraday/a360/Makefile
 create mode 100644 arch/arm/cpu/faraday/a369/Makefile
 create mode 100644 arch/arm/cpu/faraday/a369/cmd_fa606.c
 create mode 100644 arch/arm/cpu/faraday/cmd_bootfa.c
 create mode 100644 arch/arm/cpu/faraday/config.mk
 create mode 100644 arch/arm/cpu/faraday/cpu.c
 create mode 100644 arch/arm/cpu/faraday/ftpwmtmr010.c
 create mode 100644 arch/arm/cpu/faraday/fttmr010.c
 create mode 100644 arch/arm/cpu/faraday/fwimage.h
 create mode 100644 arch/arm/cpu/faraday/fwimage2.h
 create mode 100644 arch/arm/cpu/faraday/interrupts.c
 create mode 100644 arch/arm/cpu/faraday/start.S
 create mode 100644 arch/arm/include/asm/arch-a360/hardware.h
 create mode 100644 arch/arm/include/asm/arch-a360/pmu.h
 create mode 100644 arch/arm/include/asm/arch-a360/scu.h
 create mode 100644 arch/arm/include/asm/arch-a369/ahbc.h
 create mode 100644 arch/arm/include/asm/arch-a369/hardware.h
 create mode 100644 arch/arm/include/asm/arch-a369/scu.h
 create mode 100644 board/faraday/a360evb/Makefile
 create mode 100644 board/faraday/a360evb/board.c
 create mode 100644 board/faraday/a360evb/clk.c
 create mode 100644 board/faraday/a360evb/config.mk
 create mode 100644 board/faraday/a360evb/lowlevel_init.S
 create mode 100644 board/faraday/a369evb/Makefile
 create mode 100644 board/faraday/a369evb/board.c
 create mode 100644 board/faraday/a369evb/clk.c
 create mode 100644 board/faraday/a369evb/config.mk
 create mode 100644 board/faraday/a369evb/lowlevel_init.S
 create mode 100644 include/configs/a360.h
 create mode 100644 include/configs/a369-common.h
 create mode 100644 include/configs/a369.h
 create mode 100644 include/configs/a369_fa606te.h
 create mode 100644 include/configs/faraday-common.h
 create mode 100644 include/faraday/ftintc020.h
 create mode 100644 include/faraday/ftpwmtmr010.h

--
1.7.9.5

Patch

diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 5bbb0a0..9b56d79 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -3,6 +3,9 @@ 
  * Stelian Pop <stelian@popies.net>
  * Lead Tech Design <www.leadtechdesign.com>
  *
+ * (C) Copyright 2010
+ * Dante Su <dantesu@faraday-tech.com>
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
@@ -24,22 +27,75 @@ 
 #ifndef __ASM_ARM_DMA_MAPPING_H
 #define __ASM_ARM_DMA_MAPPING_H
 
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+#include <asm/u-boot.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <malloc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
+
 enum dma_data_direction {
 	DMA_BIDIRECTIONAL	= 0,
 	DMA_TO_DEVICE		= 1,
 	DMA_FROM_DEVICE		= 2,
 };
 
-static void *dma_alloc_coherent(size_t len, unsigned long *handle)
+static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
 {
-	*handle = (unsigned long)malloc(len);
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+	void *map, *va = memalign(ARCH_DMA_MINALIGN, len);
+
+	if (va && gd->arch.cpu_mmu) {
+		invalidate_dcache_range((ulong)va, (ulong)va + len);
+		map = map_physmem((phys_addr_t)va, len, MAP_NOCACHE);
+		if (!map)
+			free(va);
+		va = map;
+	}
+
+	if (handle)
+		*handle = virt_to_phys(va);
+
+	return va;
+#else  /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
+	*handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
 	return (void *)*handle;
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
+}
+
+static inline void dma_free_coherent(void *vaddr, ulong len)
+{
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+	unmap_physmem(vaddr, len);
+	vaddr = (void *)virt_to_phys(vaddr);
+#endif
+	free(vaddr);
 }
 
 static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
 					   enum dma_data_direction dir)
 {
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+	if (gd->arch.cpu_mmu) {
+		switch (dir) {
+		case DMA_BIDIRECTIONAL:
+		case DMA_TO_DEVICE:
+			flush_dcache_range((ulong)vaddr,
+				(ulong)vaddr + len);
+			break;
+
+		case DMA_FROM_DEVICE:
+			invalidate_dcache_range((ulong)vaddr,
+				(ulong)vaddr + len);
+			break;
+		}
+	}
+	return virt_to_phys((void *)vaddr);
+#else  /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 	return (unsigned long)vaddr;
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 }
 
 static inline void dma_unmap_single(volatile void *vaddr, size_t len,
diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h
index 37ac0da..bd18ff7 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -38,6 +38,10 @@  struct arch_global_data {
 	unsigned long	pllb_rate_hz;
 	unsigned long	at91_pllb_usb_init;
 #endif
+#ifdef CONFIG_FARADAY
+	unsigned long   cpu_id;
+	unsigned long   cpu_mmu;	/* has mmu */
+#endif
 	/* "static data" needed by most of timer.c on ARM platforms */
 	unsigned long timer_rate_hz;
 	unsigned long tbu;
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 1fbc531..739febd 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -2,6 +2,7 @@ 
  *  linux/include/asm-arm/io.h
  *
  *  Copyright (C) 1996-2000 Russell King
+ *  Copyright (C) 2009-2010 Dante Su <dantesu@faraday-tech.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -28,9 +29,30 @@ 
 #if 0	/* XXX###XXX */
 #include <asm/arch/hardware.h>
 #endif	/* XXX###XXX */
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+#include <asm/system.h>
+#include <asm/u-boot.h>
+#include <asm/global_data.h>
+
+#ifndef CONFIG_MMAP_START
+#define CONFIG_MMAP_START   0xd0000000
+#endif
+
+#ifndef CONFIG_MMAP_END
+#define CONFIG_MMAP_END     0xfff00000
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* arch/$(ARCH)/lib/cache.c */
+void flush_dcache_all(void);
+void flush_dcache_range(ulong start, ulong stop);
+
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 
 static inline void sync(void)
 {
+	flush_dcache_all();
 }
 
 /*
@@ -39,27 +61,143 @@  static inline void sync(void)
  * properties specified by "flags".
  */
 #define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
+#define MAP_WRCOMBINE	(1)
+#define MAP_WRBACK	(2)
+#define MAP_WRTHROUGH	(3)
+
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+static inline void map_flush(ulong start, ulong end)
+{
+	flush_dcache_range(start, end);
+
+	/* invalidate D-TLB */
+	start &= 0xfff00000;
+	end = (end + 0x000fffff) & 0xfff00000;
+	__asm__ __volatile__ (
+		"mov r3, %0\n"
+		"1:\n"
+		"mcr p15, 0, r3, c8, c6, 1\n"
+		"add r3, r3, #4096\n"
+		"cmp r3, %1\n"
+		"blo 1b\n"
+		: /* output */
+		: "r"(start), "r"(end) /* input */
+		: "r3" /* clobber list */
+	);
+}
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 
 static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+map_physmem(phys_addr_t paddr, ulong len, ulong flags)
 {
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+	u32 *page_table = (u32 *)gd->arch.tlb_addr;
+	u32 vaddr, nattr, oattr, addr, size, end;
+
+	/* 1. check if we have to create a mapping for it */
+	vaddr = paddr;
+	addr  = page_table[vaddr >> 20] & 0xfff00000;
+	oattr = page_table[vaddr >> 20] & 0x1f;
+	switch (flags) {
+	case MAP_WRCOMBINE:
+		nattr = DCACHE_WRITECOMBINE;
+		break;
+	case MAP_WRTHROUGH:
+		nattr = DCACHE_WRITETHROUGH;
+		break;
+	case MAP_WRBACK:
+		nattr = DCACHE_WRITEBACK;
+		break;
+	default:
+		nattr = DCACHE_OFF;
+		break;
+	}
+	if ((nattr == oattr) && (vaddr == addr))
+		return (void *)paddr;
+
+	/* 2. find a contiguous region for it */
+	end = (paddr + len + 0x000fffff) & 0xfff00000;
+	len = end - (paddr & 0xfff00000);
+	size = 0;
+	addr = CONFIG_MMAP_START;
+	vaddr = addr;
+	while (addr < CONFIG_MMAP_END) {
+		/* if va == pa, then it's free to use */
+		if (addr == (page_table[addr >> 20] & 0xfff00000)) {
+			size += SZ_1M;
+		} else {
+			size = 0;
+			vaddr = addr + SZ_1M;
+		}
+		if (size >= len)
+			break;
+		addr += SZ_1M;
+	}
+	if (size < len)
+		return NULL;
+
+	/* 3. create the map */
+	map_flush(vaddr, vaddr + size);
+	addr = vaddr;
+	vaddr += paddr & 0x000fffff;
+	paddr &= 0xfff00000;
+	while (size) {
+		page_table[addr >> 20] = paddr | (3 << 10) | nattr;
+		size -= SZ_1M;
+		addr += SZ_1M;
+		paddr += SZ_1M;
+	}
+	return (void *)vaddr;
+#else  /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 	return (void *)paddr;
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 }
 
 /*
  * Take down a mapping set up by map_physmem().
  */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
+static inline void unmap_physmem(void *vaddr, ulong len)
 {
-
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+	u32 *page_table = (u32 *)gd->arch.tlb_addr;
+	u32 addr, end;
+
+	/* 1. skip on NULL pointer */
+	if (!vaddr)
+		return;
+
+	/* 2. check if it's the right address map */
+	addr = (u32)vaddr;
+	if ((page_table[addr >> 20] & 0xfff00000) == addr)
+		return;
+
+	/* 3. reset the map */
+	end = (addr + len + 0x000fffff) & 0xfff00000;
+	addr &= 0xfff00000;
+	map_flush(addr, end);
+	while (addr < end) {
+		page_table[addr >> 20] = addr | (3 << 10) | DCACHE_OFF;
+		addr += SZ_1M;
+	}
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 }
 
-static inline phys_addr_t virt_to_phys(void * vaddr)
+static inline phys_addr_t virt_to_phys(void *vaddr)
 {
-	return (phys_addr_t)(vaddr);
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+	u32 *page_table = (u32 *)gd->arch.tlb_addr;
+	phys_addr_t phys = (phys_addr_t)vaddr;
+
+	if (!gd->arch.cpu_mmu || !vaddr)
+		return phys;
+
+	phys = page_table[(u32)vaddr >> 20] & 0xfff00000;
+	phys += (u32)vaddr & 0x000fffff;
+
+	return phys;
+#else  /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
+	return (phys_addr_t)vaddr;
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 }
 
 /*
diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
index 760345f..050b707 100644
--- a/arch/arm/include/asm/system.h
+++ b/arch/arm/include/asm/system.h
@@ -97,9 +97,10 @@  static inline void set_dacr(unsigned int val)
 
 /* options available for data cache on each page */
 enum dcache_option {
-	DCACHE_OFF = 0x12,
-	DCACHE_WRITETHROUGH = 0x1a,
-	DCACHE_WRITEBACK = 0x1e,
+	DCACHE_OFF = 0x12,          /* non-cached + non-buffered */
+	DCACHE_WRITECOMBINE = 0x16, /* non-cached + buffered */
+	DCACHE_WRITETHROUGH = 0x1a, /* cached + non-buffered */
+	DCACHE_WRITEBACK = 0x1e,    /* cached + buffered */
 };
 
 /* Size of an MMU section */
diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c
index 4abe1cf..ea29e83 100644
--- a/arch/arm/lib/cache-cp15.c
+++ b/arch/arm/lib/cache-cp15.c
@@ -1,6 +1,8 @@ 
 /*
  * (C) Copyright 2002
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ * (C) Copyright 2010
+ * Dante Su <dantesu@faraday-tech.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -98,6 +100,24 @@  __weak void dram_bank_mmu_setup(int bank)
 		set_section_dcache(i, DCACHE_WRITEBACK);
 #endif
 	}
+
+#if defined(CONFIG_FARADAY) && !defined(CONFIG_SYS_DCACHE_OFF)
+
+# ifdef CONFIG_USE_IRQ
+	/* make sure the exception table is at 0x00000000 */
+	if (!bank && bd->bi_dram[bank].start) {
+		u32 pa = bd->bi_dram[bank].start;
+		u32 *page_table = (u32 *)gd->arch.tlb_addr;
+
+#  ifdef CONFIG_SYS_ARM_CACHE_WRITETHROUGH
+		page_table[0] = pa | (3 << 10) | DCACHE_WRITETHROUGH;
+#  else
+		page_table[0] = pa | (3 << 10) | DCACHE_WRITEBACK;
+#  endif
+	}
+# endif /* # ifdef CONFIG_USE_IRQ */
+
+#endif /* CONFIG_FARADAY && !CONFIG_SYS_DCACHE_OFF */
 }
 
 /* to activate the MMU we need to set up virtual memory: use 1M areas */
@@ -126,6 +146,10 @@  static inline void mmu_setup(void)
 
 	/* and enable the mmu */
 	reg = get_cr();	/* get control reg. */
+#ifdef CONFIG_FARADAY
+	reg |= CR_W;	/* enable write buffer */
+	reg |= CR_Z;	/* enable branch prediction */
+#endif
 	cp_delay();
 	set_cr(reg | CR_M);
 }
@@ -140,9 +164,15 @@  static void cache_enable(uint32_t cache_bit)
 {
 	uint32_t reg;
 
+#ifdef CONFIG_FARADAY
+	if (!gd->arch.cpu_mmu && (cache_bit == CR_C))
+		return;
+#endif
+
 	/* The data cache is not active unless the mmu is enabled too */
 	if ((cache_bit == CR_C) && !mmu_enabled())
 		mmu_setup();
+
 	reg = get_cr();	/* get control reg. */
 	cp_delay();
 	set_cr(reg | cache_bit);
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 22d8440..49bdcff 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -1818,7 +1818,7 @@  static int flash_detect_legacy(phys_addr_t base, int banknum)
 					break;
 				else
 					unmap_physmem((void *)info->start[0],
-						      MAP_NOCACHE);
+						      info->portwidth);
 			}
 		}