Hans-Christian Egtvedt | 0eb5717 | 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 | 89973f8 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 21 | #include <netdev.h> |
Hans-Christian Egtvedt | 0eb5717 | 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 | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 26 | #include <asm/arch/hmatrix.h> |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 27 | #include <asm/arch/portmux.h> |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | static const struct sdram_config sdram_config = { |
| 32 | /* MT48LC4M32B2P-6 (16 MB) */ |
| 33 | .data_bits = SDRAM_DATA_32BIT, |
| 34 | .row_bits = 12, |
| 35 | .col_bits = 8, |
| 36 | .bank_bits = 2, |
| 37 | .cas = 3, |
| 38 | .twr = 2, |
| 39 | .trc = 7, |
| 40 | .trp = 2, |
| 41 | .trcd = 2, |
| 42 | .tras = 5, |
| 43 | .txsr = 5, |
| 44 | /* 15.6 us */ |
| 45 | .refresh_period = (156 * (SDRAMC_BUS_HZ / 1000)) / 10000, |
| 46 | }; |
| 47 | |
| 48 | int board_early_init_f(void) |
| 49 | { |
| 50 | /* Enable SDRAM in the EBI mux */ |
| 51 | hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); |
| 52 | |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 53 | portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH); |
| 54 | portmux_enable_usart3(PORTMUX_DRIVE_MIN); |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 55 | #if defined(CONFIG_MACB) |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 56 | portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 57 | #endif |
| 58 | #if defined(CONFIG_MMC) |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 59 | portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW); |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | phys_size_t initdram(int board_type) |
| 66 | { |
| 67 | unsigned long expected_size; |
| 68 | unsigned long actual_size; |
| 69 | void *sdram_base; |
| 70 | |
| 71 | sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE); |
| 72 | |
| 73 | expected_size = sdram_init(sdram_base, &sdram_config); |
| 74 | actual_size = get_ram_size(sdram_base, expected_size); |
| 75 | |
| 76 | unmap_physmem(sdram_base, EBI_SDRAM_SIZE); |
| 77 | |
| 78 | if (expected_size != actual_size) |
Haavard Skinnemoen | 25da0b8 | 2008-08-20 09:27:37 +0200 | [diff] [blame] | 79 | printf("Warning: Only %lu of %lu MiB SDRAM is working\n", |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 80 | actual_size >> 20, expected_size >> 20); |
| 81 | |
| 82 | return actual_size; |
| 83 | } |
| 84 | |
Haavard Skinnemoen | 25e6854 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 85 | int board_early_init_r(void) |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 86 | { |
| 87 | gd->bd->bi_phy_id[0] = 0x01; |
Haavard Skinnemoen | 25e6854 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 88 | return 0; |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | #if defined(CONFIG_MACB) && defined(CONFIG_CMD_NET) |
Hans-Christian Egtvedt | 0eb5717 | 2008-08-06 14:42:13 +0200 | [diff] [blame] | 92 | int board_eth_init(bd_t *bi) |
| 93 | { |
| 94 | return macb_eth_initialize(0, (void *)MACB0_BASE, bi->bi_phy_id[0]); |
| 95 | } |
| 96 | #endif |