blob: c661c77f83bde6cfc7b5ec97e262e837436ec5ea [file] [log] [blame]
Bo Shen42aafb32012-07-05 17:21:46 +00001/*
2 * Copyright (C) 2012 Atmel Corporation
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Bo Shen42aafb32012-07-05 17:21:46 +00005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/at91sam9x5_matrix.h>
10#include <asm/arch/at91sam9_smc.h>
11#include <asm/arch/at91_common.h>
Bo Shen42aafb32012-07-05 17:21:46 +000012#include <asm/arch/at91_rstc.h>
Bo Shen42aafb32012-07-05 17:21:46 +000013#include <asm/arch/clk.h>
Wenyou Yang78f89762016-02-03 10:16:50 +080014#include <asm/arch/gpio.h>
Wenyou Yanga9606f02017-04-18 14:51:56 +080015#include <debug_uart.h>
Bo Shen42aafb32012-07-05 17:21:46 +000016#include <lcd.h>
17#include <atmel_hlcdc.h>
Bo Shen42aafb32012-07-05 17:21:46 +000018#ifdef CONFIG_LCD_INFO
19#include <nand.h>
20#include <version.h>
21#endif
Bo Shen42aafb32012-07-05 17:21:46 +000022
23DECLARE_GLOBAL_DATA_PTR;
24
25/* ------------------------------------------------------------------------- */
26/*
27 * Miscelaneous platform dependent initialisations
28 */
29#ifdef CONFIG_CMD_NAND
30static void at91sam9x5ek_nand_hw_init(void)
31{
32 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
33 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Bo Shen42aafb32012-07-05 17:21:46 +000034 unsigned long csa;
35
36 /* Enable CS3 */
37 csa = readl(&matrix->ebicsa);
38 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
Bo Shen68df9182012-08-15 18:44:27 +000039 /* NAND flash on D16 */
40 csa |= AT91_MATRIX_NFD0_ON_D16;
Wu, Joshccae57a2012-09-05 22:14:28 +000041
42 /* Configure IO drive */
43 csa &= ~AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
44
Bo Shen42aafb32012-07-05 17:21:46 +000045 writel(csa, &matrix->ebicsa);
46
47 /* Configure SMC CS3 for NAND/SmartMedia */
Wu, Joshe3330362012-08-23 00:05:37 +000048 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
49 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
Bo Shen42aafb32012-07-05 17:21:46 +000050 &smc->cs[3].setup);
Wu, Joshe3330362012-08-23 00:05:37 +000051 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
52 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
Bo Shen42aafb32012-07-05 17:21:46 +000053 &smc->cs[3].pulse);
Wu, Joshe3330362012-08-23 00:05:37 +000054 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(6),
Bo Shen42aafb32012-07-05 17:21:46 +000055 &smc->cs[3].cycle);
56 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
57 AT91_SMC_MODE_EXNW_DISABLE |
58#ifdef CONFIG_SYS_NAND_DBW_16
59 AT91_SMC_MODE_DBW_16 |
60#else /* CONFIG_SYS_NAND_DBW_8 */
61 AT91_SMC_MODE_DBW_8 |
62#endif
Wu, Joshe3330362012-08-23 00:05:37 +000063 AT91_SMC_MODE_TDF_CYCLE(1),
Bo Shen42aafb32012-07-05 17:21:46 +000064 &smc->cs[3].mode);
65
Wenyou Yang78f89762016-02-03 10:16:50 +080066 at91_periph_clk_enable(ATMEL_ID_PIOCD);
Bo Shen42aafb32012-07-05 17:21:46 +000067
68 /* Configure RDY/BSY */
69 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
70 /* Enable NandFlash */
71 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
72
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080073 at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
74 at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
75 at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* NAND ALE */
76 at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* NAND CLE */
77 at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1);
78 at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1);
79 at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1);
80 at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1);
81 at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1);
82 at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1);
83 at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1);
84 at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1);
Bo Shen42aafb32012-07-05 17:21:46 +000085}
86#endif
Bo Shen42aafb32012-07-05 17:21:46 +000087
88#ifdef CONFIG_LCD
89vidinfo_t panel_info = {
90 .vl_col = 800,
91 .vl_row = 480,
92 .vl_clk = 24000000,
93 .vl_sync = LCDC_LCDCFG5_HSPOL | LCDC_LCDCFG5_VSPOL,
94 .vl_bpix = LCD_BPP,
95 .vl_tft = 1,
96 .vl_clk_pol = 1,
97 .vl_hsync_len = 128,
98 .vl_left_margin = 64,
99 .vl_right_margin = 64,
100 .vl_vsync_len = 2,
101 .vl_upper_margin = 22,
102 .vl_lower_margin = 21,
103 .mmio = ATMEL_BASE_LCDC,
104};
105
106void lcd_enable(void)
107{
108 if (has_lcdc())
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800109 at91_pio3_set_a_periph(AT91_PIO_PORTC, 29, 1); /* power up */
Bo Shen42aafb32012-07-05 17:21:46 +0000110}
111
112void lcd_disable(void)
113{
114 if (has_lcdc())
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800115 at91_pio3_set_a_periph(AT91_PIO_PORTC, 29, 0); /* power down */
Bo Shen42aafb32012-07-05 17:21:46 +0000116}
117
118static void at91sam9x5ek_lcd_hw_init(void)
119{
Bo Shen42aafb32012-07-05 17:21:46 +0000120 if (has_lcdc()) {
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800121 at91_pio3_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDPWM */
122 at91_pio3_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDVSYNC */
123 at91_pio3_set_a_periph(AT91_PIO_PORTC, 28, 0); /* LCDHSYNC */
124 at91_pio3_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDDISP */
125 at91_pio3_set_a_periph(AT91_PIO_PORTC, 29, 0); /* LCDDEN */
126 at91_pio3_set_a_periph(AT91_PIO_PORTC, 30, 0); /* LCDPCK */
Bo Shen42aafb32012-07-05 17:21:46 +0000127
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800128 at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDD0 */
129 at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDD1 */
130 at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDD2 */
131 at91_pio3_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDD3 */
132 at91_pio3_set_a_periph(AT91_PIO_PORTC, 4, 0); /* LCDD4 */
133 at91_pio3_set_a_periph(AT91_PIO_PORTC, 5, 0); /* LCDD5 */
134 at91_pio3_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD6 */
135 at91_pio3_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD7 */
136 at91_pio3_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD8 */
137 at91_pio3_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD9 */
138 at91_pio3_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD10 */
139 at91_pio3_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD11 */
140 at91_pio3_set_a_periph(AT91_PIO_PORTC, 12, 0); /* LCDD12 */
141 at91_pio3_set_a_periph(AT91_PIO_PORTC, 13, 0); /* LCDD13 */
142 at91_pio3_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD14 */
143 at91_pio3_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD15 */
144 at91_pio3_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD16 */
145 at91_pio3_set_a_periph(AT91_PIO_PORTC, 17, 0); /* LCDD17 */
146 at91_pio3_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD18 */
147 at91_pio3_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD19 */
148 at91_pio3_set_a_periph(AT91_PIO_PORTC, 20, 0); /* LCDD20 */
149 at91_pio3_set_a_periph(AT91_PIO_PORTC, 21, 0); /* LCDD21 */
150 at91_pio3_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD22 */
151 at91_pio3_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD23 */
Bo Shen42aafb32012-07-05 17:21:46 +0000152
Wenyou Yang78f89762016-02-03 10:16:50 +0800153 at91_periph_clk_enable(ATMEL_ID_LCDC);
Bo Shen42aafb32012-07-05 17:21:46 +0000154 }
155}
156
157#ifdef CONFIG_LCD_INFO
158void lcd_show_board_info(void)
159{
160 ulong dram_size, nand_size;
161 int i;
162 char temp[32];
163
164 if (has_lcdc()) {
165 lcd_printf("%s\n", U_BOOT_VERSION);
166 lcd_printf("(C) 2012 ATMEL Corp\n");
167 lcd_printf("at91support@atmel.com\n");
168 lcd_printf("%s CPU at %s MHz\n",
169 get_cpu_name(),
170 strmhz(temp, get_cpu_clk_rate()));
171
172 dram_size = 0;
173 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
174 dram_size += gd->bd->bi_dram[i].size;
175 nand_size = 0;
176 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Scott Wood2c1b7e12016-05-30 13:57:55 -0500177 nand_size += nand_info[i]->size;
Bo Shen42aafb32012-07-05 17:21:46 +0000178 lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
179 dram_size >> 20,
180 nand_size >> 20);
181 }
182}
183#endif /* CONFIG_LCD_INFO */
184#endif /* CONFIG_LCD */
185
Wenyou Yanga9606f02017-04-18 14:51:56 +0800186#ifdef CONFIG_DEBUG_UART_BOARD_INIT
187void board_debug_uart_init(void)
Bo Shen42aafb32012-07-05 17:21:46 +0000188{
189 at91_seriald_hw_init();
Wenyou Yanga9606f02017-04-18 14:51:56 +0800190}
191#endif
192
193#ifdef CONFIG_BOARD_EARLY_INIT_F
194int board_early_init_f(void)
195{
196#ifdef CONFIG_DEBUG_UART
197 debug_uart_init();
198#endif
Bo Shen42aafb32012-07-05 17:21:46 +0000199 return 0;
200}
Wenyou Yanga9606f02017-04-18 14:51:56 +0800201#endif
Bo Shen42aafb32012-07-05 17:21:46 +0000202
203int board_init(void)
204{
Tom Rini48157342017-01-25 20:42:35 -0500205 /* arch number of AT91SAM9X5EK-Board */
206 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9X5EK;
207
Bo Shen42aafb32012-07-05 17:21:46 +0000208 /* adress of boot parameters */
209 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
210
211#ifdef CONFIG_CMD_NAND
212 at91sam9x5ek_nand_hw_init();
213#endif
214
Richard Genoudb762a9c2012-11-29 23:18:32 +0000215#if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI)
216 at91_uhp_hw_init();
217#endif
Bo Shen42aafb32012-07-05 17:21:46 +0000218#ifdef CONFIG_LCD
219 at91sam9x5ek_lcd_hw_init();
220#endif
221 return 0;
222}
223
224int dram_init(void)
225{
226 gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
227 CONFIG_SYS_SDRAM_SIZE);
228 return 0;
229}
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800230
231#if defined(CONFIG_SPL_BUILD)
232#include <spl.h>
233#include <nand.h>
234
235void at91_spl_board_init(void)
236{
237#ifdef CONFIG_SYS_USE_MMC
238 at91_mci_hw_init();
239#elif CONFIG_SYS_USE_NANDFLASH
240 at91sam9x5ek_nand_hw_init();
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800241#endif
242}
243
244#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800245static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800246{
247 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
248
249 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
250 ATMEL_MPDDRC_CR_NR_ROW_13 |
251 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
252 ATMEL_MPDDRC_CR_NB_8BANKS |
253 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
254
255 ddr2->rtr = 0x411;
256
257 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
258 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
259 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
260 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
261 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
262 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
263 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
264 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
265
266 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
267 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
268 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
269 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
270
271 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
272 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
273 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
274 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
275 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
276}
277
278void mem_init(void)
279{
280 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
281 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800282 struct atmel_mpddrc_config ddr2;
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800283 unsigned long csa;
284
285 ddr2_conf(&ddr2);
286
287 /* enable DDR2 clock */
Erik van Luijkebaa8002015-08-13 15:43:20 +0200288 writel(AT91_PMC_DDR, &pmc->scer);
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800289
290 /* Chip select 1 is for DDR2/SDRAM */
291 csa = readl(&matrix->ebicsa);
292 csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
293 csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
294 csa |= AT91_MATRIX_EBI_DBPD_OFF;
295 csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
296 writel(csa, &matrix->ebicsa);
297
298 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200299 ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800300}
301#endif