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