blob: 0c4d51765e12044d15abcb4bd86e0f49bfbce7c7 [file] [log] [blame]
Stelian Pop2118ebb2008-05-08 18:52:25 +02001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Pop2118ebb2008-05-08 18:52:25 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Stelian Pop2118ebb2008-05-08 18:52:25 +02007 */
8
9#include <common.h>
Xu, Hong21d671d2011-08-01 03:56:53 +000010#include <asm/io.h>
Stelian Pop2118ebb2008-05-08 18:52:25 +020011#include <asm/arch/at91sam9rl.h>
12#include <asm/arch/at91sam9rl_matrix.h>
13#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD1332a2a2009-03-21 21:07:59 +010014#include <asm/arch/at91_common.h>
Stelian Pop2118ebb2008-05-08 18:52:25 +020015#include <asm/arch/at91_rstc.h>
Jean-Christophe PLAGNIOL-VILLARDdc39ae92009-04-16 21:30:44 +020016#include <asm/arch/clk.h>
Stelian Pop2118ebb2008-05-08 18:52:25 +020017#include <asm/arch/gpio.h>
Xu, Hong21d671d2011-08-01 03:56:53 +000018
Stelian Pop761c70b2008-05-08 14:52:32 +020019#include <lcd.h>
20#include <atmel_lcdc.h>
Stelian Pop2118ebb2008-05-08 18:52:25 +020021
22DECLARE_GLOBAL_DATA_PTR;
23
24/* ------------------------------------------------------------------------- */
25/*
26 * Miscelaneous platform dependent initialisations
27 */
28
Stelian Pop2118ebb2008-05-08 18:52:25 +020029#ifdef CONFIG_CMD_NAND
30static void at91sam9rlek_nand_hw_init(void)
31{
Xu, Hong21d671d2011-08-01 03:56:53 +000032 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
33 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop2118ebb2008-05-08 18:52:25 +020034 unsigned long csa;
35
36 /* Enable CS3 */
Xu, Hong21d671d2011-08-01 03:56:53 +000037 csa = readl(&matrix->ebicsa);
38 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
39
40 writel(csa, &matrix->ebicsa);
Stelian Pop2118ebb2008-05-08 18:52:25 +020041
42 /* Configure SMC CS3 for NAND/SmartMedia */
Xu, Hong21d671d2011-08-01 03:56:53 +000043 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
44 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
45 &smc->cs[3].setup);
46 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
47 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
48 &smc->cs[3].pulse);
49 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
50 &smc->cs[3].cycle);
51 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
52 AT91_SMC_MODE_EXNW_DISABLE |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053#ifdef CONFIG_SYS_NAND_DBW_16
Xu, Hong21d671d2011-08-01 03:56:53 +000054 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055#else /* CONFIG_SYS_NAND_DBW_8 */
Xu, Hong21d671d2011-08-01 03:56:53 +000056 AT91_SMC_MODE_DBW_8 |
Stelian Pop2118ebb2008-05-08 18:52:25 +020057#endif
Xu, Hong21d671d2011-08-01 03:56:53 +000058 AT91_SMC_MODE_TDF_CYCLE(2),
59 &smc->cs[3].mode);
Stelian Pop2118ebb2008-05-08 18:52:25 +020060
Wenyou Yang70341e22016-02-03 10:16:50 +080061 at91_periph_clk_enable(ATMEL_ID_PIOD);
Stelian Pop2118ebb2008-05-08 18:52:25 +020062
63 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010064 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop2118ebb2008-05-08 18:52:25 +020065
66 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010067 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Stelian Pop2118ebb2008-05-08 18:52:25 +020068
69 at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
70 at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
71}
72#endif
73
Stelian Pop761c70b2008-05-08 14:52:32 +020074#ifdef CONFIG_LCD
75vidinfo_t panel_info = {
Jeroen Hofsteec346e462014-06-10 00:16:23 +020076 .vl_col = 240,
77 .vl_row = 320,
78 .vl_clk = 4965000,
79 .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
80 ATMEL_LCDC_INVFRAME_INVERTED,
81 .vl_bpix = 3,
82 .vl_tft = 1,
83 .vl_hsync_len = 5,
84 .vl_left_margin = 1,
85 .vl_right_margin = 33,
86 .vl_vsync_len = 1,
87 .vl_upper_margin = 1,
88 .vl_lower_margin = 0,
89 .mmio = ATMEL_BASE_LCDC,
Stelian Pop761c70b2008-05-08 14:52:32 +020090};
91
92void lcd_enable(void)
93{
94 at91_set_gpio_value(AT91_PIN_PA30, 0); /* power up */
95}
96
97void lcd_disable(void)
98{
99 at91_set_gpio_value(AT91_PIN_PA30, 1); /* power down */
100}
101static void at91sam9rlek_lcd_hw_init(void)
102{
103 at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
104 at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
105 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
106 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
107 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
108 at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
109 at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
110 at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
111 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
112 at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
113 at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
114 at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
115 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
116 at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
117 at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
118 at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
119 at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
120 at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
121 at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
122 at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
123 at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
124
Wenyou Yang70341e22016-02-03 10:16:50 +0800125 at91_periph_clk_enable(ATMEL_ID_LCDC);
Stelian Pop761c70b2008-05-08 14:52:32 +0200126}
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200127
128#ifdef CONFIG_LCD_INFO
129#include <nand.h>
130#include <version.h>
131
132void lcd_show_board_info(void)
133{
134 ulong dram_size, nand_size;
135 int i;
136 char temp[32];
137
138 lcd_printf ("%s\n", U_BOOT_VERSION);
139 lcd_printf ("(C) 2008 ATMEL Corp\n");
140 lcd_printf ("at91support@atmel.com\n");
141 lcd_printf ("%s CPU at %s MHz\n",
Xu, Hong21d671d2011-08-01 03:56:53 +0000142 ATMEL_CPU_NAME,
Jean-Christophe PLAGNIOL-VILLARDdc39ae92009-04-16 21:30:44 +0200143 strmhz(temp, get_cpu_clk_rate()));
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200144
145 dram_size = 0;
146 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
147 dram_size += gd->bd->bi_dram[i].size;
148 nand_size = 0;
149 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
Scott Woodb616d9b2016-05-30 13:57:55 -0500150 nand_size += nand_info[i]->size;
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200151 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
152 dram_size >> 20,
153 nand_size >> 20 );
154}
155#endif /* CONFIG_LCD_INFO */
Stelian Pop761c70b2008-05-08 14:52:32 +0200156#endif
157
Xu, Hong21d671d2011-08-01 03:56:53 +0000158int board_early_init_f(void)
159{
Xu, Hong21d671d2011-08-01 03:56:53 +0000160 return 0;
161}
Stelian Pop761c70b2008-05-08 14:52:32 +0200162
Stelian Pop2118ebb2008-05-08 18:52:25 +0200163int board_init(void)
164{
Stelian Pop2118ebb2008-05-08 18:52:25 +0200165 /* arch number of AT91SAM9RLEK-Board */
166 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9RLEK;
167 /* adress of boot parameters */
Xu, Hong21d671d2011-08-01 03:56:53 +0000168 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop2118ebb2008-05-08 18:52:25 +0200169
Stelian Pop2118ebb2008-05-08 18:52:25 +0200170#ifdef CONFIG_CMD_NAND
171 at91sam9rlek_nand_hw_init();
172#endif
173#ifdef CONFIG_HAS_DATAFLASH
Jean-Christophe PLAGNIOL-VILLARD7ebafb72009-03-21 21:07:59 +0100174 at91_spi0_hw_init(1 << 0);
Stelian Pop2118ebb2008-05-08 18:52:25 +0200175#endif
Stelian Pop761c70b2008-05-08 14:52:32 +0200176#ifdef CONFIG_LCD
177 at91sam9rlek_lcd_hw_init();
178#endif
Stelian Pop2118ebb2008-05-08 18:52:25 +0200179 return 0;
180}
181
182int dram_init(void)
183{
Xu, Hong21d671d2011-08-01 03:56:53 +0000184 gd->ram_size = get_ram_size(
185 (void *)CONFIG_SYS_SDRAM_BASE,
186 CONFIG_SYS_SDRAM_SIZE);
Stelian Pop2118ebb2008-05-08 18:52:25 +0200187 return 0;
188}