blob: c11bb2cd105ce08a5411b031ec0c27d8f41f03bd [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>
Wenyou.Yang@microchip.comb59fe682017-07-21 13:28:40 +080010#include <debug_uart.h>
Xu, Hong0a614942011-07-31 22:49:00 +000011#include <asm/io.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020012#include <asm/arch/at91sam9261.h>
13#include <asm/arch/at91sam9261_matrix.h>
14#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD6b0b3db2009-03-21 21:07:59 +010015#include <asm/arch/at91_common.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020016#include <asm/arch/at91_rstc.h>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020017#include <asm/arch/clk.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020018#include <asm/arch/gpio.h>
Stelian Pop905ed222008-05-08 14:52:30 +020019#include <lcd.h>
20#include <atmel_lcdc.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020021#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
22#include <net.h>
Remy Bohmer7eefd922009-05-02 21:49:18 +020023#include <netdev.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020024#endif
Simon Glass0ffb9d62017-05-31 19:47:48 -060025#include <asm/mach-types.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020026
27DECLARE_GLOBAL_DATA_PTR;
28
29/* ------------------------------------------------------------------------- */
30/*
31 * Miscelaneous platform dependent initialisations
32 */
33
Stelian Pop61e69d72008-05-08 20:52:22 +020034#ifdef CONFIG_CMD_NAND
35static void at91sam9261ek_nand_hw_init(void)
36{
Xu, Hong0a614942011-07-31 22:49:00 +000037 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
38 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop61e69d72008-05-08 20:52:22 +020039 unsigned long csa;
40
41 /* Enable CS3 */
Xu, Hong0a614942011-07-31 22:49:00 +000042 csa = readl(&matrix->ebicsa);
43 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
44
45 writel(csa, &matrix->ebicsa);
Stelian Pop61e69d72008-05-08 20:52:22 +020046
47 /* Configure SMC CS3 for NAND/SmartMedia */
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020048#ifdef CONFIG_AT91SAM9G10EK
Xu, Hong0a614942011-07-31 22:49:00 +000049 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
50 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
51 &smc->cs[3].setup);
52 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(7) |
53 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(7),
54 &smc->cs[3].pulse);
55 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
56 &smc->cs[3].cycle);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020057#else
Xu, Hong0a614942011-07-31 22:49:00 +000058 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
59 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
60 &smc->cs[3].setup);
61 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
62 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
63 &smc->cs[3].pulse);
64 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
65 &smc->cs[3].cycle);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020066#endif
Xu, Hong0a614942011-07-31 22:49:00 +000067 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
68 AT91_SMC_MODE_EXNW_DISABLE |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#ifdef CONFIG_SYS_NAND_DBW_16
Xu, Hong0a614942011-07-31 22:49:00 +000070 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071#else /* CONFIG_SYS_NAND_DBW_8 */
Xu, Hong0a614942011-07-31 22:49:00 +000072 AT91_SMC_MODE_DBW_8 |
Stelian Pop61e69d72008-05-08 20:52:22 +020073#endif
Xu, Hong0a614942011-07-31 22:49:00 +000074 AT91_SMC_MODE_TDF_CYCLE(2),
75 &smc->cs[3].mode);
Stelian Pop61e69d72008-05-08 20:52:22 +020076
Wenyou Yang78f89762016-02-03 10:16:50 +080077 at91_periph_clk_enable(ATMEL_ID_PIOC);
Stelian Pop61e69d72008-05-08 20:52:22 +020078
79 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010080 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop61e69d72008-05-08 20:52:22 +020081
82 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010083 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Stelian Pop61e69d72008-05-08 20:52:22 +020084
85 at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
86 at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
87}
88#endif
89
Stelian Pop61e69d72008-05-08 20:52:22 +020090#ifdef CONFIG_DRIVER_DM9000
91static void at91sam9261ek_dm9000_hw_init(void)
92{
Xu, Hong0a614942011-07-31 22:49:00 +000093 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
94
Stelian Pop61e69d72008-05-08 20:52:22 +020095 /* Configure SMC CS2 for DM9000 */
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020096#ifdef CONFIG_AT91SAM9G10EK
Xu, Hong0a614942011-07-31 22:49:00 +000097 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
98 AT91_SMC_SETUP_NRD(3) | AT91_SMC_SETUP_NCS_RD(0),
99 &smc->cs[2].setup);
100 writel(AT91_SMC_PULSE_NWE(6) | AT91_SMC_PULSE_NCS_WR(8) |
101 AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(8),
102 &smc->cs[2].pulse);
103 writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
104 &smc->cs[2].cycle);
105 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
106 AT91_SMC_MODE_EXNW_DISABLE |
107 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
108 AT91_SMC_MODE_TDF_CYCLE(1),
109 &smc->cs[2].mode);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200110#else
Xu, Hong0a614942011-07-31 22:49:00 +0000111 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
112 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
113 &smc->cs[2].setup);
114 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
115 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
116 &smc->cs[2].pulse);
117 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
118 &smc->cs[2].cycle);
119 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
120 AT91_SMC_MODE_EXNW_DISABLE |
121 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
122 AT91_SMC_MODE_TDF_CYCLE(1),
123 &smc->cs[2].mode);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200124#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200125
126 /* Configure Reset signal as output */
127 at91_set_gpio_output(AT91_PIN_PC10, 0);
128
129 /* Configure Interrupt pin as input, no pull-up */
130 at91_set_gpio_input(AT91_PIN_PC11, 0);
131}
132#endif
133
Stelian Pop905ed222008-05-08 14:52:30 +0200134#ifdef CONFIG_LCD
135vidinfo_t panel_info = {
Jeroen Hofsteee887b722014-06-10 00:16:23 +0200136 .vl_col = 240,
137 .vl_row = 320,
138 .vl_clk = 4965000,
139 .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
140 ATMEL_LCDC_INVFRAME_INVERTED,
141 .vl_bpix = 3,
142 .vl_tft = 1,
143 .vl_hsync_len = 5,
144 .vl_left_margin = 1,
145 .vl_right_margin = 33,
146 .vl_vsync_len = 1,
147 .vl_upper_margin = 1,
148 .vl_lower_margin = 0,
149 .mmio = ATMEL_BASE_LCDC,
Stelian Pop905ed222008-05-08 14:52:30 +0200150};
151
152void lcd_enable(void)
153{
154 at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
155}
156
157void lcd_disable(void)
158{
159 at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
160}
161
162static void at91sam9261ek_lcd_hw_init(void)
163{
164 at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
165 at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
166 at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
167 at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
168 at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
169 at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
170 at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
171 at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
172 at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
173 at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
174 at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
175 at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
176 at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
177 at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
178 at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
179 at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
180 at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
181 at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
182 at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
183 at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
184 at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
185 at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
186
Wenyou Yang78f89762016-02-03 10:16:50 +0800187 at91_system_clk_enable(AT91_PMC_HCK1);
Stelian Pop905ed222008-05-08 14:52:30 +0200188
Xu, Hong0a614942011-07-31 22:49:00 +0000189 /* For 9G10EK, let U-Boot allocate the framebuffer in SDRAM */
190#ifdef CONFIG_AT91SAM9261EK
191 gd->fb_base = ATMEL_BASE_SRAM;
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200192#endif
Stelian Pop905ed222008-05-08 14:52:30 +0200193}
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200194
195#ifdef CONFIG_LCD_INFO
196#include <nand.h>
197#include <version.h>
198
199void lcd_show_board_info(void)
200{
201 ulong dram_size, nand_size;
202 int i;
203 char temp[32];
204
205 lcd_printf ("%s\n", U_BOOT_VERSION);
206 lcd_printf ("(C) 2008 ATMEL Corp\n");
207 lcd_printf ("at91support@atmel.com\n");
208 lcd_printf ("%s CPU at %s MHz\n",
Xu, Hong0a614942011-07-31 22:49:00 +0000209 ATMEL_CPU_NAME,
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200210 strmhz(temp, get_cpu_clk_rate()));
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200211
212 dram_size = 0;
213 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
214 dram_size += gd->bd->bi_dram[i].size;
215 nand_size = 0;
216 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Grygorii Strashko1e096a22017-06-26 19:13:03 -0500217 nand_size += get_nand_dev_by_index(i)->size;
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200218 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
219 dram_size >> 20,
220 nand_size >> 20 );
221}
222#endif /* CONFIG_LCD_INFO */
Stelian Pop905ed222008-05-08 14:52:30 +0200223#endif
224
Wenyou.Yang@microchip.comb59fe682017-07-21 13:28:40 +0800225#ifdef CONFIG_DEBUG_UART_BOARD_INIT
226void board_debug_uart_init(void)
227{
228 at91_seriald_hw_init();
229}
230#endif
231
232#ifdef CONFIG_BOARD_EARLY_INIT_F
233int board_early_init_f(void)
234{
235#ifdef CONFIG_DEBUG_UART
236 debug_uart_init();
237#endif
238 return 0;
239}
240#endif
241
Stelian Pop61e69d72008-05-08 20:52:22 +0200242int board_init(void)
243{
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200244#ifdef CONFIG_AT91SAM9G10EK
245 /* arch number of AT91SAM9G10EK-Board */
246 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G10EK;
247#else
Stelian Pop61e69d72008-05-08 20:52:22 +0200248 /* arch number of AT91SAM9261EK-Board */
249 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK;
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200250#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200251 /* adress of boot parameters */
Xu, Hong0a614942011-07-31 22:49:00 +0000252 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop61e69d72008-05-08 20:52:22 +0200253
Stelian Pop61e69d72008-05-08 20:52:22 +0200254#ifdef CONFIG_CMD_NAND
255 at91sam9261ek_nand_hw_init();
256#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200257#ifdef CONFIG_DRIVER_DM9000
258 at91sam9261ek_dm9000_hw_init();
259#endif
Stelian Pop905ed222008-05-08 14:52:30 +0200260#ifdef CONFIG_LCD
261 at91sam9261ek_lcd_hw_init();
262#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200263 return 0;
264}
265
Remy Bohmer7eefd922009-05-02 21:49:18 +0200266#ifdef CONFIG_DRIVER_DM9000
Wolfgang Denke5032c82009-12-07 21:06:40 +0100267int board_eth_init(bd_t *bis)
268{
Remy Bohmer7eefd922009-05-02 21:49:18 +0200269 return dm9000_initialize(bis);
Wolfgang Denke5032c82009-12-07 21:06:40 +0100270}
271#endif
272
Stelian Pop61e69d72008-05-08 20:52:22 +0200273int dram_init(void)
274{
Xu, Hong0a614942011-07-31 22:49:00 +0000275 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
276 CONFIG_SYS_SDRAM_SIZE);
277
Stelian Pop61e69d72008-05-08 20:52:22 +0200278 return 0;
279}
280
281#ifdef CONFIG_RESET_PHY_R
282void reset_phy(void)
283{
284#ifdef CONFIG_DRIVER_DM9000
285 /*
286 * Initialize ethernet HW addr prior to starting Linux,
287 * needed for nfsroot
288 */
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500289 eth_init();
Stelian Pop61e69d72008-05-08 20:52:22 +0200290#endif
291}
292#endif