Julien May | 5c374c9 | 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 | |
| 25 | #include "../cpu/at32ap/at32ap700x/sm.h" |
| 26 | |
| 27 | #include <common.h> |
Ben Warren | 89973f8 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 28 | #include <netdev.h> |
Julien May | 5c374c9 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 29 | |
| 30 | #include <asm/io.h> |
| 31 | #include <asm/sdram.h> |
| 32 | #include <asm/arch/clk.h> |
| 33 | #include <asm/arch/gpio.h> |
| 34 | #include <asm/arch/hmatrix.h> |
| 35 | #include <asm/arch/memory-map.h> |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
| 39 | static const struct sdram_config sdram_config = { |
| 40 | .data_bits = SDRAM_DATA_32BIT, |
| 41 | .row_bits = 13, |
| 42 | .col_bits = 9, |
| 43 | .bank_bits = 2, |
| 44 | .cas = 3, |
| 45 | .twr = 2, |
| 46 | .trc = 7, |
| 47 | .trp = 2, |
| 48 | .trcd = 2, |
| 49 | .tras = 5, |
| 50 | .txsr = 5, |
| 51 | /* 7.81 us */ |
| 52 | .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000, |
| 53 | }; |
| 54 | |
Julien May | 5c374c9 | 2008-06-23 13:57:52 +0200 | [diff] [blame] | 55 | #ifdef CONFIG_CMD_NET |
| 56 | int board_eth_init(bd_t *bis) |
| 57 | { |
| 58 | return macb_eth_initialize(0, (void *)MACB0_BASE, bis->bi_phy_id[0]); |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | int board_early_init_f(void) |
| 63 | { |
| 64 | /* Enable SDRAM in the EBI mux */ |
| 65 | hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); |
| 66 | |
| 67 | gpio_enable_ebi(); |
| 68 | gpio_enable_usart1(); |
| 69 | |
| 70 | #if defined(CONFIG_MACB) |
| 71 | gpio_enable_macb0(); |
| 72 | #endif |
| 73 | #if defined(CONFIG_MMC) |
| 74 | gpio_enable_mmci(); |
| 75 | #endif |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | phys_size_t initdram(int board_type) |
| 80 | { |
| 81 | unsigned long expected_size; |
| 82 | unsigned long actual_size; |
| 83 | void *sdram_base; |
| 84 | |
| 85 | sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE); |
| 86 | |
| 87 | expected_size = sdram_init(sdram_base, &sdram_config); |
| 88 | actual_size = get_ram_size(sdram_base, expected_size); |
| 89 | |
| 90 | unmap_physmem(sdram_base, EBI_SDRAM_SIZE); |
| 91 | |
| 92 | if (expected_size != actual_size) |
| 93 | printf("Warning: Only %lu of %lu MiB SDRAM is working\n", |
| 94 | actual_size >> 20, expected_size >> 20); |
| 95 | |
| 96 | return actual_size; |
| 97 | } |
| 98 | |
| 99 | void board_init_info(void) |
| 100 | { |
| 101 | gd->bd->bi_phy_id[0] = 0x01; |
| 102 | } |
| 103 | |
| 104 | void gclk_init(void) |
| 105 | { |
| 106 | /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */ |
| 107 | |
| 108 | /* Select GCLK3 peripheral function */ |
| 109 | gpio_select_periph_A(GPIO_PIN_PB29, 0); |
| 110 | |
| 111 | /* Enable GCLK3 with no input divider, from OSC0 (crystal) */ |
| 112 | sm_writel(PM_GCCTRL(3), SM_BIT(CEN)); |
| 113 | } |