blob: acc1b31b707f716900ac20da9ae9237dfc8e7bd7 [file] [log] [blame]
Daniel Gorsulowski44d80252010-01-25 10:50:41 +01001/*
Daniel Gorsulowskia950c812011-04-18 04:15:02 +00002 * (C) Copyright 2010-2011
Daniel Gorsulowski44d80252010-01-25 10:50:41 +01003 * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
4 * esd electronic system design gmbh <www.esd.eu>
5 *
6 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01007 * Stelian Pop <stelian@popies.net>
Daniel Gorsulowski44d80252010-01-25 10:50:41 +01008 * Lead Tech Design <www.leadtechdesign.com>
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010011 */
12
13#include <common.h>
Daniel Gorsulowskia950c812011-04-18 04:15:02 +000014#include <asm/io.h>
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010015#include <asm/arch/at91sam9_smc.h>
16#include <asm/arch/at91_common.h>
17#include <asm/arch/at91_pmc.h>
18#include <asm/arch/at91_rstc.h>
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010019#include <asm/arch/at91_matrix.h>
20#include <asm/arch/at91_pio.h>
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010021#include <asm/arch/clk.h>
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010022#include <netdev.h>
Daniel Gorsulowskia950c812011-04-18 04:15:02 +000023#ifdef CONFIG_LCD
24# include <atmel_lcdc.h>
25# include <lcd.h>
26# ifdef CONFIG_LCD_INFO
27# include <nand.h>
28# include <version.h>
29# endif
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010030#endif
31
32DECLARE_GLOBAL_DATA_PTR;
33
34/*
35 * Miscelaneous platform dependent initialisations
36 */
37
38static int hw_rev = -1; /* hardware revision */
39
40int get_hw_rev(void)
41{
42 if (hw_rev >= 0)
43 return hw_rev;
44
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010045 hw_rev = at91_get_pio_value(AT91_PIO_PORTB, 19);
46 hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 20) << 1;
47 hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 21) << 2;
48 hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 22) << 3;
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010049
50 if (hw_rev == 15)
51 hw_rev = 0;
52
53 return hw_rev;
54}
55
56#ifdef CONFIG_CMD_NAND
57static void otc570_nand_hw_init(void)
58{
59 unsigned long csa;
Daniel Gorsulowskia950c812011-04-18 04:15:02 +000060 at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC0;
61 at91_matrix_t *matrix = (at91_matrix_t *) ATMEL_BASE_MATRIX;
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010062
63 /* Enable CS3 */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010064 csa = readl(&matrix->csa[0]) | AT91_MATRIX_CSA_EBI_CS3A;
65 writel(csa, &matrix->csa[0]);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010066
67 /* Configure SMC CS3 for NAND/SmartMedia */
Daniel Gorsulowskic21052b2012-01-25 03:19:50 +000068 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
69 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(2),
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010070 &smc->cs[3].setup);
71
72 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
73 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
74 &smc->cs[3].pulse);
75
Daniel Gorsulowskic21052b2012-01-25 03:19:50 +000076 writel(AT91_SMC_CYCLE_NWE(6) | AT91_SMC_CYCLE_NRD(6),
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010077 &smc->cs[3].cycle);
78 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
79 AT91_SMC_MODE_EXNW_DISABLE |
Daniel Gorsulowskia950c812011-04-18 04:15:02 +000080 AT91_SMC_MODE_DBW_8 |
Daniel Gorsulowskic21052b2012-01-25 03:19:50 +000081 AT91_SMC_MODE_TDF_CYCLE(12),
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010082 &smc->cs[3].mode);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010083
84 /* Configure RDY/BSY */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010085 at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010086
87 /* Enable NandFlash */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +010088 at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010089}
90#endif /* CONFIG_CMD_NAND */
91
92#ifdef CONFIG_MACB
93static void otc570_macb_hw_init(void)
94{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +000095 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010096 /* Enable clock */
Daniel Gorsulowskia950c812011-04-18 04:15:02 +000097 writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +010098 at91_macb_hw_init();
99}
100#endif
101
102/*
103 * Static memory controller initialization to enable Beckhoff ET1100 EtherCAT
104 * controller debugging
105 * The ET1100 is located at physical address 0x70000000
106 * Its process memory is located at physical address 0x70001000
107 */
108static void otc570_ethercat_hw_init(void)
109{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000110 at91_smc_t *smc1 = (at91_smc_t *) ATMEL_BASE_SMC1;
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100111
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100112 /* Configure SMC EBI1_CS0 for EtherCAT */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100113 writel(AT91_SMC_SETUP_NWE(0) | AT91_SMC_SETUP_NCS_WR(0) |
114 AT91_SMC_SETUP_NRD(0) | AT91_SMC_SETUP_NCS_RD(0),
115 &smc1->cs[0].setup);
116 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(9) |
117 AT91_SMC_PULSE_NRD(5) | AT91_SMC_PULSE_NCS_RD(9),
118 &smc1->cs[0].pulse);
119 writel(AT91_SMC_CYCLE_NWE(10) | AT91_SMC_CYCLE_NRD(6),
120 &smc1->cs[0].cycle);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100121 /*
122 * Configure behavior at external wait signal, byte-select mode, 16 bit
123 * data bus width, none data float wait states and TDF optimization
124 */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100125 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_EXNW_READY |
126 AT91_SMC_MODE_DBW_16 | AT91_SMC_MODE_TDF_CYCLE(0) |
127 AT91_SMC_MODE_TDF, &smc1->cs[0].mode);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100128
129 /* Configure RDY/BSY */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100130 at91_set_b_periph(AT91_PIO_PORTE, 20, 0); /* EBI1_NWAIT */
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100131}
132
133#ifdef CONFIG_LCD
134/* Number of columns and rows, pixel clock in Hz and hsync/vsync polarity */
135vidinfo_t panel_info = {
136 .vl_col = 640,
137 .vl_row = 480,
138 .vl_clk = 25175000,
139 .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
140 ATMEL_LCDC_INVFRAME_INVERTED,
141
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000142 .vl_bpix = LCD_BPP,/* Bits per pixel, 0 = 1bit, 3 = 8bit */
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100143 .vl_tft = 1, /* 0 = passive, 1 = TFT */
144 .vl_vsync_len = 1, /* Length of vertical sync in NOL */
145 .vl_upper_margin = 35, /* Idle lines at the frame start */
146 .vl_lower_margin = 5, /* Idle lines at the end of the frame */
147 .vl_hsync_len = 5, /* Width of the LCDHSYNC pulse */
148 .vl_left_margin = 112, /* Idle cycles at the line beginning */
149 .vl_right_margin = 1, /* Idle cycles at the end of the line */
150
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000151 .mmio = ATMEL_BASE_LCDC,
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100152};
153
154void lcd_enable(void)
155{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000156 at91_set_pio_value(AT91_PIO_PORTA, 30, 0); /* power up */
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100157}
158
159void lcd_disable(void)
160{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000161 at91_set_pio_value(AT91_PIO_PORTA, 30, 1); /* power down */
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100162}
163
164static void otc570_lcd_hw_init(void)
165{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000166 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100167
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100168 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDVSYNC */
169 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDHSYNC */
170 at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDDOTCK */
171 at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDDEN */
172 at91_set_b_periph(AT91_PIO_PORTB, 9, 0); /* LCDCC */
173 at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD2 */
174 at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD3 */
175 at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD4 */
176 at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD5 */
177 at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD6 */
178 at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD7 */
179 at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD10 */
180 at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD11 */
181 at91_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD12 */
182 at91_set_b_periph(AT91_PIO_PORTC, 12, 0); /* LCDD13 */
183 at91_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD14 */
184 at91_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD15 */
185 at91_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD18 */
186 at91_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD19 */
187 at91_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDD20 */
188 at91_set_b_periph(AT91_PIO_PORTC, 17, 0); /* LCDD21 */
189 at91_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDD22 */
190 at91_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDD23 */
191 at91_set_pio_output(AT91_PIO_PORTA, 30, 1); /* PCI */
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100192
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000193 writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100194}
195
196#ifdef CONFIG_LCD_INFO
197void lcd_show_board_info(void)
198{
199 ulong dram_size, nand_size;
200 int i;
201 char temp[32];
202
203 dram_size = 0;
204 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
205 dram_size += gd->bd->bi_dram[i].size;
206 nand_size = 0;
207 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
208 nand_size += nand_info[i].size;
209
210 lcd_printf("\n%s\n", U_BOOT_VERSION);
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000211 lcd_printf("CPU at %s MHz\n", strmhz(temp, get_cpu_clk_rate()));
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100212 lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
213 dram_size >> 20,
214 nand_size >> 20 );
215 lcd_printf(" Board : esd ARM9 HMI Panel - OTC570\n");
216 lcd_printf(" Hardware-revision: 1.%d\n", get_hw_rev());
217 lcd_printf(" Mach-type : %lu\n", gd->bd->bi_arch_number);
218}
219#endif /* CONFIG_LCD_INFO */
220#endif /* CONFIG_LCD */
221
222int dram_init(void)
223{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000224 gd->ram_size = get_ram_size(
225 (void *)CONFIG_SYS_SDRAM_BASE,
226 CONFIG_SYS_SDRAM_SIZE);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100227 return 0;
228}
229
230int board_eth_init(bd_t *bis)
231{
232 int rc = 0;
233#ifdef CONFIG_MACB
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000234 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100235#endif
236 return rc;
237}
238
239int checkboard(void)
240{
241 char str[32];
242
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000243 puts("Board : esd ARM9 HMI Panel - OTC570");
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200244 if (getenv_f("serial#", str, sizeof(str)) > 0) {
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100245 puts(", serial# ");
246 puts(str);
247 }
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000248 printf("\n");
249 printf("Hardware-revision: 1.%d\n", get_hw_rev());
250 printf("Mach-type : %lu\n", gd->bd->bi_arch_number);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100251 return 0;
252}
253
254#ifdef CONFIG_SERIAL_TAG
255void get_board_serial(struct tag_serialnr *serialnr)
256{
257 char *str;
258
259 char *serial = getenv("serial#");
260 if (serial) {
261 str = strchr(serial, '_');
262 if (str && (strlen(str) >= 4)) {
263 serialnr->high = (*(str + 1) << 8) | *(str + 2);
264 serialnr->low = simple_strtoul(str + 3, NULL, 16);
265 }
266 } else {
267 serialnr->high = 0;
268 serialnr->low = 0;
269 }
270}
271#endif
272
273#ifdef CONFIG_REVISION_TAG
274u32 get_board_rev(void)
275{
276 return hw_rev | 0x100;
277}
278#endif
279
280#ifdef CONFIG_MISC_INIT_R
281int misc_init_r(void)
282{
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100283 char str[64];
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000284 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100285
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100286 at91_set_pio_output(AT91_PIO_PORTA, 29, 1);
287 at91_set_a_periph(AT91_PIO_PORTA, 26, 1); /* TXD0 */
288 at91_set_a_periph(AT91_PIO_PORTA, 27, 0); /* RXD0 */
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000289 writel(1 << ATMEL_ID_USART0, &pmc->pcer);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100290 /* Set USART_MODE = 1 (RS485) */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100291 writel(1, 0xFFF8C004);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100292
293 printf("USART0: ");
294
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200295 if (getenv_f("usart0", str, sizeof(str)) == -1) {
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100296 printf("No entry - assuming 1-wire\n");
297 /* CTS pin, works as mode select pin (0 = 1-wire; 1 = RS485) */
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100298 at91_set_pio_output(AT91_PIO_PORTA, 29, 0);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100299 } else {
300 if (strcmp(str, "1-wire") == 0) {
301 printf("%s\n", str);
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100302 at91_set_pio_output(AT91_PIO_PORTA, 29, 0);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100303 } else if (strcmp(str, "rs485") == 0) {
304 printf("%s\n", str);
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100305 at91_set_pio_output(AT91_PIO_PORTA, 29, 1);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100306 } else {
307 printf("Wrong entry - assuming 1-wire ");
308 printf("(valid values are '1-wire' or 'rs485')\n");
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100309 at91_set_pio_output(AT91_PIO_PORTA, 29, 0);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100310 }
311 }
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000312#ifdef CONFIG_LCD
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100313 printf("Display memory address: 0x%08lX\n", gd->fb_base);
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000314#endif
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100315
316 return 0;
317}
318#endif /* CONFIG_MISC_INIT_R */
319
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000320int board_early_init_f(void)
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100321{
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000322 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100323
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000324 /* enable all clocks */
325 writel((1 << ATMEL_ID_PIOA) |
326 (1 << ATMEL_ID_PIOB) |
327 (1 << ATMEL_ID_PIOCDE) |
328 (1 << ATMEL_ID_TWI) |
329 (1 << ATMEL_ID_SPI0) |
330#ifdef CONFIG_LCD
331 (1 << ATMEL_ID_LCDC) |
332#endif
333 (1 << ATMEL_ID_UHP),
Daniel Gorsulowski6258b042010-02-11 14:57:04 +0100334 &pmc->pcer);
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100335
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000336 at91_seriald_hw_init();
337
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100338 /* arch number of OTC570-Board */
339 gd->bd->bi_arch_number = MACH_TYPE_OTC570;
340
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000341 return 0;
342}
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100343
Daniel Gorsulowskia950c812011-04-18 04:15:02 +0000344int board_init(void)
345{
346 /* initialize ET1100 Controller */
347 otc570_ethercat_hw_init();
348
349 /* adress of boot parameters */
350 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
351
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100352#ifdef CONFIG_CMD_NAND
353 otc570_nand_hw_init();
354#endif
Daniel Gorsulowski44d80252010-01-25 10:50:41 +0100355#ifdef CONFIG_HAS_DATAFLASH
356 at91_spi0_hw_init(1 << 0);
357#endif
358#ifdef CONFIG_MACB
359 otc570_macb_hw_init();
360#endif
361#ifdef CONFIG_AT91_CAN
362 at91_can_hw_init();
363#endif
364#ifdef CONFIG_USB_OHCI_NEW
365 at91_uhp_hw_init();
366#endif
367#ifdef CONFIG_LCD
368 otc570_lcd_hw_init();
369#endif
370 return 0;
371}