23 #include <linux/slab.h>
24 #include <linux/module.h>
29 #include <linux/device.h>
30 #include <linux/tty.h>
32 #include <linux/serial_core.h>
33 #include <linux/serial.h>
41 #include <lantiq_soc.h>
43 #define PORT_LTQ_ASC 111
45 #define UART_DUMMY_UER_RX 1
46 #define DRVNAME "lantiq,asc"
48 #define LTQ_ASC_TBUF (0x0020 + 3)
49 #define LTQ_ASC_RBUF (0x0024 + 3)
51 #define LTQ_ASC_TBUF 0x0020
52 #define LTQ_ASC_RBUF 0x0024
54 #define LTQ_ASC_FSTAT 0x0048
55 #define LTQ_ASC_WHBSTATE 0x0018
56 #define LTQ_ASC_STATE 0x0014
57 #define LTQ_ASC_IRNCR 0x00F8
58 #define LTQ_ASC_CLC 0x0000
59 #define LTQ_ASC_ID 0x0008
60 #define LTQ_ASC_PISEL 0x0004
61 #define LTQ_ASC_TXFCON 0x0044
62 #define LTQ_ASC_RXFCON 0x0040
63 #define LTQ_ASC_CON 0x0010
64 #define LTQ_ASC_BG 0x0050
65 #define LTQ_ASC_IRNREN 0x00F4
67 #define ASC_IRNREN_TX 0x1
68 #define ASC_IRNREN_RX 0x2
69 #define ASC_IRNREN_ERR 0x4
70 #define ASC_IRNREN_TX_BUF 0x8
71 #define ASC_IRNCR_TIR 0x1
72 #define ASC_IRNCR_RIR 0x2
73 #define ASC_IRNCR_EIR 0x4
75 #define ASCOPT_CSIZE 0x3
78 #define ASCCLC_DISS 0x2
79 #define ASCCLC_RMCMASK 0x0000FF00
80 #define ASCCLC_RMCOFFSET 8
81 #define ASCCON_M_8ASYNC 0x0
82 #define ASCCON_M_7ASYNC 0x2
83 #define ASCCON_ODD 0x00000020
84 #define ASCCON_STP 0x00000080
85 #define ASCCON_BRS 0x00000100
86 #define ASCCON_FDE 0x00000200
87 #define ASCCON_R 0x00008000
88 #define ASCCON_FEN 0x00020000
89 #define ASCCON_ROEN 0x00080000
90 #define ASCCON_TOEN 0x00100000
91 #define ASCSTATE_PE 0x00010000
92 #define ASCSTATE_FE 0x00020000
93 #define ASCSTATE_ROE 0x00080000
94 #define ASCSTATE_ANY (ASCSTATE_ROE|ASCSTATE_PE|ASCSTATE_FE)
95 #define ASCWHBSTATE_CLRREN 0x00000001
96 #define ASCWHBSTATE_SETREN 0x00000002
97 #define ASCWHBSTATE_CLRPE 0x00000004
98 #define ASCWHBSTATE_CLRFE 0x00000008
99 #define ASCWHBSTATE_CLRROE 0x00000020
100 #define ASCTXFCON_TXFEN 0x0001
101 #define ASCTXFCON_TXFFLU 0x0002
102 #define ASCTXFCON_TXFITLMASK 0x3F00
103 #define ASCTXFCON_TXFITLOFF 8
104 #define ASCRXFCON_RXFEN 0x0001
105 #define ASCRXFCON_RXFFLU 0x0002
106 #define ASCRXFCON_RXFITLMASK 0x3F00
107 #define ASCRXFCON_RXFITLOFF 8
108 #define ASCFSTAT_RXFFLMASK 0x003F
109 #define ASCFSTAT_TXFFLMASK 0x3F00
110 #define ASCFSTAT_TXFREEMASK 0x3F000000
111 #define ASCFSTAT_TXFREEOFF 24
146 lqasc_tx_chars(port);
147 spin_unlock_irqrestore(<q_asc_lock, flags);
166 unsigned int ch = 0, rsr = 0, fifocnt;
169 dev_dbg(port->
dev,
"%s:tty is busy now", __func__);
204 if (rsr & ASCSTATE_PE)
206 else if (rsr & ASCSTATE_FE)
211 tty_insert_flip_char(tty, ch, flag);
213 if (rsr & ASCSTATE_ROE)
231 if (uart_tx_stopped(port)) {
259 lqasc_tx_int(
int irq,
void *_port)
265 spin_unlock_irqrestore(<q_asc_lock, flags);
266 lqasc_start_tx(port);
271 lqasc_err_int(
int irq,
void *_port)
279 spin_unlock_irqrestore(<q_asc_lock, flags);
284 lqasc_rx_int(
int irq,
void *_port)
290 lqasc_rx_chars(port);
291 spin_unlock_irqrestore(<q_asc_lock, flags);
315 lqasc_break_ctl(
struct uart_port *port,
int break_state)
351 pr_err(
"failed to request lqasc_tx_int\n");
358 pr_err(
"failed to request lqasc_rx_int\n");
365 pr_err(
"failed to request lqasc_err_int\n");
398 lqasc_set_termios(
struct uart_port *port,
405 unsigned int con = 0;
408 cflag =
new->c_cflag;
409 iflag =
new->c_iflag;
411 switch (cflag &
CSIZE) {
419 new->c_cflag &= ~
CSIZE;
454 if ((cflag &
CREAD) == 0)
468 divisor = divisor / 2 - 1;
488 spin_unlock_irqrestore(<q_asc_lock, flags);
507 lqasc_release_port(
struct uart_port *port)
516 lqasc_request_port(
struct uart_port *port)
524 dev_err(&pdev->
dev,
"cannot obtain I/O memory region");
527 size = resource_size(res);
530 size, dev_name(&pdev->
dev));
532 dev_err(&pdev->
dev,
"cannot request I/O memory region");
546 lqasc_config_port(
struct uart_port *port,
int flags)
550 lqasc_request_port(port);
555 lqasc_verify_port(
struct uart_port *port,
568 static struct uart_ops lqasc_pops = {
569 .tx_empty = lqasc_tx_empty,
570 .set_mctrl = lqasc_set_mctrl,
571 .get_mctrl = lqasc_get_mctrl,
572 .stop_tx = lqasc_stop_tx,
573 .start_tx = lqasc_start_tx,
574 .stop_rx = lqasc_stop_rx,
575 .enable_ms = lqasc_enable_ms,
576 .break_ctl = lqasc_break_ctl,
577 .startup = lqasc_startup,
578 .shutdown = lqasc_shutdown,
579 .set_termios = lqasc_set_termios,
581 .release_port = lqasc_release_port,
582 .request_port = lqasc_request_port,
583 .config_port = lqasc_config_port,
584 .verify_port = lqasc_verify_port,
588 lqasc_console_putchar(
struct uart_port *port,
int ch)
598 }
while (fifofree == 0);
613 ltq_port = lqasc_port[co->
index];
617 port = <q_port->
port;
621 spin_unlock_irqrestore(<q_asc_lock, flags);
637 ltq_port = lqasc_port[co->
index];
641 port = <q_port->
port;
650 static struct console lqasc_console = {
652 .write = lqasc_console_write,
654 .setup = lqasc_console_setup,
661 lqasc_console_init(
void)
671 .dev_name =
"ttyLTQ",
675 .cons = &lqasc_console,
690 if (!mmres || (ret != 3)) {
692 "failed to get memory/irq for serial port\n");
700 if (lqasc_port[line]) {
701 dev_err(&pdev->
dev,
"port %d already allocated\n", line);
710 port = <q_port->
port;
714 port->
ops = &lqasc_pops;
724 if (IS_ERR(ltq_port->
fpiclk)) {
725 pr_err(
"failed to get fpi clk\n");
736 lqasc_port[line] = ltq_port;
737 platform_set_drvdata(pdev, ltq_port);
754 .of_match_table = ltq_asc_match,