blob: 1e7b33e39c1e63b8cc7ee48d8ea92bd1e2f05292 [file] [log] [blame]
Stelian Pop0176d432008-03-26 18:52:33 +01001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Pop0176d432008-03-26 18:52:33 +01004 * Lead Tech Design <www.leadtechdesign.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000026#include <asm/io.h>
Stelian Pop0176d432008-03-26 18:52:33 +010027#include <asm/arch/at91sam9260_matrix.h>
Stelian Pop9606b3c2008-05-08 22:52:10 +020028#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD1332a2a2009-03-21 21:07:59 +010029#include <asm/arch/at91_common.h>
Stelian Pop0176d432008-03-26 18:52:33 +010030#include <asm/arch/at91_pmc.h>
31#include <asm/arch/at91_rstc.h>
32#include <asm/arch/gpio.h>
Wu, Josha73267a2013-03-28 20:28:41 +000033#include <atmel_mci.h>
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000034
Stelian Pop0176d432008-03-26 18:52:33 +010035#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000036# include <net.h>
Stelian Pop0176d432008-03-26 18:52:33 +010037#endif
Ben Warren3ae071e2008-08-12 22:11:53 -070038#include <netdev.h>
Stelian Pop0176d432008-03-26 18:52:33 +010039
40DECLARE_GLOBAL_DATA_PTR;
41
42/* ------------------------------------------------------------------------- */
43/*
44 * Miscelaneous platform dependent initialisations
45 */
46
Stelian Pop0176d432008-03-26 18:52:33 +010047#ifdef CONFIG_CMD_NAND
48static void at91sam9260ek_nand_hw_init(void)
49{
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000050 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
51 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Stelian Pop0176d432008-03-26 18:52:33 +010052 unsigned long csa;
53
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000054 /* Assign CS3 to NAND/SmartMedia Interface */
55 csa = readl(&matrix->ebicsa);
56 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
57 writel(csa, &matrix->ebicsa);
Stelian Pop0176d432008-03-26 18:52:33 +010058
59 /* Configure SMC CS3 for NAND/SmartMedia */
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000060 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
61 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
62 &smc->cs[3].setup);
63 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
64 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
65 &smc->cs[3].pulse);
66 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
67 &smc->cs[3].cycle);
68 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
69 AT91_SMC_MODE_EXNW_DISABLE |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020070#ifdef CONFIG_SYS_NAND_DBW_16
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000071 AT91_SMC_MODE_DBW_16 |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072#else /* CONFIG_SYS_NAND_DBW_8 */
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000073 AT91_SMC_MODE_DBW_8 |
Stelian Popc1212b22008-05-08 20:52:18 +020074#endif
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000075 AT91_SMC_MODE_TDF_CYCLE(2),
76 &smc->cs[3].mode);
Stelian Pop0176d432008-03-26 18:52:33 +010077
78 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010079 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Stelian Pop0176d432008-03-26 18:52:33 +010080
81 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010082 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000083
Stelian Pop0176d432008-03-26 18:52:33 +010084}
85#endif
86
Stelian Pop0176d432008-03-26 18:52:33 +010087#ifdef CONFIG_MACB
88static void at91sam9260ek_macb_hw_init(void)
89{
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000090 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
91 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
92 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
93 unsigned long erstl;
Sedji Gaouaou0aafde12009-06-24 08:32:09 +020094
Reinhard Meyer8c6407f2011-06-06 00:13:10 +000095 /* Enable EMAC clock */
96 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
Stelian Pop0176d432008-03-26 18:52:33 +010097
98 /*
99 * Disable pull-up on:
100 * RXDV (PA17) => PHY normal mode (not Test mode)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200101 * ERX0 (PA14) => PHY ADDR0
Stelian Pop0176d432008-03-26 18:52:33 +0100102 * ERX1 (PA15) => PHY ADDR1
103 * ERX2 (PA25) => PHY ADDR2
104 * ERX3 (PA26) => PHY ADDR3
105 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
106 *
107 * PHY has internal pull-down
108 */
109 writel(pin_to_mask(AT91_PIN_PA14) |
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000110 pin_to_mask(AT91_PIN_PA15) |
111 pin_to_mask(AT91_PIN_PA17) |
112 pin_to_mask(AT91_PIN_PA25) |
113 pin_to_mask(AT91_PIN_PA26) |
114 pin_to_mask(AT91_PIN_PA28),
115 &pioa->pudr);
Stelian Pop0176d432008-03-26 18:52:33 +0100116
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000117 erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
Sedji Gaouaou0aafde12009-06-24 08:32:09 +0200118
Stelian Pop0176d432008-03-26 18:52:33 +0100119 /* Need to reset PHY -> 500ms reset */
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000120 writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
121 AT91_RSTC_MR_URSTEN, &rstc->mr);
Stelian Pop0176d432008-03-26 18:52:33 +0100122
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000123 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
Stelian Pop0176d432008-03-26 18:52:33 +0100124
125 /* Wait for end hardware reset */
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000126 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
127 ;
Stelian Pop0176d432008-03-26 18:52:33 +0100128
129 /* Restore NRST value */
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000130 writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
131 &rstc->mr);
Stelian Pop0176d432008-03-26 18:52:33 +0100132
133 /* Re-enable pull-up */
134 writel(pin_to_mask(AT91_PIN_PA14) |
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000135 pin_to_mask(AT91_PIN_PA15) |
136 pin_to_mask(AT91_PIN_PA17) |
137 pin_to_mask(AT91_PIN_PA25) |
138 pin_to_mask(AT91_PIN_PA26) |
139 pin_to_mask(AT91_PIN_PA28),
140 &pioa->puer);
Stelian Pop0176d432008-03-26 18:52:33 +0100141
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000142 /* Initialize EMAC=MACB hardware */
Jean-Christophe PLAGNIOL-VILLARDe2c04762009-03-21 21:08:00 +0100143 at91_macb_hw_init();
Stelian Pop0176d432008-03-26 18:52:33 +0100144}
145#endif
146
Wu, Josha73267a2013-03-28 20:28:41 +0000147#ifdef CONFIG_GENERIC_ATMEL_MCI
148int board_mmc_init(bd_t *bd)
149{
150 at91_mci_hw_init();
151
152 return atmel_mci_init((void *)ATMEL_BASE_MCI);
153}
154#endif
155
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000156int board_early_init_f(void)
157{
158 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
159
160 /* Enable clocks for all PIOs */
161 writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
162 (1 << ATMEL_ID_PIOC),
163 &pmc->pcer);
164
165 return 0;
166}
167
Stelian Pop0176d432008-03-26 18:52:33 +0100168int board_init(void)
169{
Bo Shen8495faf2013-01-29 15:43:26 +0000170#ifdef CONFIG_AT91SAM9G20EK_2MMC
171 /* arch number of AT91SAM9G20EK_2MMC-Board */
172 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G20EK_2MMC;
173#else
Nicolas Ferredf486b12009-03-22 14:48:16 +0100174#ifdef CONFIG_AT91SAM9G20EK
Bo Shen8495faf2013-01-29 15:43:26 +0000175 /* arch number of AT91SAM9G20EK-Board */
Nicolas Ferredf486b12009-03-22 14:48:16 +0100176 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G20EK;
177#else
Stelian Pop0176d432008-03-26 18:52:33 +0100178 /* arch number of AT91SAM9260EK-Board */
179 gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9260EK;
Nicolas Ferredf486b12009-03-22 14:48:16 +0100180#endif
Bo Shen8495faf2013-01-29 15:43:26 +0000181#endif
Stelian Pop0176d432008-03-26 18:52:33 +0100182 /* adress of boot parameters */
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000183 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Stelian Pop0176d432008-03-26 18:52:33 +0100184
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000185 at91_seriald_hw_init();
Stelian Pop0176d432008-03-26 18:52:33 +0100186#ifdef CONFIG_CMD_NAND
187 at91sam9260ek_nand_hw_init();
188#endif
189#ifdef CONFIG_HAS_DATAFLASH
Albin Tonnerre50b5fff2009-09-01 11:26:20 +0200190 at91_spi0_hw_init((1 << 0) | (1 << 1));
Stelian Pop0176d432008-03-26 18:52:33 +0100191#endif
192#ifdef CONFIG_MACB
193 at91sam9260ek_macb_hw_init();
194#endif
195
196 return 0;
197}
198
199int dram_init(void)
200{
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000201 gd->ram_size = get_ram_size(
202 (void *)CONFIG_SYS_SDRAM_BASE,
203 CONFIG_SYS_SDRAM_SIZE);
Stelian Pop0176d432008-03-26 18:52:33 +0100204 return 0;
205}
206
207#ifdef CONFIG_RESET_PHY_R
208void reset_phy(void)
209{
Stelian Pop0176d432008-03-26 18:52:33 +0100210}
211#endif
Ben Warren3ae071e2008-08-12 22:11:53 -0700212
213int board_eth_init(bd_t *bis)
214{
215 int rc = 0;
216#ifdef CONFIG_MACB
Reinhard Meyer8c6407f2011-06-06 00:13:10 +0000217 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
Ben Warren3ae071e2008-08-12 22:11:53 -0700218#endif
219 return rc;
220}