Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Toradex, Inc. |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 7 | #include <env.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 8 | #include <g_dnl.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 11 | |
Igor Opaniuk | 897822d | 2020-07-15 13:31:01 +0300 | [diff] [blame] | 12 | #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 Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 19 | #include "tdx-cfg-block.h" |
Simon Glass | d9a766f | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 20 | #include <asm/setup.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 21 | #include "tdx-common.h" |
| 22 | |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 23 | #define TORADEX_OUI 0x00142dUL |
| 24 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 25 | #ifdef CONFIG_TDX_CFG_BLOCK |
| 26 | static char tdx_serial_str[9]; |
| 27 | static char tdx_board_rev_str[6]; |
| 28 | |
Igor Opaniuk | ecfe0f5 | 2020-07-15 13:30:57 +0300 | [diff] [blame] | 29 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
| 30 | static char tdx_car_serial_str[9]; |
| 31 | static char tdx_car_rev_str[6]; |
| 32 | static char *tdx_carrier_board_name; |
| 33 | #endif |
| 34 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 35 | #if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) |
| 36 | u32 get_board_revision(void) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 37 | { |
| 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 |
| 49 | void 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 | |
| 82 | int show_board_info(void) |
| 83 | { |
| 84 | unsigned char ethaddr[6]; |
| 85 | |
| 86 | if (read_tdx_cfg_block()) { |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 87 | 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 Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 90 | checkboard(); |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 91 | } 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'); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 97 | |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 98 | env_set("serial#", tdx_serial_str); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 99 | |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 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 Opaniuk | ecfe0f5 | 2020-07-15 13:30:57 +0300 | [diff] [blame] | 104 | #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 |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 126 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Check if environment contains a valid MAC address, |
| 130 | * set the one from config block if not |
| 131 | */ |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 132 | if (!eth_env_get_enetaddr("ethaddr", ethaddr)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 133 | eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 134 | |
| 135 | #ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 136 | if (!eth_env_get_enetaddr("eth1addr", ethaddr)) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 137 | /* |
| 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 Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 143 | eth_env_set_enetaddr("eth1addr", ethaddr); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 144 | } |
| 145 | #endif |
| 146 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
Stefan Agner | 57985bd | 2021-07-23 09:39:46 +0300 | [diff] [blame] | 150 | #ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 151 | int 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 Agner | a188652 | 2016-11-30 13:41:52 -0800 | [diff] [blame] | 160 | #endif |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 161 | |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 162 | #if defined(CONFIG_OF_LIBFDT) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 163 | int ft_common_board_setup(void *blob, struct bd_info *bd) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 164 | { |
| 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 Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 186 | #if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) |
| 187 | u32 get_board_revision(void) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 188 | { |
| 189 | return 0; |
| 190 | } |
| 191 | #endif /* CONFIG_REVISION_TAG */ |
| 192 | |
| 193 | #ifdef CONFIG_SERIAL_TAG |
| 194 | u32 get_board_serial(void) |
| 195 | { |
| 196 | return 0; |
| 197 | } |
| 198 | #endif /* CONFIG_SERIAL_TAG */ |
| 199 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 200 | int ft_common_board_setup(void *blob, struct bd_info *bd) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 201 | { |
| 202 | return 0; |
| 203 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 204 | |
| 205 | #endif /* CONFIG_TDX_CFG_BLOCK */ |