blob: 6a071f6b7d5800b8e5c1b9eedd9645178a860d15 [file] [log] [blame]
Sedji Gaouaou22ee6472009-07-09 10:16:29 +02001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Sedji Gaouaou22ee6472009-07-09 10:16:29 +02007 */
8
9#include <common.h>
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000010#include <asm/io.h>
11#include <asm/arch/at91sam9g45_matrix.h>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020012#include <asm/arch/at91sam9_smc.h>
13#include <asm/arch/at91_common.h>
14#include <asm/arch/at91_pmc.h>
15#include <asm/arch/at91_rstc.h>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020016#include <asm/arch/gpio.h>
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000017#include <asm/arch/clk.h>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020018#include <lcd.h>
19#include <atmel_lcdc.h>
20#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
21#include <net.h>
22#endif
23#include <netdev.h>
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/* ------------------------------------------------------------------------- */
28/*
29 * Miscelaneous platform dependent initialisations
30 */
31
32#ifdef CONFIG_CMD_NAND
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000033void at91sam9m10g45ek_nand_hw_init(void)
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020034{
Thomas Petazzoni5cfeec52011-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;
37 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020038 unsigned long csa;
39
40 /* Enable CS3 */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000041 csa = readl(&matrix->ebicsa);
42 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
43 writel(csa, &matrix->ebicsa);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020044
45 /* Configure SMC CS3 for NAND/SmartMedia */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000046 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
47 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
48 &smc->cs[3].setup);
49 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
50 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
51 &smc->cs[3].pulse);
52 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
53 &smc->cs[3].cycle);
54 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
55 AT91_SMC_MODE_EXNW_DISABLE |
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020056#ifdef CONFIG_SYS_NAND_DBW_16
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000057 AT91_SMC_MODE_DBW_16 |
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020058#else /* CONFIG_SYS_NAND_DBW_8 */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000059 AT91_SMC_MODE_DBW_8 |
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020060#endif
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000061 AT91_SMC_MODE_TDF_CYCLE(3),
62 &smc->cs[3].mode);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020063
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000064 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020065
66 /* Configure RDY/BSY */
67 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
68
69 /* Enable NandFlash */
70 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
71}
72#endif
73
Sergey Matyukevich64203c72010-06-09 23:09:06 +040074#ifdef CONFIG_CMD_USB
75static void at91sam9m10g45ek_usb_hw_init(void)
76{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000077 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
78
79 writel(1 << ATMEL_ID_PIODE, &pmc->pcer);
Sergey Matyukevich64203c72010-06-09 23:09:06 +040080
81 at91_set_gpio_output(AT91_PIN_PD1, 0);
82 at91_set_gpio_output(AT91_PIN_PD3, 0);
83}
84#endif
85
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020086#ifdef CONFIG_MACB
87static void at91sam9m10g45ek_macb_hw_init(void)
88{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000089 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
90 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
91 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
92 unsigned long erstl;
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020093
94 /* Enable clock */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000095 writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020096
97 /*
98 * Disable pull-up on:
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000099 * RXDV (PA15) => PHY normal mode (not Test mode)
100 * ERX0 (PA12) => PHY ADDR0
101 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200102 *
103 * PHY has internal pull-down
104 */
105 writel(pin_to_mask(AT91_PIN_PA15) |
106 pin_to_mask(AT91_PIN_PA12) |
107 pin_to_mask(AT91_PIN_PA13),
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000108 &pioa->pudr);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200109
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000110 erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200111
112 /* Need to reset PHY -> 500ms reset */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000113 writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
114 AT91_RSTC_MR_URSTEN, &rstc->mr);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200115
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000116 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200117
118 /* Wait for end hardware reset */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000119 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
120 ;
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200121
122 /* Restore NRST value */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000123 writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
124 &rstc->mr);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200125
126 /* Re-enable pull-up */
127 writel(pin_to_mask(AT91_PIN_PA15) |
128 pin_to_mask(AT91_PIN_PA12) |
129 pin_to_mask(AT91_PIN_PA13),
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000130 &pioa->puer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200131
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000132 /* And the pins. */
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200133 at91_macb_hw_init();
134}
135#endif
136
137#ifdef CONFIG_LCD
138
139vidinfo_t panel_info = {
140 vl_col: 480,
141 vl_row: 272,
142 vl_clk: 9000000,
143 vl_sync: ATMEL_LCDC_INVLINE_NORMAL |
144 ATMEL_LCDC_INVFRAME_NORMAL,
145 vl_bpix: 3,
146 vl_tft: 1,
147 vl_hsync_len: 45,
148 vl_left_margin: 1,
149 vl_right_margin:1,
150 vl_vsync_len: 1,
151 vl_upper_margin:40,
152 vl_lower_margin:1,
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000153 mmio : ATMEL_BASE_LCDC,
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200154};
155
156
157void lcd_enable(void)
158{
159 at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
160}
161
162void lcd_disable(void)
163{
164 at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
165}
166
167static void at91sam9m10g45ek_lcd_hw_init(void)
168{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000169 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
170
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200171 at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
172 at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
173 at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
174 at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
175 at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
176
177 at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
178 at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
179 at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
180 at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
181 at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
182 at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
183 at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
184 at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
185 at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
186 at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
187 at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
188 at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
189 at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
190 at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
191 at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
192 at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
193 at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
194 at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
195 at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
196 at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
197 at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
198 at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
199 at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
200 at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
201
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000202 writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200203
204 gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
205}
206
207#ifdef CONFIG_LCD_INFO
208#include <nand.h>
209#include <version.h>
210
211void lcd_show_board_info(void)
212{
213 ulong dram_size, nand_size;
214 int i;
215 char temp[32];
216
217 lcd_printf ("%s\n", U_BOOT_VERSION);
218 lcd_printf ("(C) 2008 ATMEL Corp\n");
219 lcd_printf ("at91support@atmel.com\n");
220 lcd_printf ("%s CPU at %s MHz\n",
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000221 ATMEL_CPU_NAME,
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200222 strmhz(temp, get_cpu_clk_rate()));
223
224 dram_size = 0;
225 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
226 dram_size += gd->bd->bi_dram[i].size;
227 nand_size = 0;
228 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
229 nand_size += nand_info[i].size;
230 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
231 dram_size >> 20,
232 nand_size >> 20 );
233}
234#endif /* CONFIG_LCD_INFO */
235#endif
236
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000237int board_early_init_f(void)
238{
239 at91_seriald_hw_init();
240 return 0;
241}
242
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200243int board_init(void)
244{
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200245 /* arch number of AT91SAM9M10G45EK-Board */
246#ifdef CONFIG_AT91SAM9M10G45EK
247 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
248#elif defined CONFIG_AT91SAM9G45EKES
249 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
250#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200251
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000252 /* adress of boot parameters */
253 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
254
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200255#ifdef CONFIG_CMD_NAND
256 at91sam9m10g45ek_nand_hw_init();
257#endif
Sergey Matyukevich64203c72010-06-09 23:09:06 +0400258#ifdef CONFIG_CMD_USB
259 at91sam9m10g45ek_usb_hw_init();
260#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200261#ifdef CONFIG_HAS_DATAFLASH
262 at91_spi0_hw_init(1 << 0);
263#endif
264#ifdef CONFIG_ATMEL_SPI
265 at91_spi0_hw_init(1 << 4);
266#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200267#ifdef CONFIG_MACB
268 at91sam9m10g45ek_macb_hw_init();
269#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200270#ifdef CONFIG_LCD
271 at91sam9m10g45ek_lcd_hw_init();
272#endif
273 return 0;
274}
275
276int dram_init(void)
277{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000278 gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
279 CONFIG_SYS_SDRAM_SIZE);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200280 return 0;
281}
282
283#ifdef CONFIG_RESET_PHY_R
284void reset_phy(void)
285{
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200286}
287#endif
288
289int board_eth_init(bd_t *bis)
290{
291 int rc = 0;
292#ifdef CONFIG_MACB
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000293 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200294#endif
295 return rc;
296}
297
298/* SPI chip select control */
299#ifdef CONFIG_ATMEL_SPI
300#include <spi.h>
301
302int spi_cs_is_valid(unsigned int bus, unsigned int cs)
303{
304 return bus == 0 && cs < 2;
305}
306
307void spi_cs_activate(struct spi_slave *slave)
308{
309 switch(slave->cs) {
310 case 1:
311 at91_set_gpio_output(AT91_PIN_PB18, 0);
312 break;
313 case 0:
314 default:
315 at91_set_gpio_output(AT91_PIN_PB3, 0);
316 break;
317 }
318}
319
320void spi_cs_deactivate(struct spi_slave *slave)
321{
322 switch(slave->cs) {
323 case 1:
324 at91_set_gpio_output(AT91_PIN_PB18, 1);
325 break;
326 case 0:
327 default:
328 at91_set_gpio_output(AT91_PIN_PB3, 1);
329 break;
330 }
331}
332#endif /* CONFIG_ATMEL_SPI */