This source file includes following definitions.
- com_enable_debugport
- com_attach_subr
- com_fifo_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/kernel.h>
67 #include <sys/device.h>
68 #include <sys/tty.h>
69
70 #include "com.h"
71 #ifdef i386
72 #include "pccom.h"
73 #else
74 #define NPCCOM 0
75 #endif
76
77 #include <machine/bus.h>
78 #if defined(__sparc64__) || !defined(__sparc__)
79 #include <machine/intr.h>
80 #endif
81
82 #if !defined(__sparc__) || defined(__sparc64__)
83 #define COM_CONSOLE
84 #include <dev/cons.h>
85 #endif
86
87 #include <dev/ic/comreg.h>
88 #include <dev/ic/ns16550reg.h>
89 #define com_lcr com_cfcr
90
91 #if NCOM > 0
92 #include <dev/ic/comvar.h>
93 #endif
94 #if NPCCOM > 0
95 #include <i386/isa/pccomvar.h>
96 #endif
97
98 #ifdef COM_PXA2X0
99 #define com_isr 8
100 #define ISR_SEND (ISR_RXPL | ISR_XMODE | ISR_XMITIR)
101 #define ISR_RECV (ISR_RXPL | ISR_XMODE | ISR_RCVEIR)
102 #endif
103
104 #ifdef COM_CONSOLE
105 #include <sys/conf.h>
106 cdev_decl(com);
107 #endif
108
109 void com_enable_debugport(struct com_softc *);
110 void com_fifo_probe(struct com_softc *);
111
112 #if defined(COM_CONSOLE) || defined(KGDB)
113 void
114 com_enable_debugport(sc)
115 struct com_softc *sc;
116 {
117 int s;
118
119
120 s = splhigh();
121 #ifdef KGDB
122 SET(sc->sc_ier, IER_ERXRDY);
123 #ifdef COM_PXA2X0
124 if (sc->sc_uarttype == COM_UART_PXA2X0)
125 sc->sc_ier |= IER_EUART | IER_ERXTOUT;
126 #endif
127 bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
128 #endif
129 SET(sc->sc_mcr, MCR_DTR | MCR_RTS | MCR_IENABLE);
130 bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
131
132 splx(s);
133 }
134 #endif
135
136 void
137 com_attach_subr(sc)
138 struct com_softc *sc;
139 {
140 bus_space_tag_t iot = sc->sc_iot;
141 bus_space_handle_t ioh = sc->sc_ioh;
142 u_int8_t lcr;
143
144 sc->sc_ier = 0;
145 #ifdef COM_PXA2X0
146 if (sc->sc_uarttype == COM_UART_PXA2X0)
147 sc->sc_ier |= IER_EUART;
148 #endif
149
150 bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
151
152 #ifdef COM_CONSOLE
153 if (sc->sc_iobase == comconsaddr) {
154 comconsattached = 1;
155 delay(10000);
156 SET(sc->sc_hwflags, COM_HW_CONSOLE);
157 SET(sc->sc_swflags, COM_SW_SOFTCAR);
158 }
159 #endif
160
161
162
163
164 lcr = bus_space_read_1(iot, ioh, com_lcr);
165 bus_space_write_1(iot, ioh, com_lcr, LCR_EFR);
166 bus_space_write_1(iot, ioh, com_efr, 0);
167 bus_space_write_1(iot, ioh, com_lcr, 0);
168
169 bus_space_write_1(iot, ioh, com_fifo, FIFO_ENABLE);
170 delay(100);
171
172
173
174
175 if (sc->sc_uarttype == COM_UART_UNKNOWN)
176 switch (bus_space_read_1(iot, ioh, com_iir) >> 6) {
177 case 0:
178 sc->sc_uarttype = COM_UART_16450;
179 break;
180 case 2:
181 sc->sc_uarttype = COM_UART_16550;
182 break;
183 case 3:
184 sc->sc_uarttype = COM_UART_16550A;
185 break;
186 default:
187 sc->sc_uarttype = COM_UART_UNKNOWN;
188 break;
189 }
190
191 if (sc->sc_uarttype == COM_UART_16550A) {
192 bus_space_write_1(iot, ioh, com_lcr, lcr | LCR_DLAB);
193 if (bus_space_read_1(iot, ioh, com_efr) == 0) {
194 sc->sc_uarttype = COM_UART_ST16650;
195 } else {
196 bus_space_write_1(iot, ioh, com_lcr, LCR_EFR);
197 if (bus_space_read_1(iot, ioh, com_efr) == 0)
198 sc->sc_uarttype = COM_UART_ST16650V2;
199 }
200 }
201
202 #if NPCCOM > 0
203 if (sc->sc_uarttype == COM_UART_ST16650V2) {
204 u_int8_t dlbl, dlbh;
205
206
207 bus_space_write_1(iot, ioh, com_lcr, lcr | LCR_DLAB);
208 dlbl = bus_space_read_1(iot, ioh, com_dlbl);
209 dlbh = bus_space_read_1(iot, ioh, com_dlbh);
210
211
212 bus_space_write_1(iot, ioh, com_dlbl, 0);
213 bus_space_write_1(iot, ioh, com_dlbh, 0);
214
215 if (bus_space_read_1(iot, ioh, com_dlbh) == 0x10) {
216 sc->sc_uarttype = COM_UART_XR16850;
217 sc->sc_uartrev = bus_space_read_1(iot, ioh, com_dlbl);
218 }
219
220
221 bus_space_write_1(iot, ioh, com_dlbl, dlbl);
222 bus_space_write_1(iot, ioh, com_dlbh, dlbh);
223 }
224 #endif
225
226 if (sc->sc_uarttype == COM_UART_16550A) {
227 bus_space_write_1(iot, ioh, com_lcr, lcr | LCR_DLAB);
228 bus_space_write_1(iot, ioh, com_fifo,
229 FIFO_ENABLE | FIFO_ENABLE_64BYTE);
230 if ((bus_space_read_1(iot, ioh, com_iir) >> 5) == 7) {
231 #if 0
232 bus_space_write_1(iot, ioh, com_lcr, 0);
233 if ((bus_space_read_1(iot, ioh, com_iir) >> 5) == 6)
234 #endif
235 sc->sc_uarttype = COM_UART_TI16750;
236 }
237 bus_space_write_1(iot, ioh, com_fifo, FIFO_ENABLE);
238 }
239
240
241 bus_space_write_1(iot, ioh, com_lcr, lcr);
242 if (sc->sc_uarttype == COM_UART_16450) {
243 u_int8_t scr0, scr1, scr2;
244
245 scr0 = bus_space_read_1(iot, ioh, com_scratch);
246 bus_space_write_1(iot, ioh, com_scratch, 0xa5);
247 scr1 = bus_space_read_1(iot, ioh, com_scratch);
248 bus_space_write_1(iot, ioh, com_scratch, 0x5a);
249 scr2 = bus_space_read_1(iot, ioh, com_scratch);
250 bus_space_write_1(iot, ioh, com_scratch, scr0);
251
252 if ((scr1 != 0xa5) || (scr2 != 0x5a))
253 sc->sc_uarttype = COM_UART_8250;
254 }
255
256
257
258
259 switch (sc->sc_uarttype) {
260 case COM_UART_UNKNOWN:
261 printf(": unknown uart\n");
262 break;
263 case COM_UART_8250:
264 printf(": ns8250, no fifo\n");
265 break;
266 case COM_UART_16450:
267 printf(": ns16450, no fifo\n");
268 break;
269 case COM_UART_16550:
270 printf(": ns16550, no working fifo\n");
271 break;
272 case COM_UART_16550A:
273 if (sc->sc_fifolen == 0)
274 sc->sc_fifolen = 16;
275 printf(": ns16550a, %d byte fifo\n", sc->sc_fifolen);
276 SET(sc->sc_hwflags, COM_HW_FIFO);
277 break;
278 #ifdef COM_PXA2X0
279 case COM_UART_PXA2X0:
280 printf(": pxa2x0, 32 byte fifo");
281 SET(sc->sc_hwflags, COM_HW_FIFO);
282 sc->sc_fifolen = 32;
283 if (sc->sc_iobase == comsiraddr) {
284 SET(sc->sc_hwflags, COM_HW_SIR);
285 printf(" (SIR)");
286 }
287 printf("\n");
288 break;
289 #endif
290 case COM_UART_ST16650:
291 printf(": st16650, no working fifo\n");
292 break;
293 case COM_UART_ST16650V2:
294 if (sc->sc_fifolen == 0)
295 sc->sc_fifolen = 32;
296 printf(": st16650, %d byte fifo\n", sc->sc_fifolen);
297 SET(sc->sc_hwflags, COM_HW_FIFO);
298 break;
299 case COM_UART_ST16C654:
300 printf(": st16c654, 64 byte fifo\n");
301 SET(sc->sc_hwflags, COM_HW_FIFO);
302 sc->sc_fifolen = 64;
303 break;
304 case COM_UART_TI16750:
305 printf(": ti16750, 64 byte fifo\n");
306 SET(sc->sc_hwflags, COM_HW_FIFO);
307 sc->sc_fifolen = 64;
308 break;
309 #if NPCCOM > 0
310 case COM_UART_XR16850:
311 printf(": xr16850 (rev %d), 128 byte fifo\n", sc->sc_uartrev);
312 SET(sc->sc_hwflags, COM_HW_FIFO);
313 sc->sc_fifolen = 128;
314 break;
315 #ifdef COM_UART_OX16C950
316 case COM_UART_OX16C950:
317 printf(": ox16c950 (rev %d), 128 byte fifo\n", sc->sc_uartrev);
318 SET(sc->sc_hwflags, COM_HW_FIFO);
319 sc->sc_fifolen = 128;
320 break;
321 #endif
322 #endif
323 default:
324 panic("comattach: bad fifo type");
325 }
326
327 #ifdef notyet
328 com_fifo_probe(sc);
329 #endif
330
331 if (sc->sc_fifolen == 0) {
332 CLR(sc->sc_hwflags, COM_HW_FIFO);
333 sc->sc_fifolen = 1;
334 }
335
336
337 bus_space_write_1(iot, ioh, com_fifo, FIFO_RCV_RST | FIFO_XMT_RST);
338 (void)bus_space_read_1(iot, ioh, com_data);
339 bus_space_write_1(iot, ioh, com_fifo, 0);
340
341 sc->sc_mcr = 0;
342 bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr);
343
344 #ifdef KGDB
345
346
347
348
349
350 if (iot == com_kgdb_iot && sc->sc_iobase == com_kgdb_addr &&
351 !ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
352 printf("%s: kgdb\n", sc->sc_dev.dv_xname);
353 SET(sc->sc_hwflags, COM_HW_KGDB);
354 }
355 #endif
356
357 #ifdef COM_CONSOLE
358 if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
359 int maj;
360
361
362 for (maj = 0; maj < nchrdev; maj++)
363 if (cdevsw[maj].d_open == comopen)
364 break;
365
366 if (maj < nchrdev && cn_tab->cn_dev == NODEV)
367 cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
368
369 printf("%s: console\n", sc->sc_dev.dv_xname);
370 }
371 #endif
372
373 timeout_set(&sc->sc_diag_tmo, comdiag, sc);
374 timeout_set(&sc->sc_dtr_tmo, com_raisedtr, sc);
375 #if NCOM > 0
376 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
377 sc->sc_si = softintr_establish(IPL_TTY, comsoft, sc);
378 if (sc->sc_si == NULL)
379 panic("%s: can't establish soft interrupt",
380 sc->sc_dev.dv_xname);
381 #else
382 timeout_set(&sc->sc_comsoft_tmo, comsoft, sc);
383 #endif
384 #endif
385
386
387
388
389
390 if (!sc->enable)
391 sc->enabled = 1;
392
393 #if defined(COM_CONSOLE) || defined(KGDB)
394 if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE|COM_HW_KGDB))
395 com_enable_debugport(sc);
396 #endif
397 }
398
399 void
400 com_fifo_probe(struct com_softc *sc)
401 {
402 bus_space_handle_t ioh = sc->sc_ioh;
403 bus_space_tag_t iot = sc->sc_iot;
404 u_int8_t fifo, ier;
405 int timo, len;
406
407 if (!ISSET(sc->sc_hwflags, COM_HW_FIFO))
408 return;
409
410 ier = 0;
411 #ifdef COM_PXA2X0
412 if (sc->sc_uarttype == COM_UART_PXA2X0)
413 ier |= IER_EUART;
414 #endif
415 bus_space_write_1(iot, ioh, com_ier, ier);
416 bus_space_write_1(iot, ioh, com_lcr, LCR_DLAB);
417 bus_space_write_1(iot, ioh, com_dlbl, 3);
418 bus_space_write_1(iot, ioh, com_dlbh, 0);
419 bus_space_write_1(iot, ioh, com_lcr, LCR_PNONE | LCR_8BITS);
420 bus_space_write_1(iot, ioh, com_mcr, MCR_LOOPBACK);
421
422 fifo = FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST;
423 if (sc->sc_uarttype == COM_UART_TI16750)
424 fifo |= FIFO_ENABLE_64BYTE;
425
426 bus_space_write_1(iot, ioh, com_fifo, fifo);
427
428 for (len = 0; len < 256; len++) {
429 bus_space_write_1(iot, ioh, com_data, (len + 1));
430 timo = 2000;
431 while (!ISSET(bus_space_read_1(iot, ioh, com_lsr),
432 LSR_TXRDY) && --timo)
433 delay(1);
434 if (!timo)
435 break;
436 }
437
438 delay(100);
439
440 for (len = 0; len < 256; len++) {
441 timo = 2000;
442 while (!ISSET(bus_space_read_1(iot, ioh, com_lsr),
443 LSR_RXRDY) && --timo)
444 delay(1);
445 if (!timo || bus_space_read_1(iot, ioh, com_data) != (len + 1))
446 break;
447 }
448
449
450 if (sc->sc_fifolen > len) {
451 printf("%s: probed fifo depth: %d bytes\n",
452 sc->sc_dev.dv_xname, len);
453 sc->sc_fifolen = len;
454 }
455 }