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