blob: 8aabc5595196b12c7c1953b2052dda758ae918b3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sedji Gaouaou538566d2009-07-09 10:16:29 +02002/*
3 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01004 * Stelian Pop <stelian@popies.net>
Sedji Gaouaou538566d2009-07-09 10:16:29 +02005 * Lead Tech Design <www.leadtechdesign.com>
Sedji Gaouaou538566d2009-07-09 10:16:29 +02006 */
7
8#include <common.h>
Wenyou Yangcf6667c2017-04-18 15:15:50 +08009#include <debug_uart.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070010#include <init.h>
Simon Glass0c364412019-12-28 10:44:48 -070011#include <net.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070012#include <vsprintf.h>
Thomas Petazzonia5e85762011-08-04 11:08:50 +000013#include <asm/io.h>
Bo Shenc56e9f42015-03-27 14:23:34 +080014#include <asm/arch/clk.h>
Thomas Petazzonia5e85762011-08-04 11:08:50 +000015#include <asm/arch/at91sam9g45_matrix.h>
Sedji Gaouaou538566d2009-07-09 10:16:29 +020016#include <asm/arch/at91sam9_smc.h>
17#include <asm/arch/at91_common.h>
Sedji Gaouaou538566d2009-07-09 10:16:29 +020018#include <asm/arch/gpio.h>
Thomas Petazzonia5e85762011-08-04 11:08:50 +000019#include <asm/arch/clk.h>
Sedji Gaouaou538566d2009-07-09 10:16:29 +020020#include <lcd.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090021#include <linux/mtd/rawnand.h>
Sedji Gaouaou538566d2009-07-09 10:16:29 +020022#include <atmel_lcdc.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060023#include <asm/mach-types.h>
Sedji Gaouaou538566d2009-07-09 10:16:29 +020024
25DECLARE_GLOBAL_DATA_PTR;
26
27/* ------------------------------------------------------------------------- */
28/*
29 * Miscelaneous platform dependent initialisations
30 */
31
32#ifdef CONFIG_CMD_NAND
Thomas Petazzonia5e85762011-08-04 11:08:50 +000033void at91sam9m10g45ek_nand_hw_init(void)
Sedji Gaouaou538566d2009-07-09 10:16:29 +020034{
Thomas Petazzonia5e85762011-08-04 11:08:50 +000035 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
36 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Sedji Gaouaou538566d2009-07-09 10:16:29 +020037 unsigned long csa;
38
39 /* Enable CS3 */
Thomas Petazzonia5e85762011-08-04 11:08:50 +000040 csa = readl(&matrix->ebicsa);
41 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
42 writel(csa, &matrix->ebicsa);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020043
44 /* Configure SMC CS3 for NAND/SmartMedia */
Thomas Petazzonia5e85762011-08-04 11:08:50 +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),
47 &smc->cs[3].setup);
48 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
49 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
50 &smc->cs[3].pulse);
51 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
52 &smc->cs[3].cycle);
53 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
54 AT91_SMC_MODE_EXNW_DISABLE |
Sedji Gaouaou538566d2009-07-09 10:16:29 +020055#ifdef CONFIG_SYS_NAND_DBW_16
Thomas Petazzonia5e85762011-08-04 11:08:50 +000056 AT91_SMC_MODE_DBW_16 |
Sedji Gaouaou538566d2009-07-09 10:16:29 +020057#else /* CONFIG_SYS_NAND_DBW_8 */
Thomas Petazzonia5e85762011-08-04 11:08:50 +000058 AT91_SMC_MODE_DBW_8 |
Sedji Gaouaou538566d2009-07-09 10:16:29 +020059#endif
Thomas Petazzonia5e85762011-08-04 11:08:50 +000060 AT91_SMC_MODE_TDF_CYCLE(3),
61 &smc->cs[3].mode);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020062
Wenyou Yang78f89762016-02-03 10:16:50 +080063 at91_periph_clk_enable(ATMEL_ID_PIOC);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020064
65 /* Configure RDY/BSY */
66 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
67
68 /* Enable NandFlash */
69 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
70}
71#endif
72
Bo Shenc56e9f42015-03-27 14:23:34 +080073#if defined(CONFIG_SPL_BUILD)
74#include <spl.h>
75#include <nand.h>
76
77void at91_spl_board_init(void)
78{
79 /*
80 * On the at91sam9m10g45ek board, the chip wm9711 stays in the
81 * test mode, so it needs do some action to exit test mode.
82 */
83 at91_periph_clk_enable(ATMEL_ID_PIODE);
84 at91_set_gpio_output(AT91_PIN_PD7, 0);
85 at91_set_gpio_output(AT91_PIN_PD8, 0);
86 at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
87 at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
88
Wenyou Yange035ea72017-09-14 11:07:44 +080089#ifdef CONFIG_SD_BOOT
Bo Shenc56e9f42015-03-27 14:23:34 +080090 at91_mci_hw_init();
Wenyou Yange035ea72017-09-14 11:07:44 +080091#elif CONFIG_NAND_BOOT
Bo Shenc56e9f42015-03-27 14:23:34 +080092 at91sam9m10g45ek_nand_hw_init();
93#endif
94}
95
96#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangaa0a58d2016-02-01 18:12:15 +080097static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Bo Shenc56e9f42015-03-27 14:23:34 +080098{
99 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
100
101 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
102 ATMEL_MPDDRC_CR_NR_ROW_14 |
103 ATMEL_MPDDRC_CR_DQMS_SHARED |
104 ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
105
106 ddr2->rtr = 0x24b;
107
108 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
109 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
110 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
111 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 60 ns */
112 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
113 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
114 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
115 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
116
117 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
118 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
119 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
120 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
121
122 ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
123 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
124 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
125 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
126}
127
128void mem_init(void)
129{
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800130 struct atmel_mpddrc_config ddr2;
Bo Shenc56e9f42015-03-27 14:23:34 +0800131
132 ddr2_conf(&ddr2);
133
Wenyou Yang78f89762016-02-03 10:16:50 +0800134 at91_system_clk_enable(AT91_PMC_DDR);
Bo Shenc56e9f42015-03-27 14:23:34 +0800135
Bo Shenc56e9f42015-03-27 14:23:34 +0800136 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200137 ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
Bo Shenc56e9f42015-03-27 14:23:34 +0800138}
139#endif
140
Sergey Matyukevichd25010d2010-06-09 23:09:06 +0400141#ifdef CONFIG_CMD_USB
142static void at91sam9m10g45ek_usb_hw_init(void)
143{
Wenyou Yang78f89762016-02-03 10:16:50 +0800144 at91_periph_clk_enable(ATMEL_ID_PIODE);
Sergey Matyukevichd25010d2010-06-09 23:09:06 +0400145
146 at91_set_gpio_output(AT91_PIN_PD1, 0);
147 at91_set_gpio_output(AT91_PIN_PD3, 0);
148}
149#endif
150
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200151#ifdef CONFIG_LCD
152
153vidinfo_t panel_info = {
Jeroen Hofsteee887b722014-06-10 00:16:23 +0200154 .vl_col = 480,
155 .vl_row = 272,
156 .vl_clk = 9000000,
157 .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
158 ATMEL_LCDC_INVFRAME_NORMAL,
159 .vl_bpix = 3,
160 .vl_tft = 1,
161 .vl_hsync_len = 45,
162 .vl_left_margin = 1,
163 .vl_right_margin = 1,
164 .vl_vsync_len = 1,
165 .vl_upper_margin = 40,
166 .vl_lower_margin = 1,
167 .mmio = ATMEL_BASE_LCDC,
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200168};
169
170
171void lcd_enable(void)
172{
173 at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
174}
175
176void lcd_disable(void)
177{
178 at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
179}
180
181static void at91sam9m10g45ek_lcd_hw_init(void)
182{
183 at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
184 at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
185 at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
186 at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
187 at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
188
189 at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
190 at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
191 at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
192 at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
193 at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
194 at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
195 at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
196 at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
197 at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
198 at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
199 at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
200 at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
201 at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
202 at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
203 at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
204 at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
205 at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
206 at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
207 at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
208 at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
209 at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
210 at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
211 at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
212 at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
213
Wenyou Yang78f89762016-02-03 10:16:50 +0800214 at91_periph_clk_enable(ATMEL_ID_LCDC);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200215
216 gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
217}
218
219#ifdef CONFIG_LCD_INFO
220#include <nand.h>
221#include <version.h>
222
223void lcd_show_board_info(void)
224{
225 ulong dram_size, nand_size;
226 int i;
227 char temp[32];
228
229 lcd_printf ("%s\n", U_BOOT_VERSION);
230 lcd_printf ("(C) 2008 ATMEL Corp\n");
231 lcd_printf ("at91support@atmel.com\n");
232 lcd_printf ("%s CPU at %s MHz\n",
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000233 ATMEL_CPU_NAME,
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200234 strmhz(temp, get_cpu_clk_rate()));
235
236 dram_size = 0;
237 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
238 dram_size += gd->bd->bi_dram[i].size;
239 nand_size = 0;
240 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Grygorii Strashko1e096a22017-06-26 19:13:03 -0500241 nand_size += get_nand_dev_by_index(i)->size;
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200242 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
243 dram_size >> 20,
244 nand_size >> 20 );
245}
246#endif /* CONFIG_LCD_INFO */
247#endif
248
Wenyou Yangcf6667c2017-04-18 15:15:50 +0800249#ifdef CONFIG_DEBUG_UART_BOARD_INIT
250void board_debug_uart_init(void)
251{
252 at91_seriald_hw_init();
253}
254#endif
255
256#ifdef CONFIG_BOARD_EARLY_INIT_F
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000257int board_early_init_f(void)
258{
Wenyou Yangcf6667c2017-04-18 15:15:50 +0800259#ifdef CONFIG_DEBUG_UART
260 debug_uart_init();
261#endif
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000262 return 0;
263}
Wenyou Yangcf6667c2017-04-18 15:15:50 +0800264#endif
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000265
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200266int board_init(void)
267{
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200268 /* arch number of AT91SAM9M10G45EK-Board */
269#ifdef CONFIG_AT91SAM9M10G45EK
270 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
271#elif defined CONFIG_AT91SAM9G45EKES
272 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
273#endif
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000274
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200275 /* adress of boot parameters */
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000276 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200277
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200278#ifdef CONFIG_CMD_NAND
279 at91sam9m10g45ek_nand_hw_init();
280#endif
Sergey Matyukevichd25010d2010-06-09 23:09:06 +0400281#ifdef CONFIG_CMD_USB
282 at91sam9m10g45ek_usb_hw_init();
283#endif
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200284#ifdef CONFIG_LCD
285 at91sam9m10g45ek_lcd_hw_init();
286#endif
287 return 0;
288}
289
290int dram_init(void)
291{
Thomas Petazzonia5e85762011-08-04 11:08:50 +0000292 gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
293 CONFIG_SYS_SDRAM_SIZE);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200294 return 0;
295}
296
297#ifdef CONFIG_RESET_PHY_R
298void reset_phy(void)
299{
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200300}
301#endif