]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: date: rtc: Update command to read the first RTC with seq 0
authorMichal Simek <michal.simek@xilinx.com>
Thu, 29 Jul 2021 10:59:12 +0000 (12:59 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Fri, 6 Aug 2021 07:32:02 +0000 (09:32 +0200)
RTCs are using sequence number defined in aliases node. Date command with
DM_RTC enabled is looking for the first RTC with index 0. But when
RTC_EMULATION is enabled it gets likely most of the time index 0 even when
system has rtc0 device via aliases node and gets sequence number 0.
That's why extend the code to look for sequence 0 number first. If this
fails continue to use existing device with index 0.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
cmd/date.c

index e377cfe165e3dd5701148b9999981559d1921860..149ca426e8c4f3936685b7b22117889b51e126cd 100644 (file)
@@ -41,10 +41,13 @@ static int do_date(struct cmd_tbl *cmdtp, int flag, int argc,
 #ifdef CONFIG_DM_RTC
        struct udevice *dev;
 
-       rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
+       rcode = uclass_get_device_by_seq(UCLASS_RTC, 0, &dev);
        if (rcode) {
-               printf("Cannot find RTC: err=%d\n", rcode);
-               return CMD_RET_FAILURE;
+               rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
+               if (rcode) {
+                       printf("Cannot find RTC: err=%d\n", rcode);
+                       return CMD_RET_FAILURE;
+               }
        }
 #elif defined(CONFIG_SYS_I2C_LEGACY)
        old_bus = i2c_get_bus_num();