]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/at91-common/spl.c
arm: atmel: sama5d3: spl boot from fat fs SD card
[people/ms/u-boot.git] / arch / arm / cpu / at91-common / spl.c
1 /*
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
16 static 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
23 void 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
32 void 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
51 u32 spl_boot_device(void)
52 {
53 #ifdef CONFIG_SYS_USE_MMC
54 return BOOT_DEVICE_MMC1;
55 #endif
56 return BOOT_DEVICE_NONE;
57 }
58
59 u32 spl_boot_mode(void)
60 {
61 switch (spl_boot_device()) {
62 #ifdef CONFIG_SYS_USE_MMC
63 case BOOT_DEVICE_MMC1:
64 return MMCSD_MODE_FAT;
65 break;
66 #endif
67 case BOOT_DEVICE_NONE:
68 default:
69 hang();
70 }
71 }
72
73 void s_init(void)
74 {
75 /* disable watchdog */
76 at91_disable_wdt();
77
78 /* PMC configuration */
79 at91_pmc_init();
80
81 at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
82
83 timer_init();
84
85 board_early_init_f();
86
87 preloader_console_init();
88
89 mem_init();
90 }