1 /* $NetBSD: dz_ibus.c,v 1.8 2008/03/29 15:59:57 tsutsui Exp $ */
4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed at Ludd, University of
47 * Lule}, Sweden and its contributors.
48 * 4. The name of the author may not be used to endorse or promote products
49 * derived from this software without specific prior written permission
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: dz_ibus.c,v 1.8 2008/03/29 15:59:57 tsutsui Exp $");
69 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/ioctl.h>
76 #include <sys/device.h>
77 #include <sys/reboot.h>
79 #include <machine/bus.h>
83 #include <dev/tc/tcvar.h> /* tc_addr_t */
85 #include <dev/dec/dzreg.h>
86 #include <dev/dec/dzvar.h>
87 #include <dev/dec/dzkbdvar.h>
89 #include <pmax/ibus/ibusvar.h>
90 #include <pmax/pmax/pmaxtype.h>
91 #include <pmax/pmax/cons.h>
94 #define DZ_LINE_MOUSE 1
95 #define DZ_LINE_CONSOLE 2
98 int dz_ibus_match(device_t
, cfdata_t
, void *);
99 void dz_ibus_attach(device_t
, device_t
, void *);
100 int dz_ibus_intr(void *);
101 void dz_ibus_cnsetup(paddr_t
);
102 int dz_ibus_cngetc(dev_t
);
103 void dz_ibus_cnputc(dev_t
, int);
104 void dz_ibus_cnpollc(dev_t
, int);
105 int dz_ibus_getmajor(void);
106 int dz_ibus_print(void *, const char *);
108 int dzgetc(struct dz_linestate
*);
109 void dzputc(struct dz_linestate
*, int);
111 CFATTACH_DECL_NEW(dz_ibus
, sizeof(struct dz_softc
),
112 dz_ibus_match
, dz_ibus_attach
, NULL
, NULL
);
114 struct consdev dz_ibus_consdev
= {
115 NULL
, NULL
, dz_ibus_cngetc
, dz_ibus_cnputc
,
116 dz_ibus_cnpollc
, NULL
, NULL
, NULL
, NODEV
, CN_NORMAL
,
120 uint16_t csr
; /* 00 Csr: control/status */
123 uint16_t rbuf
; /* 08 Rbuf/Lpr: receive buffer/line param */
126 uint16_t tcr
; /* 10 Tcr: transmit console */
129 uint16_t tdr
; /* 18 Msr/Tdr: modem status reg/xmit data */
134 int dz_ibus_consln
= -1;
137 dz_ibus_match(device_t parent
, cfdata_t cf
, void *aux
)
139 struct ibus_attach_args
*iba
;
143 if (strcmp(iba
->ia_name
, "dc") != 0 &&
144 strcmp(iba
->ia_name
, "mdc") != 0 &&
145 strcmp(iba
->ia_name
, "dc7085") != 0)
148 if (badaddr((void *)iba
->ia_addr
, 2))
155 dz_ibus_attach(device_t parent
, device_t self
, void *aux
)
157 struct ibus_attach_args
*iba
= aux
;
158 struct dz_softc
*sc
= device_private(self
);
159 volatile struct dzregs
*dz
;
160 struct dzkm_attach_args daa
;
169 * XXX - This is evil and ugly, but... due to the nature of how
170 * bus_space_* works on pmax it will do for the time being.
172 sc
->sc_ioh
= (bus_space_handle_t
)MIPS_PHYS_TO_KSEG1(iba
->ia_addr
);
174 sc
->sc_dr
.dr_csr
= 0;
175 sc
->sc_dr
.dr_rbuf
= 8;
176 sc
->sc_dr
.dr_dtr
= 17;
177 sc
->sc_dr
.dr_break
= 25;
178 sc
->sc_dr
.dr_tbuf
= 24;
179 sc
->sc_dr
.dr_tcr
= 16;
180 sc
->sc_dr
.dr_dcd
= 25;
181 sc
->sc_dr
.dr_ring
= 24;
183 sc
->sc_dr
.dr_firstreg
= 0;
184 sc
->sc_dr
.dr_winsize
= sizeof(struct dzregs
);
186 sc
->sc_type
= DZ_DZV
;
188 dz
= (volatile struct dzregs
*)sc
->sc_ioh
;
190 dz
->csr
= DZ_CSR_MSE
| DZ_CSR_TXIE
;
200 sc
->sc_dsr
= 0x0f; /* XXX check if VS has modem ctrl bits */
202 aprint_normal(": DC-7085, 4 lines");
203 ibus_intr_establish(parent
, (void *)iba
->ia_cookie
, IPL_TTY
,
205 dzattach(sc
, NULL
, dz_ibus_consln
);
208 if (systype
== DS_PMAX
|| systype
== DS_3MAX
) {
211 dz
->rbuf
= DZ_LPR_RX_ENABLE
| (DZ_LPR_B4800
<< 8) |
212 DZ_LPR_8_BIT_CHAR
| DZ_LINE_KBD
;
213 daa
.daa_line
= DZ_LINE_KBD
;
214 daa
.daa_flags
= (dz_ibus_iscn
? 0 : DZKBD_CONSOLE
);
215 config_found(self
, &daa
, dz_ibus_print
);
218 dz
->rbuf
= DZ_LPR_RX_ENABLE
| (DZ_LPR_B4800
<< 8) |
219 DZ_LPR_8_BIT_CHAR
| DZ_LPR_PARENB
| DZ_LPR_OPAR
|
221 daa
.daa_line
= DZ_LINE_MOUSE
;
223 config_found(self
, &daa
, dz_ibus_print
);
229 dz_ibus_getmajor(void)
231 extern const struct cdevsw dz_cdevsw
;
232 static int cache
= -1;
237 return (cache
= cdevsw_lookup_major(&dz_cdevsw
));
241 dz_ibus_intr(void *cookie
)
244 volatile struct dzregs
*dzr
;
248 dzr
= (volatile struct dzregs
*)sc
->sc_ioh
;
250 while (((csr
= dzr
->csr
) & (DZ_CSR_RX_DONE
| DZ_CSR_TX_READY
)) != 0) {
251 if ((csr
& DZ_CSR_RX_DONE
) != 0)
253 if ((csr
& DZ_CSR_TX_READY
) != 0)
261 dz_ibus_cnsetup(paddr_t addr
)
264 dzcn
= (void *)MIPS_PHYS_TO_KSEG1(addr
);
268 dz_ibus_cnattach(int line
)
276 line
= DZ_LINE_CONSOLE
;
284 dz_ibus_consln
= line
;
286 /* Disable scanning until init is done. */
291 /* Turn on transmitter for the console. */
292 dzcn
->tcr
= (1 << line
);
296 /* Turn scanning back on. */
302 * Point the console at the DZ-11.
304 cn_tab
= &dz_ibus_consdev
;
305 cn_tab
->cn_pri
= CN_REMOTE
;
306 cn_tab
->cn_dev
= makedev(dz_ibus_getmajor(), line
);
310 dz_ibus_cngetc(dev_t dev
)
320 while ((dzcn
->csr
& DZ_CSR_RX_DONE
) == 0)
324 if (((rbuf
>> 8) & 3) != line
)
327 } while (c
== 17 || c
== 19); /* ignore XON/XOFF */
336 dz_ibus_cnputc(dev_t dev
, int ch
)
343 /* Don't hang the machine! */
346 /* Remember which lines to scan */
348 dzcn
->tcr
= (1 << minor(dev
));
352 /* Wait until ready */
353 while ((dzcn
->csr
& 0x8000) == 0)
358 /* Put the character */
364 /* Wait until ready */
365 while ((dzcn
->csr
& 0x8000) == 0)
377 dz_ibus_cnpollc(dev_t dev
, int pollflag
)
382 #if NDZKBD > 0 || NDZMS > 0
384 dz_ibus_print(void *aux
, const char *pnp
)
386 struct dzkm_attach_args
*daa
;
390 aprint_normal("lkkbd/vsms at %s", pnp
);
391 aprint_normal(" line %d", daa
->daa_line
);
396 dzgetc(struct dz_linestate
*ls
)
398 volatile struct dzregs
*dzr
;
404 * dzkbd is the only thing that should put us here.
410 dzr
= (volatile struct dzregs
*)ls
->dz_sc
->sc_ioh
;
415 while ((dzr
->csr
& DZ_CSR_RX_DONE
) == 0)
420 if (((rbuf
>> 8) & 3) == line
)
421 return (rbuf
& 0xff);
427 dzputc(struct dz_linestate
*ls
, int ch
)
429 volatile struct dzregs
*dzr
;
435 * If the dz has already been attached, the MI driver will do the
438 if (ls
!= NULL
&& ls
->dz_sc
!= NULL
) {
440 dzr
= (volatile struct dzregs
*)ls
->dz_sc
->sc_ioh
;
442 putc(ch
, &ls
->dz_tty
->t_outq
);
444 if ((tcr
& (1 << line
)) == 0) {
445 dzr
->tcr
= tcr
| (1 << line
);
454 /* Use dzcnputc to do the transmitting. */
455 dz_ibus_cnputc(makedev(dz_ibus_getmajor(), DZ_LINE_KBD
), ch
);
457 #endif /* NDZKBD > 0 || NDZMS > 0 */