23 #if defined(CONFIG_SERIAL_OMAP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
27 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/tty.h>
38 #include <linux/serial_core.h>
47 #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y))
49 #define OMAP_UART_REV_42 0x0402
50 #define OMAP_UART_REV_46 0x0406
51 #define OMAP_UART_REV_52 0x0502
52 #define OMAP_UART_REV_63 0x0603
54 #define DEFAULT_CLK_SPEED 48000000
57 #define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7)
60 #define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6)
61 #define OMAP_UART_FCR_TX_FIFO_TRIG_MASK (0x3 << 4)
64 #define OMAP_UART_MVR_SCHEME_SHIFT 30
66 #define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0
67 #define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4
68 #define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f
70 #define OMAP_UART_MVR_MAJ_MASK 0x700
71 #define OMAP_UART_MVR_MAJ_SHIFT 8
72 #define OMAP_UART_MVR_MIN_MASK 0x3f
115 #define to_uart_omap_port(p) ((container_of((p), struct uart_omap_port, port)))
126 offset <<= up->
port.regshift;
132 offset <<= up->
port.regshift;
209 static void serial_omap_enable_ms(
struct uart_port *port)
215 pm_runtime_get_sync(up->
dev);
218 pm_runtime_mark_last_busy(up->
dev);
219 pm_runtime_put_autosuspend(up->
dev);
222 static void serial_omap_stop_tx(
struct uart_port *port)
226 pm_runtime_get_sync(up->
dev);
232 serial_omap_set_forceidle(up);
234 pm_runtime_mark_last_busy(up->
dev);
235 pm_runtime_put_autosuspend(up->
dev);
238 static void serial_omap_stop_rx(
struct uart_port *port)
242 pm_runtime_get_sync(up->
dev);
246 pm_runtime_mark_last_busy(up->
dev);
247 pm_runtime_put_autosuspend(up->
dev);
250 static void transmit_chars(
struct uart_omap_port *up,
unsigned int lsr)
258 if (up->
port.x_char) {
260 up->
port.icount.tx++;
265 serial_omap_stop_tx(&up->
port);
268 count = up->
port.fifosize / 4;
272 up->
port.icount.tx++;
275 }
while (--count > 0);
278 spin_unlock(&up->
port.lock);
280 spin_lock(&up->
port.lock);
284 serial_omap_stop_tx(&up->
port);
287 static inline void serial_omap_enable_ier_thri(
struct uart_omap_port *up)
295 static void serial_omap_start_tx(
struct uart_port *port)
299 pm_runtime_get_sync(up->
dev);
300 serial_omap_enable_ier_thri(up);
301 serial_omap_set_noidle(up);
302 pm_runtime_mark_last_busy(up->
dev);
303 pm_runtime_put_autosuspend(up->
dev);
319 up->
port.icount.rng++;
321 up->
port.icount.dsr++;
334 static void serial_omap_rlsi(
struct uart_omap_port *up,
unsigned int lsr)
337 unsigned char ch = 0;
342 up->
port.icount.rx++;
348 up->
port.icount.brk++;
355 if (uart_handle_break(&up->
port))
362 up->
port.icount.parity++;
367 up->
port.icount.frame++;
371 up->
port.icount.overrun++;
373 #ifdef CONFIG_SERIAL_OMAP_CONSOLE
374 if (up->
port.line == up->
port.cons->index) {
382 static void serial_omap_rdi(
struct uart_omap_port *up,
unsigned int lsr)
384 unsigned char ch = 0;
387 if (!(lsr & UART_LSR_DR))
392 up->
port.icount.rx++;
409 unsigned int iir, lsr;
414 spin_lock(&up->
port.lock);
415 pm_runtime_get_sync(up->
dev);
430 check_modem_status(up);
433 transmit_chars(up, lsr);
438 serial_omap_rdi(up, lsr);
441 serial_omap_rlsi(up, lsr);
451 }
while (!(iir & UART_IIR_NO_INT) && max_count--);
453 spin_unlock(&up->
port.lock);
457 pm_runtime_mark_last_busy(up->
dev);
458 pm_runtime_put_autosuspend(up->
dev);
464 static unsigned int serial_omap_tx_empty(
struct uart_port *port)
467 unsigned long flags = 0;
468 unsigned int ret = 0;
470 pm_runtime_get_sync(up->
dev);
474 spin_unlock_irqrestore(&up->
port.lock, flags);
475 pm_runtime_mark_last_busy(up->
dev);
476 pm_runtime_put_autosuspend(up->
dev);
480 static unsigned int serial_omap_get_mctrl(
struct uart_port *port)
484 unsigned int ret = 0;
486 pm_runtime_get_sync(up->
dev);
487 status = check_modem_status(up);
488 pm_runtime_mark_last_busy(up->
dev);
489 pm_runtime_put_autosuspend(up->
dev);
504 static void serial_omap_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
507 unsigned char mcr = 0;
521 pm_runtime_get_sync(up->
dev);
525 pm_runtime_mark_last_busy(up->
dev);
526 pm_runtime_put_autosuspend(up->
dev);
539 static void serial_omap_break_ctl(
struct uart_port *port,
int break_state)
542 unsigned long flags = 0;
545 pm_runtime_get_sync(up->
dev);
547 if (break_state == -1)
552 spin_unlock_irqrestore(&up->
port.lock, flags);
553 pm_runtime_mark_last_busy(up->
dev);
554 pm_runtime_put_autosuspend(up->
dev);
557 static int serial_omap_startup(
struct uart_port *port)
560 unsigned long flags = 0;
573 pm_runtime_get_sync(up->
dev);
578 serial_omap_clear_fifos(up);
600 serial_omap_set_mctrl(&up->
port, up->
port.mctrl);
601 spin_unlock_irqrestore(&up->
port.lock, flags);
615 pm_runtime_mark_last_busy(up->
dev);
616 pm_runtime_put_autosuspend(up->
dev);
621 static void serial_omap_shutdown(
struct uart_port *port)
624 unsigned long flags = 0;
628 pm_runtime_get_sync(up->
dev);
636 up->
port.mctrl &= ~TIOCM_OUT2;
637 serial_omap_set_mctrl(&up->
port, up->
port.mctrl);
638 spin_unlock_irqrestore(&up->
port.lock, flags);
644 serial_omap_clear_fifos(up);
649 if (serial_in(up,
UART_LSR) & UART_LSR_DR)
652 pm_runtime_mark_last_busy(up->
dev);
653 pm_runtime_put_autosuspend(up->
dev);
658 serial_omap_configure_xonxoff
732 unsigned char cval = 0;
733 unsigned char efr = 0;
734 unsigned long flags = 0;
735 unsigned int baud, quot;
765 quot = serial_omap_get_divisor(port, baud);
772 up->
dll = quot & 0xff;
783 pm_runtime_get_sync(up->
dev);
800 up->
port.ignore_status_mask = 0;
873 serial_omap_mdr1_errataset(up, up->
mdr1);
896 if (baud > 230400 && baud != 3000000)
902 serial_omap_mdr1_errataset(up, up->
mdr1);
926 serial_omap_set_mctrl(&up->
port, up->
port.mctrl);
928 serial_omap_configure_xonxoff(up, termios);
930 spin_unlock_irqrestore(&up->
port.lock, flags);
931 pm_runtime_mark_last_busy(up->
dev);
932 pm_runtime_put_autosuspend(up->
dev);
936 static int serial_omap_set_wake(
struct uart_port *port,
unsigned int state)
940 serial_omap_enable_wakeup(up, state);
947 unsigned int oldstate)
954 pm_runtime_get_sync(up->
dev);
965 if (!device_may_wakeup(up->
dev)) {
972 pm_runtime_mark_last_busy(up->
dev);
973 pm_runtime_put_autosuspend(up->
dev);
976 static void serial_omap_release_port(
struct uart_port *port)
978 dev_dbg(port->
dev,
"serial_omap_release_port+\n");
981 static int serial_omap_request_port(
struct uart_port *port)
983 dev_dbg(port->
dev,
"serial_omap_request_port+\n");
987 static void serial_omap_config_port(
struct uart_port *port,
int flags)
991 dev_dbg(up->
port.dev,
"serial_omap_config_port+%d\n",
1000 dev_dbg(port->
dev,
"serial_omap_verify_port+\n");
1005 serial_omap_type(
struct uart_port *port)
1013 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
1017 unsigned int status, tmout = 10000;
1023 if (status & UART_LSR_BI)
1029 }
while ((status &
BOTH_EMPTY) != BOTH_EMPTY);
1034 for (tmout = 1000000; tmout; tmout--) {
1035 unsigned int msr = serial_in(up,
UART_MSR);
1046 #ifdef CONFIG_CONSOLE_POLL
1048 static void serial_omap_poll_put_char(
struct uart_port *port,
unsigned char ch)
1052 pm_runtime_get_sync(up->
dev);
1055 pm_runtime_mark_last_busy(up->
dev);
1056 pm_runtime_put_autosuspend(up->
dev);
1059 static int serial_omap_poll_get_char(
struct uart_port *port)
1064 pm_runtime_get_sync(up->
dev);
1066 if (!(status & UART_LSR_DR)) {
1071 status = serial_in(up,
UART_RX);
1074 pm_runtime_mark_last_busy(up->
dev);
1075 pm_runtime_put_autosuspend(up->
dev);
1082 #ifdef CONFIG_SERIAL_OMAP_CONSOLE
1088 static void serial_omap_console_putchar(
struct uart_port *port,
int ch)
1097 serial_omap_console_write(
struct console *co,
const char *
s,
1101 unsigned long flags;
1105 pm_runtime_get_sync(up->
dev);
1111 locked = spin_trylock(&up->
port.lock);
1113 spin_lock(&up->
port.lock);
1137 check_modem_status(up);
1139 pm_runtime_mark_last_busy(up->
dev);
1140 pm_runtime_put_autosuspend(up->
dev);
1142 spin_unlock(&up->
port.lock);
1155 if (serial_omap_console_ports[co->
index] ==
NULL)
1157 up = serial_omap_console_ports[co->
index];
1165 static struct console serial_omap_console = {
1167 .write = serial_omap_console_write,
1169 .setup = serial_omap_console_setup,
1172 .data = &serial_omap_reg,
1175 static void serial_omap_add_console_port(
struct uart_omap_port *up)
1177 serial_omap_console_ports[up->
port.line] =
up;
1180 #define OMAP_CONSOLE (&serial_omap_console)
1184 #define OMAP_CONSOLE NULL
1186 static inline void serial_omap_add_console_port(
struct uart_omap_port *up)
1191 static struct uart_ops serial_omap_pops = {
1192 .tx_empty = serial_omap_tx_empty,
1193 .set_mctrl = serial_omap_set_mctrl,
1194 .get_mctrl = serial_omap_get_mctrl,
1195 .stop_tx = serial_omap_stop_tx,
1196 .start_tx = serial_omap_start_tx,
1197 .stop_rx = serial_omap_stop_rx,
1198 .enable_ms = serial_omap_enable_ms,
1199 .break_ctl = serial_omap_break_ctl,
1200 .startup = serial_omap_startup,
1201 .shutdown = serial_omap_shutdown,
1202 .set_termios = serial_omap_set_termios,
1203 .pm = serial_omap_pm,
1204 .set_wake = serial_omap_set_wake,
1205 .type = serial_omap_type,
1206 .release_port = serial_omap_release_port,
1207 .request_port = serial_omap_request_port,
1208 .config_port = serial_omap_config_port,
1209 .verify_port = serial_omap_verify_port,
1210 #ifdef CONFIG_CONSOLE_POLL
1211 .poll_put_char = serial_omap_poll_put_char,
1212 .poll_get_char = serial_omap_poll_get_char,
1218 .driver_name =
"OMAP-SERIAL",
1224 #ifdef CONFIG_PM_SLEEP
1225 static int serial_omap_suspend(
struct device *
dev)
1235 static int serial_omap_resume(
struct device *
dev)
1271 "Unknown %s revision, defaulting to highest\n",
1306 of_property_read_u32(dev->
of_node,
"clock-frequency",
1308 return omap_up_info;
1318 if (pdev->
dev.of_node)
1319 omap_up_info = of_get_uart_port_info(&pdev->
dev);
1334 pdev->
dev.driver->name)) {
1335 dev_err(&pdev->
dev,
"memory region already claimed\n");
1339 if (gpio_is_valid(omap_up_info->
DTR_gpio) &&
1354 if (gpio_is_valid(omap_up_info->
DTR_gpio) &&
1368 up->
port.regshift = 2;
1369 up->
port.fifosize = 64;
1370 up->
port.ops = &serial_omap_pops;
1372 if (pdev->
dev.of_node)
1375 up->
port.line = pdev->
id;
1377 if (up->
port.line < 0) {
1378 dev_err(&pdev->
dev,
"failed to get alias/pdev id, errno %d\n",
1384 up->
pins = devm_pinctrl_get_select_default(&pdev->
dev);
1385 if (IS_ERR(up->
pins)) {
1386 dev_warn(&pdev->
dev,
"did not get pins for uart%i error: %li\n",
1394 resource_size(mem));
1395 if (!up->
port.membase) {
1403 if (!up->
port.uartclk) {
1405 dev_warn(&pdev->
dev,
"No clock speed specified: using default:"
1416 platform_set_drvdata(pdev, up);
1418 pm_runtime_use_autosuspend(&pdev->
dev);
1423 pm_runtime_get_sync(&pdev->
dev);
1425 omap_serial_fill_features_erratas(up);
1428 serial_omap_add_console_port(up);
1434 pm_runtime_mark_last_busy(up->
dev);
1435 pm_runtime_put_autosuspend(up->
dev);
1439 pm_runtime_put(&pdev->
dev);
1440 pm_runtime_disable(&pdev->
dev);
1443 dev_err(&pdev->
dev,
"[UART%d]: failure [%s]: %d\n",
1444 pdev->
id, __func__, ret);
1452 pm_runtime_put_sync(up->
dev);
1453 pm_runtime_disable(up->
dev);
1481 while (UART_LSR_THRE != (serial_in(up,
UART_LSR) &
1482 (UART_LSR_THRE | UART_LSR_DR))) {
1486 dev_crit(up->
dev,
"Errata i202: timedout %x\n",
1494 #ifdef CONFIG_PM_RUNTIME
1495 static void serial_omap_restore_context(
struct uart_omap_port *up)
1519 serial_omap_mdr1_errataset(up, up->
mdr1);
1524 static int serial_omap_runtime_suspend(
struct device *dev)
1537 if (device_may_wakeup(dev)) {
1539 serial_omap_enable_wakeup(up,
true);
1544 serial_omap_enable_wakeup(up,
false);
1555 static int serial_omap_runtime_resume(
struct device *dev)
1559 u32 loss_cnt = serial_omap_get_context_loss_count(up);
1562 serial_omap_restore_context(up);
1571 static const struct dev_pm_ops serial_omap_dev_pm_ops = {
1574 serial_omap_runtime_resume,
NULL)
1577 #if defined(CONFIG_OF)
1578 static const struct of_device_id omap_serial_of_match[] = {
1580 { .compatible =
"ti,omap3-uart" },
1581 { .compatible =
"ti,omap4-uart" },
1588 .probe = serial_omap_probe,
1592 .pm = &serial_omap_dev_pm_ops,
1597 static int __init serial_omap_init(
void)
1610 static void __exit serial_omap_exit(
void)