Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 1 | /* |
| 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 Warren | 2f2b6b6 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 21 | #include <netdev.h> |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 22 | |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/sdram.h> |
| 25 | #include <asm/arch/clk.h> |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 26 | #include <asm/arch/hmatrix.h> |
Haavard Skinnemoen | c6f292f | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 27 | #include <asm/arch/mmu.h> |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 28 | #include <asm/arch/portmux.h> |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Haavard Skinnemoen | c6f292f | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 32 | struct 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 Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 46 | static 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 | |
| 63 | int 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 Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 68 | portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH); |
| 69 | portmux_enable_usart3(PORTMUX_DRIVE_MIN); |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 70 | #if defined(CONFIG_MACB) |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 71 | portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 72 | #endif |
| 73 | #if defined(CONFIG_MMC) |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 74 | portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW); |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 75 | #endif |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | phys_size_t initdram(int board_type) |
| 81 | { |
| 82 | unsigned long expected_size; |
| 83 | unsigned long actual_size; |
| 84 | void *sdram_base; |
| 85 | |
Haavard Skinnemoen | 6f161e4 | 2010-08-12 13:52:53 +0700 | [diff] [blame] | 86 | sdram_base = uncached(EBI_SDRAM_BASE); |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 87 | |
| 88 | expected_size = sdram_init(sdram_base, &sdram_config); |
| 89 | actual_size = get_ram_size(sdram_base, expected_size); |
| 90 | |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 91 | if (expected_size != actual_size) |
Haavard Skinnemoen | 984cdba | 2008-08-20 09:27:37 +0200 | [diff] [blame] | 92 | printf("Warning: Only %lu of %lu MiB SDRAM is working\n", |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 93 | actual_size >> 20, expected_size >> 20); |
| 94 | |
| 95 | return actual_size; |
| 96 | } |
| 97 | |
Haavard Skinnemoen | d6799f7 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 98 | int board_early_init_r(void) |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 99 | { |
| 100 | gd->bd->bi_phy_id[0] = 0x01; |
Haavard Skinnemoen | d6799f7 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 101 | return 0; |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | #if defined(CONFIG_MACB) && defined(CONFIG_CMD_NET) |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 105 | int board_eth_init(bd_t *bi) |
| 106 | { |
Andreas Bießmann | 5807e79 | 2010-11-04 23:15:31 +0000 | [diff] [blame] | 107 | return macb_eth_initialize(0, (void *)ATMEL_BASE_MACB0, |
| 108 | bi->bi_phy_id[0]); |
Hans-Christian Egtvedt | d4b48b8 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 109 | } |
| 110 | #endif |