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