blob: 7e7e24bbe69d038d195d89616357dc02976d8a40 [file] [log] [blame]
Bo Shenf92b2982013-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 Shenf92b2982013-11-15 11:12:38 +080011#include <asm/arch/at91_wdt.h>
12#include <asm/arch/clk.h>
13#include <spl.h>
14
Heiko Schocher62e61372015-01-21 08:38:20 +010015#if defined(CONFIG_AT91SAM9_WATCHDOG)
16void at91_disable_wdt(void) { }
17#else
Heiko Schocherf1e3a8c2014-10-31 08:31:04 +010018void at91_disable_wdt(void)
Bo Shenf92b2982013-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 Schocher62e61372015-01-21 08:38:20 +010024#endif
Bo Shenf92b2982013-11-15 11:12:38 +080025
Marek Vasutf5e75132016-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 Vasut4d88f1c2016-04-22 21:56:21 +020029struct {
30 u32 r4;
31} bootrom_stash __attribute__((section(".data")));
32
33u32 spl_boot_device(void)
34{
Marek Vasutf5e75132016-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 Vasut4d88f1c2016-04-22 21:56:21 +020039
Wenyou Yang5561f6f2017-09-14 11:07:43 +080040#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Marek Vasutf5e75132016-05-14 23:43:01 +020041 if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
Wenyou Yang71806ec2017-03-24 11:34:03 +080042#if defined(CONFIG_SPL_OF_CONTROL)
43 return BOOT_DEVICE_MMC1;
44#else
Marek Vasut4d88f1c2016-04-22 21:56:21 +020045 if (off == 0)
46 return BOOT_DEVICE_MMC1;
47 if (off == 1)
48 return BOOT_DEVICE_MMC2;
49 printf("ERROR: MMC controller %i not present!\n", dev);
50 hang();
Wenyou Yang71806ec2017-03-24 11:34:03 +080051#endif
Marek Vasut4d88f1c2016-04-22 21:56:21 +020052 }
53#endif
54
Wenyou Yang5561f6f2017-09-14 11:07:43 +080055#if defined(CONFIG_SYS_USE_SERIALFLASH) || \
56 defined(CONFIG_SYS_USE_SPIFLASH) || \
57 defined(CONFIG_SPI_BOOT)
Marek Vasutf5e75132016-05-14 23:43:01 +020058 if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
Marek Vasut4d88f1c2016-04-22 21:56:21 +020059 return BOOT_DEVICE_SPI;
60#endif
Wenyou Yang0e97cad2017-09-13 14:58:51 +080061 if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI)
62 return BOOT_DEVICE_SPI;
Marek Vasut4d88f1c2016-04-22 21:56:21 +020063
Wenyou Yang71806ec2017-03-24 11:34:03 +080064 if (dev == ATMEL_SAMA5_BOOT_FROM_SMC)
65 return BOOT_DEVICE_NAND;
66
Marek Vasutf5e75132016-05-14 23:43:01 +020067 if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
68 return BOOT_DEVICE_USB;
69
Marek Vasut4d88f1c2016-04-22 21:56:21 +020070 printf("ERROR: SMC/TWI/QSPI boot device not supported!\n"
71 " Boot device %i, controller number %i\n", dev, off);
72
73 return BOOT_DEVICE_NONE;
74}
75#else
Bo Shenf92b2982013-11-15 11:12:38 +080076u32 spl_boot_device(void)
77{
Wenyou Yang5561f6f2017-09-14 11:07:43 +080078#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Bo Shenf92b2982013-11-15 11:12:38 +080079 return BOOT_DEVICE_MMC1;
Wenyou Yang5561f6f2017-09-14 11:07:43 +080080#elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT)
Bo Shen540c0312014-03-03 14:47:17 +080081 return BOOT_DEVICE_NAND;
Wenyou Yang5561f6f2017-09-14 11:07:43 +080082#elif defined(CONFIG_SYS_USE_SERIALFLASH) || \
83 defined(CONFIG_SYS_USE_SPIFLASH) || \
84 defined(CONFIG_SPI_BOOT)
Bo Shen37a36b32014-03-03 14:47:15 +080085 return BOOT_DEVICE_SPI;
Bo Shenf92b2982013-11-15 11:12:38 +080086#endif
87 return BOOT_DEVICE_NONE;
88}
Marek Vasut4d88f1c2016-04-22 21:56:21 +020089#endif
Bo Shenf92b2982013-11-15 11:12:38 +080090
Marek Vasut64d64bb2016-05-14 23:42:07 +020091u32 spl_boot_mode(const u32 boot_device)
Bo Shenf92b2982013-11-15 11:12:38 +080092{
Marek Vasut7723a342016-05-14 23:42:28 +020093 switch (boot_device) {
Wenyou Yang5561f6f2017-09-14 11:07:43 +080094#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Bo Shenf92b2982013-11-15 11:12:38 +080095 case BOOT_DEVICE_MMC1:
Marek Vasut4d88f1c2016-04-22 21:56:21 +020096 case BOOT_DEVICE_MMC2:
Guillaume GARDET602a16c2014-10-15 17:53:11 +020097 return MMCSD_MODE_FS;
Bo Shenf92b2982013-11-15 11:12:38 +080098 break;
99#endif
100 case BOOT_DEVICE_NONE:
101 default:
102 hang();
103 }
104}