.. | .. |
---|
16 | 16 | * this driver as required for the omap-platform. |
---|
17 | 17 | */ |
---|
18 | 18 | |
---|
19 | | -#if defined(CONFIG_SERIAL_OMAP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
---|
20 | | -#define SUPPORT_SYSRQ |
---|
21 | | -#endif |
---|
22 | | - |
---|
23 | 19 | #include <linux/module.h> |
---|
24 | 20 | #include <linux/init.h> |
---|
25 | 21 | #include <linux/console.h> |
---|
.. | .. |
---|
37 | 33 | #include <linux/pm_wakeirq.h> |
---|
38 | 34 | #include <linux/of.h> |
---|
39 | 35 | #include <linux/of_irq.h> |
---|
40 | | -#include <linux/gpio.h> |
---|
41 | | -#include <linux/of_gpio.h> |
---|
| 36 | +#include <linux/gpio/consumer.h> |
---|
42 | 37 | #include <linux/platform_data/serial-omap.h> |
---|
43 | | - |
---|
44 | | -#include <dt-bindings/gpio/gpio.h> |
---|
45 | 38 | |
---|
46 | 39 | #define OMAP_MAX_HSUART_PORTS 10 |
---|
47 | 40 | |
---|
.. | .. |
---|
159 | 152 | u32 errata; |
---|
160 | 153 | u32 features; |
---|
161 | 154 | |
---|
162 | | - int rts_gpio; |
---|
| 155 | + struct gpio_desc *rts_gpiod; |
---|
163 | 156 | |
---|
164 | 157 | struct pm_qos_request pm_qos_request; |
---|
165 | 158 | u32 latency; |
---|
166 | 159 | u32 calc_latency; |
---|
167 | 160 | struct work_struct qos_work; |
---|
168 | 161 | bool is_suspending; |
---|
| 162 | + |
---|
| 163 | + unsigned int rs485_tx_filter_count; |
---|
169 | 164 | }; |
---|
170 | 165 | |
---|
171 | 166 | #define to_uart_omap_port(p) ((container_of((p), struct uart_omap_port, port))) |
---|
.. | .. |
---|
309 | 304 | serial_out(up, UART_OMAP_SCR, up->scr); |
---|
310 | 305 | res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ? |
---|
311 | 306 | 1 : 0; |
---|
312 | | - if (gpio_get_value(up->rts_gpio) != res) { |
---|
| 307 | + if (up->rts_gpiod && |
---|
| 308 | + gpiod_get_value(up->rts_gpiod) != res) { |
---|
313 | 309 | if (port->rs485.delay_rts_after_send > 0) |
---|
314 | 310 | mdelay( |
---|
315 | 311 | port->rs485.delay_rts_after_send); |
---|
316 | | - gpio_set_value(up->rts_gpio, res); |
---|
| 312 | + gpiod_set_value(up->rts_gpiod, res); |
---|
317 | 313 | } |
---|
318 | 314 | } else { |
---|
319 | 315 | /* We're asked to stop, but there's still stuff in the |
---|
.. | .. |
---|
332 | 328 | |
---|
333 | 329 | if (up->ier & UART_IER_THRI) { |
---|
334 | 330 | up->ier &= ~UART_IER_THRI; |
---|
335 | | - serial_out(up, UART_IER, up->ier); |
---|
336 | | - } |
---|
337 | | - |
---|
338 | | - if ((port->rs485.flags & SER_RS485_ENABLED) && |
---|
339 | | - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { |
---|
340 | | - /* |
---|
341 | | - * Empty the RX FIFO, we are not interested in anything |
---|
342 | | - * received during the half-duplex transmission. |
---|
343 | | - */ |
---|
344 | | - serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_RCVR); |
---|
345 | | - /* Re-enable RX interrupts */ |
---|
346 | | - up->ier |= UART_IER_RLSI | UART_IER_RDI; |
---|
347 | | - up->port.read_status_mask |= UART_LSR_DR; |
---|
348 | 331 | serial_out(up, UART_IER, up->ier); |
---|
349 | 332 | } |
---|
350 | 333 | |
---|
.. | .. |
---|
373 | 356 | serial_out(up, UART_TX, up->port.x_char); |
---|
374 | 357 | up->port.icount.tx++; |
---|
375 | 358 | up->port.x_char = 0; |
---|
| 359 | + if ((up->port.rs485.flags & SER_RS485_ENABLED) && |
---|
| 360 | + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) |
---|
| 361 | + up->rs485_tx_filter_count++; |
---|
| 362 | + |
---|
376 | 363 | return; |
---|
377 | 364 | } |
---|
378 | 365 | if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { |
---|
.. | .. |
---|
384 | 371 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); |
---|
385 | 372 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
---|
386 | 373 | up->port.icount.tx++; |
---|
| 374 | + if ((up->port.rs485.flags & SER_RS485_ENABLED) && |
---|
| 375 | + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) |
---|
| 376 | + up->rs485_tx_filter_count++; |
---|
| 377 | + |
---|
387 | 378 | if (uart_circ_empty(xmit)) |
---|
388 | 379 | break; |
---|
389 | 380 | } while (--count > 0); |
---|
.. | .. |
---|
418 | 409 | |
---|
419 | 410 | /* if rts not already enabled */ |
---|
420 | 411 | res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0; |
---|
421 | | - if (gpio_get_value(up->rts_gpio) != res) { |
---|
422 | | - gpio_set_value(up->rts_gpio, res); |
---|
| 412 | + if (up->rts_gpiod && gpiod_get_value(up->rts_gpiod) != res) { |
---|
| 413 | + gpiod_set_value(up->rts_gpiod, res); |
---|
423 | 414 | if (port->rs485.delay_rts_before_send > 0) |
---|
424 | 415 | mdelay(port->rs485.delay_rts_before_send); |
---|
425 | 416 | } |
---|
.. | .. |
---|
427 | 418 | |
---|
428 | 419 | if ((port->rs485.flags & SER_RS485_ENABLED) && |
---|
429 | 420 | !(port->rs485.flags & SER_RS485_RX_DURING_TX)) |
---|
430 | | - serial_omap_stop_rx(port); |
---|
| 421 | + up->rs485_tx_filter_count = 0; |
---|
431 | 422 | |
---|
432 | 423 | serial_omap_enable_ier_thri(up); |
---|
433 | 424 | pm_runtime_mark_last_busy(up->dev); |
---|
.. | .. |
---|
493 | 484 | static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr) |
---|
494 | 485 | { |
---|
495 | 486 | unsigned int flag; |
---|
496 | | - unsigned char ch = 0; |
---|
497 | 487 | |
---|
498 | | - if (likely(lsr & UART_LSR_DR)) |
---|
499 | | - ch = serial_in(up, UART_RX); |
---|
| 488 | + /* |
---|
| 489 | + * Read one data character out to avoid stalling the receiver according |
---|
| 490 | + * to the table 23-246 of the omap4 TRM. |
---|
| 491 | + */ |
---|
| 492 | + if (likely(lsr & UART_LSR_DR)) { |
---|
| 493 | + serial_in(up, UART_RX); |
---|
| 494 | + if ((up->port.rs485.flags & SER_RS485_ENABLED) && |
---|
| 495 | + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX) && |
---|
| 496 | + up->rs485_tx_filter_count) |
---|
| 497 | + up->rs485_tx_filter_count--; |
---|
| 498 | + } |
---|
500 | 499 | |
---|
501 | 500 | up->port.icount.rx++; |
---|
502 | 501 | flag = TTY_NORMAL; |
---|
.. | .. |
---|
547 | 546 | return; |
---|
548 | 547 | |
---|
549 | 548 | ch = serial_in(up, UART_RX); |
---|
| 549 | + if ((up->port.rs485.flags & SER_RS485_ENABLED) && |
---|
| 550 | + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX) && |
---|
| 551 | + up->rs485_tx_filter_count) { |
---|
| 552 | + up->rs485_tx_filter_count--; |
---|
| 553 | + return; |
---|
| 554 | + } |
---|
| 555 | + |
---|
550 | 556 | flag = TTY_NORMAL; |
---|
551 | 557 | up->port.icount.rx++; |
---|
552 | 558 | |
---|
.. | .. |
---|
591 | 597 | transmit_chars(up, lsr); |
---|
592 | 598 | break; |
---|
593 | 599 | case UART_IIR_RX_TIMEOUT: |
---|
594 | | - /* FALLTHROUGH */ |
---|
595 | 600 | case UART_IIR_RDI: |
---|
596 | 601 | serial_omap_rdi(up, lsr); |
---|
597 | 602 | break; |
---|
.. | .. |
---|
602 | 607 | /* simply try again */ |
---|
603 | 608 | break; |
---|
604 | 609 | case UART_IIR_XOFF: |
---|
605 | | - /* FALLTHROUGH */ |
---|
606 | 610 | default: |
---|
607 | 611 | break; |
---|
608 | 612 | } |
---|
.. | .. |
---|
832 | 836 | struct uart_omap_port *up = container_of(work, struct uart_omap_port, |
---|
833 | 837 | qos_work); |
---|
834 | 838 | |
---|
835 | | - pm_qos_update_request(&up->pm_qos_request, up->latency); |
---|
| 839 | + cpu_latency_qos_update_request(&up->pm_qos_request, up->latency); |
---|
836 | 840 | } |
---|
837 | 841 | |
---|
838 | 842 | static void |
---|
.. | .. |
---|
1307 | 1311 | |
---|
1308 | 1312 | pm_runtime_get_sync(up->dev); |
---|
1309 | 1313 | |
---|
1310 | | - if (up->port.sysrq || oops_in_progress) |
---|
1311 | | - locked = spin_trylock_irqsave(&up->port.lock, flags); |
---|
| 1314 | + local_irq_save(flags); |
---|
| 1315 | + if (up->port.sysrq) |
---|
| 1316 | + locked = 0; |
---|
| 1317 | + else if (oops_in_progress) |
---|
| 1318 | + locked = spin_trylock(&up->port.lock); |
---|
1312 | 1319 | else |
---|
1313 | | - spin_lock_irqsave(&up->port.lock, flags); |
---|
| 1320 | + spin_lock(&up->port.lock); |
---|
1314 | 1321 | |
---|
1315 | 1322 | /* |
---|
1316 | 1323 | * First save the IER then disable the interrupts |
---|
.. | .. |
---|
1339 | 1346 | pm_runtime_mark_last_busy(up->dev); |
---|
1340 | 1347 | pm_runtime_put_autosuspend(up->dev); |
---|
1341 | 1348 | if (locked) |
---|
1342 | | - spin_unlock_irqrestore(&up->port.lock, flags); |
---|
| 1349 | + spin_unlock(&up->port.lock); |
---|
| 1350 | + local_irq_restore(flags); |
---|
1343 | 1351 | } |
---|
1344 | 1352 | |
---|
1345 | 1353 | static int __init |
---|
.. | .. |
---|
1409 | 1417 | /* store new config */ |
---|
1410 | 1418 | port->rs485 = *rs485; |
---|
1411 | 1419 | |
---|
1412 | | - /* |
---|
1413 | | - * Just as a precaution, only allow rs485 |
---|
1414 | | - * to be enabled if the gpio pin is valid |
---|
1415 | | - */ |
---|
1416 | | - if (gpio_is_valid(up->rts_gpio)) { |
---|
| 1420 | + if (up->rts_gpiod) { |
---|
1417 | 1421 | /* enable / disable rts */ |
---|
1418 | 1422 | val = (port->rs485.flags & SER_RS485_ENABLED) ? |
---|
1419 | 1423 | SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND; |
---|
1420 | 1424 | val = (port->rs485.flags & val) ? 1 : 0; |
---|
1421 | | - gpio_set_value(up->rts_gpio, val); |
---|
1422 | | - } else |
---|
1423 | | - port->rs485.flags &= ~SER_RS485_ENABLED; |
---|
| 1425 | + gpiod_set_value(up->rts_gpiod, val); |
---|
| 1426 | + } |
---|
1424 | 1427 | |
---|
1425 | 1428 | /* Enable interrupts */ |
---|
1426 | 1429 | up->ier = mode; |
---|
.. | .. |
---|
1595 | 1598 | } |
---|
1596 | 1599 | |
---|
1597 | 1600 | static int serial_omap_probe_rs485(struct uart_omap_port *up, |
---|
1598 | | - struct device_node *np) |
---|
| 1601 | + struct device *dev) |
---|
1599 | 1602 | { |
---|
1600 | 1603 | struct serial_rs485 *rs485conf = &up->port.rs485; |
---|
| 1604 | + struct device_node *np = dev->of_node; |
---|
| 1605 | + enum gpiod_flags gflags; |
---|
1601 | 1606 | int ret; |
---|
1602 | 1607 | |
---|
1603 | 1608 | rs485conf->flags = 0; |
---|
1604 | | - up->rts_gpio = -EINVAL; |
---|
| 1609 | + up->rts_gpiod = NULL; |
---|
1605 | 1610 | |
---|
1606 | 1611 | if (!np) |
---|
1607 | 1612 | return 0; |
---|
1608 | 1613 | |
---|
1609 | | - uart_get_rs485_mode(up->dev, rs485conf); |
---|
| 1614 | + ret = uart_get_rs485_mode(&up->port); |
---|
| 1615 | + if (ret) |
---|
| 1616 | + return ret; |
---|
1610 | 1617 | |
---|
1611 | 1618 | if (of_property_read_bool(np, "rs485-rts-active-high")) { |
---|
1612 | 1619 | rs485conf->flags |= SER_RS485_RTS_ON_SEND; |
---|
.. | .. |
---|
1617 | 1624 | } |
---|
1618 | 1625 | |
---|
1619 | 1626 | /* check for tx enable gpio */ |
---|
1620 | | - up->rts_gpio = of_get_named_gpio(np, "rts-gpio", 0); |
---|
1621 | | - if (gpio_is_valid(up->rts_gpio)) { |
---|
1622 | | - ret = devm_gpio_request(up->dev, up->rts_gpio, "omap-serial"); |
---|
1623 | | - if (ret < 0) |
---|
| 1627 | + gflags = rs485conf->flags & SER_RS485_RTS_AFTER_SEND ? |
---|
| 1628 | + GPIOD_OUT_HIGH : GPIOD_OUT_LOW; |
---|
| 1629 | + up->rts_gpiod = devm_gpiod_get_optional(dev, "rts", gflags); |
---|
| 1630 | + if (IS_ERR(up->rts_gpiod)) { |
---|
| 1631 | + ret = PTR_ERR(up->rts_gpiod); |
---|
| 1632 | + if (ret == -EPROBE_DEFER) |
---|
1624 | 1633 | return ret; |
---|
1625 | | - ret = rs485conf->flags & SER_RS485_RTS_AFTER_SEND ? 1 : 0; |
---|
1626 | | - ret = gpio_direction_output(up->rts_gpio, ret); |
---|
1627 | | - if (ret < 0) |
---|
1628 | | - return ret; |
---|
1629 | | - } else if (up->rts_gpio == -EPROBE_DEFER) { |
---|
1630 | | - return -EPROBE_DEFER; |
---|
| 1634 | + /* |
---|
| 1635 | + * FIXME: the code historically ignored any other error than |
---|
| 1636 | + * -EPROBE_DEFER and just went on without GPIO. |
---|
| 1637 | + */ |
---|
| 1638 | + up->rts_gpiod = NULL; |
---|
1631 | 1639 | } else { |
---|
1632 | | - up->rts_gpio = -EINVAL; |
---|
| 1640 | + gpiod_set_consumer_name(up->rts_gpiod, "omap-serial"); |
---|
1633 | 1641 | } |
---|
1634 | 1642 | |
---|
1635 | 1643 | return 0; |
---|
.. | .. |
---|
1676 | 1684 | up->port.regshift = 2; |
---|
1677 | 1685 | up->port.fifosize = 64; |
---|
1678 | 1686 | up->port.ops = &serial_omap_pops; |
---|
| 1687 | + up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_OMAP_CONSOLE); |
---|
1679 | 1688 | |
---|
1680 | 1689 | if (pdev->dev.of_node) |
---|
1681 | 1690 | ret = of_alias_get_id(pdev->dev.of_node, "serial"); |
---|
.. | .. |
---|
1701 | 1710 | dev_info(up->port.dev, "no wakeirq for uart%d\n", |
---|
1702 | 1711 | up->port.line); |
---|
1703 | 1712 | |
---|
1704 | | - ret = serial_omap_probe_rs485(up, pdev->dev.of_node); |
---|
| 1713 | + ret = serial_omap_probe_rs485(up, &pdev->dev); |
---|
1705 | 1714 | if (ret < 0) |
---|
1706 | 1715 | goto err_rs485; |
---|
1707 | 1716 | |
---|
.. | .. |
---|
1718 | 1727 | DEFAULT_CLK_SPEED); |
---|
1719 | 1728 | } |
---|
1720 | 1729 | |
---|
1721 | | - up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
---|
1722 | | - up->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
---|
1723 | | - pm_qos_add_request(&up->pm_qos_request, |
---|
1724 | | - PM_QOS_CPU_DMA_LATENCY, up->latency); |
---|
| 1730 | + up->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; |
---|
| 1731 | + up->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; |
---|
| 1732 | + cpu_latency_qos_add_request(&up->pm_qos_request, up->latency); |
---|
1725 | 1733 | INIT_WORK(&up->qos_work, serial_omap_uart_qos_work); |
---|
1726 | 1734 | |
---|
1727 | 1735 | platform_set_drvdata(pdev, up); |
---|
.. | .. |
---|
1755 | 1763 | pm_runtime_dont_use_autosuspend(&pdev->dev); |
---|
1756 | 1764 | pm_runtime_put_sync(&pdev->dev); |
---|
1757 | 1765 | pm_runtime_disable(&pdev->dev); |
---|
1758 | | - pm_qos_remove_request(&up->pm_qos_request); |
---|
| 1766 | + cpu_latency_qos_remove_request(&up->pm_qos_request); |
---|
1759 | 1767 | device_init_wakeup(up->dev, false); |
---|
1760 | 1768 | err_rs485: |
---|
1761 | 1769 | err_port_line: |
---|
.. | .. |
---|
1773 | 1781 | pm_runtime_dont_use_autosuspend(up->dev); |
---|
1774 | 1782 | pm_runtime_put_sync(up->dev); |
---|
1775 | 1783 | pm_runtime_disable(up->dev); |
---|
1776 | | - pm_qos_remove_request(&up->pm_qos_request); |
---|
| 1784 | + cpu_latency_qos_remove_request(&up->pm_qos_request); |
---|
1777 | 1785 | device_init_wakeup(&dev->dev, false); |
---|
1778 | 1786 | |
---|
1779 | 1787 | return 0; |
---|
.. | .. |
---|
1865 | 1873 | |
---|
1866 | 1874 | serial_omap_enable_wakeup(up, true); |
---|
1867 | 1875 | |
---|
1868 | | - up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
---|
| 1876 | + up->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; |
---|
1869 | 1877 | schedule_work(&up->qos_work); |
---|
1870 | 1878 | |
---|
1871 | 1879 | return 0; |
---|