1 /*
2  * (C) Copyright 2003, 2004
3  * ARM Ltd.
4  * Philippe Robin, <philippe.robin@arm.com>
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 /*
10  * ARM PrimeCell UART's (PL010 & PL011)
11  * ------------------------------------
12  *
13  *  Definitions common to both PL010 & PL011
14  *
15  */
16 
17 #ifndef __ASSEMBLY__
18 /*
19  * We can use a combined structure for PL010 and PL011, because they overlap
20  * only in common registers.
21  */
22 struct pl01x_regs {
23 	u32	dr;		/* 0x00 Data register */
24 	u32	ecr;		/* 0x04 Error clear register (Write) */
25 	u32	pl010_lcrh;	/* 0x08 Line control register, high byte */
26 	u32	pl010_lcrm;	/* 0x0C Line control register, middle byte */
27 	u32	pl010_lcrl;	/* 0x10 Line control register, low byte */
28 	u32	pl010_cr;	/* 0x14 Control register */
29 	u32	fr;		/* 0x18 Flag register (Read only) */
30 #ifdef CONFIG_PL011_SERIAL_RLCR
31 	u32	pl011_rlcr;	/* 0x1c Receive line control register */
32 #else
33 	u32	reserved;
34 #endif
35 	u32	ilpr;		/* 0x20 IrDA low-power counter register */
36 	u32	pl011_ibrd;	/* 0x24 Integer baud rate register */
37 	u32	pl011_fbrd;	/* 0x28 Fractional baud rate register */
38 	u32	pl011_lcrh;	/* 0x2C Line control register */
39 	u32	pl011_cr;	/* 0x30 Control register */
40 };
41 
42 #ifdef CONFIG_DM_SERIAL
43 
44 int pl01x_serial_ofdata_to_platdata(struct udevice *dev);
45 int pl01x_serial_probe(struct udevice *dev);
46 
47 /* Needed for external pl01x_serial_ops drivers */
48 int pl01x_serial_putc(struct udevice *dev, const char ch);
49 int pl01x_serial_pending(struct udevice *dev, bool input);
50 int pl01x_serial_getc(struct udevice *dev);
51 int pl01x_serial_setbrg(struct udevice *dev, int baudrate);
52 
53 struct pl01x_priv {
54 	struct pl01x_regs *regs;
55 	enum pl01x_type type;
56 };
57 
58 #endif /* CONFIG_DM_SERIAL */
59 #endif /* !__ASSEMBLY__ */
60 
61 #define UART_PL01x_RSR_OE               0x08
62 #define UART_PL01x_RSR_BE               0x04
63 #define UART_PL01x_RSR_PE               0x02
64 #define UART_PL01x_RSR_FE               0x01
65 
66 #define UART_PL01x_FR_TXFE              0x80
67 #define UART_PL01x_FR_RXFF              0x40
68 #define UART_PL01x_FR_TXFF              0x20
69 #define UART_PL01x_FR_RXFE              0x10
70 #define UART_PL01x_FR_BUSY              0x08
71 #define UART_PL01x_FR_TMSK              (UART_PL01x_FR_TXFF + UART_PL01x_FR_BUSY)
72 
73 /*
74  *  PL010 definitions
75  *
76  */
77 #define UART_PL010_CR_LPE               (1 << 7)
78 #define UART_PL010_CR_RTIE              (1 << 6)
79 #define UART_PL010_CR_TIE               (1 << 5)
80 #define UART_PL010_CR_RIE               (1 << 4)
81 #define UART_PL010_CR_MSIE              (1 << 3)
82 #define UART_PL010_CR_IIRLP             (1 << 2)
83 #define UART_PL010_CR_SIREN             (1 << 1)
84 #define UART_PL010_CR_UARTEN            (1 << 0)
85 
86 #define UART_PL010_LCRH_WLEN_8          (3 << 5)
87 #define UART_PL010_LCRH_WLEN_7          (2 << 5)
88 #define UART_PL010_LCRH_WLEN_6          (1 << 5)
89 #define UART_PL010_LCRH_WLEN_5          (0 << 5)
90 #define UART_PL010_LCRH_FEN             (1 << 4)
91 #define UART_PL010_LCRH_STP2            (1 << 3)
92 #define UART_PL010_LCRH_EPS             (1 << 2)
93 #define UART_PL010_LCRH_PEN             (1 << 1)
94 #define UART_PL010_LCRH_BRK             (1 << 0)
95 
96 
97 #define UART_PL010_BAUD_460800            1
98 #define UART_PL010_BAUD_230400            3
99 #define UART_PL010_BAUD_115200            7
100 #define UART_PL010_BAUD_57600             15
101 #define UART_PL010_BAUD_38400             23
102 #define UART_PL010_BAUD_19200             47
103 #define UART_PL010_BAUD_14400             63
104 #define UART_PL010_BAUD_9600              95
105 #define UART_PL010_BAUD_4800              191
106 #define UART_PL010_BAUD_2400              383
107 #define UART_PL010_BAUD_1200              767
108 /*
109  *  PL011 definitions
110  *
111  */
112 #define UART_PL011_LCRH_SPS             (1 << 7)
113 #define UART_PL011_LCRH_WLEN_8          (3 << 5)
114 #define UART_PL011_LCRH_WLEN_7          (2 << 5)
115 #define UART_PL011_LCRH_WLEN_6          (1 << 5)
116 #define UART_PL011_LCRH_WLEN_5          (0 << 5)
117 #define UART_PL011_LCRH_FEN             (1 << 4)
118 #define UART_PL011_LCRH_STP2            (1 << 3)
119 #define UART_PL011_LCRH_EPS             (1 << 2)
120 #define UART_PL011_LCRH_PEN             (1 << 1)
121 #define UART_PL011_LCRH_BRK             (1 << 0)
122 
123 #define UART_PL011_CR_CTSEN             (1 << 15)
124 #define UART_PL011_CR_RTSEN             (1 << 14)
125 #define UART_PL011_CR_OUT2              (1 << 13)
126 #define UART_PL011_CR_OUT1              (1 << 12)
127 #define UART_PL011_CR_RTS               (1 << 11)
128 #define UART_PL011_CR_DTR               (1 << 10)
129 #define UART_PL011_CR_RXE               (1 << 9)
130 #define UART_PL011_CR_TXE               (1 << 8)
131 #define UART_PL011_CR_LPE               (1 << 7)
132 #define UART_PL011_CR_IIRLP             (1 << 2)
133 #define UART_PL011_CR_SIREN             (1 << 1)
134 #define UART_PL011_CR_UARTEN            (1 << 0)
135 
136 #define UART_PL011_IMSC_OEIM            (1 << 10)
137 #define UART_PL011_IMSC_BEIM            (1 << 9)
138 #define UART_PL011_IMSC_PEIM            (1 << 8)
139 #define UART_PL011_IMSC_FEIM            (1 << 7)
140 #define UART_PL011_IMSC_RTIM            (1 << 6)
141 #define UART_PL011_IMSC_TXIM            (1 << 5)
142 #define UART_PL011_IMSC_RXIM            (1 << 4)
143 #define UART_PL011_IMSC_DSRMIM          (1 << 3)
144 #define UART_PL011_IMSC_DCDMIM          (1 << 2)
145 #define UART_PL011_IMSC_CTSMIM          (1 << 1)
146 #define UART_PL011_IMSC_RIMIM           (1 << 0)
147