blob: a337db4efc6872f2d09d288a3ff85080fc0c161e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wu, Josh9e336902013-04-16 23:42:44 +00002/*
3 * (C) Copyright 2013 Atmel Corporation
4 * Josh Wu <josh.wu@atmel.com>
Wu, Josh9e336902013-04-16 23:42:44 +00005 */
6
7#include <common.h>
Simon Glass9b4a2052019-12-28 10:45:05 -07008#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <net.h>
Simon Glass2189d5f2019-11-14 12:57:20 -070010#include <vsprintf.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Wu, Josh9e336902013-04-16 23:42:44 +000012#include <asm/io.h>
13#include <asm/arch/at91sam9x5_matrix.h>
14#include <asm/arch/at91sam9_smc.h>
15#include <asm/arch/at91_common.h>
Wu, Josh9e336902013-04-16 23:42:44 +000016#include <asm/arch/at91_rstc.h>
17#include <asm/arch/at91_pio.h>
18#include <asm/arch/clk.h>
Wenyou Yangc1868ad2017-04-18 14:54:53 +080019#include <debug_uart.h>
Wu, Josh9e336902013-04-16 23:42:44 +000020#include <lcd.h>
21#include <atmel_hlcdc.h>
Bo Shen16276222013-04-24 10:46:18 +080022#include <netdev.h>
Wu, Josh9e336902013-04-16 23:42:44 +000023
24#ifdef CONFIG_LCD_INFO
25#include <nand.h>
26#include <version.h>
27#endif
28
29DECLARE_GLOBAL_DATA_PTR;
30
31/* ------------------------------------------------------------------------- */
32/*
33 * Miscelaneous platform dependent initialisations
34 */
35#ifdef CONFIG_NAND_ATMEL
36static void at91sam9n12ek_nand_hw_init(void)
37{
38 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
39 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
40 unsigned long csa;
41
42 /* Assign CS3 to NAND/SmartMedia Interface */
43 csa = readl(&matrix->ebicsa);
44 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
45 /* Configure databus */
46 csa &= ~AT91_MATRIX_NFD0_ON_D16; /* nandflash connect to D0~D15 */
47 /* Configure IO drive */
Bo Shenb899fa32013-07-17 17:14:17 +080048 csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
Wu, Josh9e336902013-04-16 23:42:44 +000049
50 writel(csa, &matrix->ebicsa);
51
52 /* Configure SMC CS3 for NAND/SmartMedia */
53 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
54 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
55 &smc->cs[3].setup);
56 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
57 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(6),
58 &smc->cs[3].pulse);
59 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(7),
60 &smc->cs[3].cycle);
61 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
62 AT91_SMC_MODE_EXNW_DISABLE |
63#ifdef CONFIG_SYS_NAND_DBW_16
64 AT91_SMC_MODE_DBW_16 |
65#else /* CONFIG_SYS_NAND_DBW_8 */
66 AT91_SMC_MODE_DBW_8 |
67#endif
68 AT91_SMC_MODE_TDF_CYCLE(1),
69 &smc->cs[3].mode);
70
71 /* Configure RDY/BSY pin */
72 at91_set_pio_input(AT91_PIO_PORTD, 5, 1);
73
74 /* Configure ENABLE pin for NandFlash */
75 at91_set_pio_output(AT91_PIO_PORTD, 4, 1);
76
Wenyou Yang2dc63f72017-03-23 12:44:36 +080077 at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
78 at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
79 at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 1); /* ALE */
80 at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 1); /* CLE */
Wu, Josh9e336902013-04-16 23:42:44 +000081}
82#endif
83
84#ifdef CONFIG_LCD
85vidinfo_t panel_info = {
86 .vl_col = 480,
87 .vl_row = 272,
88 .vl_clk = 9000000,
89 .vl_bpix = LCD_BPP,
90 .vl_sync = 0,
91 .vl_tft = 1,
92 .vl_hsync_len = 5,
93 .vl_left_margin = 8,
94 .vl_right_margin = 43,
95 .vl_vsync_len = 10,
96 .vl_upper_margin = 4,
97 .vl_lower_margin = 12,
98 .mmio = ATMEL_BASE_LCDC,
99};
100
101void lcd_enable(void)
102{
103 at91_set_pio_output(AT91_PIO_PORTC, 25, 0); /* power up */
104}
105
106void lcd_disable(void)
107{
108 at91_set_pio_output(AT91_PIO_PORTC, 25, 1); /* power down */
109}
110
111#ifdef CONFIG_LCD_INFO
112void lcd_show_board_info(void)
113{
114 ulong dram_size, nand_size;
115 int i;
116 char temp[32];
117
118 lcd_printf("%s\n", U_BOOT_VERSION);
119 lcd_printf("ATMEL Corp\n");
120 lcd_printf("at91@atmel.com\n");
121 lcd_printf("%s CPU at %s MHz\n",
122 ATMEL_CPU_NAME,
123 strmhz(temp, get_cpu_clk_rate()));
124
125 dram_size = 0;
126 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
127 dram_size += gd->bd->bi_dram[i].size;
128 nand_size = 0;
129 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Grygorii Strashko31f8d392017-06-26 19:13:03 -0500130 nand_size += get_nand_dev_by_index(i)->size;
Wu, Josh9e336902013-04-16 23:42:44 +0000131 lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
132 dram_size >> 20,
133 nand_size >> 20);
134}
135#endif /* CONFIG_LCD_INFO */
136#endif /* CONFIG_LCD */
137
Bo Shend9bef0a2013-10-21 16:13:59 +0800138#ifdef CONFIG_USB_ATMEL
139void at91sam9n12ek_usb_hw_init(void)
140{
141 at91_set_pio_output(AT91_PIO_PORTB, 7, 0);
142}
143#endif
144
Wenyou Yangc1868ad2017-04-18 14:54:53 +0800145#ifdef CONFIG_DEBUG_UART_BOARD_INIT
146void board_debug_uart_init(void)
147{
148 at91_seriald_hw_init();
149}
150#endif
151
152#ifdef CONFIG_BOARD_EARLY_INIT_F
Wu, Josh9e336902013-04-16 23:42:44 +0000153int board_early_init_f(void)
154{
Wu, Josh9e336902013-04-16 23:42:44 +0000155 return 0;
156}
Wenyou Yangc1868ad2017-04-18 14:54:53 +0800157#endif
Wu, Josh9e336902013-04-16 23:42:44 +0000158
159int board_init(void)
160{
161 /* adress of boot parameters */
162 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
163
164#ifdef CONFIG_NAND_ATMEL
165 at91sam9n12ek_nand_hw_init();
166#endif
167
Wu, Josh9e336902013-04-16 23:42:44 +0000168#ifdef CONFIG_LCD
169 at91_lcd_hw_init();
170#endif
171
Bo Shend9bef0a2013-10-21 16:13:59 +0800172#ifdef CONFIG_USB_ATMEL
173 at91sam9n12ek_usb_hw_init();
174#endif
175
Wu, Josh9e336902013-04-16 23:42:44 +0000176 return 0;
177}
178
Wu, Josh9e336902013-04-16 23:42:44 +0000179int dram_init(void)
180{
181 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
182 CONFIG_SYS_SDRAM_SIZE);
183 return 0;
184}
Bo Shenff255e82015-03-27 14:23:36 +0800185
186#if defined(CONFIG_SPL_BUILD)
187#include <spl.h>
188#include <nand.h>
189
190void at91_spl_board_init(void)
191{
Wenyou Yang55415432017-09-14 11:07:44 +0800192#ifdef CONFIG_SD_BOOT
Bo Shenff255e82015-03-27 14:23:36 +0800193 at91_mci_hw_init();
Wenyou Yang55415432017-09-14 11:07:44 +0800194#elif CONFIG_NAND_BOOT
Bo Shenff255e82015-03-27 14:23:36 +0800195 at91sam9n12ek_nand_hw_init();
Wenyou Yang55415432017-09-14 11:07:44 +0800196#elif CONFIG_SPI_BOOT
Bo Shenff255e82015-03-27 14:23:36 +0800197 at91_spi0_hw_init(1 << 4);
198#endif
199}
200
201#include <asm/arch/atmel_mpddrc.h>
Wenyou Yang7e8702a2016-02-01 18:12:15 +0800202static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Bo Shenff255e82015-03-27 14:23:36 +0800203{
204 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
205
206 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
207 ATMEL_MPDDRC_CR_NR_ROW_13 |
208 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
209 ATMEL_MPDDRC_CR_NB_8BANKS |
210 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED);
211
212 ddr2->rtr = 0x411;
213
214 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
215 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
216 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
217 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
218 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
219 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
220 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
221 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
222
223 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
224 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
225 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
226 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
227
228 ddr2->tpr2 = (2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
229 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
230 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
231 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
232}
233
234void mem_init(void)
235{
236 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
237 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Wenyou Yang7e8702a2016-02-01 18:12:15 +0800238 struct atmel_mpddrc_config ddr2;
Bo Shenff255e82015-03-27 14:23:36 +0800239 unsigned long csa;
240
241 ddr2_conf(&ddr2);
242
243 /* enable DDR2 clock */
Erik van Luijkc982f6b2015-08-13 15:43:20 +0200244 writel(AT91_PMC_DDR, &pmc->scer);
Bo Shenff255e82015-03-27 14:23:36 +0800245
246 /* Chip select 1 is for DDR2/SDRAM */
247 csa = readl(&matrix->ebicsa);
248 csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
249 csa &= ~AT91_MATRIX_EBI_DBPU_OFF;
250 csa |= AT91_MATRIX_EBI_DBPD_OFF;
251 csa |= AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
252 writel(csa, &matrix->ebicsa);
253
254 /* DDRAM2 Controller initialize */
Erik van Luijk0c01c3e2015-08-13 15:43:18 +0200255 ddr2_init(ATMEL_BASE_DDRSDRC, ATMEL_BASE_CS1, &ddr2);
Bo Shenff255e82015-03-27 14:23:36 +0800256}
257#endif