blob: 2fea56ffe757f85e9a77cb5face384c90908525e [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>
Bo Shen41d41a92015-03-27 14:23:34 +080011#include <asm/arch/clk.h>
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000012#include <asm/arch/at91sam9g45_matrix.h>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020013#include <asm/arch/at91sam9_smc.h>
14#include <asm/arch/at91_common.h>
15#include <asm/arch/at91_pmc.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>
Bo Shen41d41a92015-03-27 14:23:34 +080019#include <linux/mtd/nand.h>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020020#include <atmel_lcdc.h>
Wu, Joshcf874c12014-05-21 10:42:15 +080021#include <atmel_mci.h>
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020022#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
23#include <net.h>
24#endif
25#include <netdev.h>
26
27DECLARE_GLOBAL_DATA_PTR;
28
29/* ------------------------------------------------------------------------- */
30/*
31 * Miscelaneous platform dependent initialisations
32 */
33
34#ifdef CONFIG_CMD_NAND
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000035void at91sam9m10g45ek_nand_hw_init(void)
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020036{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000037 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
38 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
39 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020040 unsigned long csa;
41
42 /* Enable CS3 */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000043 csa = readl(&matrix->ebicsa);
44 csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
45 writel(csa, &matrix->ebicsa);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020046
47 /* Configure SMC CS3 for NAND/SmartMedia */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000048 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
49 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
50 &smc->cs[3].setup);
51 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
52 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
53 &smc->cs[3].pulse);
54 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
55 &smc->cs[3].cycle);
56 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
57 AT91_SMC_MODE_EXNW_DISABLE |
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020058#ifdef CONFIG_SYS_NAND_DBW_16
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000059 AT91_SMC_MODE_DBW_16 |
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020060#else /* CONFIG_SYS_NAND_DBW_8 */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000061 AT91_SMC_MODE_DBW_8 |
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020062#endif
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000063 AT91_SMC_MODE_TDF_CYCLE(3),
64 &smc->cs[3].mode);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020065
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +000066 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +020067
68 /* Configure RDY/BSY */
69 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
70
71 /* Enable NandFlash */
72 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
73}
74#endif
75
Bo Shen41d41a92015-03-27 14:23:34 +080076#if defined(CONFIG_SPL_BUILD)
77#include <spl.h>
78#include <nand.h>
79
80void at91_spl_board_init(void)
81{
82 /*
83 * On the at91sam9m10g45ek board, the chip wm9711 stays in the
84 * test mode, so it needs do some action to exit test mode.
85 */
86 at91_periph_clk_enable(ATMEL_ID_PIODE);
87 at91_set_gpio_output(AT91_PIN_PD7, 0);
88 at91_set_gpio_output(AT91_PIN_PD8, 0);
89 at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
90 at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
91
92#ifdef CONFIG_SYS_USE_MMC
93 at91_mci_hw_init();
94#elif CONFIG_SYS_USE_NANDFLASH
95 at91sam9m10g45ek_nand_hw_init();
96#endif
97}
98
99#include <asm/arch/atmel_mpddrc.h>
100static void ddr2_conf(struct atmel_mpddr *ddr2)
101{
102 ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
103
104 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
105 ATMEL_MPDDRC_CR_NR_ROW_14 |
106 ATMEL_MPDDRC_CR_DQMS_SHARED |
107 ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
108
109 ddr2->rtr = 0x24b;
110
111 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
112 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
113 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
114 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 60 ns */
115 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
116 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
117 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
118 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
119
120 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
121 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
122 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
123 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
124
125 ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
126 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
127 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
128 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
129}
130
131void mem_init(void)
132{
133 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Bo Shen41d41a92015-03-27 14:23:34 +0800134 struct atmel_mpddr ddr2;
Bo Shen41d41a92015-03-27 14:23:34 +0800135
136 ddr2_conf(&ddr2);
137
138 /* enable DDR2 clock */
Erik van Luijkc982f6b2015-08-13 15:43:20 +0200139 writel(AT91_PMC_DDR, &pmc->scer);
Bo Shen41d41a92015-03-27 14:23:34 +0800140
Bo Shen41d41a92015-03-27 14:23:34 +0800141 /* DDRAM2 Controller initialize */
Erik van Luijk0c01c3e2015-08-13 15:43:18 +0200142 ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
Bo Shen41d41a92015-03-27 14:23:34 +0800143}
144#endif
145
Sergey Matyukevich64203c72010-06-09 23:09:06 +0400146#ifdef CONFIG_CMD_USB
147static void at91sam9m10g45ek_usb_hw_init(void)
148{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000149 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
150
151 writel(1 << ATMEL_ID_PIODE, &pmc->pcer);
Sergey Matyukevich64203c72010-06-09 23:09:06 +0400152
153 at91_set_gpio_output(AT91_PIN_PD1, 0);
154 at91_set_gpio_output(AT91_PIN_PD3, 0);
155}
156#endif
157
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200158#ifdef CONFIG_MACB
159static void at91sam9m10g45ek_macb_hw_init(void)
160{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000161 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
162 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200163
164 /* Enable clock */
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000165 writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200166
167 /*
168 * Disable pull-up on:
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000169 * RXDV (PA15) => PHY normal mode (not Test mode)
170 * ERX0 (PA12) => PHY ADDR0
171 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200172 *
173 * PHY has internal pull-down
174 */
175 writel(pin_to_mask(AT91_PIN_PA15) |
176 pin_to_mask(AT91_PIN_PA12) |
177 pin_to_mask(AT91_PIN_PA13),
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000178 &pioa->pudr);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200179
Heiko Schocher4535a242013-11-18 08:07:23 +0100180 at91_phy_reset();
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200181
182 /* Re-enable pull-up */
183 writel(pin_to_mask(AT91_PIN_PA15) |
184 pin_to_mask(AT91_PIN_PA12) |
185 pin_to_mask(AT91_PIN_PA13),
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000186 &pioa->puer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200187
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000188 /* And the pins. */
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200189 at91_macb_hw_init();
190}
191#endif
192
193#ifdef CONFIG_LCD
194
195vidinfo_t panel_info = {
Jeroen Hofsteec346e462014-06-10 00:16:23 +0200196 .vl_col = 480,
197 .vl_row = 272,
198 .vl_clk = 9000000,
199 .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
200 ATMEL_LCDC_INVFRAME_NORMAL,
201 .vl_bpix = 3,
202 .vl_tft = 1,
203 .vl_hsync_len = 45,
204 .vl_left_margin = 1,
205 .vl_right_margin = 1,
206 .vl_vsync_len = 1,
207 .vl_upper_margin = 40,
208 .vl_lower_margin = 1,
209 .mmio = ATMEL_BASE_LCDC,
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200210};
211
212
213void lcd_enable(void)
214{
215 at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
216}
217
218void lcd_disable(void)
219{
220 at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
221}
222
223static void at91sam9m10g45ek_lcd_hw_init(void)
224{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000225 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
226
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200227 at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
228 at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
229 at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
230 at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
231 at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
232
233 at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
234 at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
235 at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
236 at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
237 at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
238 at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
239 at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
240 at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
241 at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
242 at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
243 at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
244 at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
245 at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
246 at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
247 at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
248 at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
249 at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
250 at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
251 at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
252 at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
253 at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
254 at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
255 at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
256 at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
257
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000258 writel(1 << ATMEL_ID_LCDC, &pmc->pcer);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200259
260 gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
261}
262
263#ifdef CONFIG_LCD_INFO
264#include <nand.h>
265#include <version.h>
266
267void lcd_show_board_info(void)
268{
269 ulong dram_size, nand_size;
270 int i;
271 char temp[32];
272
273 lcd_printf ("%s\n", U_BOOT_VERSION);
274 lcd_printf ("(C) 2008 ATMEL Corp\n");
275 lcd_printf ("at91support@atmel.com\n");
276 lcd_printf ("%s CPU at %s MHz\n",
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000277 ATMEL_CPU_NAME,
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200278 strmhz(temp, get_cpu_clk_rate()));
279
280 dram_size = 0;
281 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
282 dram_size += gd->bd->bi_dram[i].size;
283 nand_size = 0;
284 for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
285 nand_size += nand_info[i].size;
286 lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
287 dram_size >> 20,
288 nand_size >> 20 );
289}
290#endif /* CONFIG_LCD_INFO */
291#endif
292
Wu, Joshcf874c12014-05-21 10:42:15 +0800293#ifdef CONFIG_GENERIC_ATMEL_MCI
294int board_mmc_init(bd_t *bis)
295{
296 at91_mci_hw_init();
297
298 return atmel_mci_init((void *)ATMEL_BASE_MCI0);
299}
300#endif
301
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000302int board_early_init_f(void)
303{
304 at91_seriald_hw_init();
305 return 0;
306}
307
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200308int board_init(void)
309{
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200310 /* arch number of AT91SAM9M10G45EK-Board */
311#ifdef CONFIG_AT91SAM9M10G45EK
312 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
313#elif defined CONFIG_AT91SAM9G45EKES
314 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
315#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200316
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000317 /* adress of boot parameters */
318 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
319
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200320#ifdef CONFIG_CMD_NAND
321 at91sam9m10g45ek_nand_hw_init();
322#endif
Sergey Matyukevich64203c72010-06-09 23:09:06 +0400323#ifdef CONFIG_CMD_USB
324 at91sam9m10g45ek_usb_hw_init();
325#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200326#ifdef CONFIG_HAS_DATAFLASH
327 at91_spi0_hw_init(1 << 0);
328#endif
329#ifdef CONFIG_ATMEL_SPI
330 at91_spi0_hw_init(1 << 4);
331#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200332#ifdef CONFIG_MACB
333 at91sam9m10g45ek_macb_hw_init();
334#endif
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200335#ifdef CONFIG_LCD
336 at91sam9m10g45ek_lcd_hw_init();
337#endif
338 return 0;
339}
340
341int dram_init(void)
342{
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000343 gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
344 CONFIG_SYS_SDRAM_SIZE);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200345 return 0;
346}
347
348#ifdef CONFIG_RESET_PHY_R
349void reset_phy(void)
350{
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200351}
352#endif
353
354int board_eth_init(bd_t *bis)
355{
356 int rc = 0;
357#ifdef CONFIG_MACB
Thomas Petazzoni5cfeec52011-08-04 11:08:50 +0000358 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
Sedji Gaouaou22ee6472009-07-09 10:16:29 +0200359#endif
360 return rc;
361}
362
363/* SPI chip select control */
364#ifdef CONFIG_ATMEL_SPI
365#include <spi.h>
366
367int spi_cs_is_valid(unsigned int bus, unsigned int cs)
368{
369 return bus == 0 && cs < 2;
370}
371
372void spi_cs_activate(struct spi_slave *slave)
373{
374 switch(slave->cs) {
375 case 1:
376 at91_set_gpio_output(AT91_PIN_PB18, 0);
377 break;
378 case 0:
379 default:
380 at91_set_gpio_output(AT91_PIN_PB3, 0);
381 break;
382 }
383}
384
385void spi_cs_deactivate(struct spi_slave *slave)
386{
387 switch(slave->cs) {
388 case 1:
389 at91_set_gpio_output(AT91_PIN_PB18, 1);
390 break;
391 case 0:
392 default:
393 at91_set_gpio_output(AT91_PIN_PB3, 1);
394 break;
395 }
396}
397#endif /* CONFIG_ATMEL_SPI */