Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 2 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 3 | #include <dm.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 4 | #include <init.h> |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 5 | #include <sysinfo.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 6 | #include <asm/global_data.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 7 | #include <linux/libfdt.h> |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 8 | #include <linux/compiler.h> |
| 9 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 10 | DECLARE_GLOBAL_DATA_PTR; |
| 11 | |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 12 | int __weak checkboard(void) |
| 13 | { |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 14 | return 0; |
| 15 | } |
| 16 | |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 17 | static const struct to_show { |
| 18 | const char *name; |
| 19 | enum sysinfo_id id; |
| 20 | } to_show[] = { |
| 21 | { "Manufacturer", SYSINFO_ID_BOARD_MANUFACTURER}, |
| 22 | { "Prior-stage version", SYSINFO_ID_PRIOR_STAGE_VERSION }, |
| 23 | { "Prior-stage date", SYSINFO_ID_PRIOR_STAGE_DATE }, |
| 24 | { /* sentinel */ } |
| 25 | }; |
| 26 | |
| 27 | static int try_sysinfo(void) |
| 28 | { |
| 29 | struct udevice *dev; |
| 30 | char str[80]; |
| 31 | int ret; |
| 32 | |
| 33 | /* This might provide more detail */ |
| 34 | ret = sysinfo_get(&dev); |
| 35 | if (ret) |
| 36 | return ret; |
| 37 | |
| 38 | ret = sysinfo_detect(dev); |
| 39 | if (ret) |
| 40 | return ret; |
| 41 | |
| 42 | ret = sysinfo_get_str(dev, SYSINFO_ID_BOARD_MODEL, sizeof(str), str); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | printf("Model: %s\n", str); |
| 46 | |
| 47 | if (IS_ENABLED(CONFIG_SYSINFO_EXTRA)) { |
| 48 | const struct to_show *item; |
| 49 | |
| 50 | for (item = to_show; item->id; item++) { |
| 51 | ret = sysinfo_get_str(dev, item->id, sizeof(str), str); |
| 52 | if (!ret) |
| 53 | printf("%s: %s\n", item->name, str); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Simon Glass | d2a1b43 | 2023-11-12 19:58:27 -0700 | [diff] [blame] | 60 | int show_board_info(void) |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 61 | { |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 62 | if (IS_ENABLED(CONFIG_OF_CONTROL)) { |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 63 | int ret = -ENOSYS; |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 64 | |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 65 | if (IS_ENABLED(CONFIG_SYSINFO)) |
| 66 | ret = try_sysinfo(); |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 67 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 68 | /* Fail back to the main 'model' if available */ |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 69 | if (ret) { |
| 70 | const char *model; |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 71 | |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 72 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 73 | if (model) |
| 74 | printf("Model: %s\n", model); |
| 75 | } |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 76 | } |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 77 | |
| 78 | return checkboard(); |
| 79 | } |