Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * boot-common.c |
| 3 | * |
| 4 | * Common bootmode functions for omap based boards |
| 5 | * |
| 6 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 12 | #include <spl.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 13 | #include <asm/omap_common.h> |
| 14 | #include <asm/arch/omap.h> |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 15 | #include <asm/arch/mmc_host_def.h> |
Ilya Yanok | 1befaff | 2012-11-06 13:06:28 +0000 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 17 | #include <watchdog.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 18 | |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 20 | |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 21 | void save_omap_boot_params(void) |
| 22 | { |
| 23 | u32 rom_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS); |
| 24 | u8 boot_device; |
| 25 | u32 dev_desc, dev_data; |
| 26 | |
| 27 | if ((rom_params < NON_SECURE_SRAM_START) || |
| 28 | (rom_params > NON_SECURE_SRAM_END)) |
| 29 | return; |
| 30 | |
| 31 | /* |
| 32 | * rom_params can be type casted to omap_boot_parameters and |
| 33 | * used. But it not correct to assume that romcode structure |
| 34 | * encoding would be same as u-boot. So use the defined offsets. |
| 35 | */ |
| 36 | gd->arch.omap_boot_params.omap_bootdevice = boot_device = |
| 37 | *((u8 *)(rom_params + BOOT_DEVICE_OFFSET)); |
| 38 | |
| 39 | gd->arch.omap_boot_params.ch_flags = |
| 40 | *((u8 *)(rom_params + CH_FLAGS_OFFSET)); |
| 41 | |
| 42 | if ((boot_device >= MMC_BOOT_DEVICES_START) && |
| 43 | (boot_device <= MMC_BOOT_DEVICES_END)) { |
Lokesh Vutla | 5718040 | 2013-07-30 11:36:31 +0530 | [diff] [blame] | 44 | #if !defined(CONFIG_AM33XX) && !defined(CONFIG_TI81XX) && \ |
| 45 | !defined(CONFIG_AM43XX) |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 46 | if ((omap_hw_init_context() == |
| 47 | OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)) { |
| 48 | gd->arch.omap_boot_params.omap_bootmode = |
| 49 | *((u8 *)(rom_params + BOOT_MODE_OFFSET)); |
| 50 | } else |
| 51 | #endif |
| 52 | { |
| 53 | dev_desc = *((u32 *)(rom_params + DEV_DESC_PTR_OFFSET)); |
| 54 | dev_data = *((u32 *)(dev_desc + DEV_DATA_PTR_OFFSET)); |
| 55 | gd->arch.omap_boot_params.omap_bootmode = |
| 56 | *((u32 *)(dev_data + BOOT_MODE_OFFSET)); |
| 57 | } |
| 58 | } |
Tom Rini | 79b079f | 2014-04-03 07:52:56 -0400 | [diff] [blame] | 59 | |
| 60 | #ifdef CONFIG_DRA7XX |
| 61 | /* |
| 62 | * We get different values for QSPI_1 and QSPI_4 being used, but |
| 63 | * don't actually care about this difference. Rather than |
| 64 | * mangle the later code, if we're coming in as QSPI_4 just |
| 65 | * change to the QSPI_1 value. |
| 66 | */ |
| 67 | if (gd->arch.omap_boot_params.omap_bootdevice == 11) |
| 68 | gd->arch.omap_boot_params.omap_bootdevice = BOOT_DEVICE_SPI; |
| 69 | #endif |
Tom Rini | 4596dcc | 2013-05-31 12:31:59 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 72 | #ifdef CONFIG_SPL_BUILD |
Tom Rini | 8e1b836 | 2012-08-13 12:53:23 -0700 | [diff] [blame] | 73 | u32 spl_boot_device(void) |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 74 | { |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 75 | return (u32) (gd->arch.omap_boot_params.omap_bootdevice); |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Tom Rini | 37189a1 | 2012-08-14 09:19:44 -0700 | [diff] [blame] | 78 | u32 spl_boot_mode(void) |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 79 | { |
Tom Rini | 7dbe63b | 2014-02-05 10:24:18 -0500 | [diff] [blame] | 80 | u32 val = gd->arch.omap_boot_params.omap_bootmode; |
| 81 | |
| 82 | if (val == MMCSD_MODE_RAW) |
| 83 | return MMCSD_MODE_RAW; |
| 84 | else if (val == MMCSD_MODE_FAT) |
| 85 | return MMCSD_MODE_FAT; |
| 86 | else |
| 87 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 88 | return MMCSD_MODE_EMMCBOOT; |
| 89 | #else |
| 90 | return MMCSD_MODE_UNDEFINED; |
| 91 | #endif |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 92 | } |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 93 | |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 94 | void spl_board_init(void) |
| 95 | { |
| 96 | #ifdef CONFIG_SPL_NAND_SUPPORT |
| 97 | gpmc_init(); |
| 98 | #endif |
Ilya Yanok | da07c21 | 2013-02-05 11:36:25 +0000 | [diff] [blame] | 99 | #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT) |
| 100 | arch_misc_init(); |
| 101 | #endif |
Tom Rini | 6843918 | 2013-10-01 12:32:04 -0400 | [diff] [blame] | 102 | #if defined(CONFIG_HW_WATCHDOG) |
| 103 | hw_watchdog_init(); |
| 104 | #endif |
Tom Rini | 6a0d803 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 105 | #ifdef CONFIG_AM33XX |
| 106 | am33xx_spl_board_init(); |
| 107 | #endif |
Tom Rini | d7cb93b | 2012-08-14 12:26:08 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 110 | int board_mmc_init(bd_t *bis) |
| 111 | { |
| 112 | switch (spl_boot_device()) { |
| 113 | case BOOT_DEVICE_MMC1: |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 114 | omap_mmc_init(0, 0, 0, -1, -1); |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 115 | break; |
| 116 | case BOOT_DEVICE_MMC2: |
| 117 | case BOOT_DEVICE_MMC2_2: |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 118 | omap_mmc_init(1, 0, 0, -1, -1); |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 119 | break; |
| 120 | } |
| 121 | return 0; |
| 122 | } |
SRICHARAN R | 4a0eb75 | 2013-04-24 00:41:24 +0000 | [diff] [blame] | 123 | |
| 124 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 125 | { |
| 126 | typedef void __noreturn (*image_entry_noargs_t)(u32 *); |
| 127 | image_entry_noargs_t image_entry = |
| 128 | (image_entry_noargs_t) spl_image->entry_point; |
| 129 | |
| 130 | debug("image entry point: 0x%X\n", spl_image->entry_point); |
| 131 | /* Pass the saved boot_params from rom code */ |
| 132 | image_entry((u32 *)&gd->arch.omap_boot_params); |
| 133 | } |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 134 | #endif |