Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2015 |
| 3 | * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <command.h> |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | 168068f | 2019-08-01 09:46:47 -0600 | [diff] [blame] | 11 | #include <env.h> |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 12 | #include <fdt_support.h> |
| 13 | #include <fsl_esdhc.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 15 | #include <miiphy.h> |
| 16 | #include <misc.h> |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 17 | #include <sysinfo.h> |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 18 | #include <tpm-v1.h> |
| 19 | #include <video_osd.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 21 | |
| 22 | #include "../common/ihs_mdio.h" |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 23 | #include "../../../drivers/sysinfo/gazerbeam.h" |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | struct ihs_mdio_info ihs_mdio_info[] = { |
| 28 | { .fpga = NULL, .name = "ihs0", .base = 0x58 }, |
| 29 | { .fpga = NULL, .name = "ihs1", .base = 0x58 }, |
| 30 | }; |
| 31 | |
| 32 | static int get_tpm(struct udevice **devp) |
| 33 | { |
| 34 | int rc; |
| 35 | |
| 36 | rc = uclass_first_device_err(UCLASS_TPM, devp); |
| 37 | if (rc) { |
| 38 | printf("Could not find TPM (ret=%d)\n", rc); |
| 39 | return CMD_RET_FAILURE; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | int board_early_init_r(void) |
| 46 | { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 47 | struct udevice *sysinfo; |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 48 | struct udevice *serdes; |
| 49 | int mc = 0; |
| 50 | int con = 0; |
| 51 | |
Michal Suchanek | 7b2aa21 | 2022-10-12 21:58:04 +0200 | [diff] [blame] | 52 | if (sysinfo_get(&sysinfo)) { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 53 | puts("Could not find sysinfo information device.\n"); |
Michal Suchanek | 7b2aa21 | 2022-10-12 21:58:04 +0200 | [diff] [blame] | 54 | sysinfo = NULL; |
| 55 | } |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 56 | |
| 57 | /* Initialize serdes */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 58 | uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, "serdes", &serdes); |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 59 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 60 | if (sysinfo_detect(sysinfo)) |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 61 | puts("Device information detection failed.\n"); |
| 62 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 63 | sysinfo_get_int(sysinfo, BOARD_MULTICHANNEL, &mc); |
| 64 | sysinfo_get_int(sysinfo, BOARD_VARIANT, &con); |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 65 | |
| 66 | if (mc == 2 || mc == 1) |
| 67 | dev_disable_by_path("/immr@e0000000/i2c@3100/pca9698@22"); |
| 68 | |
| 69 | if (mc == 4) { |
| 70 | dev_disable_by_path("/immr@e0000000/i2c@3100/pca9698@20"); |
| 71 | dev_enable_by_path("/localbus@e0005000/iocon_uart@2,0"); |
| 72 | dev_enable_by_path("/fpga1bus"); |
| 73 | } |
| 74 | |
| 75 | if (mc == 2 || con == VAR_CON) { |
| 76 | dev_enable_by_path("/fpga0bus/fpga0_video1"); |
| 77 | dev_enable_by_path("/fpga0bus/fpga0_iic_video1"); |
| 78 | dev_enable_by_path("/fpga0bus/fpga0_axi_video1"); |
| 79 | } |
| 80 | |
| 81 | if (con == VAR_CON) { |
| 82 | dev_enable_by_path("/fpga0bus/fpga0_video0"); |
| 83 | dev_enable_by_path("/fpga0bus/fpga0_iic_video0"); |
| 84 | dev_enable_by_path("/fpga0bus/fpga0_axi_video0"); |
| 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 90 | int checksysinfo(void) |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 91 | { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 92 | struct udevice *sysinfo; |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 93 | char *s = env_get("serial#"); |
| 94 | int mc = 0; |
| 95 | int con = 0; |
| 96 | |
Michal Suchanek | 7b2aa21 | 2022-10-12 21:58:04 +0200 | [diff] [blame] | 97 | if (sysinfo_get(&sysinfo)) { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 98 | puts("Could not find sysinfo information device.\n"); |
Michal Suchanek | 7b2aa21 | 2022-10-12 21:58:04 +0200 | [diff] [blame] | 99 | sysinfo = NULL; |
| 100 | } |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 101 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 102 | sysinfo_get_int(sysinfo, BOARD_MULTICHANNEL, &mc); |
| 103 | sysinfo_get_int(sysinfo, BOARD_VARIANT, &con); |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 104 | |
| 105 | puts("Board: Gazerbeam "); |
| 106 | printf("%s ", mc == 4 ? "MC4" : mc == 2 ? "MC2" : "SC"); |
| 107 | printf("%s", con == VAR_CON ? "CON" : "CPU"); |
| 108 | |
| 109 | if (s) { |
| 110 | puts(", serial# "); |
| 111 | puts(s); |
| 112 | } |
| 113 | |
| 114 | puts("\n"); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static void display_osd_info(struct udevice *osd, |
| 120 | struct video_osd_info *osd_info) |
| 121 | { |
| 122 | printf("OSD-%s: Digital-OSD version %01d.%02d, %d x %d characters\n", |
| 123 | osd->name, osd_info->major_version, osd_info->minor_version, |
| 124 | osd_info->width, osd_info->height); |
| 125 | } |
| 126 | |
| 127 | int last_stage_init(void) |
| 128 | { |
| 129 | int fpga_hw_rev = 0; |
| 130 | int i; |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 131 | struct udevice *sysinfo; |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 132 | struct udevice *osd; |
| 133 | struct video_osd_info osd_info; |
| 134 | struct udevice *tpm; |
| 135 | int ret; |
| 136 | |
Michal Suchanek | 7b2aa21 | 2022-10-12 21:58:04 +0200 | [diff] [blame] | 137 | if (sysinfo_get(&sysinfo)) { |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 138 | puts("Could not find sysinfo information device.\n"); |
Michal Suchanek | 7b2aa21 | 2022-10-12 21:58:04 +0200 | [diff] [blame] | 139 | sysinfo = NULL; |
| 140 | } |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 141 | |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 142 | if (sysinfo) { |
| 143 | int res = sysinfo_get_int(sysinfo, BOARD_HWVERSION, |
| 144 | &fpga_hw_rev); |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 145 | |
| 146 | if (res) |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 147 | printf("Could not determind FPGA HW revision (res = %d)\n", |
| 148 | res); |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | env_set_ulong("fpga_hw_rev", fpga_hw_rev); |
| 152 | |
| 153 | ret = get_tpm(&tpm); |
Simon Glass | d6a885f | 2021-02-06 14:23:36 -0700 | [diff] [blame] | 154 | if (ret || tpm_init(tpm) || tpm1_startup(tpm, TPM_ST_CLEAR) || |
| 155 | tpm1_continue_self_test(tpm)) { |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 156 | printf("TPM init failed\n"); |
| 157 | } |
| 158 | |
| 159 | if (fpga_hw_rev >= 4) { |
| 160 | for (i = 0; i < 4; i++) { |
| 161 | struct udevice *rxaui; |
| 162 | char name[8]; |
| 163 | |
| 164 | snprintf(name, sizeof(name), "rxaui%d", i); |
| 165 | /* Disable RXAUI polarity inversion */ |
Simon Glass | 3a8ee3d | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 166 | ret = uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, |
| 167 | name, &rxaui); |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 168 | if (!ret) |
| 169 | misc_set_enabled(rxaui, false); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | for (uclass_first_device(UCLASS_VIDEO_OSD, &osd); |
| 174 | osd; |
| 175 | uclass_next_device(&osd)) { |
| 176 | video_osd_get_info(osd, &osd_info); |
| 177 | display_osd_info(osd, &osd_info); |
| 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 184 | int ft_board_setup(void *blob, struct bd_info *bd) |
Dirk Eibach | d494cdb | 2019-03-29 10:18:19 +0100 | [diff] [blame] | 185 | { |
| 186 | ft_cpu_setup(blob, bd); |
| 187 | fsl_fdt_fixup_dr_usb(blob, bd); |
| 188 | fdt_fixup_esdhc(blob, bd); |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | #endif |