xref: /openbmc/u-boot/arch/arm/mach-at91/spl.c (revision ed4708aa)
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)
27 struct {
28 	u32	r4;
29 } bootrom_stash __attribute__((section(".data")));
30 
31 u32 spl_boot_device(void)
32 {
33 	u32 dev = (bootrom_stash.r4 >> ATMEL_SAMA5D2_BOOT_FROM_OFF) &
34 		  ATMEL_SAMA5D2_BOOT_FROM_MASK;
35 	u32 off = (bootrom_stash.r4 >> ATMEL_SAMA5D2_BOOT_DEV_ID_OFF) &
36 		  ATMEL_SAMA5D2_BOOT_DEV_ID_MASK;
37 
38 #if defined(CONFIG_SYS_USE_MMC)
39 	if (dev == ATMEL_SAMA5D2_BOOT_FROM_MCI) {
40 		if (off == 0)
41 			return BOOT_DEVICE_MMC1;
42 		if (off == 1)
43 			return BOOT_DEVICE_MMC2;
44 		printf("ERROR: MMC controller %i not present!\n", dev);
45 		hang();
46 	}
47 #endif
48 
49 #if defined(CONFIG_SYS_USE_SERIALFLASH) || defined(CONFIG_SYS_USE_SPIFLASH)
50 	if (dev == ATMEL_SAMA5D2_BOOT_FROM_SPI)
51 		return BOOT_DEVICE_SPI;
52 #endif
53 
54 	printf("ERROR: SMC/TWI/QSPI boot device not supported!\n"
55 	       "       Boot device %i, controller number %i\n", dev, off);
56 
57 	return BOOT_DEVICE_NONE;
58 }
59 #else
60 u32 spl_boot_device(void)
61 {
62 #ifdef CONFIG_SYS_USE_MMC
63 	return BOOT_DEVICE_MMC1;
64 #elif CONFIG_SYS_USE_NANDFLASH
65 	return BOOT_DEVICE_NAND;
66 #elif CONFIG_SYS_USE_SERIALFLASH || CONFIG_SYS_USE_SPIFLASH
67 	return BOOT_DEVICE_SPI;
68 #endif
69 	return BOOT_DEVICE_NONE;
70 }
71 #endif
72 
73 u32 spl_boot_mode(void)
74 {
75 	switch (spl_boot_device()) {
76 #ifdef CONFIG_SYS_USE_MMC
77 	case BOOT_DEVICE_MMC1:
78 	case BOOT_DEVICE_MMC2:
79 		return MMCSD_MODE_FS;
80 		break;
81 #endif
82 	case BOOT_DEVICE_NONE:
83 	default:
84 		hang();
85 	}
86 }
87