2 * Copyright (c) 2016 Toradex, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include "tdx-cfg-block.h"
12 #include "tdx-common.h"
14 #ifdef CONFIG_TDX_CFG_BLOCK
15 static char tdx_serial_str[9];
16 static char tdx_board_rev_str[6];
18 #ifdef CONFIG_REVISION_TAG
19 u32 get_board_rev(void)
22 if (!tdx_hw_tag.ver_major)
25 return ((tdx_hw_tag.ver_major & 0xff) << 8) |
26 ((tdx_hw_tag.ver_minor & 0xf) << 4) |
27 ((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
29 #endif /* CONFIG_TDX_CFG_BLOCK */
31 #ifdef CONFIG_SERIAL_TAG
32 void get_board_serial(struct tag_serialnr *serialnr)
35 unsigned int serial = tdx_serial;
44 * Convert to Linux serial number format (hexadecimal coded
49 array[i--] = serial % 10;
55 for (i = 1; i < 8; i++) {
60 serialnr->low = serial;
63 #endif /* CONFIG_SERIAL_TAG */
65 int show_board_info(void)
67 unsigned char ethaddr[6];
69 if (read_tdx_cfg_block()) {
70 printf("Missing Toradex config block\n");
75 /* board serial-number */
76 sprintf(tdx_serial_str, "%08u", tdx_serial);
77 sprintf(tdx_board_rev_str, "V%1d.%1d%c",
80 (char)tdx_hw_tag.ver_assembly + 'A');
82 setenv("serial#", tdx_serial_str);
85 * Check if environment contains a valid MAC address,
86 * set the one from config block if not
88 if (!eth_getenv_enetaddr("ethaddr", ethaddr))
89 eth_setenv_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
91 #ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
92 if (!eth_getenv_enetaddr("eth1addr", ethaddr)) {
94 * Secondary MAC address is allocated from block
95 * 0x100000 higher then the first MAC address
97 memcpy(ethaddr, &tdx_eth_addr, 6);
99 eth_setenv_enetaddr("eth1addr", ethaddr);
103 printf("Model: Toradex %s %s, Serial# %s\n",
104 toradex_modules[tdx_hw_tag.prodid],
111 #ifdef CONFIG_USB_GADGET_DOWNLOAD
112 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
114 unsigned short usb_pid;
116 usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
117 put_unaligned(usb_pid, &dev->idProduct);
123 #if defined(CONFIG_OF_LIBFDT)
124 int ft_common_board_setup(void *blob, bd_t *bd)
127 fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
128 strlen(tdx_serial_str) + 1);
131 if (tdx_hw_tag.ver_major) {
134 sprintf(prod_id, "%04u", tdx_hw_tag.prodid);
135 fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
137 fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
138 strlen(tdx_board_rev_str) + 1);
145 #else /* CONFIG_TDX_CFG_BLOCK */
147 #ifdef CONFIG_REVISION_TAG
148 u32 get_board_rev(void)
152 #endif /* CONFIG_REVISION_TAG */
154 #ifdef CONFIG_SERIAL_TAG
155 u32 get_board_serial(void)
159 #endif /* CONFIG_SERIAL_TAG */
161 int ft_common_board_setup(void *blob, bd_t *bd)
166 #endif /* CONFIG_TDX_CFG_BLOCK */