blob: 94e603c14f40b48446e07b919b83ccd0e2f57d79 [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
Philippe Schenker494ef102022-06-13 19:35:22 +020025#define SERIAL_STR_LEN 8
26#define MODULE_VER_STR_LEN 4 // V1.1
27#define MODULE_REV_STR_LEN 1 // [A-Z]
28
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010029#ifdef CONFIG_TDX_CFG_BLOCK
Philippe Schenker494ef102022-06-13 19:35:22 +020030static char tdx_serial_str[SERIAL_STR_LEN + 1];
31static char tdx_board_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1];
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010032
Igor Opaniuk717fa2c2020-07-15 13:30:57 +030033#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
Philippe Schenker494ef102022-06-13 19:35:22 +020034static char tdx_car_serial_str[SERIAL_STR_LEN + 1];
35static char tdx_car_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1];
Igor Opaniuk717fa2c2020-07-15 13:30:57 +030036static char *tdx_carrier_board_name;
37#endif
38
Tom Rini97744622021-08-30 09:16:30 -040039#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
40u32 get_board_revision(void)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010041{
42 /* Check validity */
43 if (!tdx_hw_tag.ver_major)
44 return 0;
45
46 return ((tdx_hw_tag.ver_major & 0xff) << 8) |
47 ((tdx_hw_tag.ver_minor & 0xf) << 4) |
48 ((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
49}
50#endif /* CONFIG_TDX_CFG_BLOCK */
51
52#ifdef CONFIG_SERIAL_TAG
53void get_board_serial(struct tag_serialnr *serialnr)
54{
55 int array[8];
56 unsigned int serial = tdx_serial;
57 int i;
58
59 serialnr->low = 0;
60 serialnr->high = 0;
61
62 /* Check validity */
63 if (serial) {
64 /*
65 * Convert to Linux serial number format (hexadecimal coded
66 * decimal)
67 */
68 i = 7;
69 while (serial) {
70 array[i--] = serial % 10;
71 serial /= 10;
72 }
73 while (i >= 0)
74 array[i--] = 0;
75 serial = array[0];
76 for (i = 1; i < 8; i++) {
77 serial *= 16;
78 serial += array[i];
79 }
80
81 serialnr->low = serial;
82 }
83}
84#endif /* CONFIG_SERIAL_TAG */
85
86int show_board_info(void)
87{
88 unsigned char ethaddr[6];
89
90 if (read_tdx_cfg_block()) {
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +010091 printf("MISSING TORADEX CONFIG BLOCK\n");
92 tdx_eth_addr.oui = htonl(TORADEX_OUI << 8);
93 tdx_eth_addr.nic = htonl(tdx_serial << 8);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +010094 checkboard();
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +010095 } else {
Philippe Schenker39ff0622022-06-13 19:35:21 +020096 snprintf(tdx_serial_str, sizeof(tdx_serial_str),
97 "%08u", tdx_serial);
98 snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str),
99 "V%1d.%1d%c",
100 tdx_hw_tag.ver_major,
101 tdx_hw_tag.ver_minor,
102 (char)tdx_hw_tag.ver_assembly + 'A');
Bhuvanchandra DV43bfc492019-03-25 17:18:28 +0100103
104 env_set("serial#", tdx_serial_str);
105
106 printf("Model: Toradex %s %s, Serial# %s\n",
107 toradex_modules[tdx_hw_tag.prodid],
108 tdx_board_rev_str,
109 tdx_serial_str);
Igor Opaniuk717fa2c2020-07-15 13:30:57 +0300110#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
111 if (read_tdx_cfg_block_carrier()) {
112 printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n");
113 try_migrate_tdx_cfg_block_carrier();
114 } else {
115 tdx_carrier_board_name = (char *)
116 toradex_carrier_boards[tdx_car_hw_tag.prodid];
117
Philippe Schenker39ff0622022-06-13 19:35:21 +0200118 snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str),
119 "%08u", tdx_car_serial);
120 snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str),
121 "V%1d.%1d%c",
122 tdx_car_hw_tag.ver_major,
123 tdx_car_hw_tag.ver_minor,
124 (char)tdx_car_hw_tag.ver_assembly + 'A');
Igor Opaniuk717fa2c2020-07-15 13:30:57 +0300125
126 env_set("carrier_serial#", tdx_car_serial_str);
127 printf("Carrier: Toradex %s %s, Serial# %s\n",
128 tdx_carrier_board_name,
129 tdx_car_rev_str,
130 tdx_car_serial_str);
131 }
132#endif
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100133 }
134
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100135 /*
136 * Check if environment contains a valid MAC address,
137 * set the one from config block if not
138 */
Simon Glass35affd72017-08-03 12:22:14 -0600139 if (!eth_env_get_enetaddr("ethaddr", ethaddr))
Simon Glassfd1e9592017-08-03 12:22:11 -0600140 eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100141
142#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
Simon Glass35affd72017-08-03 12:22:14 -0600143 if (!eth_env_get_enetaddr("eth1addr", ethaddr)) {
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100144 /*
145 * Secondary MAC address is allocated from block
146 * 0x100000 higher then the first MAC address
147 */
148 memcpy(ethaddr, &tdx_eth_addr, 6);
149 ethaddr[3] += 0x10;
Simon Glassfd1e9592017-08-03 12:22:11 -0600150 eth_env_set_enetaddr("eth1addr", ethaddr);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100151 }
152#endif
153
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100154 return 0;
155}
156
Stefan Agner421440f2021-07-23 09:39:46 +0300157#ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100158int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
159{
160 unsigned short usb_pid;
161
162 usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
163 put_unaligned(usb_pid, &dev->idProduct);
164
165 return 0;
166}
Stefan Agnerbeaf4062016-11-30 13:41:52 -0800167#endif
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100168
Stefan Agner37fa4122016-11-30 13:41:53 -0800169#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900170int ft_common_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100171{
172 if (tdx_serial) {
173 fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
174 strlen(tdx_serial_str) + 1);
175 }
176
177 if (tdx_hw_tag.ver_major) {
178 char prod_id[5];
179
Philippe Schenker39ff0622022-06-13 19:35:21 +0200180 snprintf(prod_id, sizeof(prod_id), "%04u", tdx_hw_tag.prodid);
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100181 fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
182
183 fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
184 strlen(tdx_board_rev_str) + 1);
185 }
186
187 return 0;
188}
189#endif
190
191#else /* CONFIG_TDX_CFG_BLOCK */
192
Tom Rini97744622021-08-30 09:16:30 -0400193#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
194u32 get_board_revision(void)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100195{
196 return 0;
197}
198#endif /* CONFIG_REVISION_TAG */
199
200#ifdef CONFIG_SERIAL_TAG
201u32 get_board_serial(void)
202{
203 return 0;
204}
205#endif /* CONFIG_SERIAL_TAG */
206
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900207int ft_common_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100208{
209 return 0;
210}
Marcel Ziswilera2777ec2016-11-16 17:49:22 +0100211
212#endif /* CONFIG_TDX_CFG_BLOCK */