xref: /linux/include/linux/amba/serial.h (revision 1f78c56007ba61b7b8c3f7dbb6787b6af116d3f0)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2a62c80e5SRussell King /*
3a62c80e5SRussell King  *  linux/include/asm-arm/hardware/serial_amba.h
4a62c80e5SRussell King  *
5a62c80e5SRussell King  *  Internal header file for AMBA serial ports
6a62c80e5SRussell King  *
7a62c80e5SRussell King  *  Copyright (C) ARM Limited
8a62c80e5SRussell King  *  Copyright (C) 2000 Deep Blue Solutions Ltd.
9a62c80e5SRussell King  */
10a62c80e5SRussell King #ifndef ASM_ARM_HARDWARE_SERIAL_AMBA_H
11a62c80e5SRussell King #define ASM_ARM_HARDWARE_SERIAL_AMBA_H
12a62c80e5SRussell King 
13*1f78c560SThéo Lebrun #ifndef __ASSEMBLY__
14*1f78c560SThéo Lebrun #include <linux/bitfield.h>
15*1f78c560SThéo Lebrun #include <linux/bits.h>
16*1f78c560SThéo Lebrun #endif
17*1f78c560SThéo Lebrun 
187e55d052Sviresh kumar #include <linux/types.h>
197e55d052Sviresh kumar 
20a62c80e5SRussell King /* -------------------------------------------------------------------------------
21a62c80e5SRussell King  *  From AMBA UART (PL010) Block Specification
22a62c80e5SRussell King  * -------------------------------------------------------------------------------
23a62c80e5SRussell King  *  UART Register Offsets.
24a62c80e5SRussell King  */
25a62c80e5SRussell King #define UART01x_DR		0x00	/* Data read or written from the interface. */
26a62c80e5SRussell King #define UART01x_RSR		0x04	/* Receive status register (Read). */
27a62c80e5SRussell King #define UART01x_ECR		0x04	/* Error clear register (Write). */
28a62c80e5SRussell King #define UART010_LCRH		0x08	/* Line control register, high byte. */
2929e29f27SLinus Walleij #define ST_UART011_DMAWM	0x08    /* DMA watermark configure register. */
30a62c80e5SRussell King #define UART010_LCRM		0x0C	/* Line control register, middle byte. */
3129e29f27SLinus Walleij #define ST_UART011_TIMEOUT	0x0C    /* Timeout period register. */
32a62c80e5SRussell King #define UART010_LCRL		0x10	/* Line control register, low byte. */
33a62c80e5SRussell King #define UART010_CR		0x14	/* Control register. */
34a62c80e5SRussell King #define UART01x_FR		0x18	/* Flag register (Read only). */
353f79410cSMaxime Jayat #define UART010_IIR		0x1C	/* Interrupt identification register (Read). */
36a62c80e5SRussell King #define UART010_ICR		0x1C	/* Interrupt clear register (Write). */
37ec489aa8SLinus Walleij #define ST_UART011_LCRH_RX	0x1C    /* Rx line control register. */
38a62c80e5SRussell King #define UART01x_ILPR		0x20	/* IrDA low power counter register. */
39a62c80e5SRussell King #define UART011_IBRD		0x24	/* Integer baud rate divisor register. */
40a62c80e5SRussell King #define UART011_FBRD		0x28	/* Fractional baud rate divisor register. */
41a62c80e5SRussell King #define UART011_LCRH		0x2c	/* Line control register. */
42ec489aa8SLinus Walleij #define ST_UART011_LCRH_TX	0x2c    /* Tx Line control register. */
43a62c80e5SRussell King #define UART011_CR		0x30	/* Control register. */
44a62c80e5SRussell King #define UART011_IFLS		0x34	/* Interrupt fifo level select. */
45a62c80e5SRussell King #define UART011_IMSC		0x38	/* Interrupt mask. */
46a62c80e5SRussell King #define UART011_RIS		0x3c	/* Raw interrupt status. */
47a62c80e5SRussell King #define UART011_MIS		0x40	/* Masked interrupt status. */
48a62c80e5SRussell King #define UART011_ICR		0x44	/* Interrupt clear register. */
49a62c80e5SRussell King #define UART011_DMACR		0x48	/* DMA control register. */
5029e29f27SLinus Walleij #define ST_UART011_XFCR		0x50	/* XON/XOFF control register. */
5129e29f27SLinus Walleij #define ST_UART011_XON1		0x54	/* XON1 register. */
5229e29f27SLinus Walleij #define ST_UART011_XON2		0x58	/* XON2 register. */
5329e29f27SLinus Walleij #define ST_UART011_XOFF1	0x5C	/* XON1 register. */
5429e29f27SLinus Walleij #define ST_UART011_XOFF2	0x60	/* XON2 register. */
5529e29f27SLinus Walleij #define ST_UART011_ITCR		0x80	/* Integration test control register. */
5629e29f27SLinus Walleij #define ST_UART011_ITIP		0x84	/* Integration test input register. */
5729e29f27SLinus Walleij #define ST_UART011_ABCR		0x100	/* Autobaud control register. */
5829e29f27SLinus Walleij #define ST_UART011_ABIMSC	0x15C	/* Autobaud interrupt mask/clear register. */
59a62c80e5SRussell King 
607ec75871SRussell King /*
617ec75871SRussell King  * ZTE UART register offsets.  This UART has a radically different address
627ec75871SRussell King  * allocation from the ARM and ST variants, so we list all registers here.
637ec75871SRussell King  * We assume unlisted registers do not exist.
647ec75871SRussell King  */
657ec75871SRussell King #define ZX_UART011_DR		0x04
667ec75871SRussell King #define ZX_UART011_FR		0x14
677ec75871SRussell King #define ZX_UART011_IBRD		0x24
687ec75871SRussell King #define ZX_UART011_FBRD		0x28
697ec75871SRussell King #define ZX_UART011_LCRH		0x30
707ec75871SRussell King #define ZX_UART011_CR		0x34
717ec75871SRussell King #define ZX_UART011_IFLS		0x38
727ec75871SRussell King #define ZX_UART011_IMSC		0x40
737ec75871SRussell King #define ZX_UART011_RIS		0x44
747ec75871SRussell King #define ZX_UART011_MIS		0x48
757ec75871SRussell King #define ZX_UART011_ICR		0x4c
767ec75871SRussell King #define ZX_UART011_DMACR	0x50
777ec75871SRussell King 
78*1f78c560SThéo Lebrun #define UART011_DR_OE		BIT(11)
79*1f78c560SThéo Lebrun #define UART011_DR_BE		BIT(10)
80*1f78c560SThéo Lebrun #define UART011_DR_PE		BIT(9)
81*1f78c560SThéo Lebrun #define UART011_DR_FE		BIT(8)
82a62c80e5SRussell King 
83*1f78c560SThéo Lebrun #define UART01x_RSR_OE		BIT(3)
84*1f78c560SThéo Lebrun #define UART01x_RSR_BE		BIT(2)
85*1f78c560SThéo Lebrun #define UART01x_RSR_PE		BIT(1)
86*1f78c560SThéo Lebrun #define UART01x_RSR_FE		BIT(0)
87a62c80e5SRussell King 
88*1f78c560SThéo Lebrun #define UART011_FR_RI		BIT(8)
89*1f78c560SThéo Lebrun #define UART011_FR_TXFE		BIT(7)
90*1f78c560SThéo Lebrun #define UART011_FR_RXFF		BIT(6)
91*1f78c560SThéo Lebrun #define UART01x_FR_TXFF		(1 << 5)	/* used in ASM */
92*1f78c560SThéo Lebrun #define UART01x_FR_RXFE		BIT(4)
93*1f78c560SThéo Lebrun #define UART01x_FR_BUSY		(1 << 3)	/* used in ASM */
94*1f78c560SThéo Lebrun #define UART01x_FR_DCD		BIT(2)
95*1f78c560SThéo Lebrun #define UART01x_FR_DSR		BIT(1)
96*1f78c560SThéo Lebrun #define UART01x_FR_CTS		BIT(0)
97a62c80e5SRussell King #define UART01x_FR_TMSK		(UART01x_FR_TXFF + UART01x_FR_BUSY)
98a62c80e5SRussell King 
990e125a5fSShawn Guo /*
1000e125a5fSShawn Guo  * Some bits of Flag Register on ZTE device have different position from
1010e125a5fSShawn Guo  * standard ones.
1020e125a5fSShawn Guo  */
103*1f78c560SThéo Lebrun #define ZX_UART01x_FR_BUSY	BIT(8)
104*1f78c560SThéo Lebrun #define ZX_UART01x_FR_DSR	BIT(3)
105*1f78c560SThéo Lebrun #define ZX_UART01x_FR_CTS	BIT(1)
106*1f78c560SThéo Lebrun #define ZX_UART011_FR_RI	BIT(0)
1070e125a5fSShawn Guo 
108*1f78c560SThéo Lebrun #define UART011_CR_CTSEN	BIT(15)	/* CTS hardware flow control */
109*1f78c560SThéo Lebrun #define UART011_CR_RTSEN	BIT(14)	/* RTS hardware flow control */
110*1f78c560SThéo Lebrun #define UART011_CR_OUT2		BIT(13)	/* OUT2 */
111*1f78c560SThéo Lebrun #define UART011_CR_OUT1		BIT(12)	/* OUT1 */
112*1f78c560SThéo Lebrun #define UART011_CR_RTS		BIT(11)	/* RTS */
113*1f78c560SThéo Lebrun #define UART011_CR_DTR		BIT(10)	/* DTR */
114*1f78c560SThéo Lebrun #define UART011_CR_RXE		BIT(9)	/* receive enable */
115*1f78c560SThéo Lebrun #define UART011_CR_TXE		BIT(8)	/* transmit enable */
116*1f78c560SThéo Lebrun #define UART011_CR_LBE		BIT(7)	/* loopback enable */
117*1f78c560SThéo Lebrun #define UART010_CR_RTIE		BIT(6)
118*1f78c560SThéo Lebrun #define UART010_CR_TIE		BIT(5)
119*1f78c560SThéo Lebrun #define UART010_CR_RIE		BIT(4)
120*1f78c560SThéo Lebrun #define UART010_CR_MSIE		BIT(3)
121*1f78c560SThéo Lebrun #define ST_UART011_CR_OVSFACT	BIT(3)	/* Oversampling factor */
122*1f78c560SThéo Lebrun #define UART01x_CR_IIRLP	BIT(2)	/* SIR low power mode */
123*1f78c560SThéo Lebrun #define UART01x_CR_SIREN	BIT(1)	/* SIR enable */
124*1f78c560SThéo Lebrun #define UART01x_CR_UARTEN	BIT(0)	/* UART enable */
125a62c80e5SRussell King 
126*1f78c560SThéo Lebrun #define UART011_LCRH_SPS	BIT(7)
127a62c80e5SRussell King #define UART01x_LCRH_WLEN_8	0x60
128a62c80e5SRussell King #define UART01x_LCRH_WLEN_7	0x40
129a62c80e5SRussell King #define UART01x_LCRH_WLEN_6	0x20
130a62c80e5SRussell King #define UART01x_LCRH_WLEN_5	0x00
131*1f78c560SThéo Lebrun #define UART01x_LCRH_FEN	BIT(4)
132*1f78c560SThéo Lebrun #define UART01x_LCRH_STP2	BIT(3)
133*1f78c560SThéo Lebrun #define UART01x_LCRH_EPS	BIT(2)
134*1f78c560SThéo Lebrun #define UART01x_LCRH_PEN	BIT(1)
135*1f78c560SThéo Lebrun #define UART01x_LCRH_BRK	BIT(0)
136a62c80e5SRussell King 
137*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX	GENMASK(5, 3)
138*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_1	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 0)
139*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_2	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 1)
140*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_4	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 2)
141*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_8	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 3)
142*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_16	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 4)
143*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_32	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 5)
144*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_RX_48	FIELD_PREP_CONST(ST_UART011_DMAWM_RX, 6)
145*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX	GENMASK(2, 0)
146*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_1	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 0)
147*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_2	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 1)
148*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_4	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 2)
149*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_8	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 3)
150*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_16	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 4)
151*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_32	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 5)
152*1f78c560SThéo Lebrun #define ST_UART011_DMAWM_TX_48	FIELD_PREP_CONST(ST_UART011_DMAWM_TX, 6)
15338d62436SRussell King 
154*1f78c560SThéo Lebrun #define UART010_IIR_RTIS	BIT(3)
155*1f78c560SThéo Lebrun #define UART010_IIR_TIS		BIT(2)
156*1f78c560SThéo Lebrun #define UART010_IIR_RIS		BIT(1)
157*1f78c560SThéo Lebrun #define UART010_IIR_MIS		BIT(0)
158a62c80e5SRussell King 
159*1f78c560SThéo Lebrun #define UART011_IFLS_RXIFLSEL	GENMASK(5, 3)
160*1f78c560SThéo Lebrun #define UART011_IFLS_RX1_8	FIELD_PREP_CONST(UART011_IFLS_RXIFLSEL, 0)
161*1f78c560SThéo Lebrun #define UART011_IFLS_RX2_8	FIELD_PREP_CONST(UART011_IFLS_RXIFLSEL, 1)
162*1f78c560SThéo Lebrun #define UART011_IFLS_RX4_8	FIELD_PREP_CONST(UART011_IFLS_RXIFLSEL, 2)
163*1f78c560SThéo Lebrun #define UART011_IFLS_RX6_8	FIELD_PREP_CONST(UART011_IFLS_RXIFLSEL, 3)
164*1f78c560SThéo Lebrun #define UART011_IFLS_RX7_8	FIELD_PREP_CONST(UART011_IFLS_RXIFLSEL, 4)
165*1f78c560SThéo Lebrun #define UART011_IFLS_TXIFLSEL	GENMASK(2, 0)
166*1f78c560SThéo Lebrun #define UART011_IFLS_TX1_8	FIELD_PREP_CONST(UART011_IFLS_TXIFLSEL, 0)
167*1f78c560SThéo Lebrun #define UART011_IFLS_TX2_8	FIELD_PREP_CONST(UART011_IFLS_TXIFLSEL, 1)
168*1f78c560SThéo Lebrun #define UART011_IFLS_TX4_8	FIELD_PREP_CONST(UART011_IFLS_TXIFLSEL, 2)
169*1f78c560SThéo Lebrun #define UART011_IFLS_TX6_8	FIELD_PREP_CONST(UART011_IFLS_TXIFLSEL, 3)
170*1f78c560SThéo Lebrun #define UART011_IFLS_TX7_8	FIELD_PREP_CONST(UART011_IFLS_TXIFLSEL, 4)
1715926a295SAlessandro Rubini /* special values for ST vendor with deeper fifo */
172*1f78c560SThéo Lebrun #define UART011_IFLS_RX_HALF	FIELD_PREP_CONST(UART011_IFLS_RXIFLSEL, 5)
173*1f78c560SThéo Lebrun #define UART011_IFLS_TX_HALF	FIELD_PREP_CONST(UART011_IFLS_TXIFLSEL, 5)
174a62c80e5SRussell King 
175*1f78c560SThéo Lebrun #define UART011_OEIM		BIT(10)	/* overrun error interrupt mask */
176*1f78c560SThéo Lebrun #define UART011_BEIM		BIT(9)	/* break error interrupt mask */
177*1f78c560SThéo Lebrun #define UART011_PEIM		BIT(8)	/* parity error interrupt mask */
178*1f78c560SThéo Lebrun #define UART011_FEIM		BIT(7)	/* framing error interrupt mask */
179*1f78c560SThéo Lebrun #define UART011_RTIM		BIT(6)	/* receive timeout interrupt mask */
180*1f78c560SThéo Lebrun #define UART011_TXIM		BIT(5)	/* transmit interrupt mask */
181*1f78c560SThéo Lebrun #define UART011_RXIM		BIT(4)	/* receive interrupt mask */
182*1f78c560SThéo Lebrun #define UART011_DSRMIM		BIT(3)	/* DSR interrupt mask */
183*1f78c560SThéo Lebrun #define UART011_DCDMIM		BIT(2)	/* DCD interrupt mask */
184*1f78c560SThéo Lebrun #define UART011_CTSMIM		BIT(1)	/* CTS interrupt mask */
185*1f78c560SThéo Lebrun #define UART011_RIMIM		BIT(0)	/* RI interrupt mask */
186a62c80e5SRussell King 
187*1f78c560SThéo Lebrun #define UART011_OEIS		BIT(10)	/* overrun error interrupt status */
188*1f78c560SThéo Lebrun #define UART011_BEIS		BIT(9)	/* break error interrupt status */
189*1f78c560SThéo Lebrun #define UART011_PEIS		BIT(8)	/* parity error interrupt status */
190*1f78c560SThéo Lebrun #define UART011_FEIS		BIT(7)	/* framing error interrupt status */
191*1f78c560SThéo Lebrun #define UART011_RTIS		BIT(6)	/* receive timeout interrupt status */
192*1f78c560SThéo Lebrun #define UART011_TXIS		BIT(5)	/* transmit interrupt status */
193*1f78c560SThéo Lebrun #define UART011_RXIS		BIT(4)	/* receive interrupt status */
194*1f78c560SThéo Lebrun #define UART011_DSRMIS		BIT(3)	/* DSR interrupt status */
195*1f78c560SThéo Lebrun #define UART011_DCDMIS		BIT(2)	/* DCD interrupt status */
196*1f78c560SThéo Lebrun #define UART011_CTSMIS		BIT(1)	/* CTS interrupt status */
197*1f78c560SThéo Lebrun #define UART011_RIMIS		BIT(0)	/* RI interrupt status */
198a62c80e5SRussell King 
199*1f78c560SThéo Lebrun #define UART011_OEIC		BIT(10)	/* overrun error interrupt clear */
200*1f78c560SThéo Lebrun #define UART011_BEIC		BIT(9)	/* break error interrupt clear */
201*1f78c560SThéo Lebrun #define UART011_PEIC		BIT(8)	/* parity error interrupt clear */
202*1f78c560SThéo Lebrun #define UART011_FEIC		BIT(7)	/* framing error interrupt clear */
203*1f78c560SThéo Lebrun #define UART011_RTIC		BIT(6)	/* receive timeout interrupt clear */
204*1f78c560SThéo Lebrun #define UART011_TXIC		BIT(5)	/* transmit interrupt clear */
205*1f78c560SThéo Lebrun #define UART011_RXIC		BIT(4)	/* receive interrupt clear */
206*1f78c560SThéo Lebrun #define UART011_DSRMIC		BIT(3)	/* DSR interrupt clear */
207*1f78c560SThéo Lebrun #define UART011_DCDMIC		BIT(2)	/* DCD interrupt clear */
208*1f78c560SThéo Lebrun #define UART011_CTSMIC		BIT(1)	/* CTS interrupt clear */
209*1f78c560SThéo Lebrun #define UART011_RIMIC		BIT(0)	/* RI interrupt clear */
210a62c80e5SRussell King 
211*1f78c560SThéo Lebrun #define UART011_DMAONERR	BIT(2)	/* disable dma on error */
212*1f78c560SThéo Lebrun #define UART011_TXDMAE		BIT(1)	/* enable transmit dma */
213*1f78c560SThéo Lebrun #define UART011_RXDMAE		BIT(0)	/* enable receive dma */
214a62c80e5SRussell King 
215a62c80e5SRussell King #define UART01x_RSR_ANY		(UART01x_RSR_OE | UART01x_RSR_BE | UART01x_RSR_PE | UART01x_RSR_FE)
216a62c80e5SRussell King #define UART01x_FR_MODEM_ANY	(UART01x_FR_DCD | UART01x_FR_DSR | UART01x_FR_CTS)
217a62c80e5SRussell King 
218fbb18a27SRussell King #ifndef __ASSEMBLY__
219aa853f85SAlessandro Rubini struct amba_device; /* in uncompress this is included but amba/bus.h is not */
220fbb18a27SRussell King struct amba_pl010_data {
221fbb18a27SRussell King 	void (*set_mctrl)(struct amba_device *dev, void __iomem *base, unsigned int mctrl);
222fbb18a27SRussell King };
22368b65f73SRussell King 
22468b65f73SRussell King struct dma_chan;
22568b65f73SRussell King struct amba_pl011_data {
22668b65f73SRussell King 	bool (*dma_filter)(struct dma_chan *chan, void *filter_param);
22768b65f73SRussell King 	void *dma_rx_param;
22868b65f73SRussell King 	void *dma_tx_param;
229cb06ff10SChanho Min 	bool dma_rx_poll_enable;
230cb06ff10SChanho Min 	unsigned int dma_rx_poll_rate;
231cb06ff10SChanho Min 	unsigned int dma_rx_poll_timeout;
232c16d51a3SShreshtha Kumar Sahu 	void (*init)(void);
233c16d51a3SShreshtha Kumar Sahu 	void (*exit)(void);
23468b65f73SRussell King };
235fbb18a27SRussell King #endif
236fbb18a27SRussell King 
237a62c80e5SRussell King #endif
238