blob: 2207818447a70096c62da16e9741eb634cf12649 [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 {
Philippe Schenker39ff0622022-06-13 19:35:21 +020092 snprintf(tdx_serial_str, sizeof(tdx_serial_str),
93 "%08u", tdx_serial);
94 snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str),
95 "V%1d.%1d%c",
96 tdx_hw_tag.ver_major,
97 tdx_hw_tag.ver_minor,
98 (char)tdx_hw_tag.ver_assembly + 'A');
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +010099
100 env_set("serial#", tdx_serial_str);
101
102 printf("Model: Toradex %s %s, Serial# %s\n",
103 toradex_modules[tdx_hw_tag.prodid],
104 tdx_board_rev_str,
105 tdx_serial_str);
Igor Opaniuk717fa2c2020-07-15 13:30:57 +0300106#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
107 if (read_tdx_cfg_block_carrier()) {
108 printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n");
109 try_migrate_tdx_cfg_block_carrier();
110 } else {
111 tdx_carrier_board_name = (char *)
112 toradex_carrier_boards[tdx_car_hw_tag.prodid];
113
Philippe Schenker39ff0622022-06-13 19:35:21 +0200114 snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str),
115 "%08u", tdx_car_serial);
116 snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str),
117 "V%1d.%1d%c",
118 tdx_car_hw_tag.ver_major,
119 tdx_car_hw_tag.ver_minor,
120 (char)tdx_car_hw_tag.ver_assembly + 'A');
Igor Opaniuk717fa2c2020-07-15 13:30:57 +0300121
122 env_set("carrier_serial#", tdx_car_serial_str);
123 printf("Carrier: Toradex %s %s, Serial# %s\n",
124 tdx_carrier_board_name,
125 tdx_car_rev_str,
126 tdx_car_serial_str);
127 }
128#endif
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100129 }
130
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100131 /*
132 * Check if environment contains a valid MAC address,
133 * set the one from config block if not
134 */
Simon Glass35affd72017-08-03 12:22:14 -0600135 if (!eth_env_get_enetaddr("ethaddr", ethaddr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600136 eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100137
138#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
Simon Glass35affd72017-08-03 12:22:14 -0600139 if (!eth_env_get_enetaddr("eth1addr", ethaddr)) {
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100140 /*
141 * Secondary MAC address is allocated from block
142 * 0x100000 higher then the first MAC address
143 */
144 memcpy(ethaddr, &tdx_eth_addr, 6);
145 ethaddr[3] += 0x10;
Simon Glassfd1e9592017-08-03 12:22:11 -0600146 eth_env_set_enetaddr("eth1addr", ethaddr);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100147 }
148#endif
149
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100150 return 0;
151}
152
Stefan Agner421440f2021-07-23 09:39:46 +0300153#ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100154int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
155{
156 unsigned short usb_pid;
157
158 usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
159 put_unaligned(usb_pid, &dev->idProduct);
160
161 return 0;
162}
Stefan Agnerbeaf4062016-11-30 13:41:52 -0800163#endif
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100164
Stefan Agner37fa4122016-11-30 13:41:53 -0800165#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900166int ft_common_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100167{
168 if (tdx_serial) {
169 fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
170 strlen(tdx_serial_str) + 1);
171 }
172
173 if (tdx_hw_tag.ver_major) {
174 char prod_id[5];
175
Philippe Schenker39ff0622022-06-13 19:35:21 +0200176 snprintf(prod_id, sizeof(prod_id), "%04u", tdx_hw_tag.prodid);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100177 fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
178
179 fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
180 strlen(tdx_board_rev_str) + 1);
181 }
182
183 return 0;
184}
185#endif
186
187#else /* CONFIG_TDX_CFG_BLOCK */
188
Tom Rini97744622021-08-30 09:16:30 -0400189#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
190u32 get_board_revision(void)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100191{
192 return 0;
193}
194#endif /* CONFIG_REVISION_TAG */
195
196#ifdef CONFIG_SERIAL_TAG
197u32 get_board_serial(void)
198{
199 return 0;
200}
201#endif /* CONFIG_SERIAL_TAG */
202
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900203int ft_common_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100204{
205 return 0;
206}
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100207
208#endif /* CONFIG_TDX_CFG_BLOCK */