blob: 4ece11ac873a73a2c8fd07d5dd62256c9606a2dc [file] [log] [blame]
Mark Jackson13b50fe2008-07-30 13:07:27 +01001/*
2 * Copyright (C) 2006 Atmel Corporation
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22#include <common.h>
23
24#include <asm/io.h>
25#include <asm/sdram.h>
26#include <asm/arch/clk.h>
27#include <asm/arch/gpio.h>
28#include <asm/arch/hmatrix.h>
29#include <lcd.h>
30
31#define SM_PM_GCCTRL 0x0060
32
33DECLARE_GLOBAL_DATA_PTR;
34
35static const struct sdram_config sdram_config = {
36 .data_bits = SDRAM_DATA_16BIT,
37 .row_bits = 13,
38 .col_bits = 9,
39 .bank_bits = 2,
40 .cas = 3,
41 .twr = 2,
42 .trc = 6,
43 .trp = 2,
44 .trcd = 2,
45 .tras = 6,
46 .txsr = 6,
47 /* 15.6 us */
48 .refresh_period = (156 * (SDRAMC_BUS_HZ / 1000)) / 10000,
49};
50
51int board_early_init_f(void)
52{
53 /* Enable SDRAM in the EBI mux */
54 hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));
55
56 gpio_enable_ebi();
57 gpio_enable_usart1();
58
59 /* enable higher address lines for larger flash devices */
60 gpio_select_periph_A(GPIO_PIN_PE16, 0); /* ADDR23 */
61 gpio_select_periph_A(GPIO_PIN_PE17, 0); /* ADDR24 */
62 gpio_select_periph_A(GPIO_PIN_PE18, 0); /* ADDR25 */
63
64 /* enable data flash chip select */
65 gpio_select_periph_A(GPIO_PIN_PE25, 0); /* NCS2 */
66
67 /* de-assert "force sys reset" pin */
68 gpio_set_value(GPIO_PIN_PD15, 1); /* FORCE RESET */
69 gpio_select_pio(GPIO_PIN_PD15, GPIOF_OUTPUT);
70
71 /* init custom i/o */
72 /* cpu type inputs */
73 gpio_select_pio(GPIO_PIN_PE19, 0);
74 gpio_select_pio(GPIO_PIN_PE20, 0);
75 gpio_select_pio(GPIO_PIN_PE23, 0);
76 /* main board type inputs */
77 gpio_select_pio(GPIO_PIN_PB19, 0);
78 gpio_select_pio(GPIO_PIN_PB29, 0);
79 /* DEBUG input (use weak pullup) */
80 gpio_select_pio(GPIO_PIN_PE21, GPIOF_PULLUP);
81
82 /* are we suppressing the console ? */
83 if (gpio_get_value(GPIO_PIN_PE21) == 1)
84 gd->flags |= GD_FLG_SILENT;
85
86 /* reset phys */
87 gpio_select_pio(GPIO_PIN_PE24, 0);
88 gpio_set_value(GPIO_PIN_PC18, 1); /* PHY RESET */
89 gpio_select_pio(GPIO_PIN_PC18, GPIOF_OUTPUT);
90
91 /* GCLK0 - 10MHz clock */
92 writel(0x00000004, (void *)SM_BASE + SM_PM_GCCTRL);
93 gpio_select_periph_A(GPIO_PIN_PA30, 0);
94
95 udelay(5000);
96
97 /* release phys reset */
98 gpio_set_value(GPIO_PIN_PC18, 0); /* PHY RESET (Release) */
99
100#if defined(CONFIG_MACB)
101 /* init macb0 pins */
102 gpio_select_periph_A(GPIO_PIN_PC3, 0); /* TXD0 */
103 gpio_select_periph_A(GPIO_PIN_PC4, 0); /* TXD1 */
104 gpio_select_periph_A(GPIO_PIN_PC7, 0); /* TXEN */
105 gpio_select_periph_A(GPIO_PIN_PC8, 0); /* TXCK */
106 gpio_select_periph_A(GPIO_PIN_PC9, 0); /* RXD0 */
107 gpio_select_periph_A(GPIO_PIN_PC10, 0); /* RXD1 */
108 gpio_select_periph_A(GPIO_PIN_PC13, 0); /* RXER */
109 gpio_select_periph_A(GPIO_PIN_PC15, 0); /* RXDV */
110 gpio_select_periph_A(GPIO_PIN_PC16, 0); /* MDC */
111 gpio_select_periph_A(GPIO_PIN_PC17, 0); /* MDIO */
112#if !defined(CONFIG_RMII)
113 gpio_select_periph_A(GPIO_PIN_PC0, 0); /* COL */
114 gpio_select_periph_A(GPIO_PIN_PC1, 0); /* CRS */
115 gpio_select_periph_A(GPIO_PIN_PC2, 0); /* TXER */
116 gpio_select_periph_A(GPIO_PIN_PC5, 0); /* TXD2 */
117 gpio_select_periph_A(GPIO_PIN_PC6, 0); /* TXD3 */
118 gpio_select_periph_A(GPIO_PIN_PC11, 0); /* RXD2 */
119 gpio_select_periph_A(GPIO_PIN_PC12, 0); /* RXD3 */
120 gpio_select_periph_A(GPIO_PIN_PC14, 0); /* RXCK */
121#endif
122
123 /* init macb1 pins */
124 gpio_select_periph_B(GPIO_PIN_PD13, 0); /* TXD0 */
125 gpio_select_periph_B(GPIO_PIN_PD14, 0); /* TXD1 */
126 gpio_select_periph_B(GPIO_PIN_PD11, 0); /* TXEN */
127 gpio_select_periph_B(GPIO_PIN_PD12, 0); /* TXCK */
128 gpio_select_periph_B(GPIO_PIN_PD10, 0); /* RXD0 */
129 gpio_select_periph_B(GPIO_PIN_PD6, 0); /* RXD1 */
130 gpio_select_periph_B(GPIO_PIN_PD5, 0); /* RXER */
131 gpio_select_periph_B(GPIO_PIN_PD4, 0); /* RXDV */
132 gpio_select_periph_B(GPIO_PIN_PD3, 0); /* MDC */
133 gpio_select_periph_B(GPIO_PIN_PD2, 0); /* MDIO */
134#if !defined(CONFIG_RMII)
135 gpio_select_periph_B(GPIO_PIN_PC19, 0); /* COL */
136 gpio_select_periph_B(GPIO_PIN_PC23, 0); /* CRS */
137 gpio_select_periph_B(GPIO_PIN_PC26, 0); /* TXER */
138 gpio_select_periph_B(GPIO_PIN_PC27, 0); /* TXD2 */
139 gpio_select_periph_B(GPIO_PIN_PC28, 0); /* TXD3 */
140 gpio_select_periph_B(GPIO_PIN_PC29, 0); /* RXD2 */
141 gpio_select_periph_B(GPIO_PIN_PC30, 0); /* RXD3 */
142 gpio_select_periph_B(GPIO_PIN_PC24, 0); /* RXCK */
143#endif
144#endif
145
146#if defined(CONFIG_MMC)
147 gpio_enable_mmci();
148#endif
149
150 return 0;
151}
152
153phys_size_t initdram(int board_type)
154{
155 unsigned long expected_size;
156 unsigned long actual_size;
157 void *sdram_base;
158
159 sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE);
160
161 expected_size = sdram_init(sdram_base, &sdram_config);
162 actual_size = get_ram_size(sdram_base, expected_size);
163
164 unmap_physmem(sdram_base, EBI_SDRAM_SIZE);
165
166 if (expected_size != actual_size)
167 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
168 actual_size >> 20, expected_size >> 20);
169
170 return actual_size;
171}
172
173void board_init_info(void)
174{
175 gd->bd->bi_phy_id[0] = 0x01;
176 gd->bd->bi_phy_id[1] = 0x03;
177}
178
179/* SPI chip select control */
180#ifdef CONFIG_ATMEL_SPI
181#include <spi.h>
182
183int spi_cs_is_valid(unsigned int bus, unsigned int cs)
184{
185 return (bus == 0) && (cs == 0);
186}
187
188void spi_cs_activate(struct spi_slave *slave)
189{
190}
191
192void spi_cs_deactivate(struct spi_slave *slave)
193{
194}
195#endif /* CONFIG_ATMEL_SPI */
196
197#ifdef CONFIG_CMD_NET
198extern int macb_eth_initialize(int id, void *regs, unsigned int phy_addr);
199
200int board_eth_init(bd_t *bi)
201{
202 macb_eth_initialize(0, (void *)MACB0_BASE, bi->bi_phy_id[0]);
203 macb_eth_initialize(1, (void *)MACB1_BASE, bi->bi_phy_id[1]);
204
205 return 0;
206}
207#endif