blob: 0856786a0f8a32012044365c6f2967950234a8b5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bo Shen42aafb32012-07-05 17:21:46 +00002/*
3 * Copyright (C) 2012 Atmel Corporation
Bo Shen42aafb32012-07-05 17:21:46 +00004 */
5
6#include <common.h>
7#include <asm/io.h>
8#include <asm/arch/at91sam9x5_matrix.h>
9#include <asm/arch/at91sam9_smc.h>
10#include <asm/arch/at91_common.h>
Bo Shen42aafb32012-07-05 17:21:46 +000011#include <asm/arch/at91_rstc.h>
Bo Shen42aafb32012-07-05 17:21:46 +000012#include <asm/arch/clk.h>
Wenyou Yang78f89762016-02-03 10:16:50 +080013#include <asm/arch/gpio.h>
Wenyou Yanga9606f02017-04-18 14:51:56 +080014#include <debug_uart.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060015#include <asm/mach-types.h>
Bo Shen42aafb32012-07-05 17:21:46 +000016
17DECLARE_GLOBAL_DATA_PTR;
18
19/* ------------------------------------------------------------------------- */
20/*
21 * Miscelaneous platform dependent initialisations
22 */
Eugen Hristev3232f9b2018-10-08 09:54:27 +030023
24void at91_prepare_cpu_var(void);
25
Bo Shen42aafb32012-07-05 17:21:46 +000026#ifdef CONFIG_CMD_NAND
27static void at91sam9x5ek_nand_hw_init(void)
28{
29 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
30 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Bo Shen42aafb32012-07-05 17:21:46 +000031 unsigned long csa;
32
33 /* Enable CS3 */
34 csa = readl(&matrix->ebicsa);
35 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
Bo Shen68df9182012-08-15 18:44:27 +000036 /* NAND flash on D16 */
37 csa |= AT91_MATRIX_NFD0_ON_D16;
Wu, Joshccae57a2012-09-05 22:14:28 +000038
39 /* Configure IO drive */
40 csa &= ~AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
41
Bo Shen42aafb32012-07-05 17:21:46 +000042 writel(csa, &matrix->ebicsa);
43
44 /* Configure SMC CS3 for NAND/SmartMedia */
Wu, Joshe3330362012-08-23 00:05:37 +000045 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
46 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
Bo Shen42aafb32012-07-05 17:21:46 +000047 &smc->cs[3].setup);
Wu, Joshe3330362012-08-23 00:05:37 +000048 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
49 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
Bo Shen42aafb32012-07-05 17:21:46 +000050 &smc->cs[3].pulse);
Wu, Joshe3330362012-08-23 00:05:37 +000051 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(6),
Bo Shen42aafb32012-07-05 17:21:46 +000052 &smc->cs[3].cycle);
53 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
54 AT91_SMC_MODE_EXNW_DISABLE |
55#ifdef CONFIG_SYS_NAND_DBW_16
56 AT91_SMC_MODE_DBW_16 |
57#else /* CONFIG_SYS_NAND_DBW_8 */
58 AT91_SMC_MODE_DBW_8 |
59#endif
Wu, Joshe3330362012-08-23 00:05:37 +000060 AT91_SMC_MODE_TDF_CYCLE(1),
Bo Shen42aafb32012-07-05 17:21:46 +000061 &smc->cs[3].mode);
62
Wenyou Yang78f89762016-02-03 10:16:50 +080063 at91_periph_clk_enable(ATMEL_ID_PIOCD);
Bo Shen42aafb32012-07-05 17:21:46 +000064
65 /* Configure RDY/BSY */
66 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
67 /* Enable NandFlash */
68 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
69
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080070 at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
71 at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
72 at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* NAND ALE */
73 at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* NAND CLE */
74 at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1);
75 at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1);
76 at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1);
77 at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1);
78 at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1);
79 at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1);
80 at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1);
81 at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1);
Bo Shen42aafb32012-07-05 17:21:46 +000082}
83#endif
Bo Shen42aafb32012-07-05 17:21:46 +000084
Wenyou Yangaa023532017-09-18 15:26:01 +080085#ifdef CONFIG_BOARD_LATE_INIT
86int board_late_init(void)
Bo Shen42aafb32012-07-05 17:21:46 +000087{
Wenyou Yangaa023532017-09-18 15:26:01 +080088#ifdef CONFIG_DM_VIDEO
89 at91_video_show_board_info();
90#endif
Eugen Hristev3232f9b2018-10-08 09:54:27 +030091 at91_prepare_cpu_var();
Wenyou Yangaa023532017-09-18 15:26:01 +080092 return 0;
Bo Shen42aafb32012-07-05 17:21:46 +000093}
Wenyou Yangaa023532017-09-18 15:26:01 +080094#endif
Bo Shen42aafb32012-07-05 17:21:46 +000095
Wenyou Yanga9606f02017-04-18 14:51:56 +080096#ifdef CONFIG_DEBUG_UART_BOARD_INIT
97void board_debug_uart_init(void)
Bo Shen42aafb32012-07-05 17:21:46 +000098{
99 at91_seriald_hw_init();
Wenyou Yanga9606f02017-04-18 14:51:56 +0800100}
101#endif
102
103#ifdef CONFIG_BOARD_EARLY_INIT_F
104int board_early_init_f(void)
105{
106#ifdef CONFIG_DEBUG_UART
107 debug_uart_init();
108#endif
Bo Shen42aafb32012-07-05 17:21:46 +0000109 return 0;
110}
Wenyou Yanga9606f02017-04-18 14:51:56 +0800111#endif
Bo Shen42aafb32012-07-05 17:21:46 +0000112
113int board_init(void)
114{
Tom Rini48157342017-01-25 20:42:35 -0500115 /* arch number of AT91SAM9X5EK-Board */
116 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9X5EK;
117
Bo Shen42aafb32012-07-05 17:21:46 +0000118 /* adress of boot parameters */
119 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
120
121#ifdef CONFIG_CMD_NAND
122 at91sam9x5ek_nand_hw_init();
123#endif
124
Tom Riniceed5d22017-05-12 22:33:27 -0400125#if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI_HCD)
Richard Genoudb762a9c2012-11-29 23:18:32 +0000126 at91_uhp_hw_init();
127#endif
Bo Shen42aafb32012-07-05 17:21:46 +0000128 return 0;
129}
130
131int dram_init(void)
132{
133 gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
134 CONFIG_SYS_SDRAM_SIZE);
135 return 0;
136}
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800137
138#if defined(CONFIG_SPL_BUILD)
139#include <spl.h>
140#include <nand.h>
141
142void at91_spl_board_init(void)
143{
Wenyou Yange035ea72017-09-14 11:07:44 +0800144#ifdef CONFIG_SD_BOOT
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800145 at91_mci_hw_init();
Wenyou Yange035ea72017-09-14 11:07:44 +0800146#elif CONFIG_NAND_BOOT
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800147 at91sam9x5ek_nand_hw_init();
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800148#endif
149}
150
151#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800152static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800153{
154 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
155
156 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
157 ATMEL_MPDDRC_CR_NR_ROW_13 |
158 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
159 ATMEL_MPDDRC_CR_NB_8BANKS |
160 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
161
162 ddr2->rtr = 0x411;
163
164 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
165 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
166 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
167 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
168 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
169 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
170 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
171 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
172
173 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
174 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
175 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
176 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
177
178 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
179 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
180 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
181 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
182 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
183}
184
185void mem_init(void)
186{
187 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
188 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800189 struct atmel_mpddrc_config ddr2;
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800190 unsigned long csa;
191
192 ddr2_conf(&ddr2);
193
194 /* enable DDR2 clock */
Erik van Luijkebaa8002015-08-13 15:43:20 +0200195 writel(AT91_PMC_DDR, &pmc->scer);
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800196
197 /* Chip select 1 is for DDR2/SDRAM */
198 csa = readl(&matrix->ebicsa);
199 csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
200 csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
201 csa |= AT91_MATRIX_EBI_DBPD_OFF;
202 csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
203 writel(csa, &matrix->ebicsa);
204
205 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200206 ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
Bo Shen9a3b1fe2015-03-27 14:23:35 +0800207}
208#endif