Merge branch 'master' of https://gitlab.denx.de/u-boot/custodians/u-boot-spi
[oweals/u-boot.git] / drivers / serial / serial_bcm283x_mu.c
index 40029fadbcb4b7751078725be18d2ad502aac41c..a6ffc84b963e8468d2691bd5927132f50f68d2b3 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2016 Stephen Warren <swarren@wwwdotorg.org>
  *
@@ -9,8 +10,6 @@
  * (C) Copyright 2004
  * ARM Ltd.
  * Philippe Robin, <philippe.robin@arm.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /* Simple U-Boot driver for the BCM283x mini UART */
@@ -51,6 +50,8 @@ struct bcm283x_mu_priv {
        struct bcm283x_mu_regs *regs;
 };
 
+static int bcm283x_mu_serial_getc(struct udevice *dev);
+
 static int bcm283x_mu_serial_setbrg(struct udevice *dev, int baudrate)
 {
        struct bcm283x_mu_serial_platdata *plat = dev_get_platdata(dev);
@@ -59,13 +60,17 @@ static int bcm283x_mu_serial_setbrg(struct udevice *dev, int baudrate)
        u32 divider;
 
        if (plat->skip_init)
-               return 0;
+               goto out;
 
        divider = plat->clock / (baudrate * 8);
 
        writel(BCM283X_MU_LCR_DATA_SIZE_8, &regs->lcr);
        writel(divider - 1, &regs->baud);
 
+out:
+       /* Flush the RX queue - all data in there is bogus */
+       while (bcm283x_mu_serial_getc(dev) != -EAGAIN) ;
+
        return 0;
 }
 
@@ -194,6 +199,8 @@ U_BOOT_DRIVER(serial_bcm283x_mu) = {
        .platdata_auto_alloc_size = sizeof(struct bcm283x_mu_serial_platdata),
        .probe = bcm283x_mu_serial_probe,
        .ops = &bcm283x_mu_serial_ops,
+#if !CONFIG_IS_ENABLED(OF_CONTROL) || CONFIG_IS_ENABLED(OF_BOARD)
        .flags = DM_FLAG_PRE_RELOC,
+#endif
        .priv_auto_alloc_size = sizeof(struct bcm283x_mu_priv),
 };