1 // SPDX-License-Identifier: GPL-2.0+
7 #include <asm/arch/sama5_sfr.h>
8 #include <asm/arch/sama5d3_smc.h>
9 #include <asm/arch/at91_common.h>
10 #include <asm/arch/at91_pmc.h>
11 #include <asm/arch/at91_rstc.h>
12 #include <asm/arch/gpio.h>
13 #include <asm/arch/clk.h>
18 #include <asm/arch/atmel_mpddrc.h>
19 #include <asm/arch/at91_wdt.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 /* ------------------------------------------------------------------------- */
25 * Miscelaneous platform dependent initialisations
28 void wb50n_nand_hw_init(void)
30 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
32 at91_periph_clk_enable(ATMEL_ID_SMC);
34 /* Configure SMC CS3 for NAND/SmartMedia */
35 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(1) |
36 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(1),
38 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
39 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(5),
41 writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8),
43 writel(AT91_SMC_TIMINGS_TCLR(3) | AT91_SMC_TIMINGS_TADL(10) |
44 AT91_SMC_TIMINGS_TAR(3) | AT91_SMC_TIMINGS_TRR(4) |
45 AT91_SMC_TIMINGS_TWB(5) | AT91_SMC_TIMINGS_RBNSEL(3) |
46 AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
47 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
48 AT91_SMC_MODE_EXNW_DISABLE |
50 AT91_SMC_MODE_TDF_CYCLE(3), &smc->cs[3].mode);
52 /* Disable Flash Write Protect Line */
53 at91_set_pio_output(AT91_PIO_PORTE, 14, 1);
56 int board_early_init_f(void)
58 at91_periph_clk_enable(ATMEL_ID_PIOA);
59 at91_periph_clk_enable(ATMEL_ID_PIOB);
60 at91_periph_clk_enable(ATMEL_ID_PIOC);
61 at91_periph_clk_enable(ATMEL_ID_PIOD);
62 at91_periph_clk_enable(ATMEL_ID_PIOE);
64 at91_seriald_hw_init();
71 /* adress of boot parameters */
72 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
83 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
84 CONFIG_SYS_SDRAM_SIZE);
88 int board_phy_config(struct phy_device *phydev)
91 ksz9021_phy_extended_write(phydev,
92 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x2222);
94 ksz9021_phy_extended_write(phydev,
95 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x2222);
96 /* rx/tx clock delay */
97 ksz9021_phy_extended_write(phydev,
98 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf2f4);
103 int board_eth_init(bd_t *bis)
107 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
112 #ifdef CONFIG_BOARD_LATE_INIT
113 #include <linux/ctype.h>
114 int board_late_init(void)
116 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
117 const char *LAIRD_NAME = "lrd_name";
120 strcpy(name, get_cpu_name());
121 for (p = name; *p != '\0'; *p = tolower(*p), p++)
123 strcat(name, "-wb50n");
124 env_set(LAIRD_NAME, name);
133 #ifdef CONFIG_SPL_BUILD
134 void spl_board_init(void)
136 wb50n_nand_hw_init();
139 static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
141 ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_LPDDR_SDRAM);
143 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_9 |
144 ATMEL_MPDDRC_CR_NR_ROW_13 |
145 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
146 ATMEL_MPDDRC_CR_NDQS_DISABLED |
147 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
148 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
152 ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
153 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
154 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
155 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
156 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
157 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
158 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
159 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
161 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
162 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
163 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
164 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
166 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
167 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
168 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
169 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
170 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
175 struct atmel_sfr *sfr = (struct atmel_sfr *)ATMEL_BASE_SFR;
176 struct atmel_mpddrc_config ddr2;
180 writel(ATMEL_SFR_DDRCFG_FDQIEN | ATMEL_SFR_DDRCFG_FDQSIEN,
183 /* enable MPDDR clock */
184 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
185 at91_system_clk_enable(AT91_PMC_DDR);
187 /* DDRAM2 Controller initialize */
188 ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
191 void at91_pmc_init(void)
195 tmp = AT91_PMC_PLLAR_29 |
196 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
197 AT91_PMC_PLLXR_MUL(43) | AT91_PMC_PLLXR_DIV(1);
200 at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x3));
202 tmp = AT91_PMC_MCKR_MDIV_4 | AT91_PMC_MCKR_CSS_PLLA;