Skip to content

Commit f597fbc

Browse files
shenkigregkh
authored andcommitted
serial: 8250: Add Nuvoton NPCM UART
The Nuvoton UART is almost compatible with the 8250 driver when probed via the 8250_of driver, however it requires some extra configuration at startup. Reviewed-by: Rob Herring <[email protected]> Signed-off-by: Joel Stanley <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ca7c22f commit f597fbc

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Documentation/devicetree/bindings/serial/8250.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Required properties:
2424
- "ti,da830-uart"
2525
- "aspeed,ast2400-vuart"
2626
- "aspeed,ast2500-vuart"
27+
- "nuvoton,npcm750-uart"
2728
- "serial" if the port type is unknown.
2829
- reg : offset and length of the register set for the device.
2930
- interrupts : should contain uart interrupt.

drivers/tty/serial/8250/8250_of.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ static const struct of_device_id of_platform_serial_table[] = {
316316
{ .compatible = "mrvl,mmp-uart",
317317
.data = (void *)PORT_XSCALE, },
318318
{ .compatible = "ti,da830-uart", .data = (void *)PORT_DA830, },
319+
{ .compatible = "nuvoton,npcm750-uart", .data = (void *)PORT_NPCM, },
319320
{ /* end of list */ },
320321
};
321322
MODULE_DEVICE_TABLE(of, of_platform_serial_table);

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
#define UART_EXAR_SLEEP 0x8b /* Sleep mode */
4848
#define UART_EXAR_DVID 0x8d /* Device identification */
4949

50+
/* Nuvoton NPCM timeout register */
51+
#define UART_NPCM_TOR 7
52+
#define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */
53+
5054
/*
5155
* Debugging.
5256
*/
@@ -293,6 +297,15 @@ static const struct serial8250_config uart_config[] = {
293297
UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
294298
.flags = UART_CAP_FIFO,
295299
},
300+
[PORT_NPCM] = {
301+
.name = "Nuvoton 16550",
302+
.fifo_size = 16,
303+
.tx_loadsz = 16,
304+
.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
305+
UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
306+
.rxtrig_bytes = {1, 4, 8, 14},
307+
.flags = UART_CAP_FIFO,
308+
},
296309
};
297310

298311
/* Uart divisor latch read */
@@ -2141,6 +2154,15 @@ int serial8250_do_startup(struct uart_port *port)
21412154
UART_DA830_PWREMU_MGMT_FREE);
21422155
}
21432156

2157+
if (port->type == PORT_NPCM) {
2158+
/*
2159+
* Nuvoton calls the scratch register 'UART_TOR' (timeout
2160+
* register). Enable it, and set TIOC (timeout interrupt
2161+
* comparator) to be 0x20 for correct operation.
2162+
*/
2163+
serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20);
2164+
}
2165+
21442166
#ifdef CONFIG_SERIAL_8250_RSA
21452167
/*
21462168
* If this is an RSA port, see if we can kick it up to the
@@ -2463,6 +2485,15 @@ static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up,
24632485
return quot_16 >> 4;
24642486
}
24652487

2488+
/* Nuvoton NPCM UARTs have a custom divisor calculation */
2489+
static unsigned int npcm_get_divisor(struct uart_8250_port *up,
2490+
unsigned int baud)
2491+
{
2492+
struct uart_port *port = &up->port;
2493+
2494+
return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2;
2495+
}
2496+
24662497
static unsigned int serial8250_get_divisor(struct uart_8250_port *up,
24672498
unsigned int baud,
24682499
unsigned int *frac)
@@ -2483,6 +2514,8 @@ static unsigned int serial8250_get_divisor(struct uart_8250_port *up,
24832514
quot = 0x8002;
24842515
else if (up->port.type == PORT_XR17V35X)
24852516
quot = xr17v35x_get_divisor(up, baud, frac);
2517+
else if (up->port.type == PORT_NPCM)
2518+
quot = npcm_get_divisor(up, baud);
24862519
else
24872520
quot = uart_get_divisor(port, baud);
24882521

include/uapi/linux/serial_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
#define PORT_SUNZILOG 38
7777
#define PORT_SUNSAB 39
7878

79+
/* Nuvoton UART */
80+
#define PORT_NPCM 40
81+
7982
/* Intel EG20 */
8083
#define PORT_PCH_8LINE 44
8184
#define PORT_PCH_2LINE 45

0 commit comments

Comments
 (0)