1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2014 DENX Software Engineering
4 * Heiko Schocher <hs@denx.de>
7 * Copyright (C) 2013 Atmel Corporation
8 * Bo Shen <voice.shen@atmel.com>
15 #include <asm/global_data.h>
17 #include <asm/arch/at91_common.h>
18 #include <asm/arch/at91sam9_matrix.h>
19 #include <asm/arch/at91_pit.h>
20 #include <asm/arch/at91_rstc.h>
21 #include <asm/arch/at91_wdt.h>
22 #include <asm/arch/clk.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 static void enable_ext_reset(void)
29 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
31 writel(AT91_RSTC_KEY | AT91_RSTC_MR_URSTEN, &rstc->mr);
34 void lowlevel_clock_init(void)
36 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
38 if (!(readl(&pmc->sr) & AT91_PMC_MOSCS)) {
39 /* Enable Main Oscillator */
40 writel(AT91_PMC_MOSCS | (0x40 << 8), &pmc->mor);
42 /* Wait until Main Oscillator is stable */
43 while (!(readl(&pmc->sr) & AT91_PMC_MOSCS))
47 /* After stabilization, switch to Main Oscillator */
48 if ((readl(&pmc->mckr) & AT91_PMC_CSS) == AT91_PMC_CSS_SLOW) {
51 tmp = readl(&pmc->mckr);
53 tmp |= AT91_PMC_CSS_MAIN;
54 writel(tmp, &pmc->mckr);
55 while (!(readl(&pmc->sr) & AT91_PMC_MCKRDY))
58 tmp &= ~AT91_PMC_PRES;
59 tmp |= AT91_PMC_PRES_1;
60 writel(tmp, &pmc->mckr);
61 while (!(readl(&pmc->sr) & AT91_PMC_MCKRDY))
68 void __weak matrix_init(void)
72 void __weak at91_spl_board_init(void)
76 void __weak spl_board_init(void)
80 void board_init_f(ulong dummy)
82 #if CONFIG_IS_ENABLED(OF_CONTROL)
85 ret = spl_early_init();
87 debug("spl_early_init() failed: %d\n", ret);
92 lowlevel_clock_init();
93 #if !defined(CONFIG_WDT_AT91)
98 * At this stage the main oscillator is supposed to be enabled
101 at91_pllicpr_init(0x00);
103 /* Configure PLLA = MOSC * (PLL_MULA + 1) / PLL_DIVA */
104 at91_plla_init(CONFIG_SYS_AT91_PLLA);
106 /* PCK = PLLA = 2 * MCK */
107 at91_mck_init(CONFIG_SYS_MCKR);
109 /* Switch MCK on PLLA output */
110 at91_mck_init(CONFIG_SYS_MCKR_CSS);
112 #if defined(CONFIG_SYS_AT91_PLLB)
114 at91_pllb_init(CONFIG_SYS_AT91_PLLB);
117 /* Enable External Reset */
120 /* Initialize matrix */
123 gd->arch.mck_rate_hz = CONFIG_SYS_MASTER_CLOCK;
125 * init timer long enough for using in spl.
129 /* enable clocks for all PIOs */
130 #if defined(CONFIG_AT91SAM9X5) || defined(CONFIG_AT91SAM9N12)
131 at91_periph_clk_enable(ATMEL_ID_PIOAB);
132 at91_periph_clk_enable(ATMEL_ID_PIOCD);
134 at91_periph_clk_enable(ATMEL_ID_PIOA);
135 at91_periph_clk_enable(ATMEL_ID_PIOB);
136 at91_periph_clk_enable(ATMEL_ID_PIOC);
139 #if defined(CONFIG_SPL_SERIAL)
141 at91_seriald_hw_init();
142 preloader_console_init();
147 at91_spl_board_init();