2 * linux/drivers/serial/hornet_serial.c
4 * Driver for hornet serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
8 * Copyright (C) 2010 Ryan Hsu.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
17 * A note about mapbase / membase
19 * mapbase is the physical address of the IO port.
20 * membase is an 'ioremapped' cookie.
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/ioport.h>
26 #include <linux/init.h>
27 #include <linux/console.h>
28 #include <linux/sysrq.h>
29 #include <linux/delay.h>
30 #include <linux/platform_device.h>
31 #include <linux/tty.h>
32 #include <linux/tty_flip.h>
33 #include <linux/serial_reg.h>
34 #include <linux/serial_core.h>
35 #include <linux/serial.h>
36 #include <linux/serial_8250.h>
37 #include <linux/nmi.h>
38 #include <linux/mutex.h>
39 #include <linux/slab.h>
41 #include <asm/mach-ar71xx/ar933x_uart_platform.h>
47 #define ar7240_reg_rmw_clear(_reg, _val) do {} while (0)
49 #define DRIVER_NAME "ar933x-uart"
51 #define AR933X_UART_REGS_SIZE 20
52 #define AR933X_UART_FIFO_SIZE 16
57 #define UARTDATA_UARTTXCSR_MSB 9
58 #define UARTDATA_UARTTXCSR_LSB 9
59 #define UARTDATA_UARTTXCSR_MASK 0x00000200
60 #define UARTDATA_UARTTXCSR_GET(x) (((x) & UARTDATA_UARTTXCSR_MASK) >> UARTDATA_UARTTXCSR_LSB)
61 #define UARTDATA_UARTTXCSR_SET(x) (((0 | (x)) << UARTDATA_UARTTXCSR_LSB) & UARTDATA_UARTTXCSR_MASK)
62 #define UARTDATA_UARTTXCSR_RESET 0
63 #define UARTDATA_UARTRXCSR_MSB 8
64 #define UARTDATA_UARTRXCSR_LSB 8
65 #define UARTDATA_UARTRXCSR_MASK 0x00000100
66 #define UARTDATA_UARTRXCSR_GET(x) (((x) & UARTDATA_UARTRXCSR_MASK) >> UARTDATA_UARTRXCSR_LSB)
67 #define UARTDATA_UARTRXCSR_SET(x) (((0 | (x)) << UARTDATA_UARTRXCSR_LSB) & UARTDATA_UARTRXCSR_MASK)
68 #define UARTDATA_UARTRXCSR_RESET 0
69 #define UARTDATA_UARTTXRXDATA_MSB 7
70 #define UARTDATA_UARTTXRXDATA_LSB 0
71 #define UARTDATA_UARTTXRXDATA_MASK 0x000000ff
72 #define UARTDATA_UARTTXRXDATA_GET(x) (((x) & UARTDATA_UARTTXRXDATA_MASK) >> UARTDATA_UARTTXRXDATA_LSB)
73 #define UARTDATA_UARTTXRXDATA_SET(x) (((0 | (x)) << UARTDATA_UARTTXRXDATA_LSB) & UARTDATA_UARTTXRXDATA_MASK)
74 #define UARTDATA_UARTTXRXDATA_RESET 0
75 #define UARTDATA_ADDRESS 0x0000
76 #define UARTDATA_HW_MASK 0x000003ff
77 #define UARTDATA_SW_MASK 0x000003ff
78 #define UARTDATA_RSTMASK 0x000003ff
79 #define UARTDATA_RESET 0x00000000
82 #define UARTCS_UARTRXBUSY_MSB 15
83 #define UARTCS_UARTRXBUSY_LSB 15
84 #define UARTCS_UARTRXBUSY_MASK 0x00008000
85 #define UARTCS_UARTRXBUSY_GET(x) (((x) & UARTCS_UARTRXBUSY_MASK) >> UARTCS_UARTRXBUSY_LSB)
86 #define UARTCS_UARTRXBUSY_SET(x) (((0 | (x)) << UARTCS_UARTRXBUSY_LSB) & UARTCS_UARTRXBUSY_MASK)
87 #define UARTCS_UARTRXBUSY_RESET 0
88 #define UARTCS_UARTTXBUSY_MSB 14
89 #define UARTCS_UARTTXBUSY_LSB 14
90 #define UARTCS_UARTTXBUSY_MASK 0x00004000
91 #define UARTCS_UARTTXBUSY_GET(x) (((x) & UARTCS_UARTTXBUSY_MASK) >> UARTCS_UARTTXBUSY_LSB)
92 #define UARTCS_UARTTXBUSY_SET(x) (((0 | (x)) << UARTCS_UARTTXBUSY_LSB) & UARTCS_UARTTXBUSY_MASK)
93 #define UARTCS_UARTTXBUSY_RESET 0
94 #define UARTCS_UARTHOSTINTEN_MSB 13
95 #define UARTCS_UARTHOSTINTEN_LSB 13
96 #define UARTCS_UARTHOSTINTEN_MASK 0x00002000
97 #define UARTCS_UARTHOSTINTEN_GET(x) (((x) & UARTCS_UARTHOSTINTEN_MASK) >> UARTCS_UARTHOSTINTEN_LSB)
98 #define UARTCS_UARTHOSTINTEN_SET(x) (((0 | (x)) << UARTCS_UARTHOSTINTEN_LSB) & UARTCS_UARTHOSTINTEN_MASK)
99 #define UARTCS_UARTHOSTINTEN_RESET 0
100 #define UARTCS_UARTHOSTINT_MSB 12
101 #define UARTCS_UARTHOSTINT_LSB 12
102 #define UARTCS_UARTHOSTINT_MASK 0x00001000
103 #define UARTCS_UARTHOSTINT_GET(x) (((x) & UARTCS_UARTHOSTINT_MASK) >> UARTCS_UARTHOSTINT_LSB)
104 #define UARTCS_UARTHOSTINT_SET(x) (((0 | (x)) << UARTCS_UARTHOSTINT_LSB) & UARTCS_UARTHOSTINT_MASK)
105 #define UARTCS_UARTHOSTINT_RESET 0
106 #define UARTCS_UARTTXBREAK_MSB 11
107 #define UARTCS_UARTTXBREAK_LSB 11
108 #define UARTCS_UARTTXBREAK_MASK 0x00000800
109 #define UARTCS_UARTTXBREAK_GET(x) (((x) & UARTCS_UARTTXBREAK_MASK) >> UARTCS_UARTTXBREAK_LSB)
110 #define UARTCS_UARTTXBREAK_SET(x) (((0 | (x)) << UARTCS_UARTTXBREAK_LSB) & UARTCS_UARTTXBREAK_MASK)
111 #define UARTCS_UARTTXBREAK_RESET 0
112 #define UARTCS_UARTRXBREAK_MSB 10
113 #define UARTCS_UARTRXBREAK_LSB 10
114 #define UARTCS_UARTRXBREAK_MASK 0x00000400
115 #define UARTCS_UARTRXBREAK_GET(x) (((x) & UARTCS_UARTRXBREAK_MASK) >> UARTCS_UARTRXBREAK_LSB)
116 #define UARTCS_UARTRXBREAK_SET(x) (((0 | (x)) << UARTCS_UARTRXBREAK_LSB) & UARTCS_UARTRXBREAK_MASK)
117 #define UARTCS_UARTRXBREAK_RESET 0
118 #define UARTCS_UARTSERIATXREADY_MSB 9
119 #define UARTCS_UARTSERIATXREADY_LSB 9
120 #define UARTCS_UARTSERIATXREADY_MASK 0x00000200
121 #define UARTCS_UARTSERIATXREADY_GET(x) (((x) & UARTCS_UARTSERIATXREADY_MASK) >> UARTCS_UARTSERIATXREADY_LSB)
122 #define UARTCS_UARTSERIATXREADY_SET(x) (((0 | (x)) << UARTCS_UARTSERIATXREADY_LSB) & UARTCS_UARTSERIATXREADY_MASK)
123 #define UARTCS_UARTSERIATXREADY_RESET 0
124 #define UARTCS_UARTTXREADYORIDE_MSB 8
125 #define UARTCS_UARTTXREADYORIDE_LSB 8
126 #define UARTCS_UARTTXREADYORIDE_MASK 0x00000100
127 #define UARTCS_UARTTXREADYORIDE_GET(x) (((x) & UARTCS_UARTTXREADYORIDE_MASK) >> UARTCS_UARTTXREADYORIDE_LSB)
128 #define UARTCS_UARTTXREADYORIDE_SET(x) (((0 | (x)) << UARTCS_UARTTXREADYORIDE_LSB) & UARTCS_UARTTXREADYORIDE_MASK)
129 #define UARTCS_UARTTXREADYORIDE_RESET 0
130 #define UARTCS_UARTRXREADYORIDE_MSB 7
131 #define UARTCS_UARTRXREADYORIDE_LSB 7
132 #define UARTCS_UARTRXREADYORIDE_MASK 0x00000080
133 #define UARTCS_UARTRXREADYORIDE_GET(x) (((x) & UARTCS_UARTRXREADYORIDE_MASK) >> UARTCS_UARTRXREADYORIDE_LSB)
134 #define UARTCS_UARTRXREADYORIDE_SET(x) (((0 | (x)) << UARTCS_UARTRXREADYORIDE_LSB) & UARTCS_UARTRXREADYORIDE_MASK)
135 #define UARTCS_UARTRXREADYORIDE_RESET 0
136 #define UARTCS_UARTDMAEN_MSB 6
137 #define UARTCS_UARTDMAEN_LSB 6
138 #define UARTCS_UARTDMAEN_MASK 0x00000040
139 #define UARTCS_UARTDMAEN_GET(x) (((x) & UARTCS_UARTDMAEN_MASK) >> UARTCS_UARTDMAEN_LSB)
140 #define UARTCS_UARTDMAEN_SET(x) (((0 | (x)) << UARTCS_UARTDMAEN_LSB) & UARTCS_UARTDMAEN_MASK)
141 #define UARTCS_UARTDMAEN_RESET 0
142 #define UARTCS_UARTFLOWCONTROLMODE_MSB 5
143 #define UARTCS_UARTFLOWCONTROLMODE_LSB 4
144 #define UARTCS_UARTFLOWCONTROLMODE_MASK 0x00000030
145 #define UARTCS_UARTFLOWCONTROLMODE_GET(x) (((x) & UARTCS_UARTFLOWCONTROLMODE_MASK) >> UARTCS_UARTFLOWCONTROLMODE_LSB)
146 #define UARTCS_UARTFLOWCONTROLMODE_SET(x) (((0 | (x)) << UARTCS_UARTFLOWCONTROLMODE_LSB) & UARTCS_UARTFLOWCONTROLMODE_MASK)
147 #define UARTCS_UARTFLOWCONTROLMODE_RESET 0
148 #define UARTCS_UARTINTERFACEMODE_MSB 3
149 #define UARTCS_UARTINTERFACEMODE_LSB 2
150 #define UARTCS_UARTINTERFACEMODE_MASK 0x0000000c
151 #define UARTCS_UARTINTERFACEMODE_GET(x) (((x) & UARTCS_UARTINTERFACEMODE_MASK) >> UARTCS_UARTINTERFACEMODE_LSB)
152 #define UARTCS_UARTINTERFACEMODE_SET(x) (((0 | (x)) << UARTCS_UARTINTERFACEMODE_LSB) & UARTCS_UARTINTERFACEMODE_MASK)
153 #define UARTCS_UARTINTERFACEMODE_RESET 0
154 #define UARTCS_UARTPARITYMODE_MSB 1
155 #define UARTCS_UARTPARITYMODE_LSB 0
156 #define UARTCS_UARTPARITYMODE_MASK 0x00000003
157 #define UARTCS_UARTPARITYMODE_GET(x) (((x) & UARTCS_UARTPARITYMODE_MASK) >> UARTCS_UARTPARITYMODE_LSB)
158 #define UARTCS_UARTPARITYMODE_SET(x) (((0 | (x)) << UARTCS_UARTPARITYMODE_LSB) & UARTCS_UARTPARITYMODE_MASK)
159 #define UARTCS_UARTPARITYMODE_RESET 0
160 #define UARTCS_ADDRESS 0x0004
161 #define UARTCS_HW_MASK 0x0000ffff
162 #define UARTCS_SW_MASK 0x0000ffff
163 #define UARTCS_RSTMASK 0x000029ff
164 #define UARTCS_RESET 0x00000000
166 // 0x0008 (UARTCLOCK)
167 #define UARTCLOCK_UARTCLOCKSCALE_MSB 23
168 #define UARTCLOCK_UARTCLOCKSCALE_LSB 16
169 #define UARTCLOCK_UARTCLOCKSCALE_MASK 0x00ff0000
170 #define UARTCLOCK_UARTCLOCKSCALE_GET(x) (((x) & UARTCLOCK_UARTCLOCKSCALE_MASK) >> UARTCLOCK_UARTCLOCKSCALE_LSB)
171 #define UARTCLOCK_UARTCLOCKSCALE_SET(x) (((0 | (x)) << UARTCLOCK_UARTCLOCKSCALE_LSB) & UARTCLOCK_UARTCLOCKSCALE_MASK)
172 #define UARTCLOCK_UARTCLOCKSCALE_RESET 0
173 #define UARTCLOCK_UARTCLOCKSTEP_MSB 15
174 #define UARTCLOCK_UARTCLOCKSTEP_LSB 0
175 #define UARTCLOCK_UARTCLOCKSTEP_MASK 0x0000ffff
176 #define UARTCLOCK_UARTCLOCKSTEP_GET(x) (((x) & UARTCLOCK_UARTCLOCKSTEP_MASK) >> UARTCLOCK_UARTCLOCKSTEP_LSB)
177 #define UARTCLOCK_UARTCLOCKSTEP_SET(x) (((0 | (x)) << UARTCLOCK_UARTCLOCKSTEP_LSB) & UARTCLOCK_UARTCLOCKSTEP_MASK)
178 #define UARTCLOCK_UARTCLOCKSTEP_RESET 0
179 #define UARTCLOCK_ADDRESS 0x0008
180 #define UARTCLOCK_HW_MASK 0x00ffffff
181 #define UARTCLOCK_SW_MASK 0x00ffffff
182 #define UARTCLOCK_RSTMASK 0x00ffffff
183 #define UARTCLOCK_RESET 0x00000000
186 #define UARTINT_UARTTXEMPTYINT_MSB 9
187 #define UARTINT_UARTTXEMPTYINT_LSB 9
188 #define UARTINT_UARTTXEMPTYINT_MASK 0x00000200
189 #define UARTINT_UARTTXEMPTYINT_GET(x) (((x) & UARTINT_UARTTXEMPTYINT_MASK) >> UARTINT_UARTTXEMPTYINT_LSB)
190 #define UARTINT_UARTTXEMPTYINT_SET(x) (((0 | (x)) << UARTINT_UARTTXEMPTYINT_LSB) & UARTINT_UARTTXEMPTYINT_MASK)
191 #define UARTINT_UARTTXEMPTYINT_RESET 0
192 #define UARTINT_UARTRXFULLINT_MSB 8
193 #define UARTINT_UARTRXFULLINT_LSB 8
194 #define UARTINT_UARTRXFULLINT_MASK 0x00000100
195 #define UARTINT_UARTRXFULLINT_GET(x) (((x) & UARTINT_UARTRXFULLINT_MASK) >> UARTINT_UARTRXFULLINT_LSB)
196 #define UARTINT_UARTRXFULLINT_SET(x) (((0 | (x)) << UARTINT_UARTRXFULLINT_LSB) & UARTINT_UARTRXFULLINT_MASK)
197 #define UARTINT_UARTRXFULLINT_RESET 0
198 #define UARTINT_UARTRXBREAKOFFINT_MSB 7
199 #define UARTINT_UARTRXBREAKOFFINT_LSB 7
200 #define UARTINT_UARTRXBREAKOFFINT_MASK 0x00000080
201 #define UARTINT_UARTRXBREAKOFFINT_GET(x) (((x) & UARTINT_UARTRXBREAKOFFINT_MASK) >> UARTINT_UARTRXBREAKOFFINT_LSB)
202 #define UARTINT_UARTRXBREAKOFFINT_SET(x) (((0 | (x)) << UARTINT_UARTRXBREAKOFFINT_LSB) & UARTINT_UARTRXBREAKOFFINT_MASK)
203 #define UARTINT_UARTRXBREAKOFFINT_RESET 0
204 #define UARTINT_UARTRXBREAKONINT_MSB 6
205 #define UARTINT_UARTRXBREAKONINT_LSB 6
206 #define UARTINT_UARTRXBREAKONINT_MASK 0x00000040
207 #define UARTINT_UARTRXBREAKONINT_GET(x) (((x) & UARTINT_UARTRXBREAKONINT_MASK) >> UARTINT_UARTRXBREAKONINT_LSB)
208 #define UARTINT_UARTRXBREAKONINT_SET(x) (((0 | (x)) << UARTINT_UARTRXBREAKONINT_LSB) & UARTINT_UARTRXBREAKONINT_MASK)
209 #define UARTINT_UARTRXBREAKONINT_RESET 0
210 #define UARTINT_UARTRXPARITYERRINT_MSB 5
211 #define UARTINT_UARTRXPARITYERRINT_LSB 5
212 #define UARTINT_UARTRXPARITYERRINT_MASK 0x00000020
213 #define UARTINT_UARTRXPARITYERRINT_GET(x) (((x) & UARTINT_UARTRXPARITYERRINT_MASK) >> UARTINT_UARTRXPARITYERRINT_LSB)
214 #define UARTINT_UARTRXPARITYERRINT_SET(x) (((0 | (x)) << UARTINT_UARTRXPARITYERRINT_LSB) & UARTINT_UARTRXPARITYERRINT_MASK)
215 #define UARTINT_UARTRXPARITYERRINT_RESET 0
216 #define UARTINT_UARTTXOFLOWERRINT_MSB 4
217 #define UARTINT_UARTTXOFLOWERRINT_LSB 4
218 #define UARTINT_UARTTXOFLOWERRINT_MASK 0x00000010
219 #define UARTINT_UARTTXOFLOWERRINT_GET(x) (((x) & UARTINT_UARTTXOFLOWERRINT_MASK) >> UARTINT_UARTTXOFLOWERRINT_LSB)
220 #define UARTINT_UARTTXOFLOWERRINT_SET(x) (((0 | (x)) << UARTINT_UARTTXOFLOWERRINT_LSB) & UARTINT_UARTTXOFLOWERRINT_MASK)
221 #define UARTINT_UARTTXOFLOWERRINT_RESET 0
222 #define UARTINT_UARTRXOFLOWERRINT_MSB 3
223 #define UARTINT_UARTRXOFLOWERRINT_LSB 3
224 #define UARTINT_UARTRXOFLOWERRINT_MASK 0x00000008
225 #define UARTINT_UARTRXOFLOWERRINT_GET(x) (((x) & UARTINT_UARTRXOFLOWERRINT_MASK) >> UARTINT_UARTRXOFLOWERRINT_LSB)
226 #define UARTINT_UARTRXOFLOWERRINT_SET(x) (((0 | (x)) << UARTINT_UARTRXOFLOWERRINT_LSB) & UARTINT_UARTRXOFLOWERRINT_MASK)
227 #define UARTINT_UARTRXOFLOWERRINT_RESET 0
228 #define UARTINT_UARTRXFRAMINGERRINT_MSB 2
229 #define UARTINT_UARTRXFRAMINGERRINT_LSB 2
230 #define UARTINT_UARTRXFRAMINGERRINT_MASK 0x00000004
231 #define UARTINT_UARTRXFRAMINGERRINT_GET(x) (((x) & UARTINT_UARTRXFRAMINGERRINT_MASK) >> UARTINT_UARTRXFRAMINGERRINT_LSB)
232 #define UARTINT_UARTRXFRAMINGERRINT_SET(x) (((0 | (x)) << UARTINT_UARTRXFRAMINGERRINT_LSB) & UARTINT_UARTRXFRAMINGERRINT_MASK)
233 #define UARTINT_UARTRXFRAMINGERRINT_RESET 0
234 #define UARTINT_UARTTXREADYINT_MSB 1
235 #define UARTINT_UARTTXREADYINT_LSB 1
236 #define UARTINT_UARTTXREADYINT_MASK 0x00000002
237 #define UARTINT_UARTTXREADYINT_GET(x) (((x) & UARTINT_UARTTXREADYINT_MASK) >> UARTINT_UARTTXREADYINT_LSB)
238 #define UARTINT_UARTTXREADYINT_SET(x) (((0 | (x)) << UARTINT_UARTTXREADYINT_LSB) & UARTINT_UARTTXREADYINT_MASK)
239 #define UARTINT_UARTTXREADYINT_RESET 0
240 #define UARTINT_UARTRXVALIDINT_MSB 0
241 #define UARTINT_UARTRXVALIDINT_LSB 0
242 #define UARTINT_UARTRXVALIDINT_MASK 0x00000001
243 #define UARTINT_UARTRXVALIDINT_GET(x) (((x) & UARTINT_UARTRXVALIDINT_MASK) >> UARTINT_UARTRXVALIDINT_LSB)
244 #define UARTINT_UARTRXVALIDINT_SET(x) (((0 | (x)) << UARTINT_UARTRXVALIDINT_LSB) & UARTINT_UARTRXVALIDINT_MASK)
245 #define UARTINT_UARTRXVALIDINT_RESET 0
246 #define UARTINT_ADDRESS 0x000c
247 #define UARTINT_HW_MASK 0x000003ff
248 #define UARTINT_SW_MASK 0x000003ff
249 #define UARTINT_RSTMASK 0x000003ff
250 #define UARTINT_RESET 0x00000000
252 // 0x0010 (UARTINTEN)
253 #define UARTINTEN_UARTTXEMPTYINTEN_MSB 9
254 #define UARTINTEN_UARTTXEMPTYINTEN_LSB 9
255 #define UARTINTEN_UARTTXEMPTYINTEN_MASK 0x00000200
256 #define UARTINTEN_UARTTXEMPTYINTEN_GET(x) (((x) & UARTINTEN_UARTTXEMPTYINTEN_MASK) >> UARTINTEN_UARTTXEMPTYINTEN_LSB)
257 #define UARTINTEN_UARTTXEMPTYINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTTXEMPTYINTEN_LSB) & UARTINTEN_UARTTXEMPTYINTEN_MASK)
258 #define UARTINTEN_UARTTXEMPTYINTEN_RESET 0
259 #define UARTINTEN_UARTRXFULLINTEN_MSB 8
260 #define UARTINTEN_UARTRXFULLINTEN_LSB 8
261 #define UARTINTEN_UARTRXFULLINTEN_MASK 0x00000100
262 #define UARTINTEN_UARTRXFULLINTEN_GET(x) (((x) & UARTINTEN_UARTRXFULLINTEN_MASK) >> UARTINTEN_UARTRXFULLINTEN_LSB)
263 #define UARTINTEN_UARTRXFULLINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXFULLINTEN_LSB) & UARTINTEN_UARTRXFULLINTEN_MASK)
264 #define UARTINTEN_UARTRXFULLINTEN_RESET 0
265 #define UARTINTEN_UARTRXBREAKOFFINTEN_MSB 7
266 #define UARTINTEN_UARTRXBREAKOFFINTEN_LSB 7
267 #define UARTINTEN_UARTRXBREAKOFFINTEN_MASK 0x00000080
268 #define UARTINTEN_UARTRXBREAKOFFINTEN_GET(x) (((x) & UARTINTEN_UARTRXBREAKOFFINTEN_MASK) >> UARTINTEN_UARTRXBREAKOFFINTEN_LSB)
269 #define UARTINTEN_UARTRXBREAKOFFINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXBREAKOFFINTEN_LSB) & UARTINTEN_UARTRXBREAKOFFINTEN_MASK)
270 #define UARTINTEN_UARTRXBREAKOFFINTEN_RESET 0
271 #define UARTINTEN_UARTRXBREAKONINTEN_MSB 6
272 #define UARTINTEN_UARTRXBREAKONINTEN_LSB 6
273 #define UARTINTEN_UARTRXBREAKONINTEN_MASK 0x00000040
274 #define UARTINTEN_UARTRXBREAKONINTEN_GET(x) (((x) & UARTINTEN_UARTRXBREAKONINTEN_MASK) >> UARTINTEN_UARTRXBREAKONINTEN_LSB)
275 #define UARTINTEN_UARTRXBREAKONINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXBREAKONINTEN_LSB) & UARTINTEN_UARTRXBREAKONINTEN_MASK)
276 #define UARTINTEN_UARTRXBREAKONINTEN_RESET 0
277 #define UARTINTEN_UARTRXPARITYERRINTEN_MSB 5
278 #define UARTINTEN_UARTRXPARITYERRINTEN_LSB 5
279 #define UARTINTEN_UARTRXPARITYERRINTEN_MASK 0x00000020
280 #define UARTINTEN_UARTRXPARITYERRINTEN_GET(x) (((x) & UARTINTEN_UARTRXPARITYERRINTEN_MASK) >> UARTINTEN_UARTRXPARITYERRINTEN_LSB)
281 #define UARTINTEN_UARTRXPARITYERRINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXPARITYERRINTEN_LSB) & UARTINTEN_UARTRXPARITYERRINTEN_MASK)
282 #define UARTINTEN_UARTRXPARITYERRINTEN_RESET 0
283 #define UARTINTEN_UARTTXOFLOWERRINTEN_MSB 4
284 #define UARTINTEN_UARTTXOFLOWERRINTEN_LSB 4
285 #define UARTINTEN_UARTTXOFLOWERRINTEN_MASK 0x00000010
286 #define UARTINTEN_UARTTXOFLOWERRINTEN_GET(x) (((x) & UARTINTEN_UARTTXOFLOWERRINTEN_MASK) >> UARTINTEN_UARTTXOFLOWERRINTEN_LSB)
287 #define UARTINTEN_UARTTXOFLOWERRINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTTXOFLOWERRINTEN_LSB) & UARTINTEN_UARTTXOFLOWERRINTEN_MASK)
288 #define UARTINTEN_UARTTXOFLOWERRINTEN_RESET 0
289 #define UARTINTEN_UARTRXOFLOWERRINTEN_MSB 3
290 #define UARTINTEN_UARTRXOFLOWERRINTEN_LSB 3
291 #define UARTINTEN_UARTRXOFLOWERRINTEN_MASK 0x00000008
292 #define UARTINTEN_UARTRXOFLOWERRINTEN_GET(x) (((x) & UARTINTEN_UARTRXOFLOWERRINTEN_MASK) >> UARTINTEN_UARTRXOFLOWERRINTEN_LSB)
293 #define UARTINTEN_UARTRXOFLOWERRINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXOFLOWERRINTEN_LSB) & UARTINTEN_UARTRXOFLOWERRINTEN_MASK)
294 #define UARTINTEN_UARTRXOFLOWERRINTEN_RESET 0
295 #define UARTINTEN_UARTRXFRAMINGERRINTEN_MSB 2
296 #define UARTINTEN_UARTRXFRAMINGERRINTEN_LSB 2
297 #define UARTINTEN_UARTRXFRAMINGERRINTEN_MASK 0x00000004
298 #define UARTINTEN_UARTRXFRAMINGERRINTEN_GET(x) (((x) & UARTINTEN_UARTRXFRAMINGERRINTEN_MASK) >> UARTINTEN_UARTRXFRAMINGERRINTEN_LSB)
299 #define UARTINTEN_UARTRXFRAMINGERRINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXFRAMINGERRINTEN_LSB) & UARTINTEN_UARTRXFRAMINGERRINTEN_MASK)
300 #define UARTINTEN_UARTRXFRAMINGERRINTEN_RESET 0
301 #define UARTINTEN_UARTTXREADYINTEN_MSB 1
302 #define UARTINTEN_UARTTXREADYINTEN_LSB 1
303 #define UARTINTEN_UARTTXREADYINTEN_MASK 0x00000002
304 #define UARTINTEN_UARTTXREADYINTEN_GET(x) (((x) & UARTINTEN_UARTTXREADYINTEN_MASK) >> UARTINTEN_UARTTXREADYINTEN_LSB)
305 #define UARTINTEN_UARTTXREADYINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTTXREADYINTEN_LSB) & UARTINTEN_UARTTXREADYINTEN_MASK)
306 #define UARTINTEN_UARTTXREADYINTEN_RESET 0
307 #define UARTINTEN_UARTRXVALIDINTEN_MSB 0
308 #define UARTINTEN_UARTRXVALIDINTEN_LSB 0
309 #define UARTINTEN_UARTRXVALIDINTEN_MASK 0x00000001
310 #define UARTINTEN_UARTRXVALIDINTEN_GET(x) (((x) & UARTINTEN_UARTRXVALIDINTEN_MASK) >> UARTINTEN_UARTRXVALIDINTEN_LSB)
311 #define UARTINTEN_UARTRXVALIDINTEN_SET(x) (((0 | (x)) << UARTINTEN_UARTRXVALIDINTEN_LSB) & UARTINTEN_UARTRXVALIDINTEN_MASK)
312 #define UARTINTEN_UARTRXVALIDINTEN_RESET 0
313 #define UARTINTEN_ADDRESS 0x0010
314 #define UARTINTEN_HW_MASK 0x000003ff
315 #define UARTINTEN_SW_MASK 0x000003ff
316 #define UARTINTEN_RSTMASK 0x000003ff
317 #define UARTINTEN_RESET 0x00000000
320 * uncomment below to enable WAR for EV81847.
322 //#define AR933X_EV81847_WAR
324 static struct uart_driver ar933x_uart_driver
;
330 #define DEBUG_AUTOCONF(fmt...) printk(fmt)
332 #define DEBUG_AUTOCONF(fmt...) do { } while (0)
336 #define DEBUG_INTR(fmt...) printk(fmt)
338 #define DEBUG_INTR(fmt...) do { } while (0)
342 * We default to IRQ0 for the "no irq" hack. Some
343 * machine types want others as well - they're free
344 * to redefine this in their header file.
346 #define is_real_interrupt(irq) ((irq) != 0)
348 #include <asm/serial.h>
350 struct ar933x_uart_port
{
351 struct uart_port port
;
352 struct timer_list timer
; /* "no irq" timer */
359 static inline int ar933x_ev81847_war(void)
361 #if defined(AR933X_EV81847_WAR)
368 static inline unsigned int ar933x_uart_read(struct ar933x_uart_port
*up
,
371 return readl(up
->port
.membase
+ offset
);
374 static inline void ar933x_uart_write(struct ar933x_uart_port
*up
,
375 int offset
, unsigned int value
)
377 writel(value
, up
->port
.membase
+ offset
);
380 static inline void ar933x_uart_rmw(struct ar933x_uart_port
*up
,
387 t
= ar933x_uart_read(up
, offset
);
390 ar933x_uart_write(up
, offset
, t
);
393 static inline void ar933x_uart_rmw_set(struct ar933x_uart_port
*up
,
397 ar933x_uart_rmw(up
, offset
, 0, val
);
400 static inline void ar933x_uart_rmw_clear(struct ar933x_uart_port
*up
,
404 ar933x_uart_rmw(up
, offset
, val
, 0);
407 static inline void ar933x_uart_start_tx_interrupt(struct ar933x_uart_port
*up
)
409 ar933x_uart_rmw_set(up
, UARTINTEN_ADDRESS
,
410 UARTINTEN_UARTTXEMPTYINTEN_SET(1));
413 static inline void ar933x_uart_stop_tx_interrupt(struct ar933x_uart_port
*up
)
415 if (up
->ier
& UART_IER_THRI
) {
416 up
->ier
&= ~UART_IER_THRI
;
418 /* FIXME: why this uses RXVALIDINTEN? */
419 ar933x_uart_rmw_clear(up
, UARTINTEN_ADDRESS
,
420 UARTINTEN_UARTRXVALIDINTEN_SET(1));
424 static unsigned int ar933x_uart_tx_empty(struct uart_port
*port
)
426 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
430 spin_lock_irqsave(&up
->port
.lock
, flags
);
431 rdata
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
432 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
434 return (rdata
& UARTDATA_UARTTXCSR_MASK
) ? 0 : TIOCSER_TEMT
;
437 static unsigned int ar933x_uart_get_mctrl(struct uart_port
*port
)
442 static void ar933x_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
446 static void ar933x_uart_start_tx(struct uart_port
*port
)
448 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
450 ar933x_uart_start_tx_interrupt(up
);
453 static void ar933x_uart_stop_tx(struct uart_port
*port
)
455 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
457 ar933x_uart_stop_tx_interrupt(up
);
460 static void ar933x_uart_stop_rx(struct uart_port
*port
)
462 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
464 up
->ier
&= ~UART_IER_RLSI
;
465 up
->port
.read_status_mask
&= ~UART_LSR_DR
;
467 ar933x_uart_rmw_clear(up
, UARTINTEN_ADDRESS
,
468 UARTINTEN_UARTRXVALIDINTEN_SET(1));
471 static void ar933x_uart_break_ctl(struct uart_port
*port
, int break_state
)
473 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
477 spin_lock_irqsave(&up
->port
.lock
, flags
);
479 if (break_state
== -1)
480 up
->lcr
|= UART_LCR_SBC
;
482 up
->lcr
&= ~UART_LCR_SBC
;
484 rdata
= ar933x_uart_read(up
, UARTCS_ADDRESS
);
485 if (up
->lcr
& UART_LCR_SBC
)
486 rdata
|= UARTCS_UARTTXBREAK_SET(1);
488 rdata
&= ~UARTCS_UARTTXBREAK_SET(1);
490 ar933x_uart_write(up
, UARTCS_ADDRESS
, rdata
);
492 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
495 static void ar933x_uart_enable_ms(struct uart_port
*port
)
499 static inline unsigned int ar933x_uart_get_divisor(struct uart_port
*port
,
502 return (port
->uartclk
/ (16 * baud
)) - 1;
505 static void ar933x_uart_set_termios(struct uart_port
*port
,
506 struct ktermios
*termios
,
507 struct ktermios
*old
)
509 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
512 unsigned int baud
, quot
;
514 switch (termios
->c_cflag
& CSIZE
) {
516 cval
= UART_LCR_WLEN5
;
519 cval
= UART_LCR_WLEN6
;
522 cval
= UART_LCR_WLEN7
;
526 cval
= UART_LCR_WLEN8
;
530 if (termios
->c_cflag
& CSTOPB
)
531 cval
|= UART_LCR_STOP
;
532 if (termios
->c_cflag
& PARENB
)
533 cval
|= UART_LCR_PARITY
;
534 if (!(termios
->c_cflag
& PARODD
))
535 cval
|= UART_LCR_EPAR
;
537 if (termios
->c_cflag
& CMSPAR
)
538 cval
|= UART_LCR_SPAR
;
542 * Ask the core to calculate the divisor for us.
544 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/ 16);
545 quot
= ar933x_uart_get_divisor(port
, baud
);
548 if (up
->capabilities
& UART_CAP_FIFO
&& up
->port
.fifosize
> 1) {
550 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
552 fcr
= uart_config
[up
->port
.type
].fcr
;
556 * MCR-based auto flow control. When AFE is enabled, RTS will be
557 * deasserted when the receive FIFO contains more characters than
558 * the trigger, or the MCR RTS bit is cleared. In the case where
559 * the remote UART is not using CTS auto flow control, we must
560 * have sufficient FIFO entries for the latency of the remote
561 * UART to respond. IOW, at least 32 bytes of FIFO.
563 if (up
->capabilities
& UART_CAP_AFE
&& up
->port
.fifosize
>= 32) {
564 up
->mcr
&= ~UART_MCR_AFE
;
565 if (termios
->c_cflag
& CRTSCTS
)
566 up
->mcr
|= UART_MCR_AFE
;
571 * Ok, we're now changing the port state. Do it with
572 * interrupts disabled.
574 spin_lock_irqsave(&up
->port
.lock
, flags
);
577 * Update the per-port timeout.
579 uart_update_timeout(port
, termios
->c_cflag
, baud
);
581 up
->port
.read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
582 if (termios
->c_iflag
& INPCK
)
583 up
->port
.read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
584 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
585 up
->port
.read_status_mask
|= UART_LSR_BI
;
588 * Characteres to ignore
590 up
->port
.ignore_status_mask
= 0;
591 if (termios
->c_iflag
& IGNPAR
)
592 up
->port
.ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
593 if (termios
->c_iflag
& IGNBRK
) {
594 up
->port
.ignore_status_mask
|= UART_LSR_BI
;
596 * If we're ignoring parity and break indicators,
597 * ignore overruns too (for real raw support).
599 if (termios
->c_iflag
& IGNPAR
)
600 up
->port
.ignore_status_mask
|= UART_LSR_OE
;
604 * ignore all characters if CREAD is not set
606 if ((termios
->c_cflag
& CREAD
) == 0)
607 up
->port
.ignore_status_mask
|= UART_LSR_DR
;
610 * CTS flow control flag and modem status interrupts
612 up
->ier
&= ~UART_IER_MSI
;
613 if (UART_ENABLE_MS(&up
->port
, termios
->c_cflag
))
614 up
->ier
|= UART_IER_MSI
;
616 ar933x_uart_rmw_set(up
, UARTCS_ADDRESS
,
617 UARTCS_UARTHOSTINTEN_SET(1));
622 ar933x_uart_set_mctrl(&up
->port
, up
->port
.mctrl
);
623 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
626 static void ar933x_uart_rx_chars(struct ar933x_uart_port
*up
, int *status
)
628 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
629 unsigned int lsr
= *status
;
635 ch
= (unsigned char)UARTDATA_UARTTXRXDATA_GET(lsr
);
638 up
->port
.icount
.rx
++;
640 lsr
= UARTDATA_UARTRXCSR_SET(1);
641 ar933x_uart_write(up
, UARTDATA_ADDRESS
, lsr
);
643 if (unlikely(lsr
& (UART_LSR_BI
| UART_LSR_PE
|
644 UART_LSR_FE
| UART_LSR_OE
))) {
646 * For statistics only
648 if (lsr
& UART_LSR_BI
) {
649 lsr
&= ~(UART_LSR_FE
| UART_LSR_PE
);
650 up
->port
.icount
.brk
++;
652 * We do the SysRQ and SAK checking
653 * here because otherwise the break
654 * may get masked by ignore_status_mask
655 * or read_status_mask.
657 if (uart_handle_break(&up
->port
))
659 } else if (lsr
& UART_LSR_PE
)
660 up
->port
.icount
.parity
++;
661 else if (lsr
& UART_LSR_FE
)
662 up
->port
.icount
.frame
++;
663 if (lsr
& UART_LSR_OE
)
664 up
->port
.icount
.overrun
++;
667 * Mask off conditions which should be ignored.
669 lsr
&= up
->port
.read_status_mask
;
671 if (lsr
& UART_LSR_BI
) {
672 DEBUG_INTR("handling break....");
674 } else if (lsr
& UART_LSR_PE
)
676 else if (lsr
& UART_LSR_FE
)
680 if (uart_handle_sysrq_char(&up
->port
, ch
))
683 uart_insert_char(&up
->port
, lsr
, UART_LSR_OE
, ch
, flag
);
686 lsr
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
687 } while ((lsr
& UARTDATA_UARTRXCSR_MASK
) && (max_count
-- > 0));
689 spin_unlock(&up
->port
.lock
);
690 tty_flip_buffer_push(tty
);
691 spin_lock(&up
->port
.lock
);
696 static void ar933x_uart_tx_chars(struct ar933x_uart_port
*up
)
698 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
702 rdata
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
703 if (UARTDATA_UARTTXCSR_GET(rdata
) == 0) {
704 ar933x_uart_start_tx_interrupt(up
);
708 if (up
->port
.x_char
) {
709 rdata
= UARTDATA_UARTTXRXDATA_SET((unsigned int)(up
->port
.x_char
));
710 rdata
|= UARTDATA_UARTTXCSR_SET(1);
711 ar933x_uart_write(up
, UARTDATA_ADDRESS
, rdata
);
712 up
->port
.icount
.tx
++;
714 ar933x_uart_start_tx_interrupt(up
);
718 if (uart_tx_stopped(&up
->port
)) {
719 ar933x_uart_stop_tx(&up
->port
);
723 if (uart_circ_empty(xmit
)) {
724 ar933x_uart_stop_tx_interrupt(up
);
728 count
= up
->port
.fifosize
/ 4;
730 rdata
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
731 if (UARTDATA_UARTTXCSR_GET(rdata
) == 0) {
732 ar933x_uart_start_tx_interrupt(up
);
736 rdata
= UARTDATA_UARTTXRXDATA_SET((unsigned int)(xmit
->buf
[xmit
->tail
]));
737 rdata
|= UARTDATA_UARTTXCSR_SET(1);
738 ar933x_uart_write(up
, UARTDATA_ADDRESS
, rdata
);
740 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
741 up
->port
.icount
.tx
++;
742 if (uart_circ_empty(xmit
))
744 } while (--count
> 0);
746 rdata
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
747 if (UARTDATA_UARTTXCSR_GET(rdata
) == 0) {
748 ar933x_uart_start_tx_interrupt(up
);
752 /* Re-enable TX Empty Interrupt to transmit pending chars */
753 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
) {
754 uart_write_wakeup(&up
->port
);
755 ar933x_uart_start_tx_interrupt(up
);
758 DEBUG_INTR("THRE...");
760 if (uart_circ_empty(xmit
))
761 ar933x_uart_stop_tx_interrupt(up
);
763 ar933x_uart_start_tx_interrupt(up
);
766 /*! Hornet's interrupt status is not read clear, so that we have to...
767 * a. read out the interrupt status
768 * b. clear the interrupt mask to reset the interrupt status
769 * c. enable the interrupt to reactivate interrupt
771 * Disable and clear the interrupt status
773 static inline void ar933x_uart_clear_int(struct ar933x_uart_port
*up
)
775 #define BIT3 (0x1>>3)
777 /* 1. clear MISC interrupt mask */
778 //ar7240_reg_rmw_clear(AR7240_MISC_INT_MASK, BIT3);
780 /* 2. clear uartcs hostinten mask, bit13 */
781 ar933x_uart_rmw_clear(up
, UARTCS_ADDRESS
,
782 UARTCS_UARTHOSTINTEN_SET(1));
784 /* 3. clear rx uartint */
785 ar933x_uart_write(up
, UARTINT_ADDRESS
, UARTINT_UARTRXVALIDINT_SET(1));
787 /* 4. clear misc interrupt status */
788 ar7240_reg_rmw_clear(AR7240_MISC_INT_STATUS
, BIT3
);
790 /* 5. clear rx uartinten*/
791 ar933x_uart_rmw_clear(up
, UARTINTEN_ADDRESS
,
792 UARTINTEN_UARTRXVALIDINTEN_SET(1));
794 /* 6. enable rx int*/
795 ar933x_uart_rmw_set(up
, UARTINTEN_ADDRESS
,
796 UARTINTEN_UARTRXVALIDINTEN_SET(1));
798 /* 7. set uartcs hostinten mask */
799 ar933x_uart_rmw_set(up
, UARTCS_ADDRESS
,
800 UARTCS_UARTHOSTINTEN_SET(1));
802 /* 8. set misc int mask */
803 //ar7240_reg_wr(AR7240_MISC_INT_MASK, BIT3);
806 static inline void ar933x_uart_handle_port(struct ar933x_uart_port
*up
)
809 unsigned int int_status
;
810 unsigned int en_status
;
813 status
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
814 int_status
= ar933x_uart_read(up
, UARTINT_ADDRESS
);
815 en_status
= ar933x_uart_read(up
, UARTINTEN_ADDRESS
);
817 spin_lock_irqsave(&up
->port
.lock
, flags
);
819 if( (int_status
& en_status
) & UARTINT_UARTRXVALIDINT_MASK
)
820 ar933x_uart_rx_chars(up
, &status
);
822 if (((int_status
& en_status
) & UARTINT_UARTTXEMPTYINT_MASK
)) {
823 /* clear TX empty interrupts */
824 ar933x_uart_write(up
, UARTINT_ADDRESS
,
825 UARTINT_UARTTXEMPTYINT_SET(1));
827 /* disable TX empty interrupts */
828 ar933x_uart_rmw_clear(up
, UARTINTEN_ADDRESS
,
829 UARTINTEN_UARTTXEMPTYINTEN_SET(1));
831 if (!uart_circ_empty(&up
->port
.state
->xmit
))
832 ar933x_uart_tx_chars(up
);
835 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
838 static irqreturn_t
ar933x_uart_interrupt(int irq
, void *dev_id
)
840 struct ar933x_uart_port
*up
;
843 up
= (struct ar933x_uart_port
*) dev_id
;
845 iir
= ar933x_uart_read(up
, UARTCS_ADDRESS
);
846 if ((iir
& UARTCS_UARTHOSTINT_MASK
) == 0)
849 DEBUG_INTR("ar933x_uart_interrupt(%d)...", irq
);
851 spin_lock(&up
->port
.lock
);
852 ar933x_uart_handle_port(up
);
853 ar933x_uart_clear_int(up
);
854 spin_unlock(&up
->port
.lock
);
856 DEBUG_INTR("end.\n");
861 static void ar933x_uart_timer(unsigned long data
)
863 struct uart_port
*port
= (void *)data
;
864 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
867 if (ar933x_ev81847_war()) {
868 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
871 if (!uart_circ_empty(xmit
)) {
872 spin_lock_irqsave(&up
->port
.lock
, flags
);
873 ar933x_uart_tx_chars(up
);
874 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
877 iir
= ar933x_uart_read(up
, UARTCS_ADDRESS
);
878 if (iir
& UARTCS_UARTHOSTINT_MASK
) {
879 spin_lock(&up
->port
.lock
);
880 ar933x_uart_handle_port(up
);
881 spin_unlock(&up
->port
.lock
);
885 mod_timer(&up
->timer
, jiffies
+ uart_poll_timeout(port
));
888 static int ar933x_uart_startup(struct uart_port
*port
)
890 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
894 ret
= request_irq(up
->port
.irq
, ar933x_uart_interrupt
,
895 up
->port
.irqflags
, dev_name(up
->port
.dev
), up
);
902 * Clear the interrupt registers.
904 ar933x_uart_read(up
, UARTCS_ADDRESS
);
905 ar933x_uart_read(up
, UARTINT_ADDRESS
);
907 if (!is_real_interrupt(up
->port
.irq
) || ar933x_ev81847_war()) {
908 setup_timer(&up
->timer
, ar933x_uart_timer
, (unsigned long)port
);
909 mod_timer(&up
->timer
, jiffies
+ uart_poll_timeout(port
));
913 spin_lock_irqsave(&up
->port
.lock
, flags
);
916 * Enable host interrupts
918 ar933x_uart_rmw_set(up
, UARTCS_ADDRESS
,
919 UARTCS_UARTHOSTINTEN_SET(1));
922 * Enable RX interrupts
924 up
->ier
= UART_IER_RLSI
| UART_IER_RDI
;
925 ar933x_uart_write(up
, UARTINTEN_ADDRESS
,
926 UARTINTEN_UARTRXVALIDINTEN_SET(1));
929 * And clear the interrupt registers again for luck.
931 ar933x_uart_read(up
, UARTINT_ADDRESS
);
933 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
938 static void ar933x_uart_shutdown(struct uart_port
*port
)
940 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
944 * Disable all interrupts from this port
947 ar933x_uart_write(up
, UARTINTEN_ADDRESS
, 0);
949 spin_lock_irqsave(&up
->port
.lock
, flags
);
950 up
->port
.mctrl
&= ~TIOCM_OUT2
;
951 ar933x_uart_set_mctrl(&up
->port
, up
->port
.mctrl
);
952 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
955 * Disable break condition
957 ar933x_uart_rmw_clear(up
, UARTCS_ADDRESS
,
958 UARTCS_UARTTXBREAK_SET(1));
960 if (!is_real_interrupt(up
->port
.irq
) ||
961 ar933x_ev81847_war())
962 del_timer_sync(&up
->timer
);
964 free_irq(up
->port
.irq
, up
);
967 static const char *ar933x_uart_type(struct uart_port
*port
)
969 return (port
->type
== PORT_AR933X
) ? "AR933X UART" : NULL
;
972 static void ar933x_uart_release_port(struct uart_port
*port
)
974 /* Nothing to release ... */
977 static int ar933x_uart_request_port(struct uart_port
*port
)
979 /* UARTs always present */
983 static void ar933x_uart_config_port(struct uart_port
*port
, int flags
)
985 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
987 port
->type
= PORT_AR933X
;
989 /* Clear mask, so no surprise interrupts. */
990 ar933x_uart_read(up
, UARTCS_ADDRESS
);
991 /* Clear interrupts status register */
992 ar933x_uart_read(up
, UARTINT_ADDRESS
);
995 static int ar933x_uart_verify_port(struct uart_port
*port
,
996 struct serial_struct
*ser
)
1001 static struct uart_ops ar933x_uart_ops
= {
1002 .tx_empty
= ar933x_uart_tx_empty
,
1003 .set_mctrl
= ar933x_uart_set_mctrl
,
1004 .get_mctrl
= ar933x_uart_get_mctrl
,
1005 .stop_tx
= ar933x_uart_stop_tx
,
1006 .start_tx
= ar933x_uart_start_tx
,
1007 .stop_rx
= ar933x_uart_stop_rx
,
1008 .enable_ms
= ar933x_uart_enable_ms
,
1009 .break_ctl
= ar933x_uart_break_ctl
,
1010 .startup
= ar933x_uart_startup
,
1011 .shutdown
= ar933x_uart_shutdown
,
1012 .set_termios
= ar933x_uart_set_termios
,
1013 .type
= ar933x_uart_type
,
1014 .release_port
= ar933x_uart_release_port
,
1015 .request_port
= ar933x_uart_request_port
,
1016 .config_port
= ar933x_uart_config_port
,
1017 .verify_port
= ar933x_uart_verify_port
,
1020 #ifdef CONFIG_SERIAL_AR933X_CONSOLE
1022 static struct ar933x_uart_port
*ar933x_console_ports
[CONFIG_SERIAL_AR933X_NR_UARTS
];
1024 static void ar933x_uart_wait_xmitr(struct ar933x_uart_port
*up
)
1026 unsigned int status
;
1027 unsigned int timeout
= 60000;
1029 /* Wait up to 60ms for the character(s) to be sent. */
1031 status
= ar933x_uart_read(up
, UARTDATA_ADDRESS
);
1035 } while (UARTDATA_UARTTXCSR_GET(status
) == 0);
1038 static void ar933x_uart_console_putchar(struct uart_port
*port
, int ch
)
1040 struct ar933x_uart_port
*up
= (struct ar933x_uart_port
*) port
;
1043 ar933x_uart_wait_xmitr(up
);
1045 rdata
= UARTDATA_UARTTXRXDATA_SET(ch
) |
1046 UARTDATA_UARTTXCSR_SET(1);
1047 ar933x_uart_write(up
, UARTDATA_ADDRESS
, rdata
);
1050 static void ar933x_uart_console_write(struct console
*co
, const char *s
,
1053 struct ar933x_uart_port
*up
= ar933x_console_ports
[co
->index
];
1054 unsigned long flags
;
1058 local_irq_save(flags
);
1060 if (up
->port
.sysrq
) {
1062 } else if (oops_in_progress
) {
1063 locked
= spin_trylock(&up
->port
.lock
);
1065 spin_lock(&up
->port
.lock
);
1068 * First save the IER then disable the interrupts
1070 ier
= ar933x_uart_read(up
, UARTINTEN_ADDRESS
);
1071 ar933x_uart_write(up
, UARTINTEN_ADDRESS
, 0);
1073 uart_console_write(&up
->port
, s
, count
, ar933x_uart_console_putchar
);
1076 * Finally, wait for transmitter to become empty
1077 * and restore the IER
1079 ar933x_uart_wait_xmitr(up
);
1081 ar933x_uart_write(up
, UARTINTEN_ADDRESS
, ier
);
1082 ar933x_uart_write(up
, UARTINT_ADDRESS
, UARTINT_RSTMASK
);
1085 spin_unlock(&up
->port
.lock
);
1087 local_irq_restore(flags
);
1090 static int ar933x_uart_console_setup(struct console
*co
, char *options
)
1092 struct ar933x_uart_port
*up
;
1098 if (co
->index
< 0 || co
->index
>= CONFIG_SERIAL_AR933X_NR_UARTS
)
1101 up
= ar933x_console_ports
[co
->index
];
1106 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1108 return uart_set_options(&up
->port
, co
, baud
, parity
, bits
, flow
);
1111 static struct console ar933x_uart_console
= {
1113 .write
= ar933x_uart_console_write
,
1114 .device
= uart_console_device
,
1115 .setup
= ar933x_uart_console_setup
,
1116 .flags
= CON_PRINTBUFFER
,
1118 .data
= &ar933x_uart_driver
,
1121 static int __init
ar933x_uart_console_init(void)
1123 register_console(&ar933x_uart_console
);
1126 console_initcall(ar933x_uart_console_init
);
1128 static void ar933x_uart_add_console_port(struct ar933x_uart_port
*up
)
1130 ar933x_console_ports
[up
->port
.line
] = up
;
1133 #define AR933X_SERIAL_CONSOLE &ar933x_uart_console
1137 static inline void ar933x_uart_add_console_port(struct ar933x_uart_port
*up
) {}
1139 #define AR933X_SERIAL_CONSOLE NULL
1141 #endif /* CONFIG_SERIAL_AR933X_CONSOLE */
1143 static struct uart_driver ar933x_uart_driver
= {
1144 .owner
= THIS_MODULE
,
1145 .driver_name
= DRIVER_NAME
,
1146 .dev_name
= "ttyATH",
1147 .nr
= CONFIG_SERIAL_AR933X_NR_UARTS
,
1148 .cons
= AR933X_SERIAL_CONSOLE
,
1151 static int __devinit
ar933x_uart_probe(struct platform_device
*pdev
)
1153 struct ar933x_uart_platform_data
*pdata
;
1154 struct ar933x_uart_port
*up
;
1155 struct uart_port
*port
;
1156 struct resource
*mem_res
;
1157 struct resource
*irq_res
;
1161 pdata
= pdev
->dev
.platform_data
;
1169 if (id
> CONFIG_SERIAL_AR933X_NR_UARTS
)
1172 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1174 dev_err(&pdev
->dev
, "no MEM resource\n");
1178 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1180 dev_err(&pdev
->dev
, "no IRQ resource\n");
1184 up
= kzalloc(sizeof(struct ar933x_uart_port
), GFP_KERNEL
);
1189 port
->mapbase
= mem_res
->start
;
1191 port
->membase
= ioremap(mem_res
->start
, AR933X_UART_REGS_SIZE
);
1192 if (!port
->membase
) {
1198 port
->irq
= irq_res
->start
;
1199 port
->dev
= &pdev
->dev
;
1200 port
->type
= PORT_AR933X
;
1201 port
->iotype
= UPIO_MEM32
;
1202 port
->uartclk
= pdata
->uartclk
;
1205 port
->fifosize
= AR933X_UART_FIFO_SIZE
;
1206 port
->ops
= &ar933x_uart_ops
;
1208 ar933x_uart_add_console_port(up
);
1210 ret
= uart_add_one_port(&ar933x_uart_driver
, &up
->port
);
1214 platform_set_drvdata(pdev
, up
);
1218 iounmap(up
->port
.membase
);
1224 static int __devexit
ar933x_uart_remove(struct platform_device
*pdev
)
1226 struct ar933x_uart_port
*up
;
1228 up
= platform_get_drvdata(pdev
);
1229 platform_set_drvdata(pdev
, NULL
);
1232 uart_remove_one_port(&ar933x_uart_driver
, &up
->port
);
1233 iounmap(up
->port
.membase
);
1240 static struct platform_driver ar933x_uart_platform_driver
= {
1241 .probe
= ar933x_uart_probe
,
1242 .remove
= __devexit_p(ar933x_uart_remove
),
1244 .name
= DRIVER_NAME
,
1245 .owner
= THIS_MODULE
,
1249 static int __init
ar933x_uart_init(void)
1253 ar933x_uart_driver
.nr
= CONFIG_SERIAL_AR933X_NR_UARTS
;
1254 ret
= uart_register_driver(&ar933x_uart_driver
);
1258 ret
= platform_driver_register(&ar933x_uart_platform_driver
);
1260 goto err_unregister_uart_driver
;
1264 err_unregister_uart_driver
:
1265 uart_unregister_driver(&ar933x_uart_driver
);
1270 static void __exit
ar933x_uart_exit(void)
1272 platform_driver_unregister(&ar933x_uart_platform_driver
);
1273 uart_unregister_driver(&ar933x_uart_driver
);
1276 module_init(ar933x_uart_init
);
1277 module_exit(ar933x_uart_exit
);
1279 MODULE_DESCRIPTION("Atheros AR933X UART driver");
1280 MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
1281 MODULE_LICENSE("GPL v2");
1282 MODULE_ALIAS("platform:" DRV_NAME
);