blob: 2598e09959cd9e5d24a4d24ec38d9200944156e8 [file] [log] [blame]
Bo Shenf92b2982013-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 Shen37a36b32014-03-03 14:47:15 +080055#elif CONFIG_SYS_USE_SERIALFLASH
56 return BOOT_DEVICE_SPI;
Bo Shenf92b2982013-11-15 11:12:38 +080057#endif
58 return BOOT_DEVICE_NONE;
59}
60
61u32 spl_boot_mode(void)
62{
63 switch (spl_boot_device()) {
64#ifdef CONFIG_SYS_USE_MMC
65 case BOOT_DEVICE_MMC1:
66 return MMCSD_MODE_FAT;
67 break;
68#endif
69 case BOOT_DEVICE_NONE:
70 default:
71 hang();
72 }
73}
74
75void s_init(void)
76{
77 /* disable watchdog */
78 at91_disable_wdt();
79
80 /* PMC configuration */
81 at91_pmc_init();
82
83 at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
84
85 timer_init();
86
87 board_early_init_f();
88
89 preloader_console_init();
90
91 mem_init();
92}