dm: serial: Introduce ->getinfo() callback
[oweals/u-boot.git] / drivers / serial / serial-uclass.c
index 51ae1763fb6280dbbb66110aa7f71594ed67373c..ffcd6d15af2b07049fc5973a68c4478b2fc510ce 100644 (file)
@@ -322,6 +322,25 @@ int serial_setconfig(uint config)
        return 0;
 }
 
+int serial_getinfo(struct serial_device_info *info)
+{
+       struct dm_serial_ops *ops;
+
+       if (!gd->cur_serial_dev)
+               return -ENODEV;
+
+       if (!info)
+               return -EINVAL;
+
+       info->baudrate = gd->baudrate;
+
+       ops = serial_get_ops(gd->cur_serial_dev);
+       if (ops->getinfo)
+               return ops->getinfo(gd->cur_serial_dev, info);
+
+       return -EINVAL;
+}
+
 void serial_stdio_init(void)
 {
 }
@@ -441,6 +460,8 @@ static int serial_post_probe(struct udevice *dev)
        if (ops->loop)
                ops->loop += gd->reloc_off;
 #endif
+       if (ops->getinfo)
+               ops->getinfo += gd->reloc_off;
 #endif
        /* Set the baud rate */
        if (ops->setbrg) {