blob: 9236a285492105224d3d40203f1e9f9eb3520410 [file] [log] [blame]
Bo Shen58258bd2014-11-10 15:46:22 +08001/*
2 * Copyright (C) 2014 Atmel
3 * Bo Shen <voice.shen@atmel.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <asm/io.h>
10#include <asm/arch/at91_common.h>
Bo Shen58258bd2014-11-10 15:46:22 +080011#include <asm/arch/at91_rstc.h>
Bo Shene47c0072014-12-15 13:24:39 +080012#include <asm/arch/atmel_mpddrc.h>
Bo Shen58258bd2014-11-10 15:46:22 +080013#include <asm/arch/gpio.h>
14#include <asm/arch/clk.h>
15#include <asm/arch/sama5d3_smc.h>
16#include <asm/arch/sama5d4.h>
Bo Shen0a3c2fc2015-01-08 15:20:11 +080017#include <atmel_hlcdc.h>
Wenyou Yang4d8b3212017-04-13 10:31:18 +080018#include <debug_uart.h>
Bo Shen58258bd2014-11-10 15:46:22 +080019#include <lcd.h>
Bo Shen58258bd2014-11-10 15:46:22 +080020#include <nand.h>
Wu, Josh1d55b502015-02-04 11:03:32 +080021#include <version.h>
Bo Shen58258bd2014-11-10 15:46:22 +080022
23DECLARE_GLOBAL_DATA_PTR;
24
Bo Shen58258bd2014-11-10 15:46:22 +080025#ifdef CONFIG_NAND_ATMEL
26static void sama5d4_xplained_nand_hw_init(void)
27{
28 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
29
30 at91_periph_clk_enable(ATMEL_ID_SMC);
31
32 /* Configure SMC CS3 for NAND */
33 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
34 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(1),
35 &smc->cs[3].setup);
36 writel(AT91_SMC_PULSE_NWE(2) | AT91_SMC_PULSE_NCS_WR(3) |
37 AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(3),
38 &smc->cs[3].pulse);
39 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
40 &smc->cs[3].cycle);
41 writel(AT91_SMC_TIMINGS_TCLR(2) | AT91_SMC_TIMINGS_TADL(7) |
42 AT91_SMC_TIMINGS_TAR(2) | AT91_SMC_TIMINGS_TRR(3) |
43 AT91_SMC_TIMINGS_TWB(7) | AT91_SMC_TIMINGS_RBNSEL(3)|
44 AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
45 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
46 AT91_SMC_MODE_EXNW_DISABLE |
47 AT91_SMC_MODE_DBW_8 |
48 AT91_SMC_MODE_TDF_CYCLE(3),
49 &smc->cs[3].mode);
50
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080051 at91_pio3_set_a_periph(AT91_PIO_PORTC, 5, 0); /* D0 */
52 at91_pio3_set_a_periph(AT91_PIO_PORTC, 6, 0); /* D1 */
53 at91_pio3_set_a_periph(AT91_PIO_PORTC, 7, 0); /* D2 */
54 at91_pio3_set_a_periph(AT91_PIO_PORTC, 8, 0); /* D3 */
55 at91_pio3_set_a_periph(AT91_PIO_PORTC, 9, 0); /* D4 */
56 at91_pio3_set_a_periph(AT91_PIO_PORTC, 10, 0); /* D5 */
57 at91_pio3_set_a_periph(AT91_PIO_PORTC, 11, 0); /* D6 */
58 at91_pio3_set_a_periph(AT91_PIO_PORTC, 12, 0); /* D7 */
59 at91_pio3_set_a_periph(AT91_PIO_PORTC, 13, 0); /* RE */
60 at91_pio3_set_a_periph(AT91_PIO_PORTC, 14, 0); /* WE */
61 at91_pio3_set_a_periph(AT91_PIO_PORTC, 15, 1); /* NCS */
62 at91_pio3_set_a_periph(AT91_PIO_PORTC, 16, 1); /* RDY */
63 at91_pio3_set_a_periph(AT91_PIO_PORTC, 17, 1); /* ALE */
64 at91_pio3_set_a_periph(AT91_PIO_PORTC, 18, 1); /* CLE */
Bo Shen58258bd2014-11-10 15:46:22 +080065}
66#endif
67
68#ifdef CONFIG_CMD_USB
69static void sama5d4_xplained_usb_hw_init(void)
70{
71 at91_set_pio_output(AT91_PIO_PORTE, 11, 1);
72 at91_set_pio_output(AT91_PIO_PORTE, 14, 1);
73}
74#endif
75
76#ifdef CONFIG_LCD
77vidinfo_t panel_info = {
78 .vl_col = 480,
79 .vl_row = 272,
Bo Shen0a3c2fc2015-01-08 15:20:11 +080080 .vl_clk = 9000000,
Bo Shen58258bd2014-11-10 15:46:22 +080081 .vl_bpix = LCD_BPP,
Bo Shen58258bd2014-11-10 15:46:22 +080082 .vl_tft = 1,
83 .vl_hsync_len = 41,
84 .vl_left_margin = 2,
85 .vl_right_margin = 2,
86 .vl_vsync_len = 11,
87 .vl_upper_margin = 2,
88 .vl_lower_margin = 2,
89 .mmio = ATMEL_BASE_LCDC,
90};
91
92/* No power up/down pin for the LCD pannel */
93void lcd_enable(void) { /* Empty! */ }
94void lcd_disable(void) { /* Empty! */ }
95
96unsigned int has_lcdc(void)
97{
98 return 1;
99}
100
101static void sama5d4_xplained_lcd_hw_init(void)
102{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800103 at91_pio3_set_a_periph(AT91_PIO_PORTA, 24, 0); /* LCDPWM */
104 at91_pio3_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */
105 at91_pio3_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */
106 at91_pio3_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */
107 at91_pio3_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */
108 at91_pio3_set_a_periph(AT91_PIO_PORTA, 29, 0); /* LCDDEN */
Bo Shen58258bd2014-11-10 15:46:22 +0800109
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800110 at91_pio3_set_a_periph(AT91_PIO_PORTA, 0, 0); /* LCDD0 */
111 at91_pio3_set_a_periph(AT91_PIO_PORTA, 1, 0); /* LCDD1 */
112 at91_pio3_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */
113 at91_pio3_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */
114 at91_pio3_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */
115 at91_pio3_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */
116 at91_pio3_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */
117 at91_pio3_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */
Bo Shen58258bd2014-11-10 15:46:22 +0800118
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800119 at91_pio3_set_a_periph(AT91_PIO_PORTA, 8, 0); /* LCDD9 */
120 at91_pio3_set_a_periph(AT91_PIO_PORTA, 9, 0); /* LCDD8 */
121 at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */
122 at91_pio3_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */
123 at91_pio3_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */
124 at91_pio3_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */
125 at91_pio3_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */
126 at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */
Bo Shen58258bd2014-11-10 15:46:22 +0800127
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800128 at91_pio3_set_a_periph(AT91_PIO_PORTA, 16, 0); /* LCDD16 */
129 at91_pio3_set_a_periph(AT91_PIO_PORTA, 17, 0); /* LCDD17 */
130 at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 0); /* LCDD18 */
131 at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 0); /* LCDD19 */
132 at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 0); /* LCDD20 */
133 at91_pio3_set_a_periph(AT91_PIO_PORTA, 21, 0); /* LCDD21 */
134 at91_pio3_set_a_periph(AT91_PIO_PORTA, 22, 0); /* LCDD22 */
135 at91_pio3_set_a_periph(AT91_PIO_PORTA, 23, 0); /* LCDD23 */
Bo Shen58258bd2014-11-10 15:46:22 +0800136
137 /* Enable clock */
138 at91_periph_clk_enable(ATMEL_ID_LCDC);
139}
140
141#ifdef CONFIG_LCD_INFO
142void lcd_show_board_info(void)
143{
144 ulong dram_size, nand_size;
145 int i;
146 char temp[32];
147
Wu, Josh1d55b502015-02-04 11:03:32 +0800148 lcd_printf("%s\n", U_BOOT_VERSION);
Bo Shen58258bd2014-11-10 15:46:22 +0800149 lcd_printf("2014 ATMEL Corp\n");
150 lcd_printf("%s CPU at %s MHz\n", get_cpu_name(),
151 strmhz(temp, get_cpu_clk_rate()));
152
153 dram_size = 0;
154 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
155 dram_size += gd->bd->bi_dram[i].size;
156
157 nand_size = 0;
158#ifdef CONFIG_NAND_ATMEL
159 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Grygorii Strashko1e096a22017-06-26 19:13:03 -0500160 nand_size += get_nand_dev_by_index(i)->size;
Bo Shen58258bd2014-11-10 15:46:22 +0800161#endif
162 lcd_printf("%ld MB SDRAM, %ld MB NAND\n",
163 dram_size >> 20, nand_size >> 20);
164}
165#endif /* CONFIG_LCD_INFO */
166
167#endif /* CONFIG_LCD */
168
Wenyou Yang4d8b3212017-04-13 10:31:18 +0800169#ifdef CONFIG_DEBUG_UART_BOARD_INIT
Bo Shen58258bd2014-11-10 15:46:22 +0800170static void sama5d4_xplained_serial3_hw_init(void)
171{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800172 at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
173 at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
Bo Shen58258bd2014-11-10 15:46:22 +0800174
175 /* Enable clock */
176 at91_periph_clk_enable(ATMEL_ID_USART3);
177}
178
Wenyou Yang4d8b3212017-04-13 10:31:18 +0800179void board_debug_uart_init(void)
Bo Shen58258bd2014-11-10 15:46:22 +0800180{
Bo Shen58258bd2014-11-10 15:46:22 +0800181 sama5d4_xplained_serial3_hw_init();
Wenyou Yang4d8b3212017-04-13 10:31:18 +0800182}
183#endif
Bo Shen58258bd2014-11-10 15:46:22 +0800184
Wenyou Yang4d8b3212017-04-13 10:31:18 +0800185#ifdef CONFIG_BOARD_EARLY_INIT_F
186int board_early_init_f(void)
187{
188#ifdef CONFIG_DEBUG_UART
189 debug_uart_init();
190#endif
Bo Shen58258bd2014-11-10 15:46:22 +0800191 return 0;
192}
Wenyou Yang4d8b3212017-04-13 10:31:18 +0800193#endif
Bo Shen58258bd2014-11-10 15:46:22 +0800194
Wenyou Yang16b26b02017-09-01 16:26:18 +0800195#define AT24MAC_MAC_OFFSET 0x9a
196
197#ifdef CONFIG_MISC_INIT_R
198int misc_init_r(void)
199{
200#ifdef CONFIG_I2C_EEPROM
201 at91_set_ethaddr(AT24MAC_MAC_OFFSET);
202#endif
203 return 0;
204}
205#endif
206
Bo Shen58258bd2014-11-10 15:46:22 +0800207int board_init(void)
208{
209 /* adress of boot parameters */
210 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
211
Bo Shen58258bd2014-11-10 15:46:22 +0800212#ifdef CONFIG_NAND_ATMEL
213 sama5d4_xplained_nand_hw_init();
214#endif
Bo Shen58258bd2014-11-10 15:46:22 +0800215#ifdef CONFIG_LCD
216 sama5d4_xplained_lcd_hw_init();
217#endif
218#ifdef CONFIG_CMD_USB
219 sama5d4_xplained_usb_hw_init();
220#endif
221
222 return 0;
223}
224
225int dram_init(void)
226{
227 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
228 CONFIG_SYS_SDRAM_SIZE);
229 return 0;
230}
231
Bo Shene47c0072014-12-15 13:24:39 +0800232/* SPL */
233#ifdef CONFIG_SPL_BUILD
234void spl_board_init(void)
235{
Wenyou Yange035ea72017-09-14 11:07:44 +0800236#if CONFIG_NAND_BOOT
Bo Shene47c0072014-12-15 13:24:39 +0800237 sama5d4_xplained_nand_hw_init();
Bo Shene47c0072014-12-15 13:24:39 +0800238#endif
239}
240
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800241static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Bo Shene47c0072014-12-15 13:24:39 +0800242{
243 ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
244
245 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
246 ATMEL_MPDDRC_CR_NR_ROW_14 |
247 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
248 ATMEL_MPDDRC_CR_NB_8BANKS |
249 ATMEL_MPDDRC_CR_NDQS_DISABLED |
250 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
251 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
252
253 ddr2->rtr = 0x2b0;
254
255 ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
256 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
257 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
258 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
259 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
260 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
261 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
262 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
263
264 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
265 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
266 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
267 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
268
269 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
270 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
271 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
272 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
273 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
274}
275
276void mem_init(void)
277{
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800278 struct atmel_mpddrc_config ddr2;
Bo Shene47c0072014-12-15 13:24:39 +0800279
280 ddr2_conf(&ddr2);
281
Wenyou Yang78f89762016-02-03 10:16:50 +0800282 /* Enable MPDDR clock */
Bo Shene47c0072014-12-15 13:24:39 +0800283 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
Wenyou Yang78f89762016-02-03 10:16:50 +0800284 at91_system_clk_enable(AT91_PMC_DDR);
Bo Shene47c0072014-12-15 13:24:39 +0800285
286 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200287 ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
Bo Shene47c0072014-12-15 13:24:39 +0800288}
289
290void at91_pmc_init(void)
291{
Bo Shene47c0072014-12-15 13:24:39 +0800292 u32 tmp;
293
294 tmp = AT91_PMC_PLLAR_29 |
295 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
296 AT91_PMC_PLLXR_MUL(87) |
297 AT91_PMC_PLLXR_DIV(1);
298 at91_plla_init(tmp);
299
Wenyou Yang5265b1e2016-02-02 12:46:14 +0800300 at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x0));
Bo Shene47c0072014-12-15 13:24:39 +0800301
302 tmp = AT91_PMC_MCKR_H32MXDIV |
303 AT91_PMC_MCKR_PLLADIV_2 |
304 AT91_PMC_MCKR_MDIV_3 |
305 AT91_PMC_MCKR_CSS_PLLA;
306 at91_mck_init(tmp);
307}
308#endif