26 #if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
30 #include <linux/module.h>
41 #include <linux/tty.h>
43 #include <linux/serial_core.h>
46 #include <linux/slab.h>
48 #define PXA_NAME_LEN 8
90 static void serial_pxa_stop_rx(
struct uart_port *port)
102 unsigned int ch,
flag;
118 up->
port.icount.rx++;
127 up->
port.icount.brk++;
134 if (uart_handle_break(&up->
port))
137 up->
port.icount.parity++;
139 up->
port.icount.frame++;
141 up->
port.icount.overrun++;
146 *status &= up->
port.read_status_mask;
148 #ifdef CONFIG_SERIAL_PXA_CONSOLE
149 if (up->
port.line == up->
port.cons->index) {
155 if (*status & UART_LSR_BI) {
157 }
else if (*status & UART_LSR_PE)
159 else if (*status & UART_LSR_FE)
170 }
while ((*status &
UART_LSR_DR) && (max_count-- > 0));
189 if (up->
port.x_char) {
191 up->
port.icount.tx++;
196 serial_pxa_stop_tx(&up->
port);
200 count = up->
port.fifosize / 2;
204 up->
port.icount.tx++;
207 }
while (--count > 0);
214 serial_pxa_stop_tx(&up->
port);
217 static void serial_pxa_start_tx(
struct uart_port *port)
227 static inline void check_modem_status(
struct uart_pxa_port *up)
237 up->
port.icount.rng++;
239 up->
port.icount.dsr++;
254 unsigned int iir, lsr;
260 if (lsr & UART_LSR_DR)
261 receive_chars(up, &lsr);
262 check_modem_status(up);
268 static unsigned int serial_pxa_tx_empty(
struct uart_port *port)
276 spin_unlock_irqrestore(&up->
port.lock, flags);
281 static unsigned int serial_pxa_get_mctrl(
struct uart_port *port)
301 static void serial_pxa_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
304 unsigned char mcr = 0;
322 static void serial_pxa_break_ctl(
struct uart_port *port,
int break_state)
328 if (break_state == -1)
333 spin_unlock_irqrestore(&up->
port.lock, flags);
337 static void serial_pxa_dma_init(
struct pxa_uart *up)
361 static int serial_pxa_startup(
struct uart_port *port)
405 serial_pxa_set_mctrl(&up->
port, up->
port.mctrl);
406 spin_unlock_irqrestore(&up->
port.lock, flags);
427 static void serial_pxa_shutdown(
struct uart_port *port)
441 up->
port.mctrl &= ~TIOCM_OUT2;
442 serial_pxa_set_mctrl(&up->
port, up->
port.mctrl);
443 spin_unlock_irqrestore(&up->
port.lock, flags);
460 unsigned char cval,
fcr = 0;
462 unsigned int baud, quot;
494 if ((up->
port.uartclk / quot) < (2400 * 16))
496 else if ((up->
port.uartclk / quot) < (230400 * 16))
527 up->
port.ignore_status_mask = 0;
561 serial_out(up,
UART_DLL, quot & 0xff);
570 serial_out(up,
UART_DLM, quot >> 8);
573 serial_pxa_set_mctrl(&up->
port, up->
port.mctrl);
575 spin_unlock_irqrestore(&up->
port.lock, flags);
580 unsigned int oldstate)
585 clk_prepare_enable(up->
clk);
587 clk_disable_unprepare(up->
clk);
590 static void serial_pxa_release_port(
struct uart_port *port)
594 static int serial_pxa_request_port(
struct uart_port *port)
599 static void serial_pxa_config_port(
struct uart_port *port,
int flags)
622 #ifdef CONFIG_SERIAL_PXA_CONSOLE
624 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
631 unsigned int status, tmout = 10000;
637 if (status & UART_LSR_BI)
643 }
while ((status &
BOTH_EMPTY) != BOTH_EMPTY);
654 static void serial_pxa_console_putchar(
struct uart_port *port,
int ch)
669 serial_pxa_console_write(
struct console *co,
const char *
s,
unsigned int count)
676 clk_prepare_enable(up->
clk);
682 locked = spin_trylock(&up->
port.lock);
684 spin_lock(&up->
port.lock);
702 spin_unlock(&up->
port.lock);
705 clk_disable_unprepare(up->
clk);
717 if (co->
index == -1 || co->
index >= serial_pxa_reg.nr)
719 up = serial_pxa_ports[co->
index];
729 static struct console serial_pxa_console = {
731 .write = serial_pxa_console_write,
733 .setup = serial_pxa_console_setup,
736 .data = &serial_pxa_reg,
739 #define PXA_CONSOLE &serial_pxa_console
741 #define PXA_CONSOLE NULL
745 .tx_empty = serial_pxa_tx_empty,
746 .set_mctrl = serial_pxa_set_mctrl,
747 .get_mctrl = serial_pxa_get_mctrl,
748 .stop_tx = serial_pxa_stop_tx,
749 .start_tx = serial_pxa_start_tx,
750 .stop_rx = serial_pxa_stop_rx,
751 .enable_ms = serial_pxa_enable_ms,
752 .break_ctl = serial_pxa_break_ctl,
753 .startup = serial_pxa_startup,
754 .shutdown = serial_pxa_shutdown,
755 .set_termios = serial_pxa_set_termios,
757 .type = serial_pxa_type,
758 .release_port = serial_pxa_release_port,
759 .request_port = serial_pxa_request_port,
760 .config_port = serial_pxa_config_port,
761 .verify_port = serial_pxa_verify_port,
766 .driver_name =
"PXA serial",
775 static int serial_pxa_suspend(
struct device *
dev)
785 static int serial_pxa_resume(
struct device *dev)
795 static const struct dev_pm_ops serial_pxa_pm_ops = {
797 .resume = serial_pxa_resume,
802 { .compatible =
"mrvl,pxa-uart", },
803 { .compatible =
"mrvl,mmp-uart", },
819 dev_err(&pdev->
dev,
"failed to get alias id, errno %d\n", ret);
834 if (!mmres || !irqres)
842 if (IS_ERR(sport->
clk)) {
843 ret = PTR_ERR(sport->
clk);
851 sport->
port.fifosize = 64;
857 ret = serial_pxa_probe_dt(dev, sport);
859 sport->
port.line = dev->
id;
865 if (!sport->
port.membase) {
870 serial_pxa_ports[sport->
port.line] = sport;
873 platform_set_drvdata(dev, sport);
888 platform_set_drvdata(dev,
NULL);
898 .probe = serial_pxa_probe,
899 .remove = serial_pxa_remove,
902 .name =
"pxa2xx-uart",
905 .pm = &serial_pxa_pm_ops,
907 .of_match_table = serial_pxa_dt_ids,