[U-Boot] [PATCH 00/10] AVR32: RFC/preview - support for ATEVK1100 evaluation board

This is a patch series which adds support for the ATEVK1100 evaluation board[1], and the AT32UC3A0xxx[2] microcontrollers used on that board. The patch series is based on avr32/next.
This microcontroller is similar to the AT32AP700x, which is already supported by U-Boot, and this code is therefore based on that.
Patch 1 makes a change which works around a bug in the compiler. Patch 2-8 makes changes to other avr32-code in preparation for support of the new microcontroller. Patch 9 adds support for the AT32UC3A0xxx microcontrollers. Patch 10 adds support for the ATEVK1100 evaluation board.
The current revisions of the microcontroller have a bug in the SDRAM-controller, which makes it unreliable to run code from SDRAM. We therefore currently relocate only data to SDRAM, and no code. This makes U-Boot mostly useless on this platform until new revisions of the microcontroller arrive. We are also going to add support for SRAM and running U-Boot and loaded images from SRAM.
What works: Loading U-Boot, serial console, loading image over dhcp/tftp, booting image.
What doesn't work: - Actually running the loaded image - it crashes due to the SDRAM-bug. - Saving environment to flash - requires moving the code out of flash first.
[1] http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=4114 [2] http://www.atmel.com/products/avr32/uc3/uc3_2.asp?family_id=682

