1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
2b4756f4fSMatthias Brugger /*
3b4756f4fSMatthias Brugger * Mediatek 8250 driver.
4b4756f4fSMatthias Brugger *
5b4756f4fSMatthias Brugger * Copyright (c) 2014 MundoReader S.L.
6b4756f4fSMatthias Brugger * Author: Matthias Brugger <matthias.bgg@gmail.com>
7b4756f4fSMatthias Brugger */
8b4756f4fSMatthias Brugger #include <linux/clk.h>
9b4756f4fSMatthias Brugger #include <linux/io.h>
1088725e91SArnd Bergmann #include <linux/module.h>
11b4756f4fSMatthias Brugger #include <linux/of_irq.h>
12b4756f4fSMatthias Brugger #include <linux/of_platform.h>
139315ad99SClaire Chang #include <linux/pinctrl/consumer.h>
14b4756f4fSMatthias Brugger #include <linux/platform_device.h>
15b4756f4fSMatthias Brugger #include <linux/pm_runtime.h>
16b4756f4fSMatthias Brugger #include <linux/serial_8250.h>
17b4756f4fSMatthias Brugger #include <linux/serial_reg.h>
1885b5c1ddSLong Cheng #include <linux/console.h>
1985b5c1ddSLong Cheng #include <linux/dma-mapping.h>
2085b5c1ddSLong Cheng #include <linux/tty.h>
2185b5c1ddSLong Cheng #include <linux/tty_flip.h>
22b4756f4fSMatthias Brugger
23b4756f4fSMatthias Brugger #include "8250.h"
24b4756f4fSMatthias Brugger
258ceeb470SLong Cheng #define MTK_UART_HIGHS 0x09 /* Highspeed register */
268ceeb470SLong Cheng #define MTK_UART_SAMPLE_COUNT 0x0a /* Sample count register */
278ceeb470SLong Cheng #define MTK_UART_SAMPLE_POINT 0x0b /* Sample point register */
28b4756f4fSMatthias Brugger #define MTK_UART_RATE_FIX 0x0d /* UART Rate Fix Register */
29bdbd0a7fSLong Cheng #define MTK_UART_ESCAPE_DAT 0x10 /* Escape Character register */
30bdbd0a7fSLong Cheng #define MTK_UART_ESCAPE_EN 0x11 /* Escape Enable register */
3185b5c1ddSLong Cheng #define MTK_UART_DMA_EN 0x13 /* DMA Enable register */
328ceeb470SLong Cheng #define MTK_UART_RXTRI_AD 0x14 /* RX Trigger address */
338ceeb470SLong Cheng #define MTK_UART_FRACDIV_L 0x15 /* Fractional divider LSB address */
348ceeb470SLong Cheng #define MTK_UART_FRACDIV_M 0x16 /* Fractional divider MSB address */
35e32a83c7SChangqi Hu #define MTK_UART_DEBUG0 0x18
36bdbd0a7fSLong Cheng #define MTK_UART_IER_XOFFI 0x20 /* Enable XOFF character interrupt */
37bdbd0a7fSLong Cheng #define MTK_UART_IER_RTSI 0x40 /* Enable RTS Modem status interrupt */
38bdbd0a7fSLong Cheng #define MTK_UART_IER_CTSI 0x80 /* Enable CTS Modem status interrupt */
39bdbd0a7fSLong Cheng
40bb0b197aSAngeloGioacchino Del Regno #define MTK_UART_EFR 38 /* I/O: Extended Features Register */
41bdbd0a7fSLong Cheng #define MTK_UART_EFR_EN 0x10 /* Enable enhancement feature */
42bdbd0a7fSLong Cheng #define MTK_UART_EFR_RTS 0x40 /* Enable hardware rx flow control */
43bdbd0a7fSLong Cheng #define MTK_UART_EFR_CTS 0x80 /* Enable hardware tx flow control */
44bdbd0a7fSLong Cheng #define MTK_UART_EFR_NO_SW_FC 0x0 /* no sw flow control */
45bdbd0a7fSLong Cheng #define MTK_UART_EFR_XON1_XOFF1 0xa /* XON1/XOFF1 as sw flow control */
46bdbd0a7fSLong Cheng #define MTK_UART_EFR_XON2_XOFF2 0x5 /* XON2/XOFF2 as sw flow control */
47bdbd0a7fSLong Cheng #define MTK_UART_EFR_SW_FC_MASK 0xf /* Enable CTS Modem status interrupt */
48bdbd0a7fSLong Cheng #define MTK_UART_EFR_HW_FC (MTK_UART_EFR_RTS | MTK_UART_EFR_CTS)
4985b5c1ddSLong Cheng #define MTK_UART_DMA_EN_TX 0x2
5085b5c1ddSLong Cheng #define MTK_UART_DMA_EN_RX 0x5
5185b5c1ddSLong Cheng
52bdbd0a7fSLong Cheng #define MTK_UART_ESCAPE_CHAR 0x77 /* Escape char added under sw fc */
5385b5c1ddSLong Cheng #define MTK_UART_RX_SIZE 0x8000
5485b5c1ddSLong Cheng #define MTK_UART_TX_TRIGGER 1
5585b5c1ddSLong Cheng #define MTK_UART_RX_TRIGGER MTK_UART_RX_SIZE
5685b5c1ddSLong Cheng
57e1bfdbc7SAngeloGioacchino Del Regno #define MTK_UART_XON1 40 /* I/O: Xon character 1 */
58e1bfdbc7SAngeloGioacchino Del Regno #define MTK_UART_XOFF1 42 /* I/O: Xoff character 1 */
59e1bfdbc7SAngeloGioacchino Del Regno
6085b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
6185b5c1ddSLong Cheng enum dma_rx_status {
6285b5c1ddSLong Cheng DMA_RX_START = 0,
6385b5c1ddSLong Cheng DMA_RX_RUNNING = 1,
6485b5c1ddSLong Cheng DMA_RX_SHUTDOWN = 2,
6585b5c1ddSLong Cheng };
6685b5c1ddSLong Cheng #endif
6785b5c1ddSLong Cheng
68b4756f4fSMatthias Brugger struct mtk8250_data {
69b4756f4fSMatthias Brugger int line;
7085b5c1ddSLong Cheng unsigned int rx_pos;
718ceeb470SLong Cheng unsigned int clk_count;
72b4756f4fSMatthias Brugger struct clk *uart_clk;
73c1c325d7SSascha Hauer struct clk *bus_clk;
7485b5c1ddSLong Cheng struct uart_8250_dma *dma;
7585b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
7685b5c1ddSLong Cheng enum dma_rx_status rx_status;
7785b5c1ddSLong Cheng #endif
789315ad99SClaire Chang int rx_wakeup_irq;
79b4756f4fSMatthias Brugger };
80b4756f4fSMatthias Brugger
81bdbd0a7fSLong Cheng /* flow control mode */
82bdbd0a7fSLong Cheng enum {
83bdbd0a7fSLong Cheng MTK_UART_FC_NONE,
84bdbd0a7fSLong Cheng MTK_UART_FC_SW,
85bdbd0a7fSLong Cheng MTK_UART_FC_HW,
86bdbd0a7fSLong Cheng };
87bdbd0a7fSLong Cheng
8885b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
8985b5c1ddSLong Cheng static void mtk8250_rx_dma(struct uart_8250_port *up);
9085b5c1ddSLong Cheng
mtk8250_dma_rx_complete(void * param)9185b5c1ddSLong Cheng static void mtk8250_dma_rx_complete(void *param)
9285b5c1ddSLong Cheng {
9385b5c1ddSLong Cheng struct uart_8250_port *up = param;
9485b5c1ddSLong Cheng struct uart_8250_dma *dma = up->dma;
9585b5c1ddSLong Cheng struct mtk8250_data *data = up->port.private_data;
9685b5c1ddSLong Cheng struct tty_port *tty_port = &up->port.state->port;
9785b5c1ddSLong Cheng struct dma_tx_state state;
981f74dfa8SLong Cheng int copied, total, cnt;
9985b5c1ddSLong Cheng unsigned char *ptr;
1007c4a509dSZhiyong Tao unsigned long flags;
10185b5c1ddSLong Cheng
10285b5c1ddSLong Cheng if (data->rx_status == DMA_RX_SHUTDOWN)
10385b5c1ddSLong Cheng return;
10485b5c1ddSLong Cheng
1057c4a509dSZhiyong Tao spin_lock_irqsave(&up->port.lock, flags);
1067c4a509dSZhiyong Tao
1071f74dfa8SLong Cheng dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
1081f74dfa8SLong Cheng total = dma->rx_size - state.residue;
1091f74dfa8SLong Cheng cnt = total;
1101f74dfa8SLong Cheng
1111f74dfa8SLong Cheng if ((data->rx_pos + cnt) > dma->rx_size)
1121f74dfa8SLong Cheng cnt = dma->rx_size - data->rx_pos;
1131f74dfa8SLong Cheng
11485b5c1ddSLong Cheng ptr = (unsigned char *)(data->rx_pos + dma->rx_buf);
1151f74dfa8SLong Cheng copied = tty_insert_flip_string(tty_port, ptr, cnt);
1161f74dfa8SLong Cheng data->rx_pos += cnt;
1171f74dfa8SLong Cheng
1181f74dfa8SLong Cheng if (total > cnt) {
11985b5c1ddSLong Cheng ptr = (unsigned char *)(dma->rx_buf);
1201f74dfa8SLong Cheng cnt = total - cnt;
1211f74dfa8SLong Cheng copied += tty_insert_flip_string(tty_port, ptr, cnt);
1221f74dfa8SLong Cheng data->rx_pos = cnt;
12385b5c1ddSLong Cheng }
1241f74dfa8SLong Cheng
12585b5c1ddSLong Cheng up->port.icount.rx += copied;
12685b5c1ddSLong Cheng
12785b5c1ddSLong Cheng tty_flip_buffer_push(tty_port);
12885b5c1ddSLong Cheng
12985b5c1ddSLong Cheng mtk8250_rx_dma(up);
1307c4a509dSZhiyong Tao
1317c4a509dSZhiyong Tao spin_unlock_irqrestore(&up->port.lock, flags);
13285b5c1ddSLong Cheng }
13385b5c1ddSLong Cheng
mtk8250_rx_dma(struct uart_8250_port * up)13485b5c1ddSLong Cheng static void mtk8250_rx_dma(struct uart_8250_port *up)
13585b5c1ddSLong Cheng {
13685b5c1ddSLong Cheng struct uart_8250_dma *dma = up->dma;
13785b5c1ddSLong Cheng struct dma_async_tx_descriptor *desc;
13885b5c1ddSLong Cheng
13985b5c1ddSLong Cheng desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
14085b5c1ddSLong Cheng dma->rx_size, DMA_DEV_TO_MEM,
14185b5c1ddSLong Cheng DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
14285b5c1ddSLong Cheng if (!desc) {
14385b5c1ddSLong Cheng pr_err("failed to prepare rx slave single\n");
14485b5c1ddSLong Cheng return;
14585b5c1ddSLong Cheng }
14685b5c1ddSLong Cheng
14785b5c1ddSLong Cheng desc->callback = mtk8250_dma_rx_complete;
14885b5c1ddSLong Cheng desc->callback_param = up;
14985b5c1ddSLong Cheng
15085b5c1ddSLong Cheng dma->rx_cookie = dmaengine_submit(desc);
15185b5c1ddSLong Cheng
15285b5c1ddSLong Cheng dma_async_issue_pending(dma->rxchan);
15385b5c1ddSLong Cheng }
15485b5c1ddSLong Cheng
mtk8250_dma_enable(struct uart_8250_port * up)15585b5c1ddSLong Cheng static void mtk8250_dma_enable(struct uart_8250_port *up)
15685b5c1ddSLong Cheng {
15785b5c1ddSLong Cheng struct uart_8250_dma *dma = up->dma;
15885b5c1ddSLong Cheng struct mtk8250_data *data = up->port.private_data;
15985b5c1ddSLong Cheng int lcr = serial_in(up, UART_LCR);
16085b5c1ddSLong Cheng
16185b5c1ddSLong Cheng if (data->rx_status != DMA_RX_START)
16285b5c1ddSLong Cheng return;
16385b5c1ddSLong Cheng
1641f74dfa8SLong Cheng dma->rxconf.src_port_window_size = dma->rx_size;
16585b5c1ddSLong Cheng dma->rxconf.src_addr = dma->rx_addr;
16685b5c1ddSLong Cheng
1671f74dfa8SLong Cheng dma->txconf.dst_port_window_size = UART_XMIT_SIZE;
16885b5c1ddSLong Cheng dma->txconf.dst_addr = dma->tx_addr;
16985b5c1ddSLong Cheng
17085b5c1ddSLong Cheng serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
17185b5c1ddSLong Cheng UART_FCR_CLEAR_XMIT);
17285b5c1ddSLong Cheng serial_out(up, MTK_UART_DMA_EN,
17385b5c1ddSLong Cheng MTK_UART_DMA_EN_RX | MTK_UART_DMA_EN_TX);
17485b5c1ddSLong Cheng
17585b5c1ddSLong Cheng serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
176bb0b197aSAngeloGioacchino Del Regno serial_out(up, MTK_UART_EFR, UART_EFR_ECB);
17785b5c1ddSLong Cheng serial_out(up, UART_LCR, lcr);
17885b5c1ddSLong Cheng
17985b5c1ddSLong Cheng if (dmaengine_slave_config(dma->rxchan, &dma->rxconf) != 0)
18085b5c1ddSLong Cheng pr_err("failed to configure rx dma channel\n");
18185b5c1ddSLong Cheng if (dmaengine_slave_config(dma->txchan, &dma->txconf) != 0)
18285b5c1ddSLong Cheng pr_err("failed to configure tx dma channel\n");
18385b5c1ddSLong Cheng
18485b5c1ddSLong Cheng data->rx_status = DMA_RX_RUNNING;
18585b5c1ddSLong Cheng data->rx_pos = 0;
18685b5c1ddSLong Cheng mtk8250_rx_dma(up);
18785b5c1ddSLong Cheng }
18885b5c1ddSLong Cheng #endif
18985b5c1ddSLong Cheng
mtk8250_startup(struct uart_port * port)19085b5c1ddSLong Cheng static int mtk8250_startup(struct uart_port *port)
19185b5c1ddSLong Cheng {
19285b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
19385b5c1ddSLong Cheng struct uart_8250_port *up = up_to_u8250p(port);
19485b5c1ddSLong Cheng struct mtk8250_data *data = port->private_data;
19585b5c1ddSLong Cheng
19685b5c1ddSLong Cheng /* disable DMA for console */
19785b5c1ddSLong Cheng if (uart_console(port))
19885b5c1ddSLong Cheng up->dma = NULL;
19985b5c1ddSLong Cheng
20085b5c1ddSLong Cheng if (up->dma) {
20185b5c1ddSLong Cheng data->rx_status = DMA_RX_START;
20285b5c1ddSLong Cheng uart_circ_clear(&port->state->xmit);
20385b5c1ddSLong Cheng }
20485b5c1ddSLong Cheng #endif
20585b5c1ddSLong Cheng memset(&port->icount, 0, sizeof(port->icount));
20685b5c1ddSLong Cheng
20785b5c1ddSLong Cheng return serial8250_do_startup(port);
20885b5c1ddSLong Cheng }
20985b5c1ddSLong Cheng
mtk8250_shutdown(struct uart_port * port)21085b5c1ddSLong Cheng static void mtk8250_shutdown(struct uart_port *port)
21185b5c1ddSLong Cheng {
21285b5c1ddSLong Cheng struct uart_8250_port *up = up_to_u8250p(port);
21385b5c1ddSLong Cheng struct mtk8250_data *data = port->private_data;
214*e4a1d0aaSPin-yen Lin int irq = data->rx_wakeup_irq;
21585b5c1ddSLong Cheng
216*e4a1d0aaSPin-yen Lin #ifdef CONFIG_SERIAL_8250_DMA
21785b5c1ddSLong Cheng if (up->dma)
21885b5c1ddSLong Cheng data->rx_status = DMA_RX_SHUTDOWN;
21985b5c1ddSLong Cheng #endif
22085b5c1ddSLong Cheng
221*e4a1d0aaSPin-yen Lin serial8250_do_shutdown(port);
222*e4a1d0aaSPin-yen Lin
223*e4a1d0aaSPin-yen Lin if (irq >= 0)
224*e4a1d0aaSPin-yen Lin serial8250_do_set_mctrl(&up->port, TIOCM_RTS);
22585b5c1ddSLong Cheng }
22685b5c1ddSLong Cheng
mtk8250_disable_intrs(struct uart_8250_port * up,int mask)227bdbd0a7fSLong Cheng static void mtk8250_disable_intrs(struct uart_8250_port *up, int mask)
228bdbd0a7fSLong Cheng {
229d0b309a5SJohn Ogness /* Port locked to synchronize UART_IER access against the console. */
230d0b309a5SJohn Ogness lockdep_assert_held_once(&up->port.lock);
231d0b309a5SJohn Ogness
232bdbd0a7fSLong Cheng serial_out(up, UART_IER, serial_in(up, UART_IER) & (~mask));
233bdbd0a7fSLong Cheng }
234bdbd0a7fSLong Cheng
mtk8250_enable_intrs(struct uart_8250_port * up,int mask)235bdbd0a7fSLong Cheng static void mtk8250_enable_intrs(struct uart_8250_port *up, int mask)
236bdbd0a7fSLong Cheng {
237d0b309a5SJohn Ogness /* Port locked to synchronize UART_IER access against the console. */
238d0b309a5SJohn Ogness lockdep_assert_held_once(&up->port.lock);
239d0b309a5SJohn Ogness
240bdbd0a7fSLong Cheng serial_out(up, UART_IER, serial_in(up, UART_IER) | mask);
241bdbd0a7fSLong Cheng }
242bdbd0a7fSLong Cheng
mtk8250_set_flow_ctrl(struct uart_8250_port * up,int mode)243bdbd0a7fSLong Cheng static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
244bdbd0a7fSLong Cheng {
245bdbd0a7fSLong Cheng struct uart_port *port = &up->port;
246bdbd0a7fSLong Cheng int lcr = serial_in(up, UART_LCR);
247bdbd0a7fSLong Cheng
248d0b309a5SJohn Ogness /* Port locked to synchronize UART_IER access against the console. */
249d0b309a5SJohn Ogness lockdep_assert_held_once(&port->lock);
250d0b309a5SJohn Ogness
251bdbd0a7fSLong Cheng serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
252bb0b197aSAngeloGioacchino Del Regno serial_out(up, MTK_UART_EFR, UART_EFR_ECB);
253bdbd0a7fSLong Cheng serial_out(up, UART_LCR, lcr);
254bdbd0a7fSLong Cheng lcr = serial_in(up, UART_LCR);
255bdbd0a7fSLong Cheng
256bdbd0a7fSLong Cheng switch (mode) {
257bdbd0a7fSLong Cheng case MTK_UART_FC_NONE:
258bdbd0a7fSLong Cheng serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR);
259bdbd0a7fSLong Cheng serial_out(up, MTK_UART_ESCAPE_EN, 0x00);
260bdbd0a7fSLong Cheng serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
261bb0b197aSAngeloGioacchino Del Regno serial_out(up, MTK_UART_EFR, serial_in(up, MTK_UART_EFR) &
262bdbd0a7fSLong Cheng (~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK)));
263bdbd0a7fSLong Cheng serial_out(up, UART_LCR, lcr);
264bdbd0a7fSLong Cheng mtk8250_disable_intrs(up, MTK_UART_IER_XOFFI |
265bdbd0a7fSLong Cheng MTK_UART_IER_RTSI | MTK_UART_IER_CTSI);
266bdbd0a7fSLong Cheng break;
267bdbd0a7fSLong Cheng
268bdbd0a7fSLong Cheng case MTK_UART_FC_HW:
269bdbd0a7fSLong Cheng serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR);
270bdbd0a7fSLong Cheng serial_out(up, MTK_UART_ESCAPE_EN, 0x00);
271bdbd0a7fSLong Cheng serial_out(up, UART_MCR, UART_MCR_RTS);
272bdbd0a7fSLong Cheng serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
273bdbd0a7fSLong Cheng
274bdbd0a7fSLong Cheng /*enable hw flow control*/
275bb0b197aSAngeloGioacchino Del Regno serial_out(up, MTK_UART_EFR, MTK_UART_EFR_HW_FC |
276bb0b197aSAngeloGioacchino Del Regno (serial_in(up, MTK_UART_EFR) &
277bdbd0a7fSLong Cheng (~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK))));
278bdbd0a7fSLong Cheng
279bdbd0a7fSLong Cheng serial_out(up, UART_LCR, lcr);
280bdbd0a7fSLong Cheng mtk8250_disable_intrs(up, MTK_UART_IER_XOFFI);
281bdbd0a7fSLong Cheng mtk8250_enable_intrs(up, MTK_UART_IER_CTSI | MTK_UART_IER_RTSI);
282bdbd0a7fSLong Cheng break;
283bdbd0a7fSLong Cheng
284bdbd0a7fSLong Cheng case MTK_UART_FC_SW: /*MTK software flow control */
285bdbd0a7fSLong Cheng serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR);
286bdbd0a7fSLong Cheng serial_out(up, MTK_UART_ESCAPE_EN, 0x01);
287bdbd0a7fSLong Cheng serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
288bdbd0a7fSLong Cheng
289bdbd0a7fSLong Cheng /*enable sw flow control */
290bb0b197aSAngeloGioacchino Del Regno serial_out(up, MTK_UART_EFR, MTK_UART_EFR_XON1_XOFF1 |
291bb0b197aSAngeloGioacchino Del Regno (serial_in(up, MTK_UART_EFR) &
292bdbd0a7fSLong Cheng (~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK))));
293bdbd0a7fSLong Cheng
294e1bfdbc7SAngeloGioacchino Del Regno serial_out(up, MTK_UART_XON1, START_CHAR(port->state->port.tty));
295e1bfdbc7SAngeloGioacchino Del Regno serial_out(up, MTK_UART_XOFF1, STOP_CHAR(port->state->port.tty));
296bdbd0a7fSLong Cheng serial_out(up, UART_LCR, lcr);
297bdbd0a7fSLong Cheng mtk8250_disable_intrs(up, MTK_UART_IER_CTSI|MTK_UART_IER_RTSI);
298bdbd0a7fSLong Cheng mtk8250_enable_intrs(up, MTK_UART_IER_XOFFI);
299bdbd0a7fSLong Cheng break;
300bdbd0a7fSLong Cheng default:
301bdbd0a7fSLong Cheng break;
302bdbd0a7fSLong Cheng }
303bdbd0a7fSLong Cheng }
304bdbd0a7fSLong Cheng
305b4756f4fSMatthias Brugger static void
mtk8250_set_termios(struct uart_port * port,struct ktermios * termios,const struct ktermios * old)306b4756f4fSMatthias Brugger mtk8250_set_termios(struct uart_port *port, struct ktermios *termios,
307bec5b814SIlpo Järvinen const struct ktermios *old)
308b4756f4fSMatthias Brugger {
309a6cee01bSColin Ian King static const unsigned short fraction_L_mapping[] = {
3108ceeb470SLong Cheng 0, 1, 0x5, 0x15, 0x55, 0x57, 0x57, 0x77, 0x7F, 0xFF, 0xFF
3118ceeb470SLong Cheng };
312a6cee01bSColin Ian King static const unsigned short fraction_M_mapping[] = {
3138ceeb470SLong Cheng 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3
3148ceeb470SLong Cheng };
315013e3586SAndy Shevchenko struct uart_8250_port *up = up_to_u8250p(port);
3168ceeb470SLong Cheng unsigned int baud, quot, fraction;
317b4756f4fSMatthias Brugger unsigned long flags;
318bdbd0a7fSLong Cheng int mode;
319b4756f4fSMatthias Brugger
32085b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
32185b5c1ddSLong Cheng if (up->dma) {
32285b5c1ddSLong Cheng if (uart_console(port)) {
32385b5c1ddSLong Cheng devm_kfree(up->port.dev, up->dma);
32485b5c1ddSLong Cheng up->dma = NULL;
32585b5c1ddSLong Cheng } else {
32685b5c1ddSLong Cheng mtk8250_dma_enable(up);
32785b5c1ddSLong Cheng }
32885b5c1ddSLong Cheng }
32985b5c1ddSLong Cheng #endif
33085b5c1ddSLong Cheng
331551e553fSSerge Semin /*
332551e553fSSerge Semin * Store the requested baud rate before calling the generic 8250
333551e553fSSerge Semin * set_termios method. Standard 8250 port expects bauds to be
334551e553fSSerge Semin * no higher than (uartclk / 16) so the baud will be clamped if it
335551e553fSSerge Semin * gets out of that bound. Mediatek 8250 port supports speed
336551e553fSSerge Semin * higher than that, therefore we'll get original baud rate back
337551e553fSSerge Semin * after calling the generic set_termios method and recalculate
338551e553fSSerge Semin * the speed later in this method.
339551e553fSSerge Semin */
340551e553fSSerge Semin baud = tty_termios_baud_rate(termios);
341551e553fSSerge Semin
342912ab37cSClaire Chang serial8250_do_set_termios(port, termios, NULL);
343b4756f4fSMatthias Brugger
344551e553fSSerge Semin tty_termios_encode_baud_rate(termios, baud, baud);
345551e553fSSerge Semin
346b4756f4fSMatthias Brugger /*
3478ceeb470SLong Cheng * Mediatek UARTs use an extra highspeed register (MTK_UART_HIGHS)
348b4756f4fSMatthias Brugger *
349b4756f4fSMatthias Brugger * We need to recalcualte the quot register, as the claculation depends
350b4756f4fSMatthias Brugger * on the vaule in the highspeed register.
351b4756f4fSMatthias Brugger *
352b4756f4fSMatthias Brugger * Some baudrates are not supported by the chip, so we use the next
353b4756f4fSMatthias Brugger * lower rate supported and update termios c_flag.
354b4756f4fSMatthias Brugger *
355b4756f4fSMatthias Brugger * If highspeed register is set to 3, we need to specify sample count
356b4756f4fSMatthias Brugger * and sample point to increase accuracy. If not, we reset the
357b4756f4fSMatthias Brugger * registers to their default values.
358b4756f4fSMatthias Brugger */
359b4756f4fSMatthias Brugger baud = uart_get_baud_rate(port, termios, old,
3606263368cSEd Blake port->uartclk / 16 / UART_DIV_MAX,
36181bb549fSEddie Huang port->uartclk);
362b4756f4fSMatthias Brugger
3638ceeb470SLong Cheng if (baud < 115200) {
3648ceeb470SLong Cheng serial_port_out(port, MTK_UART_HIGHS, 0x0);
365b4756f4fSMatthias Brugger quot = uart_get_divisor(port, baud);
366b4756f4fSMatthias Brugger } else {
3678ceeb470SLong Cheng serial_port_out(port, MTK_UART_HIGHS, 0x3);
3682a768264SEddie Huang quot = DIV_ROUND_UP(port->uartclk, 256 * baud);
369b4756f4fSMatthias Brugger }
370b4756f4fSMatthias Brugger
371b4756f4fSMatthias Brugger /*
372b4756f4fSMatthias Brugger * Ok, we're now changing the port state. Do it with
373b4756f4fSMatthias Brugger * interrupts disabled.
374b4756f4fSMatthias Brugger */
375b4756f4fSMatthias Brugger spin_lock_irqsave(&port->lock, flags);
376b4756f4fSMatthias Brugger
377551e553fSSerge Semin /*
378551e553fSSerge Semin * Update the per-port timeout.
379551e553fSSerge Semin */
380551e553fSSerge Semin uart_update_timeout(port, termios->c_cflag, baud);
381551e553fSSerge Semin
382b4756f4fSMatthias Brugger /* set DLAB we have cval saved in up->lcr from the call to the core */
383b4756f4fSMatthias Brugger serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB);
384b4756f4fSMatthias Brugger serial_dl_write(up, quot);
385b4756f4fSMatthias Brugger
386b4756f4fSMatthias Brugger /* reset DLAB */
387b4756f4fSMatthias Brugger serial_port_out(port, UART_LCR, up->lcr);
388b4756f4fSMatthias Brugger
3898ceeb470SLong Cheng if (baud >= 115200) {
390b4756f4fSMatthias Brugger unsigned int tmp;
391b4756f4fSMatthias Brugger
3928ceeb470SLong Cheng tmp = (port->uartclk / (baud * quot)) - 1;
3938ceeb470SLong Cheng serial_port_out(port, MTK_UART_SAMPLE_COUNT, tmp);
3948ceeb470SLong Cheng serial_port_out(port, MTK_UART_SAMPLE_POINT,
3958ceeb470SLong Cheng (tmp >> 1) - 1);
3968ceeb470SLong Cheng
3978ceeb470SLong Cheng /*count fraction to set fractoin register */
3988ceeb470SLong Cheng fraction = ((port->uartclk * 100) / baud / quot) % 100;
3998ceeb470SLong Cheng fraction = DIV_ROUND_CLOSEST(fraction, 10);
4008ceeb470SLong Cheng serial_port_out(port, MTK_UART_FRACDIV_L,
4018ceeb470SLong Cheng fraction_L_mapping[fraction]);
4028ceeb470SLong Cheng serial_port_out(port, MTK_UART_FRACDIV_M,
4038ceeb470SLong Cheng fraction_M_mapping[fraction]);
404b4756f4fSMatthias Brugger } else {
4058ceeb470SLong Cheng serial_port_out(port, MTK_UART_SAMPLE_COUNT, 0x00);
4068ceeb470SLong Cheng serial_port_out(port, MTK_UART_SAMPLE_POINT, 0xff);
4078ceeb470SLong Cheng serial_port_out(port, MTK_UART_FRACDIV_L, 0x00);
4088ceeb470SLong Cheng serial_port_out(port, MTK_UART_FRACDIV_M, 0x00);
409b4756f4fSMatthias Brugger }
410bdbd0a7fSLong Cheng
411bdbd0a7fSLong Cheng if ((termios->c_cflag & CRTSCTS) && (!(termios->c_iflag & CRTSCTS)))
412bdbd0a7fSLong Cheng mode = MTK_UART_FC_HW;
413bdbd0a7fSLong Cheng else if (termios->c_iflag & CRTSCTS)
414bdbd0a7fSLong Cheng mode = MTK_UART_FC_SW;
415bdbd0a7fSLong Cheng else
416bdbd0a7fSLong Cheng mode = MTK_UART_FC_NONE;
417bdbd0a7fSLong Cheng
418bdbd0a7fSLong Cheng mtk8250_set_flow_ctrl(up, mode);
419bdbd0a7fSLong Cheng
4208ceeb470SLong Cheng if (uart_console(port))
4218ceeb470SLong Cheng up->port.cons->cflag = termios->c_cflag;
422b4756f4fSMatthias Brugger
423b4756f4fSMatthias Brugger spin_unlock_irqrestore(&port->lock, flags);
424b4756f4fSMatthias Brugger /* Don't rewrite B0 */
425b4756f4fSMatthias Brugger if (tty_termios_baud_rate(termios))
426b4756f4fSMatthias Brugger tty_termios_encode_baud_rate(termios, baud, baud);
427b4756f4fSMatthias Brugger }
428b4756f4fSMatthias Brugger
mtk8250_runtime_suspend(struct device * dev)4299db669f1SArnd Bergmann static int __maybe_unused mtk8250_runtime_suspend(struct device *dev)
43068e5fc4aSSascha Hauer {
43168e5fc4aSSascha Hauer struct mtk8250_data *data = dev_get_drvdata(dev);
432e32a83c7SChangqi Hu struct uart_8250_port *up = serial8250_get_port(data->line);
43368e5fc4aSSascha Hauer
434e32a83c7SChangqi Hu /* wait until UART in idle status */
435e32a83c7SChangqi Hu while
436e32a83c7SChangqi Hu (serial_in(up, MTK_UART_DEBUG0));
437e32a83c7SChangqi Hu
438c1c325d7SSascha Hauer clk_disable_unprepare(data->bus_clk);
43968e5fc4aSSascha Hauer
44068e5fc4aSSascha Hauer return 0;
44168e5fc4aSSascha Hauer }
44268e5fc4aSSascha Hauer
mtk8250_runtime_resume(struct device * dev)4439db669f1SArnd Bergmann static int __maybe_unused mtk8250_runtime_resume(struct device *dev)
44468e5fc4aSSascha Hauer {
44568e5fc4aSSascha Hauer struct mtk8250_data *data = dev_get_drvdata(dev);
44668e5fc4aSSascha Hauer
447b6c7ff26SChen-Yu Tsai clk_prepare_enable(data->bus_clk);
448c1c325d7SSascha Hauer
44968e5fc4aSSascha Hauer return 0;
45068e5fc4aSSascha Hauer }
45168e5fc4aSSascha Hauer
452b4756f4fSMatthias Brugger static void
mtk8250_do_pm(struct uart_port * port,unsigned int state,unsigned int old)453b4756f4fSMatthias Brugger mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old)
454b4756f4fSMatthias Brugger {
455b4756f4fSMatthias Brugger if (!state)
456b4756f4fSMatthias Brugger pm_runtime_get_sync(port->dev);
457b4756f4fSMatthias Brugger
458b4756f4fSMatthias Brugger serial8250_do_pm(port, state, old);
459b4756f4fSMatthias Brugger
460b4756f4fSMatthias Brugger if (state)
461b6c7ff26SChen-Yu Tsai pm_runtime_put_sync_suspend(port->dev);
462b4756f4fSMatthias Brugger }
463b4756f4fSMatthias Brugger
46485b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
mtk8250_dma_filter(struct dma_chan * chan,void * param)46585b5c1ddSLong Cheng static bool mtk8250_dma_filter(struct dma_chan *chan, void *param)
46685b5c1ddSLong Cheng {
46785b5c1ddSLong Cheng return false;
46885b5c1ddSLong Cheng }
46985b5c1ddSLong Cheng #endif
47085b5c1ddSLong Cheng
mtk8250_probe_of(struct platform_device * pdev,struct uart_port * p,struct mtk8250_data * data)471b4756f4fSMatthias Brugger static int mtk8250_probe_of(struct platform_device *pdev, struct uart_port *p,
472b4756f4fSMatthias Brugger struct mtk8250_data *data)
473b4756f4fSMatthias Brugger {
47485b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
47585b5c1ddSLong Cheng int dmacnt;
47685b5c1ddSLong Cheng #endif
47785b5c1ddSLong Cheng
478c1c325d7SSascha Hauer data->uart_clk = devm_clk_get(&pdev->dev, "baud");
479c1c325d7SSascha Hauer if (IS_ERR(data->uart_clk)) {
480c1c325d7SSascha Hauer /*
481c1c325d7SSascha Hauer * For compatibility with older device trees try unnamed
482c1c325d7SSascha Hauer * clk when no baud clk can be found.
483c1c325d7SSascha Hauer */
484a5fd8445SSascha Hauer data->uart_clk = devm_clk_get(&pdev->dev, NULL);
485b4756f4fSMatthias Brugger if (IS_ERR(data->uart_clk)) {
486a5fd8445SSascha Hauer dev_warn(&pdev->dev, "Can't get uart clock\n");
487b4756f4fSMatthias Brugger return PTR_ERR(data->uart_clk);
488b4756f4fSMatthias Brugger }
489b4756f4fSMatthias Brugger
490c1c325d7SSascha Hauer return 0;
491c1c325d7SSascha Hauer }
492c1c325d7SSascha Hauer
493b6c7ff26SChen-Yu Tsai data->bus_clk = devm_clk_get_enabled(&pdev->dev, "bus");
49485b5c1ddSLong Cheng if (IS_ERR(data->bus_clk))
49585b5c1ddSLong Cheng return PTR_ERR(data->bus_clk);
49685b5c1ddSLong Cheng
49785b5c1ddSLong Cheng data->dma = NULL;
49885b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
49985b5c1ddSLong Cheng dmacnt = of_property_count_strings(pdev->dev.of_node, "dma-names");
50085b5c1ddSLong Cheng if (dmacnt == 2) {
50185b5c1ddSLong Cheng data->dma = devm_kzalloc(&pdev->dev, sizeof(*data->dma),
50285b5c1ddSLong Cheng GFP_KERNEL);
5031575c083SGustavo A. R. Silva if (!data->dma)
5041575c083SGustavo A. R. Silva return -ENOMEM;
5051575c083SGustavo A. R. Silva
50685b5c1ddSLong Cheng data->dma->fn = mtk8250_dma_filter;
50785b5c1ddSLong Cheng data->dma->rx_size = MTK_UART_RX_SIZE;
50885b5c1ddSLong Cheng data->dma->rxconf.src_maxburst = MTK_UART_RX_TRIGGER;
50985b5c1ddSLong Cheng data->dma->txconf.dst_maxburst = MTK_UART_TX_TRIGGER;
51085b5c1ddSLong Cheng }
51185b5c1ddSLong Cheng #endif
51285b5c1ddSLong Cheng
51385b5c1ddSLong Cheng return 0;
514b4756f4fSMatthias Brugger }
515b4756f4fSMatthias Brugger
mtk8250_probe(struct platform_device * pdev)516b4756f4fSMatthias Brugger static int mtk8250_probe(struct platform_device *pdev)
517b4756f4fSMatthias Brugger {
518b4756f4fSMatthias Brugger struct uart_8250_port uart = {};
519b4756f4fSMatthias Brugger struct mtk8250_data *data;
5201b1eef68SAndy Shevchenko struct resource *regs;
5211b1eef68SAndy Shevchenko int irq, err;
522b4756f4fSMatthias Brugger
5231b1eef68SAndy Shevchenko irq = platform_get_irq(pdev, 0);
5241b1eef68SAndy Shevchenko if (irq < 0)
5251b1eef68SAndy Shevchenko return irq;
5261b1eef68SAndy Shevchenko
5271b1eef68SAndy Shevchenko regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5281b1eef68SAndy Shevchenko if (!regs) {
5291b1eef68SAndy Shevchenko dev_err(&pdev->dev, "no registers defined\n");
530b4756f4fSMatthias Brugger return -EINVAL;
531b4756f4fSMatthias Brugger }
532b4756f4fSMatthias Brugger
533b4756f4fSMatthias Brugger uart.port.membase = devm_ioremap(&pdev->dev, regs->start,
534b4756f4fSMatthias Brugger resource_size(regs));
535b4756f4fSMatthias Brugger if (!uart.port.membase)
536b4756f4fSMatthias Brugger return -ENOMEM;
537b4756f4fSMatthias Brugger
538b4756f4fSMatthias Brugger data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
539b4756f4fSMatthias Brugger if (!data)
540b4756f4fSMatthias Brugger return -ENOMEM;
541b4756f4fSMatthias Brugger
542e32a83c7SChangqi Hu data->clk_count = 0;
543e32a83c7SChangqi Hu
544b4756f4fSMatthias Brugger if (pdev->dev.of_node) {
545b4756f4fSMatthias Brugger err = mtk8250_probe_of(pdev, &uart.port, data);
546b4756f4fSMatthias Brugger if (err)
547b4756f4fSMatthias Brugger return err;
548b4756f4fSMatthias Brugger } else
549b4756f4fSMatthias Brugger return -ENODEV;
550b4756f4fSMatthias Brugger
551b4756f4fSMatthias Brugger spin_lock_init(&uart.port.lock);
552b4756f4fSMatthias Brugger uart.port.mapbase = regs->start;
5531b1eef68SAndy Shevchenko uart.port.irq = irq;
554b4756f4fSMatthias Brugger uart.port.pm = mtk8250_do_pm;
555b4756f4fSMatthias Brugger uart.port.type = PORT_16550;
556b4756f4fSMatthias Brugger uart.port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
557b4756f4fSMatthias Brugger uart.port.dev = &pdev->dev;
558b4756f4fSMatthias Brugger uart.port.iotype = UPIO_MEM32;
559b4756f4fSMatthias Brugger uart.port.regshift = 2;
560b4756f4fSMatthias Brugger uart.port.private_data = data;
56185b5c1ddSLong Cheng uart.port.shutdown = mtk8250_shutdown;
56285b5c1ddSLong Cheng uart.port.startup = mtk8250_startup;
563b4756f4fSMatthias Brugger uart.port.set_termios = mtk8250_set_termios;
564c1c325d7SSascha Hauer uart.port.uartclk = clk_get_rate(data->uart_clk);
56585b5c1ddSLong Cheng #ifdef CONFIG_SERIAL_8250_DMA
56685b5c1ddSLong Cheng if (data->dma)
56785b5c1ddSLong Cheng uart.dma = data->dma;
56885b5c1ddSLong Cheng #endif
569b4756f4fSMatthias Brugger
570b4756f4fSMatthias Brugger /* Disable Rate Fix function */
571b4756f4fSMatthias Brugger writel(0x0, uart.port.membase +
572b4756f4fSMatthias Brugger (MTK_UART_RATE_FIX << uart.port.regshift));
573b4756f4fSMatthias Brugger
57468e5fc4aSSascha Hauer platform_set_drvdata(pdev, data);
57568e5fc4aSSascha Hauer
576b4756f4fSMatthias Brugger data->line = serial8250_register_8250_port(&uart);
577b6c7ff26SChen-Yu Tsai if (data->line < 0)
578b6c7ff26SChen-Yu Tsai return data->line;
579b4756f4fSMatthias Brugger
580eb9c1a41SFrank Wunderlich data->rx_wakeup_irq = platform_get_irq_optional(pdev, 1);
5819315ad99SClaire Chang
582b6c7ff26SChen-Yu Tsai pm_runtime_set_active(&pdev->dev);
583b6c7ff26SChen-Yu Tsai pm_runtime_enable(&pdev->dev);
584b6c7ff26SChen-Yu Tsai
585b4756f4fSMatthias Brugger return 0;
586b4756f4fSMatthias Brugger }
587b4756f4fSMatthias Brugger
mtk8250_remove(struct platform_device * pdev)58888725e91SArnd Bergmann static int mtk8250_remove(struct platform_device *pdev)
58988725e91SArnd Bergmann {
59088725e91SArnd Bergmann struct mtk8250_data *data = platform_get_drvdata(pdev);
59188725e91SArnd Bergmann
59288725e91SArnd Bergmann pm_runtime_get_sync(&pdev->dev);
59388725e91SArnd Bergmann
59488725e91SArnd Bergmann serial8250_unregister_port(data->line);
59588725e91SArnd Bergmann
59688725e91SArnd Bergmann pm_runtime_disable(&pdev->dev);
59788725e91SArnd Bergmann pm_runtime_put_noidle(&pdev->dev);
59888725e91SArnd Bergmann
59988725e91SArnd Bergmann return 0;
60088725e91SArnd Bergmann }
60188725e91SArnd Bergmann
mtk8250_suspend(struct device * dev)6029db669f1SArnd Bergmann static int __maybe_unused mtk8250_suspend(struct device *dev)
603b4756f4fSMatthias Brugger {
604b4756f4fSMatthias Brugger struct mtk8250_data *data = dev_get_drvdata(dev);
6059315ad99SClaire Chang int irq = data->rx_wakeup_irq;
6069315ad99SClaire Chang int err;
607b4756f4fSMatthias Brugger
608b4756f4fSMatthias Brugger serial8250_suspend_port(data->line);
609b4756f4fSMatthias Brugger
6109315ad99SClaire Chang pinctrl_pm_select_sleep_state(dev);
6119315ad99SClaire Chang if (irq >= 0) {
6129315ad99SClaire Chang err = enable_irq_wake(irq);
6139315ad99SClaire Chang if (err) {
6149315ad99SClaire Chang dev_err(dev,
6159315ad99SClaire Chang "failed to enable irq wake on IRQ %d: %d\n",
6169315ad99SClaire Chang irq, err);
6179315ad99SClaire Chang pinctrl_pm_select_default_state(dev);
6189315ad99SClaire Chang serial8250_resume_port(data->line);
6199315ad99SClaire Chang return err;
6209315ad99SClaire Chang }
6219315ad99SClaire Chang }
6229315ad99SClaire Chang
623b4756f4fSMatthias Brugger return 0;
624b4756f4fSMatthias Brugger }
625b4756f4fSMatthias Brugger
mtk8250_resume(struct device * dev)6269db669f1SArnd Bergmann static int __maybe_unused mtk8250_resume(struct device *dev)
627b4756f4fSMatthias Brugger {
628b4756f4fSMatthias Brugger struct mtk8250_data *data = dev_get_drvdata(dev);
6299315ad99SClaire Chang int irq = data->rx_wakeup_irq;
6309315ad99SClaire Chang
6319315ad99SClaire Chang if (irq >= 0)
6329315ad99SClaire Chang disable_irq_wake(irq);
6339315ad99SClaire Chang pinctrl_pm_select_default_state(dev);
634b4756f4fSMatthias Brugger
635b4756f4fSMatthias Brugger serial8250_resume_port(data->line);
636b4756f4fSMatthias Brugger
637b4756f4fSMatthias Brugger return 0;
638b4756f4fSMatthias Brugger }
639b4756f4fSMatthias Brugger
640b4756f4fSMatthias Brugger static const struct dev_pm_ops mtk8250_pm_ops = {
641b4756f4fSMatthias Brugger SET_SYSTEM_SLEEP_PM_OPS(mtk8250_suspend, mtk8250_resume)
642b4756f4fSMatthias Brugger SET_RUNTIME_PM_OPS(mtk8250_runtime_suspend, mtk8250_runtime_resume,
643b4756f4fSMatthias Brugger NULL)
644b4756f4fSMatthias Brugger };
645b4756f4fSMatthias Brugger
646b4756f4fSMatthias Brugger static const struct of_device_id mtk8250_of_match[] = {
647b4756f4fSMatthias Brugger { .compatible = "mediatek,mt6577-uart" },
648b4756f4fSMatthias Brugger { /* Sentinel */ }
649b4756f4fSMatthias Brugger };
65088725e91SArnd Bergmann MODULE_DEVICE_TABLE(of, mtk8250_of_match);
651b4756f4fSMatthias Brugger
652b4756f4fSMatthias Brugger static struct platform_driver mtk8250_platform_driver = {
653b4756f4fSMatthias Brugger .driver = {
654b4756f4fSMatthias Brugger .name = "mt6577-uart",
655b4756f4fSMatthias Brugger .pm = &mtk8250_pm_ops,
656b4756f4fSMatthias Brugger .of_match_table = mtk8250_of_match,
657b4756f4fSMatthias Brugger },
658b4756f4fSMatthias Brugger .probe = mtk8250_probe,
65988725e91SArnd Bergmann .remove = mtk8250_remove,
660b4756f4fSMatthias Brugger };
66188725e91SArnd Bergmann module_platform_driver(mtk8250_platform_driver);
662b4756f4fSMatthias Brugger
663ae73975fSMasahiro Yamada #ifdef CONFIG_SERIAL_8250_CONSOLE
early_mtk8250_setup(struct earlycon_device * device,const char * options)6642c40b57dSEddie Huang static int __init early_mtk8250_setup(struct earlycon_device *device,
6652c40b57dSEddie Huang const char *options)
6662c40b57dSEddie Huang {
6672c40b57dSEddie Huang if (!device->port.membase)
6682c40b57dSEddie Huang return -ENODEV;
6692c40b57dSEddie Huang
6702c40b57dSEddie Huang device->port.iotype = UPIO_MEM32;
671ea4de367SHsin-Yi Wang device->port.regshift = 2;
6722c40b57dSEddie Huang
6732c40b57dSEddie Huang return early_serial8250_setup(device, NULL);
6742c40b57dSEddie Huang }
6752c40b57dSEddie Huang
6762c40b57dSEddie Huang OF_EARLYCON_DECLARE(mtk8250, "mediatek,mt6577-uart", early_mtk8250_setup);
6777798edeeSArnd Bergmann #endif
67888725e91SArnd Bergmann
67988725e91SArnd Bergmann MODULE_AUTHOR("Matthias Brugger");
68088725e91SArnd Bergmann MODULE_LICENSE("GPL");
68188725e91SArnd Bergmann MODULE_DESCRIPTION("Mediatek 8250 serial port driver");
682