Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com> |
| 4 | */ |
| 5 | |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 6 | #include <cpu_func.h> |
Roman Kovalivskyi | 1bb1342 | 2020-07-28 23:35:32 +0300 | [diff] [blame] | 7 | #include <fastboot.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Neil Armstrong | 2fbfcbb | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 10 | #include <asm/arch/boot.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 14 | #include <asm/ptrace.h> |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <asm/arch/mem.h> |
| 18 | #include <asm/arch/sm.h> |
| 19 | #include <asm/armv8/mmu.h> |
| 20 | #include <asm/unaligned.h> |
| 21 | #include <efi_loader.h> |
Simon Glass | 48b6c6b | 2019-11-14 12:57:16 -0700 | [diff] [blame] | 22 | #include <u-boot/crc.h> |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 23 | |
Neil Armstrong | 1a5ed9c | 2019-05-22 13:30:25 +0200 | [diff] [blame] | 24 | #include <asm/psci.h> |
Neil Armstrong | 1a5ed9c | 2019-05-22 13:30:25 +0200 | [diff] [blame] | 25 | |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Jerome Brunet | 5c6fa8e | 2018-10-24 14:57:54 +0200 | [diff] [blame] | 28 | __weak int board_init(void) |
| 29 | { |
| 30 | return 0; |
| 31 | } |
| 32 | |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 33 | int dram_init(void) |
| 34 | { |
| 35 | const fdt64_t *val; |
| 36 | int offset; |
| 37 | int len; |
| 38 | |
| 39 | offset = fdt_path_offset(gd->fdt_blob, "/memory"); |
| 40 | if (offset < 0) |
| 41 | return -EINVAL; |
| 42 | |
| 43 | val = fdt_getprop(gd->fdt_blob, offset, "reg", &len); |
| 44 | if (len < sizeof(*val) * 2) |
| 45 | return -EINVAL; |
| 46 | |
| 47 | /* Use unaligned access since cache is still disabled */ |
| 48 | gd->ram_size = get_unaligned_be64(&val[1]); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 53 | __weak int meson_ft_board_setup(void *blob, struct bd_info *bd) |
Jerome Brunet | 5c6fa8e | 2018-10-24 14:57:54 +0200 | [diff] [blame] | 54 | { |
| 55 | return 0; |
| 56 | } |
| 57 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 58 | int ft_board_setup(void *blob, struct bd_info *bd) |
Jerome Brunet | 5c6fa8e | 2018-10-24 14:57:54 +0200 | [diff] [blame] | 59 | { |
| 60 | meson_init_reserved_memory(blob); |
| 61 | |
| 62 | return meson_ft_board_setup(blob, bd); |
| 63 | } |
| 64 | |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 65 | void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size) |
| 66 | { |
| 67 | int ret; |
| 68 | |
| 69 | ret = fdt_add_mem_rsv(fdt, start, size); |
| 70 | if (ret) |
| 71 | printf("Could not reserve zone @ 0x%llx\n", start); |
| 72 | |
Michael Walle | 282d386 | 2020-05-17 12:29:19 +0200 | [diff] [blame] | 73 | if (IS_ENABLED(CONFIG_EFI_LOADER)) |
| 74 | efi_add_memory_map(start, size, EFI_RESERVED_MEMORY_TYPE); |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Neil Armstrong | b4acf5a | 2019-06-12 11:49:07 +0200 | [diff] [blame] | 77 | int meson_generate_serial_ethaddr(void) |
| 78 | { |
| 79 | u8 mac_addr[ARP_HLEN]; |
| 80 | char serial[SM_SERIAL_SIZE]; |
| 81 | u32 sid; |
| 82 | u16 sid16; |
| 83 | |
| 84 | if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) { |
| 85 | sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE); |
| 86 | sid16 = crc16_ccitt(0, (unsigned char *)serial, SM_SERIAL_SIZE); |
| 87 | |
| 88 | /* Ensure the NIC specific bytes of the mac are not all 0 */ |
| 89 | if ((sid & 0xffffff) == 0) |
| 90 | sid |= 0x800000; |
| 91 | |
| 92 | /* Non OUI / registered MAC address */ |
| 93 | mac_addr[0] = ((sid16 >> 8) & 0xfc) | 0x02; |
| 94 | mac_addr[1] = (sid16 >> 0) & 0xff; |
| 95 | mac_addr[2] = (sid >> 24) & 0xff; |
| 96 | mac_addr[3] = (sid >> 16) & 0xff; |
| 97 | mac_addr[4] = (sid >> 8) & 0xff; |
| 98 | mac_addr[5] = (sid >> 0) & 0xff; |
| 99 | |
| 100 | eth_env_set_enetaddr("ethaddr", mac_addr); |
| 101 | } else |
| 102 | return -EINVAL; |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Neil Armstrong | 2fbfcbb | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 107 | static void meson_set_boot_source(void) |
| 108 | { |
| 109 | const char *source; |
| 110 | |
| 111 | switch (meson_get_boot_device()) { |
| 112 | case BOOT_DEVICE_EMMC: |
| 113 | source = "emmc"; |
| 114 | break; |
| 115 | |
| 116 | case BOOT_DEVICE_NAND: |
| 117 | source = "nand"; |
| 118 | break; |
| 119 | |
| 120 | case BOOT_DEVICE_SPI: |
| 121 | source = "spi"; |
| 122 | break; |
| 123 | |
| 124 | case BOOT_DEVICE_SD: |
| 125 | source = "sd"; |
| 126 | break; |
| 127 | |
| 128 | case BOOT_DEVICE_USB: |
| 129 | source = "usb"; |
| 130 | break; |
| 131 | |
| 132 | default: |
| 133 | source = "unknown"; |
| 134 | } |
| 135 | |
| 136 | env_set("boot_source", source); |
| 137 | } |
| 138 | |
| 139 | __weak int meson_board_late_init(void) |
| 140 | { |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | int board_late_init(void) |
| 145 | { |
| 146 | meson_set_boot_source(); |
| 147 | |
| 148 | return meson_board_late_init(); |
| 149 | } |
| 150 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 151 | void reset_cpu(void) |
Neil Armstrong | 1a5ed9c | 2019-05-22 13:30:25 +0200 | [diff] [blame] | 152 | { |
Jerome Brunet | f897c4b | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 153 | psci_system_reset(); |
| 154 | } |