blob: e1b1c10d52730ce4b6c5e73e1e0a864bc9ca7fbe [file] [log] [blame]
Sergey Lapin10794322008-10-31 12:28:43 +01001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Sergey Lapin10794322008-10-31 12:28:43 +01004 * Lead Tech Design <www.leadtechdesign.com>
5 * (C) Copyright 2008 Sergey Lapin <slapin@ossfans.org>
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Sergey Lapin10794322008-10-31 12:28:43 +01008 */
9
10#include <common.h>
11#include <asm/arch/at91sam9260.h>
12#include <asm/arch/at91sam9260_matrix.h>
13#include <asm/arch/at91sam9_smc.h>
Jean-Christophe PLAGNIOL-VILLARD1332a2a2009-03-21 21:07:59 +010014#include <asm/arch/at91_common.h>
Sergey Lapin10794322008-10-31 12:28:43 +010015#include <asm/arch/at91_pmc.h>
16#include <asm/arch/at91_rstc.h>
17#include <asm/arch/gpio.h>
Sergey Lapin282e27c2011-06-09 05:45:31 +000018#include <asm/io.h>
Sergey Lapin10794322008-10-31 12:28:43 +010019#include <asm/arch/hardware.h>
20#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
21#include <netdev.h>
22#include <net.h>
23#endif
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/* ------------------------------------------------------------------------- */
28/*
29 * Miscelaneous platform dependent initialisations
30 */
31
Sergey Lapin10794322008-10-31 12:28:43 +010032static void afeb9260_nand_hw_init(void)
33{
34 unsigned long csa;
Sergey Lapin282e27c2011-06-09 05:45:31 +000035 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
36 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Sergey Lapin10794322008-10-31 12:28:43 +010037
Sergey Lapin282e27c2011-06-09 05:45:31 +000038 /* Assign CS3 to NAND/SmartMedia Interface */
39 csa = readl(&matrix->ebicsa);
40 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
41 writel(csa, &matrix->ebicsa);
Sergey Lapin10794322008-10-31 12:28:43 +010042
43 /* Configure SMC CS3 for NAND/SmartMedia */
Sergey Lapin282e27c2011-06-09 05:45:31 +000044 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
45 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
46 &smc->cs[3].setup);
47 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
48 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
49 &smc->cs[3].pulse);
50 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
51 &smc->cs[3].cycle);
52 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
53 AT91_SMC_MODE_EXNW_DISABLE |
54 AT91_SMC_MODE_DBW_8 |
55 AT91_SMC_MODE_TDF_CYCLE(2),
56 &smc->cs[3].mode);
Sergey Lapin10794322008-10-31 12:28:43 +010057
58 /* Configure RDY/BSY */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010059 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
Sergey Lapin10794322008-10-31 12:28:43 +010060
61 /* Enable NandFlash */
Jean-Christophe PLAGNIOL-VILLARD74c076d2009-03-22 10:22:34 +010062 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Sergey Lapin10794322008-10-31 12:28:43 +010063}
64
Sergey Lapin10794322008-10-31 12:28:43 +010065#ifdef CONFIG_MACB
66static void afeb9260_macb_hw_init(void)
67{
Sergey Lapin282e27c2011-06-09 05:45:31 +000068 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
69 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
70 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
71 unsigned long erstl;
Sedji Gaouaou0aafde12009-06-24 08:32:09 +020072
Sergey Lapin282e27c2011-06-09 05:45:31 +000073
74 /* Enable EMAC clock */
75 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
76
Sergey Lapin10794322008-10-31 12:28:43 +010077
78 /*
79 * Disable pull-up on:
80 * RXDV (PA17) => PHY normal mode (not Test mode)
81 * ERX0 (PA14) => PHY ADDR0
82 * ERX1 (PA15) => PHY ADDR1
83 * ERX2 (PA25) => PHY ADDR2
84 * ERX3 (PA26) => PHY ADDR3
85 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
86 *
87 * PHY has internal pull-down
88 */
89 writel(pin_to_mask(AT91_PIN_PA14) |
90 pin_to_mask(AT91_PIN_PA15) |
91 pin_to_mask(AT91_PIN_PA17) |
92 pin_to_mask(AT91_PIN_PA25) |
93 pin_to_mask(AT91_PIN_PA26) |
94 pin_to_mask(AT91_PIN_PA28),
Sergey Lapin282e27c2011-06-09 05:45:31 +000095 &pioa->pudr);
Sergey Lapin10794322008-10-31 12:28:43 +010096
Sergey Lapin282e27c2011-06-09 05:45:31 +000097 erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
Sedji Gaouaou0aafde12009-06-24 08:32:09 +020098
Sergey Lapin10794322008-10-31 12:28:43 +010099 /* Need to reset PHY -> 500ms reset */
Sergey Lapin282e27c2011-06-09 05:45:31 +0000100 writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
101 AT91_RSTC_MR_URSTEN, &rstc->mr);
102 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
Sergey Lapin10794322008-10-31 12:28:43 +0100103
104 /* Wait for end hardware reset */
Sergey Lapin282e27c2011-06-09 05:45:31 +0000105 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
106 ;
Sergey Lapin10794322008-10-31 12:28:43 +0100107 /* Restore NRST value */
Sergey Lapin282e27c2011-06-09 05:45:31 +0000108 writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
109 &rstc->mr);
110
Sergey Lapin10794322008-10-31 12:28:43 +0100111
112 /* Re-enable pull-up */
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),
Sergey Lapin282e27c2011-06-09 05:45:31 +0000119 &pioa->puer);
Sergey Lapin10794322008-10-31 12:28:43 +0100120
Jean-Christophe PLAGNIOL-VILLARDe2c04762009-03-21 21:08:00 +0100121 at91_macb_hw_init();
Sergey Lapin10794322008-10-31 12:28:43 +0100122}
123#endif
Sergey Lapin282e27c2011-06-09 05:45:31 +0000124int board_early_init_f(void)
125{
126 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
127 /* Enable clocks for all PIOs */
128 writel((1 << ATMEL_ID_PIOA) |
129 (1 << ATMEL_ID_PIOB) |
130 (1 << ATMEL_ID_PIOC),
131 &pmc->pcer);
132 return 0;
133}
Sergey Lapin10794322008-10-31 12:28:43 +0100134int board_init(void)
135{
Sergey Lapin10794322008-10-31 12:28:43 +0100136 /* arch number of AT91SAM9260EK-Board */
137 gd->bd->bi_arch_number = MACH_TYPE_AFEB9260;
138 /* adress of boot parameters */
Sergey Lapin282e27c2011-06-09 05:45:31 +0000139 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Sergey Lapin10794322008-10-31 12:28:43 +0100140
Sergey Lapin282e27c2011-06-09 05:45:31 +0000141 at91_seriald_hw_init();
Sergey Lapin10794322008-10-31 12:28:43 +0100142#ifdef CONFIG_CMD_NAND
143 afeb9260_nand_hw_init();
144#endif
Albin Tonnerre50b5fff2009-09-01 11:26:20 +0200145 at91_spi0_hw_init((1 << 0) | (1 << 1));
Sergey Lapin10794322008-10-31 12:28:43 +0100146#ifdef CONFIG_MACB
147 afeb9260_macb_hw_init();
148#endif
149
150 return 0;
151}
152
153int dram_init(void)
154{
Sergey Lapin282e27c2011-06-09 05:45:31 +0000155 gd->ram_size = get_ram_size(
156 (void *)CONFIG_SYS_SDRAM_BASE,
157 CONFIG_SYS_SDRAM_SIZE);
158
Sergey Lapin10794322008-10-31 12:28:43 +0100159 return 0;
160}
161
162#ifdef CONFIG_RESET_PHY_R
163void reset_phy(void)
164{
Sergey Lapin10794322008-10-31 12:28:43 +0100165}
166#endif
167
168int board_eth_init(bd_t *bis)
169{
170 int rc = 0;
171#ifdef CONFIG_MACB
Sergey Lapin282e27c2011-06-09 05:45:31 +0000172 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x01);
Sergey Lapin10794322008-10-31 12:28:43 +0100173#endif
174 return rc;
175}