Skip to content

Commit 701c5e7

Browse files
Jisheng Zhanggregkh
authored andcommitted
serial: 8250_dw: add fractional divisor support
For Synopsys DesignWare 8250 uart which version >= 4.00a, there's a valid divisor latch fraction register. The fractional divisor width is 4bits ~ 6bits. Now the preparation is done, it's easy to add the feature support. This patch firstly tries to get the fractional divisor width during probe, then setups dw specific get_divisor() and set_divisor() hook. Signed-off-by: Jisheng Zhang <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6226e5f commit 701c5e7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

drivers/tty/serial/8250/8250_dw.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
/* Offsets for the DesignWare specific registers */
3333
#define DW_UART_USR 0x1f /* UART Status Register */
34+
#define DW_UART_DLF 0xc0 /* Divisor Latch Fraction Register */
3435
#define DW_UART_CPR 0xf4 /* Component Parameter Register */
3536
#define DW_UART_UCV 0xf8 /* UART Component Version */
3637

@@ -55,6 +56,7 @@
5556

5657
struct dw8250_data {
5758
u8 usr_reg;
59+
u8 dlf_size;
5860
int line;
5961
int msr_mask_on;
6062
int msr_mask_off;
@@ -366,6 +368,37 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
366368
return param == chan->device->dev->parent;
367369
}
368370

371+
/*
372+
* divisor = div(I) + div(F)
373+
* "I" means integer, "F" means fractional
374+
* quot = div(I) = clk / (16 * baud)
375+
* frac = div(F) * 2^dlf_size
376+
*
377+
* let rem = clk % (16 * baud)
378+
* we have: div(F) * (16 * baud) = rem
379+
* so frac = 2^dlf_size * rem / (16 * baud) = (rem << dlf_size) / (16 * baud)
380+
*/
381+
static unsigned int dw8250_get_divisor(struct uart_port *p,
382+
unsigned int baud,
383+
unsigned int *frac)
384+
{
385+
unsigned int quot, rem, base_baud = baud * 16;
386+
struct dw8250_data *d = p->private_data;
387+
388+
quot = p->uartclk / base_baud;
389+
rem = p->uartclk % base_baud;
390+
*frac = DIV_ROUND_CLOSEST(rem << d->dlf_size, base_baud);
391+
392+
return quot;
393+
}
394+
395+
static void dw8250_set_divisor(struct uart_port *p, unsigned int baud,
396+
unsigned int quot, unsigned int quot_frac)
397+
{
398+
dw8250_writel_ext(p, DW_UART_DLF, quot_frac);
399+
serial8250_do_set_divisor(p, baud, quot, quot_frac);
400+
}
401+
369402
static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
370403
{
371404
if (p->dev->of_node) {
@@ -426,6 +459,18 @@ static void dw8250_setup_port(struct uart_port *p)
426459
dev_dbg(p->dev, "Designware UART version %c.%c%c\n",
427460
(reg >> 24) & 0xff, (reg >> 16) & 0xff, (reg >> 8) & 0xff);
428461

462+
dw8250_writel_ext(p, DW_UART_DLF, ~0U);
463+
reg = dw8250_readl_ext(p, DW_UART_DLF);
464+
dw8250_writel_ext(p, DW_UART_DLF, 0);
465+
466+
if (reg) {
467+
struct dw8250_data *d = p->private_data;
468+
469+
d->dlf_size = fls(reg);
470+
p->get_divisor = dw8250_get_divisor;
471+
p->set_divisor = dw8250_set_divisor;
472+
}
473+
429474
reg = dw8250_readl_ext(p, DW_UART_CPR);
430475
if (!reg)
431476
return;

0 commit comments

Comments
 (0)