With driver model we can obtain CPU information by calling the CPU uclass.
This avoids ad-hoc code for each board. Change the code to do this when
CONFIG_BOARD is enabled.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 common/board_f.c         | 11 ++++++++++-
 drivers/cpu/cpu-uclass.c | 19 +++++++++++++++++++
 include/cpu.h            |  5 +++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/common/board_f.c b/common/board_f.c
index df9a64a20f..4d9d2f30c7 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -852,6 +852,15 @@ int reserve_arch(void)
        return board_walk_opt_phase(BOARD_F_RESERVE_ARCH);
 }
 
+int print_cpuinfo(void)
+{
+#ifdef CONFIG_CPU
+       return cpu_print_info();
+#else
+       return 0;
+#endif
+}
+
 #else
 
 /* Architecture-specific memory reservation */
@@ -938,7 +947,7 @@ static const init_fnc_t init_sequence_f[] = {
                defined(CONFIG_BOARD_ENABLE)
        checkcpu,
 #endif
-#if defined(CONFIG_DISPLAY_CPUINFO)
+#if defined(CONFIG_DISPLAY_CPUINFO) || defined(CONFIG_BOARD_ENABLED)
        print_cpuinfo,          /* display cpu info (and speed) */
 #endif
 #if defined(CONFIG_DISPLAY_BOARDINFO)
diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c
index c57ac16b3a..2a69ea3af3 100644
--- a/drivers/cpu/cpu-uclass.c
+++ b/drivers/cpu/cpu-uclass.c
@@ -54,6 +54,25 @@ int cpu_get_vendor(struct udevice *dev, char *buf, int size)
        return ops->get_vendor(dev, buf, size);
 }
 
+int cpu_print_info(void)
+{
+       struct udevice *dev;
+       char name[60];
+       int ret;
+
+       ret = uclass_first_device(UCLASS_CPU, &dev);
+       if (ret)
+               return ret;
+       if (!dev)
+               return 0;
+       ret = cpu_get_desc(dev, name, sizeof(name));
+       if (ret)
+               return ret;
+       printf("CPU:   %s\n", name);
+
+       return 0;
+}
+
 U_BOOT_DRIVER(cpu_bus) = {
        .name   = "cpu_bus",
        .id     = UCLASS_SIMPLE_BUS,
diff --git a/include/cpu.h b/include/cpu.h
index 954257715a..2d5c373343 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -124,4 +124,9 @@ int cpu_get_count(struct udevice *dev);
  */
 int cpu_get_vendor(struct udevice *dev, char *buf, int size);
 
+/**
+ * cpu_print_info() - Print information about the first CPU
+ */
+int cpu_print_info(void);
+
 #endif
-- 
2.12.0.367.g23dc2f6d3c-goog

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to