Dirk Eibach | 8fc4084 | 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> |
| 9 | #include <board.h> |
| 10 | #include <dm.h> |
| 11 | #include <fdt_support.h> |
| 12 | #include <fsl_esdhc.h> |
| 13 | #include <miiphy.h> |
| 14 | #include <misc.h> |
| 15 | #include <tpm-v1.h> |
| 16 | #include <video_osd.h> |
| 17 | |
| 18 | #include "../common/ihs_mdio.h" |
| 19 | #include "../../../drivers/board/gazerbeam.h" |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | struct ihs_mdio_info ihs_mdio_info[] = { |
| 24 | { .fpga = NULL, .name = "ihs0", .base = 0x58 }, |
| 25 | { .fpga = NULL, .name = "ihs1", .base = 0x58 }, |
| 26 | }; |
| 27 | |
| 28 | static int get_tpm(struct udevice **devp) |
| 29 | { |
| 30 | int rc; |
| 31 | |
| 32 | rc = uclass_first_device_err(UCLASS_TPM, devp); |
| 33 | if (rc) { |
| 34 | printf("Could not find TPM (ret=%d)\n", rc); |
| 35 | return CMD_RET_FAILURE; |
| 36 | } |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int board_early_init_r(void) |
| 42 | { |
| 43 | struct udevice *board; |
| 44 | struct udevice *serdes; |
| 45 | int mc = 0; |
| 46 | int con = 0; |
| 47 | |
| 48 | if (board_get(&board)) |
| 49 | puts("Could not find board information device.\n"); |
| 50 | |
| 51 | /* Initialize serdes */ |
| 52 | uclass_get_device_by_phandle(UCLASS_MISC, board, "serdes", &serdes); |
| 53 | |
| 54 | if (board_detect(board)) |
| 55 | puts("Device information detection failed.\n"); |
| 56 | |
| 57 | board_get_int(board, BOARD_MULTICHANNEL, &mc); |
| 58 | board_get_int(board, BOARD_VARIANT, &con); |
| 59 | |
| 60 | if (mc == 2 || mc == 1) |
| 61 | dev_disable_by_path("/immr@e0000000/i2c@3100/pca9698@22"); |
| 62 | |
| 63 | if (mc == 4) { |
| 64 | dev_disable_by_path("/immr@e0000000/i2c@3100/pca9698@20"); |
| 65 | dev_enable_by_path("/localbus@e0005000/iocon_uart@2,0"); |
| 66 | dev_enable_by_path("/fpga1bus"); |
| 67 | } |
| 68 | |
| 69 | if (mc == 2 || con == VAR_CON) { |
| 70 | dev_enable_by_path("/fpga0bus/fpga0_video1"); |
| 71 | dev_enable_by_path("/fpga0bus/fpga0_iic_video1"); |
| 72 | dev_enable_by_path("/fpga0bus/fpga0_axi_video1"); |
| 73 | } |
| 74 | |
| 75 | if (con == VAR_CON) { |
| 76 | dev_enable_by_path("/fpga0bus/fpga0_video0"); |
| 77 | dev_enable_by_path("/fpga0bus/fpga0_iic_video0"); |
| 78 | dev_enable_by_path("/fpga0bus/fpga0_axi_video0"); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | int checkboard(void) |
| 85 | { |
| 86 | struct udevice *board; |
| 87 | char *s = env_get("serial#"); |
| 88 | int mc = 0; |
| 89 | int con = 0; |
| 90 | |
| 91 | if (board_get(&board)) |
| 92 | puts("Could not find board information device.\n"); |
| 93 | |
| 94 | board_get_int(board, BOARD_MULTICHANNEL, &mc); |
| 95 | board_get_int(board, BOARD_VARIANT, &con); |
| 96 | |
| 97 | puts("Board: Gazerbeam "); |
| 98 | printf("%s ", mc == 4 ? "MC4" : mc == 2 ? "MC2" : "SC"); |
| 99 | printf("%s", con == VAR_CON ? "CON" : "CPU"); |
| 100 | |
| 101 | if (s) { |
| 102 | puts(", serial# "); |
| 103 | puts(s); |
| 104 | } |
| 105 | |
| 106 | puts("\n"); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static void display_osd_info(struct udevice *osd, |
| 112 | struct video_osd_info *osd_info) |
| 113 | { |
| 114 | printf("OSD-%s: Digital-OSD version %01d.%02d, %d x %d characters\n", |
| 115 | osd->name, osd_info->major_version, osd_info->minor_version, |
| 116 | osd_info->width, osd_info->height); |
| 117 | } |
| 118 | |
| 119 | int last_stage_init(void) |
| 120 | { |
| 121 | int fpga_hw_rev = 0; |
| 122 | int i; |
| 123 | struct udevice *board; |
| 124 | struct udevice *osd; |
| 125 | struct video_osd_info osd_info; |
| 126 | struct udevice *tpm; |
| 127 | int ret; |
| 128 | |
| 129 | if (board_get(&board)) |
| 130 | puts("Could not find board information device.\n"); |
| 131 | |
| 132 | if (board) { |
| 133 | int res = board_get_int(board, BOARD_HWVERSION, &fpga_hw_rev); |
| 134 | |
| 135 | if (res) |
| 136 | printf("Could not determind FPGA HW revision (res = %d)\n", res); |
| 137 | } |
| 138 | |
| 139 | env_set_ulong("fpga_hw_rev", fpga_hw_rev); |
| 140 | |
| 141 | ret = get_tpm(&tpm); |
| 142 | if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) || |
| 143 | tpm_continue_self_test(tpm)) { |
| 144 | printf("TPM init failed\n"); |
| 145 | } |
| 146 | |
| 147 | if (fpga_hw_rev >= 4) { |
| 148 | for (i = 0; i < 4; i++) { |
| 149 | struct udevice *rxaui; |
| 150 | char name[8]; |
| 151 | |
| 152 | snprintf(name, sizeof(name), "rxaui%d", i); |
| 153 | /* Disable RXAUI polarity inversion */ |
| 154 | ret = uclass_get_device_by_phandle(UCLASS_MISC, board, name, &rxaui); |
| 155 | if (!ret) |
| 156 | misc_set_enabled(rxaui, false); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | for (uclass_first_device(UCLASS_VIDEO_OSD, &osd); |
| 161 | osd; |
| 162 | uclass_next_device(&osd)) { |
| 163 | video_osd_get_info(osd, &osd_info); |
| 164 | display_osd_info(osd, &osd_info); |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 171 | int ft_board_setup(void *blob, bd_t *bd) |
| 172 | { |
| 173 | ft_cpu_setup(blob, bd); |
| 174 | fsl_fdt_fixup_dr_usb(blob, bd); |
| 175 | fdt_fixup_esdhc(blob, bd); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | #endif |