diff options
Diffstat (limited to 'board/toradex/common/common.c')
-rw-r--r-- | board/toradex/common/common.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/board/toradex/common/common.c b/board/toradex/common/common.c new file mode 100644 index 0000000000..30c8ebf8bd --- /dev/null +++ b/board/toradex/common/common.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2015 Toradex, Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include "configblock.h" +#include <common.h> +#include <g_dnl.h> + +__weak int checkboard_fallback(void) +{ + return 0; +} + +#ifdef CONFIG_REVISION_TAG +#ifdef CONFIG_TRDX_CFG_BLOCK +u32 get_board_rev(void) +{ + /* Check validity */ + if (!trdx_hw_tag.ver_major) + return 0; + + return ((trdx_hw_tag.ver_major & 0xff) << 8) | + ((trdx_hw_tag.ver_minor & 0xf) << 4) | + ((trdx_hw_tag.ver_assembly & 0xf) + 0xa); +} +#else +u32 get_board_rev(void) +{ + return 0; +} +#endif /* CONFIG_TRDX_CFG_BLOCK */ +#endif /* CONFIG_REVISION_TAG */ + +#ifdef CONFIG_SERIAL_TAG +#ifdef CONFIG_TRDX_CFG_BLOCK +void get_board_serial(struct tag_serialnr *serialnr) +{ + int array[8]; + unsigned int serial = trdx_serial; + int i; + + serialnr->low = 0; + serialnr->high = 0; + + /* Check validity */ + if (serial) { + /* + * Convert to Linux serial number format (hexadecimal coded + * decimal) + */ + i = 7; + while (serial) { + array[i--] = serial % 10; + serial /= 10; + } + while (i >= 0) + array[i--] = 0; + serial = array[0]; + for (i = 1; i < 8; i++) { + serial *= 16; + serial += array[i]; + } + + serialnr->low = serial; + } +} +#else +u32 get_board_rev(void) +{ + return 0; +} +#endif /* CONFIG_TRDX_CFG_BLOCK */ +#endif /* CONFIG_SERIAL_TAG */ + +int checkboard(void) +{ +#ifdef CONFIG_TRDX_CFG_BLOCK + if (read_trdx_cfg_block()) { + printf("Missing Toradex config block\n"); + checkboard_fallback(); + return 0; + } + + printf("Model: Toradex %s V%d.%d%c\n", + toradex_modules[trdx_hw_tag.prodid], + trdx_hw_tag.ver_major, + trdx_hw_tag.ver_minor, + (char)trdx_hw_tag.ver_assembly + 'A'); +#else + checkboard_fallback(); +#endif + return 0; +} + +#ifdef CONFIG_USBDOWNLOAD_GADGET +int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) +{ + unsigned short usb_pid = 0xffff; + +#ifdef CONFIG_TRDX_CONFIGBLOCK + usb_pid = 0x4000 + trdx_hw_tag.prodid; +#endif + put_unaligned(usb_pid, &dev->idProduct); + + return 0; +} +#endif /* CONFIG_USBDOWNLOAD_GADGET */ |