blob: 7f14af10112c2df0ea2d222c6d783bb5263a5784 [file] [log] [blame]
Stelian Pop78379932008-03-26 18:52:33 +01001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Pop78379932008-03-26 18:52:33 +01004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Stelian Pop78379932008-03-26 18:52:33 +01007 */
8
9#include <common.h>
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000010#include <asm/io.h>
Stelian Pop78379932008-03-26 18:52:33 +010011#include <asm/arch/at91sam9260_matrix.h>
Stelian Popd57846e2008-05-08 22:52:10 +020012#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD6b0b3db2009-03-21 21:07:59 +010013#include <asm/arch/at91_common.h>
Stelian Pop78379932008-03-26 18:52:33 +010014#include <asm/arch/at91_pmc.h>
Stelian Pop78379932008-03-26 18:52:33 +010015#include <asm/arch/gpio.h>
Wu, Josh1a500d62013-03-28 20:28:41 +000016#include <atmel_mci.h>
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000017
Stelian Pop78379932008-03-26 18:52:33 +010018#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000019# include <net.h>
Stelian Pop78379932008-03-26 18:52:33 +010020#endif
Ben Warren057d2022008-08-12 22:11:53 -070021#include <netdev.h>
Stelian Pop78379932008-03-26 18:52:33 +010022
23DECLARE_GLOBAL_DATA_PTR;
24
25/* ------------------------------------------------------------------------- */
26/*
27 * Miscelaneous platform dependent initialisations
28 */
29
Stelian Pop78379932008-03-26 18:52:33 +010030#ifdef CONFIG_CMD_NAND
31static void at91sam9260ek_nand_hw_init(void)
32{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000033 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
34 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop78379932008-03-26 18:52:33 +010035 unsigned long csa;
36
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000037 /* Assign CS3 to NAND/SmartMedia Interface */
38 csa = readl(&matrix->ebicsa);
39 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
40 writel(csa, &matrix->ebicsa);
Stelian Pop78379932008-03-26 18:52:33 +010041
42 /* Configure SMC CS3 for NAND/SmartMedia */
Reinhard Meyer0bda5f22011-06-06 00:13:10 +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-VILLARD03836942008-10-16 15:01:15 +020053#ifdef CONFIG_SYS_NAND_DBW_16
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000054 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055#else /* CONFIG_SYS_NAND_DBW_8 */
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000056 AT91_SMC_MODE_DBW_8 |
Stelian Popa35a4f82008-05-08 20:52:18 +020057#endif
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000058 AT91_SMC_MODE_TDF_CYCLE(2),
59 &smc->cs[3].mode);
Stelian Pop78379932008-03-26 18:52:33 +010060
61 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010062 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop78379932008-03-26 18:52:33 +010063
64 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARDc9539ba2009-03-22 10:22:34 +010065 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000066
Stelian Pop78379932008-03-26 18:52:33 +010067}
68#endif
69
Stelian Pop78379932008-03-26 18:52:33 +010070#ifdef CONFIG_MACB
71static void at91sam9260ek_macb_hw_init(void)
72{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000073 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
74 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
Sedji Gaouaou419a5812009-06-24 08:32:09 +020075
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000076 /* Enable EMAC clock */
77 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
Stelian Pop78379932008-03-26 18:52:33 +010078
79 /*
80 * Disable pull-up on:
81 * RXDV (PA17) => PHY normal mode (not Test mode)
Wolfgang Denka1be4762008-05-20 16:00:29 +020082 * ERX0 (PA14) => PHY ADDR0
Stelian Pop78379932008-03-26 18:52:33 +010083 * ERX1 (PA15) => PHY ADDR1
84 * ERX2 (PA25) => PHY ADDR2
85 * ERX3 (PA26) => PHY ADDR3
86 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
87 *
88 * PHY has internal pull-down
89 */
90 writel(pin_to_mask(AT91_PIN_PA14) |
Reinhard Meyer0bda5f22011-06-06 00:13:10 +000091 pin_to_mask(AT91_PIN_PA15) |
92 pin_to_mask(AT91_PIN_PA17) |
93 pin_to_mask(AT91_PIN_PA25) |
94 pin_to_mask(AT91_PIN_PA26) |
95 pin_to_mask(AT91_PIN_PA28),
96 &pioa->pudr);
Stelian Pop78379932008-03-26 18:52:33 +010097
Heiko Schocher8a84ae12013-11-18 08:07:23 +010098 at91_phy_reset();
Stelian Pop78379932008-03-26 18:52:33 +010099
100 /* Re-enable pull-up */
101 writel(pin_to_mask(AT91_PIN_PA14) |
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000102 pin_to_mask(AT91_PIN_PA15) |
103 pin_to_mask(AT91_PIN_PA17) |
104 pin_to_mask(AT91_PIN_PA25) |
105 pin_to_mask(AT91_PIN_PA26) |
106 pin_to_mask(AT91_PIN_PA28),
107 &pioa->puer);
Stelian Pop78379932008-03-26 18:52:33 +0100108
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000109 /* Initialize EMAC=MACB hardware */
Jean-Christophe PLAGNIOL-VILLARDfafa9232009-03-21 21:08:00 +0100110 at91_macb_hw_init();
Stelian Pop78379932008-03-26 18:52:33 +0100111}
112#endif
113
Wu, Josh1a500d62013-03-28 20:28:41 +0000114#ifdef CONFIG_GENERIC_ATMEL_MCI
115int board_mmc_init(bd_t *bd)
116{
117 at91_mci_hw_init();
118
119 return atmel_mci_init((void *)ATMEL_BASE_MCI);
120}
121#endif
122
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000123int board_early_init_f(void)
Stelian Pop78379932008-03-26 18:52:33 +0100124{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000125 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
126
127 /* Enable clocks for all PIOs */
128 writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
129 (1 << ATMEL_ID_PIOC),
130 &pmc->pcer);
Stelian Pop78379932008-03-26 18:52:33 +0100131
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000132 return 0;
133}
134
135int board_init(void)
136{
Stelian Pop78379932008-03-26 18:52:33 +0100137 /* adress of boot parameters */
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000138 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop78379932008-03-26 18:52:33 +0100139
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000140 at91_seriald_hw_init();
Stelian Pop78379932008-03-26 18:52:33 +0100141#ifdef CONFIG_CMD_NAND
142 at91sam9260ek_nand_hw_init();
143#endif
144#ifdef CONFIG_HAS_DATAFLASH
Albin Tonnerreacad29e2009-09-01 11:26:20 +0200145 at91_spi0_hw_init((1 << 0) | (1 << 1));
Stelian Pop78379932008-03-26 18:52:33 +0100146#endif
147#ifdef CONFIG_MACB
148 at91sam9260ek_macb_hw_init();
149#endif
150
151 return 0;
152}
153
154int dram_init(void)
155{
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000156 gd->ram_size = get_ram_size(
157 (void *)CONFIG_SYS_SDRAM_BASE,
158 CONFIG_SYS_SDRAM_SIZE);
Stelian Pop78379932008-03-26 18:52:33 +0100159 return 0;
160}
161
162#ifdef CONFIG_RESET_PHY_R
163void reset_phy(void)
164{
Stelian Pop78379932008-03-26 18:52:33 +0100165}
166#endif
Ben Warren057d2022008-08-12 22:11:53 -0700167
168int board_eth_init(bd_t *bis)
169{
170 int rc = 0;
171#ifdef CONFIG_MACB
Reinhard Meyer0bda5f22011-06-06 00:13:10 +0000172 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
Ben Warren057d2022008-08-12 22:11:53 -0700173#endif
174 return rc;
175}