blob: 5e1524e07bbe0e9fbd30632844c8c9bac4731397 [file] [log] [blame]
Tom Rix23b80982009-09-27 11:10:09 -05001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Tom Rix23b80982009-09-27 11:10:09 -05004 * Lead Tech Design <www.leadtechdesign.com>
5 * Ilko Iliev <www.ronetix.at>
6 *
Eric Benard95d50e52011-06-06 22:48:28 +00007 * (C) Copyright 2009-2011
Tom Rix23b80982009-09-27 11:10:09 -05008 * Eric Benard <eric@eukrea.com>
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Tom Rix23b80982009-09-27 11:10:09 -050011 */
12
13#include <common.h>
Eric Benard95d50e52011-06-06 22:48:28 +000014#include <asm/io.h>
Tom Rix23b80982009-09-27 11:10:09 -050015#include <asm/arch/at91sam9260.h>
Tom Rix23b80982009-09-27 11:10:09 -050016#include <asm/arch/at91sam9_smc.h>
17#include <asm/arch/at91_common.h>
Eric Benard95d50e52011-06-06 22:48:28 +000018#include <asm/arch/at91_matrix.h>
Tom Rix23b80982009-09-27 11:10:09 -050019#include <asm/arch/at91_pmc.h>
20#include <asm/arch/at91_rstc.h>
Eric Benardc2b2a072011-04-03 06:35:54 +000021#include <asm/arch/at91_pio.h>
22#include <asm/arch/clk.h>
Tom Rix23b80982009-09-27 11:10:09 -050023#include <asm/arch/hardware.h>
24#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
25#include <net.h>
26#endif
27#include <netdev.h>
28
29DECLARE_GLOBAL_DATA_PTR;
30
31/* ------------------------------------------------------------------------- */
32/*
33 * Miscelaneous platform dependent initialisations
34 */
35
36#ifdef CONFIG_CMD_NAND
37static void cpu9260_nand_hw_init(void)
38{
39 unsigned long csa;
Eric Benard95d50e52011-06-06 22:48:28 +000040 at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC;
41 at91_matrix_t *matrix = (at91_matrix_t *) ATMEL_BASE_MATRIX;
42 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Tom Rix23b80982009-09-27 11:10:09 -050043
44 /* Enable CS3 */
Eric Benardc2b2a072011-04-03 06:35:54 +000045 csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
46 writel(csa, &matrix->csa);
Tom Rix23b80982009-09-27 11:10:09 -050047
48 /* Configure SMC CS3 for NAND/SmartMedia */
49#if defined(CONFIG_CPU9G20)
Eric Benardc2b2a072011-04-03 06:35:54 +000050 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
51 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
52 &smc->cs[3].setup);
53 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
54 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
55 &smc->cs[3].pulse);
56 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
57 &smc->cs[3].cycle);
58 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
59 AT91_SMC_MODE_EXNW_DISABLE |
60 AT91_SMC_MODE_DBW_8 |
61 AT91_SMC_MODE_TDF_CYCLE(3),
62 &smc->cs[3].mode);
Tom Rix23b80982009-09-27 11:10:09 -050063#elif defined(CONFIG_CPU9260)
Eric Benardc2b2a072011-04-03 06:35:54 +000064 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
65 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
66 &smc->cs[3].setup);
67 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
68 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
69 &smc->cs[3].pulse);
70 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
71 &smc->cs[3].cycle);
72 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
73 AT91_SMC_MODE_EXNW_DISABLE |
74 AT91_SMC_MODE_DBW_8 |
75 AT91_SMC_MODE_TDF_CYCLE(2),
76 &smc->cs[3].mode);
Tom Rix23b80982009-09-27 11:10:09 -050077#endif
78
Eric Benard95d50e52011-06-06 22:48:28 +000079 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Tom Rix23b80982009-09-27 11:10:09 -050080
81 /* Configure RDY/BSY */
Eric Benardc2b2a072011-04-03 06:35:54 +000082 at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Tom Rix23b80982009-09-27 11:10:09 -050083
84 /* Enable NandFlash */
Eric Benardc2b2a072011-04-03 06:35:54 +000085 at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Tom Rix23b80982009-09-27 11:10:09 -050086}
87#endif
88
89#ifdef CONFIG_MACB
90static void cpu9260_macb_hw_init(void)
91{
Eric Benardc2b2a072011-04-03 06:35:54 +000092 unsigned long rstcmr;
Eric Benard95d50e52011-06-06 22:48:28 +000093 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
94 at91_rstc_t *rstc = (at91_rstc_t *) ATMEL_BASE_RSTC;
Tom Rix23b80982009-09-27 11:10:09 -050095
96 /* Enable clock */
Eric Benard95d50e52011-06-06 22:48:28 +000097 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
Tom Rix23b80982009-09-27 11:10:09 -050098
Eric Benardc2b2a072011-04-03 06:35:54 +000099 at91_set_pio_pullup(AT91_PIO_PORTA, 17, 1);
Tom Rix23b80982009-09-27 11:10:09 -0500100
Eric Benardc2b2a072011-04-03 06:35:54 +0000101 rstcmr = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
Tom Rix23b80982009-09-27 11:10:09 -0500102
103 /* Need to reset PHY -> 500ms reset */
Eric Benardc2b2a072011-04-03 06:35:54 +0000104 writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0xD) |
105 AT91_RSTC_MR_URSTEN, &rstc->mr);
Tom Rix23b80982009-09-27 11:10:09 -0500106
Eric Benardc2b2a072011-04-03 06:35:54 +0000107 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
Tom Rix23b80982009-09-27 11:10:09 -0500108
109 /* Wait for end hardware reset */
Eric Benardc2b2a072011-04-03 06:35:54 +0000110 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
Tom Rix23b80982009-09-27 11:10:09 -0500111 ;
112
113 /* Restore NRST value */
Eric Benardc2b2a072011-04-03 06:35:54 +0000114 writel(AT91_RSTC_KEY | rstcmr | AT91_RSTC_MR_URSTEN, &rstc->mr);
Tom Rix23b80982009-09-27 11:10:09 -0500115
116 at91_macb_hw_init();
117}
118#endif
119
Eric Benardc2b2a072011-04-03 06:35:54 +0000120int board_early_init_f(void)
121{
Eric Benard95d50e52011-06-06 22:48:28 +0000122 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Eric Benardc2b2a072011-04-03 06:35:54 +0000123
Eric Benard95d50e52011-06-06 22:48:28 +0000124 writel((1 << ATMEL_ID_PIOA) |
125 (1 << ATMEL_ID_PIOB) |
126 (1 << ATMEL_ID_PIOC),
Eric Benardc2b2a072011-04-03 06:35:54 +0000127 &pmc->pcer);
128
Eric Benard95d50e52011-06-06 22:48:28 +0000129 at91_seriald_hw_init();
Eric Benardc2b2a072011-04-03 06:35:54 +0000130
131 return 0;
132}
133
134
Tom Rix23b80982009-09-27 11:10:09 -0500135int board_init(void)
136{
Tom Rix23b80982009-09-27 11:10:09 -0500137 /* arch number of the board */
138#if defined(CONFIG_CPU9G20)
Eric Benard94d50c52009-10-12 10:08:20 +0200139 gd->bd->bi_arch_number = MACH_TYPE_CPUAT9G20;
Tom Rix23b80982009-09-27 11:10:09 -0500140#elif defined(CONFIG_CPU9260)
141 gd->bd->bi_arch_number = MACH_TYPE_CPUAT9260;
142#endif
143
144 /* adress of boot parameters */
Eric Benardc2b2a072011-04-03 06:35:54 +0000145 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Tom Rix23b80982009-09-27 11:10:09 -0500146
Tom Rix23b80982009-09-27 11:10:09 -0500147#ifdef CONFIG_CMD_NAND
148 cpu9260_nand_hw_init();
149#endif
150#ifdef CONFIG_MACB
151 cpu9260_macb_hw_init();
152#endif
153#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
154 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
155#endif
156 return 0;
157}
158
159int dram_init(void)
160{
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +0000161 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
Eric Benardc2b2a072011-04-03 06:35:54 +0000162 CONFIG_SYS_SDRAM_SIZE);
Tom Rix23b80982009-09-27 11:10:09 -0500163 return 0;
164}
165
Tom Rix23b80982009-09-27 11:10:09 -0500166int board_eth_init(bd_t *bis)
167{
168 int rc = 0;
169#ifdef CONFIG_MACB
Eric Benard95d50e52011-06-06 22:48:28 +0000170 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0);
Tom Rix23b80982009-09-27 11:10:09 -0500171#endif
172 return rc;
173}