blob: aa7dd31996eac2a1363112d1cada9d54a1832628 [file] [log] [blame]
Patrice Chotard01a70192023-10-27 16:43:04 +02001// 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 Chotard01a70192023-10-27 16:43:04 +02008#include <config.h>
9#include <env.h>
10#include <fdt_support.h>
Patrick Delaunay1067d7e2024-01-15 15:05:54 +010011#include <log.h>
Patrick Delaunayeff29f02024-01-15 15:05:55 +010012#include <misc.h>
Patrice Chotard01a70192023-10-27 16:43:04 +020013#include <asm/global_data.h>
14#include <asm/arch/sys_proto.h>
Patrick Delaunayeff29f02024-01-15 15:05:55 +010015#include <dm/device.h>
Patrick Delaunay1067d7e2024-01-15 15:05:54 +010016#include <dm/ofnode.h>
Patrick Delaunayeff29f02024-01-15 15:05:55 +010017#include <dm/uclass.h>
Patrice Chotard01a70192023-10-27 16:43:04 +020018
19/*
20 * Get a global data pointer
21 */
22DECLARE_GLOBAL_DATA_PTR;
23
Patrick Delaunay1067d7e2024-01-15 15:05:54 +010024int checkboard(void)
25{
Patrick Delaunayeff29f02024-01-15 15:05:55 +010026 int ret;
27 u32 otp;
28 struct udevice *dev;
Patrick Delaunay1067d7e2024-01-15 15:05:54 +010029 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 Delaunayeff29f02024-01-15 15:05:55 +010036 /* 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 Delaunay1067d7e2024-01-15 15:05:54 +010053 return 0;
54}
55
Patrice Chotard01a70192023-10-27 16:43:04 +020056/* board dependent setup after realloc */
57int board_init(void)
58{
59 return 0;
60}
61
62int 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}