[U-Boot] [PATCH v3 2/2] dm: serial: bcm6345: fix baud rate clock calculation

Álvaro Fernández Rojas noltari at gmail.com
Thu May 18 21:09:46 UTC 2017


It's currently bugged and doesn't work for even cases.
Right shift bits instead of dividing and fix even cases.

Signed-off-by: Álvaro Fernández Rojas <noltari at gmail.com>
---
 drivers/serial/serial_bcm6345.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/serial/serial_bcm6345.c b/drivers/serial/serial_bcm6345.c
index 14c1bf2..9638952 100644
--- a/drivers/serial/serial_bcm6345.c
+++ b/drivers/serial/serial_bcm6345.c
@@ -157,11 +157,9 @@ static int bcm6345_serial_init(void __iomem *base, ulong clk, u32 baudrate)
 			UART_FIFO_CFG_TX_4);
 
 	/* set baud rate */
-	val = (clk / baudrate) / 16;
-	if (val & 0x1)
-		val = val;
-	else
-		val = val / 2 - 1;
+	val = ((clk / baudrate) >> 5);
+	if (!(val & 0x1))
+		val -= 1;
 	writel_be(val, base + UART_BAUD_REG);
 
 	/* clear interrupts */
@@ -243,7 +241,7 @@ static int bcm6345_serial_probe(struct udevice *dev)
 	ret = clk_get_by_index(dev, 0, &clk);
 	if (ret < 0)
 		return ret;
-	priv->uartclk = clk_get_rate(&clk) / 2;
+	priv->uartclk = clk_get_rate(&clk);
 	clk_free(&clk);
 
 	/* initialize serial */
-- 
2.1.4



More information about the U-Boot mailing list