blob: 36f2149b61878f97cd11977d558ba2230cdbad41 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stelian Pop61e69d72008-05-08 20:52:22 +02002/*
3 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01004 * Stelian Pop <stelian@popies.net>
Stelian Pop61e69d72008-05-08 20:52:22 +02005 * Lead Tech Design <www.leadtechdesign.com>
Stelian Pop61e69d72008-05-08 20:52:22 +02006 */
7
8#include <common.h>
Wenyou.Yang@microchip.comb59fe682017-07-21 13:28:40 +08009#include <debug_uart.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070010#include <init.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070011#include <vsprintf.h>
Xu, Hong0a614942011-07-31 22:49:00 +000012#include <asm/io.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020013#include <asm/arch/at91sam9261.h>
14#include <asm/arch/at91sam9261_matrix.h>
15#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD6b0b3db2009-03-21 21:07:59 +010016#include <asm/arch/at91_common.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020017#include <asm/arch/at91_rstc.h>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020018#include <asm/arch/clk.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020019#include <asm/arch/gpio.h>
Stelian Pop905ed222008-05-08 14:52:30 +020020#include <lcd.h>
21#include <atmel_lcdc.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020022#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
23#include <net.h>
Remy Bohmer7eefd922009-05-02 21:49:18 +020024#include <netdev.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020025#endif
Simon Glass0ffb9d62017-05-31 19:47:48 -060026#include <asm/mach-types.h>
Stelian Pop61e69d72008-05-08 20:52:22 +020027
28DECLARE_GLOBAL_DATA_PTR;
29
30/* ------------------------------------------------------------------------- */
31/*
32 * Miscelaneous platform dependent initialisations
33 */
34
Stelian Pop61e69d72008-05-08 20:52:22 +020035#ifdef CONFIG_CMD_NAND
36static void at91sam9261ek_nand_hw_init(void)
37{
Xu, Hong0a614942011-07-31 22:49:00 +000038 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
39 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop61e69d72008-05-08 20:52:22 +020040 unsigned long csa;
41
42 /* Enable CS3 */
Xu, Hong0a614942011-07-31 22:49:00 +000043 csa = readl(&matrix->ebicsa);
44 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
45
46 writel(csa, &matrix->ebicsa);
Stelian Pop61e69d72008-05-08 20:52:22 +020047
48 /* Configure SMC CS3 for NAND/SmartMedia */
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020049#ifdef CONFIG_AT91SAM9G10EK
Xu, Hong0a614942011-07-31 22:49:00 +000050 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
51 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
52 &smc->cs[3].setup);
53 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(7) |
54 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(7),
55 &smc->cs[3].pulse);
56 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
57 &smc->cs[3].cycle);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020058#else
Xu, Hong0a614942011-07-31 22:49:00 +000059 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
60 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
61 &smc->cs[3].setup);
62 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
63 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
64 &smc->cs[3].pulse);
65 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
66 &smc->cs[3].cycle);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020067#endif
Xu, Hong0a614942011-07-31 22:49:00 +000068 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
69 AT91_SMC_MODE_EXNW_DISABLE |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070#ifdef CONFIG_SYS_NAND_DBW_16
Xu, Hong0a614942011-07-31 22:49:00 +000071 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072#else /* CONFIG_SYS_NAND_DBW_8 */
Xu, Hong0a614942011-07-31 22:49:00 +000073 AT91_SMC_MODE_DBW_8 |
Stelian Pop61e69d72008-05-08 20:52:22 +020074#endif
Xu, Hong0a614942011-07-31 22:49:00 +000075 AT91_SMC_MODE_TDF_CYCLE(2),
76 &smc->cs[3].mode);
Stelian Pop61e69d72008-05-08 20:52:22 +020077
Wenyou Yang78f89762016-02-03 10:16:50 +080078 at91_periph_clk_enable(ATMEL_ID_PIOC);
Stelian Pop61e69d72008-05-08 20:52:22 +020079
80 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010081 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop61e69d72008-05-08 20:52:22 +020082
83 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010084 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Stelian Pop61e69d72008-05-08 20:52:22 +020085
86 at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
87 at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
88}
89#endif
90
Stelian Pop61e69d72008-05-08 20:52:22 +020091#ifdef CONFIG_DRIVER_DM9000
92static void at91sam9261ek_dm9000_hw_init(void)
93{
Xu, Hong0a614942011-07-31 22:49:00 +000094 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
95
Stelian Pop61e69d72008-05-08 20:52:22 +020096 /* Configure SMC CS2 for DM9000 */
Sedji Gaouaou97a031b2009-06-25 17:04:15 +020097#ifdef CONFIG_AT91SAM9G10EK
Xu, Hong0a614942011-07-31 22:49:00 +000098 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
99 AT91_SMC_SETUP_NRD(3) | AT91_SMC_SETUP_NCS_RD(0),
100 &smc->cs[2].setup);
101 writel(AT91_SMC_PULSE_NWE(6) | AT91_SMC_PULSE_NCS_WR(8) |
102 AT91_SMC_PULSE_NRD(6) | AT91_SMC_PULSE_NCS_RD(8),
103 &smc->cs[2].pulse);
104 writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
105 &smc->cs[2].cycle);
106 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
107 AT91_SMC_MODE_EXNW_DISABLE |
108 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
109 AT91_SMC_MODE_TDF_CYCLE(1),
110 &smc->cs[2].mode);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200111#else
Xu, Hong0a614942011-07-31 22:49:00 +0000112 writel(AT91_SMC_SETUP_NWE(3) | AT91_SMC_SETUP_NCS_WR(0) |
113 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
114 &smc->cs[2].setup);
115 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
116 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
117 &smc->cs[2].pulse);
118 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
119 &smc->cs[2].cycle);
120 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
121 AT91_SMC_MODE_EXNW_DISABLE |
122 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
123 AT91_SMC_MODE_TDF_CYCLE(1),
124 &smc->cs[2].mode);
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200125#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200126
127 /* Configure Reset signal as output */
128 at91_set_gpio_output(AT91_PIN_PC10, 0);
129
130 /* Configure Interrupt pin as input, no pull-up */
131 at91_set_gpio_input(AT91_PIN_PC11, 0);
132}
133#endif
134
Stelian Pop905ed222008-05-08 14:52:30 +0200135#ifdef CONFIG_LCD
136vidinfo_t panel_info = {
Jeroen Hofsteee887b722014-06-10 00:16:23 +0200137 .vl_col = 240,
138 .vl_row = 320,
139 .vl_clk = 4965000,
140 .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
141 ATMEL_LCDC_INVFRAME_INVERTED,
142 .vl_bpix = 3,
143 .vl_tft = 1,
144 .vl_hsync_len = 5,
145 .vl_left_margin = 1,
146 .vl_right_margin = 33,
147 .vl_vsync_len = 1,
148 .vl_upper_margin = 1,
149 .vl_lower_margin = 0,
150 .mmio = ATMEL_BASE_LCDC,
Stelian Pop905ed222008-05-08 14:52:30 +0200151};
152
153void lcd_enable(void)
154{
155 at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
156}
157
158void lcd_disable(void)
159{
160 at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
161}
162
163static void at91sam9261ek_lcd_hw_init(void)
164{
165 at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
166 at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
167 at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
168 at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
169 at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
170 at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
171 at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
172 at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
173 at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
174 at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
175 at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
176 at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
177 at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
178 at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
179 at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
180 at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
181 at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
182 at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
183 at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
184 at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
185 at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
186 at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
187
Wenyou Yang78f89762016-02-03 10:16:50 +0800188 at91_system_clk_enable(AT91_PMC_HCK1);
Stelian Pop905ed222008-05-08 14:52:30 +0200189
Xu, Hong0a614942011-07-31 22:49:00 +0000190 /* For 9G10EK, let U-Boot allocate the framebuffer in SDRAM */
191#ifdef CONFIG_AT91SAM9261EK
192 gd->fb_base = ATMEL_BASE_SRAM;
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200193#endif
Stelian Pop905ed222008-05-08 14:52:30 +0200194}
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200195
196#ifdef CONFIG_LCD_INFO
197#include <nand.h>
198#include <version.h>
199
200void lcd_show_board_info(void)
201{
202 ulong dram_size, nand_size;
203 int i;
204 char temp[32];
205
206 lcd_printf ("%s\n", U_BOOT_VERSION);
207 lcd_printf ("(C) 2008 ATMEL Corp\n");
208 lcd_printf ("at91support@atmel.com\n");
209 lcd_printf ("%s CPU at %s MHz\n",
Xu, Hong0a614942011-07-31 22:49:00 +0000210 ATMEL_CPU_NAME,
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200211 strmhz(temp, get_cpu_clk_rate()));
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200212
213 dram_size = 0;
214 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
215 dram_size += gd->bd->bi_dram[i].size;
216 nand_size = 0;
217 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Grygorii Strashko1e096a22017-06-26 19:13:03 -0500218 nand_size += get_nand_dev_by_index(i)->size;
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200219 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
220 dram_size >> 20,
221 nand_size >> 20 );
222}
223#endif /* CONFIG_LCD_INFO */
Stelian Pop905ed222008-05-08 14:52:30 +0200224#endif
225
Wenyou.Yang@microchip.comb59fe682017-07-21 13:28:40 +0800226#ifdef CONFIG_DEBUG_UART_BOARD_INIT
227void board_debug_uart_init(void)
228{
229 at91_seriald_hw_init();
230}
231#endif
232
233#ifdef CONFIG_BOARD_EARLY_INIT_F
234int board_early_init_f(void)
235{
236#ifdef CONFIG_DEBUG_UART
237 debug_uart_init();
238#endif
239 return 0;
240}
241#endif
242
Stelian Pop61e69d72008-05-08 20:52:22 +0200243int board_init(void)
244{
Sedji Gaouaou97a031b2009-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 Pop61e69d72008-05-08 20:52:22 +0200249 /* arch number of AT91SAM9261EK-Board */
250 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9261EK;
Sedji Gaouaou97a031b2009-06-25 17:04:15 +0200251#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200252 /* adress of boot parameters */
Xu, Hong0a614942011-07-31 22:49:00 +0000253 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop61e69d72008-05-08 20:52:22 +0200254
Stelian Pop61e69d72008-05-08 20:52:22 +0200255#ifdef CONFIG_CMD_NAND
256 at91sam9261ek_nand_hw_init();
257#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200258#ifdef CONFIG_DRIVER_DM9000
259 at91sam9261ek_dm9000_hw_init();
260#endif
Stelian Pop905ed222008-05-08 14:52:30 +0200261#ifdef CONFIG_LCD
262 at91sam9261ek_lcd_hw_init();
263#endif
Stelian Pop61e69d72008-05-08 20:52:22 +0200264 return 0;
265}
266
Remy Bohmer7eefd922009-05-02 21:49:18 +0200267#ifdef CONFIG_DRIVER_DM9000
Wolfgang Denke5032c82009-12-07 21:06:40 +0100268int board_eth_init(bd_t *bis)
269{
Remy Bohmer7eefd922009-05-02 21:49:18 +0200270 return dm9000_initialize(bis);
Wolfgang Denke5032c82009-12-07 21:06:40 +0100271}
272#endif
273
Stelian Pop61e69d72008-05-08 20:52:22 +0200274int dram_init(void)
275{
Xu, Hong0a614942011-07-31 22:49:00 +0000276 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
277 CONFIG_SYS_SDRAM_SIZE);
278
Stelian Pop61e69d72008-05-08 20:52:22 +0200279 return 0;
280}
281
282#ifdef CONFIG_RESET_PHY_R
283void reset_phy(void)
284{
285#ifdef CONFIG_DRIVER_DM9000
286 /*
287 * Initialize ethernet HW addr prior to starting Linux,
288 * needed for nfsroot
289 */
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500290 eth_init();
Stelian Pop61e69d72008-05-08 20:52:22 +0200291#endif
292}
293#endif