blob: 8d537998c984fa858498117048fe05e5a9ae79f7 [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>
Simon Glassdb41d652019-12-28 10:45:07 -07008#include <hang.h>
Bo Shenc5e88852013-11-15 11:12:38 +08009#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
Prasanthi Chellakumar1473f6a2018-10-09 11:46:40 -070015#if !defined(CONFIG_WDT_AT91)
Heiko Schocher5abc00d2014-10-31 08:31:04 +010016void at91_disable_wdt(void)
Bo Shenc5e88852013-11-15 11:12:38 +080017{
18 struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT;
19
20 writel(AT91_WDT_MR_WDDIS, &wdt->mr);
21}
Heiko Schocher49b461f2015-01-21 08:38:20 +010022#endif
Bo Shenc5e88852013-11-15 11:12:38 +080023
Marek Vasut1c24f132016-05-14 23:43:01 +020024#if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \
25 defined(CONFIG_SAMA5D4)
26#include <asm/arch/sama5_boot.h>
Marek Vasutbb0c63a2016-04-22 21:56:21 +020027struct {
28 u32 r4;
Marek BehĂșn236f2ec2021-05-20 13:23:52 +020029} bootrom_stash __section(".data");
Marek Vasutbb0c63a2016-04-22 21:56:21 +020030
31u32 spl_boot_device(void)
32{
Marek Vasut1c24f132016-05-14 23:43:01 +020033 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;
Marek Vasutbb0c63a2016-04-22 21:56:21 +020037
Wenyou Yanga35c3402017-09-14 11:07:43 +080038#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Marek Vasut1c24f132016-05-14 23:43:01 +020039 if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) {
Wenyou Yangc00d7c32017-03-24 11:34:03 +080040#if defined(CONFIG_SPL_OF_CONTROL)
41 return BOOT_DEVICE_MMC1;
42#else
Marek Vasutbb0c63a2016-04-22 21:56:21 +020043 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();
Wenyou Yangc00d7c32017-03-24 11:34:03 +080049#endif
Marek Vasutbb0c63a2016-04-22 21:56:21 +020050 }
51#endif
52
Wenyou Yanga35c3402017-09-14 11:07:43 +080053#if defined(CONFIG_SYS_USE_SERIALFLASH) || \
54 defined(CONFIG_SYS_USE_SPIFLASH) || \
55 defined(CONFIG_SPI_BOOT)
Marek Vasut1c24f132016-05-14 23:43:01 +020056 if (dev == ATMEL_SAMA5_BOOT_FROM_SPI)
Marek Vasutbb0c63a2016-04-22 21:56:21 +020057 return BOOT_DEVICE_SPI;
58#endif
Wenyou Yangdfd6d3a2017-09-13 14:58:51 +080059 if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI)
60 return BOOT_DEVICE_SPI;
Marek Vasutbb0c63a2016-04-22 21:56:21 +020061
Wenyou Yangc00d7c32017-03-24 11:34:03 +080062 if (dev == ATMEL_SAMA5_BOOT_FROM_SMC)
63 return BOOT_DEVICE_NAND;
64
Marek Vasut1c24f132016-05-14 23:43:01 +020065 if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA)
66 return BOOT_DEVICE_USB;
67
Marek Vasutbb0c63a2016-04-22 21:56:21 +020068 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
Bo Shenc5e88852013-11-15 11:12:38 +080074u32 spl_boot_device(void)
75{
Wenyou Yanga35c3402017-09-14 11:07:43 +080076#if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT)
Bo Shenc5e88852013-11-15 11:12:38 +080077 return BOOT_DEVICE_MMC1;
Wenyou Yanga35c3402017-09-14 11:07:43 +080078#elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT)
Bo Shen27019e42014-03-03 14:47:17 +080079 return BOOT_DEVICE_NAND;
Wenyou Yanga35c3402017-09-14 11:07:43 +080080#elif defined(CONFIG_SYS_USE_SERIALFLASH) || \
81 defined(CONFIG_SYS_USE_SPIFLASH) || \
82 defined(CONFIG_SPI_BOOT)
Bo Shen8a45b0b2014-03-03 14:47:15 +080083 return BOOT_DEVICE_SPI;
Bo Shenc5e88852013-11-15 11:12:38 +080084#endif
85 return BOOT_DEVICE_NONE;
86}
Marek Vasutbb0c63a2016-04-22 21:56:21 +020087#endif