aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial/imx.c
AgeCommit message (Collapse)Author
2020-02-28tty: serial: imx: setup the correct sg entry for tx dmaFugang Duan
commit f76707831829530ffdd3888bebc108aecefccaa0 upstream. There has oops as below happen on i.MX8MP EVK platform that has 6G bytes DDR memory. when (xmit->tail < xmit->head) && (xmit->head == 0), it setups one sg entry with sg->length is zero: sg_set_buf(sgl + 1, xmit->buf, xmit->head); if xmit->buf is allocated from >4G address space, and SDMA only support <4G address space, then dma_map_sg() will call swiotlb_map() to do bounce buffer copying and mapping. But swiotlb_map() don't allow sg entry's length is zero, otherwise report BUG_ON(). So the patch is to correct the tx DMA scatter list. Oops: [ 287.675715] kernel BUG at kernel/dma/swiotlb.c:497! [ 287.680592] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 287.686075] Modules linked in: [ 287.689133] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.4.3-00016-g3fdc4e0-dirty #10 [ 287.696872] Hardware name: FSL i.MX8MP EVK (DT) [ 287.701402] pstate: 80000085 (Nzcv daIf -PAN -UAO) [ 287.706199] pc : swiotlb_tbl_map_single+0x1fc/0x310 [ 287.711076] lr : swiotlb_map+0x60/0x148 [ 287.714909] sp : ffff800010003c00 [ 287.718221] x29: ffff800010003c00 x28: 0000000000000000 [ 287.723533] x27: 0000000000000040 x26: ffff800011ae0000 [ 287.728844] x25: ffff800011ae09f8 x24: 0000000000000000 [ 287.734155] x23: 00000001b7af9000 x22: 0000000000000000 [ 287.739465] x21: ffff000176409c10 x20: 00000000001f7ffe [ 287.744776] x19: ffff000176409c10 x18: 000000000000002e [ 287.750087] x17: 0000000000000000 x16: 0000000000000000 [ 287.755397] x15: 0000000000000000 x14: 0000000000000000 [ 287.760707] x13: ffff00017f334000 x12: 0000000000000001 [ 287.766018] x11: 00000000001fffff x10: 0000000000000000 [ 287.771328] x9 : 0000000000000003 x8 : 0000000000000000 [ 287.776638] x7 : 0000000000000000 x6 : 0000000000000000 [ 287.781949] x5 : 0000000000200000 x4 : 0000000000000000 [ 287.787259] x3 : 0000000000000001 x2 : 00000001b7af9000 [ 287.792570] x1 : 00000000fbfff000 x0 : 0000000000000000 [ 287.797881] Call trace: [ 287.800328] swiotlb_tbl_map_single+0x1fc/0x310 [ 287.804859] swiotlb_map+0x60/0x148 [ 287.808347] dma_direct_map_page+0xf0/0x130 [ 287.812530] dma_direct_map_sg+0x78/0xe0 [ 287.816453] imx_uart_dma_tx+0x134/0x2f8 [ 287.820374] imx_uart_dma_tx_callback+0xd8/0x168 [ 287.824992] vchan_complete+0x194/0x200 [ 287.828828] tasklet_action_common.isra.0+0x154/0x1a0 [ 287.833879] tasklet_action+0x24/0x30 [ 287.837540] __do_softirq+0x120/0x23c [ 287.841202] irq_exit+0xb8/0xd8 [ 287.844343] __handle_domain_irq+0x64/0xb8 [ 287.848438] gic_handle_irq+0x5c/0x148 [ 287.852185] el1_irq+0xb8/0x180 [ 287.855327] cpuidle_enter_state+0x84/0x360 [ 287.859508] cpuidle_enter+0x34/0x48 [ 287.863083] call_cpuidle+0x18/0x38 [ 287.866571] do_idle+0x1e0/0x280 [ 287.869798] cpu_startup_entry+0x20/0x40 [ 287.873721] rest_init+0xd4/0xe0 [ 287.876949] arch_call_rest_init+0xc/0x14 [ 287.880958] start_kernel+0x420/0x44c [ 287.884622] Code: 9124c021 9417aff8 a94363f7 17ffffd5 (d4210000) [ 287.890718] ---[ end trace 5bc44c4ab6b009ce ]--- [ 287.895334] Kernel panic - not syncing: Fatal exception in interrupt [ 287.901686] SMP: stopping secondary CPUs [ 288.905607] SMP: failed to stop secondary CPUs 0-1 [ 288.910395] Kernel Offset: disabled [ 288.913882] CPU features: 0x0002,2000200c [ 288.917888] Memory Limit: none [ 288.920944] ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]--- Reported-by: Eagle Zhou <eagle.zhou@nxp.com> Tested-by: Eagle Zhou <eagle.zhou@nxp.com> Signed-off-by: Fugang Duan <fugang.duan@nxp.com> Cc: stable <stable@vger.kernel.org> Fixes: 7942f8577f2a ("serial: imx: TX DMA: clean up sg initialization") Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/1581401761-6378-1-git-send-email-fugang.duan@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-01serial: imx: fix a race condition in receive pathUwe Kleine-König
commit 101aa46bd221b768dfff8ef3745173fc8dbb85ee upstream. The main irq handler function starts by first masking disabled interrupts in the status register values to ensure to only handle enabled interrupts. This is important as when the RX path in the hardware is disabled reading the RX fifo results in an external abort. This checking must be done under the port lock, otherwise the following can happen: CPU1 | CPU2 | irq triggers as there are chars | in the RX fifo | | grab port lock imx_uart_int finds RRDY enabled | and calls imx_uart_rxint which | has to wait for port lock | | disable RX (e.g. because we're | using RS485 with !RX_DURING_TX) | | release port lock read from RX fifo with RX | disabled => exception | So take the port lock only once in imx_uart_int() instead of in the functions called from there. Reported-by: Andre Renaud <arenaud@designa-electronics.com> Cc: stable@vger.kernel.org Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20200121071702.20150-1-u.kleine-koenig@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-17tty: serial: imx: use the sg count from dma_map_sgPeng Fan
commit 596fd8dffb745afcebc0ec6968e17fe29f02044c upstream. The dmaengine_prep_slave_sg needs to use sg count returned by dma_map_sg, not use sport->dma_tx_nents, because the return value of dma_map_sg is not always same with "nents". Fixes: b4cdc8f61beb ("serial: imx: add DMA support for imx6q") Signed-off-by: Peng Fan <peng.fan@nxp.com> Link: https://lore.kernel.org/r/1573108875-26530-1-git-send-email-peng.fan@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-10-10tty: serial: imx: Use platform_get_irq_optional() for optional IRQsAnson Huang
All i.MX SoCs except i.MX1 have ONLY one necessary IRQ, use platform_get_irq_optional() to get second/third IRQ which are optional to avoid below error message during probe: [ 0.726219] imx-uart 30860000.serial: IRQ index 1 not found [ 0.731329] imx-uart 30860000.serial: IRQ index 2 not found Fixes: 7723f4c5ecdb8d83 ("driver core: platform: Add an error message to platform_get_irq*()") Signed-off-by: Anson Huang <Anson.Huang@nxp.com> Link: https://lore.kernel.org/r/1570614559-11900-1-git-send-email-Anson.Huang@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: use Tx ready rather than Tx empty irqSergey Organov
This should help to avoid unnecessary gaps in transmission while adding little overhead due to low default Tx threshold level (2 bytes). Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1567017475-11919-6-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: fix data breakage on termios changeSergey Organov
imx_set_termios(): avoid writing baud rate divider registers when the values to be written are the same as current. Any writing seems to restart transmission/receiving logic in the hardware, that leads to data breakage even when rate doesn't in fact change. E.g., user switches RTS/CTS handshake and suddenly gets broken bytes. Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1567017475-11919-5-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: do not disable individual irqs during termios changeSergey Organov
imx_set_termios(): disabling individual interrupt requests in UART for duration of the routine is pointless. Get rid of it. Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1567017475-11919-4-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: do not stop Rx/Tx on termios changeSergey Organov
imx_set_termios(): stopping receiver and transmitter does harm when something that doesn't touch transmission format/rate changes, such as RTS/CTS handshake. OTOH, it does no good on baud rate or format change, as synchronization on upper-level protocols is still required to do it right. Therefore, just stop doing it. Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1567017475-11919-3-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: get rid of unbounded busy-waiting loopSergey Organov
imx_set_termios(): remove busy-waiting "drain Tx FIFO" loop. Worse yet, it was potentially unbounded wait due to RTS/CTS (hardware) handshake. Let user space ensure draining is done before termios change, if draining is needed in the first place. Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1567017475-11919-2-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: get rid of imx_uart_rts_auto()Sergey Organov
Called in only one place, for RS232, it only obscures things, as it doesn't go well with 2 similar named functions, imx_uart_rts_inactive() and imx_uart_rts_active(), that both are RS485-specific. Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1564167161-3972-4-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: set_mctrl(): correctly restore autoRTS stateSergey Organov
imx_uart_set_mctrl() happened to set UCR2_CTSC bit whenever TIOCM_RTS was set, no matter if RTS/CTS handshake is enabled or not. Now fixed by turning handshake on only when CRTSCTS bit for the port is set. Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1564167161-3972-3-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-04serial: imx: set_termios(): do not enable autoRTS if RTS is unsetSergey Organov
Don't let receiver hardware automatically control RTS output if it was requested to be inactive. To ensure this, set_termios() shouldn't set UCR2_CTSC bit if UCR2_CTS (=TIOCM_RTS) is cleared. Added corresponding check in imx_uart_rts_auto() to fix this. Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1564167161-3972-2-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-03serial: imx: set_termios(): preserve RTS stateSergey Organov
imx_set_termios() cleared RTS on every call, now fixed. Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1561558293-7683-5-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-03serial: imx: set_termios(): clarify RTS/CTS bits calculationSergey Organov
Avoid repeating the same code for rs485 twice. Make it obvious we clear CRTSCTS bit in termios->c_cflag whenever sport->have_rtscts is false. Make it obvious we clear UCR2_IRTS whenever CRTSCTS is set. Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sergey Organov <sorganov@gmail.com> Link: https://lore.kernel.org/r/1561558293-7683-4-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-03serial: imx: set_termios(): factor-out 'ucr2' initial valueSergey Organov
Set common bits in a separate statement to make initialization explicit and not repeat the common part. Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sergey Organov <sorganov@gmail.com> Reviewed-by: Uwe Kleine-Knig <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/1561558293-7683-3-git-send-email-sorganov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-18serial: imx: fix locking in set_termios()Sergey Organov
imx_uart_set_termios() called imx_uart_rts_active(), or imx_uart_rts_inactive() before taking port->port.lock. As a consequence, sport->port.mctrl that these functions modify could have been changed without holding port->port.lock. Moved locking of port->port.lock above the calls to fix the issue. Signed-off-by: Sergey Organov <sorganov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-10serial: imx: Use dev_info() instead of pr_info()Fabio Estevam
dev_info() is more appropriate for printing messages inside drivers, so switch to dev_info(). Signed-off-by: Fabio Estevam <festevam@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-21serial: imx: remove log spamming error messageSascha Hauer
Each time the DMA engine signals a transaction error the driver prints a message at error level. Getting transaction errors is pretty much expected on baudrate mismatches and the correspoding error counters are increased in this case properly. Remove the error message which is possibly repeated at a very high rate which can lock up the whole system. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Fabio Estevam <festevam@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-27serial: imx: fix error handling in console_setupStefan Agner
The ipg clock only needs to be unprepared in case preparing per clock fails. The ipg clock has already disabled at the point. Fixes: 1cf93e0d5488 ("serial: imx: remove the uart_console() check") Signed-off-by: Stefan Agner <stefan@agner.ch> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-30Merge 4.19-rc6 into tty-nextGreg Kroah-Hartman
We want the tty/serial fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-20serial: imx: restore handshaking irq for imx1Uwe Kleine-König
Back in 2015 when irda was dropped from the driver imx1 was broken. This change reintroduces the support for the third interrupt of the UART. Fixes: afe9cbb1a6ad ("serial: imx: drop support for IRDA") Cc: stable <stable@vger.kernel.org> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-18tty: serial: imx: add pinctrl sleep/default mode switch for suspendAnson Huang
On some i.MX SoCs' low power mode, such as i.MX7D's LPSR(low power state retention), UART iomux settings will be lost, need to add pinctrl sleep/default mode switch during suspend/resume to make sure UART iomux settings are correct after resume. Signed-off-by: Anson Huang <Anson.Huang@nxp.com> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-18tty: serial: imx: add lock for registers save/restoreAnson Huang
In noirq suspend/resume stage with no_console_suspend enabled, imx_uart_console_write() may be called to print out log_buf message by printk(), so there will be race condition between imx_uart_console_write() and imx_uart_save/restore_context(), need to add lock to protect the registers save/restore operations. Signed-off-by: Anson Huang <Anson.Huang@nxp.com> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-18tty:serial:imx: use spin_lock instead of spin_lock_irqsave in isrjun qian
Before the program enters the uart ISR, the local interrupt has been disabled by the system, so it's not appropriate to use spin_lock_irqsave interface in the ISR. Signed-off-by: jun qian <hangdianqj@163.com> Reviewed-by: Barry Song <21cnbao@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-28tty: serial: imx: correct dma cookie statusRobin Gong
Correct to check the right rx dma cookie status in spit of it works because only one cookie is running in the current sdma. But it will not once sdma driver support multi cookies running based on virt-dma. Signed-off-by: Robin Gong <yibin.gong@nxp.com> Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Tested-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-06-28serial: imx: fix comment about UCR2_SRST and its handling for shadowingUwe Kleine-König
Initially when register shadowing was introduced (commit 3a0ab62f43de ("serial: imx: implement shadow registers for UCRx and UFCR")) the logic to handle UCR2_SRST was wrong but documented consistently. Later the handling was fixed, but the comment was not. This change makes up leeway for the latter. Fixes: 0aa821d846c0 ("serial: imx: fix cached UCR2 read on software reset") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-25serial: imx: disable UCR4_OREN on shutdownSebastian Reichel
UCR4_OREN is (depending on the configuration) enabled in startup, but is never disabled. Fix this by disabling it in shutdown. Reported-by: Nandor Han <nandor.han@ge.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-25serial: imx: drop CTS/RTS handling from shutdownSebastian Reichel
According to Documentation/serial/driver the shutdown function should not disable RTS, so drop it. Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-14serial: imx: dma_unmap_sg buffers on shutdownSebastian Reichel
This properly unmaps DMA SG on device shutdown. Reported-by: Nandor Han <nandor.han@ge.com> Suggested-by: Nandor Han <nandor.han@ge.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-14serial: imx: cleanup imx_uart_disable_dma()Sebastian Reichel
Remove unrelated CTSC/CTS disabling from imx_uart_disable_dma() and move it to imx_uart_shutdown(), which is the only user of the DMA disabling function. This should not change the driver's behaviour, but improves readability. After this change imx_uart_disable_dma() does the reverse thing of imx_uart_enable_dma(). Suggested-by: Nandor Han <nandor.han@ge.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-30Merge 4.17-rc3 into tty-nextGreg Kroah-Hartman
We want the tty and serial driver fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23serial: imx: fix cached UCR2 read on software resetStefan Agner
To reset the UART the SRST needs be cleared (low active). According to the documentation the bit will remain active for 4 module clocks until it is cleared (set to 1). Hence the real register need to be read in case the cached register indicates that the SRST bit is zero. This bug lead to wrong baudrate because the baud rate register got restored before reset completed in imx_flush_buffer. Fixes: 3a0ab62f43de ("serial: imx: implement shadow registers for UCRx and UFCR") Signed-off-by: Stefan Agner <stefan@agner.ch> Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23serial: imx: warn user when using unsupported configurationStefan Agner
When using half-duplex mode (which disables receiver during txing) the RTS signal cannot be driven low during transmission when using i.MX UART RTS/CTS control. This seems to be a limitation of the i.MX UART IP: The RTS (CTS_B) signal is controlled by the receiver. When the receiver is disabled, the signal stays in UART logic idle state which is high... If SER_RS485_RTS_ON_SEND is used, RTS needs to be high active during transmission. Since this is the default state of the RTS (CTS_B) signal when the receiver is off, half-duplex mode in this configuration works fine. However, a low-active RTS signal (flag SER_RS485_RTS_ON_SEND not set) cannot be generated when the receiver is turned off. Print an error if the user selects this unsupported configuration (both SER_RS485_RTS_ON_SEND and SER_RS485_RX_DURING_TX unset) and configure the closest working configuration (set the SER_RS485_RX_DURING_TX flag). Signed-off-by: Stefan Agner <stefan@agner.ch> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-22tty: serial: simplify getting .drvdataWolfram Sang
We should get drvdata from struct device directly. Going via platform_device is an unneeded step back and forth. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Michal Simek <michal.simek@xilinx.com> Acked-by: Patrice Chotard <patrice.chotard@st.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-20Merge 4.16-rc6 into tty-nextGreg Kroah-Hartman
We want the serial/tty fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: consistently use imx_uart_ as prefix for all functionsUwe Kleine-König
Having a fixed prefix helps at several places. It ensures that another driver doesn't use the same function name which confuses the linker and tools like ctags. It simplifies working with function tracing and dynamic printk() support which can filter on function names. And last but not least it helps the human source code reader to understand if a given function belongs to a driver or a more general part of the kernel. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: don't prepare to send if no data is availableUwe Kleine-König
serial_core might call the .start_tx callback without any data being available to send. In this case return early instead of going through all the setup needed for sending which might include disabling RX in RS485 half-duplex mode. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: Fix handling of TC irq in combination with DMAUwe Kleine-König
When using RS485 half duplex the Transmitter Complete irq is needed to determine the moment when the transmitter can be disabled. When using DMA this irq must only be enabled when DMA has completed to transfer all data. Otherwise the CPU might busily trigger this irq which is not properly handled and so the also pending irq for the DMA transfer cannot trigger. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: Also enable the aging timer in PIO modeUwe Kleine-König
This allows to increase the RX waterlevel which allows to delay the RRDY irq. The desired effect is that less irqs are needed to handle characters and so reduce irq count of the system. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: ensure that RX irqs are off if RX is offUwe Kleine-König
Make sure that UCR1.RXDMAEN and UCR1.ATDMAEN (for the DMA case) and UCR1.RRDYEN (for the PIO case) are off iff UCR1.RXEN is disabled. This ensures that the fifo isn't read with RX disabled which results in an exception. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: Stop to receive in .stop_rx()Uwe Kleine-König
When the UART is used in DMA mode, .stop_rx() does nothing if the port isn't suspended. This is wrong as .stop_rx() should stop receiving characters unconditionally. When the port is about to be closed the DMA channel is stopped in .shutdown(), so this isn't necessary to be in .stop_rx() here, too. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: setup fifo waterlevel before enabling aging timerUwe Kleine-König
The aging timer fires if there are characters in the RX fifo but the water level isn't reached yet. Make sure that the waterlevel is configured before the aging timer is enabled to trigger a DMA request (UCR1_ATDMAEN). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: use u32 variables with matching names for registersUwe Kleine-König
The serial/imx driver is full of inconsistently named and typed variables that hold different register values. Consistently use u32 as type (matching what readl and writel use) and name the variables after the register whose value they are holding. This makes it easier to notice when UCR2_RTSEN is written to UCR1. The only difference introduced by this commit in the compiled driver is that twice the second argument to warn_slowpath_null() changed because the two WARN_ON in dma_rx_callback() pass __LINE__ to warn_slowpath_null(). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: simplify check that prevents starting PIO when DMA is in useUwe Kleine-König
The original code looks as follows: if (sport->dma_is_enabled) { ... make sure TX DMA is running, i.e. .dma_is_txing = 1 } if (sport->dma_is_txing) return; As .dma_is_txing can only be true if .dma_is_enabled is, the return can go at the end of the first if body without an additional check. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: simplify some conditions related to dmaUwe Kleine-König
Neither .dma_is_txing nor .dma_is_rxing can evaluate to true if .dma_is_enabled evaluates to false: The only function that sets .dma_is_txing to a non-zero value is imx_dma_tx() which is only called if .dma_is_enabled is true. Same for .dma_is_rxing and start_rx_dma(). And before .dma_is_enabled is set to 0 when imx_shutdown calls imx_disable_dma(), .dma_is_rxing and .dma_is_txing are reset to zero before, too. For this reason sport->dma_is_enabled && sport->dma_is_rxing has the same value as sport->dma_is_rxing which allows to simplify three if conditions. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: implement shadow registers for UCRx and UFCRUwe Kleine-König
This reduces the amount of read accesses to the register space by shadowing the values for five registers that only change on writing them. There is a single bit in UCR2 that might change without being written to it, this is handled accordingly. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09serial: imx: add wrappers for writel and readlUwe Kleine-König
This prepares implementing shadow copies for the control registers and additionally provides a good place to hook in debug code to trace register usage. Most of this patch was done using pattern substitution: perl -p -i -e ' s/\breadl(?:_relaxed)?\((?:sport->port\.|port->)membase \+/imx_uart_readl(sport,/; s/\bwritel(?:_relaxed)?\(([^,]*), (sport->port\.|port->)membase \+/imx_uart_writel(sport, $1,/; ' drivers/tty/serial/imx.c Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-02-28serial: imx: document functions that are called with port.lock takenUwe Kleine-König
Consistently indicate being called with irqs off and the port lock taken for all functions that this applies to. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-02-28serial: imx: Rename register fields to match newer reference manualsUwe Kleine-König
Only the reference manual for the i.MX1 (I have MC9328MX1RM/D Rev 5 from 2004) uses TDMAEN and RDMAEN for these. All reference manuals for the newer chips use TXDMAEN and RXDMAEN. Update to the newer name with the assumption that most imx users don't use an imx1 any more. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-02-28serial: imx: Fix out-of-bounds access through serial port indexGeert Uytterhoeven
The imx_ports[] array is indexed using a value derived from the "serialN" alias in DT, or from platform data, which may lead to an out-of-bounds access. Fix this by adding a range check. Fixes: ff05967a07225ab6 ("serial/imx: add of_alias_get_id() reference back") Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>