serial: mvebu-uart: clarify the baud rate derivation
The current comment in ->set_baud_rate() is rather incomplete as it fails to describe what are the actual stages for the baudrate derivation. Replace this comment with something more explicit and close to the functional specification. Also adapt the variable names to it. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
20d8e8611e
commit
0e4cf69ede
1 changed files with 14 additions and 8 deletions
|
@ -72,6 +72,7 @@
|
||||||
#define BRDV_BAUD_MASK 0x3FF
|
#define BRDV_BAUD_MASK 0x3FF
|
||||||
|
|
||||||
#define UART_OSAMP 0x14
|
#define UART_OSAMP 0x14
|
||||||
|
#define OSAMP_DEFAULT_DIVISOR 16
|
||||||
|
|
||||||
#define MVEBU_NR_UARTS 2
|
#define MVEBU_NR_UARTS 2
|
||||||
|
|
||||||
|
@ -444,23 +445,28 @@ static void mvebu_uart_shutdown(struct uart_port *port)
|
||||||
static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud)
|
static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud)
|
||||||
{
|
{
|
||||||
struct mvebu_uart *mvuart = to_mvuart(port);
|
struct mvebu_uart *mvuart = to_mvuart(port);
|
||||||
unsigned int baud_rate_div;
|
unsigned int d_divisor, m_divisor;
|
||||||
u32 brdv;
|
u32 brdv;
|
||||||
|
|
||||||
if (IS_ERR(mvuart->clk))
|
if (IS_ERR(mvuart->clk))
|
||||||
return -PTR_ERR(mvuart->clk);
|
return -PTR_ERR(mvuart->clk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The UART clock is divided by the value of the divisor to generate
|
* The baudrate is derived from the UART clock thanks to two divisors:
|
||||||
* UCLK_OUT clock, which is 16 times faster than the baudrate.
|
* > D ("baud generator"): can divide the clock from 2 to 2^10 - 1.
|
||||||
* This prescaler can achieve all standard baudrates until 230400.
|
* > M ("fractional divisor"): allows a better accuracy for
|
||||||
* Higher baudrates could be achieved for the extended UART by using the
|
* baudrates higher than 230400.
|
||||||
* programmable oversampling stack (also called fractional divisor).
|
*
|
||||||
|
* As the derivation of M is rather complicated, the code sticks to its
|
||||||
|
* default value (x16) when all the prescalers are zeroed, and only
|
||||||
|
* makes use of D to configure the desired baudrate.
|
||||||
*/
|
*/
|
||||||
baud_rate_div = DIV_ROUND_UP(port->uartclk, baud * 16);
|
m_divisor = OSAMP_DEFAULT_DIVISOR;
|
||||||
|
d_divisor = DIV_ROUND_UP(port->uartclk, baud * m_divisor);
|
||||||
|
|
||||||
brdv = readl(port->membase + UART_BRDV);
|
brdv = readl(port->membase + UART_BRDV);
|
||||||
brdv &= ~BRDV_BAUD_MASK;
|
brdv &= ~BRDV_BAUD_MASK;
|
||||||
brdv |= baud_rate_div;
|
brdv |= d_divisor;
|
||||||
writel(brdv, port->membase + UART_BRDV);
|
writel(brdv, port->membase + UART_BRDV);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue