blob: 2b9da91b2d1e3c2bc81752b96e030f4ad230552a [file] [log] [blame]
Bo Shen06ce3f42014-02-09 15:52:39 +08001/*
2 * Copyright (C) 2014 Atmel Corporation
3 * Bo Shen <voice.shen@atmel.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <mmc.h>
10#include <asm/io.h>
11#include <asm/arch/sama5d3_smc.h>
12#include <asm/arch/at91_common.h>
Bo Shen06ce3f42014-02-09 15:52:39 +080013#include <asm/arch/at91_rstc.h>
14#include <asm/arch/gpio.h>
15#include <asm/arch/clk.h>
16#include <atmel_mci.h>
17#include <net.h>
18#include <netdev.h>
Bo Shen735ef1a2014-03-19 14:48:45 +080019#include <spl.h>
20#include <asm/arch/atmel_mpddrc.h>
21#include <asm/arch/at91_wdt.h>
Bo Shen06ce3f42014-02-09 15:52:39 +080022
23DECLARE_GLOBAL_DATA_PTR;
24
25#ifdef CONFIG_NAND_ATMEL
26void sama5d3_xplained_nand_hw_init(void)
27{
28 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
29
30 at91_periph_clk_enable(ATMEL_ID_SMC);
31
32 /* Configure SMC CS3 for NAND/SmartMedia */
33 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(1) |
34 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(1),
35 &smc->cs[3].setup);
36 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
37 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(5),
38 &smc->cs[3].pulse);
39 writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8),
40 &smc->cs[3].cycle);
41 writel(AT91_SMC_TIMINGS_TCLR(3) | AT91_SMC_TIMINGS_TADL(10) |
42 AT91_SMC_TIMINGS_TAR(3) | AT91_SMC_TIMINGS_TRR(4) |
43 AT91_SMC_TIMINGS_TWB(5) | AT91_SMC_TIMINGS_RBNSEL(3)|
44 AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
45 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
46 AT91_SMC_MODE_EXNW_DISABLE |
47#ifdef CONFIG_SYS_NAND_DBW_16
48 AT91_SMC_MODE_DBW_16 |
49#else /* CONFIG_SYS_NAND_DBW_8 */
50 AT91_SMC_MODE_DBW_8 |
51#endif
52 AT91_SMC_MODE_TDF_CYCLE(3),
53 &smc->cs[3].mode);
54}
55#endif
56
57#ifdef CONFIG_CMD_USB
58static void sama5d3_xplained_usb_hw_init(void)
59{
60 at91_set_pio_output(AT91_PIO_PORTE, 3, 0);
61 at91_set_pio_output(AT91_PIO_PORTE, 4, 0);
62}
63#endif
64
65#ifdef CONFIG_GENERIC_ATMEL_MCI
66static void sama5d3_xplained_mci0_hw_init(void)
67{
68 at91_mci_hw_init();
69
70 at91_set_pio_output(AT91_PIO_PORTE, 2, 0); /* MCI0 Power */
71}
72#endif
73
74int board_early_init_f(void)
75{
76 at91_periph_clk_enable(ATMEL_ID_PIOA);
77 at91_periph_clk_enable(ATMEL_ID_PIOB);
78 at91_periph_clk_enable(ATMEL_ID_PIOC);
79 at91_periph_clk_enable(ATMEL_ID_PIOD);
80 at91_periph_clk_enable(ATMEL_ID_PIOE);
81
82 at91_seriald_hw_init();
83
84 return 0;
85}
86
87int board_init(void)
88{
89 /* adress of boot parameters */
90 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
91
92#ifdef CONFIG_NAND_ATMEL
93 sama5d3_xplained_nand_hw_init();
94#endif
95#ifdef CONFIG_CMD_USB
96 sama5d3_xplained_usb_hw_init();
97#endif
98#ifdef CONFIG_GENERIC_ATMEL_MCI
99 sama5d3_xplained_mci0_hw_init();
100#endif
101#ifdef CONFIG_MACB
102 at91_gmac_hw_init();
103 at91_macb_hw_init();
104#endif
105 return 0;
106}
107
108int dram_init(void)
109{
110 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
111 CONFIG_SYS_SDRAM_SIZE);
112
113 return 0;
114}
115
116int board_eth_init(bd_t *bis)
117{
118#ifdef CONFIG_MACB
119 macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC, 0x00);
120 macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
121#endif
122 return 0;
123}
124
125#ifdef CONFIG_GENERIC_ATMEL_MCI
126int board_mmc_init(bd_t *bis)
127{
128 atmel_mci_init((void *)ATMEL_BASE_MCI0);
129
130 return 0;
131}
132#endif
Bo Shen735ef1a2014-03-19 14:48:45 +0800133
134/* SPL */
135#ifdef CONFIG_SPL_BUILD
136void spl_board_init(void)
137{
138#ifdef CONFIG_SYS_USE_MMC
139 sama5d3_xplained_mci0_hw_init();
140#elif CONFIG_SYS_USE_NANDFLASH
141 sama5d3_xplained_nand_hw_init();
142#endif
143}
144
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800145static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
Bo Shen735ef1a2014-03-19 14:48:45 +0800146{
147 ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
148
149 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
150 ATMEL_MPDDRC_CR_NR_ROW_14 |
151 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
152 ATMEL_MPDDRC_CR_ENRDM_ON |
153 ATMEL_MPDDRC_CR_NB_8BANKS |
154 ATMEL_MPDDRC_CR_NDQS_DISABLED |
155 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
156 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
157 /*
158 * As the DDR2-SDRAm device requires a refresh time is 7.8125us
159 * when DDR run at 133MHz, so it needs (7.8125us * 133MHz / 10^9) clocks
160 */
161 ddr2->rtr = 0x411;
162
163 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
164 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
165 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
166 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
167 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
168 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
169 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
170 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
171
172 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
173 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
174 28 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
175 26 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
176
177 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
178 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
179 2 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
180 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
181 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
182}
183
184void mem_init(void)
185{
Wenyou Yangaa0a58d2016-02-01 18:12:15 +0800186 struct atmel_mpddrc_config ddr2;
Bo Shen735ef1a2014-03-19 14:48:45 +0800187
188 ddr2_conf(&ddr2);
189
Wenyou Yang78f89762016-02-03 10:16:50 +0800190 /* Enable MPDDR clock */
Bo Shen735ef1a2014-03-19 14:48:45 +0800191 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
Wenyou Yang78f89762016-02-03 10:16:50 +0800192 at91_system_clk_enable(AT91_PMC_DDR);
Bo Shen735ef1a2014-03-19 14:48:45 +0800193
194 /* DDRAM2 Controller initialize */
Erik van Luijk59d780a2015-08-13 15:43:18 +0200195 ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
Bo Shen735ef1a2014-03-19 14:48:45 +0800196}
197
198void at91_pmc_init(void)
199{
Bo Shen735ef1a2014-03-19 14:48:45 +0800200 u32 tmp;
201
202 tmp = AT91_PMC_PLLAR_29 |
203 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
204 AT91_PMC_PLLXR_MUL(43) |
205 AT91_PMC_PLLXR_DIV(1);
206 at91_plla_init(tmp);
207
Wenyou Yang5265b1e2016-02-02 12:46:14 +0800208 at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x3));
Bo Shen735ef1a2014-03-19 14:48:45 +0800209
210 tmp = AT91_PMC_MCKR_MDIV_4 |
211 AT91_PMC_MCKR_CSS_PLLA;
212 at91_mck_init(tmp);
213}
214#endif