blob: 6df741e397625add6a906d88e21f09ea121154bd [file] [log] [blame]
Mark Jackson1744f5b2008-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>
Ben Warren2f2b6b62008-08-31 22:22:04 -070023#include <netdev.h>
Mark Jackson1744f5b2008-07-30 13:07:27 +010024
25#include <asm/io.h>
26#include <asm/sdram.h>
27#include <asm/arch/clk.h>
28#include <asm/arch/gpio.h>
29#include <asm/arch/hmatrix.h>
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020030#include <asm/arch/portmux.h>
Mark Jackson1744f5b2008-07-30 13:07:27 +010031#include <lcd.h>
32
Mark Jackson7daef802009-02-13 15:48:18 +000033#include "../../../cpu/at32ap/hsmc3.h"
34
Mark Jackson1744f5b2008-07-30 13:07:27 +010035DECLARE_GLOBAL_DATA_PTR;
36
37static const struct sdram_config sdram_config = {
38 .data_bits = SDRAM_DATA_16BIT,
39 .row_bits = 13,
40 .col_bits = 9,
41 .bank_bits = 2,
42 .cas = 3,
43 .twr = 2,
44 .trc = 6,
45 .trp = 2,
46 .trcd = 2,
47 .tras = 6,
48 .txsr = 6,
49 /* 15.6 us */
50 .refresh_period = (156 * (SDRAMC_BUS_HZ / 1000)) / 10000,
51};
52
53int board_early_init_f(void)
54{
55 /* Enable SDRAM in the EBI mux */
56 hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));
57
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020058 /* Enable 26 address bits and NCS2 */
59 portmux_enable_ebi(16, 26, PORTMUX_EBI_CS(2), PORTMUX_DRIVE_HIGH);
60 portmux_enable_usart1(PORTMUX_DRIVE_MIN);
Mark Jackson1744f5b2008-07-30 13:07:27 +010061
62 /* de-assert "force sys reset" pin */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020063 portmux_select_gpio(PORTMUX_PORT_D, 1 << 15,
64 PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
Mark Jackson1744f5b2008-07-30 13:07:27 +010065
66 /* init custom i/o */
67 /* cpu type inputs */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020068 portmux_select_gpio(PORTMUX_PORT_E, (1 << 19) | (1 << 20) | (1 << 23),
69 PORTMUX_DIR_INPUT);
Mark Jackson1744f5b2008-07-30 13:07:27 +010070 /* main board type inputs */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020071 portmux_select_gpio(PORTMUX_PORT_B, (1 << 19) | (1 << 29),
72 PORTMUX_DIR_INPUT);
Mark Jackson1744f5b2008-07-30 13:07:27 +010073 /* DEBUG input (use weak pullup) */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020074 portmux_select_gpio(PORTMUX_PORT_E, 1 << 21,
75 PORTMUX_DIR_INPUT | PORTMUX_PULL_UP);
Mark Jackson1744f5b2008-07-30 13:07:27 +010076
77 /* are we suppressing the console ? */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020078 if (gpio_get_value(GPIO_PIN_PE(21)) == 1)
Mark Jackson6685bf12008-10-03 11:48:57 +010079 gd->flags |= (GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE);
Mark Jackson1744f5b2008-07-30 13:07:27 +010080
81 /* reset phys */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020082 portmux_select_gpio(PORTMUX_PORT_E, 1 << 24, PORTMUX_DIR_INPUT);
83 portmux_select_gpio(PORTMUX_PORT_C, 1 << 18,
84 PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
Mark Jackson1744f5b2008-07-30 13:07:27 +010085
Mark Jackson1744f5b2008-07-30 13:07:27 +010086 udelay(5000);
87
88 /* release phys reset */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020089 gpio_set_value(GPIO_PIN_PC(18), 0); /* PHY RESET (Release) */
Mark Jackson1744f5b2008-07-30 13:07:27 +010090
Mark Jackson7daef802009-02-13 15:48:18 +000091 /* setup Data Flash chip select (NCS2) */
92 hsmc3_writel(MODE2, 0x20121003);
93 hsmc3_writel(CYCLE2, 0x000a0009);
94 hsmc3_writel(PULSE2, 0x0a060806);
95 hsmc3_writel(SETUP2, 0x00030102);
96
97 /* setup FRAM chip select (NCS3) */
98 hsmc3_writel(MODE3, 0x10120001);
99 hsmc3_writel(CYCLE3, 0x001e001d);
100 hsmc3_writel(PULSE3, 0x08040704);
101 hsmc3_writel(SETUP3, 0x02050204);
102
Mark Jackson1744f5b2008-07-30 13:07:27 +0100103#if defined(CONFIG_MACB)
104 /* init macb0 pins */
Haavard Skinnemoen610b3622008-08-29 21:09:49 +0200105 portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
106 portmux_enable_macb1(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
Mark Jackson1744f5b2008-07-30 13:07:27 +0100107#endif
108
109#if defined(CONFIG_MMC)
Haavard Skinnemoen610b3622008-08-29 21:09:49 +0200110 portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW);
Mark Jackson1744f5b2008-07-30 13:07:27 +0100111#endif
112
113 return 0;
114}
115
116phys_size_t initdram(int board_type)
117{
118 unsigned long expected_size;
119 unsigned long actual_size;
120 void *sdram_base;
121
122 sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE);
123
124 expected_size = sdram_init(sdram_base, &sdram_config);
125 actual_size = get_ram_size(sdram_base, expected_size);
126
127 unmap_physmem(sdram_base, EBI_SDRAM_SIZE);
128
129 if (expected_size != actual_size)
130 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
131 actual_size >> 20, expected_size >> 20);
132
133 return actual_size;
134}
135
Haavard Skinnemoend6799f72008-08-31 18:46:35 +0200136int board_early_init_r(void)
Mark Jackson1744f5b2008-07-30 13:07:27 +0100137{
138 gd->bd->bi_phy_id[0] = 0x01;
139 gd->bd->bi_phy_id[1] = 0x03;
Haavard Skinnemoend6799f72008-08-31 18:46:35 +0200140 return 0;
Mark Jackson1744f5b2008-07-30 13:07:27 +0100141}
142
Mark Jackson831b9462008-11-24 12:10:56 +0000143int board_postclk_init(void)
144{
145 /* Use GCLK0 as 10MHz output */
146 gclk_enable_output(0, PORTMUX_DRIVE_LOW);
147 gclk_set_rate(0, GCLK_PARENT_OSC0, 10000000);
148 return 0;
149}
150
Mark Jackson1744f5b2008-07-30 13:07:27 +0100151/* SPI chip select control */
152#ifdef CONFIG_ATMEL_SPI
153#include <spi.h>
154
155int spi_cs_is_valid(unsigned int bus, unsigned int cs)
156{
157 return (bus == 0) && (cs == 0);
158}
159
160void spi_cs_activate(struct spi_slave *slave)
161{
162}
163
164void spi_cs_deactivate(struct spi_slave *slave)
165{
166}
167#endif /* CONFIG_ATMEL_SPI */
168
169#ifdef CONFIG_CMD_NET
Mark Jackson1744f5b2008-07-30 13:07:27 +0100170int board_eth_init(bd_t *bi)
171{
172 macb_eth_initialize(0, (void *)MACB0_BASE, bi->bi_phy_id[0]);
173 macb_eth_initialize(1, (void *)MACB1_BASE, bi->bi_phy_id[1]);
174
175 return 0;
176}
177#endif