blob: 0eedee4112ab0fbd6c9a0961851b8a774864ce06 [file] [log] [blame]
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +02001/*
2 * Copyright (C) 2008 Atmel Corporation
3 *
4 * See file CREDITS for list of people who contributed to this project.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include <common.h>
Ben Warren89973f82008-08-31 22:22:04 -070021#include <netdev.h>
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020022
23#include <asm/io.h>
24#include <asm/sdram.h>
25#include <asm/arch/clk.h>
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020026#include <asm/arch/hmatrix.h>
Haavard Skinnemoen1f36f732010-08-12 13:52:54 +070027#include <asm/arch/mmu.h>
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020028#include <asm/arch/portmux.h>
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020029
30DECLARE_GLOBAL_DATA_PTR;
31
Haavard Skinnemoen1f36f732010-08-12 13:52:54 +070032struct mmu_vm_range mmu_vmr_table[CONFIG_SYS_NR_VM_REGIONS] = {
33 {
34 .virt_pgno = CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT,
35 .nr_pages = CONFIG_SYS_FLASH_SIZE >> PAGE_SHIFT,
36 .phys = (CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT)
37 | MMU_VMR_CACHE_NONE,
38 }, {
39 .virt_pgno = CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT,
40 .nr_pages = EBI_SDRAM_SIZE >> PAGE_SHIFT,
41 .phys = (CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT)
42 | MMU_VMR_CACHE_WRBACK,
43 },
44};
45
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020046static const struct sdram_config sdram_config = {
47 /* MT48LC4M32B2P-6 (16 MB) */
48 .data_bits = SDRAM_DATA_32BIT,
49 .row_bits = 12,
50 .col_bits = 8,
51 .bank_bits = 2,
52 .cas = 3,
53 .twr = 2,
54 .trc = 7,
55 .trp = 2,
56 .trcd = 2,
57 .tras = 5,
58 .txsr = 5,
59 /* 15.6 us */
60 .refresh_period = (156 * (SDRAMC_BUS_HZ / 1000)) / 10000,
61};
62
63int board_early_init_f(void)
64{
65 /* Enable SDRAM in the EBI mux */
66 hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));
67
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020068 portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH);
69 portmux_enable_usart3(PORTMUX_DRIVE_MIN);
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020070#if defined(CONFIG_MACB)
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020071 portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020072#endif
73#if defined(CONFIG_MMC)
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020074 portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW);
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020075#endif
76
77 return 0;
78}
79
80phys_size_t initdram(int board_type)
81{
82 unsigned long expected_size;
83 unsigned long actual_size;
84 void *sdram_base;
85
Haavard Skinnemoen9cec2fc2010-08-12 13:52:53 +070086 sdram_base = uncached(EBI_SDRAM_BASE);
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020087
88 expected_size = sdram_init(sdram_base, &sdram_config);
89 actual_size = get_ram_size(sdram_base, expected_size);
90
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020091 if (expected_size != actual_size)
Haavard Skinnemoen25da0b82008-08-20 09:27:37 +020092 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020093 actual_size >> 20, expected_size >> 20);
94
95 return actual_size;
96}
97
Haavard Skinnemoen25e68542008-08-31 18:46:35 +020098int board_early_init_r(void)
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +020099{
100 gd->bd->bi_phy_id[0] = 0x01;
Haavard Skinnemoen25e68542008-08-31 18:46:35 +0200101 return 0;
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +0200102}
103
104#if defined(CONFIG_MACB) && defined(CONFIG_CMD_NET)
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +0200105int board_eth_init(bd_t *bi)
106{
Andreas Bießmannf4278b72010-11-04 23:15:31 +0000107 return macb_eth_initialize(0, (void *)ATMEL_BASE_MACB0,
108 bi->bi_phy_id[0]);
Hans-Christian Egtvedt0eb57172008-08-06 14:42:13 +0200109}
110#endif