sab.c revision 1.1.2.7 1 1.1.2.7 thorpej /* $NetBSD: sab.c,v 1.1.2.7 2003/01/03 16:57:12 thorpej Exp $ */
2 1.1.2.2 nathanw /* $OpenBSD: sab.c,v 1.7 2002/04/08 17:49:42 jason Exp $ */
3 1.1.2.2 nathanw
4 1.1.2.2 nathanw /*
5 1.1.2.2 nathanw * Copyright (c) 2001 Jason L. Wright (jason (at) thought.net)
6 1.1.2.2 nathanw * All rights reserved.
7 1.1.2.2 nathanw *
8 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
10 1.1.2.2 nathanw * are met:
11 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
16 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
17 1.1.2.2 nathanw * must display the following acknowledgement:
18 1.1.2.2 nathanw * This product includes software developed by Jason L. Wright
19 1.1.2.2 nathanw * 4. The name of the author may not be used to endorse or promote products
20 1.1.2.2 nathanw * derived from this software without specific prior written permission.
21 1.1.2.2 nathanw *
22 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 1.1.2.2 nathanw * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 1.1.2.2 nathanw * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 1.1.2.2 nathanw * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 1.1.2.2 nathanw * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 1.1.2.2 nathanw * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 1.1.2.2 nathanw * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 1.1.2.2 nathanw * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
33 1.1.2.2 nathanw *
34 1.1.2.2 nathanw * Effort sponsored in part by the Defense Advanced Research Projects
35 1.1.2.2 nathanw * Agency (DARPA) and Air Force Research Laboratory, Air Force
36 1.1.2.2 nathanw * Materiel Command, USAF, under agreement number F30602-01-2-0537.
37 1.1.2.2 nathanw *
38 1.1.2.2 nathanw */
39 1.1.2.2 nathanw
40 1.1.2.2 nathanw /*
41 1.1.2.2 nathanw * SAB82532 Dual UART driver
42 1.1.2.2 nathanw */
43 1.1.2.2 nathanw
44 1.1.2.2 nathanw #include <sys/types.h>
45 1.1.2.2 nathanw #include <sys/param.h>
46 1.1.2.2 nathanw #include <sys/systm.h>
47 1.1.2.2 nathanw #include <sys/device.h>
48 1.1.2.2 nathanw #include <sys/conf.h>
49 1.1.2.2 nathanw #include <sys/file.h>
50 1.1.2.2 nathanw #include <sys/ioctl.h>
51 1.1.2.2 nathanw #include <sys/kernel.h>
52 1.1.2.2 nathanw #include <sys/proc.h>
53 1.1.2.2 nathanw #include <sys/tty.h>
54 1.1.2.2 nathanw #include <sys/syslog.h>
55 1.1.2.2 nathanw
56 1.1.2.2 nathanw #include <machine/autoconf.h>
57 1.1.2.2 nathanw #include <machine/openfirm.h>
58 1.1.2.2 nathanw
59 1.1.2.2 nathanw #include <dev/cons.h>
60 1.1.2.2 nathanw
61 1.1.2.2 nathanw #include <dev/ebus/ebusreg.h>
62 1.1.2.2 nathanw #include <dev/ebus/ebusvar.h>
63 1.1.2.2 nathanw #include <sparc64/dev/sab82532reg.h>
64 1.1.2.2 nathanw
65 1.1.2.2 nathanw #define SABUNIT(x) (minor(x) & 0x7ffff)
66 1.1.2.2 nathanw #define SABDIALOUT(x) (minor(x) & 0x80000)
67 1.1.2.2 nathanw
68 1.1.2.2 nathanw #define SABTTY_RBUF_SIZE 1024 /* must be divisible by 2 */
69 1.1.2.2 nathanw
70 1.1.2.2 nathanw struct sab_softc {
71 1.1.2.2 nathanw struct device sc_dv;
72 1.1.2.2 nathanw struct intrhand * sc_ih;
73 1.1.2.2 nathanw bus_space_tag_t sc_bt;
74 1.1.2.2 nathanw bus_space_handle_t sc_bh;
75 1.1.2.2 nathanw struct sabtty_softc * sc_child[SAB_NCHAN];
76 1.1.2.2 nathanw u_int sc_nchild;
77 1.1.2.2 nathanw void * sc_softintr;
78 1.1.2.2 nathanw int sc_node;
79 1.1.2.2 nathanw };
80 1.1.2.2 nathanw
81 1.1.2.2 nathanw struct sabtty_attach_args {
82 1.1.2.2 nathanw u_int sbt_portno;
83 1.1.2.2 nathanw };
84 1.1.2.2 nathanw
85 1.1.2.2 nathanw struct sabtty_softc {
86 1.1.2.2 nathanw struct device sc_dv;
87 1.1.2.2 nathanw struct sab_softc * sc_parent;
88 1.1.2.2 nathanw bus_space_tag_t sc_bt;
89 1.1.2.2 nathanw bus_space_handle_t sc_bh;
90 1.1.2.2 nathanw struct tty * sc_tty;
91 1.1.2.2 nathanw u_int sc_portno;
92 1.1.2.2 nathanw u_int8_t sc_pvr_dtr, sc_pvr_dsr;
93 1.1.2.2 nathanw u_int8_t sc_imr0, sc_imr1;
94 1.1.2.2 nathanw int sc_openflags;
95 1.1.2.2 nathanw u_char * sc_txp;
96 1.1.2.2 nathanw int sc_txc;
97 1.1.2.2 nathanw int sc_flags;
98 1.1.2.2 nathanw #define SABTTYF_STOP 0x01
99 1.1.2.2 nathanw #define SABTTYF_DONE 0x02
100 1.1.2.2 nathanw #define SABTTYF_RINGOVERFLOW 0x04
101 1.1.2.2 nathanw #define SABTTYF_CDCHG 0x08
102 1.1.2.2 nathanw #define SABTTYF_CONS_IN 0x10
103 1.1.2.2 nathanw #define SABTTYF_CONS_OUT 0x20
104 1.1.2.2 nathanw #define SABTTYF_TXDRAIN 0x40
105 1.1.2.2 nathanw #define SABTTYF_DONTDDB 0x80
106 1.1.2.2 nathanw u_int8_t sc_rbuf[SABTTY_RBUF_SIZE];
107 1.1.2.2 nathanw u_int8_t *sc_rend, *sc_rput, *sc_rget;
108 1.1.2.2 nathanw u_int8_t sc_polling, sc_pollrfc;
109 1.1.2.2 nathanw };
110 1.1.2.2 nathanw
111 1.1.2.2 nathanw struct sabtty_softc *sabtty_cons_input;
112 1.1.2.2 nathanw struct sabtty_softc *sabtty_cons_output;
113 1.1.2.2 nathanw
114 1.1.2.2 nathanw #define SAB_READ(sc,r) \
115 1.1.2.2 nathanw bus_space_read_1((sc)->sc_bt, (sc)->sc_bh, (r))
116 1.1.2.2 nathanw #define SAB_WRITE(sc,r,v) \
117 1.1.2.2 nathanw bus_space_write_1((sc)->sc_bt, (sc)->sc_bh, (r), (v))
118 1.1.2.2 nathanw
119 1.1.2.2 nathanw int sab_match(struct device *, struct cfdata *, void *);
120 1.1.2.2 nathanw void sab_attach(struct device *, struct device *, void *);
121 1.1.2.2 nathanw int sab_print(void *, const char *);
122 1.1.2.2 nathanw int sab_intr(void *);
123 1.1.2.2 nathanw
124 1.1.2.2 nathanw void sab_softintr(void *);
125 1.1.2.2 nathanw void sab_cnputc(dev_t, int);
126 1.1.2.2 nathanw int sab_cngetc(dev_t);
127 1.1.2.2 nathanw void sab_cnpollc(dev_t, int);
128 1.1.2.2 nathanw
129 1.1.2.2 nathanw int sabtty_match(struct device *, struct cfdata *, void *);
130 1.1.2.2 nathanw void sabtty_attach(struct device *, struct device *, void *);
131 1.1.2.2 nathanw void sabtty_start(struct tty *);
132 1.1.2.2 nathanw int sabtty_param(struct tty *, struct termios *);
133 1.1.2.2 nathanw int sabtty_intr(struct sabtty_softc *, int *);
134 1.1.2.2 nathanw void sabtty_softintr(struct sabtty_softc *);
135 1.1.2.2 nathanw int sabtty_mdmctrl(struct sabtty_softc *, int, int);
136 1.1.2.2 nathanw void sabtty_cec_wait(struct sabtty_softc *);
137 1.1.2.2 nathanw void sabtty_tec_wait(struct sabtty_softc *);
138 1.1.2.2 nathanw void sabtty_reset(struct sabtty_softc *);
139 1.1.2.2 nathanw void sabtty_flush(struct sabtty_softc *);
140 1.1.2.2 nathanw int sabtty_speed(int);
141 1.1.2.2 nathanw void sabtty_console_flags(struct sabtty_softc *);
142 1.1.2.2 nathanw void sabtty_cnpollc(struct sabtty_softc *, int);
143 1.1.2.2 nathanw void sabtty_shutdown(void *);
144 1.1.2.2 nathanw int sabttyparam(struct sabtty_softc *, struct tty *, struct termios *);
145 1.1.2.2 nathanw
146 1.1.2.2 nathanw void sabtty_cnputc(struct sabtty_softc *, int);
147 1.1.2.2 nathanw int sabtty_cngetc(struct sabtty_softc *);
148 1.1.2.2 nathanw void sabtty_abort(struct sabtty_softc *);
149 1.1.2.2 nathanw
150 1.1.2.4 nathanw CFATTACH_DECL(sab, sizeof(struct sab_softc),
151 1.1.2.4 nathanw sab_match, sab_attach, NULL, NULL);
152 1.1.2.2 nathanw
153 1.1.2.2 nathanw extern struct cfdriver sab_cd;
154 1.1.2.2 nathanw
155 1.1.2.4 nathanw CFATTACH_DECL(sabtty, sizeof(struct sabtty_softc),
156 1.1.2.4 nathanw sabtty_match, sabtty_attach, NULL, NULL);
157 1.1.2.2 nathanw
158 1.1.2.2 nathanw extern struct cfdriver sabtty_cd;
159 1.1.2.2 nathanw
160 1.1.2.3 nathanw dev_type_open(sabopen);
161 1.1.2.3 nathanw dev_type_close(sabclose);
162 1.1.2.3 nathanw dev_type_read(sabread);
163 1.1.2.3 nathanw dev_type_write(sabwrite);
164 1.1.2.3 nathanw dev_type_ioctl(sabioctl);
165 1.1.2.3 nathanw dev_type_stop(sabstop);
166 1.1.2.3 nathanw dev_type_tty(sabtty);
167 1.1.2.3 nathanw dev_type_poll(sabpoll);
168 1.1.2.3 nathanw
169 1.1.2.3 nathanw const struct cdevsw sabtty_cdevsw = {
170 1.1.2.3 nathanw sabopen, sabclose, sabread, sabwrite, sabioctl,
171 1.1.2.5 nathanw sabstop, sabtty, sabpoll, nommap, ttykqfilter, D_TTY
172 1.1.2.3 nathanw };
173 1.1.2.3 nathanw
174 1.1.2.2 nathanw struct sabtty_rate {
175 1.1.2.2 nathanw int baud;
176 1.1.2.2 nathanw int n, m;
177 1.1.2.2 nathanw };
178 1.1.2.2 nathanw
179 1.1.2.2 nathanw struct sabtty_rate sabtty_baudtable[] = {
180 1.1.2.2 nathanw { 50, 35, 10 },
181 1.1.2.2 nathanw { 75, 47, 9 },
182 1.1.2.2 nathanw { 110, 32, 9 },
183 1.1.2.2 nathanw { 134, 53, 8 },
184 1.1.2.2 nathanw { 150, 47, 8 },
185 1.1.2.2 nathanw { 200, 35, 8 },
186 1.1.2.2 nathanw { 300, 47, 7 },
187 1.1.2.2 nathanw { 600, 47, 6 },
188 1.1.2.2 nathanw { 1200, 47, 5 },
189 1.1.2.2 nathanw { 1800, 31, 5 },
190 1.1.2.2 nathanw { 2400, 47, 4 },
191 1.1.2.2 nathanw { 4800, 47, 3 },
192 1.1.2.2 nathanw { 9600, 47, 2 },
193 1.1.2.2 nathanw { 19200, 47, 1 },
194 1.1.2.2 nathanw { 38400, 23, 1 },
195 1.1.2.2 nathanw { 57600, 15, 1 },
196 1.1.2.2 nathanw { 115200, 7, 1 },
197 1.1.2.2 nathanw { 230400, 3, 1 },
198 1.1.2.2 nathanw { 460800, 1, 1 },
199 1.1.2.2 nathanw { 76800, 11, 1 },
200 1.1.2.2 nathanw { 153600, 5, 1 },
201 1.1.2.2 nathanw { 307200, 3, 1 },
202 1.1.2.2 nathanw { 614400, 3, 0 },
203 1.1.2.2 nathanw { 921600, 0, 1 },
204 1.1.2.2 nathanw };
205 1.1.2.2 nathanw
206 1.1.2.2 nathanw int
207 1.1.2.2 nathanw sab_match(parent, match, aux)
208 1.1.2.2 nathanw struct device *parent;
209 1.1.2.2 nathanw struct cfdata *match;
210 1.1.2.2 nathanw void *aux;
211 1.1.2.2 nathanw {
212 1.1.2.2 nathanw struct ebus_attach_args *ea = aux;
213 1.1.2.2 nathanw char *compat;
214 1.1.2.2 nathanw
215 1.1.2.2 nathanw if (strcmp(ea->ea_name, "se") == 0)
216 1.1.2.2 nathanw return (1);
217 1.1.2.2 nathanw
218 1.1.2.2 nathanw compat = PROM_getpropstring(ea->ea_node, "compatible");
219 1.1.2.2 nathanw if (compat != NULL && !strcmp(compat, "sab82532"))
220 1.1.2.2 nathanw return (1);
221 1.1.2.2 nathanw
222 1.1.2.2 nathanw return (0);
223 1.1.2.2 nathanw }
224 1.1.2.2 nathanw
225 1.1.2.2 nathanw void
226 1.1.2.2 nathanw sab_attach(parent, self, aux)
227 1.1.2.2 nathanw struct device *parent;
228 1.1.2.2 nathanw struct device *self;
229 1.1.2.2 nathanw void *aux;
230 1.1.2.2 nathanw {
231 1.1.2.2 nathanw struct sab_softc *sc = (struct sab_softc *)self;
232 1.1.2.2 nathanw struct ebus_attach_args *ea = aux;
233 1.1.2.2 nathanw u_int8_t r;
234 1.1.2.2 nathanw u_int i;
235 1.1.2.2 nathanw
236 1.1.2.2 nathanw sc->sc_bt = ea->ea_bustag;
237 1.1.2.2 nathanw sc->sc_node = ea->ea_node;
238 1.1.2.2 nathanw
239 1.1.2.2 nathanw /* Use prom mapping, if available. */
240 1.1.2.2 nathanw if (ea->ea_nvaddr)
241 1.1.2.2 nathanw sparc_promaddr_to_handle(sc->sc_bt, ea->ea_vaddr[0], &sc->sc_bh);
242 1.1.2.2 nathanw else if (bus_space_map(sc->sc_bt, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
243 1.1.2.2 nathanw ea->ea_reg[0].size, 0, &sc->sc_bh) != 0) {
244 1.1.2.2 nathanw printf(": can't map register space\n");
245 1.1.2.2 nathanw return;
246 1.1.2.2 nathanw }
247 1.1.2.2 nathanw
248 1.1.2.2 nathanw sc->sc_ih = bus_intr_establish(ea->ea_bustag, ea->ea_intr[0],
249 1.1.2.6 thorpej IPL_TTY, sab_intr, sc);
250 1.1.2.2 nathanw if (sc->sc_ih == NULL) {
251 1.1.2.2 nathanw printf(": can't map interrupt\n");
252 1.1.2.2 nathanw return;
253 1.1.2.2 nathanw }
254 1.1.2.2 nathanw
255 1.1.2.2 nathanw sc->sc_softintr = softintr_establish(IPL_TTY, sab_softintr, sc);
256 1.1.2.2 nathanw if (sc->sc_softintr == NULL) {
257 1.1.2.2 nathanw printf(": can't get soft intr\n");
258 1.1.2.2 nathanw return;
259 1.1.2.2 nathanw }
260 1.1.2.2 nathanw
261 1.1.2.2 nathanw printf(": rev ");
262 1.1.2.2 nathanw r = SAB_READ(sc, SAB_VSTR) & SAB_VSTR_VMASK;
263 1.1.2.2 nathanw switch (r) {
264 1.1.2.2 nathanw case SAB_VSTR_V_1:
265 1.1.2.2 nathanw printf("1");
266 1.1.2.2 nathanw break;
267 1.1.2.2 nathanw case SAB_VSTR_V_2:
268 1.1.2.2 nathanw printf("2");
269 1.1.2.2 nathanw break;
270 1.1.2.2 nathanw case SAB_VSTR_V_32:
271 1.1.2.2 nathanw printf("3.2");
272 1.1.2.2 nathanw break;
273 1.1.2.2 nathanw default:
274 1.1.2.2 nathanw printf("unknown(0x%x)", r);
275 1.1.2.2 nathanw break;
276 1.1.2.2 nathanw }
277 1.1.2.2 nathanw printf("\n");
278 1.1.2.2 nathanw
279 1.1.2.2 nathanw /* Set all pins, except DTR pins to be inputs */
280 1.1.2.2 nathanw SAB_WRITE(sc, SAB_PCR, ~(SAB_PVR_DTR_A | SAB_PVR_DTR_B));
281 1.1.2.2 nathanw /* Disable port interrupts */
282 1.1.2.2 nathanw SAB_WRITE(sc, SAB_PIM, 0xff);
283 1.1.2.2 nathanw SAB_WRITE(sc, SAB_PVR, SAB_PVR_DTR_A | SAB_PVR_DTR_B | SAB_PVR_MAGIC);
284 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IPC, SAB_IPC_ICPL);
285 1.1.2.2 nathanw
286 1.1.2.2 nathanw for (i = 0; i < SAB_NCHAN; i++) {
287 1.1.2.2 nathanw struct sabtty_attach_args sta;
288 1.1.2.2 nathanw
289 1.1.2.2 nathanw sta.sbt_portno = i;
290 1.1.2.2 nathanw sc->sc_child[i] = (struct sabtty_softc *)config_found_sm(self,
291 1.1.2.2 nathanw &sta, sab_print, sabtty_match);
292 1.1.2.2 nathanw if (sc->sc_child[i] != NULL)
293 1.1.2.2 nathanw sc->sc_nchild++;
294 1.1.2.2 nathanw }
295 1.1.2.2 nathanw }
296 1.1.2.2 nathanw
297 1.1.2.2 nathanw int
298 1.1.2.2 nathanw sab_print(args, name)
299 1.1.2.2 nathanw void *args;
300 1.1.2.2 nathanw const char *name;
301 1.1.2.2 nathanw {
302 1.1.2.2 nathanw struct sabtty_attach_args *sa = args;
303 1.1.2.2 nathanw
304 1.1.2.2 nathanw if (name)
305 1.1.2.7 thorpej aprint_normal("sabtty at %s", name);
306 1.1.2.7 thorpej aprint_normal(" port %d", sa->sbt_portno);
307 1.1.2.2 nathanw return (UNCONF);
308 1.1.2.2 nathanw }
309 1.1.2.2 nathanw
310 1.1.2.2 nathanw int
311 1.1.2.2 nathanw sab_intr(vsc)
312 1.1.2.2 nathanw void *vsc;
313 1.1.2.2 nathanw {
314 1.1.2.2 nathanw struct sab_softc *sc = vsc;
315 1.1.2.2 nathanw int r = 0, needsoft = 0;
316 1.1.2.2 nathanw u_int8_t gis;
317 1.1.2.2 nathanw
318 1.1.2.2 nathanw gis = SAB_READ(sc, SAB_GIS);
319 1.1.2.2 nathanw
320 1.1.2.2 nathanw /* channel A */
321 1.1.2.2 nathanw if ((gis & (SAB_GIS_ISA1 | SAB_GIS_ISA0)) && sc->sc_child[0] &&
322 1.1.2.2 nathanw sc->sc_child[0]->sc_tty)
323 1.1.2.2 nathanw r |= sabtty_intr(sc->sc_child[0], &needsoft);
324 1.1.2.2 nathanw
325 1.1.2.2 nathanw /* channel B */
326 1.1.2.2 nathanw if ((gis & (SAB_GIS_ISB1 | SAB_GIS_ISB0)) && sc->sc_child[1] &&
327 1.1.2.2 nathanw sc->sc_child[1]->sc_tty)
328 1.1.2.2 nathanw r |= sabtty_intr(sc->sc_child[1], &needsoft);
329 1.1.2.2 nathanw
330 1.1.2.2 nathanw if (needsoft)
331 1.1.2.2 nathanw softintr_schedule(sc->sc_softintr);
332 1.1.2.2 nathanw
333 1.1.2.2 nathanw return (r);
334 1.1.2.2 nathanw }
335 1.1.2.2 nathanw
336 1.1.2.2 nathanw void
337 1.1.2.2 nathanw sab_softintr(vsc)
338 1.1.2.2 nathanw void *vsc;
339 1.1.2.2 nathanw {
340 1.1.2.2 nathanw struct sab_softc *sc = vsc;
341 1.1.2.2 nathanw
342 1.1.2.2 nathanw if (sc->sc_child[0] && sc->sc_child[0]->sc_tty)
343 1.1.2.2 nathanw sabtty_softintr(sc->sc_child[0]);
344 1.1.2.2 nathanw if (sc->sc_child[1] && sc->sc_child[1]->sc_tty)
345 1.1.2.2 nathanw sabtty_softintr(sc->sc_child[1]);
346 1.1.2.2 nathanw }
347 1.1.2.2 nathanw
348 1.1.2.2 nathanw int
349 1.1.2.2 nathanw sabtty_match(parent, match, aux)
350 1.1.2.2 nathanw struct device *parent;
351 1.1.2.2 nathanw struct cfdata *match;
352 1.1.2.2 nathanw void *aux;
353 1.1.2.2 nathanw {
354 1.1.2.2 nathanw struct sabtty_attach_args *sa = aux;
355 1.1.2.2 nathanw
356 1.1.2.2 nathanw if (sa->sbt_portno < SAB_NCHAN)
357 1.1.2.2 nathanw return (1);
358 1.1.2.2 nathanw return (0);
359 1.1.2.2 nathanw }
360 1.1.2.2 nathanw
361 1.1.2.2 nathanw void
362 1.1.2.2 nathanw sabtty_attach(parent, self, aux)
363 1.1.2.2 nathanw struct device *parent;
364 1.1.2.2 nathanw struct device *self;
365 1.1.2.2 nathanw void *aux;
366 1.1.2.2 nathanw {
367 1.1.2.2 nathanw struct sabtty_softc *sc = (struct sabtty_softc *)self;
368 1.1.2.2 nathanw struct sabtty_attach_args *sa = aux;
369 1.1.2.2 nathanw int r;
370 1.1.2.2 nathanw
371 1.1.2.2 nathanw sc->sc_tty = ttymalloc();
372 1.1.2.2 nathanw if (sc->sc_tty == NULL) {
373 1.1.2.2 nathanw printf(": failed to allocate tty\n");
374 1.1.2.2 nathanw return;
375 1.1.2.2 nathanw }
376 1.1.2.2 nathanw tty_attach(sc->sc_tty);
377 1.1.2.2 nathanw sc->sc_tty->t_oproc = sabtty_start;
378 1.1.2.2 nathanw sc->sc_tty->t_param = sabtty_param;
379 1.1.2.2 nathanw
380 1.1.2.2 nathanw sc->sc_parent = (struct sab_softc *)parent;
381 1.1.2.2 nathanw sc->sc_bt = sc->sc_parent->sc_bt;
382 1.1.2.2 nathanw sc->sc_portno = sa->sbt_portno;
383 1.1.2.2 nathanw sc->sc_rend = sc->sc_rbuf + SABTTY_RBUF_SIZE;
384 1.1.2.2 nathanw
385 1.1.2.2 nathanw switch (sa->sbt_portno) {
386 1.1.2.2 nathanw case 0: /* port A */
387 1.1.2.2 nathanw sc->sc_pvr_dtr = SAB_PVR_DTR_A;
388 1.1.2.2 nathanw sc->sc_pvr_dsr = SAB_PVR_DSR_A;
389 1.1.2.2 nathanw r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh,
390 1.1.2.2 nathanw SAB_CHAN_A, SAB_CHANLEN, &sc->sc_bh);
391 1.1.2.2 nathanw break;
392 1.1.2.2 nathanw case 1: /* port B */
393 1.1.2.2 nathanw sc->sc_pvr_dtr = SAB_PVR_DTR_B;
394 1.1.2.2 nathanw sc->sc_pvr_dsr = SAB_PVR_DSR_B;
395 1.1.2.2 nathanw r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh,
396 1.1.2.2 nathanw SAB_CHAN_B, SAB_CHANLEN, &sc->sc_bh);
397 1.1.2.2 nathanw break;
398 1.1.2.2 nathanw default:
399 1.1.2.2 nathanw printf(": invalid channel: %u\n", sa->sbt_portno);
400 1.1.2.2 nathanw return;
401 1.1.2.2 nathanw }
402 1.1.2.2 nathanw if (r != 0) {
403 1.1.2.2 nathanw printf(": failed to allocate register subregion\n");
404 1.1.2.2 nathanw return;
405 1.1.2.2 nathanw }
406 1.1.2.2 nathanw
407 1.1.2.2 nathanw sabtty_console_flags(sc);
408 1.1.2.2 nathanw
409 1.1.2.2 nathanw if (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) {
410 1.1.2.2 nathanw struct termios t;
411 1.1.2.2 nathanw char *acc;
412 1.1.2.2 nathanw
413 1.1.2.2 nathanw switch (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) {
414 1.1.2.2 nathanw case SABTTYF_CONS_IN:
415 1.1.2.2 nathanw acc = "input";
416 1.1.2.2 nathanw break;
417 1.1.2.2 nathanw case SABTTYF_CONS_OUT:
418 1.1.2.2 nathanw acc = "output";
419 1.1.2.2 nathanw break;
420 1.1.2.2 nathanw case SABTTYF_CONS_IN|SABTTYF_CONS_OUT:
421 1.1.2.2 nathanw default:
422 1.1.2.2 nathanw acc = "i/o";
423 1.1.2.2 nathanw break;
424 1.1.2.2 nathanw }
425 1.1.2.2 nathanw
426 1.1.2.2 nathanw /* Let current output drain */
427 1.1.2.2 nathanw DELAY(100000);
428 1.1.2.2 nathanw
429 1.1.2.2 nathanw t.c_ispeed= 0;
430 1.1.2.2 nathanw t.c_ospeed = 9600;
431 1.1.2.2 nathanw t.c_cflag = CREAD | CS8 | HUPCL;
432 1.1.2.2 nathanw sc->sc_tty->t_ospeed = 0;
433 1.1.2.2 nathanw sabttyparam(sc, sc->sc_tty, &t);
434 1.1.2.2 nathanw
435 1.1.2.2 nathanw if (sc->sc_flags & SABTTYF_CONS_IN) {
436 1.1.2.2 nathanw sabtty_cons_input = sc;
437 1.1.2.2 nathanw cn_tab->cn_pollc = sab_cnpollc;
438 1.1.2.2 nathanw cn_tab->cn_getc = sab_cngetc;
439 1.1.2.2 nathanw cn_tab->cn_dev = makedev(77/*XXX*/, self->dv_unit);
440 1.1.2.2 nathanw shutdownhook_establish(sabtty_shutdown, sc);
441 1.1.2.2 nathanw }
442 1.1.2.2 nathanw
443 1.1.2.2 nathanw if (sc->sc_flags & SABTTYF_CONS_OUT) {
444 1.1.2.2 nathanw sabtty_cons_output = sc;
445 1.1.2.2 nathanw cn_tab->cn_putc = sab_cnputc;
446 1.1.2.2 nathanw cn_tab->cn_dev = makedev(77/*XXX*/, self->dv_unit);
447 1.1.2.2 nathanw }
448 1.1.2.2 nathanw printf(": console %s", acc);
449 1.1.2.2 nathanw } else {
450 1.1.2.2 nathanw /* Not a console... */
451 1.1.2.2 nathanw sabtty_reset(sc);
452 1.1.2.2 nathanw }
453 1.1.2.2 nathanw
454 1.1.2.2 nathanw printf("\n");
455 1.1.2.2 nathanw }
456 1.1.2.2 nathanw
457 1.1.2.2 nathanw int
458 1.1.2.2 nathanw sabtty_intr(sc, needsoftp)
459 1.1.2.2 nathanw struct sabtty_softc *sc;
460 1.1.2.2 nathanw int *needsoftp;
461 1.1.2.2 nathanw {
462 1.1.2.2 nathanw u_int8_t isr0, isr1;
463 1.1.2.2 nathanw int i, len = 0, needsoft = 0, r = 0, clearfifo = 0;
464 1.1.2.2 nathanw
465 1.1.2.2 nathanw isr0 = SAB_READ(sc, SAB_ISR0);
466 1.1.2.2 nathanw isr1 = SAB_READ(sc, SAB_ISR1);
467 1.1.2.2 nathanw
468 1.1.2.2 nathanw if (isr0 || isr1)
469 1.1.2.2 nathanw r = 1;
470 1.1.2.2 nathanw
471 1.1.2.2 nathanw if (isr0 & SAB_ISR0_RPF) {
472 1.1.2.2 nathanw len = 32;
473 1.1.2.2 nathanw clearfifo = 1;
474 1.1.2.2 nathanw }
475 1.1.2.2 nathanw if (isr0 & SAB_ISR0_TCD) {
476 1.1.2.2 nathanw len = (32 - 1) & SAB_READ(sc, SAB_RBCL);
477 1.1.2.2 nathanw clearfifo = 1;
478 1.1.2.2 nathanw }
479 1.1.2.2 nathanw if (isr0 & SAB_ISR0_TIME) {
480 1.1.2.2 nathanw sabtty_cec_wait(sc);
481 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RFRD);
482 1.1.2.2 nathanw }
483 1.1.2.2 nathanw if (isr0 & SAB_ISR0_RFO) {
484 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_RINGOVERFLOW;
485 1.1.2.2 nathanw clearfifo = 1;
486 1.1.2.2 nathanw }
487 1.1.2.2 nathanw if (len != 0) {
488 1.1.2.2 nathanw u_int8_t *ptr;
489 1.1.2.2 nathanw
490 1.1.2.2 nathanw ptr = sc->sc_rput;
491 1.1.2.2 nathanw for (i = 0; i < len; i++) {
492 1.1.2.2 nathanw *ptr++ = SAB_READ(sc, SAB_RFIFO);
493 1.1.2.2 nathanw if (ptr == sc->sc_rend)
494 1.1.2.2 nathanw ptr = sc->sc_rbuf;
495 1.1.2.2 nathanw if (ptr == sc->sc_rget) {
496 1.1.2.2 nathanw if (ptr == sc->sc_rbuf)
497 1.1.2.2 nathanw ptr = sc->sc_rend;
498 1.1.2.2 nathanw ptr--;
499 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_RINGOVERFLOW;
500 1.1.2.2 nathanw }
501 1.1.2.2 nathanw }
502 1.1.2.2 nathanw sc->sc_rput = ptr;
503 1.1.2.2 nathanw needsoft = 1;
504 1.1.2.2 nathanw }
505 1.1.2.2 nathanw
506 1.1.2.2 nathanw if (clearfifo) {
507 1.1.2.2 nathanw sabtty_cec_wait(sc);
508 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RMC);
509 1.1.2.2 nathanw }
510 1.1.2.2 nathanw
511 1.1.2.2 nathanw if (isr0 & SAB_ISR0_CDSC) {
512 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_CDCHG;
513 1.1.2.2 nathanw needsoft = 1;
514 1.1.2.2 nathanw }
515 1.1.2.2 nathanw
516 1.1.2.2 nathanw if (isr1 & SAB_ISR1_BRKT)
517 1.1.2.2 nathanw sabtty_abort(sc);
518 1.1.2.2 nathanw
519 1.1.2.2 nathanw if (isr1 & SAB_ISR1_ALLS) {
520 1.1.2.2 nathanw if (sc->sc_flags & SABTTYF_TXDRAIN)
521 1.1.2.2 nathanw wakeup(sc);
522 1.1.2.2 nathanw sc->sc_flags &= ~SABTTYF_STOP;
523 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_DONE;
524 1.1.2.2 nathanw sc->sc_imr1 |= SAB_IMR1_ALLS;
525 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
526 1.1.2.2 nathanw needsoft = 1;
527 1.1.2.2 nathanw }
528 1.1.2.2 nathanw
529 1.1.2.2 nathanw if (isr1 & SAB_ISR1_XPR) {
530 1.1.2.2 nathanw r = 1;
531 1.1.2.2 nathanw if ((sc->sc_flags & SABTTYF_STOP) == 0) {
532 1.1.2.2 nathanw if (sc->sc_txc < 32)
533 1.1.2.2 nathanw len = sc->sc_txc;
534 1.1.2.2 nathanw else
535 1.1.2.2 nathanw len = 32;
536 1.1.2.2 nathanw for (i = 0; i < len; i++) {
537 1.1.2.2 nathanw SAB_WRITE(sc, SAB_XFIFO + i, *sc->sc_txp);
538 1.1.2.2 nathanw sc->sc_txp++;
539 1.1.2.2 nathanw sc->sc_txc--;
540 1.1.2.2 nathanw }
541 1.1.2.2 nathanw if (i != 0) {
542 1.1.2.2 nathanw sabtty_cec_wait(sc);
543 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XF);
544 1.1.2.2 nathanw }
545 1.1.2.2 nathanw }
546 1.1.2.2 nathanw
547 1.1.2.2 nathanw if ((sc->sc_txc == 0) || (sc->sc_flags & SABTTYF_STOP)) {
548 1.1.2.2 nathanw sc->sc_imr1 |= SAB_IMR1_XPR;
549 1.1.2.2 nathanw sc->sc_imr1 &= ~SAB_IMR1_ALLS;
550 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
551 1.1.2.2 nathanw }
552 1.1.2.2 nathanw }
553 1.1.2.2 nathanw
554 1.1.2.2 nathanw if (needsoft)
555 1.1.2.2 nathanw *needsoftp = needsoft;
556 1.1.2.2 nathanw return (r);
557 1.1.2.2 nathanw }
558 1.1.2.2 nathanw
559 1.1.2.2 nathanw void
560 1.1.2.2 nathanw sabtty_softintr(sc)
561 1.1.2.2 nathanw struct sabtty_softc *sc;
562 1.1.2.2 nathanw {
563 1.1.2.2 nathanw struct tty *tp = sc->sc_tty;
564 1.1.2.2 nathanw int s, flags;
565 1.1.2.2 nathanw u_int8_t r;
566 1.1.2.2 nathanw
567 1.1.2.2 nathanw if (tp == NULL)
568 1.1.2.2 nathanw return;
569 1.1.2.2 nathanw
570 1.1.2.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0)
571 1.1.2.2 nathanw return;
572 1.1.2.2 nathanw
573 1.1.2.2 nathanw while (sc->sc_rget != sc->sc_rput) {
574 1.1.2.2 nathanw int data;
575 1.1.2.2 nathanw u_int8_t stat;
576 1.1.2.2 nathanw
577 1.1.2.2 nathanw data = sc->sc_rget[0];
578 1.1.2.2 nathanw stat = sc->sc_rget[1];
579 1.1.2.2 nathanw sc->sc_rget += 2;
580 1.1.2.2 nathanw if (stat & SAB_RSTAT_PE)
581 1.1.2.2 nathanw data |= TTY_PE;
582 1.1.2.2 nathanw if (stat & SAB_RSTAT_FE)
583 1.1.2.2 nathanw data |= TTY_FE;
584 1.1.2.2 nathanw if (sc->sc_rget == sc->sc_rend)
585 1.1.2.2 nathanw sc->sc_rget = sc->sc_rbuf;
586 1.1.2.2 nathanw
587 1.1.2.2 nathanw (*tp->t_linesw->l_rint)(data, tp);
588 1.1.2.2 nathanw }
589 1.1.2.2 nathanw
590 1.1.2.2 nathanw s = splhigh();
591 1.1.2.2 nathanw flags = sc->sc_flags;
592 1.1.2.2 nathanw sc->sc_flags &= ~(SABTTYF_DONE|SABTTYF_CDCHG|SABTTYF_RINGOVERFLOW);
593 1.1.2.2 nathanw splx(s);
594 1.1.2.2 nathanw
595 1.1.2.2 nathanw if (flags & SABTTYF_CDCHG) {
596 1.1.2.2 nathanw s = spltty();
597 1.1.2.2 nathanw r = SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD;
598 1.1.2.2 nathanw splx(s);
599 1.1.2.2 nathanw
600 1.1.2.2 nathanw (*tp->t_linesw->l_modem)(tp, r);
601 1.1.2.2 nathanw }
602 1.1.2.2 nathanw
603 1.1.2.2 nathanw if (flags & SABTTYF_RINGOVERFLOW)
604 1.1.2.2 nathanw log(LOG_WARNING, "%s: ring overflow\n", sc->sc_dv.dv_xname);
605 1.1.2.2 nathanw
606 1.1.2.2 nathanw if (flags & SABTTYF_DONE) {
607 1.1.2.2 nathanw ndflush(&tp->t_outq, sc->sc_txp - tp->t_outq.c_cf);
608 1.1.2.2 nathanw tp->t_state &= ~TS_BUSY;
609 1.1.2.2 nathanw (*tp->t_linesw->l_start)(tp);
610 1.1.2.2 nathanw }
611 1.1.2.2 nathanw }
612 1.1.2.2 nathanw
613 1.1.2.2 nathanw int
614 1.1.2.2 nathanw sabopen(dev, flags, mode, p)
615 1.1.2.2 nathanw dev_t dev;
616 1.1.2.2 nathanw int flags, mode;
617 1.1.2.2 nathanw struct proc *p;
618 1.1.2.2 nathanw {
619 1.1.2.2 nathanw struct sabtty_softc *sc;
620 1.1.2.2 nathanw struct tty *tp;
621 1.1.2.2 nathanw int s, s1;
622 1.1.2.2 nathanw
623 1.1.2.2 nathanw sc = device_lookup(&sabtty_cd, SABUNIT(dev));
624 1.1.2.2 nathanw if (sc == NULL)
625 1.1.2.2 nathanw return (ENXIO);
626 1.1.2.2 nathanw
627 1.1.2.2 nathanw tp = sc->sc_tty;
628 1.1.2.2 nathanw tp->t_dev = dev;
629 1.1.2.2 nathanw
630 1.1.2.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0) {
631 1.1.2.2 nathanw /* XXX tp->t_state |= TS_WOPEN; */
632 1.1.2.2 nathanw
633 1.1.2.2 nathanw ttychars(tp);
634 1.1.2.2 nathanw tp->t_iflag = TTYDEF_IFLAG;
635 1.1.2.2 nathanw tp->t_oflag = TTYDEF_OFLAG;
636 1.1.2.2 nathanw tp->t_cflag = TTYDEF_CFLAG;
637 1.1.2.2 nathanw if (sc->sc_openflags & TIOCFLAG_CLOCAL)
638 1.1.2.2 nathanw tp->t_cflag |= CLOCAL;
639 1.1.2.2 nathanw if (sc->sc_openflags & TIOCFLAG_CRTSCTS)
640 1.1.2.2 nathanw tp->t_cflag |= CRTSCTS;
641 1.1.2.2 nathanw if (sc->sc_openflags & TIOCFLAG_MDMBUF)
642 1.1.2.2 nathanw tp->t_cflag |= MDMBUF;
643 1.1.2.2 nathanw tp->t_lflag = TTYDEF_LFLAG;
644 1.1.2.2 nathanw tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
645 1.1.2.2 nathanw
646 1.1.2.2 nathanw sc->sc_rput = sc->sc_rget = sc->sc_rbuf;
647 1.1.2.2 nathanw
648 1.1.2.2 nathanw s = spltty();
649 1.1.2.2 nathanw
650 1.1.2.2 nathanw ttsetwater(tp);
651 1.1.2.2 nathanw
652 1.1.2.2 nathanw s1 = splhigh();
653 1.1.2.2 nathanw sabtty_reset(sc);
654 1.1.2.2 nathanw sabtty_param(tp, &tp->t_termios);
655 1.1.2.2 nathanw sc->sc_imr0 = SAB_IMR0_PERR | SAB_IMR0_FERR | SAB_IMR0_PLLA;
656 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
657 1.1.2.2 nathanw sc->sc_imr1 = SAB_IMR1_BRK | SAB_IMR1_ALLS | SAB_IMR1_XDU |
658 1.1.2.2 nathanw SAB_IMR1_TIN | SAB_IMR1_CSC | SAB_IMR1_XMR | SAB_IMR1_XPR;
659 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
660 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR0, SAB_READ(sc, SAB_CCR0) | SAB_CCR0_PU);
661 1.1.2.2 nathanw sabtty_cec_wait(sc);
662 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XRES);
663 1.1.2.2 nathanw sabtty_cec_wait(sc);
664 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
665 1.1.2.2 nathanw sabtty_cec_wait(sc);
666 1.1.2.2 nathanw splx(s1);
667 1.1.2.2 nathanw
668 1.1.2.2 nathanw sabtty_flush(sc);
669 1.1.2.2 nathanw
670 1.1.2.2 nathanw if ((sc->sc_openflags & TIOCFLAG_SOFTCAR) ||
671 1.1.2.2 nathanw (SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD))
672 1.1.2.2 nathanw tp->t_state |= TS_CARR_ON;
673 1.1.2.2 nathanw else
674 1.1.2.2 nathanw tp->t_state &= ~TS_CARR_ON;
675 1.1.2.2 nathanw } else if ((tp->t_state & TS_XCLUDE) &&
676 1.1.2.2 nathanw (!suser(p->p_ucred, &p->p_acflag))) {
677 1.1.2.2 nathanw return (EBUSY);
678 1.1.2.2 nathanw } else {
679 1.1.2.2 nathanw s = spltty();
680 1.1.2.2 nathanw }
681 1.1.2.2 nathanw
682 1.1.2.2 nathanw if ((flags & O_NONBLOCK) == 0) {
683 1.1.2.2 nathanw while ((tp->t_cflag & CLOCAL) == 0 &&
684 1.1.2.2 nathanw (tp->t_state & TS_CARR_ON) == 0) {
685 1.1.2.2 nathanw int error;
686 1.1.2.2 nathanw
687 1.1.2.2 nathanw /* XXX tp->t_state |= TS_WOPEN; */
688 1.1.2.2 nathanw error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
689 1.1.2.2 nathanw "sabttycd", 0);
690 1.1.2.2 nathanw if (error != 0) {
691 1.1.2.2 nathanw splx(s);
692 1.1.2.2 nathanw /* XXX tp->t_state &= ~TS_WOPEN; */
693 1.1.2.2 nathanw return (error);
694 1.1.2.2 nathanw }
695 1.1.2.2 nathanw }
696 1.1.2.2 nathanw }
697 1.1.2.2 nathanw
698 1.1.2.2 nathanw splx(s);
699 1.1.2.2 nathanw
700 1.1.2.2 nathanw s = (*tp->t_linesw->l_open)(dev, tp);
701 1.1.2.2 nathanw if (s != 0) {
702 1.1.2.2 nathanw if (tp->t_state & TS_ISOPEN)
703 1.1.2.2 nathanw return (s);
704 1.1.2.2 nathanw
705 1.1.2.2 nathanw if (tp->t_cflag & HUPCL) {
706 1.1.2.2 nathanw sabtty_mdmctrl(sc, 0, DMSET);
707 1.1.2.2 nathanw (void)tsleep(sc, TTIPRI, ttclos, hz);
708 1.1.2.2 nathanw }
709 1.1.2.2 nathanw
710 1.1.2.2 nathanw if ((sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) == 0) {
711 1.1.2.2 nathanw /* Flush and power down if we're not the console */
712 1.1.2.2 nathanw sabtty_flush(sc);
713 1.1.2.2 nathanw sabtty_reset(sc);
714 1.1.2.2 nathanw }
715 1.1.2.2 nathanw }
716 1.1.2.2 nathanw return (s);
717 1.1.2.2 nathanw }
718 1.1.2.2 nathanw
719 1.1.2.2 nathanw int
720 1.1.2.2 nathanw sabclose(dev, flags, mode, p)
721 1.1.2.2 nathanw dev_t dev;
722 1.1.2.2 nathanw int flags, mode;
723 1.1.2.2 nathanw struct proc *p;
724 1.1.2.2 nathanw {
725 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
726 1.1.2.2 nathanw struct sab_softc *bc = sc->sc_parent;
727 1.1.2.2 nathanw struct tty *tp = sc->sc_tty;
728 1.1.2.2 nathanw int s;
729 1.1.2.2 nathanw
730 1.1.2.2 nathanw (*tp->t_linesw->l_close)(tp, flags);
731 1.1.2.2 nathanw
732 1.1.2.2 nathanw s = spltty();
733 1.1.2.2 nathanw
734 1.1.2.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0) {
735 1.1.2.2 nathanw /* Wait for output drain */
736 1.1.2.2 nathanw sc->sc_imr1 &= ~SAB_IMR1_ALLS;
737 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
738 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_TXDRAIN;
739 1.1.2.2 nathanw (void)tsleep(sc, TTIPRI, ttclos, 5 * hz);
740 1.1.2.2 nathanw sc->sc_imr1 |= SAB_IMR1_ALLS;
741 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
742 1.1.2.2 nathanw sc->sc_flags &= ~SABTTYF_TXDRAIN;
743 1.1.2.2 nathanw
744 1.1.2.2 nathanw if (tp->t_cflag & HUPCL) {
745 1.1.2.2 nathanw sabtty_mdmctrl(sc, 0, DMSET);
746 1.1.2.2 nathanw (void)tsleep(bc, TTIPRI, ttclos, hz);
747 1.1.2.2 nathanw }
748 1.1.2.2 nathanw
749 1.1.2.2 nathanw if ((sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) == 0) {
750 1.1.2.2 nathanw /* Flush and power down if we're not the console */
751 1.1.2.2 nathanw sabtty_flush(sc);
752 1.1.2.2 nathanw sabtty_reset(sc);
753 1.1.2.2 nathanw }
754 1.1.2.2 nathanw }
755 1.1.2.2 nathanw
756 1.1.2.2 nathanw ttyclose(tp);
757 1.1.2.2 nathanw splx(s);
758 1.1.2.2 nathanw
759 1.1.2.2 nathanw return (0);
760 1.1.2.2 nathanw }
761 1.1.2.2 nathanw
762 1.1.2.2 nathanw int
763 1.1.2.2 nathanw sabread(dev, uio, flags)
764 1.1.2.2 nathanw dev_t dev;
765 1.1.2.2 nathanw struct uio *uio;
766 1.1.2.2 nathanw int flags;
767 1.1.2.2 nathanw {
768 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
769 1.1.2.2 nathanw struct tty *tp = sc->sc_tty;
770 1.1.2.2 nathanw
771 1.1.2.2 nathanw return ((*tp->t_linesw->l_read)(tp, uio, flags));
772 1.1.2.2 nathanw }
773 1.1.2.2 nathanw
774 1.1.2.2 nathanw int
775 1.1.2.2 nathanw sabwrite(dev, uio, flags)
776 1.1.2.2 nathanw dev_t dev;
777 1.1.2.2 nathanw struct uio *uio;
778 1.1.2.2 nathanw int flags;
779 1.1.2.2 nathanw {
780 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
781 1.1.2.2 nathanw struct tty *tp = sc->sc_tty;
782 1.1.2.2 nathanw
783 1.1.2.2 nathanw return ((*tp->t_linesw->l_write)(tp, uio, flags));
784 1.1.2.2 nathanw }
785 1.1.2.2 nathanw
786 1.1.2.2 nathanw int
787 1.1.2.2 nathanw sabioctl(dev, cmd, data, flags, p)
788 1.1.2.2 nathanw dev_t dev;
789 1.1.2.2 nathanw u_long cmd;
790 1.1.2.2 nathanw caddr_t data;
791 1.1.2.2 nathanw int flags;
792 1.1.2.2 nathanw struct proc *p;
793 1.1.2.2 nathanw {
794 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
795 1.1.2.2 nathanw struct tty *tp = sc->sc_tty;
796 1.1.2.2 nathanw int error;
797 1.1.2.2 nathanw
798 1.1.2.2 nathanw error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flags, p);
799 1.1.2.2 nathanw if (error >= 0)
800 1.1.2.2 nathanw return (error);
801 1.1.2.2 nathanw
802 1.1.2.2 nathanw error = ttioctl(tp, cmd, data, flags, p);
803 1.1.2.2 nathanw if (error >= 0)
804 1.1.2.2 nathanw return (error);
805 1.1.2.2 nathanw
806 1.1.2.2 nathanw error = 0;
807 1.1.2.2 nathanw
808 1.1.2.2 nathanw switch (cmd) {
809 1.1.2.2 nathanw case TIOCSBRK:
810 1.1.2.2 nathanw SAB_WRITE(sc, SAB_DAFO,
811 1.1.2.2 nathanw SAB_READ(sc, SAB_DAFO) | SAB_DAFO_XBRK);
812 1.1.2.2 nathanw break;
813 1.1.2.2 nathanw case TIOCCBRK:
814 1.1.2.2 nathanw SAB_WRITE(sc, SAB_DAFO,
815 1.1.2.2 nathanw SAB_READ(sc, SAB_DAFO) & ~SAB_DAFO_XBRK);
816 1.1.2.2 nathanw break;
817 1.1.2.2 nathanw case TIOCSDTR:
818 1.1.2.2 nathanw sabtty_mdmctrl(sc, TIOCM_DTR, DMBIS);
819 1.1.2.2 nathanw break;
820 1.1.2.2 nathanw case TIOCCDTR:
821 1.1.2.2 nathanw sabtty_mdmctrl(sc, TIOCM_DTR, DMBIC);
822 1.1.2.2 nathanw break;
823 1.1.2.2 nathanw case TIOCMBIS:
824 1.1.2.2 nathanw sabtty_mdmctrl(sc, *((int *)data), DMBIS);
825 1.1.2.2 nathanw break;
826 1.1.2.2 nathanw case TIOCMBIC:
827 1.1.2.2 nathanw sabtty_mdmctrl(sc, *((int *)data), DMBIC);
828 1.1.2.2 nathanw break;
829 1.1.2.2 nathanw case TIOCMGET:
830 1.1.2.2 nathanw *((int *)data) = sabtty_mdmctrl(sc, 0, DMGET);
831 1.1.2.2 nathanw break;
832 1.1.2.2 nathanw case TIOCMSET:
833 1.1.2.2 nathanw sabtty_mdmctrl(sc, *((int *)data), DMSET);
834 1.1.2.2 nathanw break;
835 1.1.2.2 nathanw case TIOCGFLAGS:
836 1.1.2.2 nathanw *((int *)data) = sc->sc_openflags;
837 1.1.2.2 nathanw break;
838 1.1.2.2 nathanw case TIOCSFLAGS:
839 1.1.2.2 nathanw if (suser(p->p_ucred, &p->p_acflag))
840 1.1.2.2 nathanw error = EPERM;
841 1.1.2.2 nathanw else
842 1.1.2.2 nathanw sc->sc_openflags = *((int *)data) &
843 1.1.2.2 nathanw (TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL |
844 1.1.2.2 nathanw TIOCFLAG_CRTSCTS | TIOCFLAG_MDMBUF);
845 1.1.2.2 nathanw break;
846 1.1.2.2 nathanw default:
847 1.1.2.2 nathanw error = ENOTTY;
848 1.1.2.2 nathanw }
849 1.1.2.2 nathanw
850 1.1.2.2 nathanw return (error);
851 1.1.2.2 nathanw }
852 1.1.2.2 nathanw
853 1.1.2.2 nathanw struct tty *
854 1.1.2.2 nathanw sabtty(dev)
855 1.1.2.2 nathanw dev_t dev;
856 1.1.2.2 nathanw {
857 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
858 1.1.2.2 nathanw
859 1.1.2.2 nathanw return (sc->sc_tty);
860 1.1.2.2 nathanw }
861 1.1.2.2 nathanw
862 1.1.2.2 nathanw void
863 1.1.2.2 nathanw sabstop(tp, flag)
864 1.1.2.2 nathanw struct tty *tp;
865 1.1.2.2 nathanw int flag;
866 1.1.2.2 nathanw {
867 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(tp->t_dev));
868 1.1.2.2 nathanw int s;
869 1.1.2.2 nathanw
870 1.1.2.2 nathanw s = spltty();
871 1.1.2.2 nathanw if (tp->t_state & TS_BUSY) {
872 1.1.2.2 nathanw if ((tp->t_state & TS_TTSTOP) == 0)
873 1.1.2.2 nathanw tp->t_state |= TS_FLUSH;
874 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_STOP;
875 1.1.2.2 nathanw sc->sc_imr1 &= ~SAB_IMR1_ALLS;
876 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
877 1.1.2.2 nathanw }
878 1.1.2.2 nathanw splx(s);
879 1.1.2.2 nathanw }
880 1.1.2.2 nathanw
881 1.1.2.2 nathanw int
882 1.1.2.2 nathanw sabpoll(dev, events, p)
883 1.1.2.2 nathanw dev_t dev;
884 1.1.2.2 nathanw int events;
885 1.1.2.2 nathanw struct proc *p;
886 1.1.2.2 nathanw {
887 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(dev));
888 1.1.2.2 nathanw struct tty *tp = sc->sc_tty;
889 1.1.2.2 nathanw
890 1.1.2.2 nathanw return ((*tp->t_linesw->l_poll)(tp, events, p));
891 1.1.2.2 nathanw }
892 1.1.2.2 nathanw
893 1.1.2.2 nathanw int
894 1.1.2.2 nathanw sabtty_mdmctrl(sc, bits, how)
895 1.1.2.2 nathanw struct sabtty_softc *sc;
896 1.1.2.2 nathanw int bits, how;
897 1.1.2.2 nathanw {
898 1.1.2.2 nathanw u_int8_t r;
899 1.1.2.2 nathanw int s;
900 1.1.2.2 nathanw
901 1.1.2.2 nathanw s = spltty();
902 1.1.2.2 nathanw switch (how) {
903 1.1.2.2 nathanw case DMGET:
904 1.1.2.2 nathanw bits = 0;
905 1.1.2.2 nathanw if (SAB_READ(sc, SAB_STAR) & SAB_STAR_CTS)
906 1.1.2.2 nathanw bits |= TIOCM_CTS;
907 1.1.2.2 nathanw if ((SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD) == 0)
908 1.1.2.2 nathanw bits |= TIOCM_CD;
909 1.1.2.2 nathanw
910 1.1.2.2 nathanw r = SAB_READ(sc, SAB_PVR);
911 1.1.2.2 nathanw if ((r & sc->sc_pvr_dtr) == 0)
912 1.1.2.2 nathanw bits |= TIOCM_DTR;
913 1.1.2.2 nathanw if ((r & sc->sc_pvr_dsr) == 0)
914 1.1.2.2 nathanw bits |= TIOCM_DSR;
915 1.1.2.2 nathanw
916 1.1.2.2 nathanw r = SAB_READ(sc, SAB_MODE);
917 1.1.2.2 nathanw if ((r & (SAB_MODE_RTS|SAB_MODE_FRTS)) == SAB_MODE_RTS)
918 1.1.2.2 nathanw bits |= TIOCM_RTS;
919 1.1.2.2 nathanw break;
920 1.1.2.2 nathanw case DMSET:
921 1.1.2.2 nathanw r = SAB_READ(sc, SAB_MODE);
922 1.1.2.2 nathanw if (bits & TIOCM_RTS) {
923 1.1.2.2 nathanw r &= ~SAB_MODE_FRTS;
924 1.1.2.2 nathanw r |= SAB_MODE_RTS;
925 1.1.2.2 nathanw } else
926 1.1.2.2 nathanw r |= SAB_MODE_FRTS | SAB_MODE_RTS;
927 1.1.2.2 nathanw SAB_WRITE(sc, SAB_MODE, r);
928 1.1.2.2 nathanw
929 1.1.2.2 nathanw r = SAB_READ(sc, SAB_PVR);
930 1.1.2.2 nathanw if (bits & TIOCM_DTR)
931 1.1.2.2 nathanw r &= ~sc->sc_pvr_dtr;
932 1.1.2.2 nathanw else
933 1.1.2.2 nathanw r |= sc->sc_pvr_dtr;
934 1.1.2.2 nathanw SAB_WRITE(sc, SAB_PVR, r);
935 1.1.2.2 nathanw break;
936 1.1.2.2 nathanw case DMBIS:
937 1.1.2.2 nathanw if (bits & TIOCM_RTS) {
938 1.1.2.2 nathanw r = SAB_READ(sc, SAB_MODE);
939 1.1.2.2 nathanw r &= ~SAB_MODE_FRTS;
940 1.1.2.2 nathanw r |= SAB_MODE_RTS;
941 1.1.2.2 nathanw SAB_WRITE(sc, SAB_MODE, r);
942 1.1.2.2 nathanw }
943 1.1.2.2 nathanw if (bits & TIOCM_DTR) {
944 1.1.2.2 nathanw r = SAB_READ(sc, SAB_PVR);
945 1.1.2.2 nathanw r &= ~sc->sc_pvr_dtr;
946 1.1.2.2 nathanw SAB_WRITE(sc, SAB_PVR, r);
947 1.1.2.2 nathanw }
948 1.1.2.2 nathanw break;
949 1.1.2.2 nathanw case DMBIC:
950 1.1.2.2 nathanw if (bits & TIOCM_RTS) {
951 1.1.2.2 nathanw r = SAB_READ(sc, SAB_MODE);
952 1.1.2.2 nathanw r |= SAB_MODE_FRTS | SAB_MODE_RTS;
953 1.1.2.2 nathanw SAB_WRITE(sc, SAB_MODE, r);
954 1.1.2.2 nathanw }
955 1.1.2.2 nathanw if (bits & TIOCM_DTR) {
956 1.1.2.2 nathanw r = SAB_READ(sc, SAB_PVR);
957 1.1.2.2 nathanw r |= sc->sc_pvr_dtr;
958 1.1.2.2 nathanw SAB_WRITE(sc, SAB_PVR, r);
959 1.1.2.2 nathanw }
960 1.1.2.2 nathanw break;
961 1.1.2.2 nathanw }
962 1.1.2.2 nathanw splx(s);
963 1.1.2.2 nathanw return (bits);
964 1.1.2.2 nathanw }
965 1.1.2.2 nathanw
966 1.1.2.2 nathanw int
967 1.1.2.2 nathanw sabttyparam(sc, tp, t)
968 1.1.2.2 nathanw struct sabtty_softc *sc;
969 1.1.2.2 nathanw struct tty *tp;
970 1.1.2.2 nathanw struct termios *t;
971 1.1.2.2 nathanw {
972 1.1.2.2 nathanw int s, ospeed;
973 1.1.2.2 nathanw tcflag_t cflag;
974 1.1.2.2 nathanw u_int8_t dafo, r;
975 1.1.2.2 nathanw
976 1.1.2.2 nathanw ospeed = sabtty_speed(t->c_ospeed);
977 1.1.2.2 nathanw if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
978 1.1.2.2 nathanw return (EINVAL);
979 1.1.2.2 nathanw
980 1.1.2.2 nathanw s = spltty();
981 1.1.2.2 nathanw
982 1.1.2.2 nathanw /* hang up line if ospeed is zero, otherwise raise dtr */
983 1.1.2.2 nathanw sabtty_mdmctrl(sc, TIOCM_DTR,
984 1.1.2.2 nathanw (t->c_ospeed == 0) ? DMBIC : DMBIS);
985 1.1.2.2 nathanw
986 1.1.2.2 nathanw dafo = SAB_READ(sc, SAB_DAFO);
987 1.1.2.2 nathanw
988 1.1.2.2 nathanw cflag = t->c_cflag;
989 1.1.2.2 nathanw
990 1.1.2.2 nathanw if (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) {
991 1.1.2.2 nathanw cflag |= CLOCAL;
992 1.1.2.2 nathanw cflag &= ~HUPCL;
993 1.1.2.2 nathanw }
994 1.1.2.2 nathanw
995 1.1.2.2 nathanw if (cflag & CSTOPB)
996 1.1.2.2 nathanw dafo |= SAB_DAFO_STOP;
997 1.1.2.2 nathanw else
998 1.1.2.2 nathanw dafo &= ~SAB_DAFO_STOP;
999 1.1.2.2 nathanw
1000 1.1.2.2 nathanw dafo &= ~SAB_DAFO_CHL_CSIZE;
1001 1.1.2.2 nathanw switch (cflag & CSIZE) {
1002 1.1.2.2 nathanw case CS5:
1003 1.1.2.2 nathanw dafo |= SAB_DAFO_CHL_CS5;
1004 1.1.2.2 nathanw break;
1005 1.1.2.2 nathanw case CS6:
1006 1.1.2.2 nathanw dafo |= SAB_DAFO_CHL_CS6;
1007 1.1.2.2 nathanw break;
1008 1.1.2.2 nathanw case CS7:
1009 1.1.2.2 nathanw dafo |= SAB_DAFO_CHL_CS7;
1010 1.1.2.2 nathanw break;
1011 1.1.2.2 nathanw default:
1012 1.1.2.2 nathanw dafo |= SAB_DAFO_CHL_CS8;
1013 1.1.2.2 nathanw break;
1014 1.1.2.2 nathanw }
1015 1.1.2.2 nathanw
1016 1.1.2.2 nathanw dafo &= ~SAB_DAFO_PARMASK;
1017 1.1.2.2 nathanw if (cflag & PARENB) {
1018 1.1.2.2 nathanw if (cflag & PARODD)
1019 1.1.2.2 nathanw dafo |= SAB_DAFO_PAR_ODD;
1020 1.1.2.2 nathanw else
1021 1.1.2.2 nathanw dafo |= SAB_DAFO_PAR_EVEN;
1022 1.1.2.2 nathanw } else
1023 1.1.2.2 nathanw dafo |= SAB_DAFO_PAR_NONE;
1024 1.1.2.2 nathanw
1025 1.1.2.2 nathanw if (ospeed != 0) {
1026 1.1.2.2 nathanw SAB_WRITE(sc, SAB_BGR, ospeed & 0xff);
1027 1.1.2.2 nathanw r = SAB_READ(sc, SAB_CCR2);
1028 1.1.2.2 nathanw r &= ~(SAB_CCR2_BR9 | SAB_CCR2_BR8);
1029 1.1.2.2 nathanw r |= (ospeed >> 2) & (SAB_CCR2_BR9 | SAB_CCR2_BR8);
1030 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR2, r);
1031 1.1.2.2 nathanw }
1032 1.1.2.2 nathanw
1033 1.1.2.2 nathanw r = SAB_READ(sc, SAB_MODE);
1034 1.1.2.2 nathanw r |= SAB_MODE_RAC;
1035 1.1.2.2 nathanw if (cflag & CRTSCTS) {
1036 1.1.2.2 nathanw r &= ~(SAB_MODE_RTS | SAB_MODE_FCTS);
1037 1.1.2.2 nathanw r |= SAB_MODE_FRTS;
1038 1.1.2.2 nathanw sc->sc_imr1 &= ~SAB_IMR1_CSC;
1039 1.1.2.2 nathanw } else {
1040 1.1.2.2 nathanw r |= SAB_MODE_RTS | SAB_MODE_FCTS;
1041 1.1.2.2 nathanw r &= ~SAB_MODE_FRTS;
1042 1.1.2.2 nathanw sc->sc_imr1 |= SAB_IMR1_CSC;
1043 1.1.2.2 nathanw }
1044 1.1.2.2 nathanw SAB_WRITE(sc, SAB_MODE, r);
1045 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
1046 1.1.2.2 nathanw
1047 1.1.2.2 nathanw tp->t_cflag = cflag;
1048 1.1.2.2 nathanw
1049 1.1.2.2 nathanw splx(s);
1050 1.1.2.2 nathanw return (0);
1051 1.1.2.2 nathanw }
1052 1.1.2.2 nathanw
1053 1.1.2.2 nathanw int
1054 1.1.2.2 nathanw sabtty_param(tp, t)
1055 1.1.2.2 nathanw struct tty *tp;
1056 1.1.2.2 nathanw struct termios *t;
1057 1.1.2.2 nathanw {
1058 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(tp->t_dev));
1059 1.1.2.2 nathanw
1060 1.1.2.2 nathanw return (sabttyparam(sc, tp, t));
1061 1.1.2.2 nathanw }
1062 1.1.2.2 nathanw
1063 1.1.2.2 nathanw void
1064 1.1.2.2 nathanw sabtty_start(tp)
1065 1.1.2.2 nathanw struct tty *tp;
1066 1.1.2.2 nathanw {
1067 1.1.2.2 nathanw struct sabtty_softc *sc = device_lookup(&sabtty_cd, SABUNIT(tp->t_dev));
1068 1.1.2.2 nathanw int s;
1069 1.1.2.2 nathanw
1070 1.1.2.2 nathanw s = spltty();
1071 1.1.2.2 nathanw if ((tp->t_state & (TS_TTSTOP | TS_TIMEOUT | TS_BUSY)) == 0) {
1072 1.1.2.2 nathanw if (tp->t_outq.c_cc <= tp->t_lowat) {
1073 1.1.2.2 nathanw if (tp->t_state & TS_ASLEEP) {
1074 1.1.2.2 nathanw tp->t_state &= ~TS_ASLEEP;
1075 1.1.2.2 nathanw wakeup(&tp->t_outq);
1076 1.1.2.2 nathanw }
1077 1.1.2.2 nathanw selwakeup(&tp->t_wsel);
1078 1.1.2.2 nathanw }
1079 1.1.2.2 nathanw if (tp->t_outq.c_cc) {
1080 1.1.2.2 nathanw sc->sc_txc = ndqb(&tp->t_outq, 0);
1081 1.1.2.2 nathanw sc->sc_txp = tp->t_outq.c_cf;
1082 1.1.2.2 nathanw tp->t_state |= TS_BUSY;
1083 1.1.2.2 nathanw sc->sc_imr1 &= ~SAB_IMR1_XPR;
1084 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
1085 1.1.2.2 nathanw }
1086 1.1.2.2 nathanw }
1087 1.1.2.2 nathanw splx(s);
1088 1.1.2.2 nathanw }
1089 1.1.2.2 nathanw
1090 1.1.2.2 nathanw void
1091 1.1.2.2 nathanw sabtty_cec_wait(sc)
1092 1.1.2.2 nathanw struct sabtty_softc *sc;
1093 1.1.2.2 nathanw {
1094 1.1.2.2 nathanw int i = 50000;
1095 1.1.2.2 nathanw
1096 1.1.2.2 nathanw for (;;) {
1097 1.1.2.2 nathanw if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_CEC) == 0)
1098 1.1.2.2 nathanw return;
1099 1.1.2.2 nathanw if (--i == 0)
1100 1.1.2.2 nathanw break;
1101 1.1.2.2 nathanw DELAY(1);
1102 1.1.2.2 nathanw }
1103 1.1.2.2 nathanw }
1104 1.1.2.2 nathanw
1105 1.1.2.2 nathanw void
1106 1.1.2.2 nathanw sabtty_tec_wait(sc)
1107 1.1.2.2 nathanw struct sabtty_softc *sc;
1108 1.1.2.2 nathanw {
1109 1.1.2.2 nathanw int i = 200000;
1110 1.1.2.2 nathanw
1111 1.1.2.2 nathanw for (;;) {
1112 1.1.2.2 nathanw if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_TEC) == 0)
1113 1.1.2.2 nathanw return;
1114 1.1.2.2 nathanw if (--i == 0)
1115 1.1.2.2 nathanw break;
1116 1.1.2.2 nathanw DELAY(1);
1117 1.1.2.2 nathanw }
1118 1.1.2.2 nathanw }
1119 1.1.2.2 nathanw
1120 1.1.2.2 nathanw void
1121 1.1.2.2 nathanw sabtty_reset(sc)
1122 1.1.2.2 nathanw struct sabtty_softc *sc;
1123 1.1.2.2 nathanw {
1124 1.1.2.2 nathanw /* power down */
1125 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR0, 0);
1126 1.1.2.2 nathanw
1127 1.1.2.2 nathanw /* set basic configuration */
1128 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR0,
1129 1.1.2.2 nathanw SAB_CCR0_MCE | SAB_CCR0_SC_NRZ | SAB_CCR0_SM_ASYNC);
1130 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR1, SAB_CCR1_ODS | SAB_CCR1_BCR | SAB_CCR1_CM_7);
1131 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR2, SAB_CCR2_BDF | SAB_CCR2_SSEL | SAB_CCR2_TOE);
1132 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR3, 0);
1133 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CCR4, SAB_CCR4_MCK4 | SAB_CCR4_EBRG);
1134 1.1.2.2 nathanw SAB_WRITE(sc, SAB_MODE, SAB_MODE_RTS | SAB_MODE_FCTS | SAB_MODE_RAC);
1135 1.1.2.2 nathanw SAB_WRITE(sc, SAB_RFC,
1136 1.1.2.2 nathanw SAB_RFC_DPS | SAB_RFC_RFDF | SAB_RFC_RFTH_32CHAR);
1137 1.1.2.2 nathanw
1138 1.1.2.2 nathanw /* clear interrupts */
1139 1.1.2.2 nathanw sc->sc_imr0 = sc->sc_imr1 = 0xff;
1140 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
1141 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
1142 1.1.2.2 nathanw SAB_READ(sc, SAB_ISR0);
1143 1.1.2.2 nathanw SAB_READ(sc, SAB_ISR1);
1144 1.1.2.2 nathanw }
1145 1.1.2.2 nathanw
1146 1.1.2.2 nathanw void
1147 1.1.2.2 nathanw sabtty_flush(sc)
1148 1.1.2.2 nathanw struct sabtty_softc *sc;
1149 1.1.2.2 nathanw {
1150 1.1.2.2 nathanw /* clear rx fifo */
1151 1.1.2.2 nathanw sabtty_cec_wait(sc);
1152 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1153 1.1.2.2 nathanw
1154 1.1.2.2 nathanw /* clear tx fifo */
1155 1.1.2.2 nathanw sabtty_cec_wait(sc);
1156 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XRES);
1157 1.1.2.2 nathanw }
1158 1.1.2.2 nathanw
1159 1.1.2.2 nathanw int
1160 1.1.2.2 nathanw sabtty_speed(rate)
1161 1.1.2.2 nathanw int rate;
1162 1.1.2.2 nathanw {
1163 1.1.2.2 nathanw int i, len, r;
1164 1.1.2.2 nathanw
1165 1.1.2.2 nathanw if (rate == 0)
1166 1.1.2.2 nathanw return (0);
1167 1.1.2.2 nathanw len = sizeof(sabtty_baudtable)/sizeof(sabtty_baudtable[0]);
1168 1.1.2.2 nathanw for (i = 0; i < len; i++) {
1169 1.1.2.2 nathanw if (rate == sabtty_baudtable[i].baud) {
1170 1.1.2.2 nathanw r = sabtty_baudtable[i].n |
1171 1.1.2.2 nathanw (sabtty_baudtable[i].m << 6);
1172 1.1.2.2 nathanw return (r);
1173 1.1.2.2 nathanw }
1174 1.1.2.2 nathanw }
1175 1.1.2.2 nathanw return (-1);
1176 1.1.2.2 nathanw }
1177 1.1.2.2 nathanw
1178 1.1.2.2 nathanw void
1179 1.1.2.2 nathanw sabtty_cnputc(sc, c)
1180 1.1.2.2 nathanw struct sabtty_softc *sc;
1181 1.1.2.2 nathanw int c;
1182 1.1.2.2 nathanw {
1183 1.1.2.2 nathanw sabtty_tec_wait(sc);
1184 1.1.2.2 nathanw SAB_WRITE(sc, SAB_TIC, c);
1185 1.1.2.2 nathanw sabtty_tec_wait(sc);
1186 1.1.2.2 nathanw }
1187 1.1.2.2 nathanw
1188 1.1.2.2 nathanw int
1189 1.1.2.2 nathanw sabtty_cngetc(sc)
1190 1.1.2.2 nathanw struct sabtty_softc *sc;
1191 1.1.2.2 nathanw {
1192 1.1.2.2 nathanw u_int8_t r, len;
1193 1.1.2.2 nathanw
1194 1.1.2.2 nathanw again:
1195 1.1.2.2 nathanw do {
1196 1.1.2.2 nathanw r = SAB_READ(sc, SAB_STAR);
1197 1.1.2.2 nathanw } while ((r & SAB_STAR_RFNE) == 0);
1198 1.1.2.2 nathanw
1199 1.1.2.2 nathanw /*
1200 1.1.2.2 nathanw * Ok, at least one byte in RFIFO, ask for permission to access RFIFO
1201 1.1.2.2 nathanw * (I hate this chip... hate hate hate).
1202 1.1.2.2 nathanw */
1203 1.1.2.2 nathanw sabtty_cec_wait(sc);
1204 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RFRD);
1205 1.1.2.2 nathanw
1206 1.1.2.2 nathanw /* Wait for RFIFO to come ready */
1207 1.1.2.2 nathanw do {
1208 1.1.2.2 nathanw r = SAB_READ(sc, SAB_ISR0);
1209 1.1.2.2 nathanw } while ((r & SAB_ISR0_TCD) == 0);
1210 1.1.2.2 nathanw
1211 1.1.2.2 nathanw len = SAB_READ(sc, SAB_RBCL) & (32 - 1);
1212 1.1.2.2 nathanw if (len == 0)
1213 1.1.2.2 nathanw goto again; /* Shouldn't happen... */
1214 1.1.2.2 nathanw
1215 1.1.2.2 nathanw r = SAB_READ(sc, SAB_RFIFO);
1216 1.1.2.2 nathanw
1217 1.1.2.2 nathanw /*
1218 1.1.2.2 nathanw * Blow away everything left in the FIFO...
1219 1.1.2.2 nathanw */
1220 1.1.2.2 nathanw sabtty_cec_wait(sc);
1221 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RMC);
1222 1.1.2.2 nathanw return (r);
1223 1.1.2.2 nathanw }
1224 1.1.2.2 nathanw
1225 1.1.2.2 nathanw void
1226 1.1.2.2 nathanw sabtty_cnpollc(sc, on)
1227 1.1.2.2 nathanw struct sabtty_softc *sc;
1228 1.1.2.2 nathanw int on;
1229 1.1.2.2 nathanw {
1230 1.1.2.2 nathanw u_int8_t r;
1231 1.1.2.2 nathanw
1232 1.1.2.2 nathanw if (on) {
1233 1.1.2.2 nathanw if (sc->sc_polling)
1234 1.1.2.2 nathanw return;
1235 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IPC, SAB_READ(sc, SAB_IPC) | SAB_IPC_VIS);
1236 1.1.2.2 nathanw r = sc->sc_pollrfc = SAB_READ(sc, SAB_RFC);
1237 1.1.2.2 nathanw r &= ~(SAB_RFC_RFDF);
1238 1.1.2.2 nathanw SAB_WRITE(sc, SAB_RFC, r);
1239 1.1.2.2 nathanw sabtty_cec_wait(sc);
1240 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1241 1.1.2.2 nathanw sc->sc_polling = 1;
1242 1.1.2.2 nathanw } else {
1243 1.1.2.2 nathanw if (!sc->sc_polling)
1244 1.1.2.2 nathanw return;
1245 1.1.2.2 nathanw SAB_WRITE(sc, SAB_IPC, SAB_READ(sc, SAB_IPC) & ~SAB_IPC_VIS);
1246 1.1.2.2 nathanw SAB_WRITE(sc, SAB_RFC, sc->sc_pollrfc);
1247 1.1.2.2 nathanw sabtty_cec_wait(sc);
1248 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1249 1.1.2.2 nathanw sc->sc_polling = 0;
1250 1.1.2.2 nathanw }
1251 1.1.2.2 nathanw }
1252 1.1.2.2 nathanw
1253 1.1.2.2 nathanw void
1254 1.1.2.2 nathanw sab_cnputc(dev, c)
1255 1.1.2.2 nathanw dev_t dev;
1256 1.1.2.2 nathanw int c;
1257 1.1.2.2 nathanw {
1258 1.1.2.2 nathanw struct sabtty_softc *sc = sabtty_cons_output;
1259 1.1.2.2 nathanw
1260 1.1.2.2 nathanw if (sc == NULL)
1261 1.1.2.2 nathanw return;
1262 1.1.2.2 nathanw sabtty_cnputc(sc, c);
1263 1.1.2.2 nathanw }
1264 1.1.2.2 nathanw
1265 1.1.2.2 nathanw void
1266 1.1.2.2 nathanw sab_cnpollc(dev, on)
1267 1.1.2.2 nathanw dev_t dev;
1268 1.1.2.2 nathanw int on;
1269 1.1.2.2 nathanw {
1270 1.1.2.2 nathanw struct sabtty_softc *sc = sabtty_cons_input;
1271 1.1.2.2 nathanw
1272 1.1.2.2 nathanw sabtty_cnpollc(sc, on);
1273 1.1.2.2 nathanw }
1274 1.1.2.2 nathanw
1275 1.1.2.2 nathanw int
1276 1.1.2.2 nathanw sab_cngetc(dev)
1277 1.1.2.2 nathanw dev_t dev;
1278 1.1.2.2 nathanw {
1279 1.1.2.2 nathanw struct sabtty_softc *sc = sabtty_cons_input;
1280 1.1.2.2 nathanw
1281 1.1.2.2 nathanw if (sc == NULL)
1282 1.1.2.2 nathanw return (-1);
1283 1.1.2.2 nathanw return (sabtty_cngetc(sc));
1284 1.1.2.2 nathanw }
1285 1.1.2.2 nathanw
1286 1.1.2.2 nathanw void
1287 1.1.2.2 nathanw sabtty_console_flags(sc)
1288 1.1.2.2 nathanw struct sabtty_softc *sc;
1289 1.1.2.2 nathanw {
1290 1.1.2.2 nathanw int node, channel, cookie;
1291 1.1.2.4 nathanw u_int options;
1292 1.1.2.2 nathanw char buf[255];
1293 1.1.2.2 nathanw
1294 1.1.2.2 nathanw node = sc->sc_parent->sc_node;
1295 1.1.2.2 nathanw channel = sc->sc_portno;
1296 1.1.2.2 nathanw
1297 1.1.2.4 nathanw options = OF_finddevice("/options");
1298 1.1.2.2 nathanw
1299 1.1.2.2 nathanw /* Default to channel 0 if there are no explicit prom args */
1300 1.1.2.2 nathanw cookie = 0;
1301 1.1.2.2 nathanw
1302 1.1.2.2 nathanw if (node == OF_instance_to_package(OF_stdin())) {
1303 1.1.2.4 nathanw if (OF_getprop(options, "input-device", buf,
1304 1.1.2.2 nathanw sizeof(buf)) != -1) {
1305 1.1.2.2 nathanw if (strcmp("ttyb", buf) == 0)
1306 1.1.2.2 nathanw cookie = 1;
1307 1.1.2.2 nathanw }
1308 1.1.2.2 nathanw
1309 1.1.2.2 nathanw if (channel == cookie)
1310 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_CONS_IN;
1311 1.1.2.2 nathanw }
1312 1.1.2.2 nathanw
1313 1.1.2.2 nathanw /* Default to same channel if there are no explicit prom args */
1314 1.1.2.2 nathanw
1315 1.1.2.2 nathanw if (node == OF_instance_to_package(OF_stdout())) {
1316 1.1.2.4 nathanw if (OF_getprop(options, "output-device", buf,
1317 1.1.2.2 nathanw sizeof(buf)) != -1) {
1318 1.1.2.2 nathanw if (strcmp("ttyb", buf) == 0)
1319 1.1.2.2 nathanw cookie = 1;
1320 1.1.2.2 nathanw }
1321 1.1.2.2 nathanw
1322 1.1.2.2 nathanw if (channel == cookie)
1323 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_CONS_OUT;
1324 1.1.2.2 nathanw }
1325 1.1.2.2 nathanw }
1326 1.1.2.2 nathanw
1327 1.1.2.2 nathanw void
1328 1.1.2.2 nathanw sabtty_abort(sc)
1329 1.1.2.2 nathanw struct sabtty_softc *sc;
1330 1.1.2.2 nathanw {
1331 1.1.2.2 nathanw
1332 1.1.2.2 nathanw if (sc->sc_flags & SABTTYF_CONS_IN) {
1333 1.1.2.2 nathanw #ifdef DDB
1334 1.1.2.2 nathanw cn_trap();
1335 1.1.2.2 nathanw #else
1336 1.1.2.2 nathanw callrom();
1337 1.1.2.2 nathanw #endif
1338 1.1.2.2 nathanw }
1339 1.1.2.2 nathanw }
1340 1.1.2.2 nathanw
1341 1.1.2.2 nathanw void
1342 1.1.2.2 nathanw sabtty_shutdown(vsc)
1343 1.1.2.2 nathanw void *vsc;
1344 1.1.2.2 nathanw {
1345 1.1.2.2 nathanw struct sabtty_softc *sc = vsc;
1346 1.1.2.2 nathanw
1347 1.1.2.2 nathanw /* Have to put the chip back into single char mode */
1348 1.1.2.2 nathanw sc->sc_flags |= SABTTYF_DONTDDB;
1349 1.1.2.2 nathanw SAB_WRITE(sc, SAB_RFC, SAB_READ(sc, SAB_RFC) & ~SAB_RFC_RFDF);
1350 1.1.2.2 nathanw sabtty_cec_wait(sc);
1351 1.1.2.2 nathanw SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
1352 1.1.2.2 nathanw sabtty_cec_wait(sc);
1353 1.1.2.2 nathanw }
1354