Skip to content

Commit 4486842

Browse files
Phil Elwellpopcornmix
authored andcommitted
amba_pl011: Round input clock up
The UART clock is initialised to be as close to the requested frequency as possible without exceeding it. Now that there is a clock manager that returns the actual frequencies, an expected 48MHz clock is reported as 47999625. If the requested baudrate == requested clock/16, there is no headroom and the slight reduction in actual clock rate results in failure. Detect cases where it looks like a "round" clock was chosen and adjust the reported clock to match that "round" value. As the code comment says: /* * If increasing a clock by less than 0.1% changes it * from ..999.. to ..000.., round up. */ Signed-off-by: Phil Elwell <phil@raspberrypi.org>
1 parent c21182f commit 4486842

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎drivers/tty/serial/amba-pl011.c‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,23 @@ static void pl011_put_poll_char(struct uart_port *port,
16521652

16531653
#endif /* CONFIG_CONSOLE_POLL */
16541654

1655+
unsigned long pl011_clk_round(unsigned long clk)
1656+
{
1657+
unsigned long scaler;
1658+
1659+
/*
1660+
* If increasing a clock by less than 0.1% changes it
1661+
* from ..999.. to ..000.., round up.
1662+
*/
1663+
scaler = 1;
1664+
while (scaler * 100000 < clk)
1665+
scaler *= 10;
1666+
if ((clk + scaler - 1)/scaler % 1000 == 0)
1667+
clk = (clk/scaler + 1) * scaler;
1668+
1669+
return clk;
1670+
}
1671+
16551672
static int pl011_hwinit(struct uart_port *port)
16561673
{
16571674
struct uart_amba_port *uap =
@@ -1668,7 +1685,7 @@ static int pl011_hwinit(struct uart_port *port)
16681685
if (retval)
16691686
return retval;
16701687

1671-
uap->port.uartclk = clk_get_rate(uap->clk);
1688+
uap->port.uartclk = pl011_clk_round(clk_get_rate(uap->clk));
16721689

16731690
/* Clear pending error and receive interrupts */
16741691
pl011_write(UART011_OEIS | UART011_BEIS | UART011_PEIS |
@@ -2324,7 +2341,7 @@ static int __init pl011_console_setup(struct console *co, char *options)
23242341
plat->init();
23252342
}
23262343

2327-
uap->port.uartclk = clk_get_rate(uap->clk);
2344+
uap->port.uartclk = pl011_clk_round(clk_get_rate(uap->clk));
23282345

23292346
if (uap->vendor->fixed_options) {
23302347
baud = uap->fixed_baud;
@@ -2509,6 +2526,7 @@ static struct uart_driver amba_reg = {
25092526
.cons = AMBA_CONSOLE,
25102527
};
25112528

2529+
#if 0
25122530
static int pl011_probe_dt_alias(int index, struct device *dev)
25132531
{
25142532
struct device_node *np;
@@ -2540,6 +2558,7 @@ static int pl011_probe_dt_alias(int index, struct device *dev)
25402558

25412559
return ret;
25422560
}
2561+
#endif
25432562

25442563
/* unregisters the driver also if no more ports are left */
25452564
static void pl011_unregister_port(struct uart_amba_port *uap)

0 commit comments

Comments
 (0)