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