blob: d30a1eeef6937463d04544cb7feb82cbd00c1730 [file] [log] [blame]
Stelian Popd99a8ff2008-05-08 20:52:22 +02001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Popd99a8ff2008-05-08 20:52:22 +02004 * 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>
Xu, Hongf7aea462011-07-31 22:49:00 +000026#include <asm/io.h>
Stelian Popd99a8ff2008-05-08 20:52:22 +020027#include <asm/arch/at91sam9261.h>
28#include <asm/arch/at91sam9261_matrix.h>
29#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD1332a2a2009-03-21 21:07:59 +010030#include <asm/arch/at91_common.h>
Stelian Popd99a8ff2008-05-08 20:52:22 +020031#include <asm/arch/at91_pmc.h>
32#include <asm/arch/at91_rstc.h>
Jean-Christophe PLAGNIOL-VILLARDdc39ae92009-04-16 21:30:44 +020033#include <asm/arch/clk.h>
Stelian Popd99a8ff2008-05-08 20:52:22 +020034#include <asm/arch/gpio.h>
Stelian Pop820f2a92008-05-08 14:52:30 +020035#include <lcd.h>
36#include <atmel_lcdc.h>
Stelian Popd99a8ff2008-05-08 20:52:22 +020037#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
38#include <net.h>
Remy Bohmer60f61e62009-05-02 21:49:18 +020039#include <netdev.h>
Stelian Popd99a8ff2008-05-08 20:52:22 +020040#endif
41
42DECLARE_GLOBAL_DATA_PTR;
43
44/* ------------------------------------------------------------------------- */
45/*
46 * Miscelaneous platform dependent initialisations
47 */
48
Stelian Popd99a8ff2008-05-08 20:52:22 +020049#ifdef CONFIG_CMD_NAND
50static void at91sam9261ek_nand_hw_init(void)
51{
Xu, Hongf7aea462011-07-31 22:49:00 +000052 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
53 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
54 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Stelian Popd99a8ff2008-05-08 20:52:22 +020055 unsigned long csa;
56
57 /* Enable CS3 */
Xu, Hongf7aea462011-07-31 22:49:00 +000058 csa = readl(&matrix->ebicsa);
59 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
60
61 writel(csa, &matrix->ebicsa);
Stelian Popd99a8ff2008-05-08 20:52:22 +020062
63 /* Configure SMC CS3 for NAND/SmartMedia */
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +020064#ifdef CONFIG_AT91SAM9G10EK
Xu, Hongf7aea462011-07-31 22:49:00 +000065 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
66 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
67 &smc->cs[3].setup);
68 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(7) |
69 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(7),
70 &smc->cs[3].pulse);
71 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
72 &smc->cs[3].cycle);
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +020073#else
Xu, Hongf7aea462011-07-31 22:49:00 +000074 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
75 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
76 &smc->cs[3].setup);
77 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
78 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
79 &smc->cs[3].pulse);
80 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
81 &smc->cs[3].cycle);
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +020082#endif
Xu, Hongf7aea462011-07-31 22:49:00 +000083 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
84 AT91_SMC_MODE_EXNW_DISABLE |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020085#ifdef CONFIG_SYS_NAND_DBW_16
Xu, Hongf7aea462011-07-31 22:49:00 +000086 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020087#else /* CONFIG_SYS_NAND_DBW_8 */
Xu, Hongf7aea462011-07-31 22:49:00 +000088 AT91_SMC_MODE_DBW_8 |
Stelian Popd99a8ff2008-05-08 20:52:22 +020089#endif
Xu, Hongf7aea462011-07-31 22:49:00 +000090 AT91_SMC_MODE_TDF_CYCLE(2),
91 &smc->cs[3].mode);
Stelian Popd99a8ff2008-05-08 20:52:22 +020092
Xu, Hongf7aea462011-07-31 22:49:00 +000093 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Stelian Popd99a8ff2008-05-08 20:52:22 +020094
95 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010096 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Popd99a8ff2008-05-08 20:52:22 +020097
98 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010099 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Stelian Popd99a8ff2008-05-08 20:52:22 +0200100
101 at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
102 at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
103}
104#endif
105
Stelian Popd99a8ff2008-05-08 20:52:22 +0200106#ifdef CONFIG_DRIVER_DM9000
107static void at91sam9261ek_dm9000_hw_init(void)
108{
Xu, Hongf7aea462011-07-31 22:49:00 +0000109 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
110
Stelian Popd99a8ff2008-05-08 20:52:22 +0200111 /* Configure SMC CS2 for DM9000 */
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +0200112#ifdef CONFIG_AT91SAM9G10EK
Xu, Hongf7aea462011-07-31 22:49:00 +0000113 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
114 AT91_SMC_SETUP_NRD(3) | AT91_SMC_SETUP_NCS_RD(0),
115 &smc->cs[2].setup);
116 writel(AT91_SMC_PULSE_NWE(6) | AT91_SMC_PULSE_NCS_WR(8) |
117 AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(8),
118 &smc->cs[2].pulse);
119 writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
120 &smc->cs[2].cycle);
121 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
122 AT91_SMC_MODE_EXNW_DISABLE |
123 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
124 AT91_SMC_MODE_TDF_CYCLE(1),
125 &smc->cs[2].mode);
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +0200126#else
Xu, Hongf7aea462011-07-31 22:49:00 +0000127 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
128 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
129 &smc->cs[2].setup);
130 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
131 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
132 &smc->cs[2].pulse);
133 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
134 &smc->cs[2].cycle);
135 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
136 AT91_SMC_MODE_EXNW_DISABLE |
137 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
138 AT91_SMC_MODE_TDF_CYCLE(1),
139 &smc->cs[2].mode);
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +0200140#endif
Stelian Popd99a8ff2008-05-08 20:52:22 +0200141
142 /* Configure Reset signal as output */
143 at91_set_gpio_output(AT91_PIN_PC10, 0);
144
145 /* Configure Interrupt pin as input, no pull-up */
146 at91_set_gpio_input(AT91_PIN_PC11, 0);
147}
148#endif
149
Stelian Pop820f2a92008-05-08 14:52:30 +0200150#ifdef CONFIG_LCD
151vidinfo_t panel_info = {
152 vl_col: 240,
153 vl_row: 320,
154 vl_clk: 4965000,
155 vl_sync: ATMEL_LCDC_INVLINE_INVERTED |
156 ATMEL_LCDC_INVFRAME_INVERTED,
157 vl_bpix: 3,
158 vl_tft: 1,
159 vl_hsync_len: 5,
160 vl_left_margin: 1,
161 vl_right_margin:33,
162 vl_vsync_len: 1,
163 vl_upper_margin:1,
164 vl_lower_margin:0,
Xu, Hongf7aea462011-07-31 22:49:00 +0000165 mmio: ATMEL_BASE_LCDC,
Stelian Pop820f2a92008-05-08 14:52:30 +0200166};
167
168void lcd_enable(void)
169{
170 at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
171}
172
173void lcd_disable(void)
174{
175 at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
176}
177
178static void at91sam9261ek_lcd_hw_init(void)
179{
Xu, Hongf7aea462011-07-31 22:49:00 +0000180 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
181
Stelian Pop820f2a92008-05-08 14:52:30 +0200182 at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
183 at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
184 at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
185 at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
186 at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
187 at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
188 at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
189 at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
190 at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
191 at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
192 at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
193 at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
194 at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
195 at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
196 at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
197 at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
198 at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
199 at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
200 at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
201 at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
202 at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
203 at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
204
Xu, Hongf7aea462011-07-31 22:49:00 +0000205 writel(AT91_PMC_HCK1, &pmc->scer);
Stelian Pop820f2a92008-05-08 14:52:30 +0200206
Xu, Hongf7aea462011-07-31 22:49:00 +0000207 /* For 9G10EK, let U-Boot allocate the framebuffer in SDRAM */
208#ifdef CONFIG_AT91SAM9261EK
209 gd->fb_base = ATMEL_BASE_SRAM;
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +0200210#endif
Stelian Pop820f2a92008-05-08 14:52:30 +0200211}
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200212
213#ifdef CONFIG_LCD_INFO
214#include <nand.h>
215#include <version.h>
216
217void lcd_show_board_info(void)
218{
219 ulong dram_size, nand_size;
220 int i;
221 char temp[32];
222
223 lcd_printf ("%s\n", U_BOOT_VERSION);
224 lcd_printf ("(C) 2008 ATMEL Corp\n");
225 lcd_printf ("at91support@atmel.com\n");
226 lcd_printf ("%s CPU at %s MHz\n",
Xu, Hongf7aea462011-07-31 22:49:00 +0000227 ATMEL_CPU_NAME,
Jean-Christophe PLAGNIOL-VILLARDdc39ae92009-04-16 21:30:44 +0200228 strmhz(temp, get_cpu_clk_rate()));
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200229
230 dram_size = 0;
231 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
232 dram_size += gd->bd->bi_dram[i].size;
233 nand_size = 0;
234 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
235 nand_size += nand_info[i].size;
236 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
237 dram_size >> 20,
238 nand_size >> 20 );
239}
240#endif /* CONFIG_LCD_INFO */
Stelian Pop820f2a92008-05-08 14:52:30 +0200241#endif
242
Stelian Popd99a8ff2008-05-08 20:52:22 +0200243int board_init(void)
244{
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +0200245#ifdef CONFIG_AT91SAM9G10EK
246 /* arch number of AT91SAM9G10EK-Board */
247 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G10EK;
248#else
Stelian Popd99a8ff2008-05-08 20:52:22 +0200249 /* arch number of AT91SAM9261EK-Board */
250 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK;
Sedji Gaouaou5ccc2d92009-06-25 17:04:15 +0200251#endif
Stelian Popd99a8ff2008-05-08 20:52:22 +0200252 /* adress of boot parameters */
Xu, Hongf7aea462011-07-31 22:49:00 +0000253 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Popd99a8ff2008-05-08 20:52:22 +0200254
Xu, Hongf7aea462011-07-31 22:49:00 +0000255 at91_seriald_hw_init();
Stelian Popd99a8ff2008-05-08 20:52:22 +0200256#ifdef CONFIG_CMD_NAND
257 at91sam9261ek_nand_hw_init();
258#endif
259#ifdef CONFIG_HAS_DATAFLASH
Jean-Christophe PLAGNIOL-VILLARD7ebafb72009-03-21 21:07:59 +0100260 at91_spi0_hw_init(1 << 0);
Stelian Popd99a8ff2008-05-08 20:52:22 +0200261#endif
262#ifdef CONFIG_DRIVER_DM9000
263 at91sam9261ek_dm9000_hw_init();
264#endif
Stelian Pop820f2a92008-05-08 14:52:30 +0200265#ifdef CONFIG_LCD
266 at91sam9261ek_lcd_hw_init();
267#endif
Stelian Popd99a8ff2008-05-08 20:52:22 +0200268 return 0;
269}
270
Remy Bohmer60f61e62009-05-02 21:49:18 +0200271#ifdef CONFIG_DRIVER_DM9000
Wolfgang Denke8fac252009-12-07 21:06:40 +0100272int board_eth_init(bd_t *bis)
273{
Remy Bohmer60f61e62009-05-02 21:49:18 +0200274 return dm9000_initialize(bis);
Wolfgang Denke8fac252009-12-07 21:06:40 +0100275}
276#endif
277
Stelian Popd99a8ff2008-05-08 20:52:22 +0200278int dram_init(void)
279{
Xu, Hongf7aea462011-07-31 22:49:00 +0000280 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
281 CONFIG_SYS_SDRAM_SIZE);
282
Stelian Popd99a8ff2008-05-08 20:52:22 +0200283 return 0;
284}
285
286#ifdef CONFIG_RESET_PHY_R
287void reset_phy(void)
288{
289#ifdef CONFIG_DRIVER_DM9000
290 /*
291 * Initialize ethernet HW addr prior to starting Linux,
292 * needed for nfsroot
293 */
294 eth_init(gd->bd);
295#endif
296}
297#endif