Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 1 | /* |
| 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 Shen | f92b298 | 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 | |
Heiko Schocher | 62e6137 | 2015-01-21 08:38:20 +0100 | [diff] [blame] | 15 | #if defined(CONFIG_AT91SAM9_WATCHDOG) |
| 16 | void at91_disable_wdt(void) { } |
| 17 | #else |
Heiko Schocher | f1e3a8c | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 18 | void at91_disable_wdt(void) |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 19 | { |
| 20 | struct at91_wdt *wdt = (struct at91_wdt *)ATMEL_BASE_WDT; |
| 21 | |
| 22 | writel(AT91_WDT_MR_WDDIS, &wdt->mr); |
| 23 | } |
Heiko Schocher | 62e6137 | 2015-01-21 08:38:20 +0100 | [diff] [blame] | 24 | #endif |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 25 | |
Marek Vasut | f5e7513 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 26 | #if defined(CONFIG_SAMA5D2) || defined(CONFIG_SAMA5D3) || \ |
| 27 | defined(CONFIG_SAMA5D4) |
| 28 | #include <asm/arch/sama5_boot.h> |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 29 | struct { |
| 30 | u32 r4; |
| 31 | } bootrom_stash __attribute__((section(".data"))); |
| 32 | |
| 33 | u32 spl_boot_device(void) |
| 34 | { |
Marek Vasut | f5e7513 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 35 | 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 Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 39 | |
| 40 | #if defined(CONFIG_SYS_USE_MMC) |
Marek Vasut | f5e7513 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 41 | if (dev == ATMEL_SAMA5_BOOT_FROM_MCI) { |
Wenyou Yang | 71806ec | 2017-03-24 11:34:03 +0800 | [diff] [blame] | 42 | #if defined(CONFIG_SPL_OF_CONTROL) |
| 43 | return BOOT_DEVICE_MMC1; |
| 44 | #else |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 45 | 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 Yang | 71806ec | 2017-03-24 11:34:03 +0800 | [diff] [blame] | 51 | #endif |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 52 | } |
| 53 | #endif |
| 54 | |
| 55 | #if defined(CONFIG_SYS_USE_SERIALFLASH) || defined(CONFIG_SYS_USE_SPIFLASH) |
Marek Vasut | f5e7513 | 2016-05-14 23:43:01 +0200 | [diff] [blame] | 56 | if (dev == ATMEL_SAMA5_BOOT_FROM_SPI) |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 57 | return BOOT_DEVICE_SPI; |
| 58 | #endif |
Wenyou Yang | 0e97cad | 2017-09-13 14:58:51 +0800 | [diff] [blame^] | 59 | if (dev == ATMEL_SAMA5_BOOT_FROM_QSPI) |
| 60 | return BOOT_DEVICE_SPI; |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 61 | |
Wenyou Yang | 71806ec | 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 | f5e7513 | 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 | 4d88f1c | 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 | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 74 | u32 spl_boot_device(void) |
| 75 | { |
| 76 | #ifdef CONFIG_SYS_USE_MMC |
| 77 | return BOOT_DEVICE_MMC1; |
Bo Shen | 540c031 | 2014-03-03 14:47:17 +0800 | [diff] [blame] | 78 | #elif CONFIG_SYS_USE_NANDFLASH |
| 79 | return BOOT_DEVICE_NAND; |
Bo Shen | 9a3b1fe | 2015-03-27 14:23:35 +0800 | [diff] [blame] | 80 | #elif CONFIG_SYS_USE_SERIALFLASH || CONFIG_SYS_USE_SPIFLASH |
Bo Shen | 37a36b3 | 2014-03-03 14:47:15 +0800 | [diff] [blame] | 81 | return BOOT_DEVICE_SPI; |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 82 | #endif |
| 83 | return BOOT_DEVICE_NONE; |
| 84 | } |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 85 | #endif |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 86 | |
Marek Vasut | 64d64bb | 2016-05-14 23:42:07 +0200 | [diff] [blame] | 87 | u32 spl_boot_mode(const u32 boot_device) |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 88 | { |
Marek Vasut | 7723a34 | 2016-05-14 23:42:28 +0200 | [diff] [blame] | 89 | switch (boot_device) { |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 90 | #ifdef CONFIG_SYS_USE_MMC |
| 91 | case BOOT_DEVICE_MMC1: |
Marek Vasut | 4d88f1c | 2016-04-22 21:56:21 +0200 | [diff] [blame] | 92 | case BOOT_DEVICE_MMC2: |
Guillaume GARDET | 602a16c | 2014-10-15 17:53:11 +0200 | [diff] [blame] | 93 | return MMCSD_MODE_FS; |
Bo Shen | f92b298 | 2013-11-15 11:12:38 +0800 | [diff] [blame] | 94 | break; |
| 95 | #endif |
| 96 | case BOOT_DEVICE_NONE: |
| 97 | default: |
| 98 | hang(); |
| 99 | } |
| 100 | } |