1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale lpuart serial port driver
5 * Copyright 2012-2014 Freescale Semiconductor, Inc.
9 #include <linux/console.h>
10 #include <linux/dma-mapping.h>
11 #include <linux/dmaengine.h>
12 #include <linux/dmapool.h>
14 #include <linux/irq.h>
15 #include <linux/module.h>
17 #include <linux/of_device.h>
18 #include <linux/of_dma.h>
19 #include <linux/serial_core.h>
20 #include <linux/slab.h>
21 #include <linux/tty_flip.h>
23 /* All registers are 8-bit width */
33 #define UARTMODEM 0x0d
34 #define UARTPFIFO 0x10
35 #define UARTCFIFO 0x11
36 #define UARTSFIFO 0x12
37 #define UARTTWFIFO 0x13
38 #define UARTTCFIFO 0x14
39 #define UARTRWFIFO 0x15
41 #define UARTBDH_LBKDIE 0x80
42 #define UARTBDH_RXEDGIE 0x40
43 #define UARTBDH_SBR_MASK 0x1f
45 #define UARTCR1_LOOPS 0x80
46 #define UARTCR1_RSRC 0x20
47 #define UARTCR1_M 0x10
48 #define UARTCR1_WAKE 0x08
49 #define UARTCR1_ILT 0x04
50 #define UARTCR1_PE 0x02
51 #define UARTCR1_PT 0x01
53 #define UARTCR2_TIE 0x80
54 #define UARTCR2_TCIE 0x40
55 #define UARTCR2_RIE 0x20
56 #define UARTCR2_ILIE 0x10
57 #define UARTCR2_TE 0x08
58 #define UARTCR2_RE 0x04
59 #define UARTCR2_RWU 0x02
60 #define UARTCR2_SBK 0x01
62 #define UARTSR1_TDRE 0x80
63 #define UARTSR1_TC 0x40
64 #define UARTSR1_RDRF 0x20
65 #define UARTSR1_IDLE 0x10
66 #define UARTSR1_OR 0x08
67 #define UARTSR1_NF 0x04
68 #define UARTSR1_FE 0x02
69 #define UARTSR1_PE 0x01
71 #define UARTCR3_R8 0x80
72 #define UARTCR3_T8 0x40
73 #define UARTCR3_TXDIR 0x20
74 #define UARTCR3_TXINV 0x10
75 #define UARTCR3_ORIE 0x08
76 #define UARTCR3_NEIE 0x04
77 #define UARTCR3_FEIE 0x02
78 #define UARTCR3_PEIE 0x01
80 #define UARTCR4_MAEN1 0x80
81 #define UARTCR4_MAEN2 0x40
82 #define UARTCR4_M10 0x20
83 #define UARTCR4_BRFA_MASK 0x1f
84 #define UARTCR4_BRFA_OFF 0
86 #define UARTCR5_TDMAS 0x80
87 #define UARTCR5_RDMAS 0x20
89 #define UARTMODEM_RXRTSE 0x08
90 #define UARTMODEM_TXRTSPOL 0x04
91 #define UARTMODEM_TXRTSE 0x02
92 #define UARTMODEM_TXCTSE 0x01
94 #define UARTPFIFO_TXFE 0x80
95 #define UARTPFIFO_FIFOSIZE_MASK 0x7
96 #define UARTPFIFO_TXSIZE_OFF 4
97 #define UARTPFIFO_RXFE 0x08
98 #define UARTPFIFO_RXSIZE_OFF 0
100 #define UARTCFIFO_TXFLUSH 0x80
101 #define UARTCFIFO_RXFLUSH 0x40
102 #define UARTCFIFO_RXOFE 0x04
103 #define UARTCFIFO_TXOFE 0x02
104 #define UARTCFIFO_RXUFE 0x01
106 #define UARTSFIFO_TXEMPT 0x80
107 #define UARTSFIFO_RXEMPT 0x40
108 #define UARTSFIFO_RXOF 0x04
109 #define UARTSFIFO_TXOF 0x02
110 #define UARTSFIFO_RXUF 0x01
112 /* 32-bit register definition */
113 #define UARTBAUD 0x00
114 #define UARTSTAT 0x04
115 #define UARTCTRL 0x08
116 #define UARTDATA 0x0C
117 #define UARTMATCH 0x10
118 #define UARTMODIR 0x14
119 #define UARTFIFO 0x18
120 #define UARTWATER 0x1c
122 #define UARTBAUD_MAEN1 0x80000000
123 #define UARTBAUD_MAEN2 0x40000000
124 #define UARTBAUD_M10 0x20000000
125 #define UARTBAUD_TDMAE 0x00800000
126 #define UARTBAUD_RDMAE 0x00200000
127 #define UARTBAUD_MATCFG 0x00400000
128 #define UARTBAUD_BOTHEDGE 0x00020000
129 #define UARTBAUD_RESYNCDIS 0x00010000
130 #define UARTBAUD_LBKDIE 0x00008000
131 #define UARTBAUD_RXEDGIE 0x00004000
132 #define UARTBAUD_SBNS 0x00002000
133 #define UARTBAUD_SBR 0x00000000
134 #define UARTBAUD_SBR_MASK 0x1fff
135 #define UARTBAUD_OSR_MASK 0x1f
136 #define UARTBAUD_OSR_SHIFT 24
138 #define UARTSTAT_LBKDIF 0x80000000
139 #define UARTSTAT_RXEDGIF 0x40000000
140 #define UARTSTAT_MSBF 0x20000000
141 #define UARTSTAT_RXINV 0x10000000
142 #define UARTSTAT_RWUID 0x08000000
143 #define UARTSTAT_BRK13 0x04000000
144 #define UARTSTAT_LBKDE 0x02000000
145 #define UARTSTAT_RAF 0x01000000
146 #define UARTSTAT_TDRE 0x00800000
147 #define UARTSTAT_TC 0x00400000
148 #define UARTSTAT_RDRF 0x00200000
149 #define UARTSTAT_IDLE 0x00100000
150 #define UARTSTAT_OR 0x00080000
151 #define UARTSTAT_NF 0x00040000
152 #define UARTSTAT_FE 0x00020000
153 #define UARTSTAT_PE 0x00010000
154 #define UARTSTAT_MA1F 0x00008000
155 #define UARTSTAT_M21F 0x00004000
157 #define UARTCTRL_R8T9 0x80000000
158 #define UARTCTRL_R9T8 0x40000000
159 #define UARTCTRL_TXDIR 0x20000000
160 #define UARTCTRL_TXINV 0x10000000
161 #define UARTCTRL_ORIE 0x08000000
162 #define UARTCTRL_NEIE 0x04000000
163 #define UARTCTRL_FEIE 0x02000000
164 #define UARTCTRL_PEIE 0x01000000
165 #define UARTCTRL_TIE 0x00800000
166 #define UARTCTRL_TCIE 0x00400000
167 #define UARTCTRL_RIE 0x00200000
168 #define UARTCTRL_ILIE 0x00100000
169 #define UARTCTRL_TE 0x00080000
170 #define UARTCTRL_RE 0x00040000
171 #define UARTCTRL_RWU 0x00020000
172 #define UARTCTRL_SBK 0x00010000
173 #define UARTCTRL_MA1IE 0x00008000
174 #define UARTCTRL_MA2IE 0x00004000
175 #define UARTCTRL_IDLECFG 0x00000100
176 #define UARTCTRL_LOOPS 0x00000080
177 #define UARTCTRL_DOZEEN 0x00000040
178 #define UARTCTRL_RSRC 0x00000020
179 #define UARTCTRL_M 0x00000010
180 #define UARTCTRL_WAKE 0x00000008
181 #define UARTCTRL_ILT 0x00000004
182 #define UARTCTRL_PE 0x00000002
183 #define UARTCTRL_PT 0x00000001
185 #define UARTDATA_NOISY 0x00008000
186 #define UARTDATA_PARITYE 0x00004000
187 #define UARTDATA_FRETSC 0x00002000
188 #define UARTDATA_RXEMPT 0x00001000
189 #define UARTDATA_IDLINE 0x00000800
190 #define UARTDATA_MASK 0x3ff
192 #define UARTMODIR_IREN 0x00020000
193 #define UARTMODIR_TXCTSSRC 0x00000020
194 #define UARTMODIR_TXCTSC 0x00000010
195 #define UARTMODIR_RXRTSE 0x00000008
196 #define UARTMODIR_TXRTSPOL 0x00000004
197 #define UARTMODIR_TXRTSE 0x00000002
198 #define UARTMODIR_TXCTSE 0x00000001
200 #define UARTFIFO_TXEMPT 0x00800000
201 #define UARTFIFO_RXEMPT 0x00400000
202 #define UARTFIFO_TXOF 0x00020000
203 #define UARTFIFO_RXUF 0x00010000
204 #define UARTFIFO_TXFLUSH 0x00008000
205 #define UARTFIFO_RXFLUSH 0x00004000
206 #define UARTFIFO_TXOFE 0x00000200
207 #define UARTFIFO_RXUFE 0x00000100
208 #define UARTFIFO_TXFE 0x00000080
209 #define UARTFIFO_FIFOSIZE_MASK 0x7
210 #define UARTFIFO_TXSIZE_OFF 4
211 #define UARTFIFO_RXFE 0x00000008
212 #define UARTFIFO_RXSIZE_OFF 0
213 #define UARTFIFO_DEPTH(x) (0x1 << ((x) ? ((x) + 1) : 0))
215 #define UARTWATER_COUNT_MASK 0xff
216 #define UARTWATER_TXCNT_OFF 8
217 #define UARTWATER_RXCNT_OFF 24
218 #define UARTWATER_WATER_MASK 0xff
219 #define UARTWATER_TXWATER_OFF 0
220 #define UARTWATER_RXWATER_OFF 16
222 /* Rx DMA timeout in ms, which is used to calculate Rx ring buffer size */
223 #define DMA_RX_TIMEOUT (10)
225 #define DRIVER_NAME "fsl-lpuart"
226 #define DEV_NAME "ttyLP"
229 /* IMX lpuart has four extra unused regs located at the beginning */
230 #define IMX_REG_OFF 0x10
232 static DEFINE_IDA(fsl_lpuart_ida
);
242 struct uart_port port
;
243 enum lpuart_type devtype
;
245 struct clk
*baud_clk
;
246 unsigned int txfifo_size
;
247 unsigned int rxfifo_size
;
249 bool lpuart_dma_tx_use
;
250 bool lpuart_dma_rx_use
;
251 struct dma_chan
*dma_tx_chan
;
252 struct dma_chan
*dma_rx_chan
;
253 struct dma_async_tx_descriptor
*dma_tx_desc
;
254 struct dma_async_tx_descriptor
*dma_rx_desc
;
255 dma_cookie_t dma_tx_cookie
;
256 dma_cookie_t dma_rx_cookie
;
257 unsigned int dma_tx_bytes
;
258 unsigned int dma_rx_bytes
;
259 bool dma_tx_in_progress
;
260 unsigned int dma_rx_timeout
;
261 struct timer_list lpuart_timer
;
262 struct scatterlist rx_sgl
, tx_sgl
[2];
263 struct circ_buf rx_ring
;
264 int rx_dma_rng_buf_len
;
265 unsigned int dma_tx_nents
;
266 wait_queue_head_t dma_wait
;
269 struct lpuart_soc_data
{
270 enum lpuart_type devtype
;
275 static const struct lpuart_soc_data vf_data
= {
276 .devtype
= VF610_LPUART
,
280 static const struct lpuart_soc_data ls_data
= {
281 .devtype
= LS1021A_LPUART
,
282 .iotype
= UPIO_MEM32BE
,
285 static struct lpuart_soc_data imx7ulp_data
= {
286 .devtype
= IMX7ULP_LPUART
,
287 .iotype
= UPIO_MEM32
,
288 .reg_off
= IMX_REG_OFF
,
291 static struct lpuart_soc_data imx8qxp_data
= {
292 .devtype
= IMX8QXP_LPUART
,
293 .iotype
= UPIO_MEM32
,
294 .reg_off
= IMX_REG_OFF
,
297 static const struct of_device_id lpuart_dt_ids
[] = {
298 { .compatible
= "fsl,vf610-lpuart", .data
= &vf_data
, },
299 { .compatible
= "fsl,ls1021a-lpuart", .data
= &ls_data
, },
300 { .compatible
= "fsl,imx7ulp-lpuart", .data
= &imx7ulp_data
, },
301 { .compatible
= "fsl,imx8qxp-lpuart", .data
= &imx8qxp_data
, },
304 MODULE_DEVICE_TABLE(of
, lpuart_dt_ids
);
306 /* Forward declare this for the dma callbacks*/
307 static void lpuart_dma_tx_complete(void *arg
);
309 static inline bool is_imx8qxp_lpuart(struct lpuart_port
*sport
)
311 return sport
->devtype
== IMX8QXP_LPUART
;
314 static inline u32
lpuart32_read(struct uart_port
*port
, u32 off
)
316 switch (port
->iotype
) {
318 return readl(port
->membase
+ off
);
320 return ioread32be(port
->membase
+ off
);
326 static inline void lpuart32_write(struct uart_port
*port
, u32 val
,
329 switch (port
->iotype
) {
331 writel(val
, port
->membase
+ off
);
334 iowrite32be(val
, port
->membase
+ off
);
339 static int __lpuart_enable_clks(struct lpuart_port
*sport
, bool is_en
)
344 ret
= clk_prepare_enable(sport
->ipg_clk
);
348 ret
= clk_prepare_enable(sport
->baud_clk
);
350 clk_disable_unprepare(sport
->ipg_clk
);
354 clk_disable_unprepare(sport
->baud_clk
);
355 clk_disable_unprepare(sport
->ipg_clk
);
361 static unsigned int lpuart_get_baud_clk_rate(struct lpuart_port
*sport
)
363 if (is_imx8qxp_lpuart(sport
))
364 return clk_get_rate(sport
->baud_clk
);
366 return clk_get_rate(sport
->ipg_clk
);
369 #define lpuart_enable_clks(x) __lpuart_enable_clks(x, true)
370 #define lpuart_disable_clks(x) __lpuart_enable_clks(x, false)
372 static void lpuart_stop_tx(struct uart_port
*port
)
376 temp
= readb(port
->membase
+ UARTCR2
);
377 temp
&= ~(UARTCR2_TIE
| UARTCR2_TCIE
);
378 writeb(temp
, port
->membase
+ UARTCR2
);
381 static void lpuart32_stop_tx(struct uart_port
*port
)
385 temp
= lpuart32_read(port
, UARTCTRL
);
386 temp
&= ~(UARTCTRL_TIE
| UARTCTRL_TCIE
);
387 lpuart32_write(port
, temp
, UARTCTRL
);
390 static void lpuart_stop_rx(struct uart_port
*port
)
394 temp
= readb(port
->membase
+ UARTCR2
);
395 writeb(temp
& ~UARTCR2_RE
, port
->membase
+ UARTCR2
);
398 static void lpuart32_stop_rx(struct uart_port
*port
)
402 temp
= lpuart32_read(port
, UARTCTRL
);
403 lpuart32_write(port
, temp
& ~UARTCTRL_RE
, UARTCTRL
);
406 static void lpuart_dma_tx(struct lpuart_port
*sport
)
408 struct circ_buf
*xmit
= &sport
->port
.state
->xmit
;
409 struct scatterlist
*sgl
= sport
->tx_sgl
;
410 struct device
*dev
= sport
->port
.dev
;
413 if (sport
->dma_tx_in_progress
)
416 sport
->dma_tx_bytes
= uart_circ_chars_pending(xmit
);
418 if (xmit
->tail
< xmit
->head
|| xmit
->head
== 0) {
419 sport
->dma_tx_nents
= 1;
420 sg_init_one(sgl
, xmit
->buf
+ xmit
->tail
, sport
->dma_tx_bytes
);
422 sport
->dma_tx_nents
= 2;
423 sg_init_table(sgl
, 2);
424 sg_set_buf(sgl
, xmit
->buf
+ xmit
->tail
,
425 UART_XMIT_SIZE
- xmit
->tail
);
426 sg_set_buf(sgl
+ 1, xmit
->buf
, xmit
->head
);
429 ret
= dma_map_sg(dev
, sgl
, sport
->dma_tx_nents
, DMA_TO_DEVICE
);
431 dev_err(dev
, "DMA mapping error for TX.\n");
435 sport
->dma_tx_desc
= dmaengine_prep_slave_sg(sport
->dma_tx_chan
, sgl
,
438 if (!sport
->dma_tx_desc
) {
439 dma_unmap_sg(dev
, sgl
, sport
->dma_tx_nents
, DMA_TO_DEVICE
);
440 dev_err(dev
, "Cannot prepare TX slave DMA!\n");
444 sport
->dma_tx_desc
->callback
= lpuart_dma_tx_complete
;
445 sport
->dma_tx_desc
->callback_param
= sport
;
446 sport
->dma_tx_in_progress
= true;
447 sport
->dma_tx_cookie
= dmaengine_submit(sport
->dma_tx_desc
);
448 dma_async_issue_pending(sport
->dma_tx_chan
);
451 static bool lpuart_stopped_or_empty(struct uart_port
*port
)
453 return uart_circ_empty(&port
->state
->xmit
) || uart_tx_stopped(port
);
456 static void lpuart_dma_tx_complete(void *arg
)
458 struct lpuart_port
*sport
= arg
;
459 struct scatterlist
*sgl
= &sport
->tx_sgl
[0];
460 struct circ_buf
*xmit
= &sport
->port
.state
->xmit
;
463 spin_lock_irqsave(&sport
->port
.lock
, flags
);
465 dma_unmap_sg(sport
->port
.dev
, sgl
, sport
->dma_tx_nents
, DMA_TO_DEVICE
);
467 xmit
->tail
= (xmit
->tail
+ sport
->dma_tx_bytes
) & (UART_XMIT_SIZE
- 1);
469 sport
->port
.icount
.tx
+= sport
->dma_tx_bytes
;
470 sport
->dma_tx_in_progress
= false;
471 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
473 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
474 uart_write_wakeup(&sport
->port
);
476 if (waitqueue_active(&sport
->dma_wait
)) {
477 wake_up(&sport
->dma_wait
);
481 spin_lock_irqsave(&sport
->port
.lock
, flags
);
483 if (!lpuart_stopped_or_empty(&sport
->port
))
484 lpuart_dma_tx(sport
);
486 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
489 static dma_addr_t
lpuart_dma_datareg_addr(struct lpuart_port
*sport
)
491 switch (sport
->port
.iotype
) {
493 return sport
->port
.mapbase
+ UARTDATA
;
495 return sport
->port
.mapbase
+ UARTDATA
+ sizeof(u32
) - 1;
497 return sport
->port
.mapbase
+ UARTDR
;
500 static int lpuart_dma_tx_request(struct uart_port
*port
)
502 struct lpuart_port
*sport
= container_of(port
,
503 struct lpuart_port
, port
);
504 struct dma_slave_config dma_tx_sconfig
= {};
507 dma_tx_sconfig
.dst_addr
= lpuart_dma_datareg_addr(sport
);
508 dma_tx_sconfig
.dst_addr_width
= DMA_SLAVE_BUSWIDTH_1_BYTE
;
509 dma_tx_sconfig
.dst_maxburst
= 1;
510 dma_tx_sconfig
.direction
= DMA_MEM_TO_DEV
;
511 ret
= dmaengine_slave_config(sport
->dma_tx_chan
, &dma_tx_sconfig
);
514 dev_err(sport
->port
.dev
,
515 "DMA slave config failed, err = %d\n", ret
);
522 static bool lpuart_is_32(struct lpuart_port
*sport
)
524 return sport
->port
.iotype
== UPIO_MEM32
||
525 sport
->port
.iotype
== UPIO_MEM32BE
;
528 static void lpuart_flush_buffer(struct uart_port
*port
)
530 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
533 if (sport
->lpuart_dma_tx_use
) {
534 if (sport
->dma_tx_in_progress
) {
535 dma_unmap_sg(sport
->port
.dev
, &sport
->tx_sgl
[0],
536 sport
->dma_tx_nents
, DMA_TO_DEVICE
);
537 sport
->dma_tx_in_progress
= false;
539 dmaengine_terminate_all(sport
->dma_tx_chan
);
542 if (lpuart_is_32(sport
)) {
543 val
= lpuart32_read(&sport
->port
, UARTFIFO
);
544 val
|= UARTFIFO_TXFLUSH
| UARTFIFO_RXFLUSH
;
545 lpuart32_write(&sport
->port
, val
, UARTFIFO
);
547 val
= readb(sport
->port
.membase
+ UARTCFIFO
);
548 val
|= UARTCFIFO_TXFLUSH
| UARTCFIFO_RXFLUSH
;
549 writeb(val
, sport
->port
.membase
+ UARTCFIFO
);
553 static void lpuart_wait_bit_set(struct uart_port
*port
, unsigned int offset
,
556 while (!(readb(port
->membase
+ offset
) & bit
))
560 static void lpuart32_wait_bit_set(struct uart_port
*port
, unsigned int offset
,
563 while (!(lpuart32_read(port
, offset
) & bit
))
567 #if defined(CONFIG_CONSOLE_POLL)
569 static int lpuart_poll_init(struct uart_port
*port
)
571 struct lpuart_port
*sport
= container_of(port
,
572 struct lpuart_port
, port
);
576 sport
->port
.fifosize
= 0;
578 spin_lock_irqsave(&sport
->port
.lock
, flags
);
579 /* Disable Rx & Tx */
580 writeb(0, sport
->port
.membase
+ UARTCR2
);
582 temp
= readb(sport
->port
.membase
+ UARTPFIFO
);
583 /* Enable Rx and Tx FIFO */
584 writeb(temp
| UARTPFIFO_RXFE
| UARTPFIFO_TXFE
,
585 sport
->port
.membase
+ UARTPFIFO
);
587 /* flush Tx and Rx FIFO */
588 writeb(UARTCFIFO_TXFLUSH
| UARTCFIFO_RXFLUSH
,
589 sport
->port
.membase
+ UARTCFIFO
);
591 /* explicitly clear RDRF */
592 if (readb(sport
->port
.membase
+ UARTSR1
) & UARTSR1_RDRF
) {
593 readb(sport
->port
.membase
+ UARTDR
);
594 writeb(UARTSFIFO_RXUF
, sport
->port
.membase
+ UARTSFIFO
);
597 writeb(0, sport
->port
.membase
+ UARTTWFIFO
);
598 writeb(1, sport
->port
.membase
+ UARTRWFIFO
);
600 /* Enable Rx and Tx */
601 writeb(UARTCR2_RE
| UARTCR2_TE
, sport
->port
.membase
+ UARTCR2
);
602 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
607 static void lpuart_poll_put_char(struct uart_port
*port
, unsigned char c
)
610 lpuart_wait_bit_set(port
, UARTSR1
, UARTSR1_TDRE
);
611 writeb(c
, port
->membase
+ UARTDR
);
614 static int lpuart_poll_get_char(struct uart_port
*port
)
616 if (!(readb(port
->membase
+ UARTSR1
) & UARTSR1_RDRF
))
619 return readb(port
->membase
+ UARTDR
);
622 static int lpuart32_poll_init(struct uart_port
*port
)
625 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
628 sport
->port
.fifosize
= 0;
630 spin_lock_irqsave(&sport
->port
.lock
, flags
);
632 /* Disable Rx & Tx */
633 lpuart32_write(&sport
->port
, UARTCTRL
, 0);
635 temp
= lpuart32_read(&sport
->port
, UARTFIFO
);
637 /* Enable Rx and Tx FIFO */
638 lpuart32_write(&sport
->port
, UARTFIFO
,
639 temp
| UARTFIFO_RXFE
| UARTFIFO_TXFE
);
641 /* flush Tx and Rx FIFO */
642 lpuart32_write(&sport
->port
, UARTFIFO
,
643 UARTFIFO_TXFLUSH
| UARTFIFO_RXFLUSH
);
645 /* explicitly clear RDRF */
646 if (lpuart32_read(&sport
->port
, UARTSTAT
) & UARTSTAT_RDRF
) {
647 lpuart32_read(&sport
->port
, UARTDATA
);
648 lpuart32_write(&sport
->port
, UARTFIFO
, UARTFIFO_RXUF
);
651 /* Enable Rx and Tx */
652 lpuart32_write(&sport
->port
, UARTCTRL
, UARTCTRL_RE
| UARTCTRL_TE
);
653 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
658 static void lpuart32_poll_put_char(struct uart_port
*port
, unsigned char c
)
660 lpuart32_wait_bit_set(port
, UARTSTAT
, UARTSTAT_TDRE
);
661 lpuart32_write(port
, UARTDATA
, c
);
664 static int lpuart32_poll_get_char(struct uart_port
*port
)
666 if (!(lpuart32_read(port
, UARTSTAT
) & UARTSTAT_RDRF
))
669 return lpuart32_read(port
, UARTDATA
);
673 static inline void lpuart_transmit_buffer(struct lpuart_port
*sport
)
675 struct circ_buf
*xmit
= &sport
->port
.state
->xmit
;
677 if (sport
->port
.x_char
) {
678 writeb(sport
->port
.x_char
, sport
->port
.membase
+ UARTDR
);
679 sport
->port
.icount
.tx
++;
680 sport
->port
.x_char
= 0;
684 if (lpuart_stopped_or_empty(&sport
->port
)) {
685 lpuart_stop_tx(&sport
->port
);
689 while (!uart_circ_empty(xmit
) &&
690 (readb(sport
->port
.membase
+ UARTTCFIFO
) < sport
->txfifo_size
)) {
691 writeb(xmit
->buf
[xmit
->tail
], sport
->port
.membase
+ UARTDR
);
692 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
693 sport
->port
.icount
.tx
++;
696 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
697 uart_write_wakeup(&sport
->port
);
699 if (uart_circ_empty(xmit
))
700 lpuart_stop_tx(&sport
->port
);
703 static inline void lpuart32_transmit_buffer(struct lpuart_port
*sport
)
705 struct circ_buf
*xmit
= &sport
->port
.state
->xmit
;
708 if (sport
->port
.x_char
) {
709 lpuart32_write(&sport
->port
, sport
->port
.x_char
, UARTDATA
);
710 sport
->port
.icount
.tx
++;
711 sport
->port
.x_char
= 0;
715 if (lpuart_stopped_or_empty(&sport
->port
)) {
716 lpuart32_stop_tx(&sport
->port
);
720 txcnt
= lpuart32_read(&sport
->port
, UARTWATER
);
721 txcnt
= txcnt
>> UARTWATER_TXCNT_OFF
;
722 txcnt
&= UARTWATER_COUNT_MASK
;
723 while (!uart_circ_empty(xmit
) && (txcnt
< sport
->txfifo_size
)) {
724 lpuart32_write(&sport
->port
, xmit
->buf
[xmit
->tail
], UARTDATA
);
725 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
726 sport
->port
.icount
.tx
++;
727 txcnt
= lpuart32_read(&sport
->port
, UARTWATER
);
728 txcnt
= txcnt
>> UARTWATER_TXCNT_OFF
;
729 txcnt
&= UARTWATER_COUNT_MASK
;
732 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
733 uart_write_wakeup(&sport
->port
);
735 if (uart_circ_empty(xmit
))
736 lpuart32_stop_tx(&sport
->port
);
739 static void lpuart_start_tx(struct uart_port
*port
)
741 struct lpuart_port
*sport
= container_of(port
,
742 struct lpuart_port
, port
);
745 temp
= readb(port
->membase
+ UARTCR2
);
746 writeb(temp
| UARTCR2_TIE
, port
->membase
+ UARTCR2
);
748 if (sport
->lpuart_dma_tx_use
) {
749 if (!lpuart_stopped_or_empty(port
))
750 lpuart_dma_tx(sport
);
752 if (readb(port
->membase
+ UARTSR1
) & UARTSR1_TDRE
)
753 lpuart_transmit_buffer(sport
);
757 static void lpuart32_start_tx(struct uart_port
*port
)
759 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
762 if (sport
->lpuart_dma_tx_use
) {
763 if (!lpuart_stopped_or_empty(port
))
764 lpuart_dma_tx(sport
);
766 temp
= lpuart32_read(port
, UARTCTRL
);
767 lpuart32_write(port
, temp
| UARTCTRL_TIE
, UARTCTRL
);
769 if (lpuart32_read(port
, UARTSTAT
) & UARTSTAT_TDRE
)
770 lpuart32_transmit_buffer(sport
);
774 /* return TIOCSER_TEMT when transmitter is not busy */
775 static unsigned int lpuart_tx_empty(struct uart_port
*port
)
777 struct lpuart_port
*sport
= container_of(port
,
778 struct lpuart_port
, port
);
779 unsigned char sr1
= readb(port
->membase
+ UARTSR1
);
780 unsigned char sfifo
= readb(port
->membase
+ UARTSFIFO
);
782 if (sport
->dma_tx_in_progress
)
785 if (sr1
& UARTSR1_TC
&& sfifo
& UARTSFIFO_TXEMPT
)
791 static unsigned int lpuart32_tx_empty(struct uart_port
*port
)
793 struct lpuart_port
*sport
= container_of(port
,
794 struct lpuart_port
, port
);
795 unsigned long stat
= lpuart32_read(port
, UARTSTAT
);
796 unsigned long sfifo
= lpuart32_read(port
, UARTFIFO
);
798 if (sport
->dma_tx_in_progress
)
801 if (stat
& UARTSTAT_TC
&& sfifo
& UARTFIFO_TXEMPT
)
807 static void lpuart_txint(struct lpuart_port
*sport
)
811 spin_lock_irqsave(&sport
->port
.lock
, flags
);
812 lpuart_transmit_buffer(sport
);
813 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
816 static void lpuart_rxint(struct lpuart_port
*sport
)
818 unsigned int flg
, ignored
= 0, overrun
= 0;
819 struct tty_port
*port
= &sport
->port
.state
->port
;
821 unsigned char rx
, sr
;
823 spin_lock_irqsave(&sport
->port
.lock
, flags
);
825 while (!(readb(sport
->port
.membase
+ UARTSFIFO
) & UARTSFIFO_RXEMPT
)) {
827 sport
->port
.icount
.rx
++;
829 * to clear the FE, OR, NF, FE, PE flags,
830 * read SR1 then read DR
832 sr
= readb(sport
->port
.membase
+ UARTSR1
);
833 rx
= readb(sport
->port
.membase
+ UARTDR
);
835 if (uart_handle_sysrq_char(&sport
->port
, (unsigned char)rx
))
838 if (sr
& (UARTSR1_PE
| UARTSR1_OR
| UARTSR1_FE
)) {
840 sport
->port
.icount
.parity
++;
841 else if (sr
& UARTSR1_FE
)
842 sport
->port
.icount
.frame
++;
847 if (sr
& sport
->port
.ignore_status_mask
) {
853 sr
&= sport
->port
.read_status_mask
;
857 else if (sr
& UARTSR1_FE
)
863 sport
->port
.sysrq
= 0;
866 tty_insert_flip_char(port
, rx
, flg
);
871 sport
->port
.icount
.overrun
+= overrun
;
874 * Overruns cause FIFO pointers to become missaligned.
875 * Flushing the receive FIFO reinitializes the pointers.
877 writeb(UARTCFIFO_RXFLUSH
, sport
->port
.membase
+ UARTCFIFO
);
878 writeb(UARTSFIFO_RXOF
, sport
->port
.membase
+ UARTSFIFO
);
881 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
883 tty_flip_buffer_push(port
);
886 static void lpuart32_txint(struct lpuart_port
*sport
)
890 spin_lock_irqsave(&sport
->port
.lock
, flags
);
891 lpuart32_transmit_buffer(sport
);
892 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
895 static void lpuart32_rxint(struct lpuart_port
*sport
)
897 unsigned int flg
, ignored
= 0;
898 struct tty_port
*port
= &sport
->port
.state
->port
;
900 unsigned long rx
, sr
;
902 spin_lock_irqsave(&sport
->port
.lock
, flags
);
904 while (!(lpuart32_read(&sport
->port
, UARTFIFO
) & UARTFIFO_RXEMPT
)) {
906 sport
->port
.icount
.rx
++;
908 * to clear the FE, OR, NF, FE, PE flags,
909 * read STAT then read DATA reg
911 sr
= lpuart32_read(&sport
->port
, UARTSTAT
);
912 rx
= lpuart32_read(&sport
->port
, UARTDATA
);
915 if (uart_handle_sysrq_char(&sport
->port
, (unsigned char)rx
))
918 if (sr
& (UARTSTAT_PE
| UARTSTAT_OR
| UARTSTAT_FE
)) {
919 if (sr
& UARTSTAT_PE
)
920 sport
->port
.icount
.parity
++;
921 else if (sr
& UARTSTAT_FE
)
922 sport
->port
.icount
.frame
++;
924 if (sr
& UARTSTAT_OR
)
925 sport
->port
.icount
.overrun
++;
927 if (sr
& sport
->port
.ignore_status_mask
) {
933 sr
&= sport
->port
.read_status_mask
;
935 if (sr
& UARTSTAT_PE
)
937 else if (sr
& UARTSTAT_FE
)
940 if (sr
& UARTSTAT_OR
)
943 sport
->port
.sysrq
= 0;
946 tty_insert_flip_char(port
, rx
, flg
);
950 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
952 tty_flip_buffer_push(port
);
955 static irqreturn_t
lpuart_int(int irq
, void *dev_id
)
957 struct lpuart_port
*sport
= dev_id
;
960 sts
= readb(sport
->port
.membase
+ UARTSR1
);
962 if (sts
& UARTSR1_RDRF
&& !sport
->lpuart_dma_rx_use
)
965 if (sts
& UARTSR1_TDRE
&& !sport
->lpuart_dma_tx_use
)
971 static irqreturn_t
lpuart32_int(int irq
, void *dev_id
)
973 struct lpuart_port
*sport
= dev_id
;
974 unsigned long sts
, rxcount
;
976 sts
= lpuart32_read(&sport
->port
, UARTSTAT
);
977 rxcount
= lpuart32_read(&sport
->port
, UARTWATER
);
978 rxcount
= rxcount
>> UARTWATER_RXCNT_OFF
;
980 if ((sts
& UARTSTAT_RDRF
|| rxcount
> 0) && !sport
->lpuart_dma_rx_use
)
981 lpuart32_rxint(sport
);
983 if ((sts
& UARTSTAT_TDRE
) && !sport
->lpuart_dma_tx_use
)
984 lpuart32_txint(sport
);
986 lpuart32_write(&sport
->port
, sts
, UARTSTAT
);
990 static void lpuart_copy_rx_to_tty(struct lpuart_port
*sport
)
992 struct tty_port
*port
= &sport
->port
.state
->port
;
993 struct dma_tx_state state
;
994 enum dma_status dmastat
;
995 struct circ_buf
*ring
= &sport
->rx_ring
;
999 if (lpuart_is_32(sport
)) {
1000 unsigned long sr
= lpuart32_read(&sport
->port
, UARTSTAT
);
1002 if (sr
& (UARTSTAT_PE
| UARTSTAT_FE
)) {
1003 /* Read DR to clear the error flags */
1004 lpuart32_read(&sport
->port
, UARTDATA
);
1006 if (sr
& UARTSTAT_PE
)
1007 sport
->port
.icount
.parity
++;
1008 else if (sr
& UARTSTAT_FE
)
1009 sport
->port
.icount
.frame
++;
1012 unsigned char sr
= readb(sport
->port
.membase
+ UARTSR1
);
1014 if (sr
& (UARTSR1_PE
| UARTSR1_FE
)) {
1017 /* Disable receiver during this operation... */
1018 cr2
= readb(sport
->port
.membase
+ UARTCR2
);
1020 writeb(cr2
, sport
->port
.membase
+ UARTCR2
);
1022 /* Read DR to clear the error flags */
1023 readb(sport
->port
.membase
+ UARTDR
);
1025 if (sr
& UARTSR1_PE
)
1026 sport
->port
.icount
.parity
++;
1027 else if (sr
& UARTSR1_FE
)
1028 sport
->port
.icount
.frame
++;
1030 * At this point parity/framing error is
1031 * cleared However, since the DMA already read
1032 * the data register and we had to read it
1033 * again after reading the status register to
1034 * properly clear the flags, the FIFO actually
1035 * underflowed... This requires a clearing of
1038 if (readb(sport
->port
.membase
+ UARTSFIFO
) &
1040 writeb(UARTSFIFO_RXUF
,
1041 sport
->port
.membase
+ UARTSFIFO
);
1042 writeb(UARTCFIFO_RXFLUSH
,
1043 sport
->port
.membase
+ UARTCFIFO
);
1047 writeb(cr2
, sport
->port
.membase
+ UARTCR2
);
1051 async_tx_ack(sport
->dma_rx_desc
);
1053 spin_lock_irqsave(&sport
->port
.lock
, flags
);
1055 dmastat
= dmaengine_tx_status(sport
->dma_rx_chan
,
1056 sport
->dma_rx_cookie
,
1059 if (dmastat
== DMA_ERROR
) {
1060 dev_err(sport
->port
.dev
, "Rx DMA transfer failed!\n");
1061 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
1065 /* CPU claims ownership of RX DMA buffer */
1066 dma_sync_sg_for_cpu(sport
->port
.dev
, &sport
->rx_sgl
, 1, DMA_FROM_DEVICE
);
1069 * ring->head points to the end of data already written by the DMA.
1070 * ring->tail points to the beginning of data to be read by the
1072 * The current transfer size should not be larger than the dma buffer
1075 ring
->head
= sport
->rx_sgl
.length
- state
.residue
;
1076 BUG_ON(ring
->head
> sport
->rx_sgl
.length
);
1078 * At this point ring->head may point to the first byte right after the
1079 * last byte of the dma buffer:
1080 * 0 <= ring->head <= sport->rx_sgl.length
1082 * However ring->tail must always points inside the dma buffer:
1083 * 0 <= ring->tail <= sport->rx_sgl.length - 1
1085 * Since we use a ring buffer, we have to handle the case
1086 * where head is lower than tail. In such a case, we first read from
1087 * tail to the end of the buffer then reset tail.
1089 if (ring
->head
< ring
->tail
) {
1090 count
= sport
->rx_sgl
.length
- ring
->tail
;
1092 tty_insert_flip_string(port
, ring
->buf
+ ring
->tail
, count
);
1094 sport
->port
.icount
.rx
+= count
;
1097 /* Finally we read data from tail to head */
1098 if (ring
->tail
< ring
->head
) {
1099 count
= ring
->head
- ring
->tail
;
1100 tty_insert_flip_string(port
, ring
->buf
+ ring
->tail
, count
);
1101 /* Wrap ring->head if needed */
1102 if (ring
->head
>= sport
->rx_sgl
.length
)
1104 ring
->tail
= ring
->head
;
1105 sport
->port
.icount
.rx
+= count
;
1108 dma_sync_sg_for_device(sport
->port
.dev
, &sport
->rx_sgl
, 1,
1111 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
1113 tty_flip_buffer_push(port
);
1114 mod_timer(&sport
->lpuart_timer
, jiffies
+ sport
->dma_rx_timeout
);
1117 static void lpuart_dma_rx_complete(void *arg
)
1119 struct lpuart_port
*sport
= arg
;
1121 lpuart_copy_rx_to_tty(sport
);
1124 static void lpuart_timer_func(struct timer_list
*t
)
1126 struct lpuart_port
*sport
= from_timer(sport
, t
, lpuart_timer
);
1128 lpuart_copy_rx_to_tty(sport
);
1131 static inline int lpuart_start_rx_dma(struct lpuart_port
*sport
)
1133 struct dma_slave_config dma_rx_sconfig
= {};
1134 struct circ_buf
*ring
= &sport
->rx_ring
;
1137 struct tty_port
*port
= &sport
->port
.state
->port
;
1138 struct tty_struct
*tty
= port
->tty
;
1139 struct ktermios
*termios
= &tty
->termios
;
1141 baud
= tty_get_baud_rate(tty
);
1143 bits
= (termios
->c_cflag
& CSIZE
) == CS7
? 9 : 10;
1144 if (termios
->c_cflag
& PARENB
)
1148 * Calculate length of one DMA buffer size to keep latency below
1149 * 10ms at any baud rate.
1151 sport
->rx_dma_rng_buf_len
= (DMA_RX_TIMEOUT
* baud
/ bits
/ 1000) * 2;
1152 sport
->rx_dma_rng_buf_len
= (1 << (fls(sport
->rx_dma_rng_buf_len
) - 1));
1153 if (sport
->rx_dma_rng_buf_len
< 16)
1154 sport
->rx_dma_rng_buf_len
= 16;
1156 ring
->buf
= kzalloc(sport
->rx_dma_rng_buf_len
, GFP_ATOMIC
);
1160 sg_init_one(&sport
->rx_sgl
, ring
->buf
, sport
->rx_dma_rng_buf_len
);
1161 nent
= dma_map_sg(sport
->port
.dev
, &sport
->rx_sgl
, 1, DMA_FROM_DEVICE
);
1164 dev_err(sport
->port
.dev
, "DMA Rx mapping error\n");
1168 dma_rx_sconfig
.src_addr
= lpuart_dma_datareg_addr(sport
);
1169 dma_rx_sconfig
.src_addr_width
= DMA_SLAVE_BUSWIDTH_1_BYTE
;
1170 dma_rx_sconfig
.src_maxburst
= 1;
1171 dma_rx_sconfig
.direction
= DMA_DEV_TO_MEM
;
1172 ret
= dmaengine_slave_config(sport
->dma_rx_chan
, &dma_rx_sconfig
);
1175 dev_err(sport
->port
.dev
,
1176 "DMA Rx slave config failed, err = %d\n", ret
);
1180 sport
->dma_rx_desc
= dmaengine_prep_dma_cyclic(sport
->dma_rx_chan
,
1181 sg_dma_address(&sport
->rx_sgl
),
1182 sport
->rx_sgl
.length
,
1183 sport
->rx_sgl
.length
/ 2,
1185 DMA_PREP_INTERRUPT
);
1186 if (!sport
->dma_rx_desc
) {
1187 dev_err(sport
->port
.dev
, "Cannot prepare cyclic DMA\n");
1191 sport
->dma_rx_desc
->callback
= lpuart_dma_rx_complete
;
1192 sport
->dma_rx_desc
->callback_param
= sport
;
1193 sport
->dma_rx_cookie
= dmaengine_submit(sport
->dma_rx_desc
);
1194 dma_async_issue_pending(sport
->dma_rx_chan
);
1196 if (lpuart_is_32(sport
)) {
1197 unsigned long temp
= lpuart32_read(&sport
->port
, UARTBAUD
);
1199 lpuart32_write(&sport
->port
, temp
| UARTBAUD_RDMAE
, UARTBAUD
);
1201 writeb(readb(sport
->port
.membase
+ UARTCR5
) | UARTCR5_RDMAS
,
1202 sport
->port
.membase
+ UARTCR5
);
1208 static void lpuart_dma_rx_free(struct uart_port
*port
)
1210 struct lpuart_port
*sport
= container_of(port
,
1211 struct lpuart_port
, port
);
1213 if (sport
->dma_rx_chan
)
1214 dmaengine_terminate_all(sport
->dma_rx_chan
);
1216 dma_unmap_sg(sport
->port
.dev
, &sport
->rx_sgl
, 1, DMA_FROM_DEVICE
);
1217 kfree(sport
->rx_ring
.buf
);
1218 sport
->rx_ring
.tail
= 0;
1219 sport
->rx_ring
.head
= 0;
1220 sport
->dma_rx_desc
= NULL
;
1221 sport
->dma_rx_cookie
= -EINVAL
;
1224 static int lpuart_config_rs485(struct uart_port
*port
,
1225 struct serial_rs485
*rs485
)
1227 struct lpuart_port
*sport
= container_of(port
,
1228 struct lpuart_port
, port
);
1230 u8 modem
= readb(sport
->port
.membase
+ UARTMODEM
) &
1231 ~(UARTMODEM_TXRTSPOL
| UARTMODEM_TXRTSE
);
1232 writeb(modem
, sport
->port
.membase
+ UARTMODEM
);
1234 /* clear unsupported configurations */
1235 rs485
->delay_rts_before_send
= 0;
1236 rs485
->delay_rts_after_send
= 0;
1237 rs485
->flags
&= ~SER_RS485_RX_DURING_TX
;
1239 if (rs485
->flags
& SER_RS485_ENABLED
) {
1240 /* Enable auto RS-485 RTS mode */
1241 modem
|= UARTMODEM_TXRTSE
;
1244 * RTS needs to be logic HIGH either during transer _or_ after
1245 * transfer, other variants are not supported by the hardware.
1248 if (!(rs485
->flags
& (SER_RS485_RTS_ON_SEND
|
1249 SER_RS485_RTS_AFTER_SEND
)))
1250 rs485
->flags
|= SER_RS485_RTS_ON_SEND
;
1252 if (rs485
->flags
& SER_RS485_RTS_ON_SEND
&&
1253 rs485
->flags
& SER_RS485_RTS_AFTER_SEND
)
1254 rs485
->flags
&= ~SER_RS485_RTS_AFTER_SEND
;
1257 * The hardware defaults to RTS logic HIGH while transfer.
1258 * Switch polarity in case RTS shall be logic HIGH
1260 * Note: UART is assumed to be active high.
1262 if (rs485
->flags
& SER_RS485_RTS_ON_SEND
)
1263 modem
&= ~UARTMODEM_TXRTSPOL
;
1264 else if (rs485
->flags
& SER_RS485_RTS_AFTER_SEND
)
1265 modem
|= UARTMODEM_TXRTSPOL
;
1268 /* Store the new configuration */
1269 sport
->port
.rs485
= *rs485
;
1271 writeb(modem
, sport
->port
.membase
+ UARTMODEM
);
1275 static int lpuart32_config_rs485(struct uart_port
*port
,
1276 struct serial_rs485
*rs485
)
1278 struct lpuart_port
*sport
= container_of(port
,
1279 struct lpuart_port
, port
);
1281 unsigned long modem
= lpuart32_read(&sport
->port
, UARTMODIR
)
1282 & ~(UARTMODEM_TXRTSPOL
| UARTMODEM_TXRTSE
);
1283 lpuart32_write(&sport
->port
, modem
, UARTMODIR
);
1285 /* clear unsupported configurations */
1286 rs485
->delay_rts_before_send
= 0;
1287 rs485
->delay_rts_after_send
= 0;
1288 rs485
->flags
&= ~SER_RS485_RX_DURING_TX
;
1290 if (rs485
->flags
& SER_RS485_ENABLED
) {
1291 /* Enable auto RS-485 RTS mode */
1292 modem
|= UARTMODEM_TXRTSE
;
1295 * RTS needs to be logic HIGH either during transer _or_ after
1296 * transfer, other variants are not supported by the hardware.
1299 if (!(rs485
->flags
& (SER_RS485_RTS_ON_SEND
|
1300 SER_RS485_RTS_AFTER_SEND
)))
1301 rs485
->flags
|= SER_RS485_RTS_ON_SEND
;
1303 if (rs485
->flags
& SER_RS485_RTS_ON_SEND
&&
1304 rs485
->flags
& SER_RS485_RTS_AFTER_SEND
)
1305 rs485
->flags
&= ~SER_RS485_RTS_AFTER_SEND
;
1308 * The hardware defaults to RTS logic HIGH while transfer.
1309 * Switch polarity in case RTS shall be logic HIGH
1311 * Note: UART is assumed to be active high.
1313 if (rs485
->flags
& SER_RS485_RTS_ON_SEND
)
1314 modem
&= ~UARTMODEM_TXRTSPOL
;
1315 else if (rs485
->flags
& SER_RS485_RTS_AFTER_SEND
)
1316 modem
|= UARTMODEM_TXRTSPOL
;
1319 /* Store the new configuration */
1320 sport
->port
.rs485
= *rs485
;
1322 lpuart32_write(&sport
->port
, modem
, UARTMODIR
);
1326 static unsigned int lpuart_get_mctrl(struct uart_port
*port
)
1328 unsigned int temp
= 0;
1331 reg
= readb(port
->membase
+ UARTMODEM
);
1332 if (reg
& UARTMODEM_TXCTSE
)
1335 if (reg
& UARTMODEM_RXRTSE
)
1341 static unsigned int lpuart32_get_mctrl(struct uart_port
*port
)
1343 unsigned int temp
= 0;
1346 reg
= lpuart32_read(port
, UARTMODIR
);
1347 if (reg
& UARTMODIR_TXCTSE
)
1350 if (reg
& UARTMODIR_RXRTSE
)
1356 static void lpuart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
1359 struct lpuart_port
*sport
= container_of(port
,
1360 struct lpuart_port
, port
);
1362 /* Make sure RXRTSE bit is not set when RS485 is enabled */
1363 if (!(sport
->port
.rs485
.flags
& SER_RS485_ENABLED
)) {
1364 temp
= readb(sport
->port
.membase
+ UARTMODEM
) &
1365 ~(UARTMODEM_RXRTSE
| UARTMODEM_TXCTSE
);
1367 if (mctrl
& TIOCM_RTS
)
1368 temp
|= UARTMODEM_RXRTSE
;
1370 if (mctrl
& TIOCM_CTS
)
1371 temp
|= UARTMODEM_TXCTSE
;
1373 writeb(temp
, port
->membase
+ UARTMODEM
);
1377 static void lpuart32_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
1382 static void lpuart_break_ctl(struct uart_port
*port
, int break_state
)
1386 temp
= readb(port
->membase
+ UARTCR2
) & ~UARTCR2_SBK
;
1388 if (break_state
!= 0)
1389 temp
|= UARTCR2_SBK
;
1391 writeb(temp
, port
->membase
+ UARTCR2
);
1394 static void lpuart32_break_ctl(struct uart_port
*port
, int break_state
)
1398 temp
= lpuart32_read(port
, UARTCTRL
) & ~UARTCTRL_SBK
;
1400 if (break_state
!= 0)
1401 temp
|= UARTCTRL_SBK
;
1403 lpuart32_write(port
, temp
, UARTCTRL
);
1406 static void lpuart_setup_watermark(struct lpuart_port
*sport
)
1408 unsigned char val
, cr2
;
1409 unsigned char cr2_saved
;
1411 cr2
= readb(sport
->port
.membase
+ UARTCR2
);
1413 cr2
&= ~(UARTCR2_TIE
| UARTCR2_TCIE
| UARTCR2_TE
|
1414 UARTCR2_RIE
| UARTCR2_RE
);
1415 writeb(cr2
, sport
->port
.membase
+ UARTCR2
);
1417 val
= readb(sport
->port
.membase
+ UARTPFIFO
);
1418 writeb(val
| UARTPFIFO_TXFE
| UARTPFIFO_RXFE
,
1419 sport
->port
.membase
+ UARTPFIFO
);
1421 /* flush Tx and Rx FIFO */
1422 writeb(UARTCFIFO_TXFLUSH
| UARTCFIFO_RXFLUSH
,
1423 sport
->port
.membase
+ UARTCFIFO
);
1425 /* explicitly clear RDRF */
1426 if (readb(sport
->port
.membase
+ UARTSR1
) & UARTSR1_RDRF
) {
1427 readb(sport
->port
.membase
+ UARTDR
);
1428 writeb(UARTSFIFO_RXUF
, sport
->port
.membase
+ UARTSFIFO
);
1431 writeb(0, sport
->port
.membase
+ UARTTWFIFO
);
1432 writeb(1, sport
->port
.membase
+ UARTRWFIFO
);
1435 writeb(cr2_saved
, sport
->port
.membase
+ UARTCR2
);
1438 static void lpuart_setup_watermark_enable(struct lpuart_port
*sport
)
1442 lpuart_setup_watermark(sport
);
1444 cr2
= readb(sport
->port
.membase
+ UARTCR2
);
1445 cr2
|= UARTCR2_RIE
| UARTCR2_RE
| UARTCR2_TE
;
1446 writeb(cr2
, sport
->port
.membase
+ UARTCR2
);
1449 static void lpuart32_setup_watermark(struct lpuart_port
*sport
)
1451 unsigned long val
, ctrl
;
1452 unsigned long ctrl_saved
;
1454 ctrl
= lpuart32_read(&sport
->port
, UARTCTRL
);
1456 ctrl
&= ~(UARTCTRL_TIE
| UARTCTRL_TCIE
| UARTCTRL_TE
|
1457 UARTCTRL_RIE
| UARTCTRL_RE
);
1458 lpuart32_write(&sport
->port
, ctrl
, UARTCTRL
);
1460 /* enable FIFO mode */
1461 val
= lpuart32_read(&sport
->port
, UARTFIFO
);
1462 val
|= UARTFIFO_TXFE
| UARTFIFO_RXFE
;
1463 val
|= UARTFIFO_TXFLUSH
| UARTFIFO_RXFLUSH
;
1464 lpuart32_write(&sport
->port
, val
, UARTFIFO
);
1466 /* set the watermark */
1467 val
= (0x1 << UARTWATER_RXWATER_OFF
) | (0x0 << UARTWATER_TXWATER_OFF
);
1468 lpuart32_write(&sport
->port
, val
, UARTWATER
);
1471 lpuart32_write(&sport
->port
, ctrl_saved
, UARTCTRL
);
1474 static void lpuart32_setup_watermark_enable(struct lpuart_port
*sport
)
1478 lpuart32_setup_watermark(sport
);
1480 temp
= lpuart32_read(&sport
->port
, UARTCTRL
);
1481 temp
|= UARTCTRL_RE
| UARTCTRL_TE
| UARTCTRL_ILIE
;
1482 lpuart32_write(&sport
->port
, temp
, UARTCTRL
);
1485 static void rx_dma_timer_init(struct lpuart_port
*sport
)
1487 timer_setup(&sport
->lpuart_timer
, lpuart_timer_func
, 0);
1488 sport
->lpuart_timer
.expires
= jiffies
+ sport
->dma_rx_timeout
;
1489 add_timer(&sport
->lpuart_timer
);
1492 static void lpuart_tx_dma_startup(struct lpuart_port
*sport
)
1496 if (sport
->dma_tx_chan
&& !lpuart_dma_tx_request(&sport
->port
)) {
1497 init_waitqueue_head(&sport
->dma_wait
);
1498 sport
->lpuart_dma_tx_use
= true;
1499 if (lpuart_is_32(sport
)) {
1500 uartbaud
= lpuart32_read(&sport
->port
, UARTBAUD
);
1501 lpuart32_write(&sport
->port
,
1502 uartbaud
| UARTBAUD_TDMAE
, UARTBAUD
);
1504 writeb(readb(sport
->port
.membase
+ UARTCR5
) |
1505 UARTCR5_TDMAS
, sport
->port
.membase
+ UARTCR5
);
1508 sport
->lpuart_dma_tx_use
= false;
1512 static void lpuart_rx_dma_startup(struct lpuart_port
*sport
)
1514 if (sport
->dma_rx_chan
&& !lpuart_start_rx_dma(sport
)) {
1515 /* set Rx DMA timeout */
1516 sport
->dma_rx_timeout
= msecs_to_jiffies(DMA_RX_TIMEOUT
);
1517 if (!sport
->dma_rx_timeout
)
1518 sport
->dma_rx_timeout
= 1;
1520 sport
->lpuart_dma_rx_use
= true;
1521 rx_dma_timer_init(sport
);
1523 sport
->lpuart_dma_rx_use
= false;
1527 static int lpuart_startup(struct uart_port
*port
)
1529 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
1530 unsigned long flags
;
1533 /* determine FIFO size and enable FIFO mode */
1534 temp
= readb(sport
->port
.membase
+ UARTPFIFO
);
1536 sport
->txfifo_size
= UARTFIFO_DEPTH((temp
>> UARTPFIFO_TXSIZE_OFF
) &
1537 UARTPFIFO_FIFOSIZE_MASK
);
1538 sport
->port
.fifosize
= sport
->txfifo_size
;
1540 sport
->rxfifo_size
= UARTFIFO_DEPTH((temp
>> UARTPFIFO_RXSIZE_OFF
) &
1541 UARTPFIFO_FIFOSIZE_MASK
);
1543 spin_lock_irqsave(&sport
->port
.lock
, flags
);
1545 lpuart_setup_watermark_enable(sport
);
1547 lpuart_rx_dma_startup(sport
);
1548 lpuart_tx_dma_startup(sport
);
1550 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
1555 static void lpuart32_configure(struct lpuart_port
*sport
)
1559 if (sport
->lpuart_dma_rx_use
) {
1560 /* RXWATER must be 0 */
1561 temp
= lpuart32_read(&sport
->port
, UARTWATER
);
1562 temp
&= ~(UARTWATER_WATER_MASK
<< UARTWATER_RXWATER_OFF
);
1563 lpuart32_write(&sport
->port
, temp
, UARTWATER
);
1565 temp
= lpuart32_read(&sport
->port
, UARTCTRL
);
1566 if (!sport
->lpuart_dma_rx_use
)
1567 temp
|= UARTCTRL_RIE
;
1568 if (!sport
->lpuart_dma_tx_use
)
1569 temp
|= UARTCTRL_TIE
;
1570 lpuart32_write(&sport
->port
, temp
, UARTCTRL
);
1573 static int lpuart32_startup(struct uart_port
*port
)
1575 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
1576 unsigned long flags
;
1579 /* determine FIFO size */
1580 temp
= lpuart32_read(&sport
->port
, UARTFIFO
);
1582 sport
->txfifo_size
= UARTFIFO_DEPTH((temp
>> UARTFIFO_TXSIZE_OFF
) &
1583 UARTFIFO_FIFOSIZE_MASK
);
1584 sport
->port
.fifosize
= sport
->txfifo_size
;
1586 sport
->rxfifo_size
= UARTFIFO_DEPTH((temp
>> UARTFIFO_RXSIZE_OFF
) &
1587 UARTFIFO_FIFOSIZE_MASK
);
1589 spin_lock_irqsave(&sport
->port
.lock
, flags
);
1591 lpuart32_setup_watermark_enable(sport
);
1594 lpuart_rx_dma_startup(sport
);
1595 lpuart_tx_dma_startup(sport
);
1597 lpuart32_configure(sport
);
1599 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
1603 static void lpuart_dma_shutdown(struct lpuart_port
*sport
)
1605 if (sport
->lpuart_dma_rx_use
) {
1606 del_timer_sync(&sport
->lpuart_timer
);
1607 lpuart_dma_rx_free(&sport
->port
);
1610 if (sport
->lpuart_dma_tx_use
) {
1611 if (wait_event_interruptible(sport
->dma_wait
,
1612 !sport
->dma_tx_in_progress
) != false) {
1613 sport
->dma_tx_in_progress
= false;
1614 dmaengine_terminate_all(sport
->dma_tx_chan
);
1619 static void lpuart_shutdown(struct uart_port
*port
)
1621 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
1623 unsigned long flags
;
1625 spin_lock_irqsave(&port
->lock
, flags
);
1627 /* disable Rx/Tx and interrupts */
1628 temp
= readb(port
->membase
+ UARTCR2
);
1629 temp
&= ~(UARTCR2_TE
| UARTCR2_RE
|
1630 UARTCR2_TIE
| UARTCR2_TCIE
| UARTCR2_RIE
);
1631 writeb(temp
, port
->membase
+ UARTCR2
);
1633 spin_unlock_irqrestore(&port
->lock
, flags
);
1635 lpuart_dma_shutdown(sport
);
1638 static void lpuart32_shutdown(struct uart_port
*port
)
1640 struct lpuart_port
*sport
=
1641 container_of(port
, struct lpuart_port
, port
);
1643 unsigned long flags
;
1645 spin_lock_irqsave(&port
->lock
, flags
);
1647 /* disable Rx/Tx and interrupts */
1648 temp
= lpuart32_read(port
, UARTCTRL
);
1649 temp
&= ~(UARTCTRL_TE
| UARTCTRL_RE
|
1650 UARTCTRL_TIE
| UARTCTRL_TCIE
| UARTCTRL_RIE
);
1651 lpuart32_write(port
, temp
, UARTCTRL
);
1653 spin_unlock_irqrestore(&port
->lock
, flags
);
1655 lpuart_dma_shutdown(sport
);
1659 lpuart_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
1660 struct ktermios
*old
)
1662 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
1663 unsigned long flags
;
1664 unsigned char cr1
, old_cr1
, old_cr2
, cr3
, cr4
, bdh
, modem
;
1666 unsigned int old_csize
= old
? old
->c_cflag
& CSIZE
: CS8
;
1667 unsigned int sbr
, brfa
;
1669 cr1
= old_cr1
= readb(sport
->port
.membase
+ UARTCR1
);
1670 old_cr2
= readb(sport
->port
.membase
+ UARTCR2
);
1671 cr3
= readb(sport
->port
.membase
+ UARTCR3
);
1672 cr4
= readb(sport
->port
.membase
+ UARTCR4
);
1673 bdh
= readb(sport
->port
.membase
+ UARTBDH
);
1674 modem
= readb(sport
->port
.membase
+ UARTMODEM
);
1676 * only support CS8 and CS7, and for CS7 must enable PE.
1683 while ((termios
->c_cflag
& CSIZE
) != CS8
&&
1684 (termios
->c_cflag
& CSIZE
) != CS7
) {
1685 termios
->c_cflag
&= ~CSIZE
;
1686 termios
->c_cflag
|= old_csize
;
1690 if ((termios
->c_cflag
& CSIZE
) == CS8
||
1691 (termios
->c_cflag
& CSIZE
) == CS7
)
1692 cr1
= old_cr1
& ~UARTCR1_M
;
1694 if (termios
->c_cflag
& CMSPAR
) {
1695 if ((termios
->c_cflag
& CSIZE
) != CS8
) {
1696 termios
->c_cflag
&= ~CSIZE
;
1697 termios
->c_cflag
|= CS8
;
1703 * When auto RS-485 RTS mode is enabled,
1704 * hardware flow control need to be disabled.
1706 if (sport
->port
.rs485
.flags
& SER_RS485_ENABLED
)
1707 termios
->c_cflag
&= ~CRTSCTS
;
1709 if (termios
->c_cflag
& CRTSCTS
)
1710 modem
|= UARTMODEM_RXRTSE
| UARTMODEM_TXCTSE
;
1712 modem
&= ~(UARTMODEM_RXRTSE
| UARTMODEM_TXCTSE
);
1714 termios
->c_cflag
&= ~CSTOPB
;
1716 /* parity must be enabled when CS7 to match 8-bits format */
1717 if ((termios
->c_cflag
& CSIZE
) == CS7
)
1718 termios
->c_cflag
|= PARENB
;
1720 if (termios
->c_cflag
& PARENB
) {
1721 if (termios
->c_cflag
& CMSPAR
) {
1723 if (termios
->c_cflag
& PARODD
)
1729 if ((termios
->c_cflag
& CSIZE
) == CS8
)
1731 if (termios
->c_cflag
& PARODD
)
1740 /* ask the core to calculate the divisor */
1741 baud
= uart_get_baud_rate(port
, termios
, old
, 50, port
->uartclk
/ 16);
1744 * Need to update the Ring buffer length according to the selected
1745 * baud rate and restart Rx DMA path.
1747 * Since timer function acqures sport->port.lock, need to stop before
1748 * acquring same lock because otherwise del_timer_sync() can deadlock.
1750 if (old
&& sport
->lpuart_dma_rx_use
) {
1751 del_timer_sync(&sport
->lpuart_timer
);
1752 lpuart_dma_rx_free(&sport
->port
);
1755 spin_lock_irqsave(&sport
->port
.lock
, flags
);
1757 sport
->port
.read_status_mask
= 0;
1758 if (termios
->c_iflag
& INPCK
)
1759 sport
->port
.read_status_mask
|= UARTSR1_FE
| UARTSR1_PE
;
1760 if (termios
->c_iflag
& (IGNBRK
| BRKINT
| PARMRK
))
1761 sport
->port
.read_status_mask
|= UARTSR1_FE
;
1763 /* characters to ignore */
1764 sport
->port
.ignore_status_mask
= 0;
1765 if (termios
->c_iflag
& IGNPAR
)
1766 sport
->port
.ignore_status_mask
|= UARTSR1_PE
;
1767 if (termios
->c_iflag
& IGNBRK
) {
1768 sport
->port
.ignore_status_mask
|= UARTSR1_FE
;
1770 * if we're ignoring parity and break indicators,
1771 * ignore overruns too (for real raw support).
1773 if (termios
->c_iflag
& IGNPAR
)
1774 sport
->port
.ignore_status_mask
|= UARTSR1_OR
;
1777 /* update the per-port timeout */
1778 uart_update_timeout(port
, termios
->c_cflag
, baud
);
1780 /* wait transmit engin complete */
1781 lpuart_wait_bit_set(&sport
->port
, UARTSR1
, UARTSR1_TC
);
1783 /* disable transmit and receive */
1784 writeb(old_cr2
& ~(UARTCR2_TE
| UARTCR2_RE
),
1785 sport
->port
.membase
+ UARTCR2
);
1787 sbr
= sport
->port
.uartclk
/ (16 * baud
);
1788 brfa
= ((sport
->port
.uartclk
- (16 * sbr
* baud
)) * 2) / baud
;
1789 bdh
&= ~UARTBDH_SBR_MASK
;
1790 bdh
|= (sbr
>> 8) & 0x1F;
1791 cr4
&= ~UARTCR4_BRFA_MASK
;
1792 brfa
&= UARTCR4_BRFA_MASK
;
1793 writeb(cr4
| brfa
, sport
->port
.membase
+ UARTCR4
);
1794 writeb(bdh
, sport
->port
.membase
+ UARTBDH
);
1795 writeb(sbr
& 0xFF, sport
->port
.membase
+ UARTBDL
);
1796 writeb(cr3
, sport
->port
.membase
+ UARTCR3
);
1797 writeb(cr1
, sport
->port
.membase
+ UARTCR1
);
1798 writeb(modem
, sport
->port
.membase
+ UARTMODEM
);
1800 /* restore control register */
1801 writeb(old_cr2
, sport
->port
.membase
+ UARTCR2
);
1803 if (old
&& sport
->lpuart_dma_rx_use
) {
1804 if (!lpuart_start_rx_dma(sport
))
1805 rx_dma_timer_init(sport
);
1807 sport
->lpuart_dma_rx_use
= false;
1810 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
1814 lpuart32_serial_setbrg(struct lpuart_port
*sport
, unsigned int baudrate
)
1816 u32 sbr
, osr
, baud_diff
, tmp_osr
, tmp_sbr
, tmp_diff
, tmp
;
1817 u32 clk
= sport
->port
.uartclk
;
1820 * The idea is to use the best OSR (over-sampling rate) possible.
1821 * Note, OSR is typically hard-set to 16 in other LPUART instantiations.
1822 * Loop to find the best OSR value possible, one that generates minimum
1823 * baud_diff iterate through the rest of the supported values of OSR.
1825 * Calculation Formula:
1826 * Baud Rate = baud clock / ((OSR+1) × SBR)
1828 baud_diff
= baudrate
;
1832 for (tmp_osr
= 4; tmp_osr
<= 32; tmp_osr
++) {
1833 /* calculate the temporary sbr value */
1834 tmp_sbr
= (clk
/ (baudrate
* tmp_osr
));
1839 * calculate the baud rate difference based on the temporary
1840 * osr and sbr values
1842 tmp_diff
= clk
/ (tmp_osr
* tmp_sbr
) - baudrate
;
1844 /* select best values between sbr and sbr+1 */
1845 tmp
= clk
/ (tmp_osr
* (tmp_sbr
+ 1));
1846 if (tmp_diff
> (baudrate
- tmp
)) {
1847 tmp_diff
= baudrate
- tmp
;
1851 if (tmp_diff
<= baud_diff
) {
1852 baud_diff
= tmp_diff
;
1861 /* handle buadrate outside acceptable rate */
1862 if (baud_diff
> ((baudrate
/ 100) * 3))
1863 dev_warn(sport
->port
.dev
,
1864 "unacceptable baud rate difference of more than 3%%\n");
1866 tmp
= lpuart32_read(&sport
->port
, UARTBAUD
);
1868 if ((osr
> 3) && (osr
< 8))
1869 tmp
|= UARTBAUD_BOTHEDGE
;
1871 tmp
&= ~(UARTBAUD_OSR_MASK
<< UARTBAUD_OSR_SHIFT
);
1872 tmp
|= ((osr
-1) & UARTBAUD_OSR_MASK
) << UARTBAUD_OSR_SHIFT
;
1874 tmp
&= ~UARTBAUD_SBR_MASK
;
1875 tmp
|= sbr
& UARTBAUD_SBR_MASK
;
1877 if (!sport
->lpuart_dma_rx_use
)
1878 tmp
&= ~UARTBAUD_RDMAE
;
1879 if (!sport
->lpuart_dma_tx_use
)
1880 tmp
&= ~UARTBAUD_TDMAE
;
1882 lpuart32_write(&sport
->port
, tmp
, UARTBAUD
);
1886 lpuart32_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
1887 struct ktermios
*old
)
1889 struct lpuart_port
*sport
= container_of(port
, struct lpuart_port
, port
);
1890 unsigned long flags
;
1891 unsigned long ctrl
, old_ctrl
, modem
;
1893 unsigned int old_csize
= old
? old
->c_cflag
& CSIZE
: CS8
;
1895 ctrl
= old_ctrl
= lpuart32_read(&sport
->port
, UARTCTRL
);
1896 modem
= lpuart32_read(&sport
->port
, UARTMODIR
);
1898 * only support CS8 and CS7, and for CS7 must enable PE.
1905 while ((termios
->c_cflag
& CSIZE
) != CS8
&&
1906 (termios
->c_cflag
& CSIZE
) != CS7
) {
1907 termios
->c_cflag
&= ~CSIZE
;
1908 termios
->c_cflag
|= old_csize
;
1912 if ((termios
->c_cflag
& CSIZE
) == CS8
||
1913 (termios
->c_cflag
& CSIZE
) == CS7
)
1914 ctrl
= old_ctrl
& ~UARTCTRL_M
;
1916 if (termios
->c_cflag
& CMSPAR
) {
1917 if ((termios
->c_cflag
& CSIZE
) != CS8
) {
1918 termios
->c_cflag
&= ~CSIZE
;
1919 termios
->c_cflag
|= CS8
;
1925 * When auto RS-485 RTS mode is enabled,
1926 * hardware flow control need to be disabled.
1928 if (sport
->port
.rs485
.flags
& SER_RS485_ENABLED
)
1929 termios
->c_cflag
&= ~CRTSCTS
;
1931 if (termios
->c_cflag
& CRTSCTS
) {
1932 modem
|= (UARTMODIR_RXRTSE
| UARTMODIR_TXCTSE
);
1934 termios
->c_cflag
&= ~CRTSCTS
;
1935 modem
&= ~(UARTMODIR_RXRTSE
| UARTMODIR_TXCTSE
);
1938 if (termios
->c_cflag
& CSTOPB
)
1939 termios
->c_cflag
&= ~CSTOPB
;
1941 /* parity must be enabled when CS7 to match 8-bits format */
1942 if ((termios
->c_cflag
& CSIZE
) == CS7
)
1943 termios
->c_cflag
|= PARENB
;
1945 if ((termios
->c_cflag
& PARENB
)) {
1946 if (termios
->c_cflag
& CMSPAR
) {
1947 ctrl
&= ~UARTCTRL_PE
;
1950 ctrl
|= UARTCTRL_PE
;
1951 if ((termios
->c_cflag
& CSIZE
) == CS8
)
1953 if (termios
->c_cflag
& PARODD
)
1954 ctrl
|= UARTCTRL_PT
;
1956 ctrl
&= ~UARTCTRL_PT
;
1959 ctrl
&= ~UARTCTRL_PE
;
1962 /* ask the core to calculate the divisor */
1963 baud
= uart_get_baud_rate(port
, termios
, old
, 50, port
->uartclk
/ 4);
1966 * Need to update the Ring buffer length according to the selected
1967 * baud rate and restart Rx DMA path.
1969 * Since timer function acqures sport->port.lock, need to stop before
1970 * acquring same lock because otherwise del_timer_sync() can deadlock.
1972 if (old
&& sport
->lpuart_dma_rx_use
) {
1973 del_timer_sync(&sport
->lpuart_timer
);
1974 lpuart_dma_rx_free(&sport
->port
);
1977 spin_lock_irqsave(&sport
->port
.lock
, flags
);
1979 sport
->port
.read_status_mask
= 0;
1980 if (termios
->c_iflag
& INPCK
)
1981 sport
->port
.read_status_mask
|= UARTSTAT_FE
| UARTSTAT_PE
;
1982 if (termios
->c_iflag
& (IGNBRK
| BRKINT
| PARMRK
))
1983 sport
->port
.read_status_mask
|= UARTSTAT_FE
;
1985 /* characters to ignore */
1986 sport
->port
.ignore_status_mask
= 0;
1987 if (termios
->c_iflag
& IGNPAR
)
1988 sport
->port
.ignore_status_mask
|= UARTSTAT_PE
;
1989 if (termios
->c_iflag
& IGNBRK
) {
1990 sport
->port
.ignore_status_mask
|= UARTSTAT_FE
;
1992 * if we're ignoring parity and break indicators,
1993 * ignore overruns too (for real raw support).
1995 if (termios
->c_iflag
& IGNPAR
)
1996 sport
->port
.ignore_status_mask
|= UARTSTAT_OR
;
1999 /* update the per-port timeout */
2000 uart_update_timeout(port
, termios
->c_cflag
, baud
);
2002 /* wait transmit engin complete */
2003 lpuart32_wait_bit_set(&sport
->port
, UARTSTAT
, UARTSTAT_TC
);
2005 /* disable transmit and receive */
2006 lpuart32_write(&sport
->port
, old_ctrl
& ~(UARTCTRL_TE
| UARTCTRL_RE
),
2009 lpuart32_serial_setbrg(sport
, baud
);
2010 lpuart32_write(&sport
->port
, modem
, UARTMODIR
);
2011 lpuart32_write(&sport
->port
, ctrl
, UARTCTRL
);
2012 /* restore control register */
2014 if (old
&& sport
->lpuart_dma_rx_use
) {
2015 if (!lpuart_start_rx_dma(sport
))
2016 rx_dma_timer_init(sport
);
2018 sport
->lpuart_dma_rx_use
= false;
2021 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
2024 static const char *lpuart_type(struct uart_port
*port
)
2026 return "FSL_LPUART";
2029 static void lpuart_release_port(struct uart_port
*port
)
2034 static int lpuart_request_port(struct uart_port
*port
)
2039 /* configure/autoconfigure the port */
2040 static void lpuart_config_port(struct uart_port
*port
, int flags
)
2042 if (flags
& UART_CONFIG_TYPE
)
2043 port
->type
= PORT_LPUART
;
2046 static int lpuart_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
2050 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_LPUART
)
2052 if (port
->irq
!= ser
->irq
)
2054 if (ser
->io_type
!= UPIO_MEM
)
2056 if (port
->uartclk
/ 16 != ser
->baud_base
)
2058 if (port
->iobase
!= ser
->port
)
2065 static const struct uart_ops lpuart_pops
= {
2066 .tx_empty
= lpuart_tx_empty
,
2067 .set_mctrl
= lpuart_set_mctrl
,
2068 .get_mctrl
= lpuart_get_mctrl
,
2069 .stop_tx
= lpuart_stop_tx
,
2070 .start_tx
= lpuart_start_tx
,
2071 .stop_rx
= lpuart_stop_rx
,
2072 .break_ctl
= lpuart_break_ctl
,
2073 .startup
= lpuart_startup
,
2074 .shutdown
= lpuart_shutdown
,
2075 .set_termios
= lpuart_set_termios
,
2076 .type
= lpuart_type
,
2077 .request_port
= lpuart_request_port
,
2078 .release_port
= lpuart_release_port
,
2079 .config_port
= lpuart_config_port
,
2080 .verify_port
= lpuart_verify_port
,
2081 .flush_buffer
= lpuart_flush_buffer
,
2082 #if defined(CONFIG_CONSOLE_POLL)
2083 .poll_init
= lpuart_poll_init
,
2084 .poll_get_char
= lpuart_poll_get_char
,
2085 .poll_put_char
= lpuart_poll_put_char
,
2089 static const struct uart_ops lpuart32_pops
= {
2090 .tx_empty
= lpuart32_tx_empty
,
2091 .set_mctrl
= lpuart32_set_mctrl
,
2092 .get_mctrl
= lpuart32_get_mctrl
,
2093 .stop_tx
= lpuart32_stop_tx
,
2094 .start_tx
= lpuart32_start_tx
,
2095 .stop_rx
= lpuart32_stop_rx
,
2096 .break_ctl
= lpuart32_break_ctl
,
2097 .startup
= lpuart32_startup
,
2098 .shutdown
= lpuart32_shutdown
,
2099 .set_termios
= lpuart32_set_termios
,
2100 .type
= lpuart_type
,
2101 .request_port
= lpuart_request_port
,
2102 .release_port
= lpuart_release_port
,
2103 .config_port
= lpuart_config_port
,
2104 .verify_port
= lpuart_verify_port
,
2105 .flush_buffer
= lpuart_flush_buffer
,
2106 #if defined(CONFIG_CONSOLE_POLL)
2107 .poll_init
= lpuart32_poll_init
,
2108 .poll_get_char
= lpuart32_poll_get_char
,
2109 .poll_put_char
= lpuart32_poll_put_char
,
2113 static struct lpuart_port
*lpuart_ports
[UART_NR
];
2115 #ifdef CONFIG_SERIAL_FSL_LPUART_CONSOLE
2116 static void lpuart_console_putchar(struct uart_port
*port
, int ch
)
2118 lpuart_wait_bit_set(port
, UARTSR1
, UARTSR1_TDRE
);
2119 writeb(ch
, port
->membase
+ UARTDR
);
2122 static void lpuart32_console_putchar(struct uart_port
*port
, int ch
)
2124 lpuart32_wait_bit_set(port
, UARTSTAT
, UARTSTAT_TDRE
);
2125 lpuart32_write(port
, ch
, UARTDATA
);
2129 lpuart_console_write(struct console
*co
, const char *s
, unsigned int count
)
2131 struct lpuart_port
*sport
= lpuart_ports
[co
->index
];
2132 unsigned char old_cr2
, cr2
;
2133 unsigned long flags
;
2136 if (sport
->port
.sysrq
|| oops_in_progress
)
2137 locked
= spin_trylock_irqsave(&sport
->port
.lock
, flags
);
2139 spin_lock_irqsave(&sport
->port
.lock
, flags
);
2141 /* first save CR2 and then disable interrupts */
2142 cr2
= old_cr2
= readb(sport
->port
.membase
+ UARTCR2
);
2143 cr2
|= UARTCR2_TE
| UARTCR2_RE
;
2144 cr2
&= ~(UARTCR2_TIE
| UARTCR2_TCIE
| UARTCR2_RIE
);
2145 writeb(cr2
, sport
->port
.membase
+ UARTCR2
);
2147 uart_console_write(&sport
->port
, s
, count
, lpuart_console_putchar
);
2149 /* wait for transmitter finish complete and restore CR2 */
2150 lpuart_wait_bit_set(&sport
->port
, UARTSR1
, UARTSR1_TC
);
2152 writeb(old_cr2
, sport
->port
.membase
+ UARTCR2
);
2155 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
2159 lpuart32_console_write(struct console
*co
, const char *s
, unsigned int count
)
2161 struct lpuart_port
*sport
= lpuart_ports
[co
->index
];
2162 unsigned long old_cr
, cr
;
2163 unsigned long flags
;
2166 if (sport
->port
.sysrq
|| oops_in_progress
)
2167 locked
= spin_trylock_irqsave(&sport
->port
.lock
, flags
);
2169 spin_lock_irqsave(&sport
->port
.lock
, flags
);
2171 /* first save CR2 and then disable interrupts */
2172 cr
= old_cr
= lpuart32_read(&sport
->port
, UARTCTRL
);
2173 cr
|= UARTCTRL_TE
| UARTCTRL_RE
;
2174 cr
&= ~(UARTCTRL_TIE
| UARTCTRL_TCIE
| UARTCTRL_RIE
);
2175 lpuart32_write(&sport
->port
, cr
, UARTCTRL
);
2177 uart_console_write(&sport
->port
, s
, count
, lpuart32_console_putchar
);
2179 /* wait for transmitter finish complete and restore CR2 */
2180 lpuart32_wait_bit_set(&sport
->port
, UARTSTAT
, UARTSTAT_TC
);
2182 lpuart32_write(&sport
->port
, old_cr
, UARTCTRL
);
2185 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
2189 * if the port was already initialised (eg, by a boot loader),
2190 * try to determine the current setup.
2193 lpuart_console_get_options(struct lpuart_port
*sport
, int *baud
,
2194 int *parity
, int *bits
)
2196 unsigned char cr
, bdh
, bdl
, brfa
;
2197 unsigned int sbr
, uartclk
, baud_raw
;
2199 cr
= readb(sport
->port
.membase
+ UARTCR2
);
2200 cr
&= UARTCR2_TE
| UARTCR2_RE
;
2204 /* ok, the port was enabled */
2206 cr
= readb(sport
->port
.membase
+ UARTCR1
);
2209 if (cr
& UARTCR1_PE
) {
2210 if (cr
& UARTCR1_PT
)
2221 bdh
= readb(sport
->port
.membase
+ UARTBDH
);
2222 bdh
&= UARTBDH_SBR_MASK
;
2223 bdl
= readb(sport
->port
.membase
+ UARTBDL
);
2227 brfa
= readb(sport
->port
.membase
+ UARTCR4
);
2228 brfa
&= UARTCR4_BRFA_MASK
;
2230 uartclk
= lpuart_get_baud_clk_rate(sport
);
2232 * baud = mod_clk/(16*(sbr[13]+(brfa)/32)
2234 baud_raw
= uartclk
/ (16 * (sbr
+ brfa
/ 32));
2236 if (*baud
!= baud_raw
)
2237 dev_info(sport
->port
.dev
, "Serial: Console lpuart rounded baud rate"
2238 "from %d to %d\n", baud_raw
, *baud
);
2242 lpuart32_console_get_options(struct lpuart_port
*sport
, int *baud
,
2243 int *parity
, int *bits
)
2245 unsigned long cr
, bd
;
2246 unsigned int sbr
, uartclk
, baud_raw
;
2248 cr
= lpuart32_read(&sport
->port
, UARTCTRL
);
2249 cr
&= UARTCTRL_TE
| UARTCTRL_RE
;
2253 /* ok, the port was enabled */
2255 cr
= lpuart32_read(&sport
->port
, UARTCTRL
);
2258 if (cr
& UARTCTRL_PE
) {
2259 if (cr
& UARTCTRL_PT
)
2265 if (cr
& UARTCTRL_M
)
2270 bd
= lpuart32_read(&sport
->port
, UARTBAUD
);
2271 bd
&= UARTBAUD_SBR_MASK
;
2273 uartclk
= lpuart_get_baud_clk_rate(sport
);
2275 * baud = mod_clk/(16*(sbr[13]+(brfa)/32)
2277 baud_raw
= uartclk
/ (16 * sbr
);
2279 if (*baud
!= baud_raw
)
2280 dev_info(sport
->port
.dev
, "Serial: Console lpuart rounded baud rate"
2281 "from %d to %d\n", baud_raw
, *baud
);
2284 static int __init
lpuart_console_setup(struct console
*co
, char *options
)
2286 struct lpuart_port
*sport
;
2293 * check whether an invalid uart number has been specified, and
2294 * if so, search for the first available port that does have
2297 if (co
->index
== -1 || co
->index
>= ARRAY_SIZE(lpuart_ports
))
2300 sport
= lpuart_ports
[co
->index
];
2305 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
2307 if (lpuart_is_32(sport
))
2308 lpuart32_console_get_options(sport
, &baud
, &parity
, &bits
);
2310 lpuart_console_get_options(sport
, &baud
, &parity
, &bits
);
2312 if (lpuart_is_32(sport
))
2313 lpuart32_setup_watermark(sport
);
2315 lpuart_setup_watermark(sport
);
2317 return uart_set_options(&sport
->port
, co
, baud
, parity
, bits
, flow
);
2320 static struct uart_driver lpuart_reg
;
2321 static struct console lpuart_console
= {
2323 .write
= lpuart_console_write
,
2324 .device
= uart_console_device
,
2325 .setup
= lpuart_console_setup
,
2326 .flags
= CON_PRINTBUFFER
,
2328 .data
= &lpuart_reg
,
2331 static struct console lpuart32_console
= {
2333 .write
= lpuart32_console_write
,
2334 .device
= uart_console_device
,
2335 .setup
= lpuart_console_setup
,
2336 .flags
= CON_PRINTBUFFER
,
2338 .data
= &lpuart_reg
,
2341 static void lpuart_early_write(struct console
*con
, const char *s
, unsigned n
)
2343 struct earlycon_device
*dev
= con
->data
;
2345 uart_console_write(&dev
->port
, s
, n
, lpuart_console_putchar
);
2348 static void lpuart32_early_write(struct console
*con
, const char *s
, unsigned n
)
2350 struct earlycon_device
*dev
= con
->data
;
2352 uart_console_write(&dev
->port
, s
, n
, lpuart32_console_putchar
);
2355 static int __init
lpuart_early_console_setup(struct earlycon_device
*device
,
2358 if (!device
->port
.membase
)
2361 device
->con
->write
= lpuart_early_write
;
2365 static int __init
lpuart32_early_console_setup(struct earlycon_device
*device
,
2368 if (!device
->port
.membase
)
2371 if (device
->port
.iotype
!= UPIO_MEM32
)
2372 device
->port
.iotype
= UPIO_MEM32BE
;
2374 device
->con
->write
= lpuart32_early_write
;
2378 static int __init
lpuart32_imx_early_console_setup(struct earlycon_device
*device
,
2381 if (!device
->port
.membase
)
2384 device
->port
.iotype
= UPIO_MEM32
;
2385 device
->port
.membase
+= IMX_REG_OFF
;
2386 device
->con
->write
= lpuart32_early_write
;
2390 OF_EARLYCON_DECLARE(lpuart
, "fsl,vf610-lpuart", lpuart_early_console_setup
);
2391 OF_EARLYCON_DECLARE(lpuart32
, "fsl,ls1021a-lpuart", lpuart32_early_console_setup
);
2392 OF_EARLYCON_DECLARE(lpuart32
, "fsl,imx7ulp-lpuart", lpuart32_imx_early_console_setup
);
2394 #define LPUART_CONSOLE (&lpuart_console)
2395 #define LPUART32_CONSOLE (&lpuart32_console)
2397 #define LPUART_CONSOLE NULL
2398 #define LPUART32_CONSOLE NULL
2401 static struct uart_driver lpuart_reg
= {
2402 .owner
= THIS_MODULE
,
2403 .driver_name
= DRIVER_NAME
,
2404 .dev_name
= DEV_NAME
,
2405 .nr
= ARRAY_SIZE(lpuart_ports
),
2406 .cons
= LPUART_CONSOLE
,
2409 static int lpuart_probe(struct platform_device
*pdev
)
2411 const struct of_device_id
*of_id
= of_match_device(lpuart_dt_ids
,
2413 const struct lpuart_soc_data
*sdata
= of_id
->data
;
2414 struct device_node
*np
= pdev
->dev
.of_node
;
2415 struct lpuart_port
*sport
;
2416 struct resource
*res
;
2419 sport
= devm_kzalloc(&pdev
->dev
, sizeof(*sport
), GFP_KERNEL
);
2423 ret
= of_alias_get_id(np
, "serial");
2425 ret
= ida_simple_get(&fsl_lpuart_ida
, 0, UART_NR
, GFP_KERNEL
);
2427 dev_err(&pdev
->dev
, "port line is full, add device failed\n");
2431 if (ret
>= ARRAY_SIZE(lpuart_ports
)) {
2432 dev_err(&pdev
->dev
, "serial%d out of range\n", ret
);
2435 sport
->port
.line
= ret
;
2436 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2437 sport
->port
.membase
= devm_ioremap_resource(&pdev
->dev
, res
);
2438 if (IS_ERR(sport
->port
.membase
))
2439 return PTR_ERR(sport
->port
.membase
);
2441 sport
->port
.membase
+= sdata
->reg_off
;
2442 sport
->port
.mapbase
= res
->start
;
2443 sport
->port
.dev
= &pdev
->dev
;
2444 sport
->port
.type
= PORT_LPUART
;
2445 sport
->devtype
= sdata
->devtype
;
2446 ret
= platform_get_irq(pdev
, 0);
2449 sport
->port
.irq
= ret
;
2450 sport
->port
.iotype
= sdata
->iotype
;
2451 if (lpuart_is_32(sport
))
2452 sport
->port
.ops
= &lpuart32_pops
;
2454 sport
->port
.ops
= &lpuart_pops
;
2455 sport
->port
.has_sysrq
= IS_ENABLED(CONFIG_SERIAL_FSL_LPUART_CONSOLE
);
2456 sport
->port
.flags
= UPF_BOOT_AUTOCONF
;
2458 if (lpuart_is_32(sport
))
2459 sport
->port
.rs485_config
= lpuart32_config_rs485
;
2461 sport
->port
.rs485_config
= lpuart_config_rs485
;
2463 sport
->ipg_clk
= devm_clk_get(&pdev
->dev
, "ipg");
2464 if (IS_ERR(sport
->ipg_clk
)) {
2465 ret
= PTR_ERR(sport
->ipg_clk
);
2466 dev_err(&pdev
->dev
, "failed to get uart ipg clk: %d\n", ret
);
2470 sport
->baud_clk
= NULL
;
2471 if (is_imx8qxp_lpuart(sport
)) {
2472 sport
->baud_clk
= devm_clk_get(&pdev
->dev
, "baud");
2473 if (IS_ERR(sport
->baud_clk
)) {
2474 ret
= PTR_ERR(sport
->baud_clk
);
2475 dev_err(&pdev
->dev
, "failed to get uart baud clk: %d\n", ret
);
2480 ret
= lpuart_enable_clks(sport
);
2483 sport
->port
.uartclk
= lpuart_get_baud_clk_rate(sport
);
2485 lpuart_ports
[sport
->port
.line
] = sport
;
2487 platform_set_drvdata(pdev
, &sport
->port
);
2489 if (lpuart_is_32(sport
)) {
2490 lpuart_reg
.cons
= LPUART32_CONSOLE
;
2491 ret
= devm_request_irq(&pdev
->dev
, sport
->port
.irq
, lpuart32_int
, 0,
2492 DRIVER_NAME
, sport
);
2494 lpuart_reg
.cons
= LPUART_CONSOLE
;
2495 ret
= devm_request_irq(&pdev
->dev
, sport
->port
.irq
, lpuart_int
, 0,
2496 DRIVER_NAME
, sport
);
2500 goto failed_irq_request
;
2502 ret
= uart_add_one_port(&lpuart_reg
, &sport
->port
);
2504 goto failed_attach_port
;
2506 uart_get_rs485_mode(&pdev
->dev
, &sport
->port
.rs485
);
2508 if (sport
->port
.rs485
.flags
& SER_RS485_RX_DURING_TX
)
2509 dev_err(&pdev
->dev
, "driver doesn't support RX during TX\n");
2511 if (sport
->port
.rs485
.delay_rts_before_send
||
2512 sport
->port
.rs485
.delay_rts_after_send
)
2513 dev_err(&pdev
->dev
, "driver doesn't support RTS delays\n");
2515 sport
->port
.rs485_config(&sport
->port
, &sport
->port
.rs485
);
2517 sport
->dma_tx_chan
= dma_request_slave_channel(sport
->port
.dev
, "tx");
2518 if (!sport
->dma_tx_chan
)
2519 dev_info(sport
->port
.dev
, "DMA tx channel request failed, "
2520 "operating without tx DMA\n");
2522 sport
->dma_rx_chan
= dma_request_slave_channel(sport
->port
.dev
, "rx");
2523 if (!sport
->dma_rx_chan
)
2524 dev_info(sport
->port
.dev
, "DMA rx channel request failed, "
2525 "operating without rx DMA\n");
2531 lpuart_disable_clks(sport
);
2535 static int lpuart_remove(struct platform_device
*pdev
)
2537 struct lpuart_port
*sport
= platform_get_drvdata(pdev
);
2539 uart_remove_one_port(&lpuart_reg
, &sport
->port
);
2541 ida_simple_remove(&fsl_lpuart_ida
, sport
->port
.line
);
2543 lpuart_disable_clks(sport
);
2545 if (sport
->dma_tx_chan
)
2546 dma_release_channel(sport
->dma_tx_chan
);
2548 if (sport
->dma_rx_chan
)
2549 dma_release_channel(sport
->dma_rx_chan
);
2554 #ifdef CONFIG_PM_SLEEP
2555 static int lpuart_suspend(struct device
*dev
)
2557 struct lpuart_port
*sport
= dev_get_drvdata(dev
);
2561 if (lpuart_is_32(sport
)) {
2562 /* disable Rx/Tx and interrupts */
2563 temp
= lpuart32_read(&sport
->port
, UARTCTRL
);
2564 temp
&= ~(UARTCTRL_TE
| UARTCTRL_TIE
| UARTCTRL_TCIE
);
2565 lpuart32_write(&sport
->port
, temp
, UARTCTRL
);
2567 /* disable Rx/Tx and interrupts */
2568 temp
= readb(sport
->port
.membase
+ UARTCR2
);
2569 temp
&= ~(UARTCR2_TE
| UARTCR2_TIE
| UARTCR2_TCIE
);
2570 writeb(temp
, sport
->port
.membase
+ UARTCR2
);
2573 uart_suspend_port(&lpuart_reg
, &sport
->port
);
2575 /* uart_suspend_port() might set wakeup flag */
2576 irq_wake
= irqd_is_wakeup_set(irq_get_irq_data(sport
->port
.irq
));
2578 if (sport
->lpuart_dma_rx_use
) {
2580 * EDMA driver during suspend will forcefully release any
2581 * non-idle DMA channels. If port wakeup is enabled or if port
2582 * is console port or 'no_console_suspend' is set the Rx DMA
2583 * cannot resume as as expected, hence gracefully release the
2584 * Rx DMA path before suspend and start Rx DMA path on resume.
2587 del_timer_sync(&sport
->lpuart_timer
);
2588 lpuart_dma_rx_free(&sport
->port
);
2591 /* Disable Rx DMA to use UART port as wakeup source */
2592 if (lpuart_is_32(sport
)) {
2593 temp
= lpuart32_read(&sport
->port
, UARTBAUD
);
2594 lpuart32_write(&sport
->port
, temp
& ~UARTBAUD_RDMAE
,
2597 writeb(readb(sport
->port
.membase
+ UARTCR5
) &
2598 ~UARTCR5_RDMAS
, sport
->port
.membase
+ UARTCR5
);
2602 if (sport
->lpuart_dma_tx_use
) {
2603 sport
->dma_tx_in_progress
= false;
2604 dmaengine_terminate_all(sport
->dma_tx_chan
);
2607 if (sport
->port
.suspended
&& !irq_wake
)
2608 lpuart_disable_clks(sport
);
2613 static int lpuart_resume(struct device
*dev
)
2615 struct lpuart_port
*sport
= dev_get_drvdata(dev
);
2616 bool irq_wake
= irqd_is_wakeup_set(irq_get_irq_data(sport
->port
.irq
));
2618 if (sport
->port
.suspended
&& !irq_wake
)
2619 lpuart_enable_clks(sport
);
2621 if (lpuart_is_32(sport
))
2622 lpuart32_setup_watermark_enable(sport
);
2624 lpuart_setup_watermark_enable(sport
);
2626 if (sport
->lpuart_dma_rx_use
) {
2628 if (!lpuart_start_rx_dma(sport
))
2629 rx_dma_timer_init(sport
);
2631 sport
->lpuart_dma_rx_use
= false;
2635 lpuart_tx_dma_startup(sport
);
2637 if (lpuart_is_32(sport
))
2638 lpuart32_configure(sport
);
2640 uart_resume_port(&lpuart_reg
, &sport
->port
);
2646 static SIMPLE_DEV_PM_OPS(lpuart_pm_ops
, lpuart_suspend
, lpuart_resume
);
2648 static struct platform_driver lpuart_driver
= {
2649 .probe
= lpuart_probe
,
2650 .remove
= lpuart_remove
,
2652 .name
= "fsl-lpuart",
2653 .of_match_table
= lpuart_dt_ids
,
2654 .pm
= &lpuart_pm_ops
,
2658 static int __init
lpuart_serial_init(void)
2660 int ret
= uart_register_driver(&lpuart_reg
);
2665 ret
= platform_driver_register(&lpuart_driver
);
2667 uart_unregister_driver(&lpuart_reg
);
2672 static void __exit
lpuart_serial_exit(void)
2674 ida_destroy(&fsl_lpuart_ida
);
2675 platform_driver_unregister(&lpuart_driver
);
2676 uart_unregister_driver(&lpuart_reg
);
2679 module_init(lpuart_serial_init
);
2680 module_exit(lpuart_serial_exit
);
2682 MODULE_DESCRIPTION("Freescale lpuart serial port driver");
2683 MODULE_LICENSE("GPL v2");