Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Miromico AG |
| 3 | * |
| 4 | * Mostly copied form atmel ATNGW100 sources |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 25 | #include <common.h> |
Ben Warren | 2f2b6b6 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 26 | #include <netdev.h> |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 27 | |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/sdram.h> |
| 30 | #include <asm/arch/clk.h> |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 31 | #include <asm/arch/hmatrix.h> |
Andreas Bießmann | 94156fa | 2010-11-04 23:15:30 +0000 | [diff] [blame] | 32 | #include <asm/arch/hardware.h> |
Haavard Skinnemoen | c6f292f | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 33 | #include <asm/arch/mmu.h> |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 34 | #include <asm/arch/portmux.h> |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
Haavard Skinnemoen | c6f292f | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 38 | struct mmu_vm_range mmu_vmr_table[CONFIG_SYS_NR_VM_REGIONS] = { |
| 39 | { |
| 40 | .virt_pgno = CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT, |
| 41 | .nr_pages = CONFIG_SYS_FLASH_SIZE >> PAGE_SHIFT, |
| 42 | .phys = (CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT) |
| 43 | | MMU_VMR_CACHE_NONE, |
| 44 | }, { |
| 45 | .virt_pgno = CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT, |
| 46 | .nr_pages = EBI_SDRAM_SIZE >> PAGE_SHIFT, |
| 47 | .phys = (CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT) |
| 48 | | MMU_VMR_CACHE_WRBACK, |
| 49 | }, |
| 50 | }; |
| 51 | |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 52 | static const struct sdram_config sdram_config = { |
| 53 | .data_bits = SDRAM_DATA_32BIT, |
| 54 | .row_bits = 13, |
| 55 | .col_bits = 9, |
| 56 | .bank_bits = 2, |
| 57 | .cas = 3, |
| 58 | .twr = 2, |
| 59 | .trc = 7, |
| 60 | .trp = 2, |
| 61 | .trcd = 2, |
| 62 | .tras = 5, |
| 63 | .txsr = 5, |
| 64 | /* 7.81 us */ |
| 65 | .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000, |
| 66 | }; |
| 67 | |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 68 | #ifdef CONFIG_CMD_NET |
| 69 | int board_eth_init(bd_t *bis) |
| 70 | { |
Andreas Bießmann | 5807e79 | 2010-11-04 23:15:31 +0000 | [diff] [blame^] | 71 | return macb_eth_initialize(0, (void *)ATMEL_BASE_MACB0, |
| 72 | bis->bi_phy_id[0]); |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 73 | } |
| 74 | #endif |
| 75 | |
| 76 | int board_early_init_f(void) |
| 77 | { |
| 78 | /* Enable SDRAM in the EBI mux */ |
| 79 | hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); |
| 80 | |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 81 | portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH); |
| 82 | portmux_enable_usart1(PORTMUX_DRIVE_MIN); |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 83 | |
| 84 | #if defined(CONFIG_MACB) |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 85 | portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 86 | #endif |
| 87 | #if defined(CONFIG_MMC) |
Haavard Skinnemoen | 610b362 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 88 | portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW); |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 89 | #endif |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | phys_size_t initdram(int board_type) |
| 94 | { |
| 95 | unsigned long expected_size; |
| 96 | unsigned long actual_size; |
| 97 | void *sdram_base; |
| 98 | |
Haavard Skinnemoen | 6f161e4 | 2010-08-12 13:52:53 +0700 | [diff] [blame] | 99 | sdram_base = uncached(EBI_SDRAM_BASE); |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 100 | |
| 101 | expected_size = sdram_init(sdram_base, &sdram_config); |
| 102 | actual_size = get_ram_size(sdram_base, expected_size); |
| 103 | |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 104 | if (expected_size != actual_size) |
| 105 | printf("Warning: Only %lu of %lu MiB SDRAM is working\n", |
| 106 | actual_size >> 20, expected_size >> 20); |
| 107 | |
| 108 | return actual_size; |
| 109 | } |
| 110 | |
Haavard Skinnemoen | d6799f7 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 111 | int board_early_init_r(void) |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 112 | { |
| 113 | gd->bd->bi_phy_id[0] = 0x01; |
Haavard Skinnemoen | d6799f7 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 114 | return 0; |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Haavard Skinnemoen | 23ba3ac | 2008-08-31 18:24:24 +0200 | [diff] [blame] | 117 | int board_postclk_init(void) |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 118 | { |
| 119 | /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */ |
Haavard Skinnemoen | 7d1d757 | 2008-08-31 18:07:35 +0200 | [diff] [blame] | 120 | gclk_enable_output(3, PORTMUX_DRIVE_LOW); |
| 121 | gclk_set_rate(3, GCLK_PARENT_OSC0, 25000000); |
Haavard Skinnemoen | 23ba3ac | 2008-08-31 18:24:24 +0200 | [diff] [blame] | 122 | return 0; |
Julien May | 72646d2 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 123 | } |