xref: /openbmc/u-boot/arch/arm/mach-at91/spl.c (revision 286a5c44)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2013 Atmel Corporation
4  *		      Bo Shen <voice.shen@atmel.com>
5  */
6 
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/arch/at91_common.h>
10 #include <asm/arch/at91_wdt.h>
11 #include <asm/arch/clk.h>
12 #include <spl.h>
13 
14 #if !defined(CONFIG_WDT_AT91)
15 void at91_disable_wdt(void)
16 {
17 	struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
18 
19 	writel(AT91_WDT_MR_WDDIS, &wdt->mr);
20 }
21 #endif
22 
23 #if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \
24     defined(CONFIG_SAMA5D4)
25 #include <asm/arch/sama5_boot.h>
26 struct {
27 	u32	r4;
28 } bootrom_stash __attribute__((section(".data")));
29 
30 u32 spl_boot_device(void)
31 {
32 	u32 dev = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_FROM_OFF) &
33 		  ATMEL_SAMA5_BOOT_FROM_MASK;
34 	u32 off = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_DEV_ID_OFF) &
35 		  ATMEL_SAMA5_BOOT_DEV_ID_MASK;
36 
37 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
38 	if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
39 #if defined(CONFIG_SPL_OF_CONTROL)
40 		return BOOT_DEVICE_MMC1;
41 #else
42 		if (off == 0)
43 			return BOOT_DEVICE_MMC1;
44 		if (off == 1)
45 			return BOOT_DEVICE_MMC2;
46 		printf("ERROR: MMC controller %i not present!\n", dev);
47 		hang();
48 #endif
49 	}
50 #endif
51 
52 #if defined(CONFIG_SYS_USE_SERIALFLASH) || \
53 	defined(CONFIG_SYS_USE_SPIFLASH) || \
54 	defined(CONFIG_SPI_BOOT)
55 	if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
56 		return BOOT_DEVICE_SPI;
57 #endif
58 	if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI)
59 		return BOOT_DEVICE_SPI;
60 
61 	if (dev == ATMEL_SAMA5_BOOT_FROM_SMC)
62 		return BOOT_DEVICE_NAND;
63 
64 	if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
65 		return BOOT_DEVICE_USB;
66 
67 	printf("ERROR: SMC/TWI/QSPI boot device not supported!\n"
68 	       "       Boot device %i, controller number %i\n", dev, off);
69 
70 	return BOOT_DEVICE_NONE;
71 }
72 #else
73 u32 spl_boot_device(void)
74 {
75 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
76 	return BOOT_DEVICE_MMC1;
77 #elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT)
78 	return BOOT_DEVICE_NAND;
79 #elif defined(CONFIG_SYS_USE_SERIALFLASH) || \
80 	defined(CONFIG_SYS_USE_SPIFLASH) || \
81 	defined(CONFIG_SPI_BOOT)
82 	return BOOT_DEVICE_SPI;
83 #endif
84 	return BOOT_DEVICE_NONE;
85 }
86 #endif
87