Fixed tools/env utilities
[u-boot-openmoko/mini2440.git] / board / atmel / at91cap9adk / at91cap9adk.c
blob24861ba49de757faabb9f59326d220d6c91d0cee
1 /*
2 * (C) Copyright 2007-2008
3 * Stelian Pop <stelian.pop <at> leadtechdesign.com>
4 * Lead Tech Design <www.leadtechdesign.com>
6 * See file CREDITS for list of people who contributed to this
7 * project.
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.
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.
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
25 #include <common.h>
26 #include <asm/arch/at91cap9.h>
27 #include <asm/arch/at91cap9_matrix.h>
28 #include <asm/arch/at91sam926x_mc.h>
29 #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>
33 #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
34 #include <net.h>
35 #endif
37 #define MP_BLOCK_3_BASE 0xFDF00000
39 DECLARE_GLOBAL_DATA_PTR;
41 /* ------------------------------------------------------------------------- */
43 * Miscelaneous platform dependent initialisations
46 static void at91cap9_serial_hw_init(void)
48 #ifdef CONFIG_USART0
49 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);
52 #endif
54 #ifdef CONFIG_USART1
55 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);
58 #endif
60 #ifdef CONFIG_USART2
61 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);
64 #endif
66 #ifdef CONFIG_USART3 /* DBGU */
67 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);
70 #endif
73 static void at91cap9_nor_hw_init(void)
75 unsigned long csa;
77 /* Ensure EBI supply is 3.3V */
78 csa = at91_sys_read(AT91_MATRIX_EBICSA);
79 at91_sys_write(AT91_MATRIX_EBICSA,
80 csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
81 /* Configure SMC CS0 for parallel flash */
82 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));
96 #ifdef CONFIG_CMD_NAND
97 static void at91cap9_nand_hw_init(void)
99 unsigned long csa;
101 /* Enable CS3 */
102 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);
107 /* Configure SMC CS3 for NAND/SmartMedia */
108 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));
121 at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_PIOABCD);
123 /* RDY/BSY is not connected */
125 /* Enable NandFlash */
126 at91_set_gpio_output(AT91_PIN_PD15, 1);
128 #endif
130 #ifdef CONFIG_HAS_DATAFLASH
131 static void at91cap9_spi_hw_init(void)
133 at91_set_B_periph(AT91_PIN_PA5, 0); /* SPI0_NPCS0 */
135 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 */
139 /* Enable clock */
140 at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
142 #endif
144 #ifdef CONFIG_MACB
145 static void at91cap9_macb_hw_init(void)
147 /* Enable clock */
148 at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_EMAC);
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
156 * PHY has internal pull-down
158 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);
163 /* Need to reset PHY -> 500ms reset */
164 at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
165 AT91_RSTC_ERSTL | (0x0D << 8) |
166 AT91_RSTC_URSTEN);
168 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
170 /* Wait for end hardware reset */
171 while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL));
173 /* Re-enable pull-up */
174 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);
179 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 */
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 */
199 #endif
200 /* 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
206 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);
212 #endif
214 #ifdef CONFIG_USB_OHCI_NEW
215 static void at91cap9_uhp_hw_init(void)
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
223 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);
229 #endif
231 int board_init(void)
233 /* Enable Ctrlc */
234 console_init_f();
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;
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
256 return 0;
259 int dram_init(void)
261 gd->bd->bi_dram[0].start = PHYS_SDRAM;
262 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
263 return 0;
266 #ifdef CONFIG_RESET_PHY_R
267 void reset_phy(void)
269 #ifdef CONFIG_MACB
271 * Initialize ethernet HW addr prior to starting Linux,
272 * needed for nfsroot
274 eth_init(gd->bd);
275 #endif
277 #endif