blob: 5de52b9197e6939a3eb3626606fda1fafdac9d86 [file] [log] [blame]
Stelian Pop6afcabf2008-02-07 16:37:54 +00001/*
2 * (C) Copyright 2007-2008
Stelian Pop567fb852008-05-08 22:52:09 +02003 * Stelian Pop <stelian.pop@leadtechdesign.com>
Stelian Pop6afcabf2008-02-07 16:37:54 +00004 * Lead Tech Design <www.leadtechdesign.com>
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>
Stelian Pop983c1db2008-03-26 20:52:32 +010026#include <asm/arch/at91cap9.h>
27#include <asm/arch/at91cap9_matrix.h>
Stelian Pop4f6c8102008-05-08 20:52:10 +020028#include <asm/arch/at91sam9_smc.h>
Stelian Pop983c1db2008-03-26 20:52:32 +010029#include <asm/arch/at91_pmc.h>
30#include <asm/arch/at91_rstc.h>
31#include <asm/arch/gpio.h>
32#include <asm/arch/io.h>
Jean-Christophe PLAGNIOL-VILLARD64d79202008-02-17 14:15:30 +010033#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
34#include <net.h>
35#endif
Stelian Pop6afcabf2008-02-07 16:37:54 +000036
37#define MP_BLOCK_3_BASE 0xFDF00000
38
39DECLARE_GLOBAL_DATA_PTR;
40
41/* ------------------------------------------------------------------------- */
42/*
43 * Miscelaneous platform dependent initialisations
44 */
45
46static void at91cap9_serial_hw_init(void)
47{
48#ifdef CONFIG_USART0
Stelian Pop983c1db2008-03-26 20:52:32 +010049 at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
50 at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
51 at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US0);
Stelian Pop6afcabf2008-02-07 16:37:54 +000052#endif
53
54#ifdef CONFIG_USART1
Stelian Pop983c1db2008-03-26 20:52:32 +010055 at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
56 at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
57 at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US1);
Stelian Pop6afcabf2008-02-07 16:37:54 +000058#endif
59
60#ifdef CONFIG_USART2
Stelian Pop983c1db2008-03-26 20:52:32 +010061 at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
62 at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
63 at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_US2);
Stelian Pop6afcabf2008-02-07 16:37:54 +000064#endif
65
66#ifdef CONFIG_USART3 /* DBGU */
Stelian Pop983c1db2008-03-26 20:52:32 +010067 at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
68 at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
69 at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
Stelian Pop6afcabf2008-02-07 16:37:54 +000070#endif
Stelian Pop6afcabf2008-02-07 16:37:54 +000071}
72
73static void at91cap9_nor_hw_init(void)
74{
Stelian Pop983c1db2008-03-26 20:52:32 +010075 unsigned long csa;
76
Stelian Pop6afcabf2008-02-07 16:37:54 +000077 /* Ensure EBI supply is 3.3V */
Stelian Pop983c1db2008-03-26 20:52:32 +010078 csa = at91_sys_read(AT91_MATRIX_EBICSA);
79 at91_sys_write(AT91_MATRIX_EBICSA,
80 csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
Stelian Pop6afcabf2008-02-07 16:37:54 +000081 /* Configure SMC CS0 for parallel flash */
Stelian Pop983c1db2008-03-26 20:52:32 +010082 at91_sys_write(AT91_SMC_SETUP(0),
83 AT91_SMC_NWESETUP_(4) | AT91_SMC_NCS_WRSETUP_(2) |
84 AT91_SMC_NRDSETUP_(4) | AT91_SMC_NCS_RDSETUP_(2));
85 at91_sys_write(AT91_SMC_PULSE(0),
86 AT91_SMC_NWEPULSE_(8) | AT91_SMC_NCS_WRPULSE_(10) |
87 AT91_SMC_NRDPULSE_(8) | AT91_SMC_NCS_RDPULSE_(10));
88 at91_sys_write(AT91_SMC_CYCLE(0),
89 AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
90 at91_sys_write(AT91_SMC_MODE(0),
91 AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
92 AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE |
93 AT91_SMC_DBW_16 | AT91_SMC_TDF_(1));
Stelian Pop6afcabf2008-02-07 16:37:54 +000094}
95
96#ifdef CONFIG_CMD_NAND
97static void at91cap9_nand_hw_init(void)
98{
Stelian Pop983c1db2008-03-26 20:52:32 +010099 unsigned long csa;
100
Stelian Pop6afcabf2008-02-07 16:37:54 +0000101 /* Enable CS3 */
Stelian Pop983c1db2008-03-26 20:52:32 +0100102 csa = at91_sys_read(AT91_MATRIX_EBICSA);
103 at91_sys_write(AT91_MATRIX_EBICSA,
104 csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA |
105 AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000106
107 /* Configure SMC CS3 for NAND/SmartMedia */
Stelian Pop983c1db2008-03-26 20:52:32 +0100108 at91_sys_write(AT91_SMC_SETUP(3),
109 AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1) |
110 AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
111 at91_sys_write(AT91_SMC_PULSE(3),
112 AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6) |
113 AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
114 at91_sys_write(AT91_SMC_CYCLE(3),
115 AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
116 at91_sys_write(AT91_SMC_MODE(3),
117 AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
118 AT91_SMC_EXNWMODE_DISABLE |
119 AT91_SMC_DBW_8 | AT91_SMC_TDF_(1));
Stelian Pop6afcabf2008-02-07 16:37:54 +0000120
Stelian Pop983c1db2008-03-26 20:52:32 +0100121 at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_PIOABCD);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000122
123 /* RDY/BSY is not connected */
124
125 /* Enable NandFlash */
Stelian Pop983c1db2008-03-26 20:52:32 +0100126 at91_set_gpio_output(AT91_PIN_PD15, 1);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000127}
128#endif
129
130#ifdef CONFIG_HAS_DATAFLASH
131static void at91cap9_spi_hw_init(void)
132{
Stelian Pop983c1db2008-03-26 20:52:32 +0100133 at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */
Stelian Pop6afcabf2008-02-07 16:37:54 +0000134
Stelian Pop983c1db2008-03-26 20:52:32 +0100135 at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
136 at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
137 at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
Stelian Pop6afcabf2008-02-07 16:37:54 +0000138
Stelian Pop983c1db2008-03-26 20:52:32 +0100139 /* Enable clock */
140 at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000141}
142#endif
143
144#ifdef CONFIG_MACB
145static void at91cap9_macb_hw_init(void)
146{
Stelian Pop6afcabf2008-02-07 16:37:54 +0000147 /* Enable clock */
Stelian Pop983c1db2008-03-26 20:52:32 +0100148 at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_EMAC);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000149
150 /*
151 * Disable pull-up on:
152 * RXDV (PB22) => PHY normal mode (not Test mode)
153 * ERX0 (PB25) => PHY ADDR0
154 * ERX1 (PB26) => PHY ADDR1 => PHYADDR = 0x0
155 *
156 * PHY has internal pull-down
157 */
Stelian Pop983c1db2008-03-26 20:52:32 +0100158 writel(pin_to_mask(AT91_PIN_PB22) |
159 pin_to_mask(AT91_PIN_PB25) |
160 pin_to_mask(AT91_PIN_PB26),
161 pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000162
163 /* Need to reset PHY -> 500ms reset */
Stelian Pop983c1db2008-03-26 20:52:32 +0100164 at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
165 AT91_RSTC_ERSTL | (0x0D << 8) |
166 AT91_RSTC_URSTEN);
167
168 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000169
170 /* Wait for end hardware reset */
Stelian Pop983c1db2008-03-26 20:52:32 +0100171 while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
Stelian Pop6afcabf2008-02-07 16:37:54 +0000172
173 /* Re-enable pull-up */
Stelian Pop983c1db2008-03-26 20:52:32 +0100174 writel(pin_to_mask(AT91_PIN_PB22) |
175 pin_to_mask(AT91_PIN_PB25) |
176 pin_to_mask(AT91_PIN_PB26),
177 pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000178
Stelian Pop983c1db2008-03-26 20:52:32 +0100179 at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
180 at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
181 at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
182 at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
183 at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
184 at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
185 at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
186 at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
187 at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
188 at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
189
190#ifndef CONFIG_RMII
191 at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
192 at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
193 at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
194 at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
195 at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
196 at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
197 at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
198 at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
Stelian Pop6afcabf2008-02-07 16:37:54 +0000199#endif
Stelian Pop6afcabf2008-02-07 16:37:54 +0000200 /* Unlock EMAC, 3 0 2 1 sequence */
201#define MP_MAC_KEY0 0x5969cb2a
202#define MP_MAC_KEY1 0xb4a1872e
203#define MP_MAC_KEY2 0x05683fbc
204#define MP_MAC_KEY3 0x3634fba4
205#define UNLOCK_MAC 0x00000008
Stelian Pop983c1db2008-03-26 20:52:32 +0100206 writel(MP_MAC_KEY3, MP_BLOCK_3_BASE + 0x3c);
207 writel(MP_MAC_KEY0, MP_BLOCK_3_BASE + 0x30);
208 writel(MP_MAC_KEY2, MP_BLOCK_3_BASE + 0x38);
209 writel(MP_MAC_KEY1, MP_BLOCK_3_BASE + 0x34);
210 writel(UNLOCK_MAC, MP_BLOCK_3_BASE + 0x40);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000211}
212#endif
213
214#ifdef CONFIG_USB_OHCI_NEW
215static void at91cap9_uhp_hw_init(void)
216{
217 /* Unlock USB OHCI, 3 2 0 1 sequence */
218#define MP_OHCI_KEY0 0x896c11ca
219#define MP_OHCI_KEY1 0x68ebca21
220#define MP_OHCI_KEY2 0x4823efbc
221#define MP_OHCI_KEY3 0x8651aae4
222#define UNLOCK_OHCI 0x00000010
Stelian Pop983c1db2008-03-26 20:52:32 +0100223 writel(MP_OHCI_KEY3, MP_BLOCK_3_BASE + 0x3c);
224 writel(MP_OHCI_KEY2, MP_BLOCK_3_BASE + 0x38);
225 writel(MP_OHCI_KEY0, MP_BLOCK_3_BASE + 0x30);
226 writel(MP_OHCI_KEY1, MP_BLOCK_3_BASE + 0x34);
227 writel(UNLOCK_OHCI, MP_BLOCK_3_BASE + 0x40);
Stelian Pop6afcabf2008-02-07 16:37:54 +0000228}
229#endif
230
231int board_init(void)
232{
233 /* Enable Ctrlc */
234 console_init_f();
235
236 /* arch number of AT91CAP9ADK-Board */
237 gd->bd->bi_arch_number = MACH_TYPE_AT91CAP9ADK;
238 /* adress of boot parameters */
239 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
240
241 at91cap9_serial_hw_init();
242 at91cap9_nor_hw_init();
243#ifdef CONFIG_CMD_NAND
244 at91cap9_nand_hw_init();
245#endif
246#ifdef CONFIG_HAS_DATAFLASH
247 at91cap9_spi_hw_init();
248#endif
249#ifdef CONFIG_MACB
250 at91cap9_macb_hw_init();
251#endif
252#ifdef CONFIG_USB_OHCI_NEW
253 at91cap9_uhp_hw_init();
254#endif
255
256 return 0;
257}
258
259int dram_init(void)
260{
261 gd->bd->bi_dram[0].start = PHYS_SDRAM;
262 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
263 return 0;
264}
265
266#ifdef CONFIG_RESET_PHY_R
267void reset_phy(void)
268{
269#ifdef CONFIG_MACB
270 /*
271 * Initialize ethernet HW addr prior to starting Linux,
272 * needed for nfsroot
273 */
274 eth_init(gd->bd);
275#endif
276}
277#endif