configs: x530: move MTDPART/MTDIDS_DEFAULT in defconfig
[platform/kernel/u-boot.git] / cmd / cpu.c
index adfd54a..a09736e 100644 (file)
--- a/cmd/cpu.c
+++ b/cmd/cpu.c
@@ -1,13 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2015 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
+ * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
  */
 
 #include <common.h>
 #include <command.h>
 #include <cpu.h>
+#include <display_options.h>
 #include <dm.h>
 #include <errno.h>
 
@@ -21,23 +22,18 @@ static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
 static int print_cpu_list(bool detail)
 {
        struct udevice *dev;
-       struct uclass *uc;
        char buf[100];
-       int ret;
 
-       ret = uclass_get(UCLASS_CPU, &uc);
-       if (ret) {
-               printf("Cannot find CPU uclass\n");
-               return ret;
-       }
-       uclass_foreach_dev(dev, uc) {
-               struct cpu_platdata *plat = dev_get_parent_platdata(dev);
+       for (uclass_first_device(UCLASS_CPU, &dev);
+                    dev;
+                    uclass_next_device(&dev)) {
+               struct cpu_plat *plat = dev_get_parent_plat(dev);
                struct cpu_info info;
-               bool first;
-               int i;
+               bool first = true;
+               int ret, i;
 
                ret = cpu_get_desc(dev, buf, sizeof(buf));
-               printf("%3d: %-10s %s\n", dev->seq, dev->name,
+               printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
                       ret ? "<no description>" : buf);
                if (!detail)
                        continue;
@@ -45,13 +41,12 @@ static int print_cpu_list(bool detail)
                if (ret) {
                        printf("\t(no detail available");
                        if (ret != -ENOSYS)
-                               printf(": err=%d\n", ret);
+                               printf(": err=%d", ret);
                        printf(")\n");
                        continue;
                }
                printf("\tID = %d, freq = ", plat->cpu_id);
                print_freq(info.cpu_freq, "");
-               first = true;
                for (i = 0; i < CPU_FEAT_COUNT; i++) {
                        if (info.features & (1 << i)) {
                                printf("%s%s", first ? ": " : ", ",
@@ -60,10 +55,9 @@ static int print_cpu_list(bool detail)
                        }
                }
                printf("\n");
-               if (info.features & (1 << CPU_FEAT_UCODE)) {
+               if (info.features & (1 << CPU_FEAT_UCODE))
                        printf("\tMicrocode version %#x\n",
                               plat->ucode_version);
-               }
                if (info.features & (1 << CPU_FEAT_DEVICE_ID))
                        printf("\tDevice ID %#lx\n", plat->device_id);
        }
@@ -71,7 +65,8 @@ static int print_cpu_list(bool detail)
        return 0;
 }
 
-static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
 {
        if (print_cpu_list(false))
                return CMD_RET_FAILURE;
@@ -79,7 +74,7 @@ static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        return 0;
 }
 
-static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
+static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
                         char *const argv[])
 {
        if (print_cpu_list(true))
@@ -88,35 +83,13 @@ static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
        return 0;
 }
 
-static cmd_tbl_t cmd_cpu_sub[] = {
-       U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
-       U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
-};
-
-/*
- * Process a cpu sub-command
- */
-static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
-{
-       cmd_tbl_t *c = NULL;
-
-       /* Strip off leading 'cpu' command argument */
-       argc--;
-       argv++;
-
-       if (argc)
-               c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       cpu, 2, 1, do_cpu,
-       "display information about CPUs",
+#if CONFIG_IS_ENABLED(SYS_LONGHELP)
+static char cpu_help_text[] =
        "list   - list available CPUs\n"
        "cpu detail     - show CPU detail"
-);
+       ;
+#endif
+
+U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
+       U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
+       U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail));