Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Atmel Corporation |
| 4 | * Bo Shen <voice.shen@atmel.com> |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/at91_common.h> |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 11 | #include <asm/arch/at91_wdt.h> |
| 12 | #include <asm/arch/clk.h> |
| 13 | #include <spl.h> |
| 14 | |
Prasanthi Chellakumar | 1473f6a | 2018-10-09 11:46:40 -0700 | [diff] [blame] | 15 | #if !defined(CONFIG_WDT_AT91) |
Heiko Schocher | 5abc00d | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 16 | void at91_disable_wdt(void) |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 17 | { |
| 18 | struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT; |
| 19 | |
| 20 | writel(AT91_WDT_MR_WDDIS, &wdt->mr); |
| 21 | } |
Heiko Schocher | 49b461f | 2015-01-21 08:38:20 +0100 | [diff] [blame] | 22 | #endif |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 23 | |
Marek Vasut | 1c24f13 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 24 | #if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \ |
| 25 | defined(CONFIG_SAMA5D4) |
| 26 | #include <asm/arch/sama5_boot.h> |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 27 | struct { |
| 28 | u32 r4; |
Marek BehĂșn | 236f2ec | 2021-05-20 13:23:52 +0200 | [diff] [blame] | 29 | } bootrom_stash __section(".data"); |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 30 | |
| 31 | u32 spl_boot_device(void) |
| 32 | { |
Marek Vasut | 1c24f13 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 33 | 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 Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 37 | |
Wenyou Yang | a35c340 | 2017-09-14 11:07:43 +0800 | [diff] [blame] | 38 | #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT) |
Marek Vasut | 1c24f13 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 39 | if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) { |
Wenyou Yang | c00d7c3 | 2017-03-24 11:34:03 +0800 | [diff] [blame] | 40 | #if defined(CONFIG_SPL_OF_CONTROL) |
| 41 | return BOOT_DEVICE_MMC1; |
| 42 | #else |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 43 | 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 Yang | c00d7c3 | 2017-03-24 11:34:03 +0800 | [diff] [blame] | 49 | #endif |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 50 | } |
| 51 | #endif |
| 52 | |
Wenyou Yang | a35c340 | 2017-09-14 11:07:43 +0800 | [diff] [blame] | 53 | #if defined(CONFIG_SYS_USE_SERIALFLASH) || \ |
| 54 | defined(CONFIG_SYS_USE_SPIFLASH) || \ |
| 55 | defined(CONFIG_SPI_BOOT) |
Marek Vasut | 1c24f13 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 56 | if (dev == ATMEL_SAMA5_BOOT_FROM_SPI) |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 57 | return BOOT_DEVICE_SPI; |
| 58 | #endif |
Wenyou Yang | dfd6d3a | 2017-09-13 14:58:51 +0800 | [diff] [blame] | 59 | if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI) |
| 60 | return BOOT_DEVICE_SPI; |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 61 | |
Wenyou Yang | c00d7c3 | 2017-03-24 11:34:03 +0800 | [diff] [blame] | 62 | if (dev == ATMEL_SAMA5_BOOT_FROM_SMC) |
| 63 | return BOOT_DEVICE_NAND; |
| 64 | |
Marek Vasut | 1c24f13 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 65 | if (dev == ATMEL_SAMA5_BOOT_FROM_SAMBA) |
| 66 | return BOOT_DEVICE_USB; |
| 67 | |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 68 | 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 Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 74 | u32 spl_boot_device(void) |
| 75 | { |
Wenyou Yang | a35c340 | 2017-09-14 11:07:43 +0800 | [diff] [blame] | 76 | #if defined(CONFIG_SYS_USE_MMC) || defined(CONFIG_SD_BOOT) |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 77 | return BOOT_DEVICE_MMC1; |
Wenyou Yang | a35c340 | 2017-09-14 11:07:43 +0800 | [diff] [blame] | 78 | #elif defined(CONFIG_SYS_USE_NANDFLASH) || defined(CONFIG_NAND_BOOT) |
Bo Shen | 27019e4 | 2014-03-03 14:47:17 +0800 | [diff] [blame] | 79 | return BOOT_DEVICE_NAND; |
Wenyou Yang | a35c340 | 2017-09-14 11:07:43 +0800 | [diff] [blame] | 80 | #elif defined(CONFIG_SYS_USE_SERIALFLASH) || \ |
| 81 | defined(CONFIG_SYS_USE_SPIFLASH) || \ |
| 82 | defined(CONFIG_SPI_BOOT) |
Bo Shen | 8a45b0b | 2014-03-03 14:47:15 +0800 | [diff] [blame] | 83 | return BOOT_DEVICE_SPI; |
Bo Shen | c5e8885 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 84 | #endif |
| 85 | return BOOT_DEVICE_NONE; |
| 86 | } |
Marek Vasut | bb0c63a | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 87 | #endif |