ARM: at91: spl: Add macro CONFIG_XXXX_BOOT support
[oweals/u-boot.git] / arch / arm / mach-at91 / 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_wdt.h>
12 #include <asm/arch/clk.h>
13 #include <spl.h>
14
15 #if defined(CONFIG_AT91SAM9_WATCHDOG)
16 void at91_disable_wdt(void) { }
17 #else
18 void at91_disable_wdt(void)
19 {
20         struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
21
22         writel(AT91_WDT_MR_WDDIS, &wdt->mr);
23 }
24 #endif
25
26 #if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \
27     defined(CONFIG_SAMA5D4)
28 #include <asm/arch/sama5_boot.h>
29 struct {
30         u32     r4;
31 } bootrom_stash __attribute__((section(".data")));
32
33 u32 spl_boot_device(void)
34 {
35         u32 dev = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_FROM_OFF) &
36                   ATMEL_SAMA5_BOOT_FROM_MASK;
37         u32 off = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_DEV_ID_OFF) &
38                   ATMEL_SAMA5_BOOT_DEV_ID_MASK;
39
40 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
41         if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
42 #if defined(CONFIG_SPL_OF_CONTROL)
43                 return BOOT_DEVICE_MMC1;
44 #else
45                 if (off == 0)
46                         return BOOT_DEVICE_MMC1;
47                 if (off == 1)
48                         return BOOT_DEVICE_MMC2;
49                 printf("ERROR: MMC controller %i not present!\n", dev);
50                 hang();
51 #endif
52         }
53 #endif
54
55 #if defined(CONFIG_SYS_USE_SERIALFLASH) || \
56         defined(CONFIG_SYS_USE_SPIFLASH) || \
57         defined(CONFIG_SPI_BOOT)
58         if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
59                 return BOOT_DEVICE_SPI;
60 #endif
61         if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI)
62                 return BOOT_DEVICE_SPI;
63
64         if (dev == ATMEL_SAMA5_BOOT_FROM_SMC)
65                 return BOOT_DEVICE_NAND;
66
67         if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
68                 return BOOT_DEVICE_USB;
69
70         printf("ERROR: SMC/TWI/QSPI boot device not supported!\n"
71                "       Boot device %i, controller number %i\n", dev, off);
72
73         return BOOT_DEVICE_NONE;
74 }
75 #else
76 u32 spl_boot_device(void)
77 {
78 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
79         return BOOT_DEVICE_MMC1;
80 #elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT)
81         return BOOT_DEVICE_NAND;
82 #elif defined(CONFIG_SYS_USE_SERIALFLASH) || \
83         defined(CONFIG_SYS_USE_SPIFLASH) || \
84         defined(CONFIG_SPI_BOOT)
85         return BOOT_DEVICE_SPI;
86 #endif
87         return BOOT_DEVICE_NONE;
88 }
89 #endif
90
91 u32 spl_boot_mode(const u32 boot_device)
92 {
93         switch (boot_device) {
94 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
95         case BOOT_DEVICE_MMC1:
96         case BOOT_DEVICE_MMC2:
97                 return MMCSD_MODE_FS;
98                 break;
99 #endif
100         case BOOT_DEVICE_NONE:
101         default:
102                 hang();
103         }
104 }