blob: a2a569b0cd9ca95fabff431287f9e1ca1a7d3e5f [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>
12#include <asm/sizes.h>
Asen Dimov6a595142011-07-26 04:48:41 +000013#include <asm/io.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020014#include <asm/arch/at91sam9_smc.h>
15#include <asm/arch/at91_common.h>
16#include <asm/arch/at91_pmc.h>
17#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>
29
30DECLARE_GLOBAL_DATA_PTR;
31
32/* ------------------------------------------------------------------------- */
33/*
34 * Miscelaneous platform dependent initialisations
35 */
36
37#ifdef CONFIG_CMD_NAND
38static void pm9261_nand_hw_init(void)
39{
40 unsigned long csa;
Asen Dimov6a595142011-07-26 04:48:41 +000041 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
42 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
43 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
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
Asen Dimov6a595142011-07-26 04:48:41 +000071 writel(1 << ATMEL_ID_PIOA |
72 1 << ATMEL_ID_PIOC,
Asen Dimov9128acd2010-04-06 16:18:04 +030073 &pmc->pcer);
Ilko Iliev61fdb732009-06-12 21:20:39 +020074
75 /* Configure RDY/BSY */
Asen Dimov9128acd2010-04-06 16:18:04 +030076 at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Ilko Iliev61fdb732009-06-12 21:20:39 +020077
78 /* Enable NandFlash */
Asen Dimov9128acd2010-04-06 16:18:04 +030079 at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Ilko Iliev61fdb732009-06-12 21:20:39 +020080
Asen Dimov9128acd2010-04-06 16:18:04 +030081 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */
82 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */
Ilko Iliev61fdb732009-06-12 21:20:39 +020083}
84#endif
85
86
87#ifdef CONFIG_DRIVER_DM9000
88static void pm9261_dm9000_hw_init(void)
89{
Asen Dimov6a595142011-07-26 04:48:41 +000090 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
91 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Asen Dimov9128acd2010-04-06 16:18:04 +030092
Ilko Iliev61fdb732009-06-12 21:20:39 +020093 /* Configure SMC CS2 for DM9000 */
Asen Dimov9128acd2010-04-06 16:18:04 +030094 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
95 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
96 &smc->cs[2].setup);
97
98 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
99 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
100 &smc->cs[2].pulse);
101
102 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
103 &smc->cs[2].cycle);
104
105 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
106 AT91_SMC_MODE_EXNW_DISABLE |
107 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
108 AT91_SMC_MODE_TDF_CYCLE(1),
109 &smc->cs[2].mode);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200110
111 /* Configure Interrupt pin as input, no pull-up */
Asen Dimov6a595142011-07-26 04:48:41 +0000112 writel(1 << ATMEL_ID_PIOA, &pmc->pcer);
Asen Dimov9128acd2010-04-06 16:18:04 +0300113 at91_set_pio_input(AT91_PIO_PORTA, 24, 0);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200114}
115#endif
116
117#ifdef CONFIG_LCD
118vidinfo_t panel_info = {
119 vl_col: 240,
120 vl_row: 320,
121 vl_clk: 4965000,
122 vl_sync: ATMEL_LCDC_INVLINE_INVERTED |
123 ATMEL_LCDC_INVFRAME_INVERTED,
124 vl_bpix: 3,
125 vl_tft: 1,
126 vl_hsync_len: 5,
127 vl_left_margin: 1,
128 vl_right_margin:33,
129 vl_vsync_len: 1,
130 vl_upper_margin:1,
131 vl_lower_margin:0,
Asen Dimov6a595142011-07-26 04:48:41 +0000132 mmio: ATMEL_BASE_LCDC,
Ilko Iliev61fdb732009-06-12 21:20:39 +0200133};
134
135void lcd_enable(void)
136{
Asen Dimov9128acd2010-04-06 16:18:04 +0300137 at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power up */
Ilko Iliev61fdb732009-06-12 21:20:39 +0200138}
139
140void lcd_disable(void)
141{
Asen Dimov9128acd2010-04-06 16:18:04 +0300142 at91_set_pio_value(AT91_PIO_PORTA, 22, 1); /* power down */
Ilko Iliev61fdb732009-06-12 21:20:39 +0200143}
144
145static void pm9261_lcd_hw_init(void)
146{
Asen Dimov6a595142011-07-26 04:48:41 +0000147 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200148
Asen Dimov9128acd2010-04-06 16:18:04 +0300149 at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* LCDHSYNC */
150 at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* LCDDOTCK */
151 at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* LCDDEN */
152 at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* LCDCC */
153 at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* LCDD2 */
154 at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* LCDD3 */
155 at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* LCDD4 */
156 at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* LCDD5 */
157 at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* LCDD6 */
158 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* LCDD7 */
159 at91_set_a_periph(AT91_PIO_PORTB, 15, 0); /* LCDD10 */
160 at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* LCDD11 */
161 at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* LCDD12 */
162 at91_set_a_periph(AT91_PIO_PORTB, 18, 0); /* LCDD13 */
163 at91_set_a_periph(AT91_PIO_PORTB, 19, 0); /* LCDD14 */
164 at91_set_a_periph(AT91_PIO_PORTB, 20, 0); /* LCDD15 */
165 at91_set_b_periph(AT91_PIO_PORTB, 23, 0); /* LCDD18 */
166 at91_set_b_periph(AT91_PIO_PORTB, 24, 0); /* LCDD19 */
167 at91_set_b_periph(AT91_PIO_PORTB, 25, 0); /* LCDD20 */
168 at91_set_b_periph(AT91_PIO_PORTB, 26, 0); /* LCDD21 */
169 at91_set_b_periph(AT91_PIO_PORTB, 27, 0); /* LCDD22 */
170 at91_set_b_periph(AT91_PIO_PORTB, 28, 0); /* LCDD23 */
171
172 writel(1 << 17, &pmc->scer); /* LCD controller Clock, AT91SAM9261 only */
Ilko Iliev61fdb732009-06-12 21:20:39 +0200173
Asen Dimov6a595142011-07-26 04:48:41 +0000174 gd->fb_base = ATMEL_BASE_SRAM;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200175}
176
177#ifdef CONFIG_LCD_INFO
178#include <nand.h>
179#include <version.h>
180
181extern flash_info_t flash_info[];
182
183void lcd_show_board_info(void)
184{
185 ulong dram_size, nand_size, flash_size, dataflash_size;
186 int i;
187 char temp[32];
188
189 lcd_printf ("%s\n", U_BOOT_VERSION);
190 lcd_printf ("(C) 2009 Ronetix GmbH\n");
191 lcd_printf ("support@ronetix.at\n");
192 lcd_printf ("%s CPU at %s MHz",
Achim Ehrlich443873d2010-02-24 10:29:16 +0100193 CONFIG_SYS_AT91_CPU_NAME,
Ilko Iliev61fdb732009-06-12 21:20:39 +0200194 strmhz(temp, get_cpu_clk_rate()));
195
196 dram_size = 0;
197 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
198 dram_size += gd->bd->bi_dram[i].size;
199
200 nand_size = 0;
201 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
202 nand_size += nand_info[i].size;
203
204 flash_size = 0;
205 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
206 flash_size += flash_info[i].size;
207
208 dataflash_size = 0;
209 for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
210 dataflash_size += (unsigned int) dataflash_info[i].Device.pages_number *
211 dataflash_info[i].Device.pages_size;
212
213 lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n"
214 "%ld MB DataFlash\n",
215 dram_size >> 20,
216 nand_size >> 20,
217 flash_size >> 20,
218 dataflash_size >> 20);
219}
220#endif /* CONFIG_LCD_INFO */
221
222#endif /* CONFIG_LCD */
223
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000224int board_early_init_f(void)
Ilko Iliev61fdb732009-06-12 21:20:39 +0200225{
Asen Dimov6a595142011-07-26 04:48:41 +0000226 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Asen Dimov9128acd2010-04-06 16:18:04 +0300227
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000228 /* Enable clocks for some PIOs */
Asen Dimov6a595142011-07-26 04:48:41 +0000229 writel(1 << ATMEL_ID_PIOA |
230 1 << ATMEL_ID_PIOC,
Asen Dimov9128acd2010-04-06 16:18:04 +0300231 &pmc->pcer);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200232
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000233 at91_seriald_hw_init();
234
235 return 0;
236}
237
238int board_init(void)
239{
240 /* arch number of PM9261-Board */
241 gd->bd->bi_arch_number = MACH_TYPE_PM9261;
242
Ilko Iliev61fdb732009-06-12 21:20:39 +0200243 /* adress of boot parameters */
244 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
245
Ilko Iliev61fdb732009-06-12 21:20:39 +0200246#ifdef CONFIG_CMD_NAND
247 pm9261_nand_hw_init();
248#endif
249#ifdef CONFIG_HAS_DATAFLASH
250 at91_spi0_hw_init(1 << 0);
251#endif
252#ifdef CONFIG_DRIVER_DM9000
253 pm9261_dm9000_hw_init();
254#endif
255#ifdef CONFIG_LCD
256 pm9261_lcd_hw_init();
257#endif
258 return 0;
259}
260
Ilko Ilievc120e9e2009-09-05 02:51:34 +0200261#ifdef CONFIG_DRIVER_DM9000
262int board_eth_init(bd_t *bis)
263{
264 return dm9000_initialize(bis);
265}
266#endif
267
Ilko Iliev61fdb732009-06-12 21:20:39 +0200268int dram_init(void)
269{
Asen Dimov5aae7462010-12-12 12:41:30 +0200270 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000271 gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
Asen Dimov5aae7462010-12-12 12:41:30 +0200272 PHYS_SDRAM_SIZE);
273 return 0;
274}
275
276void dram_init_banksize(void)
277{
Ilko Iliev61fdb732009-06-12 21:20:39 +0200278 gd->bd->bi_dram[0].start = PHYS_SDRAM;
279 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200280}
281
282#ifdef CONFIG_RESET_PHY_R
283void reset_phy(void)
284{
285#ifdef CONFIG_DRIVER_DM9000
286 /*
287 * Initialize ethernet HW addr prior to starting Linux,
288 * needed for nfsroot
289 */
290 eth_init(gd->bd);
291#endif
292}
293#endif
294
295#ifdef CONFIG_DISPLAY_BOARDINFO
296int checkboard (void)
297{
298 char buf[32];
299
300 printf ("Board : Ronetix PM9261\n");
301 printf ("Crystal frequency: %8s MHz\n",
302 strmhz(buf, get_main_clk_rate()));
303 printf ("CPU clock : %8s MHz\n",
304 strmhz(buf, get_cpu_clk_rate()));
305 printf ("Master clock : %8s MHz\n",
306 strmhz(buf, get_mck_clk_rate()));
307
308 return 0;
309}
310#endif