David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Board specific initialization for J721S2 EVM |
| 4 | * |
| 5 | * Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * David Huang <d-huang@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <env.h> |
| 12 | #include <fdt_support.h> |
| 13 | #include <generic-phy.h> |
| 14 | #include <image.h> |
| 15 | #include <init.h> |
| 16 | #include <log.h> |
| 17 | #include <net.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/arch/hardware.h> |
| 20 | #include <asm/gpio.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <spl.h> |
| 23 | #include <asm/arch/sys_proto.h> |
| 24 | #include <dm.h> |
| 25 | #include <dm/uclass-internal.h> |
| 26 | |
| 27 | #include "../common/board_detect.h" |
| 28 | |
| 29 | #define board_is_j721s2_som() board_ti_k3_is("J721S2X-PM1-SOM") |
| 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | int board_init(void) |
| 34 | { |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | int dram_init(void) |
| 39 | { |
| 40 | #ifdef CONFIG_PHYS_64BIT |
| 41 | gd->ram_size = 0x100000000; |
| 42 | #else |
| 43 | gd->ram_size = 0x80000000; |
| 44 | #endif |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | ulong board_get_usable_ram_top(ulong total_size) |
| 50 | { |
| 51 | #ifdef CONFIG_PHYS_64BIT |
| 52 | /* Limit RAM used by U-Boot to the DDR low region */ |
| 53 | if (gd->ram_top > 0x100000000) |
| 54 | return 0x100000000; |
| 55 | #endif |
| 56 | |
| 57 | return gd->ram_top; |
| 58 | } |
| 59 | |
| 60 | int dram_init_banksize(void) |
| 61 | { |
| 62 | /* Bank 0 declares the memory available in the DDR low region */ |
| 63 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 64 | gd->bd->bi_dram[0].size = 0x7fffffff; |
| 65 | gd->ram_size = 0x80000000; |
| 66 | |
| 67 | #ifdef CONFIG_PHYS_64BIT |
| 68 | /* Bank 1 declares the memory available in the DDR high region */ |
| 69 | gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1; |
| 70 | gd->bd->bi_dram[1].size = 0x37fffffff; |
| 71 | gd->ram_size = 0x400000000; |
| 72 | #endif |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | #ifdef CONFIG_SPL_LOAD_FIT |
| 78 | int board_fit_config_name_match(const char *name) |
| 79 | { |
| 80 | if (!strcmp(name, "k3-j721s2-common-proc-board")) |
| 81 | return 0; |
| 82 | |
| 83 | return -1; |
| 84 | } |
| 85 | #endif |
| 86 | |
| 87 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 88 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 89 | { |
| 90 | int ret; |
| 91 | |
| 92 | ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000"); |
| 93 | if (ret < 0) |
| 94 | ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", |
| 95 | "sram@70000000"); |
| 96 | if (ret) |
| 97 | printf("%s: fixing up msmc ram failed %d\n", __func__, ret); |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | #ifdef CONFIG_TI_I2C_BOARD_DETECT |
| 104 | int do_board_detect(void) |
| 105 | { |
| 106 | int ret; |
| 107 | |
| 108 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 109 | CONFIG_EEPROM_CHIP_ADDRESS); |
| 110 | if (ret) |
| 111 | pr_err("Reading on-board EEPROM at 0x%02x failed %d\n", |
| 112 | CONFIG_EEPROM_CHIP_ADDRESS, ret); |
| 113 | |
| 114 | return ret; |
| 115 | } |
| 116 | |
| 117 | int checkboard(void) |
| 118 | { |
| 119 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 120 | |
| 121 | if (do_board_detect()) |
| 122 | /* EEPROM not populated */ |
| 123 | printf("Board: %s rev %s\n", "J721S2X-PM1-SOM", "E1"); |
| 124 | else |
| 125 | printf("Board: %s rev %s\n", ep->name, ep->version); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static void setup_board_eeprom_env(void) |
| 131 | { |
| 132 | char *name = "j721s2"; |
| 133 | |
| 134 | if (do_board_detect()) |
| 135 | goto invalid_eeprom; |
| 136 | |
| 137 | if (board_is_j721s2_som()) |
| 138 | name = "j721s2"; |
| 139 | else |
| 140 | printf("Unidentified board claims %s in eeprom header\n", |
| 141 | board_ti_get_name()); |
| 142 | |
| 143 | invalid_eeprom: |
| 144 | set_board_info_env_am6(name); |
| 145 | } |
| 146 | |
| 147 | static void setup_serial(void) |
| 148 | { |
| 149 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 150 | unsigned long board_serial; |
| 151 | char *endp; |
| 152 | char serial_string[17] = { 0 }; |
| 153 | |
| 154 | if (env_get("serial#")) |
| 155 | return; |
| 156 | |
| 157 | board_serial = simple_strtoul(ep->serial, &endp, 16); |
| 158 | if (*endp != '\0') { |
| 159 | pr_err("Error: Can't set serial# to %s\n", ep->serial); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial); |
| 164 | env_set("serial#", serial_string); |
| 165 | } |
| 166 | #endif |
| 167 | |
| 168 | int board_late_init(void) |
| 169 | { |
| 170 | if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
| 171 | setup_board_eeprom_env(); |
| 172 | setup_serial(); |
| 173 | } |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | void spl_board_init(void) |
| 179 | { |
| 180 | } |