This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- net/net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/net.c b/net/net.c index 313d5d8..405ca6e 100644 --- a/net/net.c +++ b/net/net.c @@ -1685,7 +1685,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot) void NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len) { - volatile IP_t *ip = (IP_t *)xip; + IP_t *ip = (IP_t *)xip;
/* * If the data is an odd number of bytes, zero the

[Cc'ing the networking maintainer]
Olav Morken olavmrk@gmail.com wrote:
This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
Note that this bug has been reported internally, and will hopefully get fixed soon.
That said, I feel somewhat suspicious about the rather liberal use of volatile in the networking code. Is that really necessary? It looks to me that in many cases, volatile does nothing apart from hurting performance.
Looking at the assembly code, gcc does some really stupid things in there. Maybe that's an avr32-specific problem, but gcc has been known to generate crappy code on other architectures as well when volatile is involved...
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
net/net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/net.c b/net/net.c index 313d5d8..405ca6e 100644 --- a/net/net.c +++ b/net/net.c @@ -1685,7 +1685,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot) void NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len) {
- volatile IP_t *ip = (IP_t *)xip;
IP_t *ip = (IP_t *)xip;
/*
- If the data is an odd number of bytes, zero the
-- 1.6.0.2
Haavard

Olav Morken wrote:
This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
What other architectures have you tried this on?
regards, Ben

On Fri, Oct 10, 2008 at 7:01 PM, Ben Warren biggerbadderben@gmail.com wrote:
Olav Morken wrote:
This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
What other architectures have you tried this on?
None, as we don't have any other boards to test on. I do however believe that this change should have no side-effects. If any architectures relied on this function working as some sort of memory/io barrier, they would have problems with other functions such as ArpRequest, which doesn't have anything that will work as a memory/io barrier before the eth_send function.
Of course, I could be wrong. I would certainly not suggest including this change without some more testing.
The bug which causes this problem is in avr32-gcc, which makes assumptions about the alignement of IP_t when using volatile, and this change shouldn't be necessary once that bug is fixed. Until that bug is fixed, this change is needed for anyone trying to run U-Boot on this microcontroller.

On 20:56 Fri 10 Oct , Olav Morken wrote:
On Fri, Oct 10, 2008 at 7:01 PM, Ben Warren biggerbadderben@gmail.com wrote:
Olav Morken wrote:
This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
What other architectures have you tried this on?
None, as we don't have any other boards to test on. I do however believe
you can test under qemu with qemu_mips board at least
Best Regards, J.

On Fri, Oct 10, 2008 at 21:13, Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com wrote:
On 20:56 Fri 10 Oct , Olav Morken wrote:
On Fri, Oct 10, 2008 at 7:01 PM, Ben Warren biggerbadderben@gmail.com wrote:
Olav Morken wrote:
This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
What other architectures have you tried this on?
None, as we don't have any other boards to test on. I do however believe
you can test under qemu with qemu_mips board at least
Thanks for the tip. Will try to install a mips cross-compiler, and test it.

Olav Morken wrote:
This patch removes volatile from: volatile IP_t *ip = (IP_t *)xip;
Due to a bug, avr32-gcc will assume that ip is aligned on a word boundary when using volatile, which causes an exception since xip isn't aligned on a word boundary.
Applied to net/testing.
regards, Ben

On the ATEVK1100 (with an ATUC3A0512ES CPU), USART interrupts appear to be enabled after reset.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- drivers/serial/atmel_usart.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c index f3b146c..a358871 100644 --- a/drivers/serial/atmel_usart.c +++ b/drivers/serial/atmel_usart.c @@ -58,6 +58,9 @@ int serial_init(void) { usart3_writel(CR, USART3_BIT(RSTRX) | USART3_BIT(RSTTX));
+ /* Make sure that all interrupts are disabled during startup. */ + usart3_writel(IDR, 0xffffffff); + serial_setbrg();
usart3_writel(CR, USART3_BIT(RXEN) | USART3_BIT(TXEN));

The AT32UC3A series of processors doesn't contain any cache, and issuing cache control instructions on those will cause an exception. This commit makes cacheflush.h arch-dependent in preparation for the AT32UC3A-support.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- board/atmel/atstk1000/flash.c | 2 +- board/earthlcd/favr-32-ezkit/flash.c | 2 +- cpu/at32ap/cache.c | 2 +- include/asm-avr32/arch-at32ap700x/cacheflush.h | 83 ++++++++++++++++++++++++ include/asm-avr32/cacheflush.h | 83 ------------------------ include/asm-avr32/dma-mapping.h | 2 +- lib_avr32/board.c | 2 +- 7 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 include/asm-avr32/arch-at32ap700x/cacheflush.h delete mode 100644 include/asm-avr32/cacheflush.h
diff --git a/board/atmel/atstk1000/flash.c b/board/atmel/atstk1000/flash.c index e2bfd4a..1b45940 100644 --- a/board/atmel/atstk1000/flash.c +++ b/board/atmel/atstk1000/flash.c @@ -22,7 +22,7 @@ #include <common.h>
#ifdef CONFIG_ATSTK1000_EXT_FLASH -#include <asm/cacheflush.h> +#include <asm/arch/cacheflush.h> #include <asm/io.h> #include <asm/sections.h>
diff --git a/board/earthlcd/favr-32-ezkit/flash.c b/board/earthlcd/favr-32-ezkit/flash.c index 2aa9415..fdf83ad 100644 --- a/board/earthlcd/favr-32-ezkit/flash.c +++ b/board/earthlcd/favr-32-ezkit/flash.c @@ -20,7 +20,7 @@ #include <common.h>
#ifdef CONFIG_FAVR32_EZKIT_EXT_FLASH -#include <asm/cacheflush.h> +#include <asm/arch/cacheflush.h> #include <asm/io.h> #include <asm/sections.h>
diff --git a/cpu/at32ap/cache.c b/cpu/at32ap/cache.c index 41fb5aa..3f1eea5 100644 --- a/cpu/at32ap/cache.c +++ b/cpu/at32ap/cache.c @@ -22,7 +22,7 @@
#include <common.h>
-#include <asm/cacheflush.h> +#include <asm/arch/cacheflush.h>
void dcache_clean_range(volatile void *start, size_t size) { diff --git a/include/asm-avr32/arch-at32ap700x/cacheflush.h b/include/asm-avr32/arch-at32ap700x/cacheflush.h new file mode 100644 index 0000000..929f68e --- /dev/null +++ b/include/asm-avr32/arch-at32ap700x/cacheflush.h @@ -0,0 +1,83 @@ +/* + * 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_CACHEFLUSH_H +#define __ASM_AVR32_CACHEFLUSH_H + +/* + * Invalidate any cacheline containing virtual address vaddr without + * writing anything back to memory. + * + * Note that this function may corrupt unrelated data structures when + * applied on buffers that are not cacheline aligned in both ends. + */ +static inline void dcache_invalidate_line(volatile void *vaddr) +{ + asm volatile("cache %0[0], 0x0b" : : "r"(vaddr) : "memory"); +} + +/* + * Make sure any cacheline containing virtual address vaddr is written + * to memory. + */ +static inline void dcache_clean_line(volatile void *vaddr) +{ + asm volatile("cache %0[0], 0x0c" : : "r"(vaddr) : "memory"); +} + +/* + * Make sure any cacheline containing virtual address vaddr is written + * to memory and then invalidate it. + */ +static inline void dcache_flush_line(volatile void *vaddr) +{ + asm volatile("cache %0[0], 0x0d" : : "r"(vaddr) : "memory"); +} + +/* + * Invalidate any instruction cacheline containing virtual address + * vaddr. + */ +static inline void icache_invalidate_line(volatile void *vaddr) +{ + asm volatile("cache %0[0], 0x01" : : "r"(vaddr) : "memory"); +} + +/* + * Applies the above functions on all lines that are touched by the + * specified virtual address range. + */ +void dcache_invalidate_range(volatile void *start, size_t len); +void dcache_clean_range(volatile void *start, size_t len); +void dcache_flush_range(volatile void *start, size_t len); +void icache_invalidate_range(volatile void *start, size_t len); + +static inline void dcache_flush_unlocked(void) +{ + asm volatile("cache %0[5], 0x08" : : "r"(0) : "memory"); +} + +/* + * Make sure any pending writes are completed before continuing. + */ +#define sync_write_buffer() asm volatile("sync 0" : : : "memory") + +#endif /* __ASM_AVR32_CACHEFLUSH_H */ diff --git a/include/asm-avr32/cacheflush.h b/include/asm-avr32/cacheflush.h deleted file mode 100644 index 929f68e..0000000 --- a/include/asm-avr32/cacheflush.h +++ /dev/null @@ -1,83 +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_CACHEFLUSH_H -#define __ASM_AVR32_CACHEFLUSH_H - -/* - * Invalidate any cacheline containing virtual address vaddr without - * writing anything back to memory. - * - * Note that this function may corrupt unrelated data structures when - * applied on buffers that are not cacheline aligned in both ends. - */ -static inline void dcache_invalidate_line(volatile void *vaddr) -{ - asm volatile("cache %0[0], 0x0b" : : "r"(vaddr) : "memory"); -} - -/* - * Make sure any cacheline containing virtual address vaddr is written - * to memory. - */ -static inline void dcache_clean_line(volatile void *vaddr) -{ - asm volatile("cache %0[0], 0x0c" : : "r"(vaddr) : "memory"); -} - -/* - * Make sure any cacheline containing virtual address vaddr is written - * to memory and then invalidate it. - */ -static inline void dcache_flush_line(volatile void *vaddr) -{ - asm volatile("cache %0[0], 0x0d" : : "r"(vaddr) : "memory"); -} - -/* - * Invalidate any instruction cacheline containing virtual address - * vaddr. - */ -static inline void icache_invalidate_line(volatile void *vaddr) -{ - asm volatile("cache %0[0], 0x01" : : "r"(vaddr) : "memory"); -} - -/* - * Applies the above functions on all lines that are touched by the - * specified virtual address range. - */ -void dcache_invalidate_range(volatile void *start, size_t len); -void dcache_clean_range(volatile void *start, size_t len); -void dcache_flush_range(volatile void *start, size_t len); -void icache_invalidate_range(volatile void *start, size_t len); - -static inline void dcache_flush_unlocked(void) -{ - asm volatile("cache %0[5], 0x08" : : "r"(0) : "memory"); -} - -/* - * Make sure any pending writes are completed before continuing. - */ -#define sync_write_buffer() asm volatile("sync 0" : : : "memory") - -#endif /* __ASM_AVR32_CACHEFLUSH_H */ diff --git a/include/asm-avr32/dma-mapping.h b/include/asm-avr32/dma-mapping.h index 259f6e8..7e7e9d4 100644 --- a/include/asm-avr32/dma-mapping.h +++ b/include/asm-avr32/dma-mapping.h @@ -23,7 +23,7 @@ #define __ASM_AVR32_DMA_MAPPING_H
#include <asm/io.h> -#include <asm/cacheflush.h> +#include <asm/arch/cacheflush.h>
enum dma_data_direction { DMA_BIDIRECTIONAL = 0, diff --git a/lib_avr32/board.c b/lib_avr32/board.c index d5147b8..216ff74 100644 --- a/lib_avr32/board.c +++ b/lib_avr32/board.c @@ -85,7 +85,7 @@ void *sbrk(ptrdiff_t increment) }
#ifdef CFG_DMA_ALLOC_LEN -#include <asm/cacheflush.h> +#include <asm/arch/cacheflush.h> #include <asm/io.h>
static unsigned long dma_alloc_start;

Dear Olav Morken,
In message 0bc39b76c8da6492c2b2083b8e732d06d3bf13b0.1223643536.git.olavmrk@gmail.com you wrote:
The AT32UC3A series of processors doesn't contain any cache, and issuing cache control instructions on those will cause an exception. This commit makes cacheflush.h arch-dependent in preparation for the AT32UC3A-support.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
board/atmel/atstk1000/flash.c | 2 +- board/earthlcd/favr-32-ezkit/flash.c | 2 +- cpu/at32ap/cache.c | 2 +- include/asm-avr32/arch-at32ap700x/cacheflush.h | 83 ++++++++++++++++++++++++ include/asm-avr32/cacheflush.h | 83 ------------------------
Please provide the patch such that files get renamed, not removed and re-added.
include/asm-avr32/dma-mapping.h | 2 +- lib_avr32/board.c | 2 +- 7 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 include/asm-avr32/arch-at32ap700x/cacheflush.h delete mode 100644 include/asm-avr32/cacheflush.h
Please provide the patch such that files get renamed, not removed and re-added.
Best regards,
Wolfgang Denk

The AVR32A architecture (which AT32UC3A-series is based on) has a different memory layout than the AVR32B-architecture. This patch moves addrspace.h to an arch-dependent directory in preparation for AT32UC3A-support. It also moves some address-space manipulation functions from io.h to addrspace.h.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- include/asm-avr32/addrspace.h | 46 -------------- include/asm-avr32/arch-at32ap700x/addrspace.h | 84 +++++++++++++++++++++++++ include/asm-avr32/io.h | 39 +----------- lib_avr32/bootm.c | 2 +- 4 files changed, 87 insertions(+), 84 deletions(-) delete mode 100644 include/asm-avr32/addrspace.h create mode 100644 include/asm-avr32/arch-at32ap700x/addrspace.h
diff --git a/include/asm-avr32/addrspace.h b/include/asm-avr32/addrspace.h deleted file mode 100644 index b2ba1ee..0000000 --- a/include/asm-avr32/addrspace.h +++ /dev/null @@ -1,46 +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_ADDRSPACE_H -#define __ASM_AVR32_ADDRSPACE_H - -/* Memory segments when segmentation is enabled */ -#define P0SEG 0x00000000 -#define P1SEG 0x80000000 -#define P2SEG 0xa0000000 -#define P3SEG 0xc0000000 -#define P4SEG 0xe0000000 - -/* Returns the privileged segment base of a given address */ -#define PXSEG(a) (((unsigned long)(a)) & 0xe0000000) - -/* Returns the physical address of a PnSEG (n=1,2) address */ -#define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff) - -/* - * Map an address to a certain privileged segment - */ -#define P1SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P1SEG)) -#define P2SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P2SEG)) -#define P3SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG)) -#define P4SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG)) - -#endif /* __ASM_AVR32_ADDRSPACE_H */ diff --git a/include/asm-avr32/arch-at32ap700x/addrspace.h b/include/asm-avr32/arch-at32ap700x/addrspace.h new file mode 100644 index 0000000..49e2467 --- /dev/null +++ b/include/asm-avr32/arch-at32ap700x/addrspace.h @@ -0,0 +1,84 @@ +/* + * 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_ADDRSPACE_H +#define __ASM_AVR32_ADDRSPACE_H + +#include <asm/types.h> + +/* Memory segments when segmentation is enabled */ +#define P0SEG 0x00000000 +#define P1SEG 0x80000000 +#define P2SEG 0xa0000000 +#define P3SEG 0xc0000000 +#define P4SEG 0xe0000000 + +/* Returns the privileged segment base of a given address */ +#define PXSEG(a) (((unsigned long)(a)) & 0xe0000000) + +/* Returns the physical address of a PnSEG (n=1,2) address */ +#define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff) + +/* + * Map an address to a certain privileged segment + */ +#define P1SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P1SEG)) +#define P2SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P2SEG)) +#define P3SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG)) +#define P4SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG)) + +/* virt_to_phys will only work when address is in P1 or P2 */ +static __inline__ unsigned long virt_to_phys(volatile void *address) +{ + return PHYSADDR(address); +} + +static __inline__ void * phys_to_virt(unsigned long address) +{ + return (void *)P1SEGADDR(address); +} + +#define cached(addr) ((void *)P1SEGADDR(addr)) +#define uncached(addr) ((void *)P2SEGADDR(addr)) + +/* + * 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.) + */ +#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); +} + +#endif /* __ASM_AVR32_ADDRSPACE_H */ diff --git a/include/asm-avr32/io.h b/include/asm-avr32/io.h index 06e52b1..1cb17ea 100644 --- a/include/asm-avr32/io.h +++ b/include/asm-avr32/io.h @@ -73,21 +73,8 @@ extern void __readwrite_bug(const char *fn); #define inw(p) ({ unsigned int __v = __le16_to_cpu(__raw_readw(p)); __v; }) #define inl(p) ({ unsigned int __v = __le32_to_cpu(__raw_readl(p)); __v; })
-#include <asm/addrspace.h> - -/* virt_to_phys will only work when address is in P1 or P2 */ -static __inline__ unsigned long virt_to_phys(volatile void *address) -{ - return PHYSADDR(address); -} - -static __inline__ void * phys_to_virt(unsigned long address) -{ - return (void *)P1SEGADDR(address); -} - -#define cached(addr) ((void *)P1SEGADDR(addr)) -#define uncached(addr) ((void *)P2SEGADDR(addr)) +#include <asm/arch/addrspace.h> +/* Provides virt_to_phys, phys_to_virt, cached, uncached, map_physmem */
#endif /* __KERNEL__ */
@@ -96,28 +83,6 @@ 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.) - */ -#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) diff --git a/lib_avr32/bootm.c b/lib_avr32/bootm.c index 35240e2..9f1a817 100644 --- a/lib_avr32/bootm.c +++ b/lib_avr32/bootm.c @@ -24,7 +24,7 @@ #include <image.h> #include <zlib.h> #include <asm/byteorder.h> -#include <asm/addrspace.h> +#include <asm/arch/addrspace.h> #include <asm/io.h> #include <asm/setup.h> #include <asm/arch/clk.h>

Dear Olav Morken,
In message 1e4f0c3bf3b5b62b9294b0b146ec100ded6feb66.1223643536.git.olavmrk@gmail.com you wrote:
The AVR32A architecture (which AT32UC3A-series is based on) has a different memory layout than the AVR32B-architecture. This patch moves addrspace.h to an arch-dependent directory in preparation for AT32UC3A-support. It also moves some address-space manipulation functions from io.h to addrspace.h.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
include/asm-avr32/addrspace.h | 46 -------------- include/asm-avr32/arch-at32ap700x/addrspace.h | 84 +++++++++++++++++++++++++
Please provide the patch such that files get renamed, not removed and re-added.
include/asm-avr32/io.h | 39 +----------- lib_avr32/bootm.c | 2 +- 4 files changed, 87 insertions(+), 84 deletions(-) delete mode 100644 include/asm-avr32/addrspace.h create mode 100644 include/asm-avr32/arch-at32ap700x/addrspace.h
Please provide the patch such that files get renamed, not removed and re-added.
Best regards,
Wolfgang Denk

For 100mbps operation, the ethernet controller requires a 25 MHz clock in MII mode, and a 50 MHz clock in RMII mode. If the clock is slower, disable 100mbps mode.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- drivers/net/macb.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 08bebf7..4fef374 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -296,8 +296,29 @@ static void macb_phy_reset(struct macb_device *macb) struct eth_device *netdev = &macb->netdev; int i; u16 status, adv; + int rmii_mode; + unsigned min_hz; + +#ifdef CONFIG_RMII + rmii_mode = 1; + min_hz = 50000000; +#else + rmii_mode = 0; + min_hz = 25000000; +#endif + + adv = ADVERTISE_CSMA | ADVERTISE_ALL ; + + if (get_hsb_clk_rate() < min_hz) { + printf("%s: HSB clock < %u MHz in %s mode - " + "disabling 100mbit.\n", netdev->name, min_hz / 1000000, + (rmii_mode ? "RMII" : "MII")); + + adv &= ~ADVERTISE_100FULL; + adv &= ~ADVERTISE_100HALF; + adv &= ~ADVERTISE_100BASE4; + }
- adv = ADVERTISE_CSMA | ADVERTISE_ALL; macb_mdio_write(macb, MII_ADVERTISE, adv); printf("%s: Starting autonegotiation...\n", netdev->name); macb_mdio_write(macb, MII_BMCR, (BMCR_ANENABLE

Olav Morken wrote:
For 100mbps operation, the ethernet controller requires a 25 MHz clock in MII mode, and a 50 MHz clock in RMII mode. If the clock is slower, disable 100mbps mode.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
drivers/net/macb.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 08bebf7..4fef374 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -296,8 +296,29 @@ static void macb_phy_reset(struct macb_device *macb) struct eth_device *netdev = &macb->netdev; int i; u16 status, adv;
- int rmii_mode;
- unsigned min_hz;
+#ifdef CONFIG_RMII
- rmii_mode = 1;
- min_hz = 50000000;
+#else
- rmii_mode = 0;
- min_hz = 25000000;
+#endif
- adv = ADVERTISE_CSMA | ADVERTISE_ALL ;
- if (get_hsb_clk_rate() < min_hz) {
printf("%s: HSB clock < %u MHz in %s mode - "
"disabling 100mbit.\n", netdev->name, min_hz / 1000000,
(rmii_mode ? "RMII" : "MII"));
adv &= ~ADVERTISE_100FULL;
adv &= ~ADVERTISE_100HALF;
adv &= ~ADVERTISE_100BASE4;
- }
- adv = ADVERTISE_CSMA | ADVERTISE_ALL; macb_mdio_write(macb, MII_ADVERTISE, adv); printf("%s: Starting autonegotiation...\n", netdev->name); macb_mdio_write(macb, MII_BMCR, (BMCR_ANENABLE
Applied to net/testing.
regards, Ben

Dear Ben Warren,
In message 48F82A0C.9030505@gmail.com you wrote:
Applied to net/testing.
Please see previous review comment.
Best regards,
Wolfgang Denk

Dear Olav Morken,
In message 09189b13a9a10f413f4f12395032140345592cf3.1223643536.git.olavmrk@gmail.com you wrote:
For 100mbps operation, the ethernet controller requires a 25 MHz clock in MII mode, and a 50 MHz clock in RMII mode. If the clock is slower, disable 100mbps mode.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
drivers/net/macb.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 08bebf7..4fef374 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -296,8 +296,29 @@ static void macb_phy_reset(struct macb_device *macb) struct eth_device *netdev = &macb->netdev; int i; u16 status, adv;
- int rmii_mode;
- unsigned min_hz;
+#ifdef CONFIG_RMII
- rmii_mode = 1;
- min_hz = 50000000;
+#else
- rmii_mode = 0;
- min_hz = 25000000;
+#endif
- adv = ADVERTISE_CSMA | ADVERTISE_ALL ;
- if (get_hsb_clk_rate() < min_hz) {
printf("%s: HSB clock < %u MHz in %s mode - "
"disabling 100mbit.\n", netdev->name, min_hz / 1000000,
Use str_mhz() to round and print the frequency. And please use "Mbit/s" or "Mbps" instead of "mbit". See http://en.wikipedia.org/wiki/Mbps#Megabit_per_second
Best regards,
Wolfgang Denk

This patch adds support for searching through available PHY-addresses in the macb-driver. This is needed for the ATEVK1100 evaluation board, where the PHY-address will be initialized to either 1 or 7.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- drivers/net/macb.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 4fef374..561669b 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -338,6 +338,27 @@ static void macb_phy_reset(struct macb_device *macb) netdev->name, status); }
+static int macb_phy_find(struct macb_device *macb) +{ + int i; + u16 phy_id; + + /* Search for PHY... */ + for (i = 0; i < 32; i++) { + macb->phy_addr=i; + phy_id = macb_mdio_read(macb, MII_PHYSID1); + if (phy_id != 0xffff) { + printf("%s: PHY present at %d\n", macb->netdev.name, i); + return 1; + } + } + + /* PHY isn't up to snuff */ + printf("%s: PHY not found", macb->netdev.name); + + return 0; +} + static int macb_phy_init(struct macb_device *macb) { struct eth_device *netdev = &macb->netdev; @@ -346,6 +367,13 @@ static int macb_phy_init(struct macb_device *macb) int media, speed, duplex; int i;
+ if (macb->phy_addr == 0xff) { + /* Auto-detect phy_addr */ + if (!macb_phy_find(macb)) { + return 0; + } + } + /* Check if the PHY is up to snuff... */ phy_id = macb_mdio_read(macb, MII_PHYSID1); if (phy_id == 0xffff) {

Olav Morken wrote:
This patch adds support for searching through available PHY-addresses in the macb-driver. This is needed for the ATEVK1100 evaluation board, where the PHY-address will be initialized to either 1 or 7.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
drivers/net/macb.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 4fef374..561669b 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -338,6 +338,27 @@ static void macb_phy_reset(struct macb_device *macb) netdev->name, status); }
+static int macb_phy_find(struct macb_device *macb) +{
- int i;
- u16 phy_id;
- /* Search for PHY... */
- for (i = 0; i < 32; i++) {
macb->phy_addr=i;
phy_id = macb_mdio_read(macb, MII_PHYSID1);
if (phy_id != 0xffff) {
printf("%s: PHY present at %d\n", macb->netdev.name, i);
return 1;
}
- }
- /* PHY isn't up to snuff */
- printf("%s: PHY not found", macb->netdev.name);
- return 0;
+}
static int macb_phy_init(struct macb_device *macb) { struct eth_device *netdev = &macb->netdev; @@ -346,6 +367,13 @@ static int macb_phy_init(struct macb_device *macb) int media, speed, duplex; int i;
- if (macb->phy_addr == 0xff) {
/* Auto-detect phy_addr */
if (!macb_phy_find(macb)) {
return 0;
}
- }
- /* Check if the PHY is up to snuff... */ phy_id = macb_mdio_read(macb, MII_PHYSID1); if (phy_id == 0xffff) {
Applied to net/testing.
regards, Ben

Due to a bug with the SDRAM-controller, running code from the SDRAM is impossible. This patch disables relocation of the command table on those chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- lib_avr32/board.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib_avr32/board.c b/lib_avr32/board.c index 216ff74..6afa8bd 100644 --- a/lib_avr32/board.c +++ b/lib_avr32/board.c @@ -294,8 +294,13 @@ void board_init_r(gd_t *new_gd, ulong dest_addr) cmdtp != &__u_boot_cmd_end; cmdtp++) { unsigned long addr;
+ /* We don't relocate code in the at32uc3a0xxx cpu yet due to + * SDRAM bug. See errata 41.4.6.1. + */ +#ifndef CONFIG_AT32UC addr = (unsigned long)cmdtp->cmd + gd->reloc_off; cmdtp->cmd = (typeof(cmdtp->cmd))addr; +#endif
addr = (unsigned long)cmdtp->name + gd->reloc_off; cmdtp->name = (typeof(cmdtp->name))addr;

Dear Olav Morken,
In message 40c18deab5b9c9892cb9f66029058d8f7de20f3f.1223643536.git.olavmrk@gmail.com you wrote:
Due to a bug with the SDRAM-controller, running code from the SDRAM is impossible. This patch disables relocation of the command table on those chips.
You are aware that this is dangerous, as it will probably prevent you rom using U-Boot to update itself in flash?
Best regards,
Wolfgang Denk

Wolfgang Denk wd@denx.de wrote:
In message 40c18deab5b9c9892cb9f66029058d8f7de20f3f.1223643536.git.olavmrk@gmail.com you wrote:
Due to a bug with the SDRAM-controller, running code from the SDRAM is impossible. This patch disables relocation of the command table on those chips.
You are aware that this is dangerous, as it will probably prevent you rom using U-Boot to update itself in flash?
It's only a temporary thing. A patch has already been posted to re-enable relocation when running from SRAM.
Eventually, when chips without this erratum have been generally available for a while, relocation can be enabled unconditionally.
Haavard

The AT32UC3A0512ES chip has a bug when disabling interrupts. As a workaround, two NOPs can be inserted.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- lib_avr32/interrupts.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib_avr32/interrupts.c b/lib_avr32/interrupts.c index 28df20d..bbbc490 100644 --- a/lib_avr32/interrupts.c +++ b/lib_avr32/interrupts.c @@ -35,5 +35,12 @@ int disable_interrupts(void) sr = sysreg_read(SR); asm volatile("ssrf %0" : : "n"(SYSREG_GM_OFFSET));
+#ifdef CONFIG_AT32UC3A0xxx + /* Two NOPs are required after masking interrupts on the + * AT32UC3A0512ES. See errata 41.4.5.5. */ + asm("nop"); + asm("nop"); +#endif + return !SYSREG_BFEXT(GM, sr); }

This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- cpu/at32uc/Makefile | 56 ++++ cpu/at32uc/at32uc3a0xxx/Makefile | 43 +++ cpu/at32uc/at32uc3a0xxx/clk.c | 85 ++++++ cpu/at32uc/at32uc3a0xxx/portmux.c | 154 +++++++++++ cpu/at32uc/at32uc3a0xxx/sm.h | 272 ++++++++++++++++++++ cpu/at32uc/cache.c | 34 +++ cpu/at32uc/config.mk | 22 ++ cpu/at32uc/cpu.c | 79 ++++++ cpu/at32uc/exception.c | 121 +++++++++ cpu/at32uc/flashc.c | 80 ++++++ cpu/at32uc/flashc.h | 67 +++++ cpu/at32uc/interrupts.c | 150 +++++++++++ cpu/at32uc/portmux-gpio.c | 108 ++++++++ cpu/at32uc/sdramc.c | 120 +++++++++ cpu/at32uc/sdramc.h | 137 ++++++++++ cpu/at32uc/start.S | 265 +++++++++++++++++++ include/asm-avr32/arch-at32uc3a0xxx/addrspace.h | 63 +++++ include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h | 41 +++ .../asm-avr32/arch-at32uc3a0xxx/chip-features.h | 30 +++ include/asm-avr32/arch-at32uc3a0xxx/clk.h | 86 ++++++ include/asm-avr32/arch-at32uc3a0xxx/gpio.h | 44 ++++ include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h | 47 ++++ include/asm-avr32/arch-at32uc3a0xxx/memory-map.h | 75 ++++++ include/asm-avr32/arch-at32uc3a0xxx/portmux.h | 80 ++++++ 24 files changed, 2259 insertions(+), 0 deletions(-) create mode 100644 cpu/at32uc/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/clk.c create mode 100644 cpu/at32uc/at32uc3a0xxx/portmux.c create mode 100644 cpu/at32uc/at32uc3a0xxx/sm.h create mode 100644 cpu/at32uc/cache.c create mode 100644 cpu/at32uc/config.mk create mode 100644 cpu/at32uc/cpu.c create mode 100644 cpu/at32uc/exception.c create mode 100644 cpu/at32uc/flashc.c create mode 100644 cpu/at32uc/flashc.h create mode 100644 cpu/at32uc/interrupts.c create mode 100644 cpu/at32uc/portmux-gpio.c create mode 100644 cpu/at32uc/sdramc.c create mode 100644 cpu/at32uc/sdramc.h create mode 100644 cpu/at32uc/start.S create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/addrspace.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/chip-features.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/clk.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/gpio.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/memory-map.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/portmux.h
diff --git a/cpu/at32uc/Makefile b/cpu/at32uc/Makefile new file mode 100644 index 0000000..cab9bdc --- /dev/null +++ b/cpu/at32uc/Makefile @@ -0,0 +1,56 @@ +# +# (C) Copyright 2000-2006 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# 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$(CPU).a + +START-y += start.o + +COBJS-y += cpu.o +COBJS-y += sdramc.o +COBJS-y += exception.o +COBJS-y += cache.o +COBJS-y += interrupts.o +COBJS-$(CONFIG_PORTMUX_GPIO) += portmux-gpio.o +COBJS-y += flashc.o + +SRCS := $(START-y:.o=.S) $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(SOBJS-y) $(COBJS-y)) +START := $(addprefix $(obj),$(START-y)) + +all: $(obj).depend $(START) $(LIB) + +$(LIB): $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/cpu/at32uc/at32uc3a0xxx/Makefile b/cpu/at32uc/at32uc3a0xxx/Makefile new file mode 100644 index 0000000..4942e56 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/Makefile @@ -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 := clk.o portmux.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/at32uc/at32uc3a0xxx/clk.c b/cpu/at32uc/at32uc3a0xxx/clk.c new file mode 100644 index 0000000..7c66b94 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/clk.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2005-2008 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/io.h> + +#include <asm/arch/clk.h> +#include <asm/arch/memory-map.h> + +#include "sm.h" + +void clk_init(void) +{ + uint32_t cksel; + + /* in case of soft resets, disable watchdog */ + sm_writel(WDT_CTRL, SM_BF(KEY, 0x55)); + sm_writel(WDT_CTRL, SM_BF(KEY, 0xaa)); + + /* osc0 is 12mhz (Mode 7)*/ + sm_writel(PM_OSCCTRL0, (SM_BF(MODE, 7)|SM_BF(STARTUP, 1))); + + /* enable osc0 */ + sm_writel(PM_MCCTRL, SM_BIT(OSC0EN)); + + /* wait for osc0 */ + while (!(sm_readl(PM_POSCSR) & SM_BIT(OSC0RDY))) ; + + /* run from osc0 */ + sm_writel(PM_MCCTRL, SM_BF(MCSEL, 1) | SM_BIT(OSC0EN)); + +#ifdef CONFIG_PLL + /* Initialize the PLL */ + sm_writel(PM_PLL0, (SM_BF(PLLCOUNT, CFG_PLL0_SUPPRESS_CYCLES) + | SM_BF(PLLMUL, CFG_PLL0_MUL - 1) + | SM_BF(PLLDIV, CFG_PLL0_DIV) + | SM_BF(PLLOPT, CFG_PLL0_OPT) + | SM_BF(PLLOSC, 0) + | SM_BIT(PLLEN) + | SM_BIT(ERRATA))); + + /* Wait for lock */ + while (!(sm_readl(PM_POSCSR) & SM_BIT(LOCK0))) ; +#endif + + /* We cannot write the CKSEL register before the ready-signal is set. */ + while (!(sm_readl(PM_POSCSR) & SM_BIT(CKRDY))) ; + + /* Set up clocks for the CPU and all peripheral buses */ + cksel = 0; + if (CFG_CLKDIV_CPU) + cksel |= SM_BIT(CPUDIV) | SM_BF(CPUSEL, CFG_CLKDIV_CPU - 1); + if (CFG_CLKDIV_PBA) + cksel |= SM_BIT(PBADIV) | SM_BF(PBASEL, CFG_CLKDIV_PBA - 1); + if (CFG_CLKDIV_PBB) + cksel |= SM_BIT(PBBDIV) | SM_BF(PBBSEL, CFG_CLKDIV_PBB - 1); + + + sm_writel(PM_CKSEL, cksel); + +#ifdef CONFIG_PLL + /* Use PLL0 as main clock */ + sm_writel(PM_MCCTRL, SM_BF(MCSEL, 2) | SM_BIT(OSC0EN)); +#endif + +} diff --git a/cpu/at32uc/at32uc3a0xxx/portmux.c b/cpu/at32uc/at32uc3a0xxx/portmux.c new file mode 100644 index 0000000..a796f22 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/portmux.c @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2006, 2008 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/io.h> + +#include <asm/arch/chip-features.h> +#include <asm/arch/memory-map.h> +#include <asm/arch/portmux.h> + +/* + * Lots of small functions here. We depend on --gc-sections getting + * rid of the ones we don't need. + */ +void portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width, + unsigned long flags, unsigned long drive_strength) +{ + /* + * GPIO pins to be set to enable all EBI pins + * + * PIN 14-17 function C port0 mask 00 03 C0 00 + * PIN 25-28 function C port0 mask 1E 00 00 00 + * PIN 36 function C port1 mask 00 00 00 10 + * PIN 42-46 function C port1 mask 00 00 7C 00 + * PIN 48-49 function C port1 mask 00 03 00 00 + * PIN 61-63 function C port1 mask E0 00 00 00 + * PIN 70-95 function A port2 mask FF FF FF C0 + * PIN 96-109 function A port3 mask 00 00 3F FF + */ + + portmux_select_peripheral(PORTMUX_PORT(0), + 0x0003C000 | + 0x1E000000, PORTMUX_FUNC_C, 0); + portmux_select_peripheral(PORTMUX_PORT(1), + 0x00000010 | + 0x00007C00 | + 0x00030000 | + 0xE0000000, PORTMUX_FUNC_C, 0); + portmux_select_peripheral(PORTMUX_PORT(2), + 0xFFFFFFC0, PORTMUX_FUNC_A, 0); + portmux_select_peripheral(PORTMUX_PORT(3), + 0x00003FFF, PORTMUX_FUNC_A, 0); +} + +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +void portmux_enable_macb(unsigned long flags, unsigned long drive_strength) +{ + unsigned long portb_mask; + + portb_mask = (1 << 2) /* TXD0 */ + | (1 << 3) /* TXD1 */ + | (1 << 1) /* TXEN */ + | (1 << 0) /* TXCK */ + | (1 << 5) /* RXD0 */ + | (1 << 6) /* RXD1 */ + | (1 << 7) /* RXER */ + | (1 << 15) /* RXDV */ + | (1 << 8) /* MDC */ + | (1 << 9); /* MDIO */ + + if (flags & PORTMUX_MACB_MII) + portb_mask |= (1 << 16) /* COL */ + | (1 << 4) /* CRS */ + | (1 << 12) /* TXER */ + | (1 << 10) /* TXD2 */ + | (1 << 11) /* TXD3 */ + | (1 << 13) /* RXD2 */ + | (1 << 14) /* RXD3 */ + | (1 << 17); /* RXCK */ + + if (flags & PORTMUX_MACB_SPEED) + portb_mask |= (1 << 18);/* SPD */ + + /* REVISIT: Some pins are probably pure outputs */ + portmux_select_peripheral(PORTMUX_PORT_B, portb_mask, + PORTMUX_FUNC_A, PORTMUX_BUSKEEPER); +} + +#endif + + +#ifdef AT32UC3A0xxx_CHIP_HAS_SPI +void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength) +{ + unsigned long pin_mask; + + /* MOSI and SCK */ + portmux_select_peripheral(PORTMUX_PORT_A, (1 << 12) | (1 << 13), + PORTMUX_FUNC_A, 0); + /* MISO may float */ + portmux_select_peripheral(PORTMUX_PORT_A, 1 << 11, + PORTMUX_FUNC_A, PORTMUX_BUSKEEPER); + + /* Set up NPCSx as GPIO outputs, initially high */ + pin_mask = 0; + if (cs_mask & (1 << 0)) + pin_mask |= 1 << 10; + if (cs_mask & (1 << 1)) + pin_mask |= 1 << 8; + if (cs_mask & (1 << 2)) + pin_mask |= 1 << 9; + if (cs_mask & (1 << 3)) + pin_mask |= 1 << 7; + + portmux_select_gpio(PORTMUX_PORT_A, pin_mask, + PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH); +} + +void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength) +{ + unsigned long pin_mask; + + /* MOSI and SCK */ + portmux_select_peripheral(PORTMUX_PORT_B, (1 << 16) | (1 << 15), + PORTMUX_FUNC_B, 0); + /* MISO may float */ + portmux_select_peripheral(PORTMUX_PORT_B, 1 << 17, + PORTMUX_FUNC_B, PORTMUX_BUSKEEPER); + + /* Set up NPCSx as GPIO outputs, initially high */ + pin_mask = 0; + if (cs_mask & (1 << 0)) + pin_mask |= 1 << 14; + if (cs_mask & (1 << 1)) + pin_mask |= 1 << 18; + if (cs_mask & (1 << 2)) + pin_mask |= 1 << 19; + if (cs_mask & (1 << 3)) + pin_mask |= 1 << 20; + + portmux_select_gpio(PORTMUX_PORT_A, pin_mask, + PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH); +} +#endif + diff --git a/cpu/at32uc/at32uc3a0xxx/sm.h b/cpu/at32uc/at32uc3a0xxx/sm.h new file mode 100644 index 0000000..d232f91 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/sm.h @@ -0,0 +1,272 @@ +/* + * Register definitions for System Manager + */ +#ifndef __CPU_AT32UC_SM_H__ +#define __CPU_AT32UC_SM_H__ + +/* SM register offsets */ +/* PM starts at 0xFFFF0C00 */ +#define SM_PM_REGS_OFFSET 0x0c00 +#define SM_PM_MCCTRL (SM_PM_REGS_OFFSET + 0x0000) +#define SM_PM_CKSEL (SM_PM_REGS_OFFSET + 0x0004) +#define SM_PM_CPU_MASK (SM_PM_REGS_OFFSET + 0x0008) +#define SM_PM_HSB_MASK (SM_PM_REGS_OFFSET + 0x000c) +#define SM_PM_PBA_MASK (SM_PM_REGS_OFFSET + 0x0010) +#define SM_PM_PBB_MASK (SM_PM_REGS_OFFSET + 0x0014) +#define SM_PM_PLL0 (SM_PM_REGS_OFFSET + 0x0020) +#define SM_PM_PLL1 (SM_PM_REGS_OFFSET + 0x0024) +#define SM_PM_OSCCTRL0 (SM_PM_REGS_OFFSET + 0x0028) +#define SM_PM_OSCCTRL1 (SM_PM_REGS_OFFSET + 0x002c) +#define SM_PM_OSCCTRL32 (SM_PM_REGS_OFFSET + 0x0030) +#define SM_PM_IER (SM_PM_REGS_OFFSET + 0x0040) +#define SM_PM_IDR (SM_PM_REGS_OFFSET + 0x0044) +#define SM_PM_IMR (SM_PM_REGS_OFFSET + 0x0048) +#define SM_PM_ISR (SM_PM_REGS_OFFSET + 0x004c) +#define SM_PM_ICR (SM_PM_REGS_OFFSET + 0x0050) +#define SM_PM_POSCSR (SM_PM_REGS_OFFSET + 0x0054) +#define SM_PM_GCCTRL (SM_PM_REGS_OFFSET + 0x0060) +#define SM_PM_RCCR (SM_PM_REGS_OFFSET + 0x00c0) +#define SM_PM_BGCR (SM_PM_REGS_OFFSET + 0x00c4) +#define SM_PM_VREGCR (SM_PM_REGS_OFFSET + 0x00c8) +#define SM_PM_BOD (SM_PM_REGS_OFFSET + 0x00d0) +#define SM_PM_RCAUSE (SM_PM_REGS_OFFSET + 0x0140) +#define SM_RC_RCAUSE SM_PM_RCAUSE /* TODO: remove */ +/* RTC starts at 0xFFFF0D00 */ +#define SM_RTC_REGS_OFFSET 0x0d00 +#define SM_RTC_CTRL (SM_RTC_REGS_OFFSET + 0x0000) +#define SM_RTC_VAL (SM_RTC_REGS_OFFSET + 0x0004) +#define SM_RTC_TOP (SM_RTC_REGS_OFFSET + 0x0008) +#define SM_RTC_IER (SM_RTC_REGS_OFFSET + 0x0010) +#define SM_RTC_IDR (SM_RTC_REGS_OFFSET + 0x0014) +#define SM_RTC_IMR (SM_RTC_REGS_OFFSET + 0x0018) +#define SM_RTC_ISR (SM_RTC_REGS_OFFSET + 0x001c) +#define SM_RTC_ICR (SM_RTC_REGS_OFFSET + 0x0020) +/* WDT starts at 0xFFFF0D30 */ +#define SM_WDT_REGS_OFFSET 0x0d30 +#define SM_WDT_CTRL (SM_WDT_REGS_OFFSET + 0x0000) +#define SM_WDT_CLR (SM_WDT_REGS_OFFSET + 0x0004) +#define SM_WDT_EXT (SM_WDT_REGS_OFFSET + 0x0008) /* TODO: does not exist ? */ +/* EIC starts at offset 0xFFFF0D80 */ +/* TODO: change EIM to EIC */ +#define SM_EIC_REGS_OFFSET 0x0d80 +#define SM_EIM_IER (SM_EIC_REGS_OFFSET + 0x0000) +#define SM_EIM_IDR (SM_EIC_REGS_OFFSET + 0x0004) +#define SM_EIM_IMR (SM_EIC_REGS_OFFSET + 0x0008) +#define SM_EIM_ISR (SM_EIC_REGS_OFFSET + 0x000c) +#define SM_EIM_ICR (SM_EIC_REGS_OFFSET + 0x0010) +#define SM_EIM_MODE (SM_EIC_REGS_OFFSET + 0x0014) +#define SM_EIM_EDGE (SM_EIC_REGS_OFFSET + 0x0018) +#define SM_EIM_LEVEL (SM_EIC_REGS_OFFSET + 0x001c) +#define SM_EIM_FILTER (SM_EIC_REGS_OFFSET + 0x0020) +#define SM_EIM_TEST (SM_EIC_REGS_OFFSET + 0x0024) +#define SM_EIM_ASYNC (SM_EIC_REGS_OFFSET + 0x0028) +#define SM_EIM_SCAN (SM_EIC_REGS_OFFSET + 0x002c) +#define SM_EIM_EN (SM_EIC_REGS_OFFSET + 0x0030) +#define SM_EIM_DIS (SM_EIC_REGS_OFFSET + 0x0034) +#define SM_EIM_CTRL (SM_EIC_REGS_OFFSET + 0x0038) + +/* Bitfields used in many registers */ +#define SM_EN_OFFSET 0 +#define SM_EN_SIZE 1 + +/* Bitfields in PM_MCCTRL */ +#define SM_MCSEL_OFFSET 0 +#define SM_MCSEL_SIZE 2 +#define SM_OSC0EN_OFFSET 2 +#define SM_OSC0EN_SIZE 1 +#define SM_OSC1EN_OFFSET 3 +#define SM_OSC1EN_SIZE 1 + +/* Bitfields in PM_CKSEL */ +#define SM_CPUSEL_OFFSET 0 +#define SM_CPUSEL_SIZE 3 +#define SM_CPUDIV_OFFSET 7 +#define SM_CPUDIV_SIZE 1 +#define SM_HSBSEL_OFFSET 8 +#define SM_HSBSEL_SIZE 3 +#define SM_HSBDIV_OFFSET 15 +#define SM_HSBDIV_SIZE 1 +#define SM_PBASEL_OFFSET 16 +#define SM_PBASEL_SIZE 3 +#define SM_PBADIV_OFFSET 23 +#define SM_PBADIV_SIZE 1 +#define SM_PBBSEL_OFFSET 24 +#define SM_PBBSEL_SIZE 3 +#define SM_PBBDIV_OFFSET 31 +#define SM_PBBDIV_SIZE 1 + +/* Bitfields in PM_PLL0 */ +#define SM_PLLEN_OFFSET 0 +#define SM_PLLEN_SIZE 1 +#define SM_PLLOSC_OFFSET 1 +#define SM_PLLOSC_SIZE 1 +#define SM_PLLOPT_OFFSET 2 +#define SM_PLLOPT_SIZE 3 +#define SM_ERRATA_OFFSET 7 +#define SM_ERRATA_SIZE 1 +#define SM_PLLDIV_OFFSET 8 +#define SM_PLLDIV_SIZE 4 +#define SM_PLLMUL_OFFSET 16 +#define SM_PLLMUL_SIZE 4 +#define SM_PLLCOUNT_OFFSET 24 +#define SM_PLLCOUNT_SIZE 6 +#define SM_PLLTEST_OFFSET 31 /* TODO: remove */ +#define SM_PLLTEST_SIZE 1 /* TODO: remove */ + +/* Bitfields in PM_OSCCTRL0,1 */ +#define SM_MODE_OFFSET 0 +#define SM_MODE_SIZE 3 +#define SM_STARTUP_OFFSET 8 +#define SM_STARTUP_SIZE 3 + +/* Bitfields in PM_VCTRL */ +#define SM_VAUTO_OFFSET 0 /* TODO: remove */ +#define SM_VAUTO_SIZE 1 /* TODO: remove */ +#define SM_PM_VCTRL_VAL_OFFSET 8 /* TODO: remove */ +#define SM_PM_VCTRL_VAL_SIZE 7 /* TODO: remove */ + +/* Bitfields in PM_VMREF */ +#define SM_REFSEL_OFFSET 0 /* TODO: remove */ +#define SM_REFSEL_SIZE 4 /* TODO: remove */ + +/* Bitfields in PM_VMV */ +#define SM_PM_VMV_VAL_OFFSET 0 /* TODO: remove */ +#define SM_PM_VMV_VAL_SIZE 8 /* TODO: remove */ + +/* Bitfields in PM_IER/IDR/IMR/ISR/ICR, POSCSR */ +#define SM_LOCK0_OFFSET 0 +#define SM_LOCK0_SIZE 1 +#define SM_LOCK1_OFFSET 1 +#define SM_LOCK1_SIZE 1 +#define SM_WAKE_OFFSET 2 /* TODO: remove */ +#define SM_WAKE_SIZE 1 /* TODO: remove */ +#define SM_VOK_OFFSET 3 /* TODO: remove */ +#define SM_VOK_SIZE 1 /* TODO: remove */ +#define SM_VMRDY_OFFSET 4 /* TODO: remove */ +#define SM_VMRDY_SIZE 1 /* TODO: remove */ +#define SM_CKRDY_OFFSET 5 +#define SM_CKRDY_SIZE 1 +#define SM_MSKRDY_OFFSET 6 +#define SM_MSKRDY_SIZE 1 +#define SM_OSC0RDY_OFFSET 7 +#define SM_OSC0RDY_SIZE 1 +#define SM_OSC1RDY_OFFSET 8 +#define SM_OSC1RDY_SIZE 1 +#define SM_OSC32RDY_OFFSET 9 +#define SM_OSC32RDY_SIZE 1 +#define SM_BODDET_OFFSET 16 +#define SM_BODDET_SIZE 1 + +/* Bitfields in PM_GCCTRL*/ +#define SM_OSCSEL_OFFSET 0 +#define SM_OSCSEL_SIZE 1 +#define SM_PLLSEL_OFFSET 1 +#define SM_PLLSEL_SIZE 1 +#define SM_CEN_OFFSET 2 +#define SM_CEN_SIZE 1 +#define SM_DIVEN_OFFSET 4 +#define SM_DIVEN_SIZE 1 +#define SM_DIV_OFFSET 8 +#define SM_DIV_SIZE 8 + +/* Bitfields in PM_RCAUSE */ +#define SM_POR_OFFSET 0 +#define SM_POR_SIZE 1 +#define SM_BOD_OFFSET 1 +#define SM_BOD_SIZE 1 +#define SM_EXT_OFFSET 2 +#define SM_EXT_SIZE 1 +#define SM_WDT_OFFSET 3 +#define SM_WDT_SIZE 1 +#define SM_JTAG_OFFSET 4 +#define SM_JTAG_SIZE 1 +#define SM_SERP_OFFSET 5 /* TODO: remove */ +#define SM_SERP_SIZE 1 /* TODO: remove */ +#define SM_CPUERR_OFFSET 7 +#define SM_CPUERR_SIZE 1 +#define SM_OCDRST_OFFSET 8 +#define SM_OCDRST_SIZE 1 +#define SM_JTAGHARD_OFFSET 9 +#define SM_JTAGHARD_SIZE 1 + + +/* Bitfields in RTC_CTRL */ +#define SM_PCLR_OFFSET 1 +#define SM_PCLR_SIZE 1 +#define SM_WAKE_EN_OFFSET 2 +#define SM_WAKE_EN_SIZE 1 +#define SM_CLK32_OFFSET 3 +#define SM_CLK32_SIZE 1 +#define SM_BUSY_OFFSET 4 +#define SM_BUSY_SIZE 1 +#define SM_RTC_CTRL_PSEL_OFFSET 8 +#define SM_RTC_CTRL_PSEL_SIZE 4 +#define SM_CLKEN_OFFSET 16 +#define SM_CLKEN_SIZE 1 + +/* Bitfields in RTC_VAL */ +#define SM_RTC_VAL_VAL_OFFSET 0 +#define SM_RTC_VAL_VAL_SIZE 32 + +/* Bitfields in RTC_TOP */ +#define SM_RTC_TOP_VAL_OFFSET 0 +#define SM_RTC_TOP_VAL_SIZE 32 + +/* Bitfields in RTC_ICR */ +#define SM_TOPI_OFFSET 0 +#define SM_TOPI_SIZE 1 + + +/* Bitfields in WDT_CTRL */ +#define SM_WDT_CTRL_PSEL_OFFSET 8 +#define SM_WDT_CTRL_PSEL_SIZE 5 +#define SM_KEY_OFFSET 24 +#define SM_KEY_SIZE 8 + + +/* Bitfields in EIC IER/IDR/IMR/ISR/ICR and MODE/EDGE/LEVEL/FILTER/ASYNC */ +#define SM_INT0_OFFSET 0 +#define SM_INT0_SIZE 1 +#define SM_INT1_OFFSET 1 +#define SM_INT1_SIZE 1 +#define SM_INT2_OFFSET 2 +#define SM_INT2_SIZE 1 +#define SM_INT3_OFFSET 3 +#define SM_INT3_SIZE 1 +#define SM_INT4_OFFSET 4 +#define SM_INT4_SIZE 1 +#define SM_INT5_OFFSET 5 +#define SM_INT5_SIZE 1 +#define SM_INT6_OFFSET 6 +#define SM_INT6_SIZE 1 +#define SM_INT7_OFFSET 7 +#define SM_INT7_SIZE 1 +#define SM_NMI_OFFSET 8 +#define SM_NMI_SIZE 1 + +/* Bitfields in EIM_TEST */ +#define SM_TESTEN_OFFSET 31 +#define SM_TESTEN_SIZE 1 + + +/* Bit manipulation macros */ +#define SM_BIT(name) \ + (1 << SM_##name##_OFFSET) +#define SM_BF(name,value) \ + (((value) & ((1 << SM_##name##_SIZE) - 1)) \ + << SM_##name##_OFFSET) +#define SM_BFEXT(name,value) \ + (((value) >> SM_##name##_OFFSET) \ + & ((1 << SM_##name##_SIZE) - 1)) +#define SM_BFINS(name,value,old) \ + (((old) & ~(((1 << SM_##name##_SIZE) - 1) \ + << SM_##name##_OFFSET)) \ + | SM_BF(name,value)) + +/* Register access macros */ +#define sm_readl(reg) \ + readl((void *)SM_BASE + SM_##reg) +#define sm_writel(reg,value) \ + writel((value), (void *)SM_BASE + SM_##reg) + +#endif /* __CPU_AT32UC_SM_H__ */ diff --git a/cpu/at32uc/cache.c b/cpu/at32uc/cache.c new file mode 100644 index 0000000..06fa12c --- /dev/null +++ b/cpu/at32uc/cache.c @@ -0,0 +1,34 @@ +/* + * 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 + */ + +#include <common.h> + +/* + * This is called after loading something into memory. We need to + * make sure that everything that was loaded is actually written to + * RAM, and that the icache will look for it. Cleaning the dcache and + * invalidating the icache will do the trick. + */ +void flush_cache (unsigned long start_addr, unsigned long size) +{ + /* No cache to clean in the at32uc3. */ +} diff --git a/cpu/at32uc/config.mk b/cpu/at32uc/config.mk new file mode 100644 index 0000000..1a6eaa8 --- /dev/null +++ b/cpu/at32uc/config.mk @@ -0,0 +1,22 @@ +# +# 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 +# +PLATFORM_RELFLAGS += -mcpu=uc3a0512es diff --git a/cpu/at32uc/cpu.c b/cpu/at32uc/cpu.c new file mode 100644 index 0000000..4a95427 --- /dev/null +++ b/cpu/at32uc/cpu.c @@ -0,0 +1,79 @@ +/* + * 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 <common.h> +#include <command.h> + +#include <asm/io.h> +#include <asm/sections.h> +#include <asm/sysreg.h> + +#include <asm/arch/clk.h> +#include <asm/arch/memory-map.h> + +/* Sanity checks */ +#if ((CFG_CLKDIV_CPU > CFG_CLKDIV_PBA) \ + || (CFG_CLKDIV_CPU > CFG_CLKDIV_PBB)) +# error Constraint fCPU >= fPB{A,B} violated +#endif +#if defined(CONFIG_PLL) && ((CFG_PLL0_MUL < 1) || (CFG_PLL0_DIV < 0)) +# error Invalid PLL multiplier and/or divider +#endif + +DECLARE_GLOBAL_DATA_PTR; + +int cpu_init(void) +{ + extern void _evba(void); + + gd->cpu_hz = CFG_OSC0_HZ; + + clk_init(); + + /* Update the CPU speed according to the PLL configuration */ + gd->cpu_hz = get_cpu_clk_rate(); + + /* Set up the exception handler table and enable exceptions */ + sysreg_write(EVBA, (unsigned long)&_evba); + asm volatile("csrf %0" : : "i"(SYSREG_EM_OFFSET)); + + if(gclk_init) + gclk_init(); + + return 0; +} + +void prepare_to_boot(void) +{ + /* No caches to flush on this cpu. */ +} + +int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + /* This will reset the CPU core, caches, MMU and all internal busses */ + __builtin_mtdr(8, 1 << 13); /* set DC:DBE */ + __builtin_mtdr(8, 1 << 30); /* set DC:RES */ + + /* Flush the pipeline before we declare it a failure */ + asm volatile("sub pc, pc, -4"); + + return -1; +} diff --git a/cpu/at32uc/exception.c b/cpu/at32uc/exception.c new file mode 100644 index 0000000..dc9c300 --- /dev/null +++ b/cpu/at32uc/exception.c @@ -0,0 +1,121 @@ +/* + * 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 <common.h> + +#include <asm/sysreg.h> +#include <asm/ptrace.h> + +DECLARE_GLOBAL_DATA_PTR; + +static const char * const cpu_modes[8] = { + "Application", "Supervisor", "Interrupt level 0", "Interrupt level 1", + "Interrupt level 2", "Interrupt level 3", "Exception", "NMI" +}; + +static void dump_mem(const char *str, unsigned long bottom, unsigned long top) +{ + unsigned long p; + int i; + + printf("%s(0x%08lx to 0x%08lx)\n", str, bottom, top); + + for (p = bottom & ~31; p < top; ) { + printf("%04lx: ", p & 0xffff); + + for (i = 0; i < 8; i++, p += 4) { + unsigned int val; + + if (p < bottom || p >= top) + printf(" "); + else { + val = *(unsigned long *)p; + printf("%08x ", val); + } + } + printf("\n"); + } +} + +void do_unknown_exception(unsigned int ecr, struct pt_regs *regs) +{ + unsigned int mode; + + printf("\n *** Unhandled exception %u at PC=0x%08lx\n", ecr, regs->pc); + + switch (ecr) { + case ECR_BUS_ERROR_WRITE: + case ECR_BUS_ERROR_READ: + printf("Bus error at address 0x%08lx\n", + sysreg_read(BEAR)); + break; + case ECR_TLB_MULTIPLE: + case ECR_ADDR_ALIGN_X: + case ECR_PROTECTION_X: + case ECR_ADDR_ALIGN_R: + case ECR_ADDR_ALIGN_W: + case ECR_PROTECTION_R: + case ECR_PROTECTION_W: + case ECR_DTLB_MODIFIED: + case ECR_TLB_MISS_X: + case ECR_TLB_MISS_R: + case ECR_TLB_MISS_W: + printf("MMU exception at address 0x%08lx\n", + sysreg_read(TLBEAR)); + break; + } + + printf(" pc: %08lx lr: %08lx sp: %08lx r12: %08lx\n", + regs->pc, regs->lr, regs->sp, regs->r12); + printf(" r11: %08lx r10: %08lx r9: %08lx r8: %08lx\n", + regs->r11, regs->r10, regs->r9, regs->r8); + printf(" r7: %08lx r6: %08lx r5: %08lx r4: %08lx\n", + regs->r7, regs->r6, regs->r5, regs->r4); + printf(" r3: %08lx r2: %08lx r1: %08lx r0: %08lx\n", + regs->r3, regs->r2, regs->r1, regs->r0); + printf("Flags: %c%c%c%c%c\n", + regs->sr & SR_Q ? 'Q' : 'q', + regs->sr & SR_V ? 'V' : 'v', + regs->sr & SR_N ? 'N' : 'n', + regs->sr & SR_Z ? 'Z' : 'z', + regs->sr & SR_C ? 'C' : 'c'); + printf("Mode bits: %c%c%c%c%c%c%c%c%c\n", + regs->sr & SR_H ? 'H' : 'h', + regs->sr & SR_R ? 'R' : 'r', + regs->sr & SR_J ? 'J' : 'j', + regs->sr & SR_EM ? 'E' : 'e', + regs->sr & SR_I3M ? '3' : '.', + regs->sr & SR_I2M ? '2' : '.', + regs->sr & SR_I1M ? '1' : '.', + regs->sr & SR_I0M ? '0' : '.', + regs->sr & SR_GM ? 'G' : 'g'); + mode = (regs->sr >> SYSREG_M0_OFFSET) & 7; + printf("CPU Mode: %s\n", cpu_modes[mode]); + + /* Avoid exception loops */ + if (regs->sp < (gd->stack_end - CONFIG_STACKSIZE) + || regs->sp >= gd->stack_end) + printf("\nStack pointer seems bogus, won't do stack dump\n"); + else + dump_mem("\nStack: ", regs->sp, gd->stack_end); + + panic("Unhandled exception\n"); +} diff --git a/cpu/at32uc/flashc.c b/cpu/at32uc/flashc.c new file mode 100644 index 0000000..f33a4bb --- /dev/null +++ b/cpu/at32uc/flashc.c @@ -0,0 +1,80 @@ +/* + * 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 <common.h> + +#include <asm/io.h> +#include <asm/arch/memory-map.h> +#include "flashc.h" + +DECLARE_GLOBAL_DATA_PTR; + +/* Flash sizes in KB as returned by FSZ bitfield in FSR */ +const unsigned long flash_sizes[8] = { + 32, + 64, + 128, + 256, + 384, + 512, + 768, + 1024 +}; + +flash_info_t flash_info[1]; + +unsigned long flash_init(void) +{ + unsigned long fsz; + unsigned long size; + + fsz = FLASHC_BFEXT(FSZ, flashc_readl(FSR)); + + size = flash_sizes[fsz] * 1024; + + flash_info[0].size = size; + + /* Currently, all interflash have pages which are 128 words. */ + flash_info[0].sector_count = size / (128*4); + + return size; +} + +void flash_print_info(flash_info_t *info) +{ + printf("Flash: Vendor ID: 0x%02lx, Product ID: 0x%02lx\n", + info->flash_id >> 16, info->flash_id & 0xffff); + printf("Size: %ld MB in %d sectors\n", + info->size >> 10, info->sector_count); +} + +int flash_erase(flash_info_t *info, int s_first, int s_last) +{ + /* TODO */ + return ERR_OK; +} + +int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong count) +{ + /* TODO */ + return ERR_OK; +} + diff --git a/cpu/at32uc/flashc.h b/cpu/at32uc/flashc.h new file mode 100644 index 0000000..23618bc --- /dev/null +++ b/cpu/at32uc/flashc.h @@ -0,0 +1,67 @@ +/* + * Register definitions for flash controller + */ +#ifndef __ASM_AVR32_FLASHC_H__ +#define __ASM_AVR32_FLASHC_H__ + +/* FLASHC register offsets */ +#define FLASHC_FCR 0x0000 +#define FLASHC_FCMD 0x0004 +#define FLASHC_FSR 0x0008 +#define FLASHC_FGPFRHI 0x000c +#define FLASHC_FGPFRLO 0x0010 + +/* Bitfields in FCR and FSR */ +#define FLASHC_FRDY_OFFSET 0 +#define FLASHC_FRDY_SIZE 1 +#define FLASHC_LOCKE_OFFSET 2 +#define FLASHC_LOCKE_SIZE 1 +#define FLASHC_PROGE_OFFSET 3 +#define FLASHC_PROGE_SIZE 1 + +/* Bitfields in FCR */ +#define FLASHC_FWS_OFFSET 6 +#define FLASHC_FWS_SIZE 1 +#define FLASHC_SASD_OFFSET 8 +#define FLASHC_SASD_SIZE 1 + +/* Bitfields in FCMD */ +#define FLASHC_CMD_OFFSET 0 +#define FLASHC_CMD_SIZE 6 +#define FLASHC_PAGEN_OFFSET 8 +#define FLASHC_PAGEN_SIZE 16 +#define FLASHC_KEY_OFFSET 24 +#define FLASHC_KEY_SIZE 8 + +/* Bitfields in FSR */ +#define FLASHC_SECURITY_OFFSET 4 +#define FLASHC_SECURITY_SIZE 1 +#define FLASHC_QPRR_OFFSET 5 +#define FLASHC_QPRR_SIZE 1 +#define FLASHC_FSZ_OFFSET 13 +#define FLASHC_FSZ_SIZE 3 +#define FLASHC_LOCK_OFFSET 16 +#define FLASHC_LOCK_SIZE 16 + + +/* Bit manipulation macros */ +#define FLASHC_BIT(name) \ + (1 << FLASHC_##name##_OFFSET) +#define FLASHC_BF(name,value) \ + (((value) & ((1 << FLASHC_##name##_SIZE) - 1)) \ + << FLASHC_##name##_OFFSET) +#define FLASHC_BFEXT(name,value) \ + (((value) >> FLASHC_##name##_OFFSET) \ + & ((1 << FLASHC_##name##_SIZE) - 1)) +#define FLASHC_BFINS(name,value,old) \ + (((old) & ~(((1 << FLASHC_##name##_SIZE) - 1) \ + << FLASHC_##name##_OFFSET)) \ + | FLASHC_BF(name,value)) + +/* Register access macros */ +#define flashc_readl(reg) \ + readl((void *)FLASHC_BASE + FLASHC_##reg) +#define flashc_writel(reg,value) \ + writel((value), (void *)FLASHC_BASE + FLASHC_##reg) + +#endif /* __ASM_AVR32_FLASHC_H__ */ diff --git a/cpu/at32uc/interrupts.c b/cpu/at32uc/interrupts.c new file mode 100644 index 0000000..160838e --- /dev/null +++ b/cpu/at32uc/interrupts.c @@ -0,0 +1,150 @@ +/* + * 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 + */ +#include <common.h> +#include <div64.h> + +#include <asm/errno.h> +#include <asm/io.h> +#include <asm/processor.h> +#include <asm/sysreg.h> + +#include <asm/arch/memory-map.h> + +#define HANDLER_MASK 0x00ffffff +#define INTLEV_SHIFT 30 +#define INTLEV_MASK 0x00000003 + +DECLARE_GLOBAL_DATA_PTR; + +/* Incremented whenever COUNT reaches 0xffffffff by timer_interrupt_handler */ +volatile unsigned long timer_overflow; + +/* + * Instead of dividing by get_tbclk(), multiply by this constant and + * right-shift the result by 32 bits. + */ +static unsigned long tb_factor; + +unsigned long get_tbclk(void) +{ + return gd->cpu_hz; +} + +unsigned long long get_ticks(void) +{ + unsigned long lo, hi_now, hi_prev; + + do { + hi_prev = timer_overflow; + lo = sysreg_read(COUNT); + hi_now = timer_overflow; + } while (hi_prev != hi_now); + + return ((unsigned long long)hi_now << 32) | lo; +} + +void reset_timer(void) +{ + sysreg_write(COUNT, 0); + cpu_sync_pipeline(); /* process any pending interrupts */ + timer_overflow = 0; +} + +unsigned long get_timer(unsigned long base) +{ + u64 now = get_ticks(); + + now *= tb_factor; + return (unsigned long)(now >> 32) - base; +} + +void set_timer(unsigned long t) +{ + unsigned long long ticks = t; + unsigned long lo, hi, hi_new; + + ticks = (ticks * get_tbclk()) / CFG_HZ; + hi = ticks >> 32; + lo = ticks & 0xffffffffUL; + + do { + timer_overflow = hi; + sysreg_write(COUNT, lo); + hi_new = timer_overflow; + } while (hi_new != hi); +} + +/* + * For short delays only. It will overflow after a few seconds. + */ +void udelay(unsigned long usec) +{ + unsigned long cycles; + unsigned long base; + unsigned long now; + + base = sysreg_read(COUNT); + cycles = ((usec * (get_tbclk() / 10000)) + 50) / 100; + + do { + now = sysreg_read(COUNT); + } while ((now - base) < cycles); +} + +static int set_interrupt_handler(unsigned int nr, void (*handler)(void), + unsigned int priority) +{ + extern void _evba(void); + unsigned long intpr; + unsigned long handler_addr = (unsigned long)handler; + + handler_addr -= (unsigned long)&_evba; + + if ((handler_addr & HANDLER_MASK) != handler_addr + || (priority & INTLEV_MASK) != priority) + return -EINVAL; + + intpr = (handler_addr & HANDLER_MASK); + intpr |= (priority & INTLEV_MASK) << INTLEV_SHIFT; + writel(intpr, (void *)INTC_BASE + 4 * nr); + + return 0; +} + +void timer_init(void) +{ + extern void timer_interrupt_handler(void); + u64 tmp; + + sysreg_write(COUNT, 0); + + tmp = (u64)CFG_HZ << 32; + tmp += gd->cpu_hz / 2; + do_div(tmp, gd->cpu_hz); + tb_factor = (u32)tmp; + + if (set_interrupt_handler(0, &timer_interrupt_handler, 3)) + return; + + /* For all practical purposes, this gives us an overflow interrupt */ + sysreg_write(COMPARE, 0xffffffff); +} diff --git a/cpu/at32uc/portmux-gpio.c b/cpu/at32uc/portmux-gpio.c new file mode 100644 index 0000000..8ed5659 --- /dev/null +++ b/cpu/at32uc/portmux-gpio.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2008 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/io.h> +#include <asm/arch/memory-map.h> +#include <asm/arch-common/portmux-gpio.h> + + +void portmux_select_peripheral(void *port, unsigned long pin_mask, + enum portmux_function func, unsigned long flags) +{ + /* Both pull-up and pull-down set means buskeeper */ + if (flags & PORTMUX_PULL_DOWN) + gpio_writel(port, PDERS, pin_mask); + else + gpio_writel(port, PDERC, pin_mask); + if (flags & PORTMUX_PULL_UP) + gpio_writel(port, PUERS, pin_mask); + else + gpio_writel(port, PUERC, pin_mask); + + /* Select drive strength */ + if (flags & PORTMUX_DRIVE_LOW) + gpio_writel(port, ODCR0S, pin_mask); + else + gpio_writel(port, ODCR0C, pin_mask); + if (flags & PORTMUX_DRIVE_HIGH) + gpio_writel(port, ODCR1S, pin_mask); + else + gpio_writel(port, ODCR1C, pin_mask); + + /* Select function */ + if (func & PORTMUX_FUNC_B) + gpio_writel(port, PMR0S, pin_mask); + else + gpio_writel(port, PMR0C, pin_mask); + if (func & PORTMUX_FUNC_C) + gpio_writel(port, PMR1S, pin_mask); + else + gpio_writel(port, PMR1C, pin_mask); + + /* Disable GPIO (i.e. enable peripheral) */ + gpio_writel(port, GPERC, pin_mask); +} + +void portmux_select_gpio(void *port, unsigned long pin_mask, + unsigned long flags) +{ + /* Both pull-up and pull-down set means buskeeper */ + if (flags & PORTMUX_PULL_DOWN) + gpio_writel(port, PDERS, pin_mask); + else + gpio_writel(port, PDERC, pin_mask); + if (flags & PORTMUX_PULL_UP) + gpio_writel(port, PUERS, pin_mask); + else + gpio_writel(port, PUERC, pin_mask); + + /* Enable open-drain mode if requested */ + if (flags & PORTMUX_OPEN_DRAIN) + gpio_writel(port, ODMERS, pin_mask); + else + gpio_writel(port, ODMERC, pin_mask); + + /* Select drive strength */ + if (flags & PORTMUX_DRIVE_LOW) + gpio_writel(port, ODCR0S, pin_mask); + else + gpio_writel(port, ODCR0C, pin_mask); + if (flags & PORTMUX_DRIVE_HIGH) + gpio_writel(port, ODCR1S, pin_mask); + else + gpio_writel(port, ODCR1C, pin_mask); + + /* Select direction and initial pin state */ + if (flags & PORTMUX_DIR_OUTPUT) { + if (flags & PORTMUX_INIT_HIGH) + gpio_writel(port, OVRS, pin_mask); + else + gpio_writel(port, OVRC, pin_mask); + gpio_writel(port, ODERS, pin_mask); + } else { + gpio_writel(port, ODERC, pin_mask); + } + + /* Enable GPIO */ + gpio_writel(port, GPERS, pin_mask); +} diff --git a/cpu/at32uc/sdramc.c b/cpu/at32uc/sdramc.c new file mode 100644 index 0000000..2ed0066 --- /dev/null +++ b/cpu/at32uc/sdramc.c @@ -0,0 +1,120 @@ +/* + * 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 <common.h> + +#ifdef CFG_SDRAMC +#include <asm/io.h> +#include <asm/sdram.h> + +#include <asm/arch/clk.h> +#include <asm/arch/memory-map.h> + +#include "sdramc.h" + +unsigned long sdram_init(void *sdram_base, const struct sdram_config *config) +{ + unsigned long sdram_size; + uint32_t cfgreg; + unsigned int i; + + cfgreg = (SDRAMC_BF(NC, config->col_bits - 8) + | SDRAMC_BF(NR, config->row_bits - 11) + | SDRAMC_BF(NB, config->bank_bits - 1) + | SDRAMC_BF(CAS, config->cas) + | SDRAMC_BF(TWR, config->twr) + | SDRAMC_BF(TRC, config->trc) + | SDRAMC_BF(TRP, config->trp) + | SDRAMC_BF(TRCD, config->trcd) + | SDRAMC_BF(TRAS, config->tras) + | SDRAMC_BF(TXSR, config->txsr)); + + if (config->data_bits == SDRAM_DATA_16BIT) + cfgreg |= SDRAMC_BIT(DBW); + + sdramc_writel(CR, cfgreg); + + /* Send a NOP to turn on the clock (necessary on some chips) */ + sdramc_writel(MR, SDRAMC_MODE_NOP); + sdramc_readl(MR); + writel(0, sdram_base); + + /* + * Initialization sequence for SDRAM, from the data sheet: + * + * 1. A minimum pause of 200 us is provided to precede any + * signal toggle. + */ + udelay(200); + + /* + * 2. A Precharge All command is issued to the SDRAM + */ + sdramc_writel(MR, SDRAMC_MODE_BANKS_PRECHARGE); + sdramc_readl(MR); + writel(0, sdram_base); + + /* + * 3. Eight auto-refresh (CBR) cycles are provided + */ + sdramc_writel(MR, SDRAMC_MODE_AUTO_REFRESH); + sdramc_readl(MR); + for (i = 0; i < 8; i++) + writel(0, sdram_base); + + /* + * 4. A mode register set (MRS) cycle is issued to program + * SDRAM parameters, in particular CAS latency and burst + * length. + * + * The address will be chosen by the SDRAMC automatically; we + * just have to make sure BA[1:0] are set to 0. + */ + sdramc_writel(MR, SDRAMC_MODE_LOAD_MODE); + sdramc_readl(MR); + writel(0, sdram_base); + + /* + * 5. The application must go into Normal Mode, setting Mode + * to 0 in the Mode Register and performing a write access + * at any location in the SDRAM. + */ + sdramc_writel(MR, SDRAMC_MODE_NORMAL); + sdramc_readl(MR); + writel(0, sdram_base); + + /* + * 6. Write refresh rate into SDRAMC refresh timer count + * register (refresh rate = timing between refresh cycles). + */ + sdramc_writel(TR, config->refresh_period); + + if (config->data_bits == SDRAM_DATA_16BIT) + sdram_size = 1 << (config->row_bits + config->col_bits + + config->bank_bits + 1); + else + sdram_size = 1 << (config->row_bits + config->col_bits + + config->bank_bits + 2); + + return sdram_size; +} + +#endif /* CFG_SDRAMC */ diff --git a/cpu/at32uc/sdramc.h b/cpu/at32uc/sdramc.h new file mode 100644 index 0000000..8154415 --- /dev/null +++ b/cpu/at32uc/sdramc.h @@ -0,0 +1,137 @@ +/* + * Register definitions for SDRAM Controller + */ +#ifndef __ASM_AVR32_SDRAMC_H__ +#define __ASM_AVR32_SDRAMC_H__ + +/* SDRAMC register offsets */ +#define SDRAMC_MR 0x0000 +#define SDRAMC_TR 0x0004 +#define SDRAMC_CR 0x0008 +#define SDRAMC_HSR 0x000c +#define SDRAMC_LPR 0x0010 +#define SDRAMC_IER 0x0014 +#define SDRAMC_IDR 0x0018 +#define SDRAMC_IMR 0x001c +#define SDRAMC_ISR 0x0020 +#define SDRAMC_MDR 0x0024 + +/* Bitfields in MR */ +#define SDRAMC_MODE_OFFSET 0 +#define SDRAMC_MODE_SIZE 3 + +/* Bitfields in TR */ +#define SDRAMC_COUNT_OFFSET 0 +#define SDRAMC_COUNT_SIZE 12 + +/* Bitfields in CR */ +#define SDRAMC_NC_OFFSET 0 +#define SDRAMC_NC_SIZE 2 +#define SDRAMC_NR_OFFSET 2 +#define SDRAMC_NR_SIZE 2 +#define SDRAMC_NB_OFFSET 4 +#define SDRAMC_NB_SIZE 1 +#define SDRAMC_CAS_OFFSET 5 +#define SDRAMC_CAS_SIZE 2 +#define SDRAMC_DBW_OFFSET 7 +#define SDRAMC_DBW_SIZE 1 +#define SDRAMC_TWR_OFFSET 8 +#define SDRAMC_TWR_SIZE 4 +#define SDRAMC_TRC_OFFSET 12 +#define SDRAMC_TRC_SIZE 4 +#define SDRAMC_TRP_OFFSET 16 +#define SDRAMC_TRP_SIZE 4 +#define SDRAMC_TRCD_OFFSET 20 +#define SDRAMC_TRCD_SIZE 4 +#define SDRAMC_TRAS_OFFSET 24 +#define SDRAMC_TRAS_SIZE 4 +#define SDRAMC_TXSR_OFFSET 28 +#define SDRAMC_TXSR_SIZE 4 + +/* Bitfields in HSR */ +#define SDRAMC_DA_OFFSET 0 +#define SDRAMC_DA_SIZE 1 + +/* Bitfields in LPR */ +#define SDRAMC_LPCB_OFFSET 0 +#define SDRAMC_LPCB_SIZE 2 +#define SDRAMC_PASR_OFFSET 4 +#define SDRAMC_PASR_SIZE 3 +#define SDRAMC_TCSR_OFFSET 8 +#define SDRAMC_TCSR_SIZE 2 +#define SDRAMC_DS_OFFSET 10 +#define SDRAMC_DS_SIZE 2 +#define SDRAMC_TIMEOUT_OFFSET 12 +#define SDRAMC_TIMEOUT_SIZE 2 + +/* Bitfields in IDR */ +#define SDRAMC_RES_OFFSET 0 +#define SDRAMC_RES_SIZE 1 + +/* Bitfields in MDR */ +#define SDRAMC_MD_OFFSET 0 +#define SDRAMC_MD_SIZE 2 + +/* Constants for MODE */ +#define SDRAMC_MODE_NORMAL 0 +#define SDRAMC_MODE_NOP 1 +#define SDRAMC_MODE_BANKS_PRECHARGE 2 +#define SDRAMC_MODE_LOAD_MODE 3 +#define SDRAMC_MODE_AUTO_REFRESH 4 +#define SDRAMC_MODE_EXT_LOAD_MODE 5 +#define SDRAMC_MODE_POWER_DOWN 6 + +/* Constants for NC */ +#define SDRAMC_NC_8_COLUMN_BITS 0 +#define SDRAMC_NC_9_COLUMN_BITS 1 +#define SDRAMC_NC_10_COLUMN_BITS 2 +#define SDRAMC_NC_11_COLUMN_BITS 3 + +/* Constants for NR */ +#define SDRAMC_NR_11_ROW_BITS 0 +#define SDRAMC_NR_12_ROW_BITS 1 +#define SDRAMC_NR_13_ROW_BITS 2 + +/* Constants for NB */ +#define SDRAMC_NB_TWO_BANKS 0 +#define SDRAMC_NB_FOUR_BANKS 1 + +/* Constants for CAS */ +#define SDRAMC_CAS_ONE_CYCLE 1 +#define SDRAMC_CAS_TWO_CYCLES 2 +#define SDRAMC_CAS_THREE_CYCLES 3 + +/* Constants for DBW */ +#define SDRAMC_DBW_32_BITS 0 +#define SDRAMC_DBW_16_BITS 1 + +/* Constants for TIMEOUT */ +#define SDRAMC_TIMEOUT_AFTER_END 0 +#define SDRAMC_TIMEOUT_64_CYC_AFTER_END 1 +#define SDRAMC_TIMEOUT_128_CYC_AFTER_END 2 + +/* Constants for MD */ +#define SDRAMC_MD_SDRAM 0 +#define SDRAMC_MD_LOW_POWER_SDRAM 1 + +/* Bit manipulation macros */ +#define SDRAMC_BIT(name) \ + (1 << SDRAMC_##name##_OFFSET) +#define SDRAMC_BF(name,value) \ + (((value) & ((1 << SDRAMC_##name##_SIZE) - 1)) \ + << SDRAMC_##name##_OFFSET) +#define SDRAMC_BFEXT(name,value) \ + (((value) >> SDRAMC_##name##_OFFSET) \ + & ((1 << SDRAMC_##name##_SIZE) - 1)) +#define SDRAMC_BFINS(name,value,old) \ + (((old) & ~(((1 << SDRAMC_##name##_SIZE) - 1) \ + << SDRAMC_##name##_OFFSET)) \ + | SDRAMC_BF(name,value)) + +/* Register access macros */ +#define sdramc_readl(reg) \ + readl((void *)SDRAMC_BASE + SDRAMC_##reg) +#define sdramc_writel(reg,value) \ + writel((value), (void *)SDRAMC_BASE + SDRAMC_##reg) + +#endif /* __ASM_AVR32_SDRAMC_H__ */ diff --git a/cpu/at32uc/start.S b/cpu/at32uc/start.S new file mode 100644 index 0000000..e1d44cb --- /dev/null +++ b/cpu/at32uc/start.S @@ -0,0 +1,265 @@ +/* + * Copyright (C) 2005-2008 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 <config.h> +#include <asm/ptrace.h> +#include <asm/sysreg.h> + + +#define SR_INIT (SYSREG_BIT(GM) | SYSREG_BIT(EM) | SYSREG_BIT(M0)) +#define CPUCR_INIT (SYSREG_BIT(BI) | SYSREG_BIT(BE) \ + | SYSREG_BIT(FE) | SYSREG_BIT(RE) \ + | SYSREG_BIT(IBE) | SYSREG_BIT(IEE)) + + /* + * To save some space, we use the same entry point for + * exceptions and reset. This avoids lots of alignment padding + * since the reset vector is always suitably aligned. + */ + .section .exception.text, "ax", @progbits + .global _start + .global _evba + .type _start, @function + .type _evba, @function +_start: + .size _start, 0 +_evba: + .org 0x00 + rjmp unknown_exception /* Unrecoverable exception */ + .org 0x04 + rjmp unknown_exception /* TLB multiple hit */ + .org 0x08 + rjmp unknown_exception /* Bus error data fetch */ + .org 0x0c + rjmp unknown_exception /* Bus error instruction fetch */ + .org 0x10 + rjmp unknown_exception /* NMI */ + .org 0x14 + rjmp unknown_exception /* Instruction address */ + .org 0x18 + rjmp unknown_exception /* ITLB protection */ + .org 0x1c + rjmp unknown_exception /* Breakpoint */ + .org 0x20 + rjmp unknown_exception /* Illegal opcode */ + .org 0x24 + rjmp unknown_exception /* Unimplemented instruction */ + .org 0x28 + rjmp unknown_exception /* Privilege violation */ + .org 0x2c + rjmp unknown_exception /* Floating-point */ + .org 0x30 + rjmp unknown_exception /* Coprocessor absent */ + .org 0x34 + rjmp unknown_exception /* Data Address (read) */ + .org 0x38 + rjmp unknown_exception /* Data Address (write) */ + .org 0x3c + rjmp unknown_exception /* DTLB Protection (read) */ + .org 0x40 + rjmp unknown_exception /* DTLB Protection (write) */ + .org 0x44 + rjmp unknown_exception /* DTLB Modified */ + + .org 0x50 + rjmp unknown_exception /* ITLB Miss */ + .org 0x60 + rjmp unknown_exception /* DTLB Miss (read) */ + .org 0x70 + rjmp unknown_exception /* DTLB Miss (write) */ + + .size _evba, . - _evba + + .align 2 + .type unknown_exception, @function +unknown_exception: + /* Figure out whether we're handling an exception (Exception + * mode) or just booting (Supervisor mode). */ + csrfcz SYSREG_M1_OFFSET + brcc at32uc_cpu_bootstrap + + /* This is an exception. Complain. */ + pushm r0-r12 + sub r8, sp, REG_R12 - REG_R0 - 4*3 + mov r9, lr + ld.w r10, r8[-4] + ld.w r11, r8[-8] + pushm r8-r11 + mfsr r12, SYSREG_ECR + mov r11, sp + rcall do_unknown_exception +1: rjmp 1b + + /* The COUNT/COMPARE timer interrupt handler */ + .global timer_interrupt_handler + .type timer_interrupt_handler,@function + .align 2 +timer_interrupt_handler: + /* + * Increment timer_overflow and re-write COMPARE with 0xffffffff. + * + * We're running at interrupt level 3, so we don't need to save + * r8-r12 or lr to the stack. + */ + lda.w r8, timer_overflow + ld.w r9, r8[0] + mov r10, -1 + mtsr SYSREG_COMPARE, r10 + sub r9, -1 + st.w r8[0], r9 + rete + + /* + * CPU bootstrap after reset is handled here. SoC code may + * override this in case they need to initialize oscillators, + * etc. + */ + .section .text.at32uc_cpu_bootstrap, "ax", @progbits + .global at32uc_cpu_bootstrap + .weak at32uc_cpu_bootstrap + .type at32uc_cpu_bootstrap, @function + .align 2 +at32uc_cpu_bootstrap: + /* Reset the Status Register */ + mov r0, lo(SR_INIT) + orh r0, hi(SR_INIT) + mtsr SYSREG_SR, r0 + /* ERRATA: two NOPs required after mtsr which may mask interrupts. */ + nop + nop + + /* Reset CPUCR and invalidate the BTB */ + mov r2, CPUCR_INIT + mtsr SYSREG_CPUCR, r2 + + /* Internal RAM should not need any initialization. We might + have to initialize external RAM here if the part doesn't + have internal RAM (or we may use the data cache) */ + + + lddpc sp, sp_init + + /* Initialize the GOT pointer */ + lddpc r6, got_init +3: rsub r6, pc + + /* Let's go */ + rjmp board_init_f + + .align 2 + .type sp_init,@object +sp_init: + .long CFG_INIT_SP_ADDR +got_init: + .long 3b - _GLOBAL_OFFSET_TABLE_ + + /* + * void relocate_code(new_sp, new_gd, monitor_addr) + * + * Relocate the u-boot image into RAM and continue from there. + * Does not return. + */ + .section .text.relocate_code,"ax",@progbits + .global relocate_code + .type relocate_code,@function +relocate_code: + mov sp, r12 /* use new stack */ + mov r12, r11 /* save new_gd */ + mov r11, r10 /* save destination address */ + + /* copy .text section */ + lda.w r8, _text + lda.w r9, _etext + sub lr, r10, r8 /* relocation offset */ + +1: ldm r8++, r0-r3 + stm r10, r0-r3 + sub r10, -16 + ldm r8++, r0-r3 + stm r10, r0-r3 + sub r10, -16 + cp.w r8, r9 + brlt 1b + + /* copy data sections */ + lda.w r9, _edata +1: ld.d r0, r8++ + st.d r10++, r0 + cp.w r8, r9 + brlt 1b + + /* zero out .bss */ + mov r0, 0 + mov r1, 0 + lda.w r9, _end + sub r9, r8 +1: st.d r10++, r0 + sub r9, 8 + brgt 1b + + /* jump to RAM */ + /* we don't want to run from sdram. + sub r0, pc, . - in_ram + add pc, r0, lr + */ + + .align 2 +in_ram: + /* find the new GOT and relocate it */ + lddpc r6, got_init_reloc +3: rsub r6, pc + add r6, lr + mov r8, r6 + lda.w r9, _egot + lda.w r10, _got + sub r9, r10 + + lda.w r1, _end_noreloc + +1: ld.w r0, r8[0] + /* Check if the symbol points to the text-section, and + * skip relocation if they do. + */ + cp.w r0, r1 + brlt 2f + + add r0, lr + st.w r8, r0 +2: + sub r8, -4 + sub r9, 4 + brgt 1b + + /* Move the exception handlers */ + /* We don't want to run from sdram. + mfsr r2, SYSREG_EVBA + add r2, lr + mtsr SYSREG_EVBA, r2 + */ + + /* Do the rest of the initialization sequence */ + call board_init_r + + .align 2 +got_init_reloc: + .long 3b - _GLOBAL_OFFSET_TABLE_ + + .size relocate_code, . - relocate_code diff --git a/include/asm-avr32/arch-at32uc3a0xxx/addrspace.h b/include/asm-avr32/arch-at32uc3a0xxx/addrspace.h new file mode 100644 index 0000000..90feed7 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/addrspace.h @@ -0,0 +1,63 @@ +/* + * 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_ADDRSPACE_H +#define __ASM_AVR32_ADDRSPACE_H + +#include <asm/types.h> + +/* Returns the physical address of an address */ +#define PHYSADDR(a) ((unsigned long)(a)) + +/* virt_to_phys will only work when address is in P1 or P2 */ +static __inline__ unsigned long virt_to_phys(volatile void *address) +{ + return PHYSADDR(address); +} + +static __inline__ void * phys_to_virt(unsigned long address) +{ + return (void *)address; +} + +#define cached(addr) ((void *)(addr)) +#define uncached(addr) ((void *)(addr)) + +/* + * 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.) + */ +#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) +{ + return (void *)paddr; +} + +#endif /* __ASM_AVR32_ADDRSPACE_H */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h b/include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h new file mode 100644 index 0000000..3dc1068 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h @@ -0,0 +1,41 @@ +/* + * 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_CACHEFLUSH_H +#define __ASM_AVR32_CACHEFLUSH_H + +/* No cache in the UC3. */ +#define dcache_invalidate_line(vaddr) +#define dcache_clean_line(vaddr) +#define dcache_flush_line(vaddr) +#define icache_invalidate_line(vaddr) +#define dcache_invalidate_range(start, len) +#define dcache_clean_range(start, len) +#define dcache_flush_range(start, len) +#define icache_invalidate_range(start, len) +#define dcache_flush_unlocked() + +/* + * Make sure any pending writes are completed before continuing. + */ +#define sync_write_buffer() asm volatile("sync 0" : : : "memory") + +#endif /* __ASM_AVR32_CACHEFLUSH_H */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/chip-features.h b/include/asm-avr32/arch-at32uc3a0xxx/chip-features.h new file mode 100644 index 0000000..25ae8d7 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/chip-features.h @@ -0,0 +1,30 @@ +/* + * 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__ + +/* All the UC3A0xxx chips have these. */ +#define AT32UC3A0xxx_CHIP_HAS_USART +#define AT32UC3A0xxx_CHIP_HAS_SPI +#define AT32UC3A0xxx_CHIP_HAS_MACB + +#endif /* __ASM_AVR32_ARCH_CHIP_FEATURES_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/clk.h b/include/asm-avr32/arch-at32uc3a0xxx/clk.h new file mode 100644 index 0000000..1bfb721 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/clk.h @@ -0,0 +1,86 @@ +/* + * 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) / \ + ((CFG_PLL0_OPT & 0x2) ? 2 : 1)) +#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) +{ + //TODO HSB is always the same as cpu-rate + return MAIN_CLK_RATE >> CFG_CLKDIV_CPU; +} +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 AT32UC3A0xxx_CHIP_HAS_USART +static inline unsigned long get_usart_clk_rate(unsigned int dev_id) +{ + return get_pba_clk_rate(); +} +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +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 AT32UC3A0xxx_CHIP_HAS_SPI +static inline unsigned long get_spi_clk_rate(unsigned int dev_id) +{ + return get_pba_clk_rate(); +} +#endif + +extern void clk_init(void); +extern void gclk_init(void) __attribute__((weak)); + +/* Board code may need the SDRAM base clock as a compile-time constant */ +#define SDRAMC_BUS_HZ (MAIN_CLK_RATE >> CFG_CLKDIV_CPU) + +#endif /* __ASM_AVR32_ARCH_CLK_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/gpio.h b/include/asm-avr32/arch-at32uc3a0xxx/gpio.h new file mode 100644 index 0000000..165ee5d --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/gpio.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2006, 2008 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 4 + +static inline void *pio_pin_to_port(unsigned int pin) +{ + unsigned port_no; + + port_no = pin / 32; + if (port_no >= (NR_GPIO_CONTROLLERS - 1)) { + return NULL; + } + + return GPIO_PORT(port_no); +} + +#include <asm/arch-common/portmux-pio.h> + +#endif /* __ASM_AVR32_ARCH_GPIO_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h b/include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h new file mode 100644 index 0000000..907912f --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 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_HMATRIX_H__ +#define __ASM_AVR32_ARCH_HMATRIX_H__ + +#include <asm/hmatrix-common.h> + +/* Bitfields in SFR5 (EBI) */ +#define HMATRIX_EBI_SDRAM_ENABLE_OFFSET 1 +#define HMATRIX_EBI_SDRAM_ENABLE_SIZE 1 + +/* HSB masters */ +#define HMATRIX_MASTER_CPU_DATA 0 +#define HMATRIX_MASTER_CPU_INSTRUCTIONS 1 +#define HMATRIX_MASTER_CPU_SAB 2 +#define HMATRIX_MASTER_PDCA 3 +#define HMATRIX_MASTER_MACB_DMA 4 +#define HMATRIX_MASTER_USBB_DMA 5 + +/* HSB slaves */ +#define HMATRIX_SLAVE_INT_FLASH 0 +#define HMATRIX_SLAVE_HSB_PB_BR0 1 +#define HMATRIX_SLAVE_HSB_PB_BR1 2 +#define HMATRIX_SLAVE_INT_SRAM 3 +#define HMATRIX_SLAVE_USBB_DPRAM 4 +#define HMATRIX_SLAVE_EBI 5 + +#endif /* __ASM_AVR32_ARCH_HMATRIX_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/memory-map.h b/include/asm-avr32/arch-at32uc3a0xxx/memory-map.h new file mode 100644 index 0000000..cef3807 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/memory-map.h @@ -0,0 +1,75 @@ +/* + * 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 __AT32UC3A0512_MEMORY_MAP_H__ +#define __AT32UC3A0512_MEMORY_MAP_H__ + +/* Internal and external memories */ +#define EBI_SRAM_CS0_BASE 0xc0000000 +#define EBI_SRAM_CS0_SIZE 0x01000000 +#define EBI_SRAM_CS2_BASE 0xc8000000 +#define EBI_SRAM_CS2_SIZE 0x01000000 +#define EBI_SRAM_CS3_BASE 0xcc000000 +#define EBI_SRAM_CS3_SIZE 0x01000000 +#define EBI_SRAM_CS1_BASE 0xd0000000 +#define EBI_SRAM_CS1_SIZE 0x08000000 + +#define EBI_SDRAM_BASE EBI_SRAM_CS1_BASE +#define EBI_SDRAM_SIZE EBI_SRAM_CS1_SIZE + +#define INTERNAL_SRAM_BASE 0x00000000 +#define INTERNAL_SRAM_SIZE 0x00010000 + +/* Devices on HSB bus */ +#define USBB_SLAVE_BASE 0xE0000000 + +/* Devices on Peripheral Bus B (PBB) */ +#define USBB_CONFIG_BASE 0xFFFE0000 +#define HMATRIX_BASE 0xFFFE1000 +#define FLASHC_BASE 0xFFFE1400 +#define MACB_BASE 0xFFFE1800 +#define SMC_BASE 0xFFFE1C00 +#define SDRAMC_BASE 0xFFFE2000 + +/* Devices on Peripheral Bus A (PBA) */ +#define SM_BASE 0xFFFF0000 +#define PCDA_BASE 0xFFFF0000 +#define INTC_BASE 0xFFFF0800 +#define PM_BASE 0xFFFF0C00 +#define RTC_BASE 0xFFFF0D00 +#define WDT_BASE 0xFFFF0D30 +#define EIC_BASE 0xFFFF0D80 +#define GPIO_BASE 0xFFFF1000 +#define USART0_BASE 0xFFFF1400 +#define USART1_BASE 0xFFFF1800 +#define USART2_BASE 0xFFFF1C00 +#define USART3_BASE 0xFFFF2000 +#define SPI0_BASE 0xFFFF2400 +#define SPI1_BASE 0xFFFF2800 +#define TWI_BASE 0xFFFF2C00 +#define PWM_BASE 0xFFFF3000 +#define SSC_BASE 0xFFFF3400 +#define TC_BASE 0xFFFF3800 +#define ADC_BASE 0xFFFF3C00 + +#define GPIO_PORT(x) ( (void *) (GPIO_BASE + (x) * 0x0100) ) + +#endif /* __AT32UC3A0512_MEMORY_MAP_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/portmux.h b/include/asm-avr32/arch-at32uc3a0xxx/portmux.h new file mode 100644 index 0000000..2877206 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/portmux.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2006, 2008 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_PORTMUX_H__ +#define __ASM_AVR32_ARCH_PORTMUX_H__ + +#include <asm/arch-common/portmux-gpio.h> +#include <asm/arch/memory-map.h> + +#define PORTMUX_PORT(x) ( (void *) (GPIO_BASE + (x) * 0x0100) ) +#define PORTMUX_PORT_A PORTMUX_PORT(0) +#define PORTMUX_PORT_B PORTMUX_PORT(1) +#define PORTMUX_PORT_C PORTMUX_PORT(2) + +void portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width, + unsigned long flags, unsigned long drive_strength); + +#define PORTMUX_EBI_CS(x) (1 << (x)) +#define PORTMUX_EBI_NAND (1 << 6) +#define PORTMUX_EBI_CF(x) (1 << ((x) + 7)) +#define PORTMUX_EBI_NWAIT (1 << 9) + +#ifdef AT32UC3A0xxx_CHIP_HAS_USART +static inline void portmux_enable_usart0(unsigned long drive_strength) +{ + portmux_select_peripheral(PORTMUX_PORT_A, (1 << 0) | (1 << 1), + PORTMUX_FUNC_A, 0); +} + +static inline void portmux_enable_usart1(unsigned long drive_strength) +{ + portmux_select_peripheral(PORTMUX_PORT_A, (1 << 5) | (1 << 6), + PORTMUX_FUNC_A, 0); +} + +static inline void portmux_enable_usart2(unsigned long drive_strength) +{ + portmux_select_peripheral(PORTMUX_PORT_B, (1 << 29) | (1 << 30), + PORTMUX_FUNC_A, 0); +} + +static inline void portmux_enable_usart3(unsigned long drive_strength) +{ + portmux_select_peripheral(PORTMUX_PORT_B, (1 << 10) | (1 << 11), + PORTMUX_FUNC_B, 0); +} +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +void portmux_enable_macb(unsigned long flags, unsigned long drive_strength); + +#define PORTMUX_MACB_RMII (0) +#define PORTMUX_MACB_MII (1 << 0) +#define PORTMUX_MACB_SPEED (1 << 1) + +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_SPI +void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength); +void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength); +#endif + +#endif /* __ASM_AVR32_ARCH_PORTMUX_H__ */ +

Olav Morken wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
cpu/at32uc/Makefile | 56 ++++ cpu/at32uc/at32uc3a0xxx/Makefile | 43 +++ cpu/at32uc/at32uc3a0xxx/clk.c | 85 ++++++ cpu/at32uc/at32uc3a0xxx/portmux.c | 154 +++++++++++ cpu/at32uc/at32uc3a0xxx/sm.h | 272 ++++++++++++++++++++ cpu/at32uc/cache.c | 34 +++ cpu/at32uc/config.mk | 22 ++ cpu/at32uc/cpu.c | 79 ++++++ cpu/at32uc/exception.c | 121 +++++++++ cpu/at32uc/flashc.c | 80 ++++++ cpu/at32uc/flashc.h | 67 +++++ cpu/at32uc/interrupts.c | 150 +++++++++++ cpu/at32uc/portmux-gpio.c | 108 ++++++++ cpu/at32uc/sdramc.c | 120 +++++++++ cpu/at32uc/sdramc.h | 137 ++++++++++ cpu/at32uc/start.S | 265 +++++++++++++++++++ include/asm-avr32/arch-at32uc3a0xxx/addrspace.h | 63 +++++ include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h | 41 +++ .../asm-avr32/arch-at32uc3a0xxx/chip-features.h | 30 +++ include/asm-avr32/arch-at32uc3a0xxx/clk.h | 86 ++++++ include/asm-avr32/arch-at32uc3a0xxx/gpio.h | 44 ++++ include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h | 47 ++++ include/asm-avr32/arch-at32uc3a0xxx/memory-map.h | 75 ++++++ include/asm-avr32/arch-at32uc3a0xxx/portmux.h | 80 ++++++ 24 files changed, 2259 insertions(+), 0 deletions(-) create mode 100644 cpu/at32uc/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/clk.c create mode 100644 cpu/at32uc/at32uc3a0xxx/portmux.c create mode 100644 cpu/at32uc/at32uc3a0xxx/sm.h create mode 100644 cpu/at32uc/cache.c create mode 100644 cpu/at32uc/config.mk create mode 100644 cpu/at32uc/cpu.c create mode 100644 cpu/at32uc/exception.c create mode 100644 cpu/at32uc/flashc.c create mode 100644 cpu/at32uc/flashc.h create mode 100644 cpu/at32uc/interrupts.c create mode 100644 cpu/at32uc/portmux-gpio.c create mode 100644 cpu/at32uc/sdramc.c create mode 100644 cpu/at32uc/sdramc.h create mode 100644 cpu/at32uc/start.S create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/addrspace.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/chip-features.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/clk.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/gpio.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/memory-map.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/portmux.h
diff --git a/cpu/at32uc/Makefile b/cpu/at32uc/Makefile new file mode 100644 index 0000000..cab9bdc --- /dev/null +++ b/cpu/at32uc/Makefile @@ -0,0 +1,56 @@ +# +# (C) Copyright 2000-2006 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# 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$(CPU).a
+START-y += start.o
+COBJS-y += cpu.o +COBJS-y += sdramc.o +COBJS-y += exception.o +COBJS-y += cache.o +COBJS-y += interrupts.o +COBJS-$(CONFIG_PORTMUX_GPIO) += portmux-gpio.o +COBJS-y += flashc.o
+SRCS := $(START-y:.o=.S) $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(SOBJS-y) $(COBJS-y)) +START := $(addprefix $(obj),$(START-y))
+all: $(obj).depend $(START) $(LIB)
+$(LIB): $(OBJS)
- $(AR) $(ARFLAGS) $@ $^
+#########################################################################
+# defines $(obj).depend target +include $(SRCTREE)/rules.mk
+sinclude $(obj).depend
+######################################################################### diff --git a/cpu/at32uc/at32uc3a0xxx/Makefile b/cpu/at32uc/at32uc3a0xxx/Makefile new file mode 100644 index 0000000..4942e56 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/Makefile @@ -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 := clk.o portmux.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/at32uc/at32uc3a0xxx/clk.c b/cpu/at32uc/at32uc3a0xxx/clk.c new file mode 100644 index 0000000..7c66b94 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/clk.c @@ -0,0 +1,85 @@ +/*
- Copyright (C) 2005-2008 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/io.h>
+#include <asm/arch/clk.h> +#include <asm/arch/memory-map.h>
+#include "sm.h"
+void clk_init(void) +{
- uint32_t cksel;
- /* in case of soft resets, disable watchdog */
- sm_writel(WDT_CTRL, SM_BF(KEY, 0x55));
- sm_writel(WDT_CTRL, SM_BF(KEY, 0xaa));
- /* osc0 is 12mhz (Mode 7)*/
- sm_writel(PM_OSCCTRL0, (SM_BF(MODE, 7)|SM_BF(STARTUP, 1)));
- /* enable osc0 */
- sm_writel(PM_MCCTRL, SM_BIT(OSC0EN));
- /* wait for osc0 */
- while (!(sm_readl(PM_POSCSR) & SM_BIT(OSC0RDY))) ;
- /* run from osc0 */
- sm_writel(PM_MCCTRL, SM_BF(MCSEL, 1) | SM_BIT(OSC0EN));
+#ifdef CONFIG_PLL
- /* Initialize the PLL */
- sm_writel(PM_PLL0, (SM_BF(PLLCOUNT, CFG_PLL0_SUPPRESS_CYCLES)
| SM_BF(PLLMUL, CFG_PLL0_MUL - 1)
| SM_BF(PLLDIV, CFG_PLL0_DIV)
| SM_BF(PLLOPT, CFG_PLL0_OPT)
| SM_BF(PLLOSC, 0)
| SM_BIT(PLLEN)
| SM_BIT(ERRATA)));
- /* Wait for lock */
- while (!(sm_readl(PM_POSCSR) & SM_BIT(LOCK0))) ;
+#endif
- /* We cannot write the CKSEL register before the ready-signal is set. */
- while (!(sm_readl(PM_POSCSR) & SM_BIT(CKRDY))) ;
- /* Set up clocks for the CPU and all peripheral buses */
- cksel = 0;
- if (CFG_CLKDIV_CPU)
cksel |= SM_BIT(CPUDIV) | SM_BF(CPUSEL, CFG_CLKDIV_CPU - 1);
- if (CFG_CLKDIV_PBA)
cksel |= SM_BIT(PBADIV) | SM_BF(PBASEL, CFG_CLKDIV_PBA - 1);
- if (CFG_CLKDIV_PBB)
cksel |= SM_BIT(PBBDIV) | SM_BF(PBBSEL, CFG_CLKDIV_PBB - 1);
- sm_writel(PM_CKSEL, cksel);
+#ifdef CONFIG_PLL
- /* Use PLL0 as main clock */
- sm_writel(PM_MCCTRL, SM_BF(MCSEL, 2) | SM_BIT(OSC0EN));
+#endif
+} diff --git a/cpu/at32uc/at32uc3a0xxx/portmux.c b/cpu/at32uc/at32uc3a0xxx/portmux.c new file mode 100644 index 0000000..a796f22 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/portmux.c @@ -0,0 +1,154 @@ +/*
- Copyright (C) 2006, 2008 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/io.h>
+#include <asm/arch/chip-features.h> +#include <asm/arch/memory-map.h> +#include <asm/arch/portmux.h>
+/*
- Lots of small functions here. We depend on --gc-sections getting
- rid of the ones we don't need.
- */
+void portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width,
unsigned long flags, unsigned long drive_strength)
+{
- /*
* GPIO pins to be set to enable all EBI pins
*
* PIN 14-17 function C port0 mask 00 03 C0 00
* PIN 25-28 function C port0 mask 1E 00 00 00
* PIN 36 function C port1 mask 00 00 00 10
* PIN 42-46 function C port1 mask 00 00 7C 00
* PIN 48-49 function C port1 mask 00 03 00 00
* PIN 61-63 function C port1 mask E0 00 00 00
* PIN 70-95 function A port2 mask FF FF FF C0
* PIN 96-109 function A port3 mask 00 00 3F FF
*/
- portmux_select_peripheral(PORTMUX_PORT(0),
0x0003C000 |
0x1E000000, PORTMUX_FUNC_C, 0);
- portmux_select_peripheral(PORTMUX_PORT(1),
0x00000010 |
0x00007C00 |
0x00030000 |
0xE0000000, PORTMUX_FUNC_C, 0);
- portmux_select_peripheral(PORTMUX_PORT(2),
0xFFFFFFC0, PORTMUX_FUNC_A, 0);
- portmux_select_peripheral(PORTMUX_PORT(3),
0x00003FFF, PORTMUX_FUNC_A, 0);
+}
+#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +void portmux_enable_macb(unsigned long flags, unsigned long drive_strength) +{
- unsigned long portb_mask;
- portb_mask = (1 << 2) /* TXD0 */
| (1 << 3) /* TXD1 */
| (1 << 1) /* TXEN */
| (1 << 0) /* TXCK */
| (1 << 5) /* RXD0 */
| (1 << 6) /* RXD1 */
| (1 << 7) /* RXER */
| (1 << 15) /* RXDV */
| (1 << 8) /* MDC */
| (1 << 9); /* MDIO */
- if (flags & PORTMUX_MACB_MII)
portb_mask |= (1 << 16) /* COL */
| (1 << 4) /* CRS */
| (1 << 12) /* TXER */
| (1 << 10) /* TXD2 */
| (1 << 11) /* TXD3 */
| (1 << 13) /* RXD2 */
| (1 << 14) /* RXD3 */
| (1 << 17); /* RXCK */
- if (flags & PORTMUX_MACB_SPEED)
portb_mask |= (1 << 18);/* SPD */
- /* REVISIT: Some pins are probably pure outputs */
- portmux_select_peripheral(PORTMUX_PORT_B, portb_mask,
PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
+}
+#endif
+#ifdef AT32UC3A0xxx_CHIP_HAS_SPI +void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength) +{
- unsigned long pin_mask;
- /* MOSI and SCK */
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 12) | (1 << 13),
PORTMUX_FUNC_A, 0);
- /* MISO may float */
- portmux_select_peripheral(PORTMUX_PORT_A, 1 << 11,
PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
- /* Set up NPCSx as GPIO outputs, initially high */
- pin_mask = 0;
- if (cs_mask & (1 << 0))
pin_mask |= 1 << 10;
- if (cs_mask & (1 << 1))
pin_mask |= 1 << 8;
- if (cs_mask & (1 << 2))
pin_mask |= 1 << 9;
- if (cs_mask & (1 << 3))
pin_mask |= 1 << 7;
- portmux_select_gpio(PORTMUX_PORT_A, pin_mask,
PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
+}
+void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength) +{
- unsigned long pin_mask;
- /* MOSI and SCK */
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 16) | (1 << 15),
PORTMUX_FUNC_B, 0);
- /* MISO may float */
- portmux_select_peripheral(PORTMUX_PORT_B, 1 << 17,
PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
- /* Set up NPCSx as GPIO outputs, initially high */
- pin_mask = 0;
- if (cs_mask & (1 << 0))
pin_mask |= 1 << 14;
- if (cs_mask & (1 << 1))
pin_mask |= 1 << 18;
- if (cs_mask & (1 << 2))
pin_mask |= 1 << 19;
- if (cs_mask & (1 << 3))
pin_mask |= 1 << 20;
- portmux_select_gpio(PORTMUX_PORT_A, pin_mask,
PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
+} +#endif
diff --git a/cpu/at32uc/at32uc3a0xxx/sm.h b/cpu/at32uc/at32uc3a0xxx/sm.h new file mode 100644 index 0000000..d232f91 --- /dev/null +++ b/cpu/at32uc/at32uc3a0xxx/sm.h @@ -0,0 +1,272 @@ +/*
- Register definitions for System Manager
- */
+#ifndef __CPU_AT32UC_SM_H__ +#define __CPU_AT32UC_SM_H__
+/* SM register offsets */ +/* PM starts at 0xFFFF0C00 */ +#define SM_PM_REGS_OFFSET 0x0c00 +#define SM_PM_MCCTRL (SM_PM_REGS_OFFSET + 0x0000) +#define SM_PM_CKSEL (SM_PM_REGS_OFFSET + 0x0004) +#define SM_PM_CPU_MASK (SM_PM_REGS_OFFSET + 0x0008) +#define SM_PM_HSB_MASK (SM_PM_REGS_OFFSET + 0x000c) +#define SM_PM_PBA_MASK (SM_PM_REGS_OFFSET + 0x0010) +#define SM_PM_PBB_MASK (SM_PM_REGS_OFFSET + 0x0014) +#define SM_PM_PLL0 (SM_PM_REGS_OFFSET + 0x0020) +#define SM_PM_PLL1 (SM_PM_REGS_OFFSET + 0x0024) +#define SM_PM_OSCCTRL0 (SM_PM_REGS_OFFSET + 0x0028) +#define SM_PM_OSCCTRL1 (SM_PM_REGS_OFFSET + 0x002c) +#define SM_PM_OSCCTRL32 (SM_PM_REGS_OFFSET + 0x0030) +#define SM_PM_IER (SM_PM_REGS_OFFSET + 0x0040) +#define SM_PM_IDR (SM_PM_REGS_OFFSET + 0x0044) +#define SM_PM_IMR (SM_PM_REGS_OFFSET + 0x0048) +#define SM_PM_ISR (SM_PM_REGS_OFFSET + 0x004c) +#define SM_PM_ICR (SM_PM_REGS_OFFSET + 0x0050) +#define SM_PM_POSCSR (SM_PM_REGS_OFFSET + 0x0054) +#define SM_PM_GCCTRL (SM_PM_REGS_OFFSET + 0x0060) +#define SM_PM_RCCR (SM_PM_REGS_OFFSET + 0x00c0) +#define SM_PM_BGCR (SM_PM_REGS_OFFSET + 0x00c4) +#define SM_PM_VREGCR (SM_PM_REGS_OFFSET + 0x00c8) +#define SM_PM_BOD (SM_PM_REGS_OFFSET + 0x00d0) +#define SM_PM_RCAUSE (SM_PM_REGS_OFFSET + 0x0140) +#define SM_RC_RCAUSE SM_PM_RCAUSE /* TODO: remove */ +/* RTC starts at 0xFFFF0D00 */ +#define SM_RTC_REGS_OFFSET 0x0d00 +#define SM_RTC_CTRL (SM_RTC_REGS_OFFSET + 0x0000) +#define SM_RTC_VAL (SM_RTC_REGS_OFFSET + 0x0004) +#define SM_RTC_TOP (SM_RTC_REGS_OFFSET + 0x0008) +#define SM_RTC_IER (SM_RTC_REGS_OFFSET + 0x0010) +#define SM_RTC_IDR (SM_RTC_REGS_OFFSET + 0x0014) +#define SM_RTC_IMR (SM_RTC_REGS_OFFSET + 0x0018) +#define SM_RTC_ISR (SM_RTC_REGS_OFFSET + 0x001c) +#define SM_RTC_ICR (SM_RTC_REGS_OFFSET + 0x0020) +/* WDT starts at 0xFFFF0D30 */ +#define SM_WDT_REGS_OFFSET 0x0d30 +#define SM_WDT_CTRL (SM_WDT_REGS_OFFSET + 0x0000) +#define SM_WDT_CLR (SM_WDT_REGS_OFFSET + 0x0004) +#define SM_WDT_EXT (SM_WDT_REGS_OFFSET + 0x0008) /* TODO: does not exist ? */ +/* EIC starts at offset 0xFFFF0D80 */ +/* TODO: change EIM to EIC */ +#define SM_EIC_REGS_OFFSET 0x0d80 +#define SM_EIM_IER (SM_EIC_REGS_OFFSET + 0x0000) +#define SM_EIM_IDR (SM_EIC_REGS_OFFSET + 0x0004) +#define SM_EIM_IMR (SM_EIC_REGS_OFFSET + 0x0008) +#define SM_EIM_ISR (SM_EIC_REGS_OFFSET + 0x000c) +#define SM_EIM_ICR (SM_EIC_REGS_OFFSET + 0x0010) +#define SM_EIM_MODE (SM_EIC_REGS_OFFSET + 0x0014) +#define SM_EIM_EDGE (SM_EIC_REGS_OFFSET + 0x0018) +#define SM_EIM_LEVEL (SM_EIC_REGS_OFFSET + 0x001c) +#define SM_EIM_FILTER (SM_EIC_REGS_OFFSET + 0x0020) +#define SM_EIM_TEST (SM_EIC_REGS_OFFSET + 0x0024) +#define SM_EIM_ASYNC (SM_EIC_REGS_OFFSET + 0x0028) +#define SM_EIM_SCAN (SM_EIC_REGS_OFFSET + 0x002c) +#define SM_EIM_EN (SM_EIC_REGS_OFFSET + 0x0030) +#define SM_EIM_DIS (SM_EIC_REGS_OFFSET + 0x0034) +#define SM_EIM_CTRL (SM_EIC_REGS_OFFSET + 0x0038)
+/* Bitfields used in many registers */ +#define SM_EN_OFFSET 0 +#define SM_EN_SIZE 1
+/* Bitfields in PM_MCCTRL */ +#define SM_MCSEL_OFFSET 0 +#define SM_MCSEL_SIZE 2 +#define SM_OSC0EN_OFFSET 2 +#define SM_OSC0EN_SIZE 1 +#define SM_OSC1EN_OFFSET 3 +#define SM_OSC1EN_SIZE 1
+/* Bitfields in PM_CKSEL */ +#define SM_CPUSEL_OFFSET 0 +#define SM_CPUSEL_SIZE 3 +#define SM_CPUDIV_OFFSET 7 +#define SM_CPUDIV_SIZE 1 +#define SM_HSBSEL_OFFSET 8 +#define SM_HSBSEL_SIZE 3 +#define SM_HSBDIV_OFFSET 15 +#define SM_HSBDIV_SIZE 1 +#define SM_PBASEL_OFFSET 16 +#define SM_PBASEL_SIZE 3 +#define SM_PBADIV_OFFSET 23 +#define SM_PBADIV_SIZE 1 +#define SM_PBBSEL_OFFSET 24 +#define SM_PBBSEL_SIZE 3 +#define SM_PBBDIV_OFFSET 31 +#define SM_PBBDIV_SIZE 1
+/* Bitfields in PM_PLL0 */ +#define SM_PLLEN_OFFSET 0 +#define SM_PLLEN_SIZE 1 +#define SM_PLLOSC_OFFSET 1 +#define SM_PLLOSC_SIZE 1 +#define SM_PLLOPT_OFFSET 2 +#define SM_PLLOPT_SIZE 3 +#define SM_ERRATA_OFFSET 7 +#define SM_ERRATA_SIZE 1 +#define SM_PLLDIV_OFFSET 8 +#define SM_PLLDIV_SIZE 4 +#define SM_PLLMUL_OFFSET 16 +#define SM_PLLMUL_SIZE 4 +#define SM_PLLCOUNT_OFFSET 24 +#define SM_PLLCOUNT_SIZE 6 +#define SM_PLLTEST_OFFSET 31 /* TODO: remove */ +#define SM_PLLTEST_SIZE 1 /* TODO: remove */
+/* Bitfields in PM_OSCCTRL0,1 */ +#define SM_MODE_OFFSET 0 +#define SM_MODE_SIZE 3 +#define SM_STARTUP_OFFSET 8 +#define SM_STARTUP_SIZE 3
+/* Bitfields in PM_VCTRL */ +#define SM_VAUTO_OFFSET 0 /* TODO: remove */ +#define SM_VAUTO_SIZE 1 /* TODO: remove */ +#define SM_PM_VCTRL_VAL_OFFSET 8 /* TODO: remove */ +#define SM_PM_VCTRL_VAL_SIZE 7 /* TODO: remove */
+/* Bitfields in PM_VMREF */ +#define SM_REFSEL_OFFSET 0 /* TODO: remove */ +#define SM_REFSEL_SIZE 4 /* TODO: remove */
+/* Bitfields in PM_VMV */ +#define SM_PM_VMV_VAL_OFFSET 0 /* TODO: remove */ +#define SM_PM_VMV_VAL_SIZE 8 /* TODO: remove */
+/* Bitfields in PM_IER/IDR/IMR/ISR/ICR, POSCSR */ +#define SM_LOCK0_OFFSET 0 +#define SM_LOCK0_SIZE 1 +#define SM_LOCK1_OFFSET 1 +#define SM_LOCK1_SIZE 1 +#define SM_WAKE_OFFSET 2 /* TODO: remove */ +#define SM_WAKE_SIZE 1 /* TODO: remove */ +#define SM_VOK_OFFSET 3 /* TODO: remove */ +#define SM_VOK_SIZE 1 /* TODO: remove */ +#define SM_VMRDY_OFFSET 4 /* TODO: remove */ +#define SM_VMRDY_SIZE 1 /* TODO: remove */ +#define SM_CKRDY_OFFSET 5 +#define SM_CKRDY_SIZE 1 +#define SM_MSKRDY_OFFSET 6 +#define SM_MSKRDY_SIZE 1 +#define SM_OSC0RDY_OFFSET 7 +#define SM_OSC0RDY_SIZE 1 +#define SM_OSC1RDY_OFFSET 8 +#define SM_OSC1RDY_SIZE 1 +#define SM_OSC32RDY_OFFSET 9 +#define SM_OSC32RDY_SIZE 1 +#define SM_BODDET_OFFSET 16 +#define SM_BODDET_SIZE 1
+/* Bitfields in PM_GCCTRL*/ +#define SM_OSCSEL_OFFSET 0 +#define SM_OSCSEL_SIZE 1 +#define SM_PLLSEL_OFFSET 1 +#define SM_PLLSEL_SIZE 1 +#define SM_CEN_OFFSET 2 +#define SM_CEN_SIZE 1 +#define SM_DIVEN_OFFSET 4 +#define SM_DIVEN_SIZE 1 +#define SM_DIV_OFFSET 8 +#define SM_DIV_SIZE 8
+/* Bitfields in PM_RCAUSE */ +#define SM_POR_OFFSET 0 +#define SM_POR_SIZE 1 +#define SM_BOD_OFFSET 1 +#define SM_BOD_SIZE 1 +#define SM_EXT_OFFSET 2 +#define SM_EXT_SIZE 1 +#define SM_WDT_OFFSET 3 +#define SM_WDT_SIZE 1 +#define SM_JTAG_OFFSET 4 +#define SM_JTAG_SIZE 1 +#define SM_SERP_OFFSET 5 /* TODO: remove */ +#define SM_SERP_SIZE 1 /* TODO: remove */ +#define SM_CPUERR_OFFSET 7 +#define SM_CPUERR_SIZE 1 +#define SM_OCDRST_OFFSET 8 +#define SM_OCDRST_SIZE 1 +#define SM_JTAGHARD_OFFSET 9 +#define SM_JTAGHARD_SIZE 1
+/* Bitfields in RTC_CTRL */ +#define SM_PCLR_OFFSET 1 +#define SM_PCLR_SIZE 1 +#define SM_WAKE_EN_OFFSET 2 +#define SM_WAKE_EN_SIZE 1 +#define SM_CLK32_OFFSET 3 +#define SM_CLK32_SIZE 1 +#define SM_BUSY_OFFSET 4 +#define SM_BUSY_SIZE 1 +#define SM_RTC_CTRL_PSEL_OFFSET 8 +#define SM_RTC_CTRL_PSEL_SIZE 4 +#define SM_CLKEN_OFFSET 16 +#define SM_CLKEN_SIZE 1
+/* Bitfields in RTC_VAL */ +#define SM_RTC_VAL_VAL_OFFSET 0 +#define SM_RTC_VAL_VAL_SIZE 32
+/* Bitfields in RTC_TOP */ +#define SM_RTC_TOP_VAL_OFFSET 0 +#define SM_RTC_TOP_VAL_SIZE 32
+/* Bitfields in RTC_ICR */ +#define SM_TOPI_OFFSET 0 +#define SM_TOPI_SIZE 1
+/* Bitfields in WDT_CTRL */ +#define SM_WDT_CTRL_PSEL_OFFSET 8 +#define SM_WDT_CTRL_PSEL_SIZE 5 +#define SM_KEY_OFFSET 24 +#define SM_KEY_SIZE 8
+/* Bitfields in EIC IER/IDR/IMR/ISR/ICR and MODE/EDGE/LEVEL/FILTER/ASYNC */ +#define SM_INT0_OFFSET 0 +#define SM_INT0_SIZE 1 +#define SM_INT1_OFFSET 1 +#define SM_INT1_SIZE 1 +#define SM_INT2_OFFSET 2 +#define SM_INT2_SIZE 1 +#define SM_INT3_OFFSET 3 +#define SM_INT3_SIZE 1 +#define SM_INT4_OFFSET 4 +#define SM_INT4_SIZE 1 +#define SM_INT5_OFFSET 5 +#define SM_INT5_SIZE 1 +#define SM_INT6_OFFSET 6 +#define SM_INT6_SIZE 1 +#define SM_INT7_OFFSET 7 +#define SM_INT7_SIZE 1 +#define SM_NMI_OFFSET 8 +#define SM_NMI_SIZE 1
+/* Bitfields in EIM_TEST */ +#define SM_TESTEN_OFFSET 31 +#define SM_TESTEN_SIZE 1
+/* Bit manipulation macros */ +#define SM_BIT(name) \
- (1 << SM_##name##_OFFSET)
+#define SM_BF(name,value) \
- (((value) & ((1 << SM_##name##_SIZE) - 1)) \
<< SM_##name##_OFFSET)
+#define SM_BFEXT(name,value) \
- (((value) >> SM_##name##_OFFSET) \
& ((1 << SM_##name##_SIZE) - 1))
+#define SM_BFINS(name,value,old) \
- (((old) & ~(((1 << SM_##name##_SIZE) - 1) \
<< SM_##name##_OFFSET)) \
| SM_BF(name,value))
+/* Register access macros */ +#define sm_readl(reg) \
- readl((void *)SM_BASE + SM_##reg)
+#define sm_writel(reg,value) \
- writel((value), (void *)SM_BASE + SM_##reg)
+#endif /* __CPU_AT32UC_SM_H__ */ diff --git a/cpu/at32uc/cache.c b/cpu/at32uc/cache.c new file mode 100644 index 0000000..06fa12c --- /dev/null +++ b/cpu/at32uc/cache.c @@ -0,0 +1,34 @@ +/*
- 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
- */
+#include <common.h>
+/*
- This is called after loading something into memory. We need to
- make sure that everything that was loaded is actually written to
- RAM, and that the icache will look for it. Cleaning the dcache and
- invalidating the icache will do the trick.
- */
+void flush_cache (unsigned long start_addr, unsigned long size) +{
- /* No cache to clean in the at32uc3. */
+} diff --git a/cpu/at32uc/config.mk b/cpu/at32uc/config.mk new file mode 100644 index 0000000..1a6eaa8 --- /dev/null +++ b/cpu/at32uc/config.mk @@ -0,0 +1,22 @@ +# +# 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 +# +PLATFORM_RELFLAGS += -mcpu=uc3a0512es diff --git a/cpu/at32uc/cpu.c b/cpu/at32uc/cpu.c new file mode 100644 index 0000000..4a95427 --- /dev/null +++ b/cpu/at32uc/cpu.c @@ -0,0 +1,79 @@ +/*
- 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 <common.h> +#include <command.h>
+#include <asm/io.h> +#include <asm/sections.h> +#include <asm/sysreg.h>
+#include <asm/arch/clk.h> +#include <asm/arch/memory-map.h>
+/* Sanity checks */ +#if ((CFG_CLKDIV_CPU > CFG_CLKDIV_PBA) \
- || (CFG_CLKDIV_CPU > CFG_CLKDIV_PBB))
+# error Constraint fCPU >= fPB{A,B} violated +#endif +#if defined(CONFIG_PLL) && ((CFG_PLL0_MUL < 1) || (CFG_PLL0_DIV < 0)) +# error Invalid PLL multiplier and/or divider +#endif
+DECLARE_GLOBAL_DATA_PTR;
+int cpu_init(void) +{
- extern void _evba(void);
- gd->cpu_hz = CFG_OSC0_HZ;
- clk_init();
- /* Update the CPU speed according to the PLL configuration */
- gd->cpu_hz = get_cpu_clk_rate();
- /* Set up the exception handler table and enable exceptions */
- sysreg_write(EVBA, (unsigned long)&_evba);
- asm volatile("csrf %0" : : "i"(SYSREG_EM_OFFSET));
- if(gclk_init)
gclk_init();
- return 0;
+}
+void prepare_to_boot(void) +{
- /* No caches to flush on this cpu. */
+}
+int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{
- /* This will reset the CPU core, caches, MMU and all internal busses */
- __builtin_mtdr(8, 1 << 13); /* set DC:DBE */
- __builtin_mtdr(8, 1 << 30); /* set DC:RES */
- /* Flush the pipeline before we declare it a failure */
- asm volatile("sub pc, pc, -4");
- return -1;
+} diff --git a/cpu/at32uc/exception.c b/cpu/at32uc/exception.c new file mode 100644 index 0000000..dc9c300 --- /dev/null +++ b/cpu/at32uc/exception.c @@ -0,0 +1,121 @@ +/*
- 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 <common.h>
+#include <asm/sysreg.h> +#include <asm/ptrace.h>
+DECLARE_GLOBAL_DATA_PTR;
+static const char * const cpu_modes[8] = {
- "Application", "Supervisor", "Interrupt level 0", "Interrupt level 1",
- "Interrupt level 2", "Interrupt level 3", "Exception", "NMI"
+};
+static void dump_mem(const char *str, unsigned long bottom, unsigned long top) +{
- unsigned long p;
- int i;
- printf("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
- for (p = bottom & ~31; p < top; ) {
printf("%04lx: ", p & 0xffff);
for (i = 0; i < 8; i++, p += 4) {
unsigned int val;
if (p < bottom || p >= top)
printf(" ");
else {
val = *(unsigned long *)p;
printf("%08x ", val);
}
}
printf("\n");
- }
+}
+void do_unknown_exception(unsigned int ecr, struct pt_regs *regs) +{
- unsigned int mode;
- printf("\n *** Unhandled exception %u at PC=0x%08lx\n", ecr, regs->pc);
- switch (ecr) {
- case ECR_BUS_ERROR_WRITE:
- case ECR_BUS_ERROR_READ:
printf("Bus error at address 0x%08lx\n",
sysreg_read(BEAR));
break;
- case ECR_TLB_MULTIPLE:
- case ECR_ADDR_ALIGN_X:
- case ECR_PROTECTION_X:
- case ECR_ADDR_ALIGN_R:
- case ECR_ADDR_ALIGN_W:
- case ECR_PROTECTION_R:
- case ECR_PROTECTION_W:
- case ECR_DTLB_MODIFIED:
- case ECR_TLB_MISS_X:
- case ECR_TLB_MISS_R:
- case ECR_TLB_MISS_W:
printf("MMU exception at address 0x%08lx\n",
sysreg_read(TLBEAR));
break;
- }
- printf(" pc: %08lx lr: %08lx sp: %08lx r12: %08lx\n",
regs->pc, regs->lr, regs->sp, regs->r12);
- printf(" r11: %08lx r10: %08lx r9: %08lx r8: %08lx\n",
regs->r11, regs->r10, regs->r9, regs->r8);
- printf(" r7: %08lx r6: %08lx r5: %08lx r4: %08lx\n",
regs->r7, regs->r6, regs->r5, regs->r4);
- printf(" r3: %08lx r2: %08lx r1: %08lx r0: %08lx\n",
regs->r3, regs->r2, regs->r1, regs->r0);
- printf("Flags: %c%c%c%c%c\n",
regs->sr & SR_Q ? 'Q' : 'q',
regs->sr & SR_V ? 'V' : 'v',
regs->sr & SR_N ? 'N' : 'n',
regs->sr & SR_Z ? 'Z' : 'z',
regs->sr & SR_C ? 'C' : 'c');
- printf("Mode bits: %c%c%c%c%c%c%c%c%c\n",
regs->sr & SR_H ? 'H' : 'h',
regs->sr & SR_R ? 'R' : 'r',
regs->sr & SR_J ? 'J' : 'j',
regs->sr & SR_EM ? 'E' : 'e',
regs->sr & SR_I3M ? '3' : '.',
regs->sr & SR_I2M ? '2' : '.',
regs->sr & SR_I1M ? '1' : '.',
regs->sr & SR_I0M ? '0' : '.',
regs->sr & SR_GM ? 'G' : 'g');
- mode = (regs->sr >> SYSREG_M0_OFFSET) & 7;
- printf("CPU Mode: %s\n", cpu_modes[mode]);
- /* Avoid exception loops */
- if (regs->sp < (gd->stack_end - CONFIG_STACKSIZE)
|| regs->sp >= gd->stack_end)
printf("\nStack pointer seems bogus, won't do stack dump\n");
- else
dump_mem("\nStack: ", regs->sp, gd->stack_end);
- panic("Unhandled exception\n");
+} diff --git a/cpu/at32uc/flashc.c b/cpu/at32uc/flashc.c new file mode 100644 index 0000000..f33a4bb --- /dev/null +++ b/cpu/at32uc/flashc.c @@ -0,0 +1,80 @@ +/*
- 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 <common.h>
+#include <asm/io.h> +#include <asm/arch/memory-map.h> +#include "flashc.h"
+DECLARE_GLOBAL_DATA_PTR;
+/* Flash sizes in KB as returned by FSZ bitfield in FSR */ +const unsigned long flash_sizes[8] = {
- 32,
- 64,
- 128,
- 256,
- 384,
- 512,
- 768,
- 1024
+};
+flash_info_t flash_info[1];
+unsigned long flash_init(void) +{
- unsigned long fsz;
- unsigned long size;
- fsz = FLASHC_BFEXT(FSZ, flashc_readl(FSR));
- size = flash_sizes[fsz] * 1024;
- flash_info[0].size = size;
- /* Currently, all interflash have pages which are 128 words. */
- flash_info[0].sector_count = size / (128*4);
- return size;
+}
+void flash_print_info(flash_info_t *info) +{
- printf("Flash: Vendor ID: 0x%02lx, Product ID: 0x%02lx\n",
info->flash_id >> 16, info->flash_id & 0xffff);
- printf("Size: %ld MB in %d sectors\n",
info->size >> 10, info->sector_count);
+}
+int flash_erase(flash_info_t *info, int s_first, int s_last) +{
- /* TODO */
- return ERR_OK;
+}
+int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong count) +{
- /* TODO */
- return ERR_OK;
+}
diff --git a/cpu/at32uc/flashc.h b/cpu/at32uc/flashc.h new file mode 100644 index 0000000..23618bc --- /dev/null +++ b/cpu/at32uc/flashc.h @@ -0,0 +1,67 @@ +/*
- Register definitions for flash controller
- */
+#ifndef __ASM_AVR32_FLASHC_H__ +#define __ASM_AVR32_FLASHC_H__
+/* FLASHC register offsets */ +#define FLASHC_FCR 0x0000 +#define FLASHC_FCMD 0x0004 +#define FLASHC_FSR 0x0008 +#define FLASHC_FGPFRHI 0x000c +#define FLASHC_FGPFRLO 0x0010
+/* Bitfields in FCR and FSR */ +#define FLASHC_FRDY_OFFSET 0 +#define FLASHC_FRDY_SIZE 1 +#define FLASHC_LOCKE_OFFSET 2 +#define FLASHC_LOCKE_SIZE 1 +#define FLASHC_PROGE_OFFSET 3 +#define FLASHC_PROGE_SIZE 1
+/* Bitfields in FCR */ +#define FLASHC_FWS_OFFSET 6 +#define FLASHC_FWS_SIZE 1 +#define FLASHC_SASD_OFFSET 8 +#define FLASHC_SASD_SIZE 1
+/* Bitfields in FCMD */ +#define FLASHC_CMD_OFFSET 0 +#define FLASHC_CMD_SIZE 6 +#define FLASHC_PAGEN_OFFSET 8 +#define FLASHC_PAGEN_SIZE 16 +#define FLASHC_KEY_OFFSET 24 +#define FLASHC_KEY_SIZE 8
+/* Bitfields in FSR */ +#define FLASHC_SECURITY_OFFSET 4 +#define FLASHC_SECURITY_SIZE 1 +#define FLASHC_QPRR_OFFSET 5 +#define FLASHC_QPRR_SIZE 1 +#define FLASHC_FSZ_OFFSET 13 +#define FLASHC_FSZ_SIZE 3 +#define FLASHC_LOCK_OFFSET 16 +#define FLASHC_LOCK_SIZE 16
+/* Bit manipulation macros */ +#define FLASHC_BIT(name) \
- (1 << FLASHC_##name##_OFFSET)
+#define FLASHC_BF(name,value) \
- (((value) & ((1 << FLASHC_##name##_SIZE) - 1)) \
<< FLASHC_##name##_OFFSET)
+#define FLASHC_BFEXT(name,value) \
- (((value) >> FLASHC_##name##_OFFSET) \
& ((1 << FLASHC_##name##_SIZE) - 1))
+#define FLASHC_BFINS(name,value,old) \
- (((old) & ~(((1 << FLASHC_##name##_SIZE) - 1) \
<< FLASHC_##name##_OFFSET)) \
| FLASHC_BF(name,value))
+/* Register access macros */ +#define flashc_readl(reg) \
- readl((void *)FLASHC_BASE + FLASHC_##reg)
+#define flashc_writel(reg,value) \
- writel((value), (void *)FLASHC_BASE + FLASHC_##reg)
+#endif /* __ASM_AVR32_FLASHC_H__ */ diff --git a/cpu/at32uc/interrupts.c b/cpu/at32uc/interrupts.c new file mode 100644 index 0000000..160838e --- /dev/null +++ b/cpu/at32uc/interrupts.c @@ -0,0 +1,150 @@ +/*
- 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
- */
+#include <common.h> +#include <div64.h>
+#include <asm/errno.h> +#include <asm/io.h> +#include <asm/processor.h> +#include <asm/sysreg.h>
+#include <asm/arch/memory-map.h>
+#define HANDLER_MASK 0x00ffffff +#define INTLEV_SHIFT 30 +#define INTLEV_MASK 0x00000003
+DECLARE_GLOBAL_DATA_PTR;
+/* Incremented whenever COUNT reaches 0xffffffff by timer_interrupt_handler */ +volatile unsigned long timer_overflow;
+/*
- Instead of dividing by get_tbclk(), multiply by this constant and
- right-shift the result by 32 bits.
- */
+static unsigned long tb_factor;
+unsigned long get_tbclk(void) +{
- return gd->cpu_hz;
+}
+unsigned long long get_ticks(void) +{
- unsigned long lo, hi_now, hi_prev;
- do {
hi_prev = timer_overflow;
lo = sysreg_read(COUNT);
hi_now = timer_overflow;
- } while (hi_prev != hi_now);
- return ((unsigned long long)hi_now << 32) | lo;
+}
+void reset_timer(void) +{
- sysreg_write(COUNT, 0);
- cpu_sync_pipeline(); /* process any pending interrupts */
- timer_overflow = 0;
+}
+unsigned long get_timer(unsigned long base) +{
- u64 now = get_ticks();
- now *= tb_factor;
- return (unsigned long)(now >> 32) - base;
+}
+void set_timer(unsigned long t) +{
- unsigned long long ticks = t;
- unsigned long lo, hi, hi_new;
- ticks = (ticks * get_tbclk()) / CFG_HZ;
- hi = ticks >> 32;
- lo = ticks & 0xffffffffUL;
- do {
timer_overflow = hi;
sysreg_write(COUNT, lo);
hi_new = timer_overflow;
- } while (hi_new != hi);
+}
+/*
- For short delays only. It will overflow after a few seconds.
- */
+void udelay(unsigned long usec) +{
- unsigned long cycles;
- unsigned long base;
- unsigned long now;
- base = sysreg_read(COUNT);
- cycles = ((usec * (get_tbclk() / 10000)) + 50) / 100;
- do {
now = sysreg_read(COUNT);
- } while ((now - base) < cycles);
+}
+static int set_interrupt_handler(unsigned int nr, void (*handler)(void),
unsigned int priority)
+{
- extern void _evba(void);
- unsigned long intpr;
- unsigned long handler_addr = (unsigned long)handler;
- handler_addr -= (unsigned long)&_evba;
- if ((handler_addr & HANDLER_MASK) != handler_addr
|| (priority & INTLEV_MASK) != priority)
return -EINVAL;
- intpr = (handler_addr & HANDLER_MASK);
- intpr |= (priority & INTLEV_MASK) << INTLEV_SHIFT;
- writel(intpr, (void *)INTC_BASE + 4 * nr);
- return 0;
+}
+void timer_init(void) +{
- extern void timer_interrupt_handler(void);
- u64 tmp;
- sysreg_write(COUNT, 0);
- tmp = (u64)CFG_HZ << 32;
- tmp += gd->cpu_hz / 2;
- do_div(tmp, gd->cpu_hz);
- tb_factor = (u32)tmp;
- if (set_interrupt_handler(0, &timer_interrupt_handler, 3))
return;
- /* For all practical purposes, this gives us an overflow interrupt */
- sysreg_write(COMPARE, 0xffffffff);
+} diff --git a/cpu/at32uc/portmux-gpio.c b/cpu/at32uc/portmux-gpio.c new file mode 100644 index 0000000..8ed5659 --- /dev/null +++ b/cpu/at32uc/portmux-gpio.c @@ -0,0 +1,108 @@ +/*
- Copyright (C) 2008 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/io.h> +#include <asm/arch/memory-map.h> +#include <asm/arch-common/portmux-gpio.h>
+void portmux_select_peripheral(void *port, unsigned long pin_mask,
enum portmux_function func, unsigned long flags)
+{
- /* Both pull-up and pull-down set means buskeeper */
- if (flags & PORTMUX_PULL_DOWN)
gpio_writel(port, PDERS, pin_mask);
- else
gpio_writel(port, PDERC, pin_mask);
- if (flags & PORTMUX_PULL_UP)
gpio_writel(port, PUERS, pin_mask);
- else
gpio_writel(port, PUERC, pin_mask);
- /* Select drive strength */
- if (flags & PORTMUX_DRIVE_LOW)
gpio_writel(port, ODCR0S, pin_mask);
- else
gpio_writel(port, ODCR0C, pin_mask);
- if (flags & PORTMUX_DRIVE_HIGH)
gpio_writel(port, ODCR1S, pin_mask);
- else
gpio_writel(port, ODCR1C, pin_mask);
- /* Select function */
- if (func & PORTMUX_FUNC_B)
gpio_writel(port, PMR0S, pin_mask);
- else
gpio_writel(port, PMR0C, pin_mask);
- if (func & PORTMUX_FUNC_C)
gpio_writel(port, PMR1S, pin_mask);
- else
gpio_writel(port, PMR1C, pin_mask);
- /* Disable GPIO (i.e. enable peripheral) */
- gpio_writel(port, GPERC, pin_mask);
+}
+void portmux_select_gpio(void *port, unsigned long pin_mask,
unsigned long flags)
+{
- /* Both pull-up and pull-down set means buskeeper */
- if (flags & PORTMUX_PULL_DOWN)
gpio_writel(port, PDERS, pin_mask);
- else
gpio_writel(port, PDERC, pin_mask);
- if (flags & PORTMUX_PULL_UP)
gpio_writel(port, PUERS, pin_mask);
- else
gpio_writel(port, PUERC, pin_mask);
- /* Enable open-drain mode if requested */
- if (flags & PORTMUX_OPEN_DRAIN)
gpio_writel(port, ODMERS, pin_mask);
- else
gpio_writel(port, ODMERC, pin_mask);
- /* Select drive strength */
- if (flags & PORTMUX_DRIVE_LOW)
gpio_writel(port, ODCR0S, pin_mask);
- else
gpio_writel(port, ODCR0C, pin_mask);
- if (flags & PORTMUX_DRIVE_HIGH)
gpio_writel(port, ODCR1S, pin_mask);
- else
gpio_writel(port, ODCR1C, pin_mask);
- /* Select direction and initial pin state */
- if (flags & PORTMUX_DIR_OUTPUT) {
if (flags & PORTMUX_INIT_HIGH)
gpio_writel(port, OVRS, pin_mask);
else
gpio_writel(port, OVRC, pin_mask);
gpio_writel(port, ODERS, pin_mask);
- } else {
gpio_writel(port, ODERC, pin_mask);
- }
- /* Enable GPIO */
- gpio_writel(port, GPERS, pin_mask);
+} diff --git a/cpu/at32uc/sdramc.c b/cpu/at32uc/sdramc.c new file mode 100644 index 0000000..2ed0066 --- /dev/null +++ b/cpu/at32uc/sdramc.c @@ -0,0 +1,120 @@ +/*
- 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 <common.h>
+#ifdef CFG_SDRAMC +#include <asm/io.h> +#include <asm/sdram.h>
+#include <asm/arch/clk.h> +#include <asm/arch/memory-map.h>
+#include "sdramc.h"
+unsigned long sdram_init(void *sdram_base, const struct sdram_config *config) +{
- unsigned long sdram_size;
- uint32_t cfgreg;
- unsigned int i;
- cfgreg = (SDRAMC_BF(NC, config->col_bits - 8)
| SDRAMC_BF(NR, config->row_bits - 11)
| SDRAMC_BF(NB, config->bank_bits - 1)
| SDRAMC_BF(CAS, config->cas)
| SDRAMC_BF(TWR, config->twr)
| SDRAMC_BF(TRC, config->trc)
| SDRAMC_BF(TRP, config->trp)
| SDRAMC_BF(TRCD, config->trcd)
| SDRAMC_BF(TRAS, config->tras)
| SDRAMC_BF(TXSR, config->txsr));
- if (config->data_bits == SDRAM_DATA_16BIT)
cfgreg |= SDRAMC_BIT(DBW);
- sdramc_writel(CR, cfgreg);
- /* Send a NOP to turn on the clock (necessary on some chips) */
- sdramc_writel(MR, SDRAMC_MODE_NOP);
- sdramc_readl(MR);
- writel(0, sdram_base);
- /*
* Initialization sequence for SDRAM, from the data sheet:
*
* 1. A minimum pause of 200 us is provided to precede any
* signal toggle.
*/
- udelay(200);
- /*
* 2. A Precharge All command is issued to the SDRAM
*/
- sdramc_writel(MR, SDRAMC_MODE_BANKS_PRECHARGE);
- sdramc_readl(MR);
- writel(0, sdram_base);
- /*
* 3. Eight auto-refresh (CBR) cycles are provided
*/
- sdramc_writel(MR, SDRAMC_MODE_AUTO_REFRESH);
- sdramc_readl(MR);
- for (i = 0; i < 8; i++)
writel(0, sdram_base);
- /*
* 4. A mode register set (MRS) cycle is issued to program
* SDRAM parameters, in particular CAS latency and burst
* length.
*
* The address will be chosen by the SDRAMC automatically; we
* just have to make sure BA[1:0] are set to 0.
*/
- sdramc_writel(MR, SDRAMC_MODE_LOAD_MODE);
- sdramc_readl(MR);
- writel(0, sdram_base);
- /*
* 5. The application must go into Normal Mode, setting Mode
* to 0 in the Mode Register and performing a write access
* at any location in the SDRAM.
*/
- sdramc_writel(MR, SDRAMC_MODE_NORMAL);
- sdramc_readl(MR);
- writel(0, sdram_base);
- /*
* 6. Write refresh rate into SDRAMC refresh timer count
* register (refresh rate = timing between refresh cycles).
*/
- sdramc_writel(TR, config->refresh_period);
- if (config->data_bits == SDRAM_DATA_16BIT)
sdram_size = 1 << (config->row_bits + config->col_bits
+ config->bank_bits + 1);
- else
sdram_size = 1 << (config->row_bits + config->col_bits
+ config->bank_bits + 2);
- return sdram_size;
+}
+#endif /* CFG_SDRAMC */ diff --git a/cpu/at32uc/sdramc.h b/cpu/at32uc/sdramc.h new file mode 100644 index 0000000..8154415 --- /dev/null +++ b/cpu/at32uc/sdramc.h @@ -0,0 +1,137 @@ +/*
- Register definitions for SDRAM Controller
- */
+#ifndef __ASM_AVR32_SDRAMC_H__ +#define __ASM_AVR32_SDRAMC_H__
+/* SDRAMC register offsets */ +#define SDRAMC_MR 0x0000 +#define SDRAMC_TR 0x0004 +#define SDRAMC_CR 0x0008 +#define SDRAMC_HSR 0x000c +#define SDRAMC_LPR 0x0010 +#define SDRAMC_IER 0x0014 +#define SDRAMC_IDR 0x0018 +#define SDRAMC_IMR 0x001c +#define SDRAMC_ISR 0x0020 +#define SDRAMC_MDR 0x0024
+/* Bitfields in MR */ +#define SDRAMC_MODE_OFFSET 0 +#define SDRAMC_MODE_SIZE 3
+/* Bitfields in TR */ +#define SDRAMC_COUNT_OFFSET 0 +#define SDRAMC_COUNT_SIZE 12
+/* Bitfields in CR */ +#define SDRAMC_NC_OFFSET 0 +#define SDRAMC_NC_SIZE 2 +#define SDRAMC_NR_OFFSET 2 +#define SDRAMC_NR_SIZE 2 +#define SDRAMC_NB_OFFSET 4 +#define SDRAMC_NB_SIZE 1 +#define SDRAMC_CAS_OFFSET 5 +#define SDRAMC_CAS_SIZE 2 +#define SDRAMC_DBW_OFFSET 7 +#define SDRAMC_DBW_SIZE 1 +#define SDRAMC_TWR_OFFSET 8 +#define SDRAMC_TWR_SIZE 4 +#define SDRAMC_TRC_OFFSET 12 +#define SDRAMC_TRC_SIZE 4 +#define SDRAMC_TRP_OFFSET 16 +#define SDRAMC_TRP_SIZE 4 +#define SDRAMC_TRCD_OFFSET 20 +#define SDRAMC_TRCD_SIZE 4 +#define SDRAMC_TRAS_OFFSET 24 +#define SDRAMC_TRAS_SIZE 4 +#define SDRAMC_TXSR_OFFSET 28 +#define SDRAMC_TXSR_SIZE 4
+/* Bitfields in HSR */ +#define SDRAMC_DA_OFFSET 0 +#define SDRAMC_DA_SIZE 1
+/* Bitfields in LPR */ +#define SDRAMC_LPCB_OFFSET 0 +#define SDRAMC_LPCB_SIZE 2 +#define SDRAMC_PASR_OFFSET 4 +#define SDRAMC_PASR_SIZE 3 +#define SDRAMC_TCSR_OFFSET 8 +#define SDRAMC_TCSR_SIZE 2 +#define SDRAMC_DS_OFFSET 10 +#define SDRAMC_DS_SIZE 2 +#define SDRAMC_TIMEOUT_OFFSET 12 +#define SDRAMC_TIMEOUT_SIZE 2
+/* Bitfields in IDR */ +#define SDRAMC_RES_OFFSET 0 +#define SDRAMC_RES_SIZE 1
+/* Bitfields in MDR */ +#define SDRAMC_MD_OFFSET 0 +#define SDRAMC_MD_SIZE 2
+/* Constants for MODE */ +#define SDRAMC_MODE_NORMAL 0 +#define SDRAMC_MODE_NOP 1 +#define SDRAMC_MODE_BANKS_PRECHARGE 2 +#define SDRAMC_MODE_LOAD_MODE 3 +#define SDRAMC_MODE_AUTO_REFRESH 4 +#define SDRAMC_MODE_EXT_LOAD_MODE 5 +#define SDRAMC_MODE_POWER_DOWN 6
+/* Constants for NC */ +#define SDRAMC_NC_8_COLUMN_BITS 0 +#define SDRAMC_NC_9_COLUMN_BITS 1 +#define SDRAMC_NC_10_COLUMN_BITS 2 +#define SDRAMC_NC_11_COLUMN_BITS 3
+/* Constants for NR */ +#define SDRAMC_NR_11_ROW_BITS 0 +#define SDRAMC_NR_12_ROW_BITS 1 +#define SDRAMC_NR_13_ROW_BITS 2
+/* Constants for NB */ +#define SDRAMC_NB_TWO_BANKS 0 +#define SDRAMC_NB_FOUR_BANKS 1
+/* Constants for CAS */ +#define SDRAMC_CAS_ONE_CYCLE 1 +#define SDRAMC_CAS_TWO_CYCLES 2 +#define SDRAMC_CAS_THREE_CYCLES 3
+/* Constants for DBW */ +#define SDRAMC_DBW_32_BITS 0 +#define SDRAMC_DBW_16_BITS 1
+/* Constants for TIMEOUT */ +#define SDRAMC_TIMEOUT_AFTER_END 0 +#define SDRAMC_TIMEOUT_64_CYC_AFTER_END 1 +#define SDRAMC_TIMEOUT_128_CYC_AFTER_END 2
+/* Constants for MD */ +#define SDRAMC_MD_SDRAM 0 +#define SDRAMC_MD_LOW_POWER_SDRAM 1
+/* Bit manipulation macros */ +#define SDRAMC_BIT(name) \
- (1 << SDRAMC_##name##_OFFSET)
+#define SDRAMC_BF(name,value) \
- (((value) & ((1 << SDRAMC_##name##_SIZE) - 1)) \
<< SDRAMC_##name##_OFFSET)
+#define SDRAMC_BFEXT(name,value) \
- (((value) >> SDRAMC_##name##_OFFSET) \
& ((1 << SDRAMC_##name##_SIZE) - 1))
+#define SDRAMC_BFINS(name,value,old) \
- (((old) & ~(((1 << SDRAMC_##name##_SIZE) - 1) \
<< SDRAMC_##name##_OFFSET)) \
| SDRAMC_BF(name,value))
+/* Register access macros */ +#define sdramc_readl(reg) \
- readl((void *)SDRAMC_BASE + SDRAMC_##reg)
+#define sdramc_writel(reg,value) \
- writel((value), (void *)SDRAMC_BASE + SDRAMC_##reg)
+#endif /* __ASM_AVR32_SDRAMC_H__ */ diff --git a/cpu/at32uc/start.S b/cpu/at32uc/start.S new file mode 100644 index 0000000..e1d44cb --- /dev/null +++ b/cpu/at32uc/start.S @@ -0,0 +1,265 @@ +/*
- Copyright (C) 2005-2008 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 <config.h> +#include <asm/ptrace.h> +#include <asm/sysreg.h>
+#define SR_INIT (SYSREG_BIT(GM) | SYSREG_BIT(EM) | SYSREG_BIT(M0)) +#define CPUCR_INIT (SYSREG_BIT(BI) | SYSREG_BIT(BE) \
| SYSREG_BIT(FE) | SYSREG_BIT(RE) \
| SYSREG_BIT(IBE) | SYSREG_BIT(IEE))
- /*
* To save some space, we use the same entry point for
* exceptions and reset. This avoids lots of alignment padding
* since the reset vector is always suitably aligned.
*/
- .section .exception.text, "ax", @progbits
- .global _start
- .global _evba
- .type _start, @function
- .type _evba, @function
+_start:
- .size _start, 0
+_evba:
- .org 0x00
- rjmp unknown_exception /* Unrecoverable exception */
- .org 0x04
- rjmp unknown_exception /* TLB multiple hit */
- .org 0x08
- rjmp unknown_exception /* Bus error data fetch */
- .org 0x0c
- rjmp unknown_exception /* Bus error instruction fetch */
- .org 0x10
- rjmp unknown_exception /* NMI */
- .org 0x14
- rjmp unknown_exception /* Instruction address */
- .org 0x18
- rjmp unknown_exception /* ITLB protection */
- .org 0x1c
- rjmp unknown_exception /* Breakpoint */
- .org 0x20
- rjmp unknown_exception /* Illegal opcode */
- .org 0x24
- rjmp unknown_exception /* Unimplemented instruction */
- .org 0x28
- rjmp unknown_exception /* Privilege violation */
- .org 0x2c
- rjmp unknown_exception /* Floating-point */
- .org 0x30
- rjmp unknown_exception /* Coprocessor absent */
- .org 0x34
- rjmp unknown_exception /* Data Address (read) */
- .org 0x38
- rjmp unknown_exception /* Data Address (write) */
- .org 0x3c
- rjmp unknown_exception /* DTLB Protection (read) */
- .org 0x40
- rjmp unknown_exception /* DTLB Protection (write) */
- .org 0x44
- rjmp unknown_exception /* DTLB Modified */
- .org 0x50
- rjmp unknown_exception /* ITLB Miss */
- .org 0x60
- rjmp unknown_exception /* DTLB Miss (read) */
- .org 0x70
- rjmp unknown_exception /* DTLB Miss (write) */
- .size _evba, . - _evba
- .align 2
- .type unknown_exception, @function
+unknown_exception:
- /* Figure out whether we're handling an exception (Exception
* mode) or just booting (Supervisor mode). */
- csrfcz SYSREG_M1_OFFSET
- brcc at32uc_cpu_bootstrap
- /* This is an exception. Complain. */
- pushm r0-r12
- sub r8, sp, REG_R12 - REG_R0 - 4*3
- mov r9, lr
- ld.w r10, r8[-4]
- ld.w r11, r8[-8]
- pushm r8-r11
- mfsr r12, SYSREG_ECR
- mov r11, sp
- rcall do_unknown_exception
+1: rjmp 1b
- /* The COUNT/COMPARE timer interrupt handler */
- .global timer_interrupt_handler
- .type timer_interrupt_handler,@function
- .align 2
+timer_interrupt_handler:
- /*
* Increment timer_overflow and re-write COMPARE with 0xffffffff.
*
* We're running at interrupt level 3, so we don't need to save
* r8-r12 or lr to the stack.
*/
- lda.w r8, timer_overflow
- ld.w r9, r8[0]
- mov r10, -1
- mtsr SYSREG_COMPARE, r10
- sub r9, -1
- st.w r8[0], r9
- rete
- /*
* CPU bootstrap after reset is handled here. SoC code may
* override this in case they need to initialize oscillators,
* etc.
*/
- .section .text.at32uc_cpu_bootstrap, "ax", @progbits
- .global at32uc_cpu_bootstrap
- .weak at32uc_cpu_bootstrap
- .type at32uc_cpu_bootstrap, @function
- .align 2
+at32uc_cpu_bootstrap:
- /* Reset the Status Register */
- mov r0, lo(SR_INIT)
- orh r0, hi(SR_INIT)
- mtsr SYSREG_SR, r0
- /* ERRATA: two NOPs required after mtsr which may mask interrupts. */
- nop
- nop
- /* Reset CPUCR and invalidate the BTB */
- mov r2, CPUCR_INIT
- mtsr SYSREG_CPUCR, r2
- /* Internal RAM should not need any initialization. We might
have to initialize external RAM here if the part doesn't
have internal RAM (or we may use the data cache) */
- lddpc sp, sp_init
- /* Initialize the GOT pointer */
- lddpc r6, got_init
+3: rsub r6, pc
- /* Let's go */
- rjmp board_init_f
- .align 2
- .type sp_init,@object
+sp_init:
- .long CFG_INIT_SP_ADDR
+got_init:
- .long 3b - _GLOBAL_OFFSET_TABLE_
- /*
* void relocate_code(new_sp, new_gd, monitor_addr)
*
* Relocate the u-boot image into RAM and continue from there.
* Does not return.
*/
- .section .text.relocate_code,"ax",@progbits
- .global relocate_code
- .type relocate_code,@function
+relocate_code:
- mov sp, r12 /* use new stack */
- mov r12, r11 /* save new_gd */
- mov r11, r10 /* save destination address */
- /* copy .text section */
- lda.w r8, _text
- lda.w r9, _etext
- sub lr, r10, r8 /* relocation offset */
+1: ldm r8++, r0-r3
- stm r10, r0-r3
- sub r10, -16
- ldm r8++, r0-r3
- stm r10, r0-r3
- sub r10, -16
- cp.w r8, r9
- brlt 1b
- /* copy data sections */
- lda.w r9, _edata
+1: ld.d r0, r8++
- st.d r10++, r0
- cp.w r8, r9
- brlt 1b
- /* zero out .bss */
- mov r0, 0
- mov r1, 0
- lda.w r9, _end
- sub r9, r8
+1: st.d r10++, r0
- sub r9, 8
- brgt 1b
- /* jump to RAM */
- /* we don't want to run from sdram.
- sub r0, pc, . - in_ram
- add pc, r0, lr
- */
- .align 2
+in_ram:
- /* find the new GOT and relocate it */
- lddpc r6, got_init_reloc
+3: rsub r6, pc
- add r6, lr
- mov r8, r6
- lda.w r9, _egot
- lda.w r10, _got
- sub r9, r10
- lda.w r1, _end_noreloc
+1: ld.w r0, r8[0]
- /* Check if the symbol points to the text-section, and
* skip relocation if they do.
*/
- cp.w r0, r1
- brlt 2f
- add r0, lr
- st.w r8, r0
+2:
- sub r8, -4
- sub r9, 4
- brgt 1b
- /* Move the exception handlers */
- /* We don't want to run from sdram.
- mfsr r2, SYSREG_EVBA
- add r2, lr
- mtsr SYSREG_EVBA, r2
- */
- /* Do the rest of the initialization sequence */
- call board_init_r
- .align 2
+got_init_reloc:
- .long 3b - _GLOBAL_OFFSET_TABLE_
- .size relocate_code, . - relocate_code
diff --git a/include/asm-avr32/arch-at32uc3a0xxx/addrspace.h b/include/asm-avr32/arch-at32uc3a0xxx/addrspace.h new file mode 100644 index 0000000..90feed7 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/addrspace.h @@ -0,0 +1,63 @@ +/*
- 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_ADDRSPACE_H +#define __ASM_AVR32_ADDRSPACE_H
+#include <asm/types.h>
+/* Returns the physical address of an address */ +#define PHYSADDR(a) ((unsigned long)(a))
+/* virt_to_phys will only work when address is in P1 or P2 */ +static __inline__ unsigned long virt_to_phys(volatile void *address) +{
- return PHYSADDR(address);
+}
+static __inline__ void * phys_to_virt(unsigned long address) +{
- return (void *)address;
+}
+#define cached(addr) ((void *)(addr)) +#define uncached(addr) ((void *)(addr))
+/*
- 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.)
- */
+#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) +{
- return (void *)paddr;
+}
+#endif /* __ASM_AVR32_ADDRSPACE_H */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h b/include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h new file mode 100644 index 0000000..3dc1068 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h @@ -0,0 +1,41 @@ +/*
- 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_CACHEFLUSH_H +#define __ASM_AVR32_CACHEFLUSH_H
+/* No cache in the UC3. */ +#define dcache_invalidate_line(vaddr) +#define dcache_clean_line(vaddr) +#define dcache_flush_line(vaddr) +#define icache_invalidate_line(vaddr) +#define dcache_invalidate_range(start, len) +#define dcache_clean_range(start, len) +#define dcache_flush_range(start, len) +#define icache_invalidate_range(start, len) +#define dcache_flush_unlocked()
+/*
- Make sure any pending writes are completed before continuing.
- */
+#define sync_write_buffer() asm volatile("sync 0" : : : "memory")
+#endif /* __ASM_AVR32_CACHEFLUSH_H */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/chip-features.h b/include/asm-avr32/arch-at32uc3a0xxx/chip-features.h new file mode 100644 index 0000000..25ae8d7 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/chip-features.h @@ -0,0 +1,30 @@ +/*
- 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__
+/* All the UC3A0xxx chips have these. */ +#define AT32UC3A0xxx_CHIP_HAS_USART +#define AT32UC3A0xxx_CHIP_HAS_SPI +#define AT32UC3A0xxx_CHIP_HAS_MACB
+#endif /* __ASM_AVR32_ARCH_CHIP_FEATURES_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/clk.h b/include/asm-avr32/arch-at32uc3a0xxx/clk.h new file mode 100644 index 0000000..1bfb721 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/clk.h @@ -0,0 +1,86 @@ +/*
- 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) / \
((CFG_PLL0_OPT & 0x2) ? 2 : 1))
+#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) +{
- //TODO HSB is always the same as cpu-rate
- return MAIN_CLK_RATE >> CFG_CLKDIV_CPU;
+} +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 AT32UC3A0xxx_CHIP_HAS_USART +static inline unsigned long get_usart_clk_rate(unsigned int dev_id) +{
- return get_pba_clk_rate();
+} +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +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 AT32UC3A0xxx_CHIP_HAS_SPI +static inline unsigned long get_spi_clk_rate(unsigned int dev_id) +{
- return get_pba_clk_rate();
+} +#endif
+extern void clk_init(void); +extern void gclk_init(void) __attribute__((weak));
+/* Board code may need the SDRAM base clock as a compile-time constant */ +#define SDRAMC_BUS_HZ (MAIN_CLK_RATE >> CFG_CLKDIV_CPU)
+#endif /* __ASM_AVR32_ARCH_CLK_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/gpio.h b/include/asm-avr32/arch-at32uc3a0xxx/gpio.h new file mode 100644 index 0000000..165ee5d --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/gpio.h @@ -0,0 +1,44 @@ +/*
- Copyright (C) 2006, 2008 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 4
+static inline void *pio_pin_to_port(unsigned int pin) +{
- unsigned port_no;
- port_no = pin / 32;
- if (port_no >= (NR_GPIO_CONTROLLERS - 1)) {
return NULL;
- }
- return GPIO_PORT(port_no);
+}
+#include <asm/arch-common/portmux-pio.h>
+#endif /* __ASM_AVR32_ARCH_GPIO_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h b/include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h new file mode 100644 index 0000000..907912f --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h @@ -0,0 +1,47 @@ +/*
- Copyright (C) 2008 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_HMATRIX_H__ +#define __ASM_AVR32_ARCH_HMATRIX_H__
+#include <asm/hmatrix-common.h>
+/* Bitfields in SFR5 (EBI) */ +#define HMATRIX_EBI_SDRAM_ENABLE_OFFSET 1 +#define HMATRIX_EBI_SDRAM_ENABLE_SIZE 1
+/* HSB masters */ +#define HMATRIX_MASTER_CPU_DATA 0 +#define HMATRIX_MASTER_CPU_INSTRUCTIONS 1 +#define HMATRIX_MASTER_CPU_SAB 2 +#define HMATRIX_MASTER_PDCA 3 +#define HMATRIX_MASTER_MACB_DMA 4 +#define HMATRIX_MASTER_USBB_DMA 5
+/* HSB slaves */ +#define HMATRIX_SLAVE_INT_FLASH 0 +#define HMATRIX_SLAVE_HSB_PB_BR0 1 +#define HMATRIX_SLAVE_HSB_PB_BR1 2 +#define HMATRIX_SLAVE_INT_SRAM 3 +#define HMATRIX_SLAVE_USBB_DPRAM 4 +#define HMATRIX_SLAVE_EBI 5
+#endif /* __ASM_AVR32_ARCH_HMATRIX_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/memory-map.h b/include/asm-avr32/arch-at32uc3a0xxx/memory-map.h new file mode 100644 index 0000000..cef3807 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/memory-map.h @@ -0,0 +1,75 @@ +/*
- 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 __AT32UC3A0512_MEMORY_MAP_H__ +#define __AT32UC3A0512_MEMORY_MAP_H__
+/* Internal and external memories */ +#define EBI_SRAM_CS0_BASE 0xc0000000 +#define EBI_SRAM_CS0_SIZE 0x01000000 +#define EBI_SRAM_CS2_BASE 0xc8000000 +#define EBI_SRAM_CS2_SIZE 0x01000000 +#define EBI_SRAM_CS3_BASE 0xcc000000 +#define EBI_SRAM_CS3_SIZE 0x01000000 +#define EBI_SRAM_CS1_BASE 0xd0000000 +#define EBI_SRAM_CS1_SIZE 0x08000000
+#define EBI_SDRAM_BASE EBI_SRAM_CS1_BASE +#define EBI_SDRAM_SIZE EBI_SRAM_CS1_SIZE
+#define INTERNAL_SRAM_BASE 0x00000000 +#define INTERNAL_SRAM_SIZE 0x00010000
+/* Devices on HSB bus */ +#define USBB_SLAVE_BASE 0xE0000000
+/* Devices on Peripheral Bus B (PBB) */ +#define USBB_CONFIG_BASE 0xFFFE0000 +#define HMATRIX_BASE 0xFFFE1000 +#define FLASHC_BASE 0xFFFE1400 +#define MACB_BASE 0xFFFE1800 +#define SMC_BASE 0xFFFE1C00 +#define SDRAMC_BASE 0xFFFE2000
+/* Devices on Peripheral Bus A (PBA) */ +#define SM_BASE 0xFFFF0000 +#define PCDA_BASE 0xFFFF0000 +#define INTC_BASE 0xFFFF0800 +#define PM_BASE 0xFFFF0C00 +#define RTC_BASE 0xFFFF0D00 +#define WDT_BASE 0xFFFF0D30 +#define EIC_BASE 0xFFFF0D80 +#define GPIO_BASE 0xFFFF1000 +#define USART0_BASE 0xFFFF1400 +#define USART1_BASE 0xFFFF1800 +#define USART2_BASE 0xFFFF1C00 +#define USART3_BASE 0xFFFF2000 +#define SPI0_BASE 0xFFFF2400 +#define SPI1_BASE 0xFFFF2800 +#define TWI_BASE 0xFFFF2C00 +#define PWM_BASE 0xFFFF3000 +#define SSC_BASE 0xFFFF3400 +#define TC_BASE 0xFFFF3800 +#define ADC_BASE 0xFFFF3C00
+#define GPIO_PORT(x) ( (void *) (GPIO_BASE + (x) * 0x0100) )
+#endif /* __AT32UC3A0512_MEMORY_MAP_H__ */ diff --git a/include/asm-avr32/arch-at32uc3a0xxx/portmux.h b/include/asm-avr32/arch-at32uc3a0xxx/portmux.h new file mode 100644 index 0000000..2877206 --- /dev/null +++ b/include/asm-avr32/arch-at32uc3a0xxx/portmux.h @@ -0,0 +1,80 @@ +/*
- Copyright (C) 2006, 2008 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_PORTMUX_H__ +#define __ASM_AVR32_ARCH_PORTMUX_H__
+#include <asm/arch-common/portmux-gpio.h> +#include <asm/arch/memory-map.h>
+#define PORTMUX_PORT(x) ( (void *) (GPIO_BASE + (x) * 0x0100) ) +#define PORTMUX_PORT_A PORTMUX_PORT(0) +#define PORTMUX_PORT_B PORTMUX_PORT(1) +#define PORTMUX_PORT_C PORTMUX_PORT(2)
+void portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width,
unsigned long flags, unsigned long drive_strength);
+#define PORTMUX_EBI_CS(x) (1 << (x)) +#define PORTMUX_EBI_NAND (1 << 6) +#define PORTMUX_EBI_CF(x) (1 << ((x) + 7)) +#define PORTMUX_EBI_NWAIT (1 << 9)
+#ifdef AT32UC3A0xxx_CHIP_HAS_USART +static inline void portmux_enable_usart0(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 0) | (1 << 1),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart1(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 5) | (1 << 6),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart2(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 29) | (1 << 30),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart3(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 10) | (1 << 11),
PORTMUX_FUNC_B, 0);
+} +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +void portmux_enable_macb(unsigned long flags, unsigned long drive_strength);
+#define PORTMUX_MACB_RMII (0) +#define PORTMUX_MACB_MII (1 << 0) +#define PORTMUX_MACB_SPEED (1 << 1)
+#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_SPI +void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength); +void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength); +#endif
+#endif /* __ASM_AVR32_ARCH_PORTMUX_H__ */
Applied to net/testing.
regards, Ben

Dear Ben Warren,
In message 48F82A2F.4010800@gmail.com you wrote:
Olav Morken wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
[2500+ lines of full quote deleted]
Applied to net/testing.
Was there a single sane reason to full-quote the 2500+ lines of the original message just to add this single line?
Best regards,
Wolfgang Denk

Wolfgang Denk wrote:
Dear Ben Warren,
In message 48F82A2F.4010800@gmail.com you wrote:
Olav Morken wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
[2500+ lines of full quote deleted]
Applied to net/testing.
Was there a single sane reason to full-quote the 2500+ lines of the original message just to add this single line?
Sane? no. Sorry.
Ben

On Thu, 16 Oct 2008 23:01:19 -0700 Ben Warren biggerbadderben@gmail.com wrote:
Olav Morken wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
cpu/at32uc/Makefile | 56 ++++ cpu/at32uc/at32uc3a0xxx/Makefile | 43 +++ cpu/at32uc/at32uc3a0xxx/clk.c | 85 ++++++ cpu/at32uc/at32uc3a0xxx/portmux.c | 154 +++++++++++ cpu/at32uc/at32uc3a0xxx/sm.h | 272 ++++++++++++++++++++ cpu/at32uc/cache.c | 34 +++ cpu/at32uc/config.mk | 22 ++ cpu/at32uc/cpu.c | 79 ++++++ cpu/at32uc/exception.c | 121 +++++++++ cpu/at32uc/flashc.c | 80 ++++++ cpu/at32uc/flashc.h | 67 +++++ cpu/at32uc/interrupts.c | 150 +++++++++++ cpu/at32uc/portmux-gpio.c | 108 ++++++++ cpu/at32uc/sdramc.c | 120 +++++++++ cpu/at32uc/sdramc.h | 137 ++++++++++ cpu/at32uc/start.S | 265 +++++++++++++++++++ include/asm-avr32/arch-at32uc3a0xxx/addrspace.h | 63 +++++ include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h | 41 +++ .../asm-avr32/arch-at32uc3a0xxx/chip-features.h | 30 +++ include/asm-avr32/arch-at32uc3a0xxx/clk.h | 86 ++++++ include/asm-avr32/arch-at32uc3a0xxx/gpio.h | 44 ++++ include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h | 47 ++++ include/asm-avr32/arch-at32uc3a0xxx/memory-map.h | 75 ++++++ include/asm-avr32/arch-at32uc3a0xxx/portmux.h | 80 ++++++ 24 files changed, 2259 insertions(+), 0 deletions(-) create mode 100644 cpu/at32uc/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/clk.c create mode 100644 cpu/at32uc/at32uc3a0xxx/portmux.c create mode 100644 cpu/at32uc/at32uc3a0xxx/sm.h create mode 100644 cpu/at32uc/cache.c create mode 100644 cpu/at32uc/config.mk create mode 100644 cpu/at32uc/cpu.c create mode 100644 cpu/at32uc/exception.c create mode 100644 cpu/at32uc/flashc.c create mode 100644 cpu/at32uc/flashc.h create mode 100644 cpu/at32uc/interrupts.c create mode 100644 cpu/at32uc/portmux-gpio.c create mode 100644 cpu/at32uc/sdramc.c create mode 100644 cpu/at32uc/sdramc.h create mode 100644 cpu/at32uc/start.S create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/addrspace.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/chip-features.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/clk.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/gpio.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/memory-map.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/portmux.h
[...]
Applied to net/testing.
Oh. I was kind of planning to apply this to the avr32 tree after people has had some time to look at it.
But thanks for taking the two net patches.
Haavard

On Sat, Oct 18, 2008 at 4:32 AM, Haavard Skinnemoen < haavard.skinnemoen@atmel.com> wrote:
On Thu, 16 Oct 2008 23:01:19 -0700 Ben Warren biggerbadderben@gmail.com wrote:
Olav Morken wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
cpu/at32uc/Makefile | 56 ++++ cpu/at32uc/at32uc3a0xxx/Makefile | 43 +++ cpu/at32uc/at32uc3a0xxx/clk.c | 85 ++++++ cpu/at32uc/at32uc3a0xxx/portmux.c | 154 +++++++++++ cpu/at32uc/at32uc3a0xxx/sm.h | 272
++++++++++++++++++++
cpu/at32uc/cache.c | 34 +++ cpu/at32uc/config.mk | 22 ++ cpu/at32uc/cpu.c | 79 ++++++ cpu/at32uc/exception.c | 121 +++++++++ cpu/at32uc/flashc.c | 80 ++++++ cpu/at32uc/flashc.h | 67 +++++ cpu/at32uc/interrupts.c | 150 +++++++++++ cpu/at32uc/portmux-gpio.c | 108 ++++++++ cpu/at32uc/sdramc.c | 120 +++++++++ cpu/at32uc/sdramc.h | 137 ++++++++++ cpu/at32uc/start.S | 265
+++++++++++++++++++
include/asm-avr32/arch-at32uc3a0xxx/addrspace.h | 63 +++++ include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h | 41 +++ .../asm-avr32/arch-at32uc3a0xxx/chip-features.h | 30 +++ include/asm-avr32/arch-at32uc3a0xxx/clk.h | 86 ++++++ include/asm-avr32/arch-at32uc3a0xxx/gpio.h | 44 ++++ include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h | 47 ++++ include/asm-avr32/arch-at32uc3a0xxx/memory-map.h | 75 ++++++ include/asm-avr32/arch-at32uc3a0xxx/portmux.h | 80 ++++++ 24 files changed, 2259 insertions(+), 0 deletions(-) create mode 100644 cpu/at32uc/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/Makefile create mode 100644 cpu/at32uc/at32uc3a0xxx/clk.c create mode 100644 cpu/at32uc/at32uc3a0xxx/portmux.c create mode 100644 cpu/at32uc/at32uc3a0xxx/sm.h create mode 100644 cpu/at32uc/cache.c create mode 100644 cpu/at32uc/config.mk create mode 100644 cpu/at32uc/cpu.c create mode 100644 cpu/at32uc/exception.c create mode 100644 cpu/at32uc/flashc.c create mode 100644 cpu/at32uc/flashc.h create mode 100644 cpu/at32uc/interrupts.c create mode 100644 cpu/at32uc/portmux-gpio.c create mode 100644 cpu/at32uc/sdramc.c create mode 100644 cpu/at32uc/sdramc.h create mode 100644 cpu/at32uc/start.S create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/addrspace.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/cacheflush.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/chip-features.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/clk.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/gpio.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/hmatrix.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/memory-map.h create mode 100644 include/asm-avr32/arch-at32uc3a0xxx/portmux.h
[...]
Applied to net/testing.
Oh. I was kind of planning to apply this to the avr32 tree after people has had some time to look at it.
But thanks for taking the two net patches.
Git should figure this out right? If not, I can back them off and add a SOB.
Haavard
regards, Ben

"Ben Warren" biggerbadderben@gmail.com wrote:
Oh. I was kind of planning to apply this to the avr32 tree after people has had some time to look at it.
But thanks for taking the two net patches.
Git should figure this out right? If not, I can back them off and add a SOB.
I don't think so if we apply the patches independently. If I pull your tree, it will work, but I'm not sure if I want your whole testing branch in my avr32 tree :-)
Haavard

Haavard,
Haavard Skinnemoen wrote:
"Ben Warren" biggerbadderben@gmail.com wrote:
Oh. I was kind of planning to apply this to the avr32 tree after people has had some time to look at it.
But thanks for taking the two net patches.
Git should figure this out right? If not, I can back them off and add a SOB.
I don't think so if we apply the patches independently. If I pull your tree, it will work, but I'm not sure if I want your whole testing branch in my avr32 tree :-)
Haavard
I've pulled these from the net tree. They're all yours. Please add Acked-by Ben Warren biggerbadderben@gmail.com
regards, Ben

Dear Olav Morken,
In message fa1e825be37320d862f752c6962c81f9b19ed3db.1223643536.git.olavmrk@gmail.com you wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
Coding style violations: C++ comments, indentation not by TAB, too long lines, incorrect multiline comment style.
...
+static inline unsigned long get_hsb_clk_rate(void) +{
- //TODO HSB is always the same as cpu-rate
-------^^
- return MAIN_CLK_RATE >> CFG_CLKDIV_CPU;
+} +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 AT32UC3A0xxx_CHIP_HAS_USART +static inline unsigned long get_usart_clk_rate(unsigned int dev_id) +{
- return get_pba_clk_rate();
+} +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +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 AT32UC3A0xxx_CHIP_HAS_SPI +static inline unsigned long get_spi_clk_rate(unsigned int dev_id) +{
- return get_pba_clk_rate();
+} +#endif
Would it make sense to provide weak functions the get defined accordingly? A function which only calls another function looks stupid to me.
+#ifdef AT32UC3A0xxx_CHIP_HAS_USART +static inline void portmux_enable_usart0(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 0) | (1 << 1),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart1(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 5) | (1 << 6),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart2(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 29) | (1 << 30),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart3(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 10) | (1 << 11),
PORTMUX_FUNC_B, 0);
+} +#endif
I don't like this either.
Best regards,
Wolfgang Denk

Wolfgang Denk wd@denx.de wrote:
Dear Olav Morken,
In message fa1e825be37320d862f752c6962c81f9b19ed3db.1223643536.git.olavmrk@gmail.com you wrote:
This patch adds support for the AT32UC3A0xxx chips.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
Coding style violations: C++ comments, indentation not by TAB, too long lines, incorrect multiline comment style.
...
+static inline unsigned long get_hsb_clk_rate(void) +{
- //TODO HSB is always the same as cpu-rate
-------^^
- return MAIN_CLK_RATE >> CFG_CLKDIV_CPU;
+} +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 AT32UC3A0xxx_CHIP_HAS_USART +static inline unsigned long get_usart_clk_rate(unsigned int dev_id) +{
- return get_pba_clk_rate();
+} +#endif +#ifdef AT32UC3A0xxx_CHIP_HAS_MACB +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 AT32UC3A0xxx_CHIP_HAS_SPI +static inline unsigned long get_spi_clk_rate(unsigned int dev_id) +{
- return get_pba_clk_rate();
+} +#endif
Would it make sense to provide weak functions the get defined accordingly? A function which only calls another function looks stupid to me.
This matches other AVR32 chips. I'm not sure how you intend to use weak functions here...the whole point of these things is to make drivers unaware of which bus a certain peripheral is connected to.
I suppose the same thing could be done using aliases, but then you can't do it inline, which in turn means that the constant calculations won't be constant anymore, and the code gets larger and slower as a result.
+#ifdef AT32UC3A0xxx_CHIP_HAS_USART +static inline void portmux_enable_usart0(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 0) | (1 << 1),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart1(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_A, (1 << 5) | (1 << 6),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart2(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 29) | (1 << 30),
PORTMUX_FUNC_A, 0);
+}
+static inline void portmux_enable_usart3(unsigned long drive_strength) +{
- portmux_select_peripheral(PORTMUX_PORT_B, (1 << 10) | (1 << 11),
PORTMUX_FUNC_B, 0);
+} +#endif
I don't like this either.
Why not? I think it's pretty elegant -- the board code only needs to specify which USARTs to enable, it doesn't need to know which pins and functions it corresponds to.
That said, it might be a better idea to make a single function with a switch () block.
Haavard

Wolfgang Denk wd@denx.de wrote:
+static inline unsigned long get_hsb_clk_rate(void) +{
- //TODO HSB is always the same as cpu-rate
-------^^
- return MAIN_CLK_RATE >> CFG_CLKDIV_CPU;
Simply removing this comment should be fine.
Haavard

From: Paul Driveklepp pauldriveklepp@gmail.com
This patch adds support for the ATEVK1100 evaluation kit, which contains an AT32UC3A0512ES chip.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com --- Makefile | 3 + board/atmel/atevk1100/Makefile | 44 +++++++++ board/atmel/atevk1100/atevk1100.c | 97 ++++++++++++++++++ board/atmel/atevk1100/config.mk | 4 + board/atmel/atevk1100/u-boot.lds | 75 ++++++++++++++ include/configs/atevk1100.h | 194 +++++++++++++++++++++++++++++++++++++ 6 files changed, 417 insertions(+), 0 deletions(-) create mode 100644 board/atmel/atevk1100/Makefile create mode 100644 board/atmel/atevk1100/atevk1100.c create mode 100644 board/atmel/atevk1100/config.mk create mode 100644 board/atmel/atevk1100/u-boot.lds create mode 100644 include/configs/atevk1100.h
diff --git a/Makefile b/Makefile index 7c13ce8..7480749 100644 --- a/Makefile +++ b/Makefile @@ -3071,6 +3071,9 @@ hammerhead_config : unconfig mimc200_config : unconfig @$(MKCONFIG) $(@:_config=) avr32 at32ap mimc200 mimc at32ap700x
+atevk1100_config : unconfig + @$(MKCONFIG) $(@:_config=) avr32 at32uc atevk1100 atmel at32uc3a0xxx + #======================================================================== # SH3 (SuperH) #======================================================================== diff --git a/board/atmel/atevk1100/Makefile b/board/atmel/atevk1100/Makefile new file mode 100644 index 0000000..b5ba79f --- /dev/null +++ b/board/atmel/atevk1100/Makefile @@ -0,0 +1,44 @@ +# +# (C) Copyright 2001-2006 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# 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$(BOARD).a + +COBJS := $(BOARD).o + +SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS)) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/board/atmel/atevk1100/atevk1100.c b/board/atmel/atevk1100/atevk1100.c new file mode 100644 index 0000000..105e5c9 --- /dev/null +++ b/board/atmel/atevk1100/atevk1100.c @@ -0,0 +1,97 @@ +/* + * 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 <common.h> + +#include <asm/io.h> +#include <asm/sdram.h> +#include <asm/arch/clk.h> +#include <asm/arch/hmatrix.h> +#include <asm/arch/portmux.h> + +DECLARE_GLOBAL_DATA_PTR; + +static const struct sdram_config sdram_config = { + /* MT48LC16M16A2-7E (32 MB) */ + .data_bits = SDRAM_DATA_16BIT, + .row_bits = 13, + .col_bits = 9, + .bank_bits = 2, + .cas = 2, + .twr = 2, + .trc = 7, + .trp = 2, + .trcd = 2, + .tras = 4, + .txsr = 7, + /* 7.81 us */ + .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000, +}; + +int board_early_init_f(void) +{ + /* Enable SDRAM in the EBI mux according to AP7000 datasheet */ + hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); + + /* 16 bit data, 24 bit address */ + portmux_enable_ebi(16, 23, 0, PORTMUX_DRIVE_HIGH); + portmux_enable_usart0(PORTMUX_DRIVE_MIN); +#if defined(CONFIG_MACB) + portmux_enable_macb(0, PORTMUX_DRIVE_HIGH); +#endif + + return 0; +} + +phys_size_t initdram(int board_type) +{ + unsigned long expected_size; + unsigned long actual_size; + void *sdram_base; + + sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE); + + expected_size = sdram_init(sdram_base, &sdram_config); + actual_size = get_ram_size(sdram_base, expected_size); + + unmap_physmem(sdram_base, EBI_SDRAM_SIZE); + + if (expected_size != actual_size) + printf("Warning: Only %lu of %lu MiB SDRAM is working\n", + actual_size >> 20, expected_size >> 20); + + return actual_size; +} + +int board_early_init_r(void) +{ + /* Physical address of phy (0xff = auto-detect) */ + gd->bd->bi_phy_id[0] = 0xff; + return 0; +} + +#ifdef CONFIG_CMD_NET +int board_eth_init(bd_t *bi) +{ + macb_eth_initialize(0, (void *)MACB_BASE, bi->bi_phy_id[0]); + return 0; +} +#endif diff --git a/board/atmel/atevk1100/config.mk b/board/atmel/atevk1100/config.mk new file mode 100644 index 0000000..ca23f88 --- /dev/null +++ b/board/atmel/atevk1100/config.mk @@ -0,0 +1,4 @@ +PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections +PLATFORM_LDFLAGS += --gc-sections +TEXT_BASE = 0x80000000 +LDSCRIPT = $(obj)board/atmel/atevk1100/u-boot.lds diff --git a/board/atmel/atevk1100/u-boot.lds b/board/atmel/atevk1100/u-boot.lds new file mode 100644 index 0000000..3c20979 --- /dev/null +++ b/board/atmel/atevk1100/u-boot.lds @@ -0,0 +1,75 @@ +/* -*- Fundamental -*- + * + * 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 + */ +OUTPUT_FORMAT("elf32-avr32", "elf32-avr32", "elf32-avr32") +OUTPUT_ARCH(avr32) +ENTRY(_start) + +SECTIONS +{ + . = 0x80000000; + _text = .; + .text : { + *(.exception.text) + *(.text) + *(.text.*) + } + _etext = .; + + .rodata : { + *(.rodata) + *(.rodata.*) + } + + _end_noreloc = .; + + . = ALIGN(8); + _data = .; + .data : { + *(.data) + *(.data.*) + } + + . = ALIGN(4); + __u_boot_cmd_start = .; + .u_boot_cmd : { + KEEP(*(.u_boot_cmd)) + } + __u_boot_cmd_end = .; + + . = ALIGN(4); + _got = .; + .got : { + *(.got) + } + _egot = .; + + . = ALIGN(8); + _edata = .; + + .bss (NOLOAD) : { + *(.bss) + *(.bss.*) + } + . = ALIGN(8); + _end = .; +} diff --git a/include/configs/atevk1100.h b/include/configs/atevk1100.h new file mode 100644 index 0000000..db5af37 --- /dev/null +++ b/include/configs/atevk1100.h @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2005-2006 Atmel Corporation + * + * Configuration settings for the ATEVK1100 evaluation kit + * + * 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 + +#include <asm/arch/memory-map.h> + +#define CONFIG_AVR32 1 +#define CONFIG_AT32UC 1 +#define CONFIG_AT32UC3A0xxx 1 +#define CONFIG_ATEVK1100 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 132 MHz, and the CPU, PBA and PBB to run at PLL/2. + * fVCO = (CFG_OSC0_HZ * CFG_PLL0_MUL) / CFG_PLL0_DIV + * fPLL = fVCO / ((CFG_PLL0_OPT & 0x2) ? 2 : 1) + */ +#define CONFIG_PLL 1 +#define CFG_POWER_MANAGER 1 +#define CFG_OSC0_HZ 12000000 +#define CFG_PLL0_DIV 1 +#define CFG_PLL0_MUL 11 +#define CFG_PLL0_SUPPRESS_CYCLES 64 +/* + * Set the CPU running at: + * PLL / (2^CFG_CLKDIV_CPU) = CPU MHz + */ +#define CFG_CLKDIV_CPU 1 +/* + * Set the PBA running at: + * PLL / (2^CFG_CLKDIV_PBA) = PBA MHz + * On the atuc3a0512es, the maximum clock rate of PBA is 33 MHz. + */ +#define CFG_CLKDIV_PBA 1 +/* + * 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: + * + * Select the operating range for the PLL. + * PLLOPT[0]: Select the VCO frequency range. + * PLLOPT[1]: Enable the extra output divider. + * PLLOPT[2]: Disable the Wide-Bandwidth mode (Wide-Bandwidth mode allows a faster startup time and out-of-lock time). + * + * We want to run the cpu at 66 MHz, and the fVCO of the PLL at 132 MHz. + */ +#define CFG_PLL0_OPT 0x03 + + +#define CONFIG_USART0 1 +#undef CONFIG_USART1 +#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 9600 +#define CONFIG_BOOTARGS \ + "console=ttyS0 root=/dev/mmcblk0p1 fbmem=600k rootwait=1" + +#define CONFIG_BOOTCOMMAND \ + "fsload; bootm $(fileaddr)" + +/* + * 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 0 +#define CONFIG_AUTOBOOT_KEYED 1 +#define CONFIG_AUTOBOOT_PROMPT \ + "Press SPACE to abort autoboot in %d seconds\n", bootdelay +#define CONFIG_AUTOBOOT_DELAY_STR "d" +#define CONFIG_AUTOBOOT_STOP_STR " " + +/* + * After booting the board for the first time, new ethernet addresses + * should be generated and assigned to the environment variables + * "ethaddr" and "eth1addr". This is normally done during production. + */ +#define CONFIG_OVERWRITE_ETHADDR_ONCE 1 +#define CONFIG_NET_MULTI 1 + +/* + * BOOTP/DHCP options + */ +#define CONFIG_BOOTP_SUBNETMASK +#define CONFIG_BOOTP_GATEWAY + + +/* + * Command line configuration. + */ +#include <config_cmd_default.h> + +#define CONFIG_CMD_ASKENV +#define CONFIG_CMD_DHCP + +#undef CONFIG_CMD_AUTOSCRIPT +#undef CONFIG_CMD_FPGA +#undef CONFIG_CMD_SETGETDCR +#undef CONFIG_CMD_XIMG + +/* Ethernet - RMII mode */ +#define CONFIG_MACB 1 +#define CONFIG_RMII 1 + +#define CONFIG_ATMEL_USART 1 +#define CONFIG_ATMEL_SPI 1 +#define CONFIG_PORTMUX_GPIO 1 +#define CFG_NR_PIOS 5 +#define CFG_SDRAMC 1 + +#define CFG_DCACHE_LINESZ 32 +#define CFG_ICACHE_LINESZ 32 + +#define CONFIG_NR_DRAM_BANKS 1 + +/* Internal flash on the microcontroller (TODO?) (512kB)*/ +#define CFG_FLASH_BASE 0x80000000 +#define CFG_FLASH_SIZE 0x80000 +#define CFG_MAX_FLASH_BANKS 1 +#define CFG_MAX_FLASH_SECT 135 + +#define CFG_MONITOR_BASE CFG_FLASH_BASE + +#define CFG_INTRAM_BASE INTERNAL_SRAM_BASE +#define CFG_INTRAM_SIZE INTERNAL_SRAM_SIZE +#define CFG_SDRAM_BASE EBI_SDRAM_BASE + +#define CONFIG_ENV_IS_IN_FLASH 1 +#define CONFIG_ENV_SIZE 65536 +#define CONFIG_ENV_ADDR (CFG_FLASH_BASE + CFG_FLASH_SIZE - CONFIG_ENV_SIZE) + +#define CFG_INIT_SP_ADDR (CFG_INTRAM_BASE + CFG_INTRAM_SIZE) + +#define CFG_MALLOC_LEN (256*1024) +#define CFG_DMA_ALLOC_LEN (16384) + +/* Allow 4MB for the kernel run-time image */ +#define CFG_LOAD_ADDR (EBI_SDRAM_BASE + 0x00400000) +#define CFG_BOOTPARAMS_LEN (16 * 1024) + +/* Other configuration settings that shouldn't have to change all that often */ +#define CFG_PROMPT "U-Boot> " +#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 EBI_SDRAM_BASE +#define CFG_MEMTEST_END (CFG_MEMTEST_START + 0x700000) +#define CFG_BAUDRATE_TABLE { 115200, 38400, 19200, 9600, 2400 } + +#endif /* __CONFIG_H */

Dear Olav Morken,
In message 3ce5e013aa7b33edc8f3fb5af2532103bd2b053f.1223643536.git.olavmrk@gmail.com you wrote:
From: Paul Driveklepp pauldriveklepp@gmail.com
This patch adds support for the ATEVK1100 evaluation kit, which contains an AT32UC3A0512ES chip.
Signed-off-by: Gunnar Rangoy gunnar@rangoy.com Signed-off-by: Paul Driveklepp pauldriveklepp@gmail.com Signed-off-by: Olav Morken olavmrk@gmail.com
...
diff --git a/Makefile b/Makefile index 7c13ce8..7480749 100644 --- a/Makefile +++ b/Makefile @@ -3071,6 +3071,9 @@ hammerhead_config : unconfig mimc200_config : unconfig @$(MKCONFIG) $(@:_config=) avr32 at32ap mimc200 mimc at32ap700x
+atevk1100_config : unconfig
- @$(MKCONFIG) $(@:_config=) avr32 at32uc atevk1100 atmel at32uc3a0xxx
Please keep lists sorted.
Please also add board to MAKEALL script and to MAINTAINERS file.
And fix some too long lines, please.
Best regards,
Wolfgang Denk

Olav Morken olavmrk@gmail.com wrote:
This is a patch series which adds support for the ATEVK1100 evaluation board[1], and the AT32UC3A0xxx[2] microcontrollers used on that board. The patch series is based on avr32/next.
I've applied this and the other series you posted to the 'evk1100' branch in
git://git.denx.de/u-boot-avr32.git evk1100
Please submit incremental patches addressing the comments you got during review.
Haavard

Dear Haavard Skinnemoen,
In message 20081119160944.6e01a708@hskinnemo-gx745.norway.atmel.com you wrote:
I've applied this and the other series you posted to the 'evk1100' branch in
git://git.denx.de/u-boot-avr32.git evk1100
Please submit incremental patches addressing the comments you got during review.
Umm... but please do NOT merge this branch into your AVR32 repository for me to poll from. In mainline, I want to see consolidated patches only.
Best regards,
Wolfgang Denk

Wolfgang Denk wd@denx.de wrote:
Dear Haavard Skinnemoen,
In message 20081119160944.6e01a708@hskinnemo-gx745.norway.atmel.com you wrote:
I've applied this and the other series you posted to the 'evk1100' branch in
git://git.denx.de/u-boot-avr32.git evk1100
Please submit incremental patches addressing the comments you got during review.
Umm... but please do NOT merge this branch into your AVR32 repository for me to poll from. In mainline, I want to see consolidated patches only.
That's the plan. I just thought I'd give them somewhere to live until they're ready.
So a big fat warning to everyone: the evk1100 branch _will_ get rebased.
Haavard
participants (5)
-
Ben Warren
-
Haavard Skinnemoen
-
Jean-Christophe PLAGNIOL-VILLARD
-
Olav Morken
-
Wolfgang Denk