blob: 6da6d41be2ecffc5cbe99b46e80a538e046f1683 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bo Shenc5e88852013-11-15 11:12:38 +08002/*
3 * Copyright (C) 2013 Atmel Corporation
4 * Bo Shen <voice.shen@atmel.com>
Bo Shenc5e88852013-11-15 11:12:38 +08005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/at91_common.h>
Bo Shenc5e88852013-11-15 11:12:38 +080010#include <asm/arch/at91_wdt.h>
11#include <asm/arch/clk.h>
12#include <spl.h>
13
Prasanthi Chellakumar1473f6a2018-10-09 11:46:40 -070014#if !defined(CONFIG_WDT_AT91)
Heiko Schocher5abc00d2014-10-31 08:31:04 +010015void at91_disable_wdt(void)
Bo Shenc5e88852013-11-15 11:12:38 +080016{
17 struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
18
19 writel(AT91_WDT_MR_WDDIS, &wdt->mr);
20}
Heiko Schocher49b461f2015-01-21 08:38:20 +010021#endif
Bo Shenc5e88852013-11-15 11:12:38 +080022
Marek Vasut1c24f132016-05-14 23:43:01 +020023#if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \
24 defined(CONFIG_SAMA5D4)
25#include <asm/arch/sama5_boot.h>
Marek Vasutbb0c63a2016-04-22 21:56:21 +020026struct {
27 u32 r4;
28} bootrom_stash __attribute__((section(".data")));
29
30u32 spl_boot_device(void)
31{
Marek Vasut1c24f132016-05-14 23:43:01 +020032 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;
Marek Vasutbb0c63a2016-04-22 21:56:21 +020036
Wenyou Yanga35c3402017-09-14 11:07:43 +080037#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Marek Vasut1c24f132016-05-14 23:43:01 +020038 if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
Wenyou Yangc00d7c32017-03-24 11:34:03 +080039#if defined(CONFIG_SPL_OF_CONTROL)
40 return BOOT_DEVICE_MMC1;
41#else
Marek Vasutbb0c63a2016-04-22 21:56:21 +020042 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();
Wenyou Yangc00d7c32017-03-24 11:34:03 +080048#endif
Marek Vasutbb0c63a2016-04-22 21:56:21 +020049 }
50#endif
51
Wenyou Yanga35c3402017-09-14 11:07:43 +080052#if defined(CONFIG_SYS_USE_SERIALFLASH) || \
53 defined(CONFIG_SYS_USE_SPIFLASH) || \
54 defined(CONFIG_SPI_BOOT)
Marek Vasut1c24f132016-05-14 23:43:01 +020055 if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
Marek Vasutbb0c63a2016-04-22 21:56:21 +020056 return BOOT_DEVICE_SPI;
57#endif
Wenyou Yangdfd6d3a2017-09-13 14:58:51 +080058 if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI)
59 return BOOT_DEVICE_SPI;
Marek Vasutbb0c63a2016-04-22 21:56:21 +020060
Wenyou Yangc00d7c32017-03-24 11:34:03 +080061 if (dev == ATMEL_SAMA5_BOOT_FROM_SMC)
62 return BOOT_DEVICE_NAND;
63
Marek Vasut1c24f132016-05-14 23:43:01 +020064 if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
65 return BOOT_DEVICE_USB;
66
Marek Vasutbb0c63a2016-04-22 21:56:21 +020067 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
Bo Shenc5e88852013-11-15 11:12:38 +080073u32 spl_boot_device(void)
74{
Wenyou Yanga35c3402017-09-14 11:07:43 +080075#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Bo Shenc5e88852013-11-15 11:12:38 +080076 return BOOT_DEVICE_MMC1;
Wenyou Yanga35c3402017-09-14 11:07:43 +080077#elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT)
Bo Shen27019e42014-03-03 14:47:17 +080078 return BOOT_DEVICE_NAND;
Wenyou Yanga35c3402017-09-14 11:07:43 +080079#elif defined(CONFIG_SYS_USE_SERIALFLASH) || \
80 defined(CONFIG_SYS_USE_SPIFLASH) || \
81 defined(CONFIG_SPI_BOOT)
Bo Shen8a45b0b2014-03-03 14:47:15 +080082 return BOOT_DEVICE_SPI;
Bo Shenc5e88852013-11-15 11:12:38 +080083#endif
84 return BOOT_DEVICE_NONE;
85}
Marek Vasutbb0c63a2016-04-22 21:56:21 +020086#endif