David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2013 |
| 3 | * David Feng <fenghua@phytium.com.cn> |
| 4 | * Sharma Bhupesh <bhupesh.sharma@freescale.com> |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | #include <common.h> |
| 9 | #include <malloc.h> |
| 10 | #include <errno.h> |
| 11 | #include <netdev.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <linux/compiler.h> |
Darwin Rambo | 261d276 | 2014-06-09 11:12:59 -0700 | [diff] [blame] | 14 | #include <asm/semihosting.h> |
David Feng | d8bafe13 | 2015-01-31 11:55:29 +0800 | [diff] [blame^] | 15 | #include <dm/platdata.h> |
| 16 | #include <dm/platform_data/serial_pl01x.h> |
David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
David Feng | d8bafe13 | 2015-01-31 11:55:29 +0800 | [diff] [blame^] | 20 | static const struct pl01x_serial_platdata serial_platdata = { |
| 21 | .base = V2M_UART0, |
| 22 | .type = TYPE_PL011, |
| 23 | .clock = 2400 * 1000, |
| 24 | }; |
| 25 | |
| 26 | U_BOOT_DEVICE(vexpress_serials) = { |
| 27 | .name = "serial_pl01x", |
| 28 | .platdata = &serial_platdata, |
| 29 | }; |
| 30 | |
David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 31 | int board_init(void) |
| 32 | { |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int dram_init(void) |
| 37 | { |
David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 38 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
| 39 | return 0; |
| 40 | } |
| 41 | |
David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 42 | /* |
| 43 | * Board specific reset that is system reset. |
| 44 | */ |
| 45 | void reset_cpu(ulong addr) |
| 46 | { |
| 47 | } |
| 48 | |
Darwin Rambo | 261d276 | 2014-06-09 11:12:59 -0700 | [diff] [blame] | 49 | #ifdef CONFIG_BOARD_LATE_INIT |
| 50 | int board_late_init(void) |
| 51 | { |
| 52 | #ifdef CONFIG_SEMIHOSTING |
| 53 | /* |
| 54 | * Please refer to doc/README.semihosting for a more complete |
| 55 | * description. |
| 56 | * |
| 57 | * We require that the board include file defines these env variables: |
| 58 | * - kernel_name |
| 59 | * - kernel_addr_r |
| 60 | * - initrd_name |
| 61 | * - initrd_addr_r |
| 62 | * - fdt_name |
| 63 | * - fdt_addr_r |
| 64 | * |
| 65 | * For the "fdt chosen" startup macro, this code will then define: |
| 66 | * - initrd_end (based on initrd_addr_r plus actual initrd_size) |
| 67 | * |
| 68 | * We will then load the kernel, initrd, and fdt into the specified |
| 69 | * locations in memory in a similar way that the ATF fastmodel code |
| 70 | * uses semihosting calls to load other boot stages and u-boot itself. |
| 71 | */ |
| 72 | |
| 73 | /* Env variable strings */ |
| 74 | char *kernel_name = getenv("kernel_name"); |
| 75 | char *kernel_addr_str = getenv("kernel_addr_r"); |
| 76 | char *initrd_name = getenv("initrd_name"); |
| 77 | char *initrd_addr_str = getenv("initrd_addr_r"); |
| 78 | char *fdt_name = getenv("fdt_name"); |
| 79 | char *fdt_addr_str = getenv("fdt_addr_r"); |
| 80 | char initrd_end_str[64]; |
| 81 | |
| 82 | /* Actual addresses converted from env variables */ |
| 83 | void *kernel_addr_r; |
| 84 | void *initrd_addr_r; |
| 85 | void *fdt_addr_r; |
| 86 | |
| 87 | /* Actual initrd base and size */ |
| 88 | unsigned long initrd_base; |
| 89 | unsigned long initrd_size; |
| 90 | |
| 91 | /* Space available */ |
| 92 | int avail; |
| 93 | |
| 94 | /* Make sure the environment variables needed are set */ |
| 95 | if (!(kernel_addr_str && initrd_addr_str && fdt_addr_str)) { |
| 96 | printf("%s: Define {kernel/initrd/fdt}_addr_r\n", __func__); |
| 97 | return -1; |
| 98 | } |
| 99 | if (!(kernel_name && initrd_name && fdt_name)) { |
| 100 | printf("%s: Define {kernel/initrd/fdt}_name\n", __func__); |
| 101 | return -1; |
| 102 | } |
| 103 | |
| 104 | /* Get exact initrd_size */ |
| 105 | initrd_size = smh_len(initrd_name); |
| 106 | if (initrd_size == -1) { |
| 107 | printf("%s: Can't get file size for \'%s\'\n", __func__, |
| 108 | initrd_name); |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | /* Set initrd_end */ |
| 113 | initrd_base = simple_strtoul(initrd_addr_str, NULL, 16); |
| 114 | initrd_addr_r = (void *)initrd_base; |
| 115 | sprintf(initrd_end_str, "0x%lx", initrd_base + initrd_size - 1); |
| 116 | setenv("initrd_end", initrd_end_str); |
| 117 | |
| 118 | /* Load kernel to memory */ |
| 119 | fdt_addr_r = (void *)simple_strtoul(fdt_addr_str, NULL, 16); |
| 120 | kernel_addr_r = (void *)simple_strtoul(kernel_addr_str, NULL, 16); |
| 121 | |
| 122 | /* |
| 123 | * The kernel must be lower in memory than fdt and loading the |
| 124 | * kernel must not trample the fdt or vice versa. |
| 125 | */ |
| 126 | avail = fdt_addr_r - kernel_addr_r; |
| 127 | if (avail < 0) { |
| 128 | printf("%s: fdt must be after kernel\n", __func__); |
| 129 | return -1; |
| 130 | } |
| 131 | smh_load(kernel_name, kernel_addr_r, avail, 1); |
| 132 | |
| 133 | /* Load fdt to memory */ |
| 134 | smh_load(fdt_name, fdt_addr_r, 0x20000, 1); |
| 135 | |
| 136 | /* Load initrd to memory */ |
| 137 | smh_load(initrd_name, initrd_addr_r, initrd_size, 1); |
| 138 | |
| 139 | #endif /* CONFIG_SEMIHOSTING */ |
| 140 | return 0; |
| 141 | } |
| 142 | #endif /* CONFIG_BOARD_LATE_INIT */ |
| 143 | |
David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 144 | /* |
| 145 | * Board specific ethernet initialization routine. |
| 146 | */ |
| 147 | int board_eth_init(bd_t *bis) |
| 148 | { |
| 149 | int rc = 0; |
| 150 | #ifdef CONFIG_SMC91111 |
| 151 | rc = smc91111_initialize(0, CONFIG_SMC91111_BASE); |
| 152 | #endif |
Linus Walleij | b31f9d7 | 2015-02-17 11:35:25 +0100 | [diff] [blame] | 153 | #ifdef CONFIG_SMC911X |
| 154 | rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 155 | #endif |
David Feng | 1291682 | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 156 | return rc; |
| 157 | } |