Skip to content

Commit 0238d2b

Browse files
Jisheng Zhanggregkh
authored andcommitted
serial: 8250: introduce get_divisor() and set_divisor() hook
Add these two hooks so that they can be overridden with driver specific implementations. Signed-off-by: Jisheng Zhang <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 16777ec commit 0238d2b

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

drivers/tty/serial/8250/8250_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,10 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
10231023
uart->port.get_mctrl = up->port.get_mctrl;
10241024
if (up->port.set_mctrl)
10251025
uart->port.set_mctrl = up->port.set_mctrl;
1026+
if (up->port.get_divisor)
1027+
uart->port.get_divisor = up->port.get_divisor;
1028+
if (up->port.set_divisor)
1029+
uart->port.set_divisor = up->port.set_divisor;
10261030
if (up->port.startup)
10271031
uart->port.startup = up->port.startup;
10281032
if (up->port.shutdown)

drivers/tty/serial/8250/8250_port.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,9 +2498,9 @@ static unsigned int npcm_get_divisor(struct uart_8250_port *up,
24982498
return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2;
24992499
}
25002500

2501-
static unsigned int serial8250_get_divisor(struct uart_port *port,
2502-
unsigned int baud,
2503-
unsigned int *frac)
2501+
static unsigned int serial8250_do_get_divisor(struct uart_port *port,
2502+
unsigned int baud,
2503+
unsigned int *frac)
25042504
{
25052505
struct uart_8250_port *up = up_to_u8250p(port);
25062506
unsigned int quot;
@@ -2532,6 +2532,16 @@ static unsigned int serial8250_get_divisor(struct uart_port *port,
25322532
return quot;
25332533
}
25342534

2535+
static unsigned int serial8250_get_divisor(struct uart_port *port,
2536+
unsigned int baud,
2537+
unsigned int *frac)
2538+
{
2539+
if (port->get_divisor)
2540+
return port->get_divisor(port, baud, frac);
2541+
2542+
return serial8250_do_get_divisor(port, baud, frac);
2543+
}
2544+
25352545
static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
25362546
tcflag_t c_cflag)
25372547
{
@@ -2570,7 +2580,7 @@ static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
25702580
return cval;
25712581
}
25722582

2573-
static void serial8250_set_divisor(struct uart_port *port, unsigned int baud,
2583+
static void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
25742584
unsigned int quot, unsigned int quot_frac)
25752585
{
25762586
struct uart_8250_port *up = up_to_u8250p(port);
@@ -2603,6 +2613,15 @@ static void serial8250_set_divisor(struct uart_port *port, unsigned int baud,
26032613
}
26042614
}
26052615

2616+
static void serial8250_set_divisor(struct uart_port *port, unsigned int baud,
2617+
unsigned int quot, unsigned int quot_frac)
2618+
{
2619+
if (port->set_divisor)
2620+
port->set_divisor(port, baud, quot, quot_frac);
2621+
else
2622+
serial8250_do_set_divisor(port, baud, quot, quot_frac);
2623+
}
2624+
26062625
static unsigned int serial8250_get_baud_rate(struct uart_port *port,
26072626
struct ktermios *termios,
26082627
struct ktermios *old)

include/linux/serial_core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ struct uart_port {
127127
struct ktermios *);
128128
unsigned int (*get_mctrl)(struct uart_port *);
129129
void (*set_mctrl)(struct uart_port *, unsigned int);
130+
unsigned int (*get_divisor)(struct uart_port *,
131+
unsigned int baud,
132+
unsigned int *frac);
133+
void (*set_divisor)(struct uart_port *,
134+
unsigned int baud,
135+
unsigned int quot,
136+
unsigned int quot_frac);
130137
int (*startup)(struct uart_port *port);
131138
void (*shutdown)(struct uart_port *port);
132139
void (*throttle)(struct uart_port *port);

0 commit comments

Comments
 (0)