blob: 8bfb2a452b5e89b898697df2d1f9ee1600bcf558 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bo Shenf92b2982013-11-15 11:12:38 +08002/*
3 * Copyright (C) 2013 Atmel Corporation
4 * Bo Shen <voice.shen@atmel.com>
Bo Shenf92b2982013-11-15 11:12:38 +08005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/at91_common.h>
Bo Shenf92b2982013-11-15 11:12:38 +080010#include <asm/arch/at91_wdt.h>
11#include <asm/arch/clk.h>
12#include <spl.h>
13
Tom Rini4a2b61b2018-05-10 07:15:52 -040014#if !defined(CONFIG_AT91SAM9_WATCHDOG)
Heiko Schocherf1e3a8c2014-10-31 08:31:04 +010015void at91_disable_wdt(void)
Bo Shenf92b2982013-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 Schocher62e61372015-01-21 08:38:20 +010021#endif
Bo Shenf92b2982013-11-15 11:12:38 +080022
Marek Vasutf5e75132016-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 Vasut4d88f1c2016-04-22 21:56:21 +020026struct {
27 u32 r4;
28} bootrom_stash __attribute__((section(".data")));
29
30u32 spl_boot_device(void)
31{
Marek Vasutf5e75132016-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 Vasut4d88f1c2016-04-22 21:56:21 +020036
Wenyou Yang5561f6f2017-09-14 11:07:43 +080037#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Marek Vasutf5e75132016-05-14 23:43:01 +020038 if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
Wenyou Yang71806ec2017-03-24 11:34:03 +080039#if defined(CONFIG_SPL_OF_CONTROL)
40 return BOOT_DEVICE_MMC1;
41#else
Marek Vasut4d88f1c2016-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 Yang71806ec2017-03-24 11:34:03 +080048#endif
Marek Vasut4d88f1c2016-04-22 21:56:21 +020049 }
50#endif
51
Wenyou Yang5561f6f2017-09-14 11:07:43 +080052#if defined(CONFIG_SYS_USE_SERIALFLASH) || \
53 defined(CONFIG_SYS_USE_SPIFLASH) || \
54 defined(CONFIG_SPI_BOOT)
Marek Vasutf5e75132016-05-14 23:43:01 +020055 if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
Marek Vasut4d88f1c2016-04-22 21:56:21 +020056 return BOOT_DEVICE_SPI;
57#endif
Wenyou Yang0e97cad2017-09-13 14:58:51 +080058 if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI)
59 return BOOT_DEVICE_SPI;
Marek Vasut4d88f1c2016-04-22 21:56:21 +020060
Wenyou Yang71806ec2017-03-24 11:34:03 +080061 if (dev == ATMEL_SAMA5_BOOT_FROM_SMC)
62 return BOOT_DEVICE_NAND;
63
Marek Vasutf5e75132016-05-14 23:43:01 +020064 if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
65 return BOOT_DEVICE_USB;
66
Marek Vasut4d88f1c2016-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 Shenf92b2982013-11-15 11:12:38 +080073u32 spl_boot_device(void)
74{
Wenyou Yang5561f6f2017-09-14 11:07:43 +080075#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Bo Shenf92b2982013-11-15 11:12:38 +080076 return BOOT_DEVICE_MMC1;
Wenyou Yang5561f6f2017-09-14 11:07:43 +080077#elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT)
Bo Shen540c0312014-03-03 14:47:17 +080078 return BOOT_DEVICE_NAND;
Wenyou Yang5561f6f2017-09-14 11:07:43 +080079#elif defined(CONFIG_SYS_USE_SERIALFLASH) || \
80 defined(CONFIG_SYS_USE_SPIFLASH) || \
81 defined(CONFIG_SPI_BOOT)
Bo Shen37a36b32014-03-03 14:47:15 +080082 return BOOT_DEVICE_SPI;
Bo Shenf92b2982013-11-15 11:12:38 +080083#endif
84 return BOOT_DEVICE_NONE;
85}
Marek Vasut4d88f1c2016-04-22 21:56:21 +020086#endif