7fd078125424d1b029d188733f29f1a522bae57c
[platform/kernel/u-boot.git] / board / miromico / hammerhead / hammerhead.c
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 <common.h>
26
27 #include <asm/io.h>
28 #include <asm/sdram.h>
29 #include <asm/arch/clk.h>
30 #include <asm/arch/hmatrix.h>
31 #include <asm/arch/memory-map.h>
32 #include <asm/arch/portmux.h>
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 static const struct sdram_config sdram_config = {
37         .data_bits      = SDRAM_DATA_32BIT,
38         .row_bits       = 13,
39         .col_bits       = 9,
40         .bank_bits      = 2,
41         .cas            = 3,
42         .twr            = 2,
43         .trc            = 7,
44         .trp            = 2,
45         .trcd           = 2,
46         .tras           = 5,
47         .txsr           = 5,
48         /* 7.81 us */
49         .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000,
50 };
51
52 extern int macb_eth_initialize(int id, void *regs, unsigned int phy_addr);
53
54 #ifdef CONFIG_CMD_NET
55 int board_eth_init(bd_t *bis)
56 {
57         return macb_eth_initialize(0, (void *)MACB0_BASE, bis->bi_phy_id[0]);
58 }
59 #endif
60
61 int board_early_init_f(void)
62 {
63         /* Enable SDRAM in the EBI mux */
64         hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));
65
66         portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH);
67         portmux_enable_usart1(PORTMUX_DRIVE_MIN);
68
69 #if defined(CONFIG_MACB)
70         portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
71 #endif
72 #if defined(CONFIG_MMC)
73         portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW);
74 #endif
75         return 0;
76 }
77
78 phys_size_t initdram(int board_type)
79 {
80         unsigned long expected_size;
81         unsigned long actual_size;
82         void *sdram_base;
83
84         sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE);
85
86         expected_size = sdram_init(sdram_base, &sdram_config);
87         actual_size = get_ram_size(sdram_base, expected_size);
88
89         unmap_physmem(sdram_base, EBI_SDRAM_SIZE);
90
91         if (expected_size != actual_size)
92                 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
93                        actual_size >> 20, expected_size >> 20);
94
95         return actual_size;
96 }
97
98 int board_early_init_r(void)
99 {
100         gd->bd->bi_phy_id[0] = 0x01;
101         return 0;
102 }
103
104 int board_postclk_init(void)
105 {
106         /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */
107         gclk_enable_output(3, PORTMUX_DRIVE_LOW);
108         gclk_set_rate(3, GCLK_PARENT_OSC0, 25000000);
109         return 0;
110 }