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_AT91SAM9_WATCHDOG) 15 void at91_disable_wdt(void) { } 16 #else 17 void at91_disable_wdt(void) 18 { 19 struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT; 20 21 writel(AT91_WDT_MR_WDDIS, &wdt->mr); 22 } 23 #endif 24 25 #if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \ 26 defined(CONFIG_SAMA5D4) 27 #include <asm/arch/sama5_boot.h> 28 struct { 29 u32 r4; 30 } bootrom_stash __attribute__((section(".data"))); 31 32 u32 spl_boot_device(void) 33 { 34 u32 dev = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_FROM_OFF) & 35 ATMEL_SAMA5_BOOT_FROM_MASK; 36 u32 off = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_DEV_ID_OFF) & 37 ATMEL_SAMA5_BOOT_DEV_ID_MASK; 38 39 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT) 40 if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) { 41 #if defined(CONFIG_SPL_OF_CONTROL) 42 return BOOT_DEVICE_MMC1; 43 #else 44 if (off == 0) 45 return BOOT_DEVICE_MMC1; 46 if (off == 1) 47 return BOOT_DEVICE_MMC2; 48 printf("ERROR: MMC controller %i not present!\n", dev); 49 hang(); 50 #endif 51 } 52 #endif 53 54 #if defined(CONFIG_SYS_USE_SERIALFLASH) || \ 55 defined(CONFIG_SYS_USE_SPIFLASH) || \ 56 defined(CONFIG_SPI_BOOT) 57 if (dev == ATMEL_SAMA5_BOOT_FROM_SPI) 58 return BOOT_DEVICE_SPI; 59 #endif 60 if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI) 61 return BOOT_DEVICE_SPI; 62 63 if (dev == ATMEL_SAMA5_BOOT_FROM_SMC) 64 return BOOT_DEVICE_NAND; 65 66 if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA) 67 return BOOT_DEVICE_USB; 68 69 printf("ERROR: SMC/TWI/QSPI boot device not supported!\n" 70 " Boot device %i, controller number %i\n", dev, off); 71 72 return BOOT_DEVICE_NONE; 73 } 74 #else 75 u32 spl_boot_device(void) 76 { 77 #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT) 78 return BOOT_DEVICE_MMC1; 79 #elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT) 80 return BOOT_DEVICE_NAND; 81 #elif defined(CONFIG_SYS_USE_SERIALFLASH) || \ 82 defined(CONFIG_SYS_USE_SPIFLASH) || \ 83 defined(CONFIG_SPI_BOOT) 84 return BOOT_DEVICE_SPI; 85 #endif 86 return BOOT_DEVICE_NONE; 87 } 88 #endif 89