blob: 0e7fa1e333e4191645eeed951c71358ff4648b9b [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>
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <command.h>
Dirk Eibach8fc40842019-03-29 10:18:19 +010010#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>
Simon Glass458b66a2020-11-05 06:32:05 -070017#include <sysinfo.h>
Dirk Eibach8fc40842019-03-29 10:18:19 +010018#include <tpm-v1.h>
19#include <video_osd.h>
20
21#include "../common/ihs_mdio.h"
Simon Glass458b66a2020-11-05 06:32:05 -070022#include "../../../drivers/sysinfo/gazerbeam.h"
Dirk Eibach8fc40842019-03-29 10:18:19 +010023
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{
Simon Glass458b66a2020-11-05 06:32:05 -070046 struct udevice *sysinfo;
Dirk Eibach8fc40842019-03-29 10:18:19 +010047 struct udevice *serdes;
48 int mc = 0;
49 int con = 0;
50
Simon Glass458b66a2020-11-05 06:32:05 -070051 if (sysinfo_get(&sysinfo))
52 puts("Could not find sysinfo information device.\n");
Dirk Eibach8fc40842019-03-29 10:18:19 +010053
54 /* Initialize serdes */
Simon Glass458b66a2020-11-05 06:32:05 -070055 uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, "serdes", &serdes);
Dirk Eibach8fc40842019-03-29 10:18:19 +010056
Simon Glass458b66a2020-11-05 06:32:05 -070057 if (sysinfo_detect(sysinfo))
Dirk Eibach8fc40842019-03-29 10:18:19 +010058 puts("Device information detection failed.\n");
59
Simon Glass458b66a2020-11-05 06:32:05 -070060 sysinfo_get_int(sysinfo, BOARD_MULTICHANNEL, &mc);
61 sysinfo_get_int(sysinfo, BOARD_VARIANT, &con);
Dirk Eibach8fc40842019-03-29 10:18:19 +010062
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
Simon Glass458b66a2020-11-05 06:32:05 -070087int checksysinfo(void)
Dirk Eibach8fc40842019-03-29 10:18:19 +010088{
Simon Glass458b66a2020-11-05 06:32:05 -070089 struct udevice *sysinfo;
Dirk Eibach8fc40842019-03-29 10:18:19 +010090 char *s = env_get("serial#");
91 int mc = 0;
92 int con = 0;
93
Simon Glass458b66a2020-11-05 06:32:05 -070094 if (sysinfo_get(&sysinfo))
95 puts("Could not find sysinfo information device.\n");
Dirk Eibach8fc40842019-03-29 10:18:19 +010096
Simon Glass458b66a2020-11-05 06:32:05 -070097 sysinfo_get_int(sysinfo, BOARD_MULTICHANNEL, &mc);
98 sysinfo_get_int(sysinfo, BOARD_VARIANT, &con);
Dirk Eibach8fc40842019-03-29 10:18:19 +010099
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;
Simon Glass458b66a2020-11-05 06:32:05 -0700126 struct udevice *sysinfo;
Dirk Eibach8fc40842019-03-29 10:18:19 +0100127 struct udevice *osd;
128 struct video_osd_info osd_info;
129 struct udevice *tpm;
130 int ret;
131
Simon Glass458b66a2020-11-05 06:32:05 -0700132 if (sysinfo_get(&sysinfo))
133 puts("Could not find sysinfo information device.\n");
Dirk Eibach8fc40842019-03-29 10:18:19 +0100134
Simon Glass458b66a2020-11-05 06:32:05 -0700135 if (sysinfo) {
136 int res = sysinfo_get_int(sysinfo, BOARD_HWVERSION,
137 &fpga_hw_rev);
Dirk Eibach8fc40842019-03-29 10:18:19 +0100138
139 if (res)
Simon Glass458b66a2020-11-05 06:32:05 -0700140 printf("Could not determind FPGA HW revision (res = %d)\n",
141 res);
Dirk Eibach8fc40842019-03-29 10:18:19 +0100142 }
143
144 env_set_ulong("fpga_hw_rev", fpga_hw_rev);
145
146 ret = get_tpm(&tpm);
147 if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
148 tpm_continue_self_test(tpm)) {
149 printf("TPM init failed\n");
150 }
151
152 if (fpga_hw_rev >= 4) {
153 for (i = 0; i < 4; i++) {
154 struct udevice *rxaui;
155 char name[8];
156
157 snprintf(name, sizeof(name), "rxaui%d", i);
158 /* Disable RXAUI polarity inversion */
Simon Glass458b66a2020-11-05 06:32:05 -0700159 ret = uclass_get_device_by_phandle(UCLASS_MISC, sysinfo,
160 name, &rxaui);
Dirk Eibach8fc40842019-03-29 10:18:19 +0100161 if (!ret)
162 misc_set_enabled(rxaui, false);
163 }
164 }
165
166 for (uclass_first_device(UCLASS_VIDEO_OSD, &osd);
167 osd;
168 uclass_next_device(&osd)) {
169 video_osd_get_info(osd, &osd_info);
170 display_osd_info(osd, &osd_info);
171 }
172
173 return 0;
174}
175
176#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900177int ft_board_setup(void *blob, struct bd_info *bd)
Dirk Eibach8fc40842019-03-29 10:18:19 +0100178{
179 ft_cpu_setup(blob, bd);
180 fsl_fdt_fixup_dr_usb(blob, bd);
181 fdt_fixup_esdhc(blob, bd);
182
183 return 0;
184}
185#endif