blob: f255b59195e6da69e704192d65308143fd637b2b [file] [log] [blame]
Bo Shenc5e88852013-11-15 11:12:38 +08001/*
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>
Bo Shenc5e88852013-11-15 11:12:38 +080011#include <asm/arch/at91_wdt.h>
12#include <asm/arch/clk.h>
13#include <spl.h>
14
Heiko Schocher49b461f2015-01-21 08:38:20 +010015#if defined(CONFIG_AT91SAM9_WATCHDOG)
16void at91_disable_wdt(void) { }
17#else
Heiko Schocher5abc00d2014-10-31 08:31:04 +010018void at91_disable_wdt(void)
Bo Shenc5e88852013-11-15 11:12:38 +080019{
20 struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
21
22 writel(AT91_WDT_MR_WDDIS, &wdt->mr);
23}
Heiko Schocher49b461f2015-01-21 08:38:20 +010024#endif
Bo Shenc5e88852013-11-15 11:12:38 +080025
Marek Vasut1c24f132016-05-14 23:43:01 +020026#if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \
27 defined(CONFIG_SAMA5D4)
28#include <asm/arch/sama5_boot.h>
Marek Vasutbb0c63a2016-04-22 21:56:21 +020029struct {
30 u32 r4;
31} bootrom_stash __attribute__((section(".data")));
32
33u32 spl_boot_device(void)
34{
Marek Vasut1c24f132016-05-14 23:43:01 +020035 u32 dev = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_FROM_OFF) &
36 ATMEL_SAMA5_BOOT_FROM_MASK;
37 u32 off = (bootrom_stash.r4 >> ATMEL_SAMA5_BOOT_DEV_ID_OFF) &
38 ATMEL_SAMA5_BOOT_DEV_ID_MASK;
Marek Vasutbb0c63a2016-04-22 21:56:21 +020039
40#if defined(CONFIG_SYS_USE_MMC)
Marek Vasut1c24f132016-05-14 23:43:01 +020041 if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
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();
48 }
49#endif
50
51#if defined(CONFIG_SYS_USE_SERIALFLASH) || defined(CONFIG_SYS_USE_SPIFLASH)
Marek Vasut1c24f132016-05-14 23:43:01 +020052 if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
Marek Vasutbb0c63a2016-04-22 21:56:21 +020053 return BOOT_DEVICE_SPI;
54#endif
55
Marek Vasut1c24f132016-05-14 23:43:01 +020056 if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
57 return BOOT_DEVICE_USB;
58
Marek Vasutbb0c63a2016-04-22 21:56:21 +020059 printf("ERROR: SMC/TWI/QSPI boot device not supported!\n"
60 " Boot device %i, controller number %i\n", dev, off);
61
62 return BOOT_DEVICE_NONE;
63}
64#else
Bo Shenc5e88852013-11-15 11:12:38 +080065u32 spl_boot_device(void)
66{
67#ifdef CONFIG_SYS_USE_MMC
68 return BOOT_DEVICE_MMC1;
Bo Shen27019e42014-03-03 14:47:17 +080069#elif CONFIG_SYS_USE_NANDFLASH
70 return BOOT_DEVICE_NAND;
Bo Shend85e8912015-03-27 14:23:35 +080071#elif CONFIG_SYS_USE_SERIALFLASH || CONFIG_SYS_USE_SPIFLASH
Bo Shen8a45b0b2014-03-03 14:47:15 +080072 return BOOT_DEVICE_SPI;
Bo Shenc5e88852013-11-15 11:12:38 +080073#endif
74 return BOOT_DEVICE_NONE;
75}
Marek Vasutbb0c63a2016-04-22 21:56:21 +020076#endif
Bo Shenc5e88852013-11-15 11:12:38 +080077
78u32 spl_boot_mode(void)
79{
80 switch (spl_boot_device()) {
81#ifdef CONFIG_SYS_USE_MMC
82 case BOOT_DEVICE_MMC1:
Marek Vasutbb0c63a2016-04-22 21:56:21 +020083 case BOOT_DEVICE_MMC2:
Guillaume GARDET205b4f32014-10-15 17:53:11 +020084 return MMCSD_MODE_FS;
Bo Shenc5e88852013-11-15 11:12:38 +080085 break;
86#endif
87 case BOOT_DEVICE_NONE:
88 default:
89 hang();
90 }
91}