blob: 7b7cd2c42627796b069bb7313f3dc9350b4a606c [file] [log] [blame]
Stelian Pop61e69d72008-05-08 20:52:22 +02001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Pop61e69d72008-05-08 20:52:22 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Stelian Pop61e69d72008-05-08 20:52:22 +02007 */
8
9#include <common.h>
Xu, Hong0a614942011-07-31 22:49:00 +000010#include <asm/io.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020011#include <asm/arch/at91sam9261.h>
12#include <asm/arch/at91sam9261_matrix.h>
13#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD6b0b3db2009-03-21 21:07:59 +010014#include <asm/arch/at91_common.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020015#include <asm/arch/at91_rstc.h>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020016#include <asm/arch/clk.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020017#include <asm/arch/gpio.h>
Stelian Pop905ed222008-05-08 14:52:30 +020018#include <lcd.h>
19#include <atmel_lcdc.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020020#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
21#include <net.h>
Remy Bohmer7eefd922009-05-02 21:49:18 +020022#include <netdev.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020023#endif
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/* ------------------------------------------------------------------------- */
28/*
29 * Miscelaneous platform dependent initialisations
30 */
31
Stelian Pop61e69d72008-05-08 20:52:22 +020032#ifdef CONFIG_CMD_NAND
33static void at91sam9261ek_nand_hw_init(void)
34{
Xu, Hong0a614942011-07-31 22:49:00 +000035 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
36 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop61e69d72008-05-08 20:52:22 +020037 unsigned long csa;
38
39 /* Enable CS3 */
Xu, Hong0a614942011-07-31 22:49:00 +000040 csa = readl(&matrix->ebicsa);
41 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
42
43 writel(csa, &matrix->ebicsa);
Stelian Pop61e69d72008-05-08 20:52:22 +020044
45 /* Configure SMC CS3 for NAND/SmartMedia */
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020046#ifdef CONFIG_AT91SAM9G10EK
Xu, Hong0a614942011-07-31 22:49:00 +000047 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
48 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
49 &smc->cs[3].setup);
50 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(7) |
51 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(7),
52 &smc->cs[3].pulse);
53 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
54 &smc->cs[3].cycle);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020055#else
Xu, Hong0a614942011-07-31 22:49:00 +000056 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
57 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
58 &smc->cs[3].setup);
59 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
60 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
61 &smc->cs[3].pulse);
62 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
63 &smc->cs[3].cycle);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020064#endif
Xu, Hong0a614942011-07-31 22:49:00 +000065 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
66 AT91_SMC_MODE_EXNW_DISABLE |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020067#ifdef CONFIG_SYS_NAND_DBW_16
Xu, Hong0a614942011-07-31 22:49:00 +000068 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#else /* CONFIG_SYS_NAND_DBW_8 */
Xu, Hong0a614942011-07-31 22:49:00 +000070 AT91_SMC_MODE_DBW_8 |
Stelian Pop61e69d72008-05-08 20:52:22 +020071#endif
Xu, Hong0a614942011-07-31 22:49:00 +000072 AT91_SMC_MODE_TDF_CYCLE(2),
73 &smc->cs[3].mode);
Stelian Pop61e69d72008-05-08 20:52:22 +020074
Wenyou Yang78f89762016-02-03 10:16:50 +080075 at91_periph_clk_enable(ATMEL_ID_PIOC);
Stelian Pop61e69d72008-05-08 20:52:22 +020076
77 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010078 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop61e69d72008-05-08 20:52:22 +020079
80 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010081 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Stelian Pop61e69d72008-05-08 20:52:22 +020082
83 at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
84 at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
85}
86#endif
87
Stelian Pop61e69d72008-05-08 20:52:22 +020088#ifdef CONFIG_DRIVER_DM9000
89static void at91sam9261ek_dm9000_hw_init(void)
90{
Xu, Hong0a614942011-07-31 22:49:00 +000091 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
92
Stelian Pop61e69d72008-05-08 20:52:22 +020093 /* Configure SMC CS2 for DM9000 */
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020094#ifdef CONFIG_AT91SAM9G10EK
Xu, Hong0a614942011-07-31 22:49:00 +000095 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
96 AT91_SMC_SETUP_NRD(3) | AT91_SMC_SETUP_NCS_RD(0),
97 &smc->cs[2].setup);
98 writel(AT91_SMC_PULSE_NWE(6) | AT91_SMC_PULSE_NCS_WR(8) |
99 AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(8),
100 &smc->cs[2].pulse);
101 writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
102 &smc->cs[2].cycle);
103 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
104 AT91_SMC_MODE_EXNW_DISABLE |
105 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
106 AT91_SMC_MODE_TDF_CYCLE(1),
107 &smc->cs[2].mode);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200108#else
Xu, Hong0a614942011-07-31 22:49:00 +0000109 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
110 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
111 &smc->cs[2].setup);
112 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
113 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
114 &smc->cs[2].pulse);
115 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
116 &smc->cs[2].cycle);
117 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
118 AT91_SMC_MODE_EXNW_DISABLE |
119 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
120 AT91_SMC_MODE_TDF_CYCLE(1),
121 &smc->cs[2].mode);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200122#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200123
124 /* Configure Reset signal as output */
125 at91_set_gpio_output(AT91_PIN_PC10, 0);
126
127 /* Configure Interrupt pin as input, no pull-up */
128 at91_set_gpio_input(AT91_PIN_PC11, 0);
129}
130#endif
131
Stelian Pop905ed222008-05-08 14:52:30 +0200132#ifdef CONFIG_LCD
133vidinfo_t panel_info = {
Jeroen Hofsteee887b722014-06-10 00:16:23 +0200134 .vl_col = 240,
135 .vl_row = 320,
136 .vl_clk = 4965000,
137 .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
138 ATMEL_LCDC_INVFRAME_INVERTED,
139 .vl_bpix = 3,
140 .vl_tft = 1,
141 .vl_hsync_len = 5,
142 .vl_left_margin = 1,
143 .vl_right_margin = 33,
144 .vl_vsync_len = 1,
145 .vl_upper_margin = 1,
146 .vl_lower_margin = 0,
147 .mmio = ATMEL_BASE_LCDC,
Stelian Pop905ed222008-05-08 14:52:30 +0200148};
149
150void lcd_enable(void)
151{
152 at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
153}
154
155void lcd_disable(void)
156{
157 at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
158}
159
160static void at91sam9261ek_lcd_hw_init(void)
161{
162 at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
163 at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
164 at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
165 at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
166 at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
167 at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
168 at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
169 at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
170 at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
171 at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
172 at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
173 at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
174 at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
175 at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
176 at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
177 at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
178 at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
179 at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
180 at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
181 at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
182 at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
183 at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
184
Wenyou Yang78f89762016-02-03 10:16:50 +0800185 at91_system_clk_enable(AT91_PMC_HCK1);
Stelian Pop905ed222008-05-08 14:52:30 +0200186
Xu, Hong0a614942011-07-31 22:49:00 +0000187 /* For 9G10EK, let U-Boot allocate the framebuffer in SDRAM */
188#ifdef CONFIG_AT91SAM9261EK
189 gd->fb_base = ATMEL_BASE_SRAM;
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200190#endif
Stelian Pop905ed222008-05-08 14:52:30 +0200191}
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200192
193#ifdef CONFIG_LCD_INFO
194#include <nand.h>
195#include <version.h>
196
197void lcd_show_board_info(void)
198{
199 ulong dram_size, nand_size;
200 int i;
201 char temp[32];
202
203 lcd_printf ("%s\n", U_BOOT_VERSION);
204 lcd_printf ("(C) 2008 ATMEL Corp\n");
205 lcd_printf ("at91support@atmel.com\n");
206 lcd_printf ("%s CPU at %s MHz\n",
Xu, Hong0a614942011-07-31 22:49:00 +0000207 ATMEL_CPU_NAME,
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200208 strmhz(temp, get_cpu_clk_rate()));
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200209
210 dram_size = 0;
211 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
212 dram_size += gd->bd->bi_dram[i].size;
213 nand_size = 0;
214 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
215 nand_size += nand_info[i].size;
216 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
217 dram_size >> 20,
218 nand_size >> 20 );
219}
220#endif /* CONFIG_LCD_INFO */
Stelian Pop905ed222008-05-08 14:52:30 +0200221#endif
222
Stelian Pop61e69d72008-05-08 20:52:22 +0200223int board_init(void)
224{
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200225#ifdef CONFIG_AT91SAM9G10EK
226 /* arch number of AT91SAM9G10EK-Board */
227 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G10EK;
228#else
Stelian Pop61e69d72008-05-08 20:52:22 +0200229 /* arch number of AT91SAM9261EK-Board */
230 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK;
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200231#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200232 /* adress of boot parameters */
Xu, Hong0a614942011-07-31 22:49:00 +0000233 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop61e69d72008-05-08 20:52:22 +0200234
Xu, Hong0a614942011-07-31 22:49:00 +0000235 at91_seriald_hw_init();
Stelian Pop61e69d72008-05-08 20:52:22 +0200236#ifdef CONFIG_CMD_NAND
237 at91sam9261ek_nand_hw_init();
238#endif
239#ifdef CONFIG_HAS_DATAFLASH
Jean-Christophe PLAGNIOL-VILLARD12dcdef2009-03-21 21:07:59 +0100240 at91_spi0_hw_init(1 << 0);
Stelian Pop61e69d72008-05-08 20:52:22 +0200241#endif
242#ifdef CONFIG_DRIVER_DM9000
243 at91sam9261ek_dm9000_hw_init();
244#endif
Stelian Pop905ed222008-05-08 14:52:30 +0200245#ifdef CONFIG_LCD
246 at91sam9261ek_lcd_hw_init();
247#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200248 return 0;
249}
250
Remy Bohmer7eefd922009-05-02 21:49:18 +0200251#ifdef CONFIG_DRIVER_DM9000
Wolfgang Denke5032c82009-12-07 21:06:40 +0100252int board_eth_init(bd_t *bis)
253{
Remy Bohmer7eefd922009-05-02 21:49:18 +0200254 return dm9000_initialize(bis);
Wolfgang Denke5032c82009-12-07 21:06:40 +0100255}
256#endif
257
Stelian Pop61e69d72008-05-08 20:52:22 +0200258int dram_init(void)
259{
Xu, Hong0a614942011-07-31 22:49:00 +0000260 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
261 CONFIG_SYS_SDRAM_SIZE);
262
Stelian Pop61e69d72008-05-08 20:52:22 +0200263 return 0;
264}
265
266#ifdef CONFIG_RESET_PHY_R
267void reset_phy(void)
268{
269#ifdef CONFIG_DRIVER_DM9000
270 /*
271 * Initialize ethernet HW addr prior to starting Linux,
272 * needed for nfsroot
273 */
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500274 eth_init();
Stelian Pop61e69d72008-05-08 20:52:22 +0200275#endif
276}
277#endif