Lines Matching +full:use +full:- +full:sw +full:- +full:pm
1 // SPDX-License-Identifier: GPL-2.0+
19 #include <linux/dma-mapping.h>
44 #define MTK_UART_EFR_NO_SW_FC 0x0 /* no sw flow control */
45 #define MTK_UART_EFR_XON1_XOFF1 0xa /* XON1/XOFF1 as sw flow control */
46 #define MTK_UART_EFR_XON2_XOFF2 0x5 /* XON2/XOFF2 as sw flow control */
52 #define MTK_UART_ESCAPE_CHAR 0x77 /* Escape char added under sw fc */
94 struct uart_8250_dma *dma = up->dma; in mtk8250_dma_rx_complete()
95 struct mtk8250_data *data = up->port.private_data; in mtk8250_dma_rx_complete()
96 struct tty_port *tty_port = &up->port.state->port; in mtk8250_dma_rx_complete()
102 if (data->rx_status == DMA_RX_SHUTDOWN) in mtk8250_dma_rx_complete()
105 spin_lock_irqsave(&up->port.lock, flags); in mtk8250_dma_rx_complete()
107 dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); in mtk8250_dma_rx_complete()
108 total = dma->rx_size - state.residue; in mtk8250_dma_rx_complete()
111 if ((data->rx_pos + cnt) > dma->rx_size) in mtk8250_dma_rx_complete()
112 cnt = dma->rx_size - data->rx_pos; in mtk8250_dma_rx_complete()
114 ptr = (unsigned char *)(data->rx_pos + dma->rx_buf); in mtk8250_dma_rx_complete()
116 data->rx_pos += cnt; in mtk8250_dma_rx_complete()
119 ptr = (unsigned char *)(dma->rx_buf); in mtk8250_dma_rx_complete()
120 cnt = total - cnt; in mtk8250_dma_rx_complete()
122 data->rx_pos = cnt; in mtk8250_dma_rx_complete()
125 up->port.icount.rx += copied; in mtk8250_dma_rx_complete()
131 spin_unlock_irqrestore(&up->port.lock, flags); in mtk8250_dma_rx_complete()
136 struct uart_8250_dma *dma = up->dma; in mtk8250_rx_dma()
139 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, in mtk8250_rx_dma()
140 dma->rx_size, DMA_DEV_TO_MEM, in mtk8250_rx_dma()
147 desc->callback = mtk8250_dma_rx_complete; in mtk8250_rx_dma()
148 desc->callback_param = up; in mtk8250_rx_dma()
150 dma->rx_cookie = dmaengine_submit(desc); in mtk8250_rx_dma()
152 dma_async_issue_pending(dma->rxchan); in mtk8250_rx_dma()
157 struct uart_8250_dma *dma = up->dma; in mtk8250_dma_enable()
158 struct mtk8250_data *data = up->port.private_data; in mtk8250_dma_enable()
161 if (data->rx_status != DMA_RX_START) in mtk8250_dma_enable()
164 dma->rxconf.src_port_window_size = dma->rx_size; in mtk8250_dma_enable()
165 dma->rxconf.src_addr = dma->rx_addr; in mtk8250_dma_enable()
167 dma->txconf.dst_port_window_size = UART_XMIT_SIZE; in mtk8250_dma_enable()
168 dma->txconf.dst_addr = dma->tx_addr; in mtk8250_dma_enable()
179 if (dmaengine_slave_config(dma->rxchan, &dma->rxconf) != 0) in mtk8250_dma_enable()
181 if (dmaengine_slave_config(dma->txchan, &dma->txconf) != 0) in mtk8250_dma_enable()
184 data->rx_status = DMA_RX_RUNNING; in mtk8250_dma_enable()
185 data->rx_pos = 0; in mtk8250_dma_enable()
194 struct mtk8250_data *data = port->private_data; in mtk8250_startup()
198 up->dma = NULL; in mtk8250_startup()
200 if (up->dma) { in mtk8250_startup()
201 data->rx_status = DMA_RX_START; in mtk8250_startup()
202 uart_circ_clear(&port->state->xmit); in mtk8250_startup()
205 memset(&port->icount, 0, sizeof(port->icount)); in mtk8250_startup()
214 struct mtk8250_data *data = port->private_data; in mtk8250_shutdown()
216 if (up->dma) in mtk8250_shutdown()
217 data->rx_status = DMA_RX_SHUTDOWN; in mtk8250_shutdown()
235 struct uart_port *port = &up->port; in mtk8250_set_flow_ctrl()
276 /*enable sw flow control */ in mtk8250_set_flow_ctrl()
281 serial_out(up, MTK_UART_XON1, START_CHAR(port->state->port.tty)); in mtk8250_set_flow_ctrl()
282 serial_out(up, MTK_UART_XOFF1, STOP_CHAR(port->state->port.tty)); in mtk8250_set_flow_ctrl()
308 if (up->dma) { in mtk8250_set_termios()
310 devm_kfree(up->port.dev, up->dma); in mtk8250_set_termios()
311 up->dma = NULL; in mtk8250_set_termios()
334 * Mediatek UARTs use an extra highspeed register (MTK_UART_HIGHS) in mtk8250_set_termios()
339 * Some baudrates are not supported by the chip, so we use the next in mtk8250_set_termios()
347 port->uartclk / 16 / UART_DIV_MAX, in mtk8250_set_termios()
348 port->uartclk); in mtk8250_set_termios()
355 quot = DIV_ROUND_UP(port->uartclk, 256 * baud); in mtk8250_set_termios()
362 spin_lock_irqsave(&port->lock, flags); in mtk8250_set_termios()
365 * Update the per-port timeout. in mtk8250_set_termios()
367 uart_update_timeout(port, termios->c_cflag, baud); in mtk8250_set_termios()
369 /* set DLAB we have cval saved in up->lcr from the call to the core */ in mtk8250_set_termios()
370 serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); in mtk8250_set_termios()
374 serial_port_out(port, UART_LCR, up->lcr); in mtk8250_set_termios()
379 tmp = (port->uartclk / (baud * quot)) - 1; in mtk8250_set_termios()
382 (tmp >> 1) - 1); in mtk8250_set_termios()
385 fraction = ((port->uartclk * 100) / baud / quot) % 100; in mtk8250_set_termios()
398 if ((termios->c_cflag & CRTSCTS) && (!(termios->c_iflag & CRTSCTS))) in mtk8250_set_termios()
400 else if (termios->c_iflag & CRTSCTS) in mtk8250_set_termios()
408 up->port.cons->cflag = termios->c_cflag; in mtk8250_set_termios()
410 spin_unlock_irqrestore(&port->lock, flags); in mtk8250_set_termios()
419 struct uart_8250_port *up = serial8250_get_port(data->line); in mtk8250_runtime_suspend()
425 if (data->clk_count == 0U) { in mtk8250_runtime_suspend()
428 clk_disable_unprepare(data->bus_clk); in mtk8250_runtime_suspend()
429 data->clk_count--; in mtk8250_runtime_suspend()
440 if (data->clk_count > 0U) { in mtk8250_runtime_resume()
442 data->clk_count); in mtk8250_runtime_resume()
444 err = clk_prepare_enable(data->bus_clk); in mtk8250_runtime_resume()
449 data->clk_count++; in mtk8250_runtime_resume()
459 if (!mtk8250_runtime_resume(port->dev)) in mtk8250_do_pm()
460 pm_runtime_get_sync(port->dev); in mtk8250_do_pm()
465 if (!pm_runtime_put_sync_suspend(port->dev)) in mtk8250_do_pm()
466 mtk8250_runtime_suspend(port->dev); in mtk8250_do_pm()
483 data->uart_clk = devm_clk_get(&pdev->dev, "baud"); in mtk8250_probe_of()
484 if (IS_ERR(data->uart_clk)) { in mtk8250_probe_of()
489 data->uart_clk = devm_clk_get(&pdev->dev, NULL); in mtk8250_probe_of()
490 if (IS_ERR(data->uart_clk)) { in mtk8250_probe_of()
491 dev_warn(&pdev->dev, "Can't get uart clock\n"); in mtk8250_probe_of()
492 return PTR_ERR(data->uart_clk); in mtk8250_probe_of()
498 data->bus_clk = devm_clk_get(&pdev->dev, "bus"); in mtk8250_probe_of()
499 if (IS_ERR(data->bus_clk)) in mtk8250_probe_of()
500 return PTR_ERR(data->bus_clk); in mtk8250_probe_of()
502 data->dma = NULL; in mtk8250_probe_of()
504 dmacnt = of_property_count_strings(pdev->dev.of_node, "dma-names"); in mtk8250_probe_of()
506 data->dma = devm_kzalloc(&pdev->dev, sizeof(*data->dma), in mtk8250_probe_of()
508 if (!data->dma) in mtk8250_probe_of()
509 return -ENOMEM; in mtk8250_probe_of()
511 data->dma->fn = mtk8250_dma_filter; in mtk8250_probe_of()
512 data->dma->rx_size = MTK_UART_RX_SIZE; in mtk8250_probe_of()
513 data->dma->rxconf.src_maxburst = MTK_UART_RX_TRIGGER; in mtk8250_probe_of()
514 data->dma->txconf.dst_maxburst = MTK_UART_TX_TRIGGER; in mtk8250_probe_of()
534 dev_err(&pdev->dev, "no registers defined\n"); in mtk8250_probe()
535 return -EINVAL; in mtk8250_probe()
538 uart.port.membase = devm_ioremap(&pdev->dev, regs->start, in mtk8250_probe()
541 return -ENOMEM; in mtk8250_probe()
543 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in mtk8250_probe()
545 return -ENOMEM; in mtk8250_probe()
547 data->clk_count = 0; in mtk8250_probe()
549 if (pdev->dev.of_node) { in mtk8250_probe()
554 return -ENODEV; in mtk8250_probe()
557 uart.port.mapbase = regs->start; in mtk8250_probe()
559 uart.port.pm = mtk8250_do_pm; in mtk8250_probe()
562 uart.port.dev = &pdev->dev; in mtk8250_probe()
569 uart.port.uartclk = clk_get_rate(data->uart_clk); in mtk8250_probe()
571 if (data->dma) in mtk8250_probe()
572 uart.dma = data->dma; in mtk8250_probe()
581 pm_runtime_enable(&pdev->dev); in mtk8250_probe()
582 err = mtk8250_runtime_resume(&pdev->dev); in mtk8250_probe()
586 data->line = serial8250_register_8250_port(&uart); in mtk8250_probe()
587 if (data->line < 0) { in mtk8250_probe()
588 err = data->line; in mtk8250_probe()
592 data->rx_wakeup_irq = platform_get_irq_optional(pdev, 1); in mtk8250_probe()
597 pm_runtime_disable(&pdev->dev); in mtk8250_probe()
606 pm_runtime_get_sync(&pdev->dev); in mtk8250_remove()
608 serial8250_unregister_port(data->line); in mtk8250_remove()
610 pm_runtime_disable(&pdev->dev); in mtk8250_remove()
611 pm_runtime_put_noidle(&pdev->dev); in mtk8250_remove()
613 if (!pm_runtime_status_suspended(&pdev->dev)) in mtk8250_remove()
614 mtk8250_runtime_suspend(&pdev->dev); in mtk8250_remove()
622 int irq = data->rx_wakeup_irq; in mtk8250_suspend()
625 serial8250_suspend_port(data->line); in mtk8250_suspend()
635 serial8250_resume_port(data->line); in mtk8250_suspend()
646 int irq = data->rx_wakeup_irq; in mtk8250_resume()
652 serial8250_resume_port(data->line); in mtk8250_resume()
664 { .compatible = "mediatek,mt6577-uart" },
671 .name = "mt6577-uart",
672 .pm = &mtk8250_pm_ops,
684 if (!device->port.membase) in early_mtk8250_setup()
685 return -ENODEV; in early_mtk8250_setup()
687 device->port.iotype = UPIO_MEM32; in early_mtk8250_setup()
688 device->port.regshift = 2; in early_mtk8250_setup()
693 OF_EARLYCON_DECLARE(mtk8250, "mediatek,mt6577-uart", early_mtk8250_setup);