blob: 9db4553e0f7bbffa1411d7a75e46b761aad7f26c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marcel Ziswilera2777ec2016-11-16 17:49:22 +01002/*
3 * Copyright (c) 2016 Toradex, Inc.
Marcel Ziswilera2777ec2016-11-16 17:49:22 +01004 */
5
6#include <common.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06007#include <env.h>
Marcel Ziswilera2777ec2016-11-16 17:49:22 +01008#include <g_dnl.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010011
Igor Opaniukd3241892020-07-15 13:31:01 +030012#ifdef CONFIG_DM_VIDEO
13#include <bmp_logo.h>
14#include <dm.h>
15#include <splash.h>
16#include <video.h>
17#endif
18
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010019#include "tdx-cfg-block.h"
Simon Glass5d982852017-05-17 08:23:00 -060020#include <asm/setup.h>
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010021#include "tdx-common.h"
22
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +010023#define TORADEX_OUI 0x00142dUL
24
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010025#ifdef CONFIG_TDX_CFG_BLOCK
26static char tdx_serial_str[9];
27static char tdx_board_rev_str[6];
28
Igor Opaniuk717fa2c2020-07-15 13:30:57 +030029#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
30static char tdx_car_serial_str[9];
31static char tdx_car_rev_str[6];
32static char *tdx_carrier_board_name;
33#endif
34
Tom Rini97744622021-08-30 09:16:30 -040035#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
36u32 get_board_revision(void)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010037{
38 /* Check validity */
39 if (!tdx_hw_tag.ver_major)
40 return 0;
41
42 return ((tdx_hw_tag.ver_major & 0xff) << 8) |
43 ((tdx_hw_tag.ver_minor & 0xf) << 4) |
44 ((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
45}
46#endif /* CONFIG_TDX_CFG_BLOCK */
47
48#ifdef CONFIG_SERIAL_TAG
49void get_board_serial(struct tag_serialnr *serialnr)
50{
51 int array[8];
52 unsigned int serial = tdx_serial;
53 int i;
54
55 serialnr->low = 0;
56 serialnr->high = 0;
57
58 /* Check validity */
59 if (serial) {
60 /*
61 * Convert to Linux serial number format (hexadecimal coded
62 * decimal)
63 */
64 i = 7;
65 while (serial) {
66 array[i--] = serial % 10;
67 serial /= 10;
68 }
69 while (i >= 0)
70 array[i--] = 0;
71 serial = array[0];
72 for (i = 1; i < 8; i++) {
73 serial *= 16;
74 serial += array[i];
75 }
76
77 serialnr->low = serial;
78 }
79}
80#endif /* CONFIG_SERIAL_TAG */
81
82int show_board_info(void)
83{
84 unsigned char ethaddr[6];
85
86 if (read_tdx_cfg_block()) {
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +010087 printf("MISSING TORADEX CONFIG BLOCK\n");
88 tdx_eth_addr.oui = htonl(TORADEX_OUI << 8);
89 tdx_eth_addr.nic = htonl(tdx_serial << 8);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010090 checkboard();
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +010091 } else {
92 sprintf(tdx_serial_str, "%08u", tdx_serial);
93 sprintf(tdx_board_rev_str, "V%1d.%1d%c",
94 tdx_hw_tag.ver_major,
95 tdx_hw_tag.ver_minor,
96 (char)tdx_hw_tag.ver_assembly + 'A');
97
98 env_set("serial#", tdx_serial_str);
99
100 printf("Model: Toradex %s %s, Serial# %s\n",
101 toradex_modules[tdx_hw_tag.prodid],
102 tdx_board_rev_str,
103 tdx_serial_str);
Igor Opaniuk717fa2c2020-07-15 13:30:57 +0300104#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
105 if (read_tdx_cfg_block_carrier()) {
106 printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n");
107 try_migrate_tdx_cfg_block_carrier();
108 } else {
109 tdx_carrier_board_name = (char *)
110 toradex_carrier_boards[tdx_car_hw_tag.prodid];
111
112 sprintf(tdx_car_serial_str, "%08u", tdx_car_serial);
113 sprintf(tdx_car_rev_str, "V%1d.%1d%c",
114 tdx_car_hw_tag.ver_major,
115 tdx_car_hw_tag.ver_minor,
116 (char)tdx_car_hw_tag.ver_assembly +
117 'A');
118
119 env_set("carrier_serial#", tdx_car_serial_str);
120 printf("Carrier: Toradex %s %s, Serial# %s\n",
121 tdx_carrier_board_name,
122 tdx_car_rev_str,
123 tdx_car_serial_str);
124 }
125#endif
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100126 }
127
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100128 /*
129 * Check if environment contains a valid MAC address,
130 * set the one from config block if not
131 */
Simon Glass35affd72017-08-03 12:22:14 -0600132 if (!eth_env_get_enetaddr("ethaddr", ethaddr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600133 eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100134
135#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
Simon Glass35affd72017-08-03 12:22:14 -0600136 if (!eth_env_get_enetaddr("eth1addr", ethaddr)) {
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100137 /*
138 * Secondary MAC address is allocated from block
139 * 0x100000 higher then the first MAC address
140 */
141 memcpy(ethaddr, &tdx_eth_addr, 6);
142 ethaddr[3] += 0x10;
Simon Glassfd1e9592017-08-03 12:22:11 -0600143 eth_env_set_enetaddr("eth1addr", ethaddr);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100144 }
145#endif
146
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100147 return 0;
148}
149
Stefan Agner421440f2021-07-23 09:39:46 +0300150#ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100151int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
152{
153 unsigned short usb_pid;
154
155 usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
156 put_unaligned(usb_pid, &dev->idProduct);
157
158 return 0;
159}
Stefan Agnerbeaf4062016-11-30 13:41:52 -0800160#endif
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100161
Stefan Agner37fa4122016-11-30 13:41:53 -0800162#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900163int ft_common_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100164{
165 if (tdx_serial) {
166 fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
167 strlen(tdx_serial_str) + 1);
168 }
169
170 if (tdx_hw_tag.ver_major) {
171 char prod_id[5];
172
173 sprintf(prod_id, "%04u", tdx_hw_tag.prodid);
174 fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
175
176 fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
177 strlen(tdx_board_rev_str) + 1);
178 }
179
180 return 0;
181}
182#endif
183
184#else /* CONFIG_TDX_CFG_BLOCK */
185
Tom Rini97744622021-08-30 09:16:30 -0400186#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
187u32 get_board_revision(void)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100188{
189 return 0;
190}
191#endif /* CONFIG_REVISION_TAG */
192
193#ifdef CONFIG_SERIAL_TAG
194u32 get_board_serial(void)
195{
196 return 0;
197}
198#endif /* CONFIG_SERIAL_TAG */
199
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900200int ft_common_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100201{
202 return 0;
203}
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100204
205#endif /* CONFIG_TDX_CFG_BLOCK */