blob: f60dddac7b8fa315763d035c1b4d13196f607189 [file] [log] [blame]
Ilko Iliev61fdb732009-06-12 21:20:39 +02001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Ilko Iliev61fdb732009-06-12 21:20:39 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
6 * Copyright (C) 2009 Jean-Christopher PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Ilko Iliev61fdb732009-06-12 21:20:39 +02009 */
10
11#include <common.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040012#include <linux/sizes.h>
Asen Dimov6a595142011-07-26 04:48:41 +000013#include <asm/io.h>
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010014#include <asm/gpio.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020015#include <asm/arch/at91sam9_smc.h>
16#include <asm/arch/at91_common.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020017#include <asm/arch/at91_rstc.h>
Asen Dimov9128acd2010-04-06 16:18:04 +030018#include <asm/arch/at91_matrix.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020019#include <asm/arch/clk.h>
Asen Dimov6a595142011-07-26 04:48:41 +000020#include <asm/arch/gpio.h>
21
Ilko Iliev61fdb732009-06-12 21:20:39 +020022#include <lcd.h>
23#include <atmel_lcdc.h>
24#include <dataflash.h>
25#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
26#include <net.h>
27#endif
28#include <netdev.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060029#include <asm/mach-types.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020030
31DECLARE_GLOBAL_DATA_PTR;
32
33/* ------------------------------------------------------------------------- */
34/*
35 * Miscelaneous platform dependent initialisations
36 */
37
38#ifdef CONFIG_CMD_NAND
39static void pm9261_nand_hw_init(void)
40{
41 unsigned long csa;
Asen Dimov6a595142011-07-26 04:48:41 +000042 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
43 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Ilko Iliev61fdb732009-06-12 21:20:39 +020044
45 /* Enable CS3 */
Asen Dimov9128acd2010-04-06 16:18:04 +030046 csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
47 writel(csa, &matrix->csa);
Ilko Iliev61fdb732009-06-12 21:20:39 +020048
49 /* Configure SMC CS3 for NAND/SmartMedia */
Asen Dimov9128acd2010-04-06 16:18:04 +030050 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
51 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
52 &smc->cs[3].setup);
53
54 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
55 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
56 &smc->cs[3].pulse);
57
58 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
59 &smc->cs[3].cycle);
60
61 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
62 AT91_SMC_MODE_EXNW_DISABLE |
Ilko Iliev61fdb732009-06-12 21:20:39 +020063#ifdef CONFIG_SYS_NAND_DBW_16
Asen Dimov9128acd2010-04-06 16:18:04 +030064 AT91_SMC_MODE_DBW_16 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020065#else /* CONFIG_SYS_NAND_DBW_8 */
Asen Dimov9128acd2010-04-06 16:18:04 +030066 AT91_SMC_MODE_DBW_8 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020067#endif
Asen Dimov9128acd2010-04-06 16:18:04 +030068 AT91_SMC_MODE_TDF_CYCLE(2),
69 &smc->cs[3].mode);
70
Wenyou Yang78f89762016-02-03 10:16:50 +080071 at91_periph_clk_enable(ATMEL_ID_PIOA);
72 at91_periph_clk_enable(ATMEL_ID_PIOC);
Ilko Iliev61fdb732009-06-12 21:20:39 +020073
74 /* Configure RDY/BSY */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010075 gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
Ilko Iliev61fdb732009-06-12 21:20:39 +020076
77 /* Enable NandFlash */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010078 gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Ilko Iliev61fdb732009-06-12 21:20:39 +020079
Asen Dimov9128acd2010-04-06 16:18:04 +030080 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */
81 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */
Ilko Iliev61fdb732009-06-12 21:20:39 +020082}
83#endif
84
85
86#ifdef CONFIG_DRIVER_DM9000
87static void pm9261_dm9000_hw_init(void)
88{
Asen Dimov6a595142011-07-26 04:48:41 +000089 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
Asen Dimov9128acd2010-04-06 16:18:04 +030090
Ilko Iliev61fdb732009-06-12 21:20:39 +020091 /* Configure SMC CS2 for DM9000 */
Asen Dimov9128acd2010-04-06 16:18:04 +030092 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
93 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
94 &smc->cs[2].setup);
95
96 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
97 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
98 &smc->cs[2].pulse);
99
100 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
101 &smc->cs[2].cycle);
102
103 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
104 AT91_SMC_MODE_EXNW_DISABLE |
105 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
106 AT91_SMC_MODE_TDF_CYCLE(1),
107 &smc->cs[2].mode);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200108
109 /* Configure Interrupt pin as input, no pull-up */
Wenyou Yang78f89762016-02-03 10:16:50 +0800110 at91_periph_clk_enable(ATMEL_ID_PIOA);
Asen Dimov9128acd2010-04-06 16:18:04 +0300111 at91_set_pio_input(AT91_PIO_PORTA, 24, 0);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200112}
113#endif
114
115#ifdef CONFIG_LCD
116vidinfo_t panel_info = {
Jeroen Hofsteee887b722014-06-10 00:16:23 +0200117 .vl_col = 240,
118 .vl_row = 320,
119 .vl_clk = 4965000,
120 .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
121 ATMEL_LCDC_INVFRAME_INVERTED,
122 .vl_bpix = 3,
123 .vl_tft = 1,
124 .vl_hsync_len = 5,
125 .vl_left_margin = 1,
126 .vl_right_margin = 33,
127 .vl_vsync_len = 1,
128 .vl_upper_margin = 1,
129 .vl_lower_margin = 0,
130 .mmio = ATMEL_BASE_LCDC,
Ilko Iliev61fdb732009-06-12 21:20:39 +0200131};
132
133void lcd_enable(void)
134{
Asen Dimov9128acd2010-04-06 16:18:04 +0300135 at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power up */
Ilko Iliev61fdb732009-06-12 21:20:39 +0200136}
137
138void lcd_disable(void)
139{
Asen Dimov9128acd2010-04-06 16:18:04 +0300140 at91_set_pio_value(AT91_PIO_PORTA, 22, 1); /* power down */
Ilko Iliev61fdb732009-06-12 21:20:39 +0200141}
142
143static void pm9261_lcd_hw_init(void)
144{
Asen Dimov9128acd2010-04-06 16:18:04 +0300145 at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* LCDHSYNC */
146 at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* LCDDOTCK */
147 at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* LCDDEN */
148 at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* LCDCC */
149 at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* LCDD2 */
150 at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* LCDD3 */
151 at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* LCDD4 */
152 at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* LCDD5 */
153 at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* LCDD6 */
154 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* LCDD7 */
155 at91_set_a_periph(AT91_PIO_PORTB, 15, 0); /* LCDD10 */
156 at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* LCDD11 */
157 at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* LCDD12 */
158 at91_set_a_periph(AT91_PIO_PORTB, 18, 0); /* LCDD13 */
159 at91_set_a_periph(AT91_PIO_PORTB, 19, 0); /* LCDD14 */
160 at91_set_a_periph(AT91_PIO_PORTB, 20, 0); /* LCDD15 */
161 at91_set_b_periph(AT91_PIO_PORTB, 23, 0); /* LCDD18 */
162 at91_set_b_periph(AT91_PIO_PORTB, 24, 0); /* LCDD19 */
163 at91_set_b_periph(AT91_PIO_PORTB, 25, 0); /* LCDD20 */
164 at91_set_b_periph(AT91_PIO_PORTB, 26, 0); /* LCDD21 */
165 at91_set_b_periph(AT91_PIO_PORTB, 27, 0); /* LCDD22 */
166 at91_set_b_periph(AT91_PIO_PORTB, 28, 0); /* LCDD23 */
167
Wenyou Yang78f89762016-02-03 10:16:50 +0800168 at91_system_clk_enable(AT91_PMC_HCK1);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200169
Asen Dimov6a595142011-07-26 04:48:41 +0000170 gd->fb_base = ATMEL_BASE_SRAM;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200171}
172
173#ifdef CONFIG_LCD_INFO
174#include <nand.h>
175#include <version.h>
176
177extern flash_info_t flash_info[];
178
179void lcd_show_board_info(void)
180{
181 ulong dram_size, nand_size, flash_size, dataflash_size;
182 int i;
183 char temp[32];
184
185 lcd_printf ("%s\n", U_BOOT_VERSION);
186 lcd_printf ("(C) 2009 Ronetix GmbH\n");
187 lcd_printf ("support@ronetix.at\n");
188 lcd_printf ("%s CPU at %s MHz",
Achim Ehrlich443873d2010-02-24 10:29:16 +0100189 CONFIG_SYS_AT91_CPU_NAME,
Ilko Iliev61fdb732009-06-12 21:20:39 +0200190 strmhz(temp, get_cpu_clk_rate()));
191
192 dram_size = 0;
193 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
194 dram_size += gd->bd->bi_dram[i].size;
195
196 nand_size = 0;
197 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Scott Wood2c1b7e12016-05-30 13:57:55 -0500198 nand_size += nand_info[i]->size;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200199
200 flash_size = 0;
201 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
202 flash_size += flash_info[i].size;
203
204 dataflash_size = 0;
205 for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
206 dataflash_size += (unsigned int) dataflash_info[i].Device.pages_number *
207 dataflash_info[i].Device.pages_size;
208
209 lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n"
210 "%ld MB DataFlash\n",
211 dram_size >> 20,
212 nand_size >> 20,
213 flash_size >> 20,
214 dataflash_size >> 20);
215}
216#endif /* CONFIG_LCD_INFO */
217
218#endif /* CONFIG_LCD */
219
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000220int board_early_init_f(void)
Ilko Iliev61fdb732009-06-12 21:20:39 +0200221{
Wenyou Yang78f89762016-02-03 10:16:50 +0800222 at91_periph_clk_enable(ATMEL_ID_PIOA);
223 at91_periph_clk_enable(ATMEL_ID_PIOC);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200224
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000225 at91_seriald_hw_init();
226
227 return 0;
228}
229
230int board_init(void)
231{
232 /* arch number of PM9261-Board */
233 gd->bd->bi_arch_number = MACH_TYPE_PM9261;
234
Ilko Iliev61fdb732009-06-12 21:20:39 +0200235 /* adress of boot parameters */
236 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
237
Ilko Iliev61fdb732009-06-12 21:20:39 +0200238#ifdef CONFIG_CMD_NAND
239 pm9261_nand_hw_init();
240#endif
241#ifdef CONFIG_HAS_DATAFLASH
242 at91_spi0_hw_init(1 << 0);
243#endif
244#ifdef CONFIG_DRIVER_DM9000
245 pm9261_dm9000_hw_init();
246#endif
247#ifdef CONFIG_LCD
248 pm9261_lcd_hw_init();
249#endif
250 return 0;
251}
252
Ilko Ilievc120e9e2009-09-05 02:51:34 +0200253#ifdef CONFIG_DRIVER_DM9000
254int board_eth_init(bd_t *bis)
255{
256 return dm9000_initialize(bis);
257}
258#endif
259
Ilko Iliev61fdb732009-06-12 21:20:39 +0200260int dram_init(void)
261{
Asen Dimov5aae7462010-12-12 12:41:30 +0200262 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000263 gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
Asen Dimov5aae7462010-12-12 12:41:30 +0200264 PHYS_SDRAM_SIZE);
265 return 0;
266}
267
Simon Glass2f949c32017-03-31 08:40:32 -0600268int dram_init_banksize(void)
Asen Dimov5aae7462010-12-12 12:41:30 +0200269{
Ilko Iliev61fdb732009-06-12 21:20:39 +0200270 gd->bd->bi_dram[0].start = PHYS_SDRAM;
271 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -0600272
273 return 0;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200274}
275
276#ifdef CONFIG_RESET_PHY_R
277void reset_phy(void)
278{
279#ifdef CONFIG_DRIVER_DM9000
280 /*
281 * Initialize ethernet HW addr prior to starting Linux,
282 * needed for nfsroot
283 */
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500284 eth_init();
Ilko Iliev61fdb732009-06-12 21:20:39 +0200285#endif
286}
287#endif
288
289#ifdef CONFIG_DISPLAY_BOARDINFO
290int checkboard (void)
291{
292 char buf[32];
293
294 printf ("Board : Ronetix PM9261\n");
295 printf ("Crystal frequency: %8s MHz\n",
296 strmhz(buf, get_main_clk_rate()));
297 printf ("CPU clock : %8s MHz\n",
298 strmhz(buf, get_cpu_clk_rate()));
299 printf ("Master clock : %8s MHz\n",
300 strmhz(buf, get_mck_clk_rate()));
301
302 return 0;
303}
304#endif