Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2023, STMicroelectronics - All Rights Reserved |
| 4 | */ |
| 5 | |
| 6 | #define LOG_CATEGORY LOGC_BOARD |
| 7 | |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 8 | #include <config.h> |
| 9 | #include <env.h> |
| 10 | #include <fdt_support.h> |
Patrick Delaunay | d7b448f | 2024-01-15 15:05:54 +0100 | [diff] [blame] | 11 | #include <log.h> |
Patrick Delaunay | 300cb92 | 2024-01-15 15:05:55 +0100 | [diff] [blame] | 12 | #include <misc.h> |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 13 | #include <asm/global_data.h> |
| 14 | #include <asm/arch/sys_proto.h> |
Patrick Delaunay | 300cb92 | 2024-01-15 15:05:55 +0100 | [diff] [blame] | 15 | #include <dm/device.h> |
Patrick Delaunay | d7b448f | 2024-01-15 15:05:54 +0100 | [diff] [blame] | 16 | #include <dm/ofnode.h> |
Patrick Delaunay | 300cb92 | 2024-01-15 15:05:55 +0100 | [diff] [blame] | 17 | #include <dm/uclass.h> |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Get a global data pointer |
| 21 | */ |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Patrick Delaunay | d7b448f | 2024-01-15 15:05:54 +0100 | [diff] [blame] | 24 | int checkboard(void) |
| 25 | { |
Patrick Delaunay | 300cb92 | 2024-01-15 15:05:55 +0100 | [diff] [blame] | 26 | int ret; |
| 27 | u32 otp; |
| 28 | struct udevice *dev; |
Patrick Delaunay | d7b448f | 2024-01-15 15:05:54 +0100 | [diff] [blame] | 29 | const char *fdt_compat; |
| 30 | int fdt_compat_len; |
| 31 | |
| 32 | fdt_compat = ofnode_get_property(ofnode_root(), "compatible", &fdt_compat_len); |
| 33 | |
| 34 | log_info("Board: stm32mp2 (%s)\n", fdt_compat && fdt_compat_len ? fdt_compat : ""); |
| 35 | |
Patrick Delaunay | 300cb92 | 2024-01-15 15:05:55 +0100 | [diff] [blame] | 36 | /* display the STMicroelectronics board identification */ |
| 37 | if (CONFIG_IS_ENABLED(CMD_STBOARD)) { |
| 38 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 39 | DM_DRIVER_GET(stm32mp_bsec), |
| 40 | &dev); |
| 41 | if (!ret) |
| 42 | ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), |
| 43 | &otp, sizeof(otp)); |
| 44 | if (ret > 0 && otp) |
| 45 | log_info("Board: MB%04x Var%d.%d Rev.%c-%02d\n", |
| 46 | otp >> 16, |
| 47 | (otp >> 12) & 0xF, |
| 48 | (otp >> 4) & 0xF, |
| 49 | ((otp >> 8) & 0xF) - 1 + 'A', |
| 50 | otp & 0xF); |
| 51 | } |
| 52 | |
Patrick Delaunay | d7b448f | 2024-01-15 15:05:54 +0100 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 56 | /* board dependent setup after realloc */ |
| 57 | int board_init(void) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int board_late_init(void) |
| 63 | { |
| 64 | const void *fdt_compat; |
| 65 | int fdt_compat_len; |
| 66 | char dtb_name[256]; |
| 67 | int buf_len; |
| 68 | |
| 69 | if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) { |
| 70 | fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 71 | &fdt_compat_len); |
| 72 | if (fdt_compat && fdt_compat_len) { |
| 73 | if (strncmp(fdt_compat, "st,", 3) != 0) { |
| 74 | env_set("board_name", fdt_compat); |
| 75 | } else { |
| 76 | env_set("board_name", fdt_compat + 3); |
| 77 | |
| 78 | buf_len = sizeof(dtb_name); |
| 79 | strlcpy(dtb_name, fdt_compat + 3, buf_len); |
| 80 | buf_len -= strlen(fdt_compat + 3); |
| 81 | strlcat(dtb_name, ".dtb", buf_len); |
| 82 | env_set("fdtfile", dtb_name); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | } |