]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bdinfo: Show information about the serial port
authorSimon Glass <sjg@chromium.org>
Wed, 12 Jul 2023 15:04:37 +0000 (09:04 -0600)
committerBin Meng <bmeng@tinylab.org>
Mon, 17 Jul 2023 05:38:34 +0000 (13:38 +0800)
It is useful to see the detailed setting of the serial port, e.g. to
allow setting up earlycon or console for Linux. Add this output to the
'bdinfo' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: squashed in 20230716033929.253357-2-sjg@chromium.org]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
cmd/bdinfo.c
test/cmd/bdinfo.c

index 365357ca545f9728ebc2b6f0da714d52c937bca8..dab73f1d93c472b7e4cddfc161c5cd39bc4b83bd 100644 (file)
@@ -13,6 +13,7 @@
 #include <lmb.h>
 #include <mapmem.h>
 #include <net.h>
+#include <serial.h>
 #include <video.h>
 #include <vsprintf.h>
 #include <asm/cache.h>
@@ -113,6 +114,25 @@ static void show_video_info(void)
        }
 }
 
+static void print_serial(struct udevice *dev)
+{
+       struct serial_device_info info;
+       int ret;
+
+       if (!dev || !IS_ENABLED(CONFIG_DM_SERIAL))
+               return;
+
+       ret = serial_getinfo(dev, &info);
+       if (ret)
+               return;
+
+       bdinfo_print_num_l("serial addr", info.addr);
+       bdinfo_print_num_l(" width", info.reg_width);
+       bdinfo_print_num_l(" shift", info.reg_shift);
+       bdinfo_print_num_l(" offset", info.reg_offset);
+       bdinfo_print_num_l(" clock", info.clock);
+}
+
 int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
        struct bd_info *bd = gd->bd;
@@ -151,6 +171,7 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
                if (IS_ENABLED(CONFIG_OF_REAL))
                        printf("devicetree  = %s\n", fdtdec_get_srcname());
        }
+       print_serial(gd->cur_serial_dev);
 
        arch_print_bdinfo();
 
index cddf1a46d491726ac48de4dbce04b10d50b36497..6480393fd5d877e060c31dc522f13115e339a747 100644 (file)
@@ -16,6 +16,7 @@
 #include <env.h>
 #include <lmb.h>
 #include <net.h>
+#include <serial.h>
 #include <video.h>
 #include <vsprintf.h>
 #include <asm/cache.h>
@@ -191,6 +192,19 @@ static int bdinfo_test_move(struct unit_test_state *uts)
                        ut_assert_nextline("devicetree  = %s", fdtdec_get_srcname());
        }
 
+       if (IS_ENABLED(CONFIG_DM_SERIAL)) {
+               struct serial_device_info info;
+
+               ut_assertnonnull(gd->cur_serial_dev);
+               ut_assertok(serial_getinfo(gd->cur_serial_dev, &info));
+
+               ut_assertok(test_num_l(uts, "serial addr", info.addr));
+               ut_assertok(test_num_l(uts, " width", info.reg_width));
+               ut_assertok(test_num_l(uts, " shift", info.reg_shift));
+               ut_assertok(test_num_l(uts, " offset", info.reg_offset));
+               ut_assertok(test_num_l(uts, " clock", info.clock));
+       }
+
        ut_assertok(ut_check_console_end(uts));
 
        return 0;