blob: 7f4debb912597d5a251cfa095b0309497b2528b0 [file] [log] [blame]
Bo Shenc5e88852013-11-15 11:12:38 +08001/*
2 * Copyright (C) 2013 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 <asm/io.h>
10#include <asm/arch/at91_common.h>
11#include <asm/arch/at91_pmc.h>
12#include <asm/arch/at91_wdt.h>
13#include <asm/arch/clk.h>
14#include <spl.h>
15
16static void at91_disable_wdt(void)
17{
18 struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
19
20 writel(AT91_WDT_MR_WDDIS, &wdt->mr);
21}
22
23void at91_plla_init(u32 pllar)
24{
25 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
26
27 writel(pllar, &pmc->pllar);
28 while (!(readl(&pmc->sr) & (AT91_PMC_LOCKA | AT91_PMC_MCKRDY)))
29 ;
30}
31
32void at91_mck_init(u32 mckr)
33{
34 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
35 u32 tmp;
36
37 tmp = readl(&pmc->mckr);
38 tmp &= ~(AT91_PMC_MCKR_PRES_MASK |
39 AT91_PMC_MCKR_MDIV_MASK |
40 AT91_PMC_MCKR_PLLADIV_2);
41 tmp |= mckr & (AT91_PMC_MCKR_PRES_MASK |
42 AT91_PMC_MCKR_MDIV_MASK |
43 AT91_PMC_MCKR_PLLADIV_2);
44 writel(tmp, &pmc->mckr);
45
46 while (!(readl(&pmc->sr) & AT91_PMC_MCKRDY))
47 ;
48}
49
50
51u32 spl_boot_device(void)
52{
53#ifdef CONFIG_SYS_USE_MMC
54 return BOOT_DEVICE_MMC1;
Bo Shen27019e42014-03-03 14:47:17 +080055#elif CONFIG_SYS_USE_NANDFLASH
56 return BOOT_DEVICE_NAND;
Bo Shen8a45b0b2014-03-03 14:47:15 +080057#elif CONFIG_SYS_USE_SERIALFLASH
58 return BOOT_DEVICE_SPI;
Bo Shenc5e88852013-11-15 11:12:38 +080059#endif
60 return BOOT_DEVICE_NONE;
61}
62
63u32 spl_boot_mode(void)
64{
65 switch (spl_boot_device()) {
66#ifdef CONFIG_SYS_USE_MMC
67 case BOOT_DEVICE_MMC1:
68 return MMCSD_MODE_FAT;
69 break;
70#endif
71 case BOOT_DEVICE_NONE:
72 default:
73 hang();
74 }
75}
76
77void s_init(void)
78{
79 /* disable watchdog */
80 at91_disable_wdt();
81
82 /* PMC configuration */
83 at91_pmc_init();
84
85 at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
86
87 timer_init();
88
89 board_early_init_f();
90
91 preloader_console_init();
92
93 mem_init();
94}