blob: d3b368451b2704583a7db56345c4a1b876bf3630 [file] [log] [blame]
Albin Tonnerre4f572d82009-08-24 18:03:26 +02001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Albin Tonnerre4f572d82009-08-24 18:03:26 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
6 * Copyright (C) 2009
7 * Albin Tonnerre, Free-Electrons <albin.tonnerre@free-electrons.com>
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000029#include <asm/io.h>
Albin Tonnerre4f572d82009-08-24 18:03:26 +020030#include <asm/arch/at91sam9260_matrix.h>
31#include <asm/arch/at91sam9_smc.h>
32#include <asm/arch/at91_common.h>
33#include <asm/arch/at91_pmc.h>
34#include <asm/arch/at91_rstc.h>
35#include <asm/arch/gpio.h>
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000036
Albin Tonnerre4f572d82009-08-24 18:03:26 +020037#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
38#include <net.h>
39#endif
40#include <netdev.h>
41
42DECLARE_GLOBAL_DATA_PTR;
43
44/* ------------------------------------------------------------------------- */
45/*
46 * Miscelaneous platform dependent initialisations
47 */
48
49#ifdef CONFIG_CMD_NAND
50static void sbc35_a9g20_nand_hw_init(void)
51{
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000052 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
53 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
54 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Albin Tonnerre4f572d82009-08-24 18:03:26 +020055 unsigned long csa;
56
57 /* Enable CS3 */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000058 csa = readl(&matrix->ebicsa);
59 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
60 writel(csa, &matrix->ebicsa);
Albin Tonnerre4f572d82009-08-24 18:03:26 +020061
62 /* Configure SMC CS3 for NAND/SmartMedia */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000063 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
64 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
65 &smc->cs[3].setup);
66 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
67 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
68 &smc->cs[3].pulse);
69 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
70 &smc->cs[3].cycle);
71 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
72 AT91_SMC_MODE_EXNW_DISABLE |
Albin Tonnerre4f572d82009-08-24 18:03:26 +020073#ifdef CONFIG_SYS_NAND_DBW_16
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000074 AT91_SMC_MODE_DBW_16 |
Albin Tonnerre4f572d82009-08-24 18:03:26 +020075#else /* CONFIG_SYS_NAND_DBW_8 */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000076 AT91_SMC_MODE_DBW_8 |
Albin Tonnerre4f572d82009-08-24 18:03:26 +020077#endif
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000078 AT91_SMC_MODE_TDF_CYCLE(2),
79 &smc->cs[3].mode);
Albin Tonnerre4f572d82009-08-24 18:03:26 +020080
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000081 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Albin Tonnerre4f572d82009-08-24 18:03:26 +020082
83 /* Configure RDY/BSY */
84 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
85
86 /* Enable NandFlash */
87 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
88}
89#endif
90
91#ifdef CONFIG_MACB
92static void sbc35_a9g20_macb_hw_init(void)
93{
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000094 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
95 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
96 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
97 unsigned long erstl;
Albin Tonnerre4f572d82009-08-24 18:03:26 +020098
Thomas Petazzoni740fcb62011-08-04 02:22:20 +000099 /* Enable EMAC clock */
100 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200101
102 /*
103 * Disable pull-up on:
104 * RXDV (PA17) => PHY normal mode (not Test mode)
105 * ERX0 (PA14) => PHY ADDR0
106 * ERX1 (PA15) => PHY ADDR1
107 * ERX2 (PA25) => PHY ADDR2
108 * ERX3 (PA26) => PHY ADDR3
109 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
110 *
111 * PHY has internal pull-down
112 */
113 writel(pin_to_mask(AT91_PIN_PA14) |
114 pin_to_mask(AT91_PIN_PA15) |
115 pin_to_mask(AT91_PIN_PA17) |
116 pin_to_mask(AT91_PIN_PA25) |
117 pin_to_mask(AT91_PIN_PA26) |
118 pin_to_mask(AT91_PIN_PA28),
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000119 &pioa->pudr);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200120
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000121 erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200122
123 /* Need to reset PHY -> 500ms reset */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000124 writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
125 AT91_RSTC_MR_URSTEN, &rstc->mr);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200126
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000127 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200128
129 /* Wait for end hardware reset */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000130 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
131 ;
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200132
133 /* Restore NRST value */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000134 writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
135 &rstc->mr);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200136
137 /* Re-enable pull-up */
138 writel(pin_to_mask(AT91_PIN_PA14) |
139 pin_to_mask(AT91_PIN_PA15) |
140 pin_to_mask(AT91_PIN_PA17) |
141 pin_to_mask(AT91_PIN_PA25) |
142 pin_to_mask(AT91_PIN_PA26) |
143 pin_to_mask(AT91_PIN_PA28),
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000144 &pioa->puer);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200145
146 at91_macb_hw_init();
147}
148#endif
149
150int board_init(void)
151{
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200152 /* adress of boot parameters */
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000153 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200154
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000155 at91_seriald_hw_init();
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200156 sbc35_a9g20_nand_hw_init();
157#ifdef CONFIG_ATMEL_SPI
158 at91_spi0_hw_init(1 << 4 | 1 << 5);
159#endif
160#ifdef CONFIG_MACB
161 sbc35_a9g20_macb_hw_init();
162#endif
163
164 return 0;
165}
166
167int dram_init(void)
168{
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000169 gd->ram_size = get_ram_size(
170 (void *)CONFIG_SYS_SDRAM_BASE,
171 CONFIG_SYS_SDRAM_SIZE);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200172 return 0;
173}
174
175#ifdef CONFIG_RESET_PHY_R
176void reset_phy(void)
177{
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200178}
179#endif
180
181int board_eth_init(bd_t *bis)
182{
183 int rc = 0;
184#ifdef CONFIG_MACB
Thomas Petazzoni740fcb62011-08-04 02:22:20 +0000185 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
Albin Tonnerre4f572d82009-08-24 18:03:26 +0200186#endif
187 return rc;
188}