blob: 8fa989a2a4ffcc64eb496749b26dd7e59bd82895 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ben Whitten44b7fc82017-11-23 13:47:48 +00002/*
Ben Whitten44b7fc82017-11-23 13:47:48 +00003 */
4
5#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06007#include <asm/global_data.h>
Ben Whitten44b7fc82017-11-23 13:47:48 +00008#include <asm/io.h>
Tudor Ambarus680897a2019-09-27 13:09:00 +00009#include <asm/arch/at91_sfr.h>
Ben Whitten44b7fc82017-11-23 13:47:48 +000010#include <asm/arch/sama5d3_smc.h>
11#include <asm/arch/at91_common.h>
12#include <asm/arch/at91_pmc.h>
13#include <asm/arch/at91_rstc.h>
14#include <asm/arch/gpio.h>
15#include <asm/arch/clk.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Ben Whitten44b7fc82017-11-23 13:47:48 +000017#include <micrel.h>
18#include <net.h>
19#include <netdev.h>
20#include <spl.h>
21#include <asm/arch/atmel_mpddrc.h>
22#include <asm/arch/at91_wdt.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
26/* ------------------------------------------------------------------------- */
27/*
28 * Miscelaneous platform dependent initialisations
29 */
30
31void wb50n_nand_hw_init(void)
32{
33 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
34
35 at91_periph_clk_enable(ATMEL_ID_SMC);
36
37 /* Configure SMC CS3 for NAND/SmartMedia */
38 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(1) |
39 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(1),
40 &smc->cs[3].setup);
41 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
42 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(5),
43 &smc->cs[3].pulse);
44 writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8),
45 &smc->cs[3].cycle);
46 writel(AT91_SMC_TIMINGS_TCLR(3) | AT91_SMC_TIMINGS_TADL(10) |
47 AT91_SMC_TIMINGS_TAR(3) | AT91_SMC_TIMINGS_TRR(4) |
48 AT91_SMC_TIMINGS_TWB(5) | AT91_SMC_TIMINGS_RBNSEL(3) |
49 AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
50 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
51 AT91_SMC_MODE_EXNW_DISABLE |
52 AT91_SMC_MODE_DBW_8 |
53 AT91_SMC_MODE_TDF_CYCLE(3), &smc->cs[3].mode);
54
55 /* Disable Flash Write Protect Line */
56 at91_set_pio_output(AT91_PIO_PORTE, 14, 1);
57}
58
59int board_early_init_f(void)
60{
61 at91_periph_clk_enable(ATMEL_ID_PIOA);
62 at91_periph_clk_enable(ATMEL_ID_PIOB);
63 at91_periph_clk_enable(ATMEL_ID_PIOC);
64 at91_periph_clk_enable(ATMEL_ID_PIOD);
65 at91_periph_clk_enable(ATMEL_ID_PIOE);
66
67 at91_seriald_hw_init();
68
69 return 0;
70}
71
72int board_init(void)
73{
74 /* adress of boot parameters */
75 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
76
77 wb50n_nand_hw_init();
78
79 at91_macb_hw_init();
80
81 return 0;
82}
83
84int dram_init(void)
85{
86 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
87 CONFIG_SYS_SDRAM_SIZE);
88 return 0;
89}
90
91int board_phy_config(struct phy_device *phydev)
92{
93 /* rx data delay */
94 ksz9021_phy_extended_write(phydev,
95 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x2222);
96 /* tx data delay */
97 ksz9021_phy_extended_write(phydev,
98 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x2222);
99 /* rx/tx clock delay */
100 ksz9021_phy_extended_write(phydev,
101 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf2f4);
102
103 return 0;
104}
105
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900106int board_eth_init(struct bd_info *bis)
Ben Whitten44b7fc82017-11-23 13:47:48 +0000107{
108 int rc = 0;
109
110 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
111
112 return rc;
113}
114
115#ifdef CONFIG_BOARD_LATE_INIT
116#include <linux/ctype.h>
117int board_late_init(void)
118{
119#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
120 const char *LAIRD_NAME = "lrd_name";
121 char name[32], *p;
122
123 strcpy(name, get_cpu_name());
124 for (p = name; *p != '\0'; *p = tolower(*p), p++)
125 ;
126 strcat(name, "-wb50n");
127 env_set(LAIRD_NAME, name);
128
129#endif
130
131 return 0;
132}
133#endif
134
135/* SPL */
136#ifdef CONFIG_SPL_BUILD
137void spl_board_init(void)
138{
139 wb50n_nand_hw_init();
140}
141
142static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
143{
144 ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_LPDDR_SDRAM);
145
146 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_9 |
147 ATMEL_MPDDRC_CR_NR_ROW_13 |
148 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
149 ATMEL_MPDDRC_CR_NDQS_DISABLED |
150 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
151 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
152
153 ddr2->rtr = 0x411;
154
155 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
156 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
157 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
158 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
159 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
160 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
161 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
162 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
163
164 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
165 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
166 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
167 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
168
169 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
170 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
171 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
172 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
173 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
174}
175
176void mem_init(void)
177{
Ben Whitten44b7fc82017-11-23 13:47:48 +0000178 struct atmel_mpddrc_config ddr2;
179
180 ddr2_conf(&ddr2);
181
Eugen Hristev19ac3ca2019-08-08 07:48:31 +0000182 configure_ddrcfg_input_buffers(true);
Ben Whitten44b7fc82017-11-23 13:47:48 +0000183
184 /* enable MPDDR clock */
185 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
186 at91_system_clk_enable(AT91_PMC_DDR);
187
188 /* DDRAM2 Controller initialize */
189 ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
190}
191
192void at91_pmc_init(void)
193{
194 u32 tmp;
195
196 tmp = AT91_PMC_PLLAR_29 |
197 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
198 AT91_PMC_PLLXR_MUL(43) | AT91_PMC_PLLXR_DIV(1);
199 at91_plla_init(tmp);
200
201 at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x3));
202
203 tmp = AT91_PMC_MCKR_MDIV_4 | AT91_PMC_MCKR_CSS_PLLA;
204 at91_mck_init(tmp);
205}
206#endif