blob: 3d6cf9b28b8de8e7be0ee46f5cce23114534a9b7 [file] [log] [blame]
Julien May5c374c92008-06-23 13:57:52 +02001/*
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>
28
29#include <asm/io.h>
30#include <asm/sdram.h>
31#include <asm/arch/clk.h>
Julien May5c374c92008-06-23 13:57:52 +020032#include <asm/arch/hmatrix.h>
33#include <asm/arch/memory-map.h>
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020034#include <asm/arch/portmux.h>
Julien May5c374c92008-06-23 13:57:52 +020035
36DECLARE_GLOBAL_DATA_PTR;
37
38static const struct sdram_config sdram_config = {
39 .data_bits = SDRAM_DATA_32BIT,
40 .row_bits = 13,
41 .col_bits = 9,
42 .bank_bits = 2,
43 .cas = 3,
44 .twr = 2,
45 .trc = 7,
46 .trp = 2,
47 .trcd = 2,
48 .tras = 5,
49 .txsr = 5,
50 /* 7.81 us */
51 .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000,
52};
53
54extern int macb_eth_initialize(int id, void *regs, unsigned int phy_addr);
55
56#ifdef CONFIG_CMD_NET
57int board_eth_init(bd_t *bis)
58{
59 return macb_eth_initialize(0, (void *)MACB0_BASE, bis->bi_phy_id[0]);
60}
61#endif
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_usart1(PORTMUX_DRIVE_MIN);
Julien May5c374c92008-06-23 13:57:52 +020070
71#if defined(CONFIG_MACB)
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020072 portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
Julien May5c374c92008-06-23 13:57:52 +020073#endif
74#if defined(CONFIG_MMC)
Haavard Skinnemoenab0df362008-08-29 21:09:49 +020075 portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW);
Julien May5c374c92008-06-23 13:57:52 +020076#endif
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
86 sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE);
87
88 expected_size = sdram_init(sdram_base, &sdram_config);
89 actual_size = get_ram_size(sdram_base, expected_size);
90
91 unmap_physmem(sdram_base, EBI_SDRAM_SIZE);
92
93 if (expected_size != actual_size)
94 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
95 actual_size >> 20, expected_size >> 20);
96
97 return actual_size;
98}
99
100void board_init_info(void)
101{
102 gd->bd->bi_phy_id[0] = 0x01;
103}
104
105void gclk_init(void)
106{
107 /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */
108
109 /* Select GCLK3 peripheral function */
Haavard Skinnemoenab0df362008-08-29 21:09:49 +0200110 portmux_select_peripheral(PORTMUX_PORT_B, 1 << 29, PORTMUX_FUNC_A, 0);
Julien May5c374c92008-06-23 13:57:52 +0200111
112 /* Enable GCLK3 with no input divider, from OSC0 (crystal) */
113 sm_writel(PM_GCCTRL(3), SM_BIT(CEN));
114